SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: nathan89 on February 03, 2009, 07:40:45 PM

Title: Whos online Block
Post by: nathan89 on February 03, 2009, 07:40:45 PM
What code would I use to display whos online exactly how it is displayed below the forum with the membergroup key? 

I found this code however it doesn't display the other information.
Code: [Select]
global $boarddir;
require_once($boarddir . '/SSI.php');
ssi_whosOnline();


Users Online
    45 Guests, 9 User
Users active in past 15 minutes:
user 
[Administrator]  [AdminUser]  [Global Moderator]  [Supporter]
Most Online Today: . Most Online Ever:
Title: Re: Whos online Block
Post by: Nathaniel on February 04, 2009, 01:59:10 AM
Put this code (for SMF2) into a new PHP Block:
Code: [Select]

global $txt, $modSettings, $scripturl, $context, $sourcedir;

// Get the user online list.
require_once($sourcedir . '/Subs-MembersOnline.php');
$membersOnlineOptions = array(
'show_hidden' => allowedTo('moderate_forum'),
'sort' => 'log_time',
'reverse_sort' => true,
);
$context += getMembersOnlineStats($membersOnlineOptions);

// "Users online" - in order of activity.
echo '
<div class="infocenter_section">
<div class="windowbg">
<div class="windowbg2 sectionbody">
', $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.
$bracketList = array();
if ($context['show_buddies'])
$bracketList[] = $context['num_buddies'] . ' ' . ($context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
if (!empty($context['num_spiders']))
$bracketList[] = $context['num_spiders'] . ' ' . ($context['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
if (!empty($context['num_users_hidden']))
$bracketList[] = $context['num_users_hidden'] . ' ' . $txt['hidden'];

if (!empty($bracketList))
echo ' (' . implode(', ', $bracketList) . ')';

echo $context['show_who'] ? '</a>' : '', '
<div class="smalltext">';

// Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
if (!empty($context['users_online']))
{
echo '
', sprintf($txt['users_active'], $modSettings['lastActive']), ':<br />', implode(', ', $context['list_users_online']);

// Showing membergroups?
if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
echo '
<br />[' . implode(']&nbsp;&nbsp;[', $context['membergroups']) . ']';
}

echo '
</div>
<hr />
<div class="smalltext">
', $txt['most_online_today'], ': <b>', $modSettings['mostOnlineToday'], '</b>.
', $txt['most_online_ever'], ': ', $modSettings['mostOnline'], ' (' , timeformat($modSettings['mostDate']), ')
</div>
</div>
</div>
</div>';
Title: Re: Whos online Block
Post by: nathan89 on February 04, 2009, 07:09:04 AM
Great! Thank you very much.
Title: Re: Whos online Block
Post by: dwd2000 on February 12, 2009, 10:53:44 PM
Works great.  ;D

Can you do the same for Calendar events? I'm turning the calendar into a sort of a "Today in History" thing.
Title: Re: Whos online Block
Post by: Ares on January 09, 2011, 02:15:50 AM
updated for 2.0 RC4
Code: [Select]
global $txt, $modSettings, $scripturl, $context, $sourcedir;
   
   // Get the user online list.
   require_once($sourcedir . '/Subs-MembersOnline.php');
   $membersOnlineOptions = array(
      'show_hidden' => allowedTo('moderate_forum'),
      'sort' => 'log_time',
      'reverse_sort' => true,
   );
   $context += getMembersOnlineStats($membersOnlineOptions);
   
   // "Users online" - in order of activity.
   echo '
         <div class="infocenter_section">
            <div class="windowbg">
               <div class="windowbg2 sectionbody">
                  ', $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.
   $bracketList = array();
   if ($context['show_buddies'])
      $bracketList[] = $context['num_buddies'] . ' ' . ($context['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
   if (!empty($context['num_spiders']))
      $bracketList[] = $context['num_spiders'] . ' ' . ($context['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
   if (!empty($context['num_users_hidden']))
      $bracketList[] = $context['num_users_hidden'] . ' ' . $txt['hidden'];

   if (!empty($bracketList))
      echo ' (' . implode(', ', $bracketList) . ')';

   echo $context['show_who'] ? '</a>' : '', '
                  <div class="smalltext">';

   // Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
   if (!empty($context['users_online']))
   {
      echo '
                     ', sprintf($txt['users_active'], $modSettings['lastActive']), ':<br />', implode(', ', $context['list_users_online']);

      // Showing membergroups?
global $context, $settings;
$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());

      if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
   echo '
      <br />[' . implode(']&nbsp;&nbsp;[', $context['membergroups']) . ']';
   }

   echo '
                  </div>
                  <hr />
                  <div class="smalltext">
                     ', $txt['most_online_today'], ': <b>', $modSettings['mostOnlineToday'], '</b>.
                     ', $txt['most_online_ever'], ': ', $modSettings['mostOnline'], ' (' , timeformat($modSettings['mostDate']), ')
</div>
               </div>
            </div>
         </div>';
SimplePortal 2.3.8 © 2008-2024, SimplePortal