Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2008, 05:50 PM
alla n1015 alla n1015 is offline
 
Join Date: Jan 2008
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #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
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:03 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.03660 seconds
  • Memory Usage 2,173KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete