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'] > 1 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