Welcome, Guest. Please login or register.
Did you miss your activation email?
October 21, 2014, 05:57:02 AM

Login with username, password and session length

Recent

Members
  • Total Members: 3468
  • Latest: Castiel
Stats
  • Total Posts: 174000
  • Total Topics: 19854
  • Online Today: 54
  • Online Ever: 278
  • (October 31, 2012, 08:52:18 AM)
Users Online
Users: 0
Guests: 51
Total: 51
Please read the Posting Guidelines

Author Topic: [Block] Top Posters with Avatar  (Read 3964 times)

0 Members and 1 Guest are viewing this topic.

Offline IchBin™

  • Developer
  • *
  • Posts: 16121
    • My Website
[Block] Top Posters with Avatar
« on: January 11, 2010, 10:02:16 AM »
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.

Code: [Select]
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>';

Offline IchBin™

  • Developer
  • *
  • Posts: 16121
    • My Website
Re: [Block] Top Posters with Avatar
« Reply #1 on: April 13, 2010, 08:06:35 PM »
Code for SMF2 TP 1
Code: [Select]
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>';
« Last Edit: April 28, 2012, 05:59:12 PM by IchBin™ »