News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Online User's avatars rotation

Started by Fizzy, July 10, 2004, 03:39:46 AM

Previous topic - Next topic

NukeWorker.com

I couldn't get your code to work, some of the <tr>'s and <td>'s were wrong.  I played with it a little to fix that, and make it do what I wanted.  This is basically a SSI like who's online + avatars.  It works for me.  So I figured I'd share it with others. (By the way, how do we get this to work with logonline() ??

// Shows a list of recent users: YY Guests, ZZ Users and then a list...
function ssi_whosRecent($output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $modSettings;

// Load the users online right now.
$result = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline, mem.avatar,
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 = mem.ID_GROUP OR (mem.ID_GROUP = 0 AND mg.ID_GROUP = mem.ID_POST_GROUP))", __FILE__, __LINE__);

$return['users'] = array();
$return['guests'] = 0;
$return['hidden'] = 0;

while ($tmp = mysql_fetch_assoc($result))
{
if (!isset($tmp['realName']))
{
$return['guests']++;
continue;
}
elseif (empty($tmp['showOnline']))
{
$return['hidden']++;
continue;
}

$link = '';

// The user Avatar...
if ($tmp['avatar'] == '')
{
$AvatarReq = db_query ("SELECT * FROM {$db_prefix}attachments WHERE ID_MEMBER = '$tmp[ID_MEMBER]'", __FILE__, __LINE__);
$AvatarRes = mysql_fetch_assoc($AvatarReq);
if (mysql_num_rows ($AvatarReq) == 1)
$link .= '<br><img src="' . $scripturl . '?action=dlattach;id=' . $AvatarRes['ID_ATTACH'] . ';type=avatar" height="24">&nbsp;';
$link .= '
';
}
elseif (strtoupper(substr($tmp['avatar'],0,7)) == 'HTTP://')
$link .= '
<br><img src="' . $tmp['avatar'] . '" height="24">&nbsp;';
else
$link .= '
<br><img src="' . $modSettings['avatar_url'] . '/' . $tmp['avatar'] . '" height=24>&nbsp;';

$link .= '
<a href="' . $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'] . '" style="color: ' . $tmp['onlineColor'] . ';"><b><font size=2>' . $tmp['realName'] . '</a></b></font>, ';


$return['users'][] = array(
'id' => $tmp['ID_MEMBER'],
'username' => $tmp['memberName'],
'name' => $tmp['realName'],
'group' => $tmp['ID_GROUP'],
'href' => $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'],
'link' => $link,
'is_last' => false
);
}
mysql_free_result($result);

$return['num_users'] = count($return['users']) + $return['hidden'];
$return['total_users'] = $return['num_users'] + $return['guests'];

if (!empty($return['users']))
$return['users'][count($return['users']) - 1]['is_last'] = true;

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

echo '
', $return['guests'], ' ', $return['guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', $return['num_users'], ' ', $return['num_users'] == 1 ? $txt['user'] : $txt['users'], $return['hidden'] > 0 ? ' (' . $return['hidden'] . ' ' . $txt['hidden'] . ')' : '', '<br />
';

echo '<table border="0" style="border-collapse: collapse" cellpadding="0" cellspacing="0" width=140><tr><td>';
foreach ($return['users'] as $user)
echo $user['link'], !$user['is_last'] ? '' : '';
echo '</td></tr></table>';
}

Senkusha

Currently I haven't had time to add the logonline (guest counter)  I plan to add this functionality sometime this week.
--Senkusha
The Anime Brigade
Anime-style Role Playing Games and Discussion.
(SMF v. 2.1.4, PHP v. 8.0)

Elisa

I have resolved the problem of the timetable.  I do not have more need of the modification.  For the IP, the administrators it can always see!  Therefore qual' it is the problem?

damo1065

Quote from: Mysterio on August 13, 2004, 12:59:14 PM
Senkusha, I tried installing the 'Avatar Online' mod, but it brought back some errors:

QuoteNotice: Undefined variable: tmp in /****/****/****/****/Sources/BoardIndex.php on line 271
Notice: Undefined variable: tmp in /****/****/****/****/Sources/BoardIndex.php on line 272
Notice: Undefined variable: tmp in /****/****/****/****/Sources/BoardIndex.php on line 273
Notice: Undefined variable: tmp in /****/****/****/****/Sources/BoardIndex.php on line 274
Notice: Undefined variable: tmp in /****/****/****/****/Sources/BoardIndex.php on line 275
Notice: Undefined variable: tmp in /****/****/****/****/Sources/BoardIndex.php on line 279

And here is what's on lines 271-275:

         
Quote'id' => $tmp['ID_MEMBER'],
         'username' => $tmp['memberName'],
         'name' => $tmp['realName'],
         'group' => $tmp['ID_GROUP'],

And 279:

Quoteif ($tmp['onlineColor'] != '')

How do I fix that?

Thanks.

Are you still running Beta 5 - you need to upgrade to RC1.0

Senkusha - the uploaded avatars - how do you get them to show on your forums - btw fantastic mod....exactly what I was looking for, cheers :D

Wy not visit my site... The Gaff'll be bored to be honest, unless you're from Cork in Ireland

Elisa

You must excuse to me but I have one new demand.  If you can, helps me!  I would want, in the page of statistics of the forum, the number total of the users connected in one day.  How I can make?  Thanks!

Vinoth

senuska did u do  who is online in 24 hrs in a day!

if so pm me with the code,
Vinoth And Sachin ( SpecHackers Team )
The Best  Way to Help Poor Is not Becoming One Of Them.

Elisa

I have the page with the list of the users, with avatars, than but every day is cancelled.  I would want in the page of statistics, (where hour there are number users registered, the maximum number users connected...) the number total of the users connected to you during every day.  I would have to add one column to the table!  The code that I have used is what senuska it has written here.

http://www.simplemachines.org/community/index.php?topic=13676.msg127629#msg127629

FaSan

#87
I've modification the code for the visualizzation all member online today on the index of the forum. In list, without Avatars :)

On BoardIndex.php


<Search>
// Load the users online right now.
</Search>

<Add Before>
// Load the users online today.

$midnight = ((date("U") - (date("H") * 3600)) - (date("i") * 60));

// Load the users online for the past 24 hours.
$result = db_query("
SELECT
mem.ID_MEMBER, mem.realName, mem.memberName, mem.ID_GROUP, mem.showOnline, mem.avatar, mem.lastLogin, mem.posts,
mg.onlineColor
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP OR (mem.ID_GROUP = 0 AND mg.ID_GROUP = mem.ID_POST_GROUP))
WHERE mem.lastLogin >= '$midnight'
ORDER BY mem.realName", __FILE__, __LINE__);

$today['users'] = array();
$today['num_users'] = 0;
$link = '';

while ($tmp = mysql_fetch_assoc($result))
{
$link .= '<a href="' . $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'] . '" style="color: ' . $tmp['onlineColor'] . ';">' . $tmp['realName'] . '</a>, ';
$today['num_users']++;
}

mysql_free_result($result);

$context['user_today'] = $link;
$context['num_users_today'] = $today['num_users'];
</Add Before>



On BoardIndex.template.php


<Search>
// If they are logged in, but SP1 style information is off... show a personal message bar.
</Search>


<Add Before>
// "Users online Today"
echo '
<tr>
<td class="catbg" colspan="2">', $txt['158bis'], ' ( ', $context['num_users_today'], ' ', $context['num_users_today'] == 1 ? $txt['user'] : $txt['users'], ' )</td>
</tr><tr>
<td class="windowbg" width="20" valign="middle" align="center"><img src="', $settings['images_url'], '/icons/online.gif" alt="', $txt['158bis'], '" border="0" /></td>
<td class="windowbg2" width="100%"><span class="smalltext">', $context['user_today'], '</span></td></tr>';
</Add Before>



On Modifications.english.php


<Search>
// Version: 1.0 RC1; Modifications
</Search>

<Add After>
$txt['158bis'] = 'OnLine Users Today';
</Add After>



On Modifications.italian.php


<Search>
// Version: 1.0 RC1; Modifications
</Search>

<Add After>
$txt['158bis'] = 'Utenti OnLine nella Giornata di Oggi';
</Add After>

Elisa

#88
You are very very very fantastic!!!!!!!!!!

FaSan

Quote from: Elisa on August 25, 2004, 12:15:58 PM
I have this error:

Notice: Undefined index: 158bis in /web/htdocs/www.lovemusic.it/home/forum/Themes/viola theme/BoardIndex.template.php on line 387 ( 134 Utenti )



Add the lines on Modifications files ;)

Elisa

Fatto fatto fatto!!!!
Tutto a posto!!!!


FaSan


Elisa

Beh veramente ci sarebbe un'altra cosa che vorrei fare!!!! Se vedi un pochino sopra ho fatto una richiesta che ora mi sembra un tantino supercomplicata!

FaSan

Quote from: Elisa on August 25, 2004, 12:31:51 PM
Beh veramente ci sarebbe un'altra cosa che vorrei fare!!!! Se vedi un pochino sopra ho fatto una richiesta che ora mi sembra un tantino supercomplicata!


You posting the details on Italian's Support Area ! ;)

Elisa


damo1065

Great Stuff FaSan - I've changed my forum board to include the Users Online today as I had problems with the avatars not showing the uploaded avatars, and the way the were a vertical line.
Wy not visit my site... The Gaff'll be bored to be honest, unless you're from Cork in Ireland

TodaysXt

#96
Senkusha,
Thanks so much for your Work.  I've wanted a mod like this and posted a request but didn't get much of a response, So I tried to do it myself  (example 1).  I haven't done much PHP so It was going slow.  I couldn't get my avatars right and needed help formating the time. 
The $context and array stuff is killing me.  I thing I've read too many different examples and missing some concepts like why '->' and not '=>' . 
I was about to give up when I saw your post. 
I tried the SSI function, works pretty good, but doesn't count the guest, it stays at zero?  I've also tried the boardindex.php code, but wasn't sure how to get it to sow up in the template so I just included it straight in the template and got it to work there as well, still showed zero guest though.

If I can make a request please, so I can stop banging my head.  Can you modify your code to end up like example 2 below? 
This was my query, Basically I wanted to end up like example 2.
I wanted it to show the last 10 recent members online.  (The Avatar, on/off line image, Name and lastlogin) going across the page.

   $rv = mysql_query("
      SELECT ID_MEMBER, memberName, realName, avatar, lastLogin
      FROM {$db_prefix}members
ORDER BY lastLogin DESC  LIMIT 10");
      while ($row = mysql_fetch_row($rv))


I will sart to try and work with your code to make this work but not having too much luck at the moment. 

Thanks for your time.
Xt.



TodaysXt

Tercel

#97
Hi Out there!
After trying to fix the original code (too much tds and trs - got a headache from that) i changed the code a little bit, and it works for me - may 4 u too ;D
It´s not professional, but ugly coding what I did, i know ;-)

Comments and critics are welcome!

Just add before "?>" at the end of SSI.php and call it from anywhere in your templates with ssi_whosRecent();

BTW: Thanks to Senkusha - should be a official Mod!

You might need this picture or similar for the changes - put it to your images-directory:
  <<< "save as" !

// Shows a list of recent users:  YY Guests, ZZ Users and then a list...
function ssi_whosRecent($output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings;

$midnight = ((date("U") - (date("H") * 3600)) - (date("i") * 60));
// ---------------------------------------------------------> ^ more than midnight (hours)?
// Load the users online for the past 24 (?) hours.
$result = db_query("
SELECT
mem.ID_MEMBER, mem.realName, mem.memberName, mem.ID_GROUP, mem.showOnline, mem.avatar, mem.lastLogin, mem.posts,
mg.onlineColor
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP OR (mem.ID_GROUP = 0 AND mg.ID_GROUP = mem.ID_POST_GROUP))
WHERE mem.lastLogin >= '$midnight'
ORDER BY mem.lastLogin DESC LIMIT 5", __FILE__, __LINE__);
//------------------------------> ^ More than the 5 last Users?
$return['users'] = array();
$return['guests'] = 0;
$return['hidden'] = 0;
echo '<table "width="80" bgcolor="#FFFFFF" border="0px">';
while ($tmp = mysql_fetch_assoc($result))
{
if (!isset($tmp['realName']))
{
$return['guests']++;
continue;
}
elseif (empty($tmp['showOnline']))
{
$return['hidden']++;
continue;
}



// The user Avatar...
$found = 0;
if ($tmp['avatar'] == '')
{
$AvatarReq = db_query ("SELECT * FROM {$db_prefix}attachments WHERE ID_MEMBER = '$tmp[ID_MEMBER]'", __FILE__, __LINE__);
$AvatarRes = mysql_fetch_assoc($AvatarReq);

if (mysql_num_rows ($AvatarReq) == 1)
{
$found = 1;
echo '<tr><td style="width: 45; valign: middle; align: center;"><img src="' . $scripturl . '?action=dlattach;id=' . $AvatarRes['ID_ATTACH'] . ';type=avatar" height="40" alt=""></td>';
}
}
elseif (strtoupper(substr($tmp['avatar'],0,7)) == 'HTTP://')
{
$found = 1;
echo '<tr><td style="width: 45; valign: middle; align: center;"><img src="' . $tmp['avatar'] . '" height="40" alt=""></td>';
}
if ((empty($tmp['avatar'])) && ($found == 0))
{
echo '<tr><td style="width: 45; valign: middle; align: center;"><img src="' . $settings['images_url'] . '/guestlogo.gif" alt="" border="0" align="middle" height="40"/></td>';
}
if ((!empty($tmp['avatar'])) && ($found != 1))
{
echo '<tr><td style="width: 45; valign: middle; align: center;"><img src="' . $modSettings['avatar_url'] . '/' . $tmp['avatar'] . '" height="40" alt=""></td>';
}

// Some basic color coding...what the hell is going on here???
if (!empty($row['onlineColor']))
echo '<td align="left" valign="top" nowrap><font size="1" face="Tahoma"><a href="' . $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'] . '" style="color: ' . $tmp['onlineColor'] . ';">' . $tmp['realName'] . '</a></font><br>';
else
echo '<td align="left" valign="top" nowrap><font size="1" face="Tahoma"><a href="' . $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'] . '">' . $tmp['realName'] . '</a><br>';
// Number of total posts
echo '<font size="1" face="Tahoma">Posts:&nbsp;' . $tmp['posts'] . '</font><br>';
// Time the member last logged in  !!! Just Comment // Out if User don´t like !!!
echo '<font size="1" face="Tahoma">On:' . date("d.m/H:i", $tmp['lastLogin']) . '</font>';


$return['users'][] = array(
'id' => $tmp['ID_MEMBER'],
'username' => $tmp['memberName'],
'name' => $tmp['realName'],
'group' => $tmp['ID_GROUP'],
'href' => $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'],
'online' => $tmp['showOnline'],
'is_last' => false
);
}
mysql_free_result($result);

$return['num_users'] = count($return['users']) + $return['hidden'];
$return['total_users'] = $return['num_users'] + $return['guests'];

if (!empty($return['users']))
$return['users'][count($return['users']) - 1]['is_last'] = true;

if ($output_method != 'echo')
return $return;
// -------------------- Comment 1st echo (not the table commands!!!) below out, if no User/Guest stuff needed -
echo '', $return['guests'], ' ', $return['guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', $return['num_users'], ' ', $return['num_users'] == 1 ? $txt['user'] : $txt['users'], $return['hidden'] > 0 ? ' (' . $return['hidden'] . ' ' . $txt['hidden'] . ')' : '', '<br />';

echo '</td></tr></table>';
}

AxeCrazy

Quote from: Senkusha on August 11, 2004, 12:55:09 PM

      // The user Avatar...
      if ($row['avatar'] == '')
         $link = '&nbsp;<br>';
      elseif (strtoupper(substr($row['avatar'],0,7)) == 'HTTP://')
         $link = '<img src="' . $row['avatar'] . '" height="40"><br>';
      else
         $link = '<img src="' . $modSettings['avatar_url'] . '/' . $row['avatar'] . '" height="40"><br>';
Great one this ;D
just did a slight modification there in the boardindex.php.
I added the realname as ALT on each avatar of the user.

so
Quote
      // The user Avatar...
      if ($row['avatar'] == '')
         $link = $row['realName'] ;
      elseif (strtoupper(substr($row['avatar'],0,7)) == 'HTTP://')
         $link = '<img src="' . $row['avatar'] . '" height="40" alt="' .$row['realName'] .'" >';
      else
         $link = '<img src="' . $modSettings['avatar_url'] . '/' . $row['avatar'] . '" height="40" alt="' .$row['realName'] .'" >';

SeaOfSin

Does this work with version 1.13, the board version not the ssi one?

Advertisement: