News: April 1st, 2012, A Day That Will Live in Infamy ~~ TinyPortal 1.0 Final Released!  GET IT NOW !!!
To Read More About It, Just Click Here!

Login  |  Register
* *

Welcome !!!

Welcome, Guest. Please login or register.
Did you miss your activation email?
Please welcome tupoar, our newest member.

 
 

Welcome, Guest. Please login or register.
Did you miss your activation email?
September 01, 2015, 01:55:20 AM

Login with username, password and session length

Recent

Members
  • Total Members: 3548
  • Latest: tupoar
Stats
  • Total Posts: 175630
  • Total Topics: 19965
  • Online Today: 32
  • Online Ever: 383
  • (January 02, 2015, 05:58:49 AM)
Users Online
Users: 1
Guests: 25
Total: 26

Please read the Posting Guidelines


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

0 Members and 1 Guest are viewing this topic.

Offline IchBin™

  • Developer
  • *
  • Posts: 16193
    • 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: 16193
    • 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™ »