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

Recent

Welcome to TinyPortal. Please login or sign up.

June 28, 2024, 03:26:31 PM

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

[Block] Top Karma w/ Linked Avatar

Started by tim antley, September 04, 2008, 07:35:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ianedres

This script will list the top x karma ratings for members; displays their avatar, with member name and karma below. Clicking on the avatar will take you to that member's profile.

The script should be placed in a php block and activated; probably best if used in a right or left block, as it does not have much to display.

Variables in the script allow for total number of members to be listed, as well as a max height and width for the avatar displayed, and a border size of the avatar too.

Attached is a 43 byte blank .gif file for those members who are not using any avatar; place on your server and configure the variable in the script to its location

Modified: Removed SQL query for avatar; script now loads avatar by way of $memberContext variable. Original code could not properly detect an off-site avatar versus on-site images.

// karma_fetch.php | Sep 2, 2008
// Tim Antley | www.BayouMX.com

// For Use With SMF & TinyPortal

require_once('Sources/Load.php');

global $db_prefix, $scripturl, $memberContext;

$blank_image = 'http://www.yourdomain.com/blank_1x1.gif'; // url to blank image for no avatar
$limit = '5'; // number of members to display

$max_height = '40'; // max height of avatar
$max_width = '40'; // max width of avatar
$border = '1'; // image border size

$karma = array();

function cmp($a, $b)
{
if($a['karmaTotal'] < $b['karmaTotal'])
{
return 1;
}
else
return -1;

// return strcasecmp($a['karmaTotal'], $b['karmaTotal']);
}

// start of script

$query = db_query(
    "SELECT ID_MEMBER, karmaGood, karmaBad
     FROM {$db_prefix}members
", __FILE__, __LINE__);

while ($row = mysql_fetch_array($query))
{
$karmaGood = $row['karmaGood'];
$karmaBad = $row['karmaBad'];

$karmaTotal = $karmaGood - $karmaBad;

if($karmaTotal > 0)
{
$ID_MEMBER = $row['ID_MEMBER'];

loadMemberData($ID_MEMBER);
loadMemberContext($ID_MEMBER);

if(!empty($memberContext[$ID_MEMBER]['avatar']['href']))
{
$avatar = $memberContext[$ID_MEMBER]['avatar']['href'];
}
else
{
$avatar = $blank_image;
}

$karma[] = array('ID_MEMBER' => $row['ID_MEMBER'], 'memberName' => $memberContext[$ID_MEMBER]['username'], 'karmaTotal' => $karmaTotal, 'avatar' => $avatar);
}
}

uasort($karma, 'cmp');

$count = 1;

if(count($karma) > 0)
{
echo '<div align="center" class="smalltext">';

foreach($karma as $value)
{
if($limit >= $count)
{
if($value['avatar'] != $blank_image)
{
list($width, $height, $type, $attr) = getimagesize($value['avatar']);
}
else
{
$width = $max_width;
$height = $max_height;
}

if($width > $max_width) $width = $max_width;
if($height > $max_height) $height = $max_height;

echo '<a href="' . $scripturl . '?action=profile;u=' . $value['ID_MEMBER'] . '">';
echo $value['memberName'] . '<br />';
echo '<img src="' . $value['avatar'] . '" height="' . $height . '" width="' . $width . '" border="' .
$border . '" /></a>' . '<br />';
echo $value['karmaTotal'] . '<hr />';
$count++;
}
}

echo '</div>';
}

jdvarner


Ianedres

It was designed and tested on a SMF 1.1.6 / TP 1.05 installation; it is still in operation on a live site and the admin has not notified me of any issues.

I will need some additional specific information concerning why it is not working with your site before I can assist you.




djrey

It works in SMF 1.1.7 TinyPortal v0.9.8 Thanks for this, I like it a lot...

Only sudgestion if there would be a way to fix a size of the avartar, something small like 50x50 pix would look real nice since there is users that use outside links for their avartars and in those cases It comes in real size that distorts. Lets say 200x200 pix...
With a fixed avartar It could be arranged in rows, = Avartar.......Karma points, that I think It would look much better...


IchBin

Did you try changing the settings for max_height and max_width in the script?

Ianedres

As IchBin suggested, I don't see why that would not address the issue you are having if you set the maximums you want on your site in the script.

The original intent of the script is to provide a single row of the top-ranked members; it is not coded to generate rows and such.

Glad that you liked the snippet and found a use for it...

djrey

Yes I did tried but those settings of max hight and width only apply to the avatars that are uploaded to the forum server.
In my forum you can use an avartar that is hosted some where else, and the forum resizes those avatars too, but the the top karma can not..

Ianedres

This code uses the SMF-recommended form of retrieving the avatar through the API loadMember structure. If it is not loading your modded installation's avatars, then that mod may not be following the proper loading procedure.

I would rather not alter the code, as it may create issues with standard installations.

IchBin

Can anyone test something for me using this code? I tried using the memberLoadData functions once, and noticed that it used a lot of queries the more users you display. I don't have Karma enabled on my site, so I can't test it. But I just wanted to know if this increases the queries used exponentially by the number of users that have Karma.

HellBent

I just installed this block and it appears to be working fine with smf 1.1.7 and TP 0.9.8 and it appears to be fine.

IchBin if you tell me how to test it exponentially .... I'll do it for you :)