Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Owdy on January 26, 2005, 07:20:29 PM

Title: $context['list_users_online']
Post by: Owdy on January 26, 2005, 07:20:29 PM
';

// Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
if (!empty($context['users_online']))
echo '
', $txt[140], ':<br />', implode(', ', $context['list_users_online']);
This works only in board index. How can a make it work in index.template.php?


Another choise would be how to pull list of only users from SSI.php?
Title: Re: $context['list_users_online']
Post by: Jerry on January 27, 2005, 12:13:06 AM
It seems like it is hard coded into /Sources/BoardIndex.template.php

// 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, mg.groupName
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__);

$context['users_online'] = array();
$context['list_users_online'] = array();
$context['online_groups'] = array();
$context['num_guests'] = 0;
$context['num_users_hidden'] = 0;
while ($row = mysql_fetch_assoc($result))
{
if (!isset($row['realName']))
{
$context['num_guests']++;
continue;
}
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>';

$context['users_online'][$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']),
);

$context['list_users_online'][$row['logTime'] . $row['memberName']] = empty($row['showOnline']) ? '<i>' . $link . '</i>' : $link;

if (!isset($context['online_groups'][$row['ID_GROUP']]))
$context['online_groups'][$row['ID_GROUP']] = array(
'id' => $row['ID_GROUP'],
'name' => $row['groupName'],
'color' => $row['onlineColor']
);
}
else
$context['num_users_hidden']++;
}
mysql_free_result($result);

krsort($context['users_online']);
krsort($context['list_users_online']);
ksort($context['online_groups']);

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

// Track most online statistics?
if (!empty($modSettings['trackStats']))
{
// Determine the most users online - both all time and per day.
$total_users = $context['num_guests'] + count($context['users_online']) + $context['num_users_hidden'];
if (!isset($modSettings['mostOnline']) || $total_users >= $modSettings['mostOnline'])
updateSettings(array('mostOnline' => $total_users, 'mostDate' => time()));

$date = strftime('%Y%m%d', forum_time(false));

// One or more stats are not up-to-date?
if (!isset($modSettings['mostOnlineUpdated']) || $modSettings['mostOnlineUpdated'] != $date)
{
$request = db_query("
SELECT mostOn
FROM {$db_prefix}log_activity
WHERE date = $date", __FILE__, __LINE__);

// The log_activity hasn't got an entry for today?
if (mysql_num_rows($request) == 0)
{
db_query("
INSERT IGNORE INTO {$db_prefix}log_activity
(date, mostOn)
VALUES ($date, $total_users)", __FILE__, __LINE__);
updateSettings(array('mostOnlineUpdated' => $date, 'mostOnlineToday' => $total_users));
}
// There's an entry in log_activity on today...
else
{
list ($modSettings['mostOnlineToday']) = mysql_fetch_row($request);

if ($total_users > $modSettings['mostOnlineToday'])
trackStats(array('mostOn' => $total_users));

updateSettings(array('mostOnlineUpdated' => $date, 'mostOnlineToday' => max($total_users, $modSettings['mostOnlineToday'])));
}
mysql_free_result($request);
}
// Highest number of users online today?
elseif ($total_users > $modSettings['mostOnlineToday'])
{
trackStats(array('mostOn' => $total_users));
updateSettings(array('mostOnlineUpdated' => $date, 'mostOnlineToday' => $total_users));
}
}
not sure if that would help you at all :-X
Title: Re: $context['list_users_online']
Post by: Kirby on January 27, 2005, 12:23:08 AM
QuoteAnother choise would be how to pull list of only users from SSI.php?
SSI.php has an ssi_whosOnline() function so you could just use:
', ssi_whosOnline() ,'
Title: Re: $context['list_users_online']
Post by: Jerry on January 27, 2005, 12:24:20 AM
Can you use SSI functions in your templates?

/me investigates a bit more
Title: Re: $context['list_users_online']
Post by: Kirby on January 27, 2005, 12:27:00 AM
yup...
just include SSI.php
Title: Re: $context['list_users_online']
Post by: Jerry on January 27, 2005, 12:30:52 AM
That doesn't seem like it would work very well. SSI.php uses sessions, and so do the forums... sounds like they would conflict.
Title: Re: $context['list_users_online']
Post by: [Unknown] on January 27, 2005, 04:01:59 AM
Quote from: Jerry on January 27, 2005, 12:30:52 AM
That doesn't seem like it would work very well. SSI.php uses sessions, and so do the forums... sounds like they would conflict.

But it's been designed so you cna use SSI.php in your templates, so this is not a problem.

-[Unknown]
Title: Re: $context['list_users_online']
Post by: Jerry on January 27, 2005, 04:03:00 AM
oh alright, thanks :)
Title: Re: $context['list_users_online']
Post by: Owdy on January 27, 2005, 06:18:55 AM
I could use SSI (and  have been using it alot in my theme), yes. But like i sayd, i'd like to show only Users, not guests in that list. How do i do that with ssi?

Like this: Users logged in: Jerry, Owdy , ....
Title: Re: $context['list_users_online']
Post by: [Unknown] on January 27, 2005, 03:06:39 PM
Use the array output method!!

-[Unknown]
Title: Re: $context['list_users_online']
Post by: Owdy on January 27, 2005, 03:07:25 PM
HOw? Still PHP n00b here ;) I have tryed lots of stuff, but nothing works :(
Title: Re: $context['list_users_online']
Post by: [Unknown] on January 27, 2005, 03:41:48 PM
$who = ssi_whosOnline('array');
print_r($who);

-[Unknown]
Title: Re: $context['list_users_online']
Post by: Owdy on January 27, 2005, 03:53:39 PM
';

if ($context['user']['is_logged'])

{

require_once('/www/blaat/public_html/foorumi/SSI.php');


$users = ssi_whosOnline('array');
print_r($users);
}
echo '
??
Title: Re: $context['list_users_online']
Post by: Kirby on January 27, 2005, 03:54:23 PM
that should work..
Title: Re: $context['list_users_online']
Post by: Owdy on January 27, 2005, 03:58:23 PM
Nope.
Title: Re: $context['list_users_online']
Post by: Kirby on January 27, 2005, 04:09:29 PM
require_once('/www/blaat/public_html/foorumi/SSI.php'); <-- is that correct?
Title: Re: $context['list_users_online']
Post by: Owdy on January 27, 2005, 04:10:14 PM
yes
Title: Re: $context['list_users_online']
Post by: Kirby on January 27, 2005, 04:13:17 PM
have you tried:
require_once('../../SSI.php');
or
require_once('SSI.php');
Title: Re: $context['list_users_online']
Post by: Owdy on January 27, 2005, 04:16:02 PM
Thanks, but it isint that. That path works with my other ssi things in that same theme.  ;)
Title: Re: $context['list_users_online']
Post by: Kirby on January 27, 2005, 04:31:05 PM
thats kinda wierd... must be a problem with what unknown posted
Title: Re: $context['list_users_online']
Post by: [Unknown] on January 27, 2005, 05:24:53 PM
By not working, what do you mean?  It displays nothing?

-[Unknown]
Title: Re: $context['list_users_online']
Post by: Owdy on January 28, 2005, 12:26:38 PM
Prints:Array ( [users] => Array ( [2034634566628192606Admin] => Array ( [id] => 1 [username] => Admin [name] => ‹Oz› [group] => 1 [href] => http://foorumi.hoitajat.net/index.php?action=profile;u=1 [link] => ‹Oz›  [hidden] => [is_last] => ) etc.
Title: Re: $context['list_users_online']
Post by: [Unknown] on January 28, 2005, 04:50:08 PM
Yes, which shows you the information is available.  See, you can use $users['users']... and output it with a foreach.  Come on, Owdy, I know you know that much PHP.

-[Unknown]
Title: Re: $context['list_users_online']
Post by: Owdy on January 28, 2005, 05:02:26 PM
Thanks for beliving me, but i dont. Itryed something like this and it isnt working:';

if ($context['user']['is_logged'])

{

require_once('/www/asiakkaat/public_html/foorumi/SSI.php');
$array = ssi_whosOnline();
foreach ($array as $users)
{
echo '
', $users['users'], '

}
echo '
Title: Re: $context['list_users_online']
Post by: [Unknown] on January 28, 2005, 05:22:52 PM
';

if ($context['user']['is_logged'])
{
require_once('/www/asiakkaat/public_html/foorumi/SSI.php');
$array = ssi_whosOnline('array');
foreach ($array['users'] as $users)
{
echo '
', $users['link'];
}
}

echo '


-[Unknown]
Title: Re: $context['list_users_online']
Post by: Owdy on January 28, 2005, 05:28:24 PM
Parse error. This cant be this hard.  :(
Title: Re: $context['list_users_online']
Post by: [Unknown] on January 28, 2005, 05:29:10 PM
Typo.  See above.

-[Unknown]
Title: Re: $context['list_users_online']
Post by: Owdy on January 28, 2005, 05:31:11 PM
PEEEERRRRRRRRFECTTT!!!! :D Thanks! :D
Title: Re: $context['list_users_online']
Post by: Owdy on January 28, 2005, 06:09:19 PM
Ok, it missed commas between names. I use this code from SSI.php to show them, but it shows it also after last person. What is wrong in that code?

';

if ($context['user']['is_logged'])
{
require_once('/www/asiakkaat/public_html/foorumi/SSI.php');
$array = ssi_whosOnline('array');
foreach ($array['users'] as $users)
{
echo '
', $users['link'],  ', ';
}
}

echo '
And sorry beeing perfectionist about this :D
Title: Re: $context['list_users_online']
Post by: [Unknown] on January 28, 2005, 07:51:09 PM
';

if ($context['user']['is_logged'])
{
require_once('/www/asiakkaat/public_html/foorumi/SSI.php');
$array = ssi_whosOnline('array');

$newarray = array();
foreach ($array['users'] as $user)
   $newarray[] = $user['link'];

echo implode(', ', $newarray);
}

echo '


-[Unknown]
Title: Re: $context['list_users_online']
Post by: Owdy on January 28, 2005, 07:54:03 PM
Perfect. Thanks again!