Advertisement:

Author Topic: Most Popular Topic Today  (Read 43810 times)

Offline BigMike

  • Full Member
  • ***
  • Posts: 594
  • Gender: Male
    • Marlin Crawler, Inc.
Re: Most Popular Topic Today
« Reply #120 on: April 19, 2012, 04:01:33 PM »
First, thank you Runic for this awesome mod!! :) :D

FAQ
How do I add more post?
Once installed open your BoardIndex.php file located in your sources folder and search for
Code: [Select]
LIMIT 1'
Simply increase this number to your desired amount for example:
Code: [Select]
LIMIT 5'


It´s doesn´t work in LIMIT 5

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: [Select]
//*********************************** 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);
//******************************************************************************************//

...and in BoardIndex.template.php,
Code: [Select]
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 />';
    }

I have changed the output to be on one line, making the following changes to the template language file,
Code: [Select]
$txt['most_popular_topic_today'] = 'Our Current Most Active Topics';
$txt['most_pop_top'] = 'replies per day';

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)

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
« Last Edit: April 19, 2012, 04:21:34 PM by BigMike »

Offline BigMike

  • Full Member
  • ***
  • Posts: 594
  • Gender: Male
    • Marlin Crawler, Inc.
Re: Most Popular Topic Today
« Reply #121 on: May 08, 2012, 12:14:48 PM »
...and in BoardIndex.template.php,
Code: [Select]
<strong><a href="', $scripturl, '?topic=', $post['id_topic'], '">', substr($post['subject'], 4), '</a></strong>

......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 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: [Select]
<strong><a href="', $scripturl, '?topic=', $post['id_topic'], '">', preg_replace('/Re: /','',$post['subject']), '</a></strong>

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

Online Runic

  • Project Manager
  • SMF Master
  • *
  • Posts: 25,082
  • Gender: Male
  • Bah Humbug!!
    • BryanRunicDeakin on Facebook
    • bryandeakin on LinkedIn
    • @bryandeakin on Twitter
    • Bryan Deakin.com
Re: Most Popular Topic Today
« Reply #122 on: May 08, 2012, 02:15:28 PM »
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.
AUNT CLARA IS HERE!!!

Bryan Runic Deakin
|
Μπράιαν Poύνικ Ντίκεν
Project Manager/Marketing
|
Διαχειριστής έργου/Μάρκετινγκ
Wha Like Us!
Say YES to Scottish Independence

Offline bestfriendavinash

  • Jr. Member
  • **
  • Posts: 159
  • Gender: Male
  • ~ ~ Fun With Best Friends ~ ~
    • Fun With Best Friends
Re: Most Popular Topic Today
« Reply #123 on: May 09, 2012, 06:50:52 AM »
working fine with smf 2.0.2