vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   subforums - list by last post (https://vborg.vbsupport.ru/showthread.php?t=169088)

alla n1015 01-29-2008 05:50 PM

subforums - list by last post
 
Hi,

Im on a project to try and make subforums display in order of last post made, I mean subforums on the 2cd level pages, (forumdiusplay.php) not home page.

Reverse engineering is getting time consuming, just thought Id ask if anyone has done this, and /or can point me to areas of code that might be places to touch.

Allan

cheesegrits 01-30-2008 04:23 AM

I think you'd need to plugin to the forumdisplay_start hook and re-order $vbulletin->iforumcache[] according to the lastpost data in the forumcache.

Something like:

Code:

function lastpost_sort ($a, $b) {
        global $vbulletin;
        if ($vbulletin->forumcache[$a]['lastpost'] == $vbulletin->forumcache[$b]['lastpost'])
        {
                return 0;
        }
        else
        {
                return ($vbulletin->forumcache[$a]['lastpost'] > $vbulletin->forumcache[$b]['lastpost'] ? -1 : 1);
        }
}

uksort($vbulletin->iforumcache[$vbulletin->GPC['forumid']], 'lastpost_sort');


-- hugh

--------------- Added [DATE]1201676889[/DATE] at [TIME]1201676889[/TIME] ---------------

Well poop. That won't work because cache_ordered_forums(), which builds the iforumcache, is called AFTER forumdisplay_start.

There's a hook in cache_ordered_forums itself, but I'm still trying to work out how to use it.

I'm needing to do almost exactly the same thing, so I hope I'll find a workaround soon ...

-- hugh

--------------- Added [DATE]1201712842[/DATE] at [TIME]1201712842[/TIME] ---------------

Well, good news for me, bad news for you. I worked out how to do this for my requirement (which uses some fields I added to the forum table, for forum rating). Uses this code on forumdisplay_start, which is very similar to the code I first posted, but sorts the actual forumcache, not the iforumcache. Turns out the iforumcache is simply derived from the ordering of forumcache:

Code:

<?php
function forumrate_sort ($a, $b) {
        global $vbulletin;
        if ($vbulletin->forumcache[$a]['votetotal'] == $vbulletin->forumcache[$b]['votetotal'])
        {
                return 0;
        }
        else
        {
                return ($vbulletin->forumcache[$a]['votetotal'] < $vbulletin->forumcache[$b]['votetotal'] ? -1 : 1);
        }
}

uksort($vbulletin->forumcache, 'forumrate_sort');
?>

Theoretically, this should work for you by just using 'lastpost' instead of 'votetotal'. But for reasons I don't understand, 'lastpost' isn't in the forumcache. Even though I can see it in the serialized data in my datastore table when init.php run the datastore->fetch().

-- hugh

--------------- Added [DATE]1201716914[/DATE] at [TIME]1201716914[/TIME] ---------------

OK, I finally got this to work. It's one of those chicken and egg problems. The 'lastpost' info is added to the forumcache by cache_ordered_forums(), but the only hook we can use is called before cache_ordered_forums(). So the only solution I can find is to modify the above code, and add a call to cache_ordered_forums() before the uksort().

This works, but adds a query to the forumdisplay page load, because forumdisplay is going to call cache_ordered_forums() again after our hook runs (but this time, it'll build it from our re-ordered forumcache).

If you can live with this, then the following code (still on the forumdisplay_start hook) does what you want. Tested in 3.7b3, but should work on 3.6:

Code:

<?php
function forumrate_sort ($a, $b) {
        global $vbulletin;
        if ($vbulletin->forumcache[$a]['lastpost'] == $vbulletin->forumcache[$b]['lastpost'])
        {
                return 0;
        }
        else
        {
                return ($vbulletin->forumcache[$a]['lastpost'] > $vbulletin->forumcache[$b]['lastpost'] ? -1 : 1);
        }
}
cache_ordered_forums(1, 1);
uksort($vbulletin->forumcache, 'forumrate_sort');
?>

You might want to "unset($vbulletin->iforumcache);" as the last line, just in case.

-- hugh


All times are GMT. The time now is 03:51 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01156 seconds
  • Memory Usage 1,721KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete