Firefox PHP

[it works] VIEWS HACK for 3.4.1-stable

Posted by c0330 
[it works] VIEWS HACK for 3.4.1-stable
February 04, 2003 01:15AM
/////////////////////////////////////////////////////////
/
/ VIEWS HACK 2.0a for 3.4.1
/ MySQL only, but easilly adapted
/ Modified by Arthur
////////////////////////////////////////////////////////

!!!!!!BEFORE YOU DO ANYTHING, BACKUP YOUR ENTIRE PHORUM DIR USING ZIP OR TAR!!!!!!!!


It was TESTED and WORKED using Phorum 3.4.1 with PHP 4.2.3 and MySQL 3.23.55
All line numbers for v3.4.1. In newer or older Phorum Versions Lines will be different...

1. Modify read.php (this will increment the view count everytime someone fetches the page):

BEFORE line 184:



$msg_body = new query($DB, $sSQL);



INSERT:



// Views Hack Start
$vSQL = "SELECT * FROM $ForumTableName WHERE id=".$id;
$views = mysql_query($vSQL);
$row = mysql_fetch_array($views);
$vSQL = "UPDATE $ForumTableName SET views=" . ($row["views"] + 1) . " WHERE id=$id";
mysql_query($vSQL);
// Views Hack End



2. Modify db/mysql.php (this will make sure all new forums get the extra views column):

REPLACE line 167:



function create_table(&$DB, $table, $table_name){
global $q;
switch($table){
case "main":
$sSQL="CREATE TABLE $table_name (
id int unsigned DEFAULT '0' NOT NULL,
datestamp datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
thread int unsigned DEFAULT '0' NOT NULL,
parent int unsigned DEFAULT '0' NOT NULL,
author char(37) DEFAULT '' NOT NULL,
subject char(255) DEFAULT '' NOT NULL,
email char(200) DEFAULT '' NOT NULL,
host varchar(255) DEFAULT '' NOT NULL,
email_reply char(1) NOT NULL DEFAULT 'N',
approved char(1) NOT NULL DEFAULT 'N',
msgid char(100) DEFAULT '' NOT NULL,
modifystamp int unsigned DEFAULT '0' NOT NULL,
userid int unsigned DEFAULT 0 NOT NULL,
closed tinyint DEFAULT 0 NOT NULL,
PRIMARY KEY (id),
KEY author (author),
KEY userid (userid),
KEY datestamp (datestamp),
KEY subject (subject),
KEY thread (thread),
KEY parent (parent),
KEY approved (approved),
KEY msgid (msgid),
KEY modifystamp (modifystamp)
)";



WITH :



function create_table(&$DB, $table, $table_name){
global $q;
switch($table){
case "main":
$sSQL="CREATE TABLE $table_name (
id int unsigned DEFAULT '0' NOT NULL,
datestamp datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
thread int unsigned DEFAULT '0' NOT NULL,
parent int unsigned DEFAULT '0' NOT NULL,
author char(37) DEFAULT '' NOT NULL,
subject char(255) DEFAULT '' NOT NULL,
email char(200) DEFAULT '' NOT NULL,
host varchar(255) DEFAULT '' NOT NULL,
email_reply char(1) NOT NULL DEFAULT 'N',
approved char(1) NOT NULL DEFAULT 'N',
msgid char(100) DEFAULT '' NOT NULL,
modifystamp int unsigned DEFAULT '0' NOT NULL,
userid int unsigned DEFAULT 0 NOT NULL,
closed tinyint DEFAULT 0 NOT NULL,
views INT(7) DEFAULT '0',
PRIMARY KEY (id),
KEY author (author),
KEY userid (userid),
KEY datestamp (datestamp),
KEY subject (subject),
KEY thread (thread),
KEY parent (parent),
KEY approved (approved),
KEY msgid (msgid),
KEY modifystamp (modifystamp)
)";



3. Modify list.php (enable views fetching from db):

REPLACE line 176 AND 274:



if($$phcollapse==0){
$SQL = "Select id,parent,thread,subject,author,datestamp,userid from $ForumTableName where approved='Y' AND thread<=$max and thread>=$min order by thread desc, id asc";
}
else{
$SQL = "Select id,thread,subject,author,datestamp,userid from $ForumTableName where approved='Y' AND thread = id AND thread<=$max AND thread>=$min order by thread desc";
}



WITH:



if($$phcollapse==0){
$SQL = "Select id,parent,thread,subject,author,datestamp,userid,views from $ForumTableName where approved='Y' AND thread<=$max and thread>=$min order by thread desc, id asc";
}
else{
$SQL = "Select id,thread,subject,author,datestamp,userid,views from $ForumTableName where approved='Y' AND thread = id AND thread<=$max AND thread>=$min order by thread desc";
}



4.1 Modify include/multi-threads.php (to display the actual views):

AFTER line 21:



$thread_total="";



INSERT:



$views = $topic["views"];



4.2 Modify include/multi-threads.php (to display the $views):

REPLACE line 196:



<table class="PhorumListTable" width="<?php echo $ForumTableWidth;?>" cellspacing="0" cellpadding="0" border="0" align="center">
<tr>
<td class="PhorumListHeader"<?php echo bgcolor($ForumTableHeaderColor);?>><font color="<?php echo $ForumTableHeaderFontColor; ?>"> <?php echo $lTopics;?><img src="images/trans.gif" border="0" width=1 height=24 align="absmiddle"></font></td>
<td class="PhorumListHeader"<?php echo bgcolor($ForumTableHeaderColor);?> nowrap width=150><font color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lAuthor;?> </font></td>
<td class="PhorumListHeader"<?php echo bgcolor($ForumTableHeaderColor);?> nowrap width=150><font color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lDate;?></font></td>
</tr>



WITH:



<table class="PhorumListTable" width="<?php echo $ForumTableWidth;?>" cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="PhorumListHeader"<?php echo bgcolor($ForumTableHeaderColor);?>><font color="<?php echo $ForumTableHeaderFontColor; ?>">&nbsp;<?php echo $lTopics;?><img src="images/trans.gif" border="0" width=1 height=24 align="absmiddle"></font></td>
<td class="PhorumListHeader"<?php echo bgcolor($ForumTableHeaderColor);?> nowrap="nowrap" width=150><font color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lAuthor;?>&nbsp;</font></td>
<td class="PhorumListHeader"<?PHP echo bgcolor($ForumTableHeaderColor);?> nowrap="nowrap" width=80><font color="<?php echo $ForumTableHeaderFontColor; ?>">Views</font></td>
<td class="PhorumListHeader"<?php echo bgcolor($ForumTableHeaderColor);?> nowrap="nowrap" width=150><font color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lDate;?></font></td>
</tr>



4.3 Modify include/multi-threads.php (to display the tables for $views):

REPLACE line 82:



<tr valign=middle>
<td class="PhorumListRow" <?php echo bgcolor($bgcolor);?>><?php echo $subject;?></td>
<td class="PhorumListRow" <?php echo bgcolor($bgcolor);?> nowrap><font color="<?php echo $font_color;?>"><?php echo $author;?></font></td>
<td class="PhorumListRow" <?php echo bgcolor($bgcolor);?> nowrap><font color="<?php echo $font_color;?>"><?php echo $datestamp;?> </font></td>
</tr>



WITH:



<tr valign=middle>
<td class="PhorumListRow" <?php echo bgcolor($bgcolor);?>><?php echo $subject;?></td>
<td class="PhorumListRow" <?php echo bgcolor($bgcolor);?> nowrap="nowrap"><font color="<?php echo $font_color;?>"><?php echo $author;?></font></td>
<td class="PhorumListRow" <?PHP echo bgcolor($bgcolor);?> nowrap="nowrap"><font color="<?php echo $font_color;?>"><?php echo $views;?></font></td>
<td class="PhorumListRow" <?php echo bgcolor($bgcolor);?> nowrap="nowrap"><font color="<?php echo $font_color;?>"><?php echo $datestamp;?>&nbsp;</font></td>
</tr>



5.1 Modify include/threads.php (to display the actual views):

BEFORE line 56:



$message = next($headers);



INSERT:



$views = $message["views"];



5.2 Modify include/threads.php (to display the $views):

REPLACE line 10:



<table class="PhorumListTable" width="<?php echo $ForumTableWidth; ?>" cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="PhorumListHeader" <?php echo bgcolor($ForumTableHeaderColor); ?>><FONT color="<?php echo $ForumTableHeaderFontColor; ?>">&nbsp;<?php echo $lTopics;?><img src="images/trans.gif" border=0 width=1 height=24 align="absmiddle"></font></td>
<td class="PhorumListHeader" <?php echo bgcolor($ForumTableHeaderColor); ?> width="150" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lAuthor;?>&nbsp;</font></td>
<?php if ( empty($read) && $$phcollapse != 0) { ?>
<td class="PhorumListHeader" align="center" <?php echo bgcolor($ForumTableHeaderColor); ?> width="80" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lReplies;?>&nbsp;</font></td>
<td class="PhorumListHeader" <?php echo bgcolor($ForumTableHeaderColor); ?> width="120" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lLatest;?></font></td>
<?php }else{ ?>
<td class="PhorumListHeader" <?php echo bgcolor($ForumTableHeaderColor); ?> width="120" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lDate;?></font></td>
<?php } ?>
</tr>



replace with:



<table class="PhorumListTable" width="<?php echo $ForumTableWidth; ?>" cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="PhorumListHeader" <?php echo bgcolor($ForumTableHeaderColor); ?>><FONT color="<?php echo $ForumTableHeaderFontColor; ?>">&nbsp;<?php echo $lTopics;?><img src="images/trans.gif" border=0 width=1 height=24 align="absmiddle"></font></td>
<td class="PhorumListHeader" <?php echo bgcolor($ForumTableHeaderColor); ?> width="150" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lAuthor;?>&nbsp;</font></td>
<?php if ( empty($read) && $$phcollapse != 0) { ?>
<td class="PhorumListHeader" align="center" <?php echo bgcolor($ForumTableHeaderColor); ?> width="80" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lReplies;?>&nbsp;</font></td>
<td class="PhorumListHeader" align="center" <?php echo bgcolor($ForumTableHeaderColor); ?> width="80" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>">Views&nbsp;</font></td>
<td class="PhorumListHeader" <?php echo bgcolor($ForumTableHeaderColor); ?> width="120" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lLatest;?></font></td>
<?php }else{ ?>
<td class="PhorumListHeader" align="center" <?php echo bgcolor($ForumTableHeaderColor); ?> width="80" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>">Views&nbsp;</font></td>
<td class="PhorumListHeader" <?php echo bgcolor($ForumTableHeaderColor); ?> width="120" nowrap="nowrap"><FONT color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lDate;?></font></td>
<?php } ?>
</tr>



5.3 Modify include/threads.php (to display the tables for $views):

REPLACE line 116:



echo "</td>\n";
echo ' <td class="PhorumListRow" width="150" '.$color.' nowrap="nowrap"><FONT color="'.$fcolor.'">'.$t_author.'&nbsp;</font></td>'."\n";
if( $$phcollapse != 0 && empty($read) ){
$t_count=$trec["tcount"]-1;
if(!empty($message)) $trec=$threads[$message["thread"]];
echo ' <td class="PhorumListRow" align="center" width="80" '.$color.' nowrap="nowrap"><FONT color="'.$fcolor.'" size=-1>'.$t_count."&nbsp;</font></td>\n";
echo ' <td class="PhorumListRow" width="120" '.$color.' nowrap="nowrap"><FONT color="'.$fcolor.'" size=-1>'.$t_latest."&nbsp;</font></td>\n";
}



WITH:



echo "</td>\n";
echo ' <td class="PhorumListRow" width="150" '.$color.' nowrap="nowrap"><FONT color="'.$fcolor.'">'.$t_author.'&nbsp;</font></td>'."\n";
if( $$phcollapse != 0 && empty($read) ){
$t_count=$trec["tcount"]-1;
if(!empty($message)) $trec=$threads[$message["thread"]];
echo ' <td class="PhorumListRow" align="center" width="80" '.$color.' nowrap="nowrap"><FONT color="'.$fcolor.'" size=-1>'.$t_count."&nbsp;</font></td>\n";
echo ' <td class="PhorumListRow" align="center" width="80" '.$color.' nowrap="nowrap"><FONT color="'.$fcolor.'">'.$views.' </font></td>'."\n";
echo ' <td class="PhorumListRow" width="120" '.$color.' nowrap="nowrap"><FONT color="'.$fcolor.'" size=-1>'.$t_latest."&nbsp;</font></td>\n";
}






6. Now go to MySQL, add a new colume to the data base

Do this with every forum.



ALTER TABLE <forumname> ADD views INT(7) DEFAULT '0';




Good Luck!


You will know what is happening from my forum (traditional chinese)

[info.yingwa.edu.hk]

P.S. Sorry for my bad english... I am only a college students in HongKong!

~Arthur



Post Edited (02-22-03 05:49)
Re: Views hack for 3.4.1-stable
February 04, 2003 01:16AM
nothing...
see [itforum.ez2.us] for the result .

P.S. This is a forum in traditional chinese !



Post Edited (02-22-03 05:50)
No Subject
February 04, 2003 08:55AM
hope can help !



Post Edited (02-05-03 08:44)
Re: [it works] VIEWS HACK for 3.4.1-stable
February 14, 2003 01:35PM
Hi,

I did exactly what it is described here, words for words but any message appears. Even by posting new messages.

Can you help me please, I have Phorum 3.4.1, thank you
--
Jo
Re: [it works] VIEWS HACK for 3.4.1-stable
February 15, 2003 07:49AM
I had the same problem, I copied the php script from Macromedia into the phorum dir, and I had the same problem as you, I found out that madromedia was changing some codes into directory items like F://path to phorum...

so I copied the scripts by Explorer into the phorum dir and everything is running fine now

see [plein.veteranen.info]

mabye this will help you.....


friendly

Rob



Post Edited (02-15-03 06:50)
Re: [it works] VIEWS HACK for 3.4.1-stable
February 15, 2003 09:06AM
Hi Rob,

Your forum works fine, I left you a message ;)

But mine does not function. Could you send your script to me? or the modification which you made compared to original script See my forum here: [www.franceorage.com]
--
Jo
Re: [it works] VIEWS HACK for 3.4.1-stable
February 18, 2003 02:34AM
Please have a look at

[itforum.ez2.us]

It works perfectly !
Re: [it works] VIEWS HACK for 3.4.1-stable
February 18, 2003 06:29AM
Apparement, you have the same problem as me in the collapse mode.
The post of Kobe in bottom display always 0

Jo
i had the same problem...
February 19, 2003 05:30PM
...where no messages at all were listed. I believe I am running 3.4.1. The problems were in the changes to list.php. By subsituting Step 3 with these changes, I did fine.


REPLACE line 176:

if($$phcollapse==0){
$SQL = "Select id,parent,thread,subject,author,datestamp,userid from $ForumTableName WHERE approved='Y' $myflag and thread IN (".$threadstring.") order by modifystamp desc, id asc";
}
else {
$SQL = "Select id,0 as parent,thread,subject,author,datestamp,userid from $ForumTableName WHERE approved='Y' AND parent = 0 $myflag and thread IN (".$threadstring.") order by modifystamp desc";
}

WITH:

if($$phcollapse==0){
$SQL = "Select id,parent,thread,subject,author,datestamp,userid,views from $ForumTableName WHERE approved='Y' $myflag and thread IN (".$threadstring.") order by modifystamp desc, id asc";
}
else {
$SQL = "Select id,0 as parent,thread,subject,author,datestamp,userid,views from $ForumTableName WHERE approved='Y' AND parent = 0 $myflag and thread IN (".$threadstring.") order by modifystamp desc";
}


AND THEN REPLACE line 274:


if($$phcollapse==0){
$SQL = "Select id,parent,thread,subject,author,datestamp,userid,views from $ForumTableName where approved='Y' AND thread<=$max and thread>=$min order by thread desc, id asc";
}
else{
$SQL = "Select id,thread,subject,author,datestamp,userid,views from $ForumTableName where approved='Y' AND thread = id AND thread<=$max AND thread>=$min order by thread desc";
}

WITH:

if($$phcollapse==0){
$SQL = "Select id,parent,thread,subject,author,datestamp,userid,views from $ForumTableName where approved='Y' AND thread<=$max and thread>=$min order by thread desc, id asc";
}
else{
$SQL = "Select id,thread,subject,author,datestamp,userid,views from $ForumTableName where approved='Y' AND thread = id AND thread<=$max AND thread>=$min order by thread desc";
}



Both lines needed to be replaced seperately as the original code is slightly different (even though the changes made are the same).

I migh have old code, but either way this worked for me.

GHXC

(edited to fix line #'s)



Post Edited (02-19-03 16:32)
ATTN: Joakim - Collapse View bug
February 19, 2003 07:08PM
I had the same problem in collapse view. If you look carefully you'll notice ALL the numbering is off (shifted "up") in the collapse view. It has to do with one of the lines in the threads.php file.

In the original Install Instructions substitute the following for step 5.1:



5.1 Modify include/threads.php (to display the actual views):

*BEFORE* line 56:
$message = next($headers);

INSERT:
$views = $message["views"];



If the install is complete, just swap the two lines and you'll be fine.

Hope this helps!

GHXC
Re: ATTN: Joakim - Collapse View bug
February 19, 2003 08:26PM
greg hxc wrote:

> 5.1 Modify include/threads.php (to display the actual views):
>
> *BEFORE* line 56:
> $message = next($headers);
>
> INSERT:
> $views = $message["views"];


Yes, I had included these two lines like this:
$message = next($headers);
$views = $message["views"];

But by modifying them like that:
$views = $message["views"];
$message = next($headers);

All functions well now
thank you very much ;)
--
Jo
Yup yup
February 20, 2003 12:10PM
It was just set to aquire the view numbers after it had already switched to the next record. I was working on modding a new board so it was much easier to spot with only three posts!

GHXC
p
Re: [it works] VIEWS HACK for 3.4.1-stable
March 05, 2003 09:36AM
tnx to you for this hack.
i used your hack + greg hxc's patch and it works fine for me on 3.4.1 :)

Re: [it works] VIEWS HACK for 3.4.1-stable
March 08, 2003 03:34PM
It works nice,
but how can I change the word Views for the German word "Zugriffe"?
Could I change it in the languagefile?

No Subject
March 08, 2003 03:35PM




Post Edited (03-12-03 09:00)
Anonymous User
Re: [it works] VIEWS HACK for 3.4.1-stable
May 08, 2003 02:32PM
Does it work on Phorum 3.4.2?.

I´ve tried to use it on Phorum 3.4.2 and the problem is that now on the Views column i see the Date/Hour of the post and the Date/post column appear empty.

Any help?.

Regards,

Jesus
Re: [it works] VIEWS HACK for 3.4.1-stable
June 15, 2003 09:10AM
Hi,
I am using Phorum 3.4.3a with MySQL and don't have any problem (with greg hxc's fix).
If you want to have a look at the result:
[www.easyexpat.com]

Just a remark. It would be better, when we use the flat view, if all the messages of the thread are updated at the same time when you view them, instead of only the first one...

Cyril
Anonymous User
Re: [it works] VIEWS HACK for 3.4.1-stable
July 04, 2003 09:55PM
It works with 3.4.4 (mysql)
ex: =>[mhscinteractif.free.fr]



Post Edited (07-05-03 11:33)
Works sweet at [happymtb.org] as well.

An addition to the SQL part for the beginner;

Before you run "ALTER TABLE <forumname> ADD views INT(7) DEFAULT '0';" in mysql you have to run "USE <databasename>".
Nickwe
Re: [it works] VIEWS HACK for 3.4.1-stable
January 03, 2004 01:36PM
Works well on my phorum 3.4.4 :-)
[www.astel.be] (French!)

Thanks a lot for the feature!

++
Sorry, you do not have permission to post/reply in this forum.