1 (edited by FalconFour 2008-12-02 18:18)

Topic: [Extension release] 1.3 Final - Active Topics list on Index

*huff* About darn time this extension made it out of the shop. A much needed add-on for forums that need an attention-grabber. wink

I have no idea about performance implications, as it was a pain-in-the-arse enough just getting the stupid thing working! The design of this forum is very unconductive to adding or rearranging page elements, as I had to make this work without editing any of the existing stylesheet. Seeing as though, thanks to the genius that decided to inject CSS into every aspect of PunBB, the whole page layout is constructed in CSS, all I could really do is recycle and abuse other existing CSS classes and hope it doesn't break.

Seriously: fixed-defining the positions of elements to "fake" a table out of a list element is doin it rong. Very "rong".

Anyway, on with the show.

Create a new folder in your extensions folder, call it "active_topics". Save the following code as "manifest.xml":

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

<extension engine="1.0">
    <id>active_topics</id>
    <title>Active Topics List on Index</title>
    <version>1.2</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'].')'
        )
    ),
    'WHERE' => '(fp.read_forum IS NULL OR fp.read_forum=1)',
    '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 are no active topics.</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 (!empty($item_nav))
                $item_title['nav'] = '<span class="item-nav">'.sprintf($lang_forum['Topic navigation'], implode('&#160;&#160;', $item_nav)).'</span>';

            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_title['status'] = '<span class="item-status">'.sprintf($lang_forum['Item status'], implode(' ', $item_subject_status)).'</span>';
            $item_title['link'] = '<a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.forum_htmlencode($cur_set['subject']).'</a>';
            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_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>';

            // 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';
            }
            
            $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>

Change $topics_count = 5 in the first line of the hook script, to however many topics you want to show in the list.

Go to your extensions page, and hit install.

Enjoy!

Now, time for me to lay off the CSS for a while before my mind melts out my ears.

Version history:
1.0 - First version (unreleased)
1.1 - Made "new posts" indicator work properly
1.2 - Fixed the "item status" (closed, sticky) indicators appear properly. Made the list respect permissions, which is kinda important if you have an active moderator forum wink

2

Re: [Extension release] 1.3 Final - Active Topics list on Index

Nice...it works fine..tnx. Any idea how to move it below main forums?

Re: [Extension release] 1.3 Final - Active Topics list on Index

Moving it below the forum listing? Looks like it should be possible by replacing:
<hook id="in_main_output_start">
with:
<hook id="in_end">
in "manifest.xml", then reinstalling the extension.

There are different hooks all throughout index.php, that put the script in at different places. I just really don't want to go through the hassle of uninstalling, reinstalling, uninstalling, then reinstalling, on my board, to test it. It looks like in_end is the right place to get it below the forum output though. Let me know how it works!

4 (edited by teva 2008-12-03 08:08)

Re: [Extension release] 1.3 Final - Active Topics list on Index

yep..it worked. Tnx a lot

in future release, you could add options in admin to change $topic_count and hook id, so you can change this variables easily.

How about adding h2 class (used to name forum groups) with language variable. This would allow to give name like "Last 10 posts from forums".

just some thoughts smile

5

Re: [Extension release] 1.3 Final - Active Topics list on Index

I think i found a bug.

The dot in front topic name, that marks topic that you have posted to is shown on every topic, even if you have not posted. You have to be registered to see this.

Re: [Extension release] 1.3 Final - Active Topics list on Index

Hm, you know, I think I'm just going to (almost) entirely rewrite the code for the next version. This was based mostly on a code snip from Slavok, and it's really really sloppy. I could probably chop it down to 1/10th the size and make the code a lot more readable for the next version. I'll keep this tab open so I remember to get started on it... eventually. =\

7 (edited by FalconFour 2008-12-04 19:51)

Re: [Extension release] 1.3 Final - Active Topics list on Index

Holy stinking crap, did this just get added to the official extensions database? I got an upgrade notification for my own extension... =o

Re: [Extension release] 1.3 Final - Active Topics list on Index

    'WHERE' => '(fp.read_forum IS NULL OR fp.read_forum=1)',
    'ORDER BY'    => 't.last_post DESC',
    'LIMIT' => $topics_count

It's just show last x recent post not topic. If you want to Show last x topic (not post) find-

    'ORDER BY'    => 't.last_post DESC',

replace with

    'ORDER BY'    => 't.id DESC',

:-)

Never explain yourself to anyone. Because the person who likes you doesn’t need it, and the person who dislikes you won’t believe it.

Re: [Extension release] 1.3 Final - Active Topics list on Index

I like it smile
Good work dude!

Re: [Extension release] 1.3 Final - Active Topics list on Index

I agree it would be nice to have a H2 heading saying "most recently active topics" or something
smile

Re: [Extension release] 1.3 Final - Active Topics list on Index

FalconFour wrote:

Seriously: fixed-defining the positions of elements to "fake" a table out of a list element isdoin it rong. Very "rong".

No, that is a very correct and valid way to use CSS, it is EXTREMELY well documented and tested (although Informer has not perfected their Oxygen css yet).

FalconFour wrote:

Seeing as though, thanks to the genius that decided to inject CSS into every aspect of PunBB, the whole page layout is constructed in CSS, all I could really do is recycle and abuse other existing CSS classes and hope it doesn't break.

Right, the entire page styling is SUPPOSED to be in CSS, because if you drop all the CSS files, you are given a cleanly printed page which follows a logical top-to-bottom (vertical) progression of sentences which make sense.  This is ideal for web-pages because it lends itself well to being printed on a wide variety of screen types, sizes and resolutions.  A 1990's style rigid table design of this same page could NEVER be printed properly on a PDA or cell phone screen... this one can, if you drop the CSS or write a PDA appropriate CSS.

You're complaining too much, and projecting your frustration.  Truth of the matter is that your work wasn't perfect, either, but it was also nearly good enough.  Study more, and blame less, please.

That said, thanks for the extension, sir.  I like it, was inspired to fix it, and am inspired to consider improvements after I study it more.

Update:
* Closed a <div> that was breaking sibling <div>.
* Added the requested <h2>

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

<extension engine="1.0">
    <id>active_topics</id>
    <title>Active Topics List on Index</title>
    <version>1.2.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, FalconFour and whatrevolution</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'].')'
        )
    ),
    'WHERE' => '(fp.read_forum IS NULL OR fp.read_forum=1)',
    '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 are no active topics.</p>
    </div>
<?php
    
} else {
    require_once FORUM_ROOT.'lang/'.$forum_user['language'].'/forum.php';

?>    
    <div class="main-head">
      <h2 class="hn"><span>Most Recent Posts</span></h2>
    </div>
    <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 (!empty($item_nav))
                $item_title['nav'] = '<span class="item-nav">'.sprintf($lang_forum['Topic navigation'], implode('&#160;&#160;', $item_nav)).'</span>';

            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_title['status'] = '<span class="item-status">'.sprintf($lang_forum['Item status'], implode(' ', $item_subject_status)).'</span>';
            $item_title['link'] = '<a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.forum_htmlencode($cur_set['subject']).'</a>';
            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_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>';

            // 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';
            }
            
            $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
       }
?>
    </div>
<?php
}
        ]]>
        </hook>
    </hooks>
</extension>

Re: [Extension release] 1.3 Final - Active Topics list on Index

I've hit a bug in this, and am reporting it before I look at the code to solve it.

http://www.honestlyillustrated.com/off-site/screenshots/punbb_recent_posts_bug_01.png

Looks like a simple need to reset a variable at the end of foreach.  In the screenshot, only the top (most recent) post is actually Sticky or Closed.  You can see that by the row color.

Re: [Extension release] 1.3 Final - Active Topics list on Index

Temporarily Fixed:

Line 71:

        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 = ''; 
            unset($item_status);
            unset($item_subject_status);

Very improper use of variables in this script.

14

Re: [Extension release] 1.3 Final - Active Topics list on Index

            $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 you don't want the BY XXXXX after topic title - change line 101 to this (deleting <em....) - it's still next to date anyway....

            $item_body['subject']['title'] = '<h3 class="hn"><span class="item-num">'.forum_number_format(++$item_num).'</span> '.implode(' ', $item_title).'</h3> ';

Re: [Extension release] 1.3 Final - Active Topics list on Index

Sounds like a cool extension. I'll test it out once it is further developed smile

Programming Designs - Tech, programming, and web design blog
PD Forums - Using the latest and greatest PunBB 1.3 =)

16

Re: [Extension release] 1.3 Final - Active Topics list on Index

@FalconFour  (or anyone else  for that matter)

What needs to be modified/added so that after TOPIC TITLE  my guests see which FORUM it was posted in?

Thx.