[geeklog-devel] A lib-common mod to highlight newest comments
Rob Griffiths
robg at macosxhints.com
Wed Oct 6 00:02:47 EDT 2004
GL Team:
Below is my latest tweak to the core GL code ... driven by my desire to
keep up better with the comments on my site.
I prefer to read comments on my site in nested mode, as I find it the
easiest way to follow the conversations. However, what's not easy is
finding the newest comments in nested mode, even with sort by newest.
Obviously, this is because a new reply may be the 10th in line to a
very old comment, which will push it down the sort order.
So I modified lib-common today to support the concept of highlighting
the five newest hints, regardless of sort order. Now when I read
through the comments, the five newest ones will always be visually
called out, making them very easy to spot.
I've detailed my changes below; I would be interested in any help that
might be provided to clean it up (in particular, it strikes me that
building the array the way I do is somewhat redundant, but it's the
only way I could get it to work). I would also be interested in some
way of doing this in lib-custom, but I didn't see an easy solution
there, especially given my lack of programming experience. I know it's
not ideal to be setting style names in the PHP files, but again, I
didn't see an easy way around it. Finally, this has not been tested on
anything other than my local dev box, and then, only (so far) in nested
mode.
Feel free to use, change, delete, etc., as you wish, but I thought I'd
at least share the hack. Details follow...
-rob.
===============================
Changes in lib-common.php (based on 1.3.9sr2); approximate line numbers
provided, though they will be off based on other changes I've made.
Function COM_getComment:
* [Line 2704] Change the first line to pass the array of newest
comments:
function COM_getComment( $A, $mode, $type, $order, $new_comments,
$delete_option = false, $preview = false)
* [line 2807] Add in the routine to check for a match between the
current comment and the array. Insert this just
after the "nice_date" check:
if ( in_array($A['cid'], $new_comments, TRUE)) {
$template->set_var( 'rstyle', "hidate");
} else {
$template->set_var( 'rstyle', "lodate");
}
* [line 2891] Add in the array to the recursive function call:
$retval .= COM_getComment( $A, $mode, $type, $order, $new_comments,
$delete_option );
Now in function COM_userComments...
* [line 2977] Add the routine to build the array of newest comments;
insert this just below the
"$result = DB_query( $q )" line:
$myquery = "select CID from {$_TABLES['comments']} WHERE sid='" .
$sid . "' ORDER BY DATE DESC LIMIT 5";
$r1array = DB_query($myquery);
$nrows = db_NumRows($r1array);
for( $i = 0; $i < $nrows; $i++ ) {
$r1r = DB_fetchArray($r1array);
$new_comments[] = $r1r['CID'];
}
* [line 2991] Add in the array of newest comments to the list of
passed variables:
$thecomments .= COM_getComment( $A, $mode, $type, $order,
$new_comments,
$delete_option);
Now just create two classes, lodate and hidate, in your CSS, and place
a call to the new variable 'rstyle' in the comment.thtml file. I've
chosen to highlight the date, but you could obviously use the style to
do whatever you wish with the newest comments. Here's how my date row
looks:
<tr><td colspan="2"><span class="{rstyle}">{date}</span></td></tr>
-rob.
More information about the geeklog-devel
mailing list