Firefox PHP

Hack to list N latest unread by you

Posted by eivind sivertsen 
Hi! I wanted a list of the N latest messages not already read by me and took the liberty of starting with Timothy Ha's nice hack that lists the 10 latest topics. I extended the hack to work with the cookie gallery in phorum so that if it finds the phorum cookies (for this phorum) on your computer, it will be able to list only those you haven't read already. Otherwise, simply the N latest are shown (you can include N in the URL, if not it is hardcoded to N=10).

Since this was OK with Timothy, I post it both as a new hack and under the thread for Timothy's original hack.
Code below and in attached textfile. To be included at the same spot that mr. Ha mentions; in "list.php" just before the first mention of <table width=\"<?PHP echo $ForumTableWidth; ?>\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\"> .

Best regards,



// ------ GETTING LAST N POSTS IN NICE TABLE -- HACK 1403 EAS ---------------

global $UseCookies, $haveread, $use_haveread, $old_message;
global $N;
(IsSet($N))? $N = $N : $N = 10;

// --Using cookies--
if(IsSet($old_message) && $old_message > 0){
if($use_haveread && count($haveread) > 0){
$hread = array();
foreach($haveread as $i => $v)
array_push($hread, $i);
$hread = implode(", ", $hread);
$add = " AND ( (id>$old_message) AND (id NOT IN ($hread)) ) ";
$add = " AND id>$old_message ";
$latest_txt = "Latest postings unread by you, regardless of topic";
}else{// --old_message not set--
$add = "";
$latest_txt = "Latest $N postings, regardless of topic";
// --No cookie-using--
$add = "";
$latest_txt = "Latest $N postings, regardless of topic";
}// END cookie galore

$easi_query = "Select id,thread,subject,author,datestamp from $ForumTableName where approved='Y'
$add order by datestamp desc limit $N";
$easi_result = new query($DB, $easi_query);
$newtopics = "\n<!-- START HACK TABLE -- EAS 140301 -->
<table align=left width=\"$ForumTableWidth\" border=0 cellpadding=1 cellspacing=0>
<tr><td colspan=3>
<font face=helvetica color=gray size=-2>$latest_txt</font>\n</td></tr>
<tr bgcolor=\"#999999\">
<td><font color=white>Date</font></td>
<td><font color=white>Author</font></td>
<td><font color=white>Subject</font></td></tr>\n";
$ctr = 0;
$row = $easi_result->getrow();
$id = $row["id"];
$thread = $row["thread"];
$date = date_format($row["datestamp"]);
$author = $row["author"];
$subject = $row["subject"];
$new = "";
($ctr % 2 == 0)? $color = "#ffffff" : $color = "#eeeeee";

$newtopics .= "<TR bgcolor=\"$color\"><TD>$date</TD><TD>$author</TD>
<TD><a href=\"read.php?f=$f&i=$id&t=$thread\">$subject</a>$new</TD></TR>\n";
$row = $easi_result->getrow();
}// end while

$newtopics .= "</table></center><BR clear=all><BR>\n";
if($ctr > 0) print $newtopics;

echo "<BR><center><table width=\"$ForumTableWidth\" cellspacing=\"0\"
cellpadding=\"3\" border=\"0\">\n";

// ---------------- END HACK 1403 EAS -------------------------
open | download - last_n_posts_in_table.txt (2.3 KB)
Another fantastic addon! I worked like a charm! Perhaps the colors should not be hardcoded though...?

- Ståle
Eivind :-)
Re: Hack to list N latest unread by you
May 20, 2001 04:19PM
Might as well alter it to use the phorum's own colours. Just insert the variable names instead of the hardcodes... ,-)

Re: Hack to list N latest unread by you
June 08, 2001 03:25PM
where i can see the sample??
Re: A small bug
August 16, 2001 05:11PM
Hello Eivind,

there is a small bug in your script.

In your script you use $id but it is also used in the script multi-threads.php which follows (without setting this variable). So the last value from your script is used.

This cause that on of the topics is printed in bold without his link.

Change the name of $id for example ti $id1 (two times) and it will wirk very well.

Oliver Riesen
Re: A small bug
August 21, 2001 04:48AM
Thank you so much, Oliver, for pointing this out. I have been wondering why this happened; but never read the code close enough to suspect this was the case. I merely read it superficially, concluded that the logics/"mechanics" looked allright, and kept on wondering what was wrong.

End of this mystery. Thank you! :-D

August 23, 2001 08:47AM
This is the same hack, but with the Oliver's bugfix!
open | download - last_n_posts_in_table.txt (2.3 KB)
October 12, 2001 05:58PM
Sorry, I only get the following warnings/errors:

Warning: GLOBAL variable declaration meaningless in main() scope
Fatal error: Call to unsupported or undefined function foreach()

Any idea what I am doing wrong?

October 16, 2001 04:43AM
Well, for one you could be using an old version of PHP. The hack includes a 'foreach' construct, not implemented in PHP3 but in PHP4. => You must run PHP4 to utilize the hack...

even if I look at all the messages in a forum, this hack still shows me the last 10...the only way I can make it dissapear is to click "mark all read"... do you have any idea what I could be doing wrong? It looks like it is "almost" working...seems like there is something wrong with the way it handles cookies...

thanks for any thoughts...

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