TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,993
  • Total Topics: 21,324
  • Online today: 388
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 337
  • Total: 337

Users Logged In Today on TP Stats

Started by weimi, June 23, 2008, 09:25:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JPDeni

Use this instead


function ssi_whosOnline_today($output_method = 'echo')
{
   global $txt, $scripturl, $db_prefix, $ID_MEMBER, $user_info, $sourcedir;
   global $modSettings, $settings;
   //global $context;

   // Load the users online right now.
   $result = db_query("
      SELECT
         lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
         mg.onlineColor, mg.ID_GROUP
      FROM {$db_prefix}log_online AS lo
         LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
         LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
  WHERE mem.showOnline = 1", __FILE__, __LINE__);

   $return['users'] = array();
   $return['guests'] = 0;
   $return['hidden'] = 0;
   $return['buddies'] = 0;
   $show_buddies = !empty($user_info['buddies']);

   while ($row = mysql_fetch_assoc($result))
   {
      if (!isset($row['realName']))
         $return['guests']++;
      elseif (!empty($row['showOnline']) || allowedTo('moderate_forum'))
      {
         // Some basic color coding...
         if (!empty($row['onlineColor']))
            $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a>';
         else
            $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';

         // Bold any buddies.
         if ($show_buddies && in_array($row['ID_MEMBER'], $user_info['buddies']))
         {
            $return['buddies']++;
            $link = '<b>' . $link . '</b>';
         }
         
         $return['users'][$row['logTime'] . $row['memberName']] = array(
            'id' => $row['ID_MEMBER'],
            'username' => $row['memberName'],
            'name' => $row['realName'],
            'group' => $row['ID_GROUP'],
            'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
            'link' => $link,
            'hidden' => empty($row['showOnline']),
            'is_last' => false,
         );
      }
      else
         $return['hidden']++;
   }
   mysql_free_result($result);

   if (!empty($return['users']))
   {
      krsort($return['users']);
      $userlist = array_keys($return['users']);
      $return['users'][$userlist[count($userlist) - 1]]['is_last'] = true;
   }
   $return['num_users'] = count($return['users']) + $return['hidden'];
   $return['total_users'] = $return['num_users'] + $return['guests'];

   // echo to screen?
   if ($output_method == 'echo')
   {     
      echo '
         <div class="smalltext">';

      echo '
         ', $return['guests'], ' ', $return['guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', $return['num_users'], ' ', $return['num_users'] == 1 ? $txt['user'] : $txt['users'];

      // Hidden users, or buddies?
      if ($return['hidden'] > 0 || $show_buddies)
         echo '
            (' . ($show_buddies ? ($return['buddies'] . ' ' . ($return['buddies'] == 1 ? $txt['buddy'] : $txt['buddies'])) : '') . ($show_buddies && $return['hidden'] ? ', ' : '') . (!$return['hidden'] ? '' : $return['hidden'] . ' ' . $txt['hidden']) . ')';

      echo '<br />';
      foreach ($return['users'] as $user)
         echo $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'], $user['is_last'] ? '' : ', ';
     
      echo'</div><br /><hr>';
   }
     
   // Load the users online today.
   $nowdate = getdate(forum_time(false));
   $midnight = mktime(0, 0, 0, $nowdate['mon'], $nowdate['mday'], $nowdate['year']) - ($modSettings['time_offset'] * 3600);

//   $midnight = strtotime('24 hours ago');
   $s = strpos($user_info['time_format'], '%S') === false ? '' : ':%S';
   if (strpos($user_info['time_format'], '%H') === false && strpos($user_info['time_format'], '%T') === false)
      $time_fmt = '%I:%M' . $s . ' %p';
   else
      $time_fmt = '%H:%M' . $s;

   $result = db_query("
      SELECT
         mem.ID_MEMBER, mem.lastLogin, mem.realName, mem.memberName, mem.showOnline,
         mg.onlineColor, mg.ID_GROUP, mg.groupName
      FROM {$db_prefix}members AS mem
         LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
      WHERE mem.lastLogin >= $midnight
  AND mem.showOnline = 1", __FILE__, __LINE__);

   $return['users_online_today'] = array();
   $return['list_users_online_today'] = array();

   while ($row = mysql_fetch_assoc($result))
   {
      $userday = strftime('%d', forum_time(true));
      $loginday = strftime('%d', forum_time(true, $row['lastLogin']));
      $yesterday = $userday == $loginday ? '' : $txt['uot_yesterday'];
   
      $lastLogin = $yesterday . strftime($time_fmt, forum_time(true, $row['lastLogin']));
      $title = (allowedTo('moderate_forum') || !empty($row['showOnline'])) ? ' title="' . $lastLogin . '"' : '';

      // Some basic color coding...
      if (!empty($row['onlineColor']))
         $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '"' . $title . ' style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a>';
      else
         $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '"' . $title . '>' . $row['realName'] . '</a>';

      $is_buddy = in_array($row['ID_MEMBER'], $user_info['buddies']);
      if ($is_buddy)
      {
         $link = '<b>' . $link . '</b>';
      }
           
      $is_online = false;
      if ($return['num_users']>0)
      {
         foreach($return['users'] as $user)
         {
            if ($user['id'] == $row['ID_MEMBER'])
            {
               $is_online = true;
            }
         }
      }
     
      $return['users_online_today'][$row['lastLogin'] . $row['memberName']] = array(
         'id' => $row['ID_MEMBER'],
         'username' => $row['memberName'],
         'name' => $row['realName'],
         'group' => $row['ID_GROUP'],
         'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
         'link' => $link,
         'is_buddy' => $is_buddy,
         'is_online' => $is_online,
         'hidden' => empty($row['showOnline']),
      );

      $return['list_users_online_today'][$row['lastLogin'] . $row['memberName']] = (empty($row['showOnline']) && allowedTo('moderate_forum')) ? '<i>' . $link . '</i>' : $link;
   }
   mysql_free_result($result);

   krsort($return['users_online_today']);
   krsort($return['list_users_online_today']);

   $return['num_users_online_today'] = count($return['users_online_today']);
   
   // echo to screen?
   if ($output_method == 'echo')
   {     
      echo '
         <div class="smalltext">';

      echo $return['num_users_online_today'], ' ', $return['num_users_online_today'] == 1 ? strtolower($txt['user']) : strtolower($txt['users']);

      // Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
      if (!empty($return['users_online_today']))
         echo '
            ', 'online today', ':<br />', implode(', ', $return['list_users_online_today']);

      echo '
            <br />', $return['show_stats'] && !$settings['show_sp1_info'] ? '
            <a href="' . $scripturl . '?action=stats">' . $txt['smf223'] . '</a>' : '', '
         </div>';
   }
   else
      return $return;
}


QuoteAlso.. when i try to del/change in  TPBlocks.template

Don't change TPBlocks.template.

alhaudhie

#31
tq soo much.. how can i apply this code to tpblock online users to hide hidden users from showing to moderator that can menage members? what must i change in TPBlocks.template or ssi.php?

ZarPrime

Actually, I'm having trouble understanding why you would want to remove all trace of hidden members from your site from Admins and Moderators.  Don't you want to know who is prowling around your site so that you can check up on them once in a while to make sure they are not up to no good?  This is confusing.

ZarPrime

JPDeni

Quote from: Mrcare on January 28, 2010, 04:48:03 AM
tq soo much.. how can i apply this code to tpblock online users to hide hidden users from showing to moderator that can menage members? what must i change in TPBlocks.template or ssi.php?
Just use the code in a php block.

TheCodfather

were in the SSi file do u add this ?

IchBin

You can add that whole chunk of code right before the closing PHP tag ?> at the end of the file.

TheCodfather

just did that and i get a white blank screen when saving the block, when i remove code from SSI.PHP it works again.

i must be doing something wrong hmmmm

have attached the SSI.PHP if any 1 cares to have a look be grateful thanks

TheCodfather

no 1 willing to help i keep adding the above code and i keep getting a white page

TheCodfather

also now when i added the smaller code to a php block getting this error

Unknown column 'lo.logTime' in 'field list'
File: /home/goseafis/public_html/SSI.php
Line: 1993

IchBin

This code is only working with SMF1.x right now. The code needs to be converted to work with SMF2. Some of the rows in the tables have changed names as well as the query structure. I don't have the time to do this for you right now.

This website is proudly hosted on Crocweb Cloud Website Hosting.