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

Recent

Welcome to TinyPortal. Please login or sign up.

April 14, 2024, 05:20:57 AM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,156
  • Total Topics: 21,219
  • Online today: 59
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 35
  • Total: 35

[Block] Users Online scrolling with Avatar

Started by IchBin, January 11, 2010, 09:14:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IchBin

Name of Snippet: Users online scrolling avatars
SMF/TP versions tested:: SMF1.1.11/SMF2/TP1 beta 4
Block Type:: php,
Author: IchBin
Link to Discussion: N/A
Other Requirements: None
Description:
This next bit of code creates a single row with the avatars of users online scrolling to the left. There is no column configuration for this code as it will scroll all the online users within the configurable time limit to scroll in the block. For users without an avatar noavatar.gif is displayed. This file must be in your themes images directory.
global $memberContext, $db_prefix, $scripturl, $modSettings;

/* ###  CONFIGURATION OPTIONS  ### */
// Set time limit using seconds
// 1 hour = 3600
// 1 day = 84600
$timelimit = 3600;

// Set the height and width of avatars
// This will resize the avatars to be more uniform
$width = "40px";
$height = "40px";

// Set or change the style of all the elements
echo '<style type="text/css">
.avatar_column
{
border: 0;
}
.avatar_column td
{
height: 60px;
width: 60px;
overflow: hidden;
text-align: center;
vertical-align: top;
}
.default
{
border: 2px solid black;
}
.he
{
border: 2px solid blue;
}
.she
{
border: 2px solid pink;
}
</style>';

/* ###  END CONFIGURATION OPTIONS  ### */

// Load all users who have logged in within $timelimit
$result = db_query("
SELECT mem.ID_MEMBER, mem.showOnline, mem.lastLogin, mem.realName, mem.avatar, mem.gender, a.ID_ATTACH, a.attachmentType, a.filename
FROM ({$db_prefix}members as mem)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
WHERE mem.lastLogin > (UNIX_TIMESTAMP() - $timelimit)
ORDER BY mem.lastLogin DESC", __FILE__, __LINE__);

$users = array();

// Loop through the results to display the users avatar
while ($row = mysql_fetch_assoc($result))
{
    $users[$row['ID_MEMBER']] = array (
    'id' => $row['ID_MEMBER'],
    'href' => $scripturl.'?action=profile;u='.$row['ID_MEMBER'],
    'name' => $row['realName'],
    'show' => $row['showOnline'],
'gender' => $row['gender'],
    'avatar' => array(
    'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? 'src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />'),
    ),
    );
}

mysql_free_result($result);

echo '
<marquee direction="left">
<table class="avatar_column">
<tr>';

foreach ($users as $user)
{
if ($user['show'] == 1)
{
switch ($user['gender'])
{
case 0:
$css = "default";
break;
case 1:
$css = "he";
break;
case 2:
$css = "she";
break;
}
echo '
<td>',(empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a><h6>'.$user['name'].'</h6>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6>'),'</td>';

}
}

echo '
</tr>
</table>
</marquee>';

IchBin

Code for SMF2

global $memberContext, $db_prefix, $scripturl, $modSettings;

/* ###  CONFIGURATION OPTIONS  ### */
// Set time limit using seconds
// 1 hour = 3600
// 1 day = 84600
$timelimit = 3600;

// Set the height and width of avatars
// This will resize the avatars to be more uniform
$width = "40px";
$height = "40px";

// Set or change the style of all the elements
echo '<style type="text/css">
.avatar_column
{
border: 0;
}
.avatar_column td
{
height: 60px;
width: 60px;
overflow: hidden;
text-align: center;
vertical-align: top;
}
.default
{
border: 2px solid black;
}
.he
{
border: 2px solid blue;
}
.she
{
border: 2px solid pink;
}
</style>';
/* ###  END OF CONFIGURATION OPTIONS  ### */

$mdate = date("U");

// Load all users who have logged in within $timelimit
$result = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.last_login, mem.real_name, mem.avatar, mem.gender, a.id_attach, a.attachment_type, a.filename
FROM smf_members AS mem
LEFT JOIN smf_attachments AS a ON (a.id_member = mem.id_member)
WHERE mem.last_login > ({int:date} - '.$timelimit.')
ORDER BY mem.last_login DESC',
array('date' => $mdate)
);

$users = array();

// Loop through the results to display the users avatar
while ($row = $smcFunc['db_fetch_assoc']($result)) {
    $users[$row['id_member']] = array (
    'id' => $row['id_member'],
    'href' => $scripturl.'?action=profile;u='.$row['id_member'],
    'name' => $row['real_mame'],
    'show' => $row['show_online'],
'gender' => $row['gender'],
    'avatar' => array(
    'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? 'src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
    ),
    );
}

$smcFunc['db_free_result']($result);

echo '
<marquee direction="left">
<table class="avatar_column">
<tr>';

foreach ($users as $user)
{
if ($user['show'] == 1)
{
switch ($user['gender'])
{
case 0:
$css = "default";
break;
case 1:
$css = "he";
break;
case 2:
$css = "she";
break;
}
echo '
<td>',(empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a><h6>'.$user['name'].'</h6>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6>'),'</td>';

}
}

echo '
</tr>
</table>
</marquee>';