News:

Wondering if this will always be free?  See why free is better.

Main Menu

Most Popular Topic Today

Started by vbgamer45, September 15, 2007, 01:56:23 PM

Previous topic - Next topic

BigMike

#120
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
LIMIT 1'

Simply increase this number to your desired amount for example:
LIMIT 5'


Quote from: Casal on April 24, 2011, 07:03:07 AM
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,

//*********************************** 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,

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,

$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:

QuoteOur 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

BigMike

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

<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...

<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

Deaks

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.
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

bestfriendavinash

working fine with smf 2.0.2

TheListener

Runic as ya now the owner of the mod.

How would I get rid of

QuoteSorry, no-one hes replied today

and just leave the topic title?

bros

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?

Biology Forums

This is very interesting! Could you limit it do a certain board?

Alpay

Hello ,

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

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

BigMike

Quote from: Liam_michael on September 27, 2013, 10:08:46 PM
This is very interesting! Could you limit it do a certain board?
Yes indeed, change the $request in BoardIndex.php to the following:

    $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:
    AND boa.id_board IN ({array_int:boards})
and
    'boards' =>  array(1, 2, 3),

Quote from: Alpay on October 23, 2013, 05:51:05 PM
change ?
604800 = 7 day and week ?
Yes, this works! This will arrange by Most Active Topics per week :)

BigMike

MangosMadMax

Hey there,

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

Quotehttps://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

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

Biology Forums

#130
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

DarkAngel612

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

vbgamer45

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

DarkAngel612

Fantasy Attic ::  Fantasies Realm Market :: SMF 2.0+ with various mods and TinyPortal

KittyGalore

Quote from: MangosMadMax 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:

Quotehttps://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

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>';

Was there ever a fix for this it seems that if topics are hidden for certain members and guests the error is in the error log. SMF Version 2.0.17 SMF Default theme
SMF Curve 2.0x

vbgamer45

What error are you getting in the log?
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

KittyGalore

Quote from: vbgamer45 on January 26, 2020, 01:27:36 PM
What error are you getting in the log?
These 2 errors everytime from the same IP or member at the same time. Also for guests 2 errors for one person viewing at a certain time for example a guest recorded time on both errors at 16:41:04

Apply Filter: Only show the errors with the same message2: implode(): Invalid arguments passedApply Filter: Only show the errors from this fileFile: /home/xxxxxxxxx/public_html/Themes/default/BoardIndex.template.php
Line: 302


8: Undefined variable: user_infoApply Filter: Only show the errors from this fileFile: /home/xxxxxxxxxxx/public_html/Themes/default/BoardIndex.template.php
Line: 302


The code at line 302.

echo $txt['cant_read_mpt'] . ' ' . implode(',', $user_info['groups']);
SMF Curve 2.0x

vbgamer45

Posted an update to the mod.
See if that helps!
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

KittyGalore

Quote from: vbgamer45 on January 26, 2020, 02:20:01 PM
Posted an update to the mod.
See if that helps!
Thanks  :) :) I have installed the new update i'll let you know if i get any more errors. At the moment i don't have any.
SMF Curve 2.0x

KittyGalore

Quote from: vbgamer45 on January 26, 2020, 02:20:01 PM
Posted an update to the mod.
See if that helps!
Thanks that update seems to have sorted it i removed all my errors in log and the log is still at 0. It's over an hour or so now and that error hasn't come back.
SMF Curve 2.0x

Advertisement: