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,973
  • Latest: NonStop
Stats
  • Total Posts: 196,166
  • Total Topics: 21,346
  • Online today: 518
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online

Users Online Today

Started by JayT, January 28, 2006, 05:47:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

exodia

Thanks G6 i found it...i really starting fallin love with TP

G6Cad

Glad to hear im not the only one :)

evilicy

Quote from: Haiduk on October 08, 2006, 05:27:00 PM
I'm also using 1.1rc2
PLEASE PLEASE PLEASE ALWAYS BACKUP FILES BEFORE CHANGING THEM!!!

Okay I played around with this idea some today.  I tried the PHPbox method and noticed that the regular Stats Box wasn't showing Online Today.  I wanted to show the Users that were online today within the Stats Box and Light an Icon if they were also currently online.  I also wanted a nice way to see what time they were online.

These are the changes I made.  They worked for me without generating errors.


Cool thanks for sharing just used it works perfect ;)

exodia

can some one help me in add this code in to this.
to add a scroll bar. i mean if the members online today goes beyond 7 then the scroll bar will be activated. like we have here in the "Some stats.."

blndsyd

Quote from: Haiduk on October 08, 2006, 05:27:00 PM
I'm also using 1.1rc2
PLEASE PLEASE PLEASE ALWAYS BACKUP FILES BEFORE CHANGING THEM!!!

Okay I played around with this idea some today.  I tried the PHPbox method and noticed that the regular Stats Box wasn't showing Online Today.  I wanted to show the Users that were online today within the Stats Box and Light an Icon if they were also currently online.  I also wanted a nice way to see what time they were online.

These are the changes I made.  They worked for me without generating errors.

in SSI.PHP add before the ?> at the end, add this:


// Shows a list of online users:  YY Guests, ZZ Users and then a list...  Also shows who was online TODAY
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))", __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);

$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", __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;
}



and in the TPortalBlocks.template.php find the TPortal_statsbox() function:

just after this:


// TPortal stats box
function TPortal_statsbox()
{
       global $context, $settings, $options, $scripturl, $txt, $modSettings;

$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet2 = '<img src="'.$settings['images_url'].'/TPdivider2.gif" alt="" border="0" style="margin:0 2px 0 0;" />';



add this:



$bullet_on = '<img src="'.$settings['images_url'].'/useron.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet_off = '<img src="'.$settings['images_url'].'/useroff.gif" alt="" border="0" style="margin:0 2px 0 0;" />';



and just after this:


if(isset($context['TPortal']['userbox']['online']))
{
// add online users
            echo '<hr /><img src="'.$settings['images_url'].'/icons/online.gif" style="margin: 0;" align="bottom" alt="" />
                 <a href="'.$scripturl.'?action=who"><b>'.$txt[158].'</b></a><br />';

            $online = ssi_whosOnline('array');
echo $bullet.$txt['tp-users'].': '.$online['num_users'];
echo '<br />'.$bullet.$txt['tp-guests'].': '.$online['guests'];
//echo '<br />'.$bullet.$txt['tp-total'].': '.$online['total_users'].'<hr />
echo '<br />'.$bullet.$txt['tp-total'].': '.$online['total_users'].'
<div style="width: 100%; ' , $online['num_users']>14 ? 'height: 23ex;overflow: auto;' : '' ,'"><br />';

foreach($online['users'] as $user)
{
echo $bullet2 , $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];
echo '<br />';
}
echo '</div>';



add this:


// add online today
            echo '<br /><b>Online Today</b><br />';

            $online = ssi_whosOnline_today('array');

echo $bullet.$txt['tp-total'].': '.$online['num_users_online_today'].'
<div style="width: 100%; ' , $online['num_users_online_today']>14 ? 'height: 23ex;overflow: auto;' : '' ,'"><br />';

foreach($online['users_online_today'] as $user)
{
if ($user['is_online'])
echo $bullet_on, $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];
else
echo $bullet_off, $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];

echo '<br />';
}
echo '</div>';




also works from a PHP block with this code:

require("/home/********PATH_TO_YOUR_FILE/public_html/smf/SSI.php");

ssi_whosOnline_today();



I am still pretty new to PHP, but I'm learning.  If you know a better and/or more efficient way to do this, please by all means tell us about it.

Worked like a charm , Thank you

Porky

Can some one help me followed everything and this is what I got: When more than one person is logged in it dupilcates everything

Porky

ok what did I due wrong Because I can't see anything wrong, I have one for each person. added files if anyone can look

blndsyd

#37
could someone take a look at this again, it doesnt seem to work with the 1.1 final upgrade
Nevermind , I got it. Thanks

bjowensbo

OK... I have 2 questions.
1.  is there a way to only put on online users today and not online users.  See it looks stuipid to have to online users and I like using the one in the stats box cause I can use the view online users link.  I tryed to see if I could do it myself and I locked up the site.  Thank goodness of backed up files.
2.  I'm also getting a forum error:

   Site Admin   Today at 09:25 AM 

caderothwelllodge.org/forum/index.php?action=tpadmin;sa=blocks 
8: Undefined index: show_stats
File: /var/www/html/forum/SSI.php
Line: 1803


line 1803:

', $return['show_stats'] & !$settings['show_sp1_info'] ? '

any ideas?

mariz26

Please help, I'm using RC3 1.1 and I ahve downloaded twice this mod and there are test failed on the files:

Installing this package will perform the following actions:
   Type    Action    Description
1.    Execute Modification    ./Sources/BoardIndex.php    Test successful
2.    Execute Modification    ./Sources/Stats.php    Test successful
3.    Execute Modification    ./Themes/default/BoardIndex.template.php    Test successful
4.    Execute Modification    ./Themes/default/Stats.template.php    Test failed
5.    Execute Modification    ./Themes/default/languages/Modifications.english.php    Test successful
6.    Execute Modification    ./Themes/default/languages/Stats.english.php    Test failed


Still the same even if I reset to default theme.

Help pls

This website is proudly hosted on Crocweb Cloud Website Hosting.