Topic: Active Topics list...

I just upgraded from 1.2 but am missing some stuff that my users really really miss so I am trying to recreate them piece by piece. But everything's changed so much none of my old hacks work.

1.2 had a Mod called "Active Topics Mod" where I could drop in an Include call into say the Index.php page and the ViewTopic.php pages and display a list of say the last 20 replied to topics. My users used this more than the actual forum lists themselves. (Yeah I know about the links at the top, they're not the same) So I have been trying to recreate it. Thinking it should be easy. Just call the database and ask for 20 items sorted by last update time and viola...

But I just can't get the syntax right.

Can someone help with some starter code? Remember that it needs to be able to be placed in pages that are already established. Namely the Index and Topic pages.

I already have the "table" set up, I just need to drop the data into it.

Re: Active Topics list...

Nobody? I can't get the hang of the new structure.

3

Re: Active Topics list...

I think you and me want the same thing. I already made a extension request on wiki

http://punbb.informer.com/forums/topic/ … irst-page/

Re: Active Topics list...

Here is query for getting last 20 posts. It is used Query Builder.

$query = array(
                'SELECT'    => 'p.id AS pid, p.poster AS pposter, p.posted AS pposted, p.poster_id, p.message, p.hide_smilies, t.id AS tid, t.poster, t.subject, t.first_post_id, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_replies, t.forum_id, f.forum_name',
                'FROM'        => 'posts AS p',
                'JOINS'        => array(
                    array(
                        'INNER JOIN'    => 'topics AS t',
                        'ON'            => 't.id=p.topic_id'
                    ),
                    array(
                        'INNER JOIN'    => 'forums AS f',
                        'ON'            => 'f.id=t.forum_id'
                    ),
                    array(
                        'LEFT JOIN'        => 'forum_perms AS fp',
                        'ON'            => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
                    )
                ),
                'ORDER BY'    => 'pposted DESC',
                'LIMIT'        => '20'
            );

This code should be added after including the "include/common.php" file.

Re: Active Topics list...

Thanks. But can you help me figure out how to get that into the correct arrays?

Basically so I can go through with the For...Next loop and put the values into the right rows.

($hook = get_hook('vf_qr_get_topics')) ? eval($hook) : null;
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);

I have this so far, but how do I rip the stuff out of the Result array and place it into all the appropriate arrays like the Topic title, number of replies and views, time posted and user and etc.?

Thanks

Re: Active Topics list...

If it helps any, here is a truncated version of the old Active Topics Mod file I used...

<?php
    $active_topic_limit = 20; // change this to the number of active topics you want to display.
    $result = $db->query('SELECT t.*, f.forum_name 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='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL ORDER BY t.last_post DESC  LIMIT '.$active_topic_limit) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
?>
<table cellspacing="0" cellpadding="0" border="0">
<?php
// If there are topics in this forum.
if ($db->num_rows($result))
{
  $new_border = '';
  while ($cur_topic_act = $db->fetch_assoc($result))
  {
    $oldtopicisnew = $topicisnew;
    $item_status = '';

    if ($pun_config['o_censoring'] == '1')
      $cur_topic_act['subject'] = censor_words($cur_topic_act['subject']);

    //$last_post = ''.pun_htmlspecialchars($cur_topic_act['subject']).'</a>';
    $last_post = '<a href="viewtopic.php?id='.$cur_topic_act['id'].'&amp;action=new" class="atthreadname">'.pun_htmlspecialchars($cur_topic_act['subject']).'</a>';

    if (!$pun_user['is_guest'] && $cur_topic_act['last_post'] > $pun_user['last_visit'])
    {
      $show_icon = '<div class="icon inew"><div class="nosize"><!-- --> There are new posts</div></div>';
    } else {
      $show_icon = '<div class="icon"><div class="nosize"><!-- --> There are new posts</div></div>';
    }
?>
     <tr<?php if ($item_status != '') echo ' class="'.$item_status.'"'; ?>>
        <td class="tcl<?php echo $div_status; ?>"<?php echo $new_border; ?>>
            <div class="intd">
                <?php echo $show_icon; ?>
                <div class="tclcon">
                    <?php echo $last_post; ?> by <?php echo $posterwho; ?>
                </div>
            </div>
        </td>
        <td class="tc2"<?php echo $new_border; ?>><?php echo $cur_topic_act['num_replies']; ?></td>
        <td class="tc3"<?php echo $new_border; ?>><?php echo $cur_topic_act['num_views']; ?></td>
        <td class="tcr"<?php echo $new_border; ?>><?php echo '<a href="viewtopic.php?pid='.$cur_topic_act['last_post_id'].'#p'.$cur_topic_act['last_post_id'].'">'.format_time($cur_topic_act['last_post'],true).'</a>'; ?> by <?php echo $lastposterwho; ?></td>
    </tr>
<?php
  }
}
?>
</table>

As you see, 1.3 has changed everything drastically I can't even begin to figure out how to grab stuff from the SQL result query.

Re: Active Topics list...

I'm interested in this as well. My forum is intended to be an off-shoot of another website that heavily relies on the "active topics" list (which only shows the last 5 topics with a post), and this plus a "topic subject in last post on index page" are the two extensions I'm really banking on to get this thing working nice.

Only problem is, the code is so cryptic and complicated that my procedural understanding of PHP is nowheres near able to figure that complicated mess out. All I can really do is wait. sad

Re: Active Topics list...

This script will show last 20 posts. It will be correctly work after including file "include/common.php", also for correct displaying it should be inside of div with id "brd-main".

<?php
    $topics_count = 20;
    $query_active_topics= array(
        'SELECT'    => 't.id AS tid, t.poster, t.subject, t.posted AS has_posted, t.last_post, t.last_post_id, t.num_replies, t.num_views, t.closed, t.sticky, t.forum_id',
        'FROM'        => 'topics AS t',
        'JOINS'        => array(
            array(
                'INNER JOIN'    => 'forums AS f',
                'ON'            => 'f.id=t.forum_id'
            ),
            array(
                'LEFT JOIN'     => 'forum_perms AS fp',
                'ON'            => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
            )
        ),
        'ORDER BY'    => 't.last_post',
        'LIMIT' => $topics_count
    );
    $result_active = $forum_db->query_build($query_active_topics) or error(__FILE__, __LINE__);
    
    if ($forum_db->num_rows($result_active) == 0)
    {

    ?>
        <div class="main-content main-message">
            <p>There is no message.</p>
        </div>
    <?php
        
    } 
    else
    {
        require_once FORUM_ROOT.'lang/'.$forum_user['language'].'/forum.php';

    ?>    
        <div class="main-subhead">
                <p class="item-summary">
                    <span>
                        <strong class="subject-title"><?php echo $lang_index['Topics']; ?></strong>
                        <strong class="info-replies"><?php echo $lang_forum['Replies']; ?></strong>
                        <strong class="info-views"><?php echo $lang_forum['Views']; ?></strong>
                    </span>
                </p>                                                
            </div>
        <div class="main-content main-forum">                    
        <?php

            $item_num = 1;
            while ($cur_set = $forum_db->fetch_assoc($result_active))
            {
               // Start from scratch
                $item_subject = $item_body = $item_status = $item_nav = $item_title = array();
                $item_indicator = ''; 
                
                if (!$forum_user['is_guest'] && $forum_config['o_show_dot'] == '1' && $cur_set['has_posted'] > 0)
                {
                    $item_title['posted'] = '<span class="posted-mark">'.$lang_forum['You posted indicator'].'</span>';
                    $item_status['posted'] = 'posted';
                }

                $item_title['link'] = '<a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.forum_htmlencode($cur_set['subject']).'</a>';

                if (!empty($item_nav))
                    $item_title['nav'] = '<span class="item-nav">'.sprintf($lang_forum['Topic navigation'], implode('&#160;&#160;', $item_nav)).'</span>';

                $item_body['subject']['title'] = '<h3 class="hn"><span class="item-num">'.forum_number_format(++$item_num).'</span> '.implode(' ', $item_title).'</h3>';
                if ($cur_set['sticky'] == '1')
                {
                    $item_subject_status['sticky'] = $lang_forum['Sticky'];
                    $item_status['sticky'] = 'sticky';
                }
    
                if ($cur_set['closed'] != '0')
                {
                    $item_subject_status['closed'] = $lang_forum['Closed'];
                    $item_status['closed'] = 'closed';
                }
    
                if (!empty($item_subject_status))
                    $item_subject['status'] = '<span class="item-status">'.sprintf($lang_forum['Item status'], implode(' ', $item_subject_status)).'</span>';
    
                $item_subject['starter'] = '<span class="item-starter">'.sprintf($lang_forum['Topic starter'], '<cite>'.forum_htmlencode($cur_set['poster']).'</cite>').'</span>';
    
                $item_body['subject']['desc'] = implode(' ', $item_subject);
                if (empty($item_status))
                    $item_status['normal'] = 'normal';

                $item_style = (($item_num % 2 != 0) ? ' odd' : ' even').(($item_num == 1) ? ' main-first-item' : '').((!empty($item_status)) ? ' '.implode(' ', $item_status) : '');

                $item_body['info']['replies'] = '<li class="info-replies"><strong>'.forum_number_format($cur_set['num_replies']).'</strong> <span class="label">'.(($cur_set['num_replies'] == 1) ? $lang_forum['Reply'] : $lang_forum['Replies']).'</span></li>';
                $item_body['info']['views'] = '<li class="info-replies"><strong>'.forum_number_format($cur_set['num_views']).'</strong> <span class="label">'.(($cur_set['num_views'] == 1) ? $lang_forum['View'] : $lang_forum['Views']).'</span></li>';

                ?>
                    <div class="main-item<?php echo $item_style ?>">
                        <span class="icon <?php echo implode(' ', $item_status) ?>"><!-- --></span>
                        <div class="item-subject">
                            <?php echo implode("\n\t\t\t\t", $item_body['subject'])."\n" ?>
                        </div>
                        <ul class="item-info">
                            <?php echo implode("\n\t\t\t\t", $item_body['info'])."\n" ?>
                        </ul>
                  </div>
        <?php

           }

        ?>
        </div>
    <?php
    
    }

?>

9 (edited by FalconFour 2008-12-01 20:17)

Re: Active Topics list...

Don't mean to be a bug or anything, but how do I use that bit of script? brd-main seems to be part of functions.php and I don't know if I should be directly editing that stuff...

10

Re: Active Topics list...

Place this script in a file with .php extension. On those pages where you want to display the topic list, insert this line:

include "<your_file_name.php>";

This line should be placed inside php-tags.

On every forum page, there is a div with id brd-main, it's not a part of functions.php.

11 (edited by FalconFour 2008-12-02 08:44)

Re: Active Topics list...

Hm, that's odd, maybe we're not talking about the same version. In my version (regular ol' 1.3), I've only got one (relevant) instance of the term "brd-main" in all the source code (used a file-search), and that's in functions.php that generates the header...

But I'll try putting it after "($hook = get_hook('in_main_output_start')) ? eval($hook) : null;", see how that works.

edit: Well, it worked... now I just need to figure out how to make it smaller, and fix the "sticky" thing. wink
http://hostfile.org/thumbs/L_7VibratingDoldoes-Forum.png.png

edit: Wait, shoot, those aren't even the last 7 topics... hmm. sad
*back to the drawing board* I think I can figure it out though... smile

12

Re: Active Topics list...

To delete "Sticky" and "Closed" notes remove this lines from script

 if ($cur_set['sticky'] == '1')
{
    $item_subject_status['sticky'] = $lang_forum['Sticky'];
    $item_status['sticky'] = 'sticky';
 }
    
if ($cur_set['closed'] != '0')
{
    $item_subject_status['closed'] = $lang_forum['Closed'];
    $item_status['closed'] = 'closed';
}

Re: Active Topics list...

Ahh, I found the problem. It wasn't that I wanted to remove the indicator for a sticky topic (that's like taking out the "service engine" bulb...), but rather that I wanted to figure out why it was saying all the topics were sticky. tongue

The problem was that it wasn't actually showing the most recent topics, but rather just showing seemingly random topics. A little database browsing revealed that it wasn't showing random topics... rather, it was showing the least recent (oldest) topics by sorting the wrong way! sad

I changed line 16 to show 'ORDER BY'    => 't.last_post DESC', and it showed the proper topics, and it also got rid of "Sticky:" on all the posts, because none of the recent topics were sticky.

Funny thing is, only two of the oldest topics shown were sticky... I think maybe it's accidentally flagging all the results as sticky, or maybe showing "Sticky" from that point on (perhaps by setting sticky = true instead of checking sticky == true?). I'll do a little more figuring on that.

14 (edited by FalconFour 2008-12-02 17:48)

Re: Active Topics list...

I made an installable extension out of it... yay!

But since there is no documentation on how to create an extension (which I'm sure is a huge hangup in the extensions community, not to mention the obscure and impossible to manipulate choice of using a fully CSS-based page design), I took an existing broken beta extension, and wrapped the code around it with a hook.

<?xml version="1.0" encoding="utf-8"?>

<extension engine="1.0">
    <id>active_topics</id>
    <title>Active Topics List on Index</title>
    <version>1.1</version>
    <description>This will add the x most recent posts to the index page of the forum for easy navigation and attention-grabbing.</description>
    <author>Slavok and FalconFour</author>
    <minversion>1.3</minversion>
    <maxtestedon>1.3</maxtestedon>
    <install>
        <![CDATA[
        ]]>
    </install>
    <uninstall>
        <![CDATA[
        ]]>
    </uninstall>    
    <hooks>
        <hook id="in_main_output_start"><![CDATA[
$topics_count = 5;
$query_active_topics= array(
    'SELECT'    => 't.id AS tid, t.poster, t.subject, t.posted AS has_posted, t.last_post, t.last_post_id, t.num_replies, t.num_views, t.closed, t.sticky, t.forum_id, t.last_poster',
    'FROM'        => 'topics AS t',
    'JOINS'        => array(
        array(
            'INNER JOIN'    => 'forums AS f',
            'ON'            => 'f.id=t.forum_id'
        ),
        array(
            'LEFT JOIN'     => 'forum_perms AS fp',
            'ON'            => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
        )
    ),
    'ORDER BY'    => 't.last_post DESC',
    'LIMIT' => $topics_count
);
$result_active = $forum_db->query_build($query_active_topics) or error(__FILE__, __LINE__);

if ($forum_db->num_rows($result_active) == 0) {

?>
    <div class="main-content main-message">
        <p>There is no message.</p>
    </div>
<?php
    
} else {
    require_once FORUM_ROOT.'lang/'.$forum_user['language'].'/forum.php';

?>    
    <div class="main-subhead">
            <p class="item-summary">
                <span>
                    <strong class="subject-title"><?php echo $lang_index['Topics']; ?></strong>
                    <strong class="info-replies"><?php echo $lang_forum['Replies']; ?></strong>
                    <strong class="info-views"><?php echo $lang_forum['Views']; ?></strong>
                    <strong class="info-lastpost"><?php echo $lang_index['last post']; ?></strong>
                </span>
            </p>                                                
        </div>
    <div class="main-content main-forum">                    
    <?php

        $item_num = 1;

        while ($cur_set = $forum_db->fetch_assoc($result_active))
        {
           // Start from scratch
            $item_subject = $item_body = $item_status = $item_nav = $item_title = array();
            $item_indicator = ''; 
            
            if (!$forum_user['is_guest'] && $forum_config['o_show_dot'] == '1' && $cur_set['has_posted'] > 0)
            {
                $item_title['posted'] = '<span class="posted-mark">'.$lang_forum['You posted indicator'].'</span>';
                $item_status['posted'] = 'posted';
            }

            $item_title['link'] = '<a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.forum_htmlencode($cur_set['subject']).'</a>';

            if (!empty($item_nav))
                $item_title['nav'] = '<span class="item-nav">'.sprintf($lang_forum['Topic navigation'], implode('&#160;&#160;', $item_nav)).'</span>';

            $item_body['subject']['title'] = '<h3 class="hn"><span class="item-num">'.forum_number_format(++$item_num).'</span> '.implode(' ', $item_title).'</h3> <em> by '.forum_htmlencode($cur_set['poster']).'</em>';
            if ($cur_set['sticky'] == '1')
            {
                $item_subject_status['sticky'] = $lang_forum['Sticky'];
                $item_status['sticky'] = 'sticky';
            }

            if ($cur_set['closed'] != '0')
            {
                $item_subject_status['closed'] = $lang_forum['Closed'];
                $item_status['closed'] = 'closed';
            }
            // Does this topic contain posts we haven't read? If so, tag it accordingly.
            if (!$forum_user['is_guest'] && $cur_set['last_post'] > $forum_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_set['tid']]) || $tracked_topics['topics'][$cur_set['tid']] < $cur_set['last_post']) && (!isset($tracked_topics['forums'][$cur_set['forum_id']]) || $tracked_topics['forums'][$cur_set['forum_id']] < $cur_set['last_post']))
            {
                $item_status['new'] = 'new';
            }
            
            if (!empty($item_subject_status))
                $item_subject['status'] = '<span class="item-status">'.sprintf($lang_forum['Item status'], implode(' ', $item_subject_status)).'</span>';

//            $item_subject['starter'] = '<span class="item-starter">'.sprintf($lang_forum['Topic starter'], '<cite>'.forum_htmlencode($cur_set['poster']).'</cite>').'</span>';

            $item_body['subject']['desc'] = implode(' ', $item_subject);
            if (empty($item_status))
                $item_status['normal'] = 'normal';

            $item_style = (($item_num % 2 != 0) ? ' odd' : ' even').(($item_num == 1) ? ' main-first-item' : '').((!empty($item_status)) ? ' '.implode(' ', $item_status) : '');
            
            $item_body['info']['replies'] = '<li class="info-replies"><strong>'.forum_number_format($cur_set['num_replies']).'</strong> <span class="label">'.(($cur_set['num_replies'] == 1) ? $lang_forum['Reply'] : $lang_forum['Replies']).'</span></li>';
            $item_body['info']['views'] = '<li class="info-replies"><strong>'.forum_number_format($cur_set['num_views']).'</strong> <span class="label">'.(($cur_set['num_views'] == 1) ? $lang_forum['View'] : $lang_forum['Views']).'</span></li>';
            $item_body['info']['last_post'] = '<li class="info-lastpost"><span class="label">'.$lang_index['Last post'].'</span> <strong><a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.format_time($cur_set['last_post']).'</a></strong> <cite>'.sprintf($lang_index['Last poster'], forum_htmlencode($cur_set['last_poster'])).'</cite></li>';

            ?>
                <div class="main-item<?php echo $item_style ?>">
                    <span class="icon <?php echo implode(' ', $item_status) ?>"><!-- --></span>
                    <div class="item-subject">
                        <?php echo implode("\n\t\t\t\t", $item_body['subject'])."\n" ?>
                    </div>
                    <ul class="item-info">
                        <?php echo implode("\n\t\t\t\t", $item_body['info'])."\n" ?>
                    </ul>
              </div>
    <?php

       }

}
        ]]></hook>
    </hooks>
</extension>

http://hostfile.org/thumbs/L_0_7VibratingDoldoes-Forum.png.png

Create a new folder in "extensions" called "active_topics", and save the above code as "manifest.xml".

Honestly though, I think I might be switching to either PunBB 1.2, which is more properly and cleanly supported, or just dropping PunBB altogether, since it seems its developers don't even know what's going on! sad