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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 287
  • Total: 287

[Block] Top Posters with avatar

Started by IchBin, June 22, 2009, 08:30:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IchBin

Top Posters block. 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>';


Herr Inoddorell

#1
I've attached a pic of the block from my site, for everyone to see how it looks. I included the "Posts" word next to the number of posts, set the $topPoster variable to 5, changed the $width/$height to 50px, and changed the margin of the "h5 style" entry to 5px.

BTW, I've noticed that in the code of the OP, a bit disalignment between the user name and the total post they made. This issue get fixed by changing the first <h5style="margin: 4px;"> entry to <h5 style="margin: 4px;">. <-- Well done, Ich LOL).

Hope everyone enjoy this code :). Great work Ich! ;)!

EDIT: Also attached the "noavatar.gif" image, if you need it.

IchBin

Fixed the code. Don't ask me how I didn't fix that last time. Upgrade at work, doing to many things at once. lol

jabisai

Sorry but how i upload this block to my site??
'cos I try to put in the "Panels and Blocks" and then "Add left block" and I paste your code in php form.

But I can see the block in the left panel?

IchBin

What version of TP are you using? When you edit the block again, is all the code there? Are you using a PHP block type?

ZarPrime

Besides what Ichbin said, have you set where the block should show?  At the bottom of the block edit screen, where you see "[Show][Hide]", be sure to click [Show] to expand it so that you can select where to show the block.

See enclosed pic below.

ZarPrime

tigerclaw

grate script ichBin...i really love it... ;)

vas

nomage.gif gets stored in the themes image dir. Because of that the noimage.gif has to be laoded in each theme dir. Is there a way to store in the forum image directory so that the image loading can be centralized. Thanks.

IchBin

Yep, just change the path on the image.
<img src="'.$settings['images_url'].'/noavatar.gif"

Replace this text '.$settings['images_url'].' with the path to your image that you want.

<img src="'/home/user/www/images/noavatar.gif"


dkharp

greetings!

Block is up and works good! 

This is the path to my pic. www.36thid.info//Themes/default/images/ImagesOnBoard/noavatar.gif

Where would I put this?

This website is proudly hosted on Crocweb Cloud Website Hosting.