Advertisement:

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

Offline BigMike

  • Full Member
  • ***
  • Posts: 632
  • Gender: Male
    • http://facebook.com/huusoku on Facebook
    • 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: 632
  • Gender: Male
    • http://facebook.com/huusoku on Facebook
    • 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

Offline Poύνικ

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,906
  • Gender: Male
  • His Royal Runicness
    • bryan.deakin.1 on Facebook
    • pouvik on GitHub
    • @bryandeakin on Twitter
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.

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

TheListener

  • Guest
Re: Most Popular Topic Today
« Reply #124 on: June 16, 2013, 05:56:44 PM »
Runic as ya now the owner of the mod.

How would I get rid of

Quote
Sorry, no-one hes replied today

and just leave the topic title?

Offline bros

  • Full Member
  • ***
  • Posts: 634
Re: Most Popular Topic Today
« Reply #125 on: September 27, 2013, 09:39:32 PM »
Question - would it be possible to integrate this into a simpleportal block, so I could display today's active topics in lets say, a sidebar?

Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,799
    • Free Homework Help
Re: Most Popular Topic Today
« Reply #126 on: September 27, 2013, 10:08:46 PM »
This is very interesting! Could you limit it do a certain board?

Offline Alpay

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 3,492
  • Gender: Male
    • Personal Web Page
Re: Most Popular Topic Today
« Reply #127 on: October 23, 2013, 05:51:05 PM »
Hello ,

array(
          'time' => time(),
          'time2' => (time()-86400),
       )

change ?
86400 = 1 day 86400*7 = 604800
604800 = 7 day and week ?

Offline BigMike

  • Full Member
  • ***
  • Posts: 632
  • Gender: Male
    • http://facebook.com/huusoku on Facebook
    • Marlin Crawler, Inc.
Re: Most Popular Topic Today
« Reply #128 on: November 06, 2013, 01:21:15 PM »
This is very interesting! Could you limit it do a certain board?
Yes indeed, change the $request in BoardIndex.php to the following:

Code: [Select]
    $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}
    AND boa.id_board IN ({array_int:boards})
    GROUP BY id_topic
    ORDER BY t DESC
    LIMIT 5',
    array(
    'time' => time(),
    'time2' => (time()-86400),
    'boards' =>  array(1, 2, 3),
    )
    );

Noting the line near the end, "'boards' =>  array(1, 2, 3),". Simply enter in whatever board ID you want to be included and it will only draw posts from those boards. You can enter just one number here or all of your board IDs, the size of the array doesn't matter so long as you have at least one ID number in there.

To do the inverse, if you want to include all boards except for those in the array, don't waste your time filling the array with all your boards minus a couple. Instead change the IN to NOT EXIST like so:
AND boa.id_board NOT EXIST ({array_int:boards})
Now it will pull all board IDs except for the ones you have in the array (which again could just be a single ID if needed).

Side note: This modification was very simple. Here are the only two lines that were added:
Code: [Select]
    AND boa.id_board IN ({array_int:boards})and
Code: [Select]
    'boards' =>  array(1, 2, 3),
change ?
604800 = 7 day and week ?
Yes, this works! This will arrange by Most Active Topics per week :)

BigMike

Offline MangosMadMax

  • Semi-Newbie
  • *
  • Posts: 28
  • Gender: Male
    • getMaNGOS
Re: Most Popular Topic Today
« Reply #129 on: March 03, 2014, 06:10:29 AM »
Hey there,

Using this mod with the Bluebird theme and the error log for the forum is full of the following:

Quote
https://community.getmangos.co.uk/index.php?https://community.getmangos.co.uk/community/
2: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed
File: /home/mangos/public_html/community/Themes/BlueBird/BoardIndex.template.php
Line: 312

Code: [Select]
311: if ($context['topic_mod'] == '0')
==>312: echo $txt['cant_read_mpt'] . ' ' . implode(',', $user_info['groups']);
313: elseif (!isset($context['most_popular_topic_today']['coll']) || ($context['topic_mod']) == '2')
314:         echo $txt['most_pop_top_abs'];
315:     else
316:       echo '
317:     <strong><a href="', $scripturl, '?topic=', $context['most_popular_topic_today']['id_topic'], '">', $context['most_popular_topic_today']['subject'], '</a></strong>
318:     <div class="smalltext">
319:     ', $txt['most_pop_top'], ' &quot;', $context['most_popular_topic_today']['coll'], '&quot;
320:     </div>';
321: echo '
322: </p>';
Regards,
MadMax

Cisco Certified Desktop Support & Network Engineer

Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,799
    • Free Homework Help
Re: Most Popular Topic Today
« Reply #130 on: March 03, 2014, 10:44:35 AM »
Could you upload the 1.x version; it appears to have been discontinued. If not, please visit:

http://www.simplemachines.org/community/index.php?topic=519331
« Last Edit: March 03, 2014, 10:30:41 PM by Liam_michael »

Offline DarkAngel612

  • Sr. Member
  • ****
  • Posts: 907
  • Gender: Female
Re: Most Popular Topic Today
« Reply #131 on: July 25, 2015, 12:04:24 AM »
I realize you are uber busy but thought to let you know, in case you are updating this to work with 2.0.10

I installed it a few years ago and it works beautifully.

1. still can not see more that one popular thread.

2. I tried inserting the code that was offered a few posts before this and got not favorable effect....page was blank. (removed code)

3. Also noted that when logged in the members or admin/staff belonging to said thread will see like they should. Unlogged in will see (our forum is open for all to see save some group only areas.) when viewing the Recent area at bottom of forum...will not see the most popular "anyone" thread, they see sort of a stats section but no thread.

Not sure if that is how it should be with the code I mentioned in #3 but when the original code is reinstated the logged/unlogged DO see the popular thread...I like that.

Will you be updating this mod or is it defunct or waiting for the next version of SMF?
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.0+ with various mods and TinyPortal

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 17,444
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Most Popular Topic Today
« Reply #132 on: July 25, 2015, 11:01:05 AM »
On hold on the moment not too familiar with the code will have to go over it should work still for SMF 2.0.x
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Offline DarkAngel612

  • Sr. Member
  • ****
  • Posts: 907
  • Gender: Female
Re: Most Popular Topic Today
« Reply #133 on: July 25, 2015, 07:44:49 PM »
ok, thanks
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.0+ with various mods and TinyPortal