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 12, 2022, 03:57:03 AM

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

Author Topic: Online Today Snipe.  (Read 9447 times)

0 Members and 1 Guest are viewing this topic.

-BeNt-

  • Guest
Online Today Snipe.
« on: November 18, 2006, 03:53:41 PM »
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....

Code: [Select]
// 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 />';

Offline Crip

  • Jesus Inside.
  • Themes
  • *
  • Posts: 4168
  • Theme Support
    • Cripzone
Re: Online Today Snipe.
« Reply #1 on: November 18, 2006, 04:00:48 PM »
I'm not a code monkey but looks like you could change it like this::::

Code: [Select]
// 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

  • Guest
Re: Online Today Snipe.
« Reply #2 on: November 18, 2006, 04:06:58 PM »
It'll probably work if you change

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

to

Code: [Select]
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-

  • Guest
Re: Online Today Snipe.
« Reply #3 on: November 18, 2006, 04:39:50 PM »
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.........

Code: [Select]
// 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

  • Guest
Re: Online Today Snipe.
« Reply #4 on: November 18, 2006, 06:03:25 PM »
I see.

Try changing (from the original)
Code: [Select]
foreach($online['users_online_today'] as $user)
{

to

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

-BeNt-

  • Guest
Re: Online Today Snipe.
« Reply #5 on: November 25, 2006, 04:02:17 PM »
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!

Code: [Select]
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>';


Offline Jpg

  • Hero Member
  • *****
  • Posts: 591
Re: Online Today Snipe.
« Reply #6 on: November 25, 2006, 04:36:56 PM »
Thanks dude...I love it. :)

Techdomain

  • Guest
Re: Online Today Snipe.
« Reply #7 on: November 25, 2006, 04:53:18 PM »
Hey Bent - are you using custom graphics to get it looking like that?

Techdomain

  • Guest
Re: Online Today Snipe.
« Reply #8 on: November 25, 2006, 05:03:12 PM »
nvm - found that you were using a different theme in the url's. Thanks for teh code!

Techdomain

  • Guest
Re: Online Today Snipe.
« Reply #9 on: November 25, 2006, 05:14:53 PM »
my
"New This Week: 0
 New Today: 0"
are both reading 0, thoung i have new members. any ideas why?