View Single Post
  #3  
Old 02-21-2011, 02:13 AM
El Queso El Queso is offline
 
Join Date: Oct 2010
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I probably should have returned and posted my solution for other's reference.

The problem I found with trying to set a variable was I didn't (and still don't) completely understand how the user data is being generated when the user is a guest.

The code that determines the sort order is in SHOWTHREAD.PHP. The value it uses is the guest user's "postorder" variable ($vbulletin->userinfo['postorder']). The standard guest user name in the version that comes out of the box is "Unregistered". I don't have a user with the user name "Unregistered" so obviously vBulletin is doing something on authentication to create that user and its information. I don't know if there's something else in the admin portions of vBulletin that allows one to set the "Unregistered" user's default info or not, but I couldn't find it if there is.

Doing this from a hook seems to be problematic. You have to be able to set the $vbulletin->userinfo['postorder'] to '' (empty string) to make it work (see the code below for how it generates the sort order for the query), but when I tried to do this in a plug-in, using the 'showthread_start' hook, I got no changes in my sort order. Maybe this property unassignable, or the user (or its information) gets recreated every postback because it's not a database user? I don't know.

What I did to solve the problem was to hack the SHOWTHREAD.PHP file thusly:

Find this code ("set post order" should find it directly):

PHP Code:
// set post order
if ($vbulletin->userinfo['postorder'] == 0)
{
   
$postorder '';
}
else
{
   
$postorder 'DESC';

and change it to this:

PHP Code:
// set post order
if ($vbulletin->userinfo['postorder'] == AND $vbulletin->userinfo['username'] != 'Unregistered')
{
   
$postorder '';
}
else
{
   
$postorder 'DESC';

NOTE that I read something about the user name for language packs other than the default English may well have other user names than "unregistered" and therefore may not work in those situations.

As far as going further with highest rated threads sorting and/or promoting threads - you can see where to make the changes to the sort order itself, but it will be a bit more complex than I laid out than for just a user that's not logged in. You will obviously have to get the other info you are interested in and make the conditional fit your needs.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01215 seconds
  • Memory Usage 1,782KB
  • 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
  • (2)bbcode_php
  • (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