Code for SMF2
global $smcFunc, $db_prefix, $scripturl, $modSettings, $settings;
/* ### CONFIGURATION OPTIONS ### */
// Set time limit using seconds
// 1 hour = 3600
// 1 day = 84600
$timelimit = 3600;
// Set $columns to the amount of columns you need
// You set this depending on whether you want it in a side block or a top/bottom block.
$columns = 5;
// 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: 100px;
width: 100px;
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 '
<table class="avatar_column">
<tr>';
$counter = 0;
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;
}
if ($counter < $columns){
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>';
$counter++;
}
else{
echo '
</tr>
<tr>
<td>',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" /></a><h6>'.$user['name'].'</h6>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6></td>';
$counter = 1;
}
}
}
echo '
</tr>
</table>';