Firefox PHP

Views Hack v2 Finished, Tested, and working

Posted by Vulpes 
im getting this error after following your instructions:

Unknown column 'userid' in 'field list'
Insert Into bbt (id, author, userid, email, datestamp, subject, host, thread, parent, email_reply, approved, msgid) values ('1', 'Peter', '2', 'staff@aussiesexposed.com', '2002-04-21 14:17:36', 'another Aussie Celeb group', 'adlax1-135.dialup.optusnet.com.au', '1', '0', '', 'Y', '')Unknown column 'modifystamp' in 'field list'
UPDATE bbt SET modifystamp = 1019416656 WHERE thread = 1
Warning: Cannot add header information - headers already sent by (output started at /home/www/aussieexposed/forums/include/post_functions.php:382) in /home/www/aussieexposed/forums/post.php on line 198

Warning: Cannot add header information - headers already sent by (output started at /home/www/aussieexposed/forums/include/post_functions.php:382) in /home/www/aussieexposed/forums/post.php on line 264



can anyone help me please?
3.3.2.a
April 25, 2002 06:05PM
I cant get it to work in 3.3.2a I think its to do with the following modification

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

replace (around line 176):

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

with:

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

But i have
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";
}

and making the above changes destroys it

any one got it working on 3.3.2a can send their source
Re: 3.3.2.a
May 18, 2002 07:16AM
Yeah I could do with the source to get it working in 3.3.2a aswell.

Can I someone post what to do step by step for a beginner in PHP and mySQL.

I have the Phorum 3.3.2c

Thanks
I tried adding a hack to version 3.3.2
this is what I get:

Unknown column 'userid' in 'field list'
Insert Into test (id, author, userid, email, datestamp, subject, host, thread, parent, email_reply, approved, msgid) values ('1', 'Test', '0', '', '2002-05-30 23:26:10', 'test', 'my_ip_here', '1', '0', '', 'Y', '<5cc3c7a87fc36be25f5bb4109c378c21.>')Unknown column 'modifystamp' in 'field list'
UPDATE test SET modifystamp = 1022819170 WHERE thread = 1
Warning: Cannot add header information - headers already sent by (output started at /home/sites/site162/web/forum/include/post_functions.php:382) in /home/sites/site162/web/forum/post.php on line 198

Warning: Cannot add header information - headers already sent by (output started at /home/sites/site162/web/forum/include/post_functions.php:382) in /home/sites/site162/web/forum/post.php on line 267
quiries changed a bit, the code isnt accurate anymore

Are there instructions anywhere how to implement the views hack on 3.3.2?
Re: Views Hack v2 Finished, Tested, and working
August 25, 2002 10:37AM
I did it with 3.3.2c, just a little amention and then it works now!(tips:don't just copy & paste the code, only change the part has something to do with 'views', that is all!).:-)
Re: Views Hack v2 Finished, Tested, and working
September 01, 2002 11:59PM
Please help to make this work with version 3.4. Thanks in advance
Re: Views Hack v2 Finished, Tested, and working
September 05, 2002 12:16AM
Hi:

I think I made the hack to work with 3.4, the current development version.

You can try it, see if you have any issues.

Regards

PS: don't replay to the email, it's a fake!
Re: Views Hack v2 Finished, Tested, and working
September 05, 2002 12:20AM
why I don't see the attachment?

Try againa and post it here.

---------------------


#######################################################
# #
# VIEWS HACK 2.0a #
# MySQL only, but easilly adapted #
# #
########################################################

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

It was tested and worked using Phorum 3.4_dev with PHP 4.2.2 and MySQL 3.23.32

All line numbers for v3.4. 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 this line (Line 176):

$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 char(50) 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,
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 this :

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 char(50) 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,
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)
)";

which is just adding a line
views INT(7) DEFAULT '0',


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

replace (line 270):

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. Modify include/multi-threads.php (to display the actual views):

after this line (should be at the very beginning of the file):

$thread_total="";

insert:

$views = $topic["views"];


You can now use echo($views); to display the number of views, you can choose where you want to insert the views count.

To use it do this:

Find in the very buttom:

<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; ?>">&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 width=150><font color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lAuthor;?>&nbsp;</font></td>
<td class="PhorumListHeader"<?php echo bgcolor($ForumTableHeaderColor);?> nowrap width=150><font color="<?php echo $ForumTableHeaderFontColor; ?>"><?php echo $lDate;?></font></td>
</tr>

This is top Header where it says Subject, Author, Date.
to add Views colum add:

<TD class="PhorumListHeader" <?PHP echo bgcolor($ForumTableHeaderColor);?> NOWRAP WIDTH=70><center><FONT COLOR="<?php echo $ForumTableHeaderFontColor; ?>">Views &nbsp;</FONT></center></TD>

You can chage it however you want

Now to add numbers find it somewhere in the middle:

<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;?>&nbsp;</font></td>
</tr>
it's actual variables
add viewes colum:

<TD class="PhorumListRow" <?PHP echo bgcolor($bgcolor);?> nowrap><FONT COLOR="<?php echo $font_color;?>">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $views;?></FONT></TD>

You can chage it however you want

5. Modify include/threads.php:

after this line (should be around line 58 (you get this right)):

$t_author=chop($message["author"]);

insert:

$views = $message["views"];

You can now use echo($views); to display the number of views, you can choose where you want to insert the views count.

To use it do this:

Find (should be around the bottom)


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";
}

it's actual variables
add viewes colum :

echo "</td>\n";
echo ' <td class="PhorumListRow" width="150" '.$color.' nowrap="nowrap"><FONT color="'.$fcolor.'">'.$t_author.'&nbsp;'</font></td>'."\n";
echo ' <td class="PhorumListRow" width="70" '.$color.' nowrap><FONT color="'.$fcolor.'">'.$views.'&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";
}


You can chage it however you want
Done with hack part...

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

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

Do this with every forum.

My hosting has Phorum 3.4 current dev with MySQL 3.23.32 and php4.2.2

Good Luck


---------------------------------------------------------------------------------------------
Re: Views Hack v2 Finished, Tested, and working
September 05, 2002 12:40AM
You can come here try it out. [You post might be deleted later if there is no meaningful contents]

forums

Just open the site.

Still need to figure out a lot of things.

Regards
Re: Views Hack v2 Finished, Tested, and working
September 27, 2002 06:23AM
I got it working with phorum 3.4dev, php 4.0.1 and mysql 3.23.42 in bulgarian.
It needed some fime-tuning.
Re: Views Hack v2 Finished, Tested, and working
October 03, 2002 04:06AM
HI,
can I download the full phorum included the view hack?

Im not a programmer, so its impossible for me to work with things like mysql or list.php....:-/

thanx for helping me getting a great phorum works on my site......hopefully

so long
Torsten
I´m trying to use it on dev3.4
October 15, 2002 10:28AM

Hi, i´ve instaled this hack on 3.4 Dev...

Well i´m not an expert in php (i´m a rookie yet :-)), and what happened is that on the Forum List (list.php) i get only the Views tittle, and i get no views numbers...
When i go to a message, (read.php) i get everything ok in the treath...

I dont know whats the problem... i did everything like Vulpes said, probably is because i´m using 3.4 dev ... But its very strange that works on read.php and dont works on list.php, when both files include threath.php and multi-threath.php...

Does anybody can help me with this... :-)))

I´m also thinking in create some sort of ranking of the most viewed posts of the day/week/month/all times....

best regards, and thanks in advance for this great team !!!

Same problem
October 17, 2002 10:57AM
did you solved it ?

i only get views on multi-threat when i use read.php ... cant get it to work on list.php ... :-(

can you help me with 3,4dev ?
October 17, 2002 11:37AM
i read everypost here, and i still cant get it work...

I see the views numbers on read.php but cant see them on list.php

can you help me please ?

HEHEH... ok i got it...
October 18, 2002 08:43AM
Finally i got it....

It was a simple little thing in the list.php code.... i forgot tu put the sql request for views and i was doing on the wrong line...

A little update request ... :-)
October 18, 2002 08:20PM

I´ve implemented the hack.... thats really cool .... :-)

Know i was thinking in doing a little update, to sort the Forum list.php from the most viewed postes... (no problem with that)....
But how can i sort it from the most viewed messages of the DAY ?

I dont know much about php... if anybody could teach me how to make it... i´d be greatful...i got this on list.php :

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 views 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 views desc";
}

How to sort by views, and with a time limite ?


best regards

Joe
Re: Views Hack v2 Finished, Tested, and working
October 23, 2002 02:25PM
Can anyone help with instructions on how to add views hack to 3.3.2?
Thanks!
Sorry, you do not have permission to post/reply in this forum.