1 (edited by khalido 2005-05-12 03:46)

Topic: Last Subject headers in Index

When I opened the forum for the first time, the first thing that
struck me, was the deserted look. It seemed as if a tumble
weed was just going to roll across my screen, any moment...

So I suggest that like other boards, the subject of the last post
in a section be visible in the main forum view (Index), so when
someone logs in to this forum, s/he can look at the subject header
and then decide whether they wish to participate.
Right now,
you have to get into each section to look at the headers. Most
people will likely take a pass on that ---and that, would be a
shame.

Also, the subject headers of posts in the various sections will
add some life and vitality to the anemic look, Index is sporting
currently.

There seems to be a couple of mods for this, and a few other discussions, but I couldn't see a specific way to hack the code for 1.2.5, or a plugin/mod which would do so. It would be great if this was an option somewhere.

Re: Last Subject headers in Index

I added it to my 1.2.5 board. I just don't remember the exact changes I made. Read thru this thread http://punbb.org/forums/viewtopic.php?id=6932 and you should be able to make it work.

Re: Last Subject headers in Index

Thanks, but this solution doesn't work properly. Empty forums don't show up in the list.

Re: Last Subject headers in Index

Mmm, I thinkthe easiest way might be to add a column to the forums table "last_subject" (should be a VARCHAR(255))

Then
FIND

//
// Update posts, topics, last_post, last_post_id and last_poster for a forum (redirect topics are not included)
//
function update_forum($forum_id)
{
    global $db;

    $result = $db->query('SELECT COUNT(id), SUM(num_replies) FROM '.$db->prefix.'topics WHERE moved_to IS NULL AND forum_id='.$forum_id) or error('Unable to fetch forum topic count', __FILE__, __LINE__, $db->error());
    list($num_topics, $num_posts) = $db->fetch_row($result);

    $num_posts = $num_posts + $num_topics;        // $num_posts is only the sum of all replies (we have to add the topic posts)

    $result = $db->query('SELECT last_post, last_post_id, last_poster FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.' AND moved_to IS NULL ORDER BY last_post DESC LIMIT 1') or error('Unable to fetch last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))        // There are topics in the forum
    {
        list($last_post, $last_post_id, $last_poster) = $db->fetch_row($result);

        $db->query('UPDATE '.$db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', last_post='.$last_post.', last_post_id='.$last_post_id.', last_poster=\''.$db->escape($last_poster).'\' WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
    }
    else    // There are no topics
        $db->query('UPDATE '.$db->prefix.'forums SET num_topics=0, num_posts=0, last_post=NULL, last_post_id=NULL, last_poster=NULL WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
}

REPLACE WITH

//
// Update posts, topics, last_post, last_post_id, last_subject and last_poster for a forum (redirect topics are not included)
//
function update_forum($forum_id)
{
    global $db;

    $result = $db->query('SELECT COUNT(id), SUM(num_replies) FROM '.$db->prefix.'topics WHERE moved_to IS NULL AND forum_id='.$forum_id) or error('Unable to fetch forum topic count', __FILE__, __LINE__, $db->error());
    list($num_topics, $num_posts) = $db->fetch_row($result);

    $num_posts = $num_posts + $num_topics;        // $num_posts is only the sum of all replies (we have to add the topic posts)

    $result = $db->query('SELECT last_post, last_post_id, last_poster, subject FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.' AND moved_to IS NULL ORDER BY last_post DESC LIMIT 1') or error('Unable to fetch last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result))        // There are topics in the forum
    {
        list($last_post, $last_post_id, $last_poster, $last_subject) = $db->fetch_row($result);

        $db->query('UPDATE '.$db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', last_post='.$last_post.', last_post_id='.$last_post_id.', last_poster=\''.$db->escape($last_poster).'\', last_subject = \''.$db->escape($last_subject).'\' WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
    }
    else    // There are no topics
        $db->query('UPDATE '.$db->prefix.'forums SET num_topics=0, num_posts=0, last_post=NULL, last_post_id=NULL, last_poster=NULL WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
}

And then edit index.php like so:
FIND

$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

REPLACE WITH

$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster f.last_subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

FIND

if ($cur_forum['last_post'] != '')
        $last_post = '<a href="viewtopic.php?pid='.$cur_forum['last_post_id'].'#p'.$cur_forum['last_post_id'].'">'.format_time($cur_forum['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_forum['last_poster']).'</span>';

REPLACE WITH

if ($cur_forum['last_post'] != '')
        $last_post = '<a href="viewtopic.php?pid='.$cur_forum['last_post_id'].'#p'.$cur_forum['last_post_id'].'">'.$cur_forum['last_subject'].'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_forum['last_poster']).' at '.format_time($cur_forum['last_post']).'</span>';

Completely untested, tell me if it works right smile

Re: Last Subject headers in Index

someone should add it to the punres wiki wink

Re: Last Subject headers in Index

I agree.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Last Subject headers in Index

Any change of this being part of the official program? Or at least a easy to implement mod or plugin?

Re: Last Subject headers in Index

It is an easy mod tongue