PunBB Resource

Your ultimate PunBB resource!

Keywords:

    (Extended)

You are not logged in.

#1 2007-07-09 19:00:56

vochomaster
Member
Registered: 2007-07-09
Posts: 64
Website

Recent updated topics

Hi, I'm new on PunBB and I'm working on my computer to test the board, features, mods, etc. before to try it on a real site.

I was looking for a Latest active topics mod and I've only found it on extern.php, but I have miniportal and the function should be internal instead of external, so I've copied the code from extern.php and added a new function to do this, now I can have Recent updated topics on Miniportal's pages or Forum index page (you can see this feature in a lot of BB out there, so this is my first try to make a mod.

Recent Updated Topics v1.0 beta

Code:

##
##
##        Mod title:  Recent updated topics
##
##      Mod version:  1.0 beta
##   Works on PunBB:  1.2.15 (tested only on latest release)
##     Release date:  2007-07-09
##           Author:  Vochomaster (sms@elbajio.com)
##  Original Author:  Based on an extern.php code (Latest active topics)
##
##      Description:  Display recent updated topics on forum index
##
##   Affected files:  index.php (or forum.php if you have miniportal installed)
##                    include/functions.php
##                    lang/English/common.php
##
##       Affects DB:  No
##
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##            NOTES:  You can easily add recent updated topics on index.php if you
##                    have Miniportal installed, just do all steps and later edit
##                    your index.php and place the function showRecent(10) anywhere
##                    on your main page, where 10 is the number of desired topics to be
##                    displayed; the default value is 5.

#
#---------[ 1. OPEN ]---------------------------------------------------------
#

index.php

#
#---------[ 2. FIND ]---------------------------------------------------------
#
# we will add the recent updated topics block at the top of the page
#

require PUN_ROOT.'header.php';

#
#---------[ 3. AFTER, ADD ]---------------------------------------------------
#
# Note that you can alter the number of topics to be displayed at your own criteria
# or leave blank this parameter to show de default value (5)
#

// Recent updated topics
showRecent(5);

#
#---------[ 4. OPEN ]---------------------------------------------------------
#

include/functions.php

#
#---------[ 5. FIND ]---------------------------------------------------------
#
# we will add the function at the end of the file
#

function dump()
{
    echo '<pre>';

    $num_args = func_num_args();

    for ($i = 0; $i < $num_args; ++$i)
    {
        print_r(func_get_arg($i));
        echo "\n\n";
    }

    echo '</pre>';
    exit;
}

#
#---------[ 6. AFTER, ADD ]---------------------------------------------------
#

function showRecent($show=5) {
    global $lang_common, $db, $pun_config, $db_prefix;

    $order_by = 't.last_post';
    $forum_sql = '';

    $show = isset($_GET['show']) ? intval($_GET['show']) : 15;
    if ($show < 1 || $show > 50) $show = 5;

    // Fetch $show topics
    $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT '.$show) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());


    echo '<div class="block"><h2><span>' . $lang_common['Recent updated'] . '</span></h2>';
    echo '<div class="box"><div class="inbox">';
    while ($cur_topic = $db->fetch_assoc($result)) {
        if ($pun_config['o_censoring'] == '1')
            $cur_topic['subject'] = censor_words($cur_topic['subject']);

        $subject_truncated = pun_htmlspecialchars($cur_topic['subject']);

        echo '<li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&amp;action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.$subject_truncated.'</a> - <em>' . $lang_common['Recent posted by'] . ': <b>'.$cur_topic['poster'].'</b> ' . date($lang_common['Recent date'], $cur_topic['posted']) . $lang_common['Recent at'] . date('h:i A', $cur_topic['posted']).'</em></li>'."\n";
    }
    echo '</div></div></div>';
    return;
}

#
#---------[ 7. OPEN ]---------------------------------------------------------
#

lang/English/common.php

#
#---------[ 8. FIND ]---------------------------------------------------------
#

//For extern.php RSS feed

#
#---------[ 9. BEFORE, ADD ]--------------------------------------------------
#

// For recent updated topics
'Recent updated'        =>    'Recent updated topics',    // Recent updated topics title
'Recent posted by'        =>    'Posted by:',            // Posted by (Author will be appended)
'Recent date'            =>    'd-m/Y',            // Desired posted date PHP format
'Recent at'            =>    ' at ',                // at (hour will be appended)

#
#---------[ 10. SAVE/UPLOAD ]-------------------------------------------------
#

Since I've got this code from extern.php I guess my function will only display topics from forums where user has read access, so please give it a try and tell me if it works fine or need some adjustments.

Thanks.


Sorry 4 my bad english, hope you can understand me wink

Offline

 

#2 2007-07-14 02:35:45

crusader
Member
From: Canada
Registered: 2006-10-26
Posts: 219
Website

Re: Recent updated topics

I've tried this and it works perfectly. I just modified it a bit to truncate the amount of text displayed and I am also using it as a side block.

Offline

 

#3 2007-07-14 15:52:20

vochomaster
Member
Registered: 2007-07-09
Posts: 64
Website

Re: Recent updated topics

I'm glad to hear that my first little mod works, yes I know it's a piece of cake, but not so bad to be the first smile

By the way, I removed the truncate stuff from the original code in extern.php to get the complete subject on pages, maybe it'll be good to add a parameter to the function, in order to select how many characters to show:

0=complete subject
number=truncate subject at desired number of characters

Easy to recode, maybe monday morning I'll post it again with this little change and maybe add more parameters to select what info display (Post author, date and time) if you want to ommit any of both.


Sorry 4 my bad english, hope you can understand me wink

Offline

 

#4 2007-07-14 22:37:07

crusader
Member
From: Canada
Registered: 2006-10-26
Posts: 219
Website

Re: Recent updated topics

Well, this is my modified version below. It is saved in the include/user/ folder as recenttopics.inc.php and is called from my main.tpl file

<pun_include "recenttopics.inc.php">

Code:

<?php

showRecent(10); // Set amount of posts to be displayed here

function showRecent($show=5) {
    global $lang_common, $db, $pun_config, $db_prefix;

    $order_by = 't.last_post';
    $forum_sql = '';

//$show = isset($_GET['show']) ? intval($_GET['show']) : 5;
        //if ($show < 1 || $show > 50) $show = 5;

$trunc_len = 20; // Set amount of text to be displayed in subject.

// Fetch $show topics
    $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT '.$show) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());


    echo '<div class="block"><h2><span>Recent 10 Posts</span></h2>';
    echo '<div class="box"><div class="inbox"><dl>';
            while ($cur_topic = $db->fetch_assoc($result)) {
        if ($pun_config['o_censoring'] == '1')
     $cur_topic['subject'] = censor_words($cur_topic['subject']);
    $subject_truncated = pun_htmlspecialchars($cur_topic['subject']);
 



    echo '<dd><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&amp;action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.substr($cur_topic['subject'], 0, $trunc_len).'</a>...</dd>'."\n";
    }
    echo '</dl></div></div></div>';
    return;
}

Last edited by crusader (2007-07-16 00:07:57)

Offline

 

#5 2007-07-15 19:24:08

vochomaster
Member
Registered: 2007-07-09
Posts: 64
Website

Re: Recent updated topics

Crusader, that's really good to insert recent topics on a side box on a single step, well done!


Sorry 4 my bad english, hope you can understand me wink

Offline

 

#6 2007-08-19 14:15:15

doki
Member
Registered: 2007-04-30
Posts: 225

Re: Recent updated topics

hi crusader,

I have this error using your code above.

Code:

Fatal error: Cannot redeclare showrecent() (previously declared in /home/xxx/public_html/include/user/topics_latest.php:5) in /home/xxx/public_html/include/user/topics_latest.php on line 34

Offline

 

#7 2007-08-19 14:43:58

doki
Member
Registered: 2007-04-30
Posts: 225

Re: Recent updated topics

I solve it. I've modified it to work on my site...

Code:

<?php
$result = $db->query('SELECT subject, id FROM '.$db_prefix.'topics ORDER BY last_post DESC LIMIT 8') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());

$trunc_len = 34; // Set amount of text to be displayed in subject.

while($cur_topic = $db->fetch_assoc($result))

 {
        if ($pun_config['o_censoring'] == '1')
     $cur_topic['subject'] = censor_words($cur_topic['subject']);
    $subject_truncated = pun_htmlspecialchars($cur_topic['subject']);
     echo '<li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].' title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.substr($cur_topic['subject'], 0, $trunc_len).'...'.'</a></li>'."\n";
    }
?>

Last edited by doki (2007-08-19 14:44:23)

Offline

 

#8 2009-01-31 13:29:43

gorsan
Member
Registered: 2008-10-31
Posts: 14

Re: Recent updated topics

this makes heavy load on server if you have many topics

Offline

 

#9 2009-07-24 14:37:39

warrior
New member
Registered: 2009-07-24
Posts: 1

Re: Recent updated topics

yeap, really heavy load on server

Offline

 

Board footer

Based on PunBB
© Copyright 2002–2005 Rickard Andersson

© Copyright 2004–2006 Kristoffer Jansson

User contributed files are property of their respective owners.