Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 19, 2022, 04:49:19 AM

Login with username, password and session length
Members
  • Total Members: 3843
  • Latest: Tricky
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 51
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 42
Total: 42

Author Topic: Users Online Today  (Read 28219 times)

0 Members and 1 Guest are viewing this topic.

JayT

  • Guest
Users Online Today
« on: January 27, 2006, 10:47:26 PM »
Does anyone know what the code would be to add this to a block. Right now it is a mod for SMF.

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Users Online Today
« Reply #1 on: January 27, 2006, 10:59:53 PM »
I haven't taken a real good look. I'm not even sure if this will work. If you have the mod working currently in the theme you're using. Try adding this code to a phpbox.
Code: [Select]
global $context, $settings, $options, $scripturl, $txt;
echo '<table>
<tr>
<td class="catbg" colspan="2">', $txt['uot_users_online_today_title'], '</td>
</tr><tr>
<td class="windowbg" width="20" valign="middle" align="center">
<img src="', $settings['images_url'], '/icons/online.gif" alt="', $txt[158], ' ', $txt['uot_users_online_today_title'], '" border="0" />
</td>
<td class="windowbg2" width="100%">';

echo '
<div class="smalltext">';

echo $context['num_users_online_today'], ' ', $context['num_users_online_today'] == 1 ? $txt['uot_user_online_today'] : $txt['uot_users_online_today'];

if (!empty($context['users_online_today']))
echo ':<br />', implode(', ', $context['list_users_online_today']);

echo '
<br />', $context['show_stats'] && !$settings['show_sp1_info'] ? '
<a href="' . $scripturl . '?action=stats">' . $txt['smf223'] . '</a>' : '', '
</div>
</td>
</tr></table>';
« Last Edit: January 27, 2006, 11:02:29 PM by IchBinâ„¢ »

JayT

  • Guest
Re: Users Online Today
« Reply #2 on: January 28, 2006, 12:52:37 PM »
That doesn't work

core

  • Guest
Re: Users Online Today
« Reply #3 on: February 02, 2006, 02:29:40 AM »
it does work... but only on forum pages

what do we need to change to make it work on all TP pages?
« Last Edit: February 02, 2006, 02:32:02 AM by core »

snork13

  • Guest
Re: Users Online Today
« Reply #4 on: February 02, 2006, 08:36:42 PM »
ok, this be be done a # of ways...

oh ya, i tested on 1.1rc2 :P

ALWAYS MAKE BACKUPS OF FILES :)

/SSI.php

re-write the function "function ssi_whosOnline" to what's below

Code: [Select]
// Shows a list of online users:  YY Guests, ZZ Users and then a list...
function ssi_whosOnline($output_method = 'echo')
{
global $txt, $scripturl, $db_prefix, $ID_MEMBER, $user_info, $sourcedir;
global $modSettings, $context, $settings;

// 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'];

if ($output_method != 'echo')
return $return;

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__);

$context['users_online_today'] = array();
$context['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>';
}

$context['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,
'hidden' => empty($row['showOnline']),
);

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

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

$context['num_users_online_today'] = count($context['users_online_today']);
 

$context['num_users_online'] = count($context['users_online']) + $context['num_users_hidden'];

echo '
<div class="smalltext">';

echo $context['num_users_online_today'], ' ', $context['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($context['users_online_today']))
echo '
', 'online today', ':<br />', implode(', ', $context['list_users_online_today']);

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

}

then in a phpbox add:

Code: [Select]
require("/home/********PATH_TO_YOUR_FILE/public_html/forum/SSI.php");

ssi_whosOnline();


 :o

[attachment deleted by admin]
« Last Edit: February 02, 2006, 09:06:34 PM by snork13 »

houston

  • Guest
Re: Users Online Today
« Reply #5 on: February 03, 2006, 12:00:32 AM »
Or if you want to keep any existing modifications to the SSI.php file (ie: Googlebot) just add another function by renaming
Code: [Select]
function ssi_whosOnline($output_method = 'echo')
to
Code: [Select]
function ssi_whosOnline_tp($output_method = 'echo')
and then add that function to the bottom of the SSI.php file and save it to your server

Then do the last step that snork13 suggested at the bottom of his post.

snork13

  • Guest
Re: Users Online Today
« Reply #6 on: February 03, 2006, 06:34:19 AM »
yes, as houston said, you could just add a new function if you wanted too.

core

  • Guest
Re: Users Online Today
« Reply #7 on: February 03, 2006, 09:34:35 AM »
great stuff! works great thanks!!!!!

insanemustang

  • Guest
Re: Users Online Today
« Reply #8 on: February 05, 2006, 02:34:15 PM »
I'm not sure what I am doing wrong but I cannot get this to work...

I got my forum upgraded to RC2, so that is not the problem anymore.

I'm not real familiar with SMF so the instructions above are pretty confusing to me.

Is there any way I can have better/detailed instructions for this?

Thank you in advance.
« Last Edit: February 05, 2006, 03:08:01 PM by insanemustang »

core

  • Guest
Re: Users Online Today
« Reply #9 on: March 04, 2006, 07:31:29 PM »
aloha!

bad news about above code by Snork... I have been clearing up errors in the forum error log and I found 3 SSI errors wich come from above code!

errors:
Code: [Select]


8: Undefined index: show_stats
File: /home/resellers/841289/841289/corenation.com/www/smf/SSI.php
Line: 1711

8: Undefined index: num_users_hidden
File: /home/resellers/841289/841289/corenation.com/www/smf/SSI.php
Line: 1698

8: Undefined index: users_online
File: /home/resellers/841289/841289/corenation.com/www/smf/SSI.php
Line: 1698

as soon as I turn the block off - no errors!

please help resolve!

cheers,

core