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

Recent

Welcome to TinyPortal. Please login or sign up.

April 18, 2024, 05:50:22 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,164
  • Total Topics: 21,219
  • Online today: 203
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 134
  • Total: 135
  • @rjen

Online Today Snipe.

Started by -BeNt-, November 18, 2006, 10:53:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

-BeNt-

Ok I took it and I'm modifying it and adding it into the statsbox.Thats done.But instead of it listing everyone who was online today how can I change this code to only display the last 10 members?Or simply strip out anyone over 10?Here is the code I'm using as is....

// 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']>20 ? 'height: 40ex;overflow: auto;' : '' ,'"><br />';

foreach($online['users_online_today'] as $user)
{
if ($user['is_online'])
echo '<img src="/Themes/TP_counter-strike/images/useron.gif">' , $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];
else
echo '<img src="/Themes/TP_counter-strike/images/useroff.gif">' , $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];

echo '<br />';

Crip

I'm not a code monkey but looks like you could change it like 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']>10 ? 'height: 40ex;overflow: auto;' : '' ,'"><br />';

foreach($online['users_online_today'] as $user)
{
if ($user['is_online'])
echo '<img src="/Themes/TP_counter-strike/images/useron.gif">' , $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];
else
echo '<img src="/Themes/TP_counter-strike/images/useroff.gif">' , $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];

echo '<br />';


Not sure about this...
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



JPDeni

It'll probably work if you change

foreach($online['users_online_today'] as $user)
{


to


count($online['users_online_today']) > 10 ? $max = 10 : $max = count($online['users_online_today']);
for ($i = 0; $i < $max; ++$i)
{
 $user = $online['users_online_today'][$i]


That's just a guess, though, because I don't have the ssi_whosOnline_today function to be able to know for sure. This will probably work if the most recent ones are printed first.

-BeNt-

Thanks for the help so far guys.

To crip, when you change that number that's only how many it shows but then it put a scroll box in there.That was the first thing I tried lol.

To JPDeni, I tried your coding changes,I've been messing about with it for awhile today,and it doesn't seem to work.All it will pull up with that code change is the title bar.

Here's the ssi functions for it.........

// 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;
}


Thanks alot for your help so far.Hopefully either you guys or someone who has done this will come along with some insight.I'm done pulling my hair out since I have none left  :uglystupid2:

JPDeni

I see.

Try changing (from the original)

foreach($online['users_online_today'] as $user)
{


to


$i = 0;
foreach($online['users_online_today'] as $user)
{
  ++$i;
  if ($i > 10)
    break;

-BeNt-

Awesome I finally got enough time off from the Holidays to check your code out.It works wonderfully thanks alot for your help JPDeni!Heres what she looks like after you put this code in a php box!

global $db_prefix, $txt, $scripturl, $modSettings;

$today = strtotime("today");
date('j') == 1 ? $thismonth = $today : $thismonth = strtotime(date('F') . ' 1');
date('l') == 'Sunday' ? $thisweek = $today : $thisweek = strtotime('last Sunday');
date('M') == 'January' ? $thisyear = $thismonth : $thisyear = strtotime('January 1');

$query = db_query("SELECT
COUNT(dateRegistered > $thisyear OR NULL) as year,
COUNT(dateRegistered > $thismonth OR NULL) as month,
COUNT(dateRegistered > $thisweek OR NULL) as week,
COUNT(dateRegistered > $today OR NULL) as today
FROM {$db_prefix}members
WHERE is_activated = 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($query);

settype($row['today'], "integer");
settype($row['week'], "integer");
settype($row['month'], "integer");

echo '<span class="smalltext">';
echo '<img src="/Themes/TP_counter-strike/images/icons/members.gif"><b><a href="/index.php?action=mlist"> Members </a></b><br />';
echo '<img src="/Themes/TP_counter-strike/images/TPdivider.gif"> Total Members: ', $modSettings['totalMembers'],'<br />';
echo '<img src="/Themes/TP_counter-strike/images/TPdivider.gif"> Latest: <a href="', $scripturl, '?action=profile;u=', $modSettings['latestMember'], '"><b>', $modSettings['latestRealName'], '</b></a><br>';
echo '<img src="/Themes/TP_counter-strike/images/TPdivider.gif"> New This Month: ', $row['month'],'<br />';
echo '<img src="/Themes/TP_counter-strike/images/TPdivider.gif"> New This Week: ', $row['week'],'<br />';
echo '<img src="/Themes/TP_counter-strike/images/TPdivider.gif"> New Today: ', $row['today'];

echo ' <table>
                  <hr /><img src="'.$settings['images_url'].'/icons/info.gif" style="margin: 0;" align="bottom" alt="" />
                 <a href="'.$scripturl.'?action=stats"><b>'.$txt['tp-stats'].'</b></a>
                                  <br /><img src="/Themes/TP_counter-strike/images/TPdivider.gif"> Total Posts: '.$modSettings['totalMessages']. '
                                  <br /><img src="/Themes/TP_counter-strike/images/TPdivider.gif"> Total Topics: '.$modSettings['totalTopics']. '
                                  <br /><img src="/Themes/TP_counter-strike/images/TPdivider.gif"> Most Ever Online: '.$modSettings['mostOnline'].'<br />
  ('.timeformat($modSettings['mostDate']).')
  ';

       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 />
<div style="width: 100%; ' , $online['num_users']>10 ? 'height: 23ex;overflow: auto;' : '' ,'">';

     
// add online today
            echo '<br /><b>Last 10 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']>10 ? 'height: 30ex;overflow: auto;' : '' ,'"><br />';

$i = 0;
foreach($online['users_online_today'] as $user)
{
  ++$i;
  if ($i > 10)
    break;
if ($user['is_online'])
echo '<img src="/Themes/TP_counter-strike/images/useron.gif">' , $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];
else
echo '<img src="/Themes/TP_counter-strike/images/useroff.gif">' , $user['hidden'] ? '<i>' . $user['link'] . '</i>' : $user['link'];

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

echo '<br /></td></tr></table>';
echo '</span>';



Jpg


Techdomain

Hey Bent - are you using custom graphics to get it looking like that?

Techdomain

nvm - found that you were using a different theme in the url's. Thanks for teh code!

Techdomain

my
"New This Week: 0
New Today: 0"
are both reading 0, thoung i have new members. any ideas why?