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

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 08:35:29 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 174
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 169
  • Total: 169

[Block] Top Posters with Avatar

Started by IchBin, January 11, 2010, 05:02:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IchBin

Name of Snippet: Top Posters with Avatar
SMF/TP versions tested:: SMF1.1.11/TP1 beta 4
Block Type:: php
Author: IchBin
Link to Discussion: N/A
Other Requirements: None
Description:
Made for a vertical layout only. This block will show the avatar, username, and post count of the Top Posters on your site. You can select the size that you want the avatars to be display by changing the $width/$height variables at the top. You can also change how many users you want to show by changing the $topPoster variable. There is also a noavatar.gif posted below that you will need to use, because this code shows a default avatar for users who don't have one.


global $db_prefix, $scripturl, $modSettings;

// Height and width of avatar
$width = '40px';
$height = '40px';
// Number of top posters displayed
$topPoster = 8;

// Find the latest poster.
$request = db_query("SELECT mem.ID_MEMBER, mem.showOnline, mem.realName, mem.posts, mem.avatar, 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 showOnline = 1
ORDER BY posts DESC
LIMIT $topPoster", __FILE__, __LINE__);

$users = array();

while ($row = mysql_fetch_assoc($request))
{
$users[] = array(
'id' => $row['ID_MEMBER'],
'name' => $row['realName'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>',
'posts' => $row['posts'],
'show' => $row['showOnline'],
'avatar' => array(
    'image' => empty($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($request);

// Output our array of users with avatar, posts, and name
echo '
<table cellpadding="0" cellspacing="8">';

foreach ($users as $user)
{
echo '
<tr>
<td>',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">'. $user['posts'] .'</h5></td>
</tr>';
}

echo '
</table>';

IchBin

#1
Code for SMF2 TP 1
global $smcFunc, $scripturl, $modSettings, $settings;

// Height and width of avatar
$width = '40px';
$height = '40px';
// Number of top posters displayed
$topPoster = 8;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, mem.avatar, a.id_attach, a.attachment_type, a.filename
FROM ({db_prefix}members as mem)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE show_online = 1
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topPoster)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$users[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => $row['posts'],
'show' => $row['show_online'],
'avatar' => array(
    'image' => empty($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']($request);

// Output our array of users with avatar, posts, and name
echo '
<table cellpadding="0" cellspacing="8">';

foreach ($users as $user)
{
echo '
<tr>
<td>',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">'. $user['posts'] .'</h5></td>
</tr>';
}

echo '
</table>';