View Single Post
  #2  
Old 01-30-2008, 04:23 AM
cheesegrits's Avatar
cheesegrits cheesegrits is offline
 
Join Date: May 2006
Posts: 500
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01852 seconds
  • Memory Usage 1,778KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete