Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 10-28-2010, 05:30 AM
El Queso El Queso is offline
 
Join Date: Oct 2010
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Default post order in thread display for unauthenticated users

I've searched for quite awhile for something on this and can't find what I'm looking for. Admittedly I'm new at vBulletin programming - the answer may be relatively simple, but for a newby there is an overwhelming amount of information to sift through!

Is there a way to change the default order in which posts are displayed when displaying a thread to users who are not logged in?

The default order is earliest posts first. I have a large forum with threads that reach hundreds (some actually thousands) and go 'way back in time. When unauthenticated users are browsing the forum, I want them to see the latest posts in a thread first so they see the latest information.

I can't find any admin options that allow me to set this default for any but logged in users. I'm assuming I will have to either use a plugin/hook or do a hack, but I can't figure out what template, code file, hook and/or variable I need to look at to make this happen.
Reply With Quote
  #2  
Old 02-20-2011, 10:15 PM
Meestor_X Meestor_X is offline
 
Join Date: Apr 2006
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I too want to do this.

I want visitors to first see the highest rated threads, but registered users to see the default sort order (in my case most recent first)...
Or even better to have it change via a promotion. Sort order changes after you make one post or something like that.
Reply With Quote
  #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
  #4  
Old 02-21-2011, 04:37 AM
Meestor_X Meestor_X is offline
 
Join Date: Apr 2006
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for that information!

I'm trying to understand that code (I'm only a beginner in PHP)...

This code seems to deal only with ascending and descending order for the posts, by date. (I assume that's what dateline means?)

What if they're sorted by thread rating or some other factor? Where is that taken into account?

The query seems to be:
PHP Code:
$getpostids $db->query_read("
            SELECT postid
            FROM " 
TABLE_PREFIX "post AS post
            
$hook_query_joins
            WHERE threadid = 
$threadid
                AND visible = 1
                
$hook_query_where
            ORDER BY dateline 
$postorder
            LIMIT 
$limitlower$perpage
        "
); 
-Andy.
Reply With Quote
  #5  
Old 02-21-2011, 05:24 PM
El Queso El Queso is offline
 
Join Date: Oct 2010
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You hit on a good question - "What if they're sorted by thread rating or some other factor? Where is that taken into account?"

I've been making a lot of admin moderation additions for a friend of mine who bemoans the complete lack of moderation "extras" in vBulletin. The problem there is that there are no templates to be used and I have found myself making changes to the code itself in almost all instances, when related specifically to admincp stuff.

With the user experience (in this case, specifically SHOWTHREAD.PHP) you have a bit more options because you can modify templates and put code in plugins. But you will still have situations (like this, it appears) that will cause you a problem. If vBulletin has not left you a hook and also variables to modify via the hook, then you really have no choice but to modify the PHP code itself.

In this case, as far as I'm aware vBulletin does not have any ability to set what the thread sort order field itself is - only which direction by date you can change. In the user profile you can only change the thread order, you can't set what field you want to sort on, or what calculation, etc.

In fact, as far as changing the sort order goes, you may actually be able to hook in and change variables befre the query is run. I saw this when I went back in to look and answer some of your questions. Look for "vBulletinHook::fetch_hook" to find what hook plugin events the PHP code is processing. There are various hooks for various operations within SHOWTHREAD.PHP. I know this doesn't help you much, I just metnion it in case someone else is reading to augment the information I previously posted.

But the sort order of "dateline" (yeah, it's the UNIX date/time of the post) seems to be the only field on which vBulletin, out of the box, allows us to change the sort order of the thread display query.

The only way I see for you to do this would be to change the query itself by adding a variable of your own, with your own logic to determine the sort order. It's not easy, not for the squeamish (or uncertain).

Remember that when you upgrade, there is a chance that vBulletin will have made modifications to whatever files you have changed, and therefore overwrite any changes you've made when you upgrade to a later version. If you DO make any changes, make sure you comment them in your code so you can go back and make the changes again in new versions.

BTW - I don't know if you've seen these links:

https://vborg.vbsupport.ru/showthrea...t=%24vbulletin
https://vborg.vbsupport.ru/showthrea...oduct+template

I have a hard time finding good information on really technical issues, but those two threads are valuable and not all that easy to find either. They will help you with understanding how some of the "guts" of vBulletin works.

I'm by trade a .Net developer. I found it (and still do in many ways) extremely difficult to get into the whole mindset of procedural programming and a lack of good object-oriented programming. However, the more I learn the easier it becomes to do stuff. I need to go back and remember the days of ASP programming and then it's just a matter of syntax and particulars of vBulletin's API and templates.

I don't know what your background is, but if it's a developer in another language than PHP, the hardest part of this is not only learning PHP, but tying in what vBulletin's API (through the objects it does use, like the data managers, the $vbulletin object, etc) does, their use of templates to easily modify user interface, and so on.

If you're not a developer to begin with, however, I have to say that I would not recommend modifying the PHP files to any great extent, and of course always make sure you have a backup of the original so you can things back to the way they were.
Reply With Quote
  #6  
Old 02-14-2013, 03:34 AM
Adrijan Adrijan is offline
 
Join Date: Jan 2009
Location: Croatia
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by El Queso View Post
Is there a way to change the default order in which posts are displayed when displaying a thread to users who are not logged in?

The default order is earliest posts first. I have a large forum with threads that reach hundreds (some actually thousands) and go 'way back in time. When unauthenticated users are browsing the forum, I want them to see the latest posts in a thread first so they see the latest information.

I can't find any admin options that allow me to set this default for any but logged in users. I'm assuming I will have to either use a plugin/hook or do a hack, but I can't figure out what template, code file, hook and/or variable I need to look at to make this happen.
You need add this PHP code to hook location ... showthread_start ...

Admin CP > Plugin Manager > Add new plugin >

Product : vBulletin
Hook location : showthread_start
Title : Change Display Posts Order For Guests - Newest First
Execution Order : 5
Plugin is Active : Yes
Plugin PHP Code :

PHP Code:
if ($vbulletin->userinfo['userid'] == 0) { $vbulletin->userinfo['postorder'] = 1; } 

Reply With Quote
Reply

Thread Tools
Display Modes

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 03:29 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03902 seconds
  • Memory Usage 2,227KB
  • Queries Executed 11 (?)
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
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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_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