Thread: Forum Display Enhancements - Sort View Forum Leaders VB 4.1.11
View Single Post
  #6  
Old 10-18-2014, 04:52 PM
Voodoo262 Voodoo262 is offline
 
Join Date: Dec 2009
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you to GrabMyWrist for writing this up. I was able to set this mod up to my liking on our site. Here are a few notes for people that are having issues.

First of all, when using the HTML comments (<!-- x -->) to embed/define the sort order, remember that PHP (like most computer software) uses pure ASCII sorting, not numeric sorting, when sorting strings of characters. Therefore, "10" will come before "2" (because it compares "1" against "2"), "3456" will come before "7" (because it compares "3" against "7"), and so forth. If you want the mod to obey your sort order, all of the numbers must have the same number of digits. So if you have at least 10 usergroups you want to display, I would recommend using 2 digits for all the numbers, for example:
HTML Code:
<!-- 00 -->Administrators
<!-- 01 -->Super Moderators
<!-- 02 -->Moderators
etc

Second, when you modify your showgroups.php, make sure you also delete the "if" statement before the block of code that GrabMyWrist posted, otherwise you risk breaking the page completely due to syntax and/or runtime errors, because PHP will be interpreting the code as follows:
PHP Code:
if ($vbulletin->options['forumleaders'] == 1)
{
    
$navpopup = array(
        
'id'    => 'showgroups_navpopup',
        
'title' => $vbphrase['show_groups'],
        
'link'  => 'showgroups.php' $vbulletin->session->vars['sessionurl_q'],
    );

...Meaning it will only initialize and set the value of the $navpopup variable if the preceding condition is true. This is dangerous.

Here is the full block of code you'll want to delete. Actually, what I did was enclose it in comments by placing a "/*" before and a "*/" after, effectively accomplishing the same thing but without getting rid of the original code:
PHP Code:
if ($vbulletin->options['forumleaders'] == 1)
{
    
// get moderators **********************************************************
    
$moderators $db->query_read_slave("
        SELECT user.*,
            moderator.forumid,
            usertextfield.buddylist,
            " 
. ($show['locationfield'] ? 'userfield.field2,' '') . "
            IF(user.displaygroupid = 0, user.usergroupid, user.displaygroupid) AS displaygroupid
            " 
. ($vbulletin->options['avatarenabled'] ? ",avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight, customavatar.width_thumb AS avwidth_thumb, customavatar.height_thumb AS avheight_thumb, filedata_thumb, NOT ISNULL(customavatar.userid) AS hascustom" "") . "
        
$hook_query_fields
        FROM " 
TABLE_PREFIX "moderator AS moderator
        INNER JOIN " 
TABLE_PREFIX "user AS user USING(userid)
        INNER JOIN " 
TABLE_PREFIX "userfield AS userfield ON(userfield.userid = user.userid)
        INNER JOIN " 
TABLE_PREFIX "usertextfield AS usertextfield ON(usertextfield.userid=user.userid)
        " 
. ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " TABLE_PREFIX "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " TABLE_PREFIX "customavatar AS customavatar ON(customavatar.userid = user.userid)" "") . "
        
$hook_query_joins
        WHERE moderator.forumid <> -1
        
$hook_query_where
    "
);
    
$modcache = array();
    while (
$moderator $db->fetch_array($moderators))
    {
        if (!isset(
$modcache["$moderator[username]"]))
        {
            
$modcache["$moderator[username]"] = $moderator;
        }
        
$modcache["$moderator[username]"]['forums'][] = $moderator['forumid'];
    }
    unset(
$moderator);
    
$db->free_result($moderators);

    if (
is_array($modcache))
    {
        
$showforums true;
        
uksort($modcache'strnatcasecmp'); // alphabetically sort moderator usernames
        
foreach ($modcache AS $moderator)
        {
            
$premodforums = array();
            foreach (
$moderator['forums'] AS $forumid)
            {
                if (
$vbulletin->forumcache["$forumid"]['options'] & $vbulletin->bf_misc_forumoptions['active'] AND (($vbulletin->forumcache["$forumid"]['showprivate'] > OR (!$vbulletin->forumcache["$forumid"]['showprivate'] AND $vbulletin->options['showprivateforums'])) OR ($vbulletin->userinfo['forumpermissions']["$forumid"] & $vbulletin->bf_ugp_forumpermissions['canview'])))
                {
                    
$forumtitle $vbulletin->forumcache["$forumid"]['title'];
                    
$premodforums["$forumid"] = $forumtitle;
                }
            }
            if (empty(
$premodforums))
            {
                continue;
            }

            
$clc 0;
            
$modforums = array();
            
uasort($premodforums'strnatcasecmp'); // alphabetically sort moderator usernames
            
foreach($premodforums AS $forumid => $forumtitle)
            {
                
$foruminfo = array(
                    
'forumid' => $forumid,
                    
'title'   => $forumtitle,
                );

                (
$hook vBulletinHook::fetch_hook('showgroups_forum')) ? eval($hook) : false;

                
$clc++;
                
$foruminfo['comma'] = $vbphrase['comma_space'];
                
$modforums[$clc] = $foruminfo;
            }

            
// Last element
            
if ($clc
            {
                
$modforums[$clc]['comma'] = '';
            }

            
$moderator process_showgroups_userinfo($moderator);

            if (
$vbulletin->options['enablepms'] AND $vbulletin->userinfo['permissions']['pmquota'] AND ($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel']
                     OR (
$moderator['receivepm'] AND $moderator['permissions']['pmquota']
                     AND (!
$moderator['receivepmbuddies'] OR can_moderate() OR strpos($moderator[buddylist] "' ' $vbulletin->userinfo['userid'] . ' ') !== false))
             ))
            {
                
$show['pmlink'] = true;
            }
            else
            {
                
$show['pmlink'] = false;
            }

            if (
$moderator['showemail'] AND $vbulletin->options['displayemails'] AND (!$vbulletin->options['secureemail'] OR ($vbulletin->options['secureemail'] AND $vbulletin->options['enableemail'])) AND $vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canemailmember'] AND $vbulletin->userinfo['userid'])
            {
                
$show['emaillink'] = true;
            }
            else
            {
                
$show['emaillink'] = false;
            }

            (
$hook vBulletinHook::fetch_hook('showgroups_usergroup')) ? eval($hook) : false;

            
$templater vB_Template::create('showgroups_usergroupbit');
                
$templater->register('modforums'$modforums);
                
$templater->register('showforums'$showforums);
                
$templater->register('user'$moderator); // Needs to be 'user' because we are using the same template as above.
                
$templater->register('xhtml_id', ++$xhtmlid2);
            
$moderatorbits .= $templater->render();
        }
    }
}

// ******************************************************* 


Finally, after you have updated the usergroup titles, you'll have to reset the group cache in order for the sorting to take effect. This can be accomplished by running the following SQL query. The cache will be rebuilt the next time you reload the page:
Code:
delete from cache where cacheid = 'showgroups.groupcache';

I have attached my version of showgroups.php (vB 4.2.2) for your convenience (make sure you update your vBulletin License at the top). It also includes another optimization that moves the sorting from the PHP into the MySQL (because after all, what's the point of caching if you're gonna sort the cache every time anyways? )

This ends today's programming lesson
Attached Files
File Type: php showgroups.php (13.2 KB, 16 views)
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01725 seconds
  • Memory Usage 1,906KB
  • Queries Executed 12 (?)
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
  • (1)bbcode_code
  • (1)bbcode_html
  • (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_attachment
  • (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_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete