Customizing SMF > Modifications and Packages

Most Popular Topic Today

<< < (25/25)

BigMike:
First, thank you Runic for this awesome mod!! :) :D


--- Quote from: Runic on September 15, 2007, 01:56:23 PM ---FAQ
How do I add more post?
Once installed open your BoardIndex.php file located in your sources folder and search for

--- Code: ---LIMIT 1'
--- End code ---

Simply increase this number to your desired amount for example:

--- Code: ---LIMIT 5'
--- End code ---

--- End quote ---



--- Quote from: Casal on April 24, 2011, 07:03:07 AM ---It´s doesn´t work in LIMIT 5
--- End quote ---

I am using SMF 2.0.2 and Casal is correct, this does not work. I am _VERY_ shocked this mod is over 4-1/2 years old / 119 replies in this thread and no one has offered a solution to this!

Looking at the code it is very easy to see why it doesn't work as advertised: All Runic's suggestion does is increment the amount of data pulled from the database. This is good, but as coded, any increased number of information from the database is simply overwritten atop itself in the $context['most_popular_topic_today'] array, and the template file does not contain any additional while or for...next loops to support this.

I spent a few mins and got this to work. I rewrote some of the code & here is what I am using to display the current top 5 most active topics:

In BoardIndex.php,


--- Code: --- //*********************************** Most popular topic today.***************************//
$id_group = $user_info['groups'];
    $request = $smcFunc['db_query']('', '
    SELECT COUNT(mes.id_topic) as t, mes.id_topic, mes.subject, boa.member_groups
    FROM {db_prefix}messages AS mes
    LEFT JOIN {db_prefix}boards as boa ON (mes.id_board = boa.id_board)
    WHERE poster_time <= {int:time}
    AND poster_time >= {int:time2}
    GROUP BY id_topic
    ORDER BY t DESC
    LIMIT 5',
    array(
    'time' => time(),
    'time2' => (time()-86400),
    )
    );
    $i = 0;
    $context['most_popular_topic_today'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
    {
      // Build the Array
      $context['most_popular_topic_today'][$i] = array(
        'coll' => $row['t'],
    'id_topic' => $row['id_topic'],
    'subject' => $row['subject'],
    'memberGroups' => explode(',', $row['member_groups'])
    );

    // User cannot read this topic
    if ((isset($context['most_popular_topic_today'][$i]['memberGroups'])) && (!array_intersect($context['most_popular_topic_today'][$i]['memberGroups'], $id_group) && !allowedTo('admin_forums')))
        $context['most_popular_topic_today'][$i]['id_topic'] = "hide";

    // No one has replied to anything in the given time period
    elseif (isset($context['most_popular_topic_today'][$i]['coll']) == '')
      $context['most_popular_topic_today'][$i]['id_topic'] = "none";

      $i = $i + 1;
    }
    $smcFunc['db_free_result']($request);
//******************************************************************************************//

--- End code ---

...and in BoardIndex.template.php,

--- Code: --- echo '
<h4 class="titlebg">
<span class="ie6_header floatleft">
', $txt['most_popular_topic_today'], '
</span>
</h4>
<p>';

    foreach ($context['most_popular_topic_today'] as $post)
    {
      if ($post['id_topic'] == "hide")
        echo $txt['cant_read_mpt'] . ' ' . implode(',', $user_info['groups']);
      elseif ($post['id_topic'] == "none")
        echo $txt['most_pop_top_abs'];
      else
        echo '
      <strong><a href="', $scripturl, '?topic=', $post['id_topic'], '">', substr($post['subject'], 4), '</a></strong>
      <span class="smalltext">
       (', $post['coll'], ' ', $txt['most_pop_top'], ')
      </span>';
      echo '<br />';
    }

--- End code ---

I have changed the output to be on one line, making the following changes to the template language file,

--- Code: ---$txt['most_popular_topic_today'] = 'Our Current Most Active Topics';
$txt['most_pop_top'] = 'replies per day';

--- End code ---

And I have also trimmed the first 4 characters of the topic's reply title to remove the "Re: ", since it's not the reply which is popular, it's the topic! I also dropped the $context['topic_mod'] variable and used a unique 'topic_id' to handle the permission checks instead (uses 1 less variable).

The result looks like this:


--- Quote ---Our Current Most Active Topics

Topic One (# replies per day)
Topic Two (# replies per day)
Topic Three (# replies per day)
Topic Four (# replies per day)
Topic Five (# replies per day)
--- End quote ---

You can see it along with the "Statistics in jQuery" mod in action here: http://board.marlincrawler.com

Just theme for your own needs and enjoy :D

Regards,
BigMike

BigMike:

--- Quote from: BigMike on April 19, 2012, 04:01:33 PM ---...and in BoardIndex.template.php,

--- Code: ---<strong><a href="', $scripturl, '?topic=', $post['id_topic'], '">', substr($post['subject'], 4), '</a></strong>

--- End code ---

......I have also trimmed the first 4 characters of the topic's reply title to remove the "Re: ", since it's not the reply which is popular, it's the topic!

--- End quote ---

I have seen a few times where the topic subject is called instead of the reply subject, so removing the first 4 characters doesn't work in all cases.

For this reason, I've decided to do an expression replace if "Re: " ever exists in any subject being used. Update my above line to the following...

--- Code: ---<strong><a href="', $scripturl, '?topic=', $post['id_topic'], '">', preg_replace('/Re: /','',$post['subject']), '</a></strong>

--- End code ---

And that will take care of any and all reply subjects without affecting wayward topic subjects. This will fail if anyone decides to make a topic that has "Re: " in it -- it is case sensitive -- such as "Hey Sally, remember me Re: last night", but I don't think I've ever seen that on my 1 million post community. At any rate, it's omission probably won't logically destroy the subject anyway lol  :D

Sure I could run additional checks but I'm too lazy to learn how :P

BigMike

Runic:
interesting, I have been extremley busy with offline stuff but I will incorporate your changes into the mod of course with your permission and credit given where due.

bestfriendavinash:
working fine with smf 2.0.2

Navigation

[0] Message Index

[*] Previous page

Go to full version