I wrote this for my forum, anyone got any comments / suggestions for what I should add next? If this is in the wrong forum, sorry!
This mod basically makes the users online more easily customisable.
############### SQL ###############
INSERT INTO `smf_settings` ( `variable` , `value` )
VALUES (
'onlineUsersFormat', '{guests}, {users}, {mods}, {gmods}, {admins} ({hidden}, {buddies})'
);
############### SQL ###############
################# FILE [/Themes/xxxxxxx/languages/index.english.php] #################
[################# Find #################]
$txt['users'] = 'Users';
[################# After, Add #################]
$txt['mod'] = 'Mod';
$txt['mods'] = 'Mods';
$txt['gmod'] = 'G-Mod';
$txt['gmods'] = 'G-Mods';
$txt['admin'] = 'Admin';
$txt['admins'] = 'Admins';
################# CLOSE [/Themes/xxxxxxx/languages/index.english.php] #################
################# FILE [/Themes/xxxxxxx/BoardIndex.template.php] #################
[################# Find #################]
echo '
', $context['show_who'] ? '<a href="' . $scripturl . '?action=who">' : '', $context['num_guests'], ' ', $context['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ' . $context['num_users_online'], ' ', $context['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
// Handle hidden users and buddies.
if (!empty($context['num_users_hidden']) || ($context['show_buddies'] && !empty($context['show_buddies'])))
{
echo ' (';
// Show the number of buddies online?
if ($context['show_buddies'])
echo $context['num_buddies'], ' ', $context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies'];
// How about hidden users?
if (!empty($context['num_users_hidden']))
echo $context['show_buddies'] ? ', ' : '', $context['num_users_hidden'] . ' ' . $txt['hidden'];
echo ')';
}
echo $context['show_who'] ? '</a>' : '', '
<div class="smalltext">';
[################# Replace #################]
if ($context['show_who'])
{
# Load what we need from $modSettings if you will...
$useAdmins = preg_match('~\{admins\}~i', $modSettings['onlineUsersFormat']);
$useGMods = preg_match('~\{gmods\}~i' , $modSettings['onlineUsersFormat']);
$useMods = preg_match('~\{mods\}~i' , $modSettings['onlineUsersFormat']);
$useUsers = preg_match('~\{users\}~i' , $modSettings['onlineUsersFormat']);
$useGuests = preg_match('~\{guests\}~i', $modSettings['onlineUsersFormat']);
$useHidden = preg_match('~\{hidden\}~i' , $modSettings['onlineUsersFormat']);
$useBuddies = preg_match('~\{buddies\}~i', $modSettings['onlineUsersFormat']);
$endOutputString = $modSettings['onlineUsersFormat'];
# No ned to check for $useHidden and $useBuddies as they are extra.
if (!$useAdmins && !$useGMods && !$useMods && !$useUsers && !$useGuests)
{
# Seems something has screwed up.
$useUsers = true;
$useGuests = true;
}
$context['num_admins_online'] = 0;
$context['num_gmods_online'] = 0;
$context['num_mods_online'] = 0;
# Count users online for each group.
foreach ($context['users_online'] as $Key)
{
if (((string)$Key['group'] == '1') && $useAdmins)
{
++$context['num_admins_online'];
}
else if (((string)$Key['group'] == '2') && $useGMods)
{
++$context['num_gmods_online'];
}
else if (((string)$Key['group'] == '3') && $useMods)
{
++$context['num_mods_online'];
}
}
# Deal with the numbers.
if ($useAdmins)
$context['num_users_online'] -= $context['num_admins_online'];
if ($useGMods)
$context['num_users_online'] -= $context['num_gmods_online'];
if ($useMods)
$context['num_users_online'] -= $context['num_mods_online'];
# Text up!
$adminText = $context['num_admins_online'] . ' ' . (($context['num_admins_online'] == 1) ? $txt['admin'] : $txt['admins']);
$gmodsText = $context['num_gmods_online'] . ' ' . (($context['num_gmods_online'] == 1) ? $txt['gmod'] : $txt['gmods']);
$modsText = $context['num_mods_online'] . ' ' . (($context['num_mods_online'] == 1) ? $txt['mod'] : $txt['mods']);
$usersText = $context['num_users_online'] . ' ' . (($context['num_users_online'] == 1) ? $txt['user'] : $txt['users']);
$guestsText = $context['num_guests'] . ' ' . (($context['num_guests'] == 1) ? $txt['guest'] : $txt['guests']);
$hiddenText = $context['num_users_hidden'] . ' ' . $txt['hidden'];
$buddyText = $context['num_buddies'] . ' ' . (($context['num_buddies'] == 1) ? $txt['buddy'] : $txt['buddies']);
# Replace into final string.
if (!$context['show_buddies'])
$endOutputString = preg_replace('~(, )?{buddies\}~i', '', $endOutputString);
else
$endOutputString = preg_replace('~{buddies\}~i' , $buddyText , $endOutputString);
if ($useAdmins)
$endOutputString = preg_replace('~{admins\}~i' , $adminText , $endOutputString);
if ($useGMods)
$endOutputString = preg_replace('~{gmods\}~i' , $gmodsText , $endOutputString);
if ($useMods)
$endOutputString = preg_replace('~{mods\}~i' , $modsText , $endOutputString);
if ($useUsers)
$endOutputString = preg_replace('~{users\}~i' , $usersText , $endOutputString);
if ($useGuests)
$endOutputString = preg_replace('~{guests\}~i' , $guestsText , $endOutputString);
if ($useHidden)
$endOutputString = preg_replace('~{hidden\}~i' , $hiddenText , $endOutputString);
echo '
';
echo '<a href="' . $scripturl . '?action=who">';
# Do we need to show these?
echo $endOutputString;
echo '</a><br />';
}
else
{
echo '<div class="smalltext">';
}
################# CLOSE [/Themes/xxxxxxx/BoardIndex.template.php] #################
Sorry, have not had time to make a proper installer yet.
Edit: Live example here (http://standards.spiralmindsinc.com/Forums/).
Cheers,
Ryan Jones