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: 1
  • Guests: 447
  • Total: 448
  • NonStop

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.

akulion

hey just wanted to ask is there a way i can have a "horizontal layout" as opposed to a vertical one?

Cos my page blocks are sure piling up and its looking crazy now :P

rebelrose

#21
You could also try something like this in a php block: It will list all the users horizonally, not in a list format. Best of all you don't need to change any code in the templates.

without a image


echo '
<span class="smalltext">';
ssi_whosOnline();
echo '</span>';



with a image:


echo '<a href="'.$scripturl.'?action=who"><img src="'.$settings['actual_images_url'].'/icons/online.gif'.'"  /> <b>'.$txt[158].'</b></a><br>
<span class="smalltext">';
ssi_whosOnline();
echo '</span>';


akulion


rebelrose

 :coolsmiley: Anyone who wants to use it  ;)

akulion

oohhh lol

i was just askin cos i wanted a horizontal lay out

the vertical one is getting a bit crowded on my site

rebelrose

Well give it a shot in a horizontal layout and see if you like it.

exodia

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.

hey i tired this code on rc3 work ok. but i cant find TPortalBlocks.template.php. i just edited SSI.php and copied this into phpbox "ssi_whosOnline_today(); ". can someone tell me how to do like he told. am using smf 1.1 rc3 and tp v0.9.5

regards

G6Cad

If the theme you edit the code in doesent have it's own TPortalBlock.template.php file, it fetch the one from the default themes folder instead.
So if you missing out on some code, thats where you have to add the code in.

exodia

Quote from: G6 on October 17, 2006, 07:26:57 AM
If the theme you edit the code in doesent have it's own TPortalBlock.template.php file, it fetch the one from the default themes folder instead.
So if you missing out on some code, thats where you have to add the code in.
G6 am sorry i dint understand

G6Cad

If the othet theme you have installed dosent have the TPortalBlocks.template.php, the theme will look for the file in the default theme directory instead.
So if you add code in that TPortalBlocks.template.php need (if it doesent have it already as all mods installs to the default theme directory) you have to add it in the file in the default directory

This website is proudly hosted on Crocweb Cloud Website Hosting.