SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: Kobar on October 05, 2012, 05:30:22 PM

Title: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Kobar on October 05, 2012, 05:30:22 PM
According to http://www.simplemachines.org/community/index.php?topic=436974.msg3416088#msg3416088

+members avatars

EDIT: Oops! I posted this in the wrong section.. Mod Request > Block Request.
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Kobar on October 10, 2012, 05:23:58 AM
Anyone? :)
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 22, 2012, 07:25:13 AM
It can be done, since the Pro Version of SMF Likes adds a Top 10 Liked Members to the stats page.  But, it uses code from Sources/Stats.php and Stats.template.php to achieve this.  And, I'm not sure on how to combine the 2 into a php block added block.

Also, I doubt this would work for your site unless you have the Likes Pro MOD.
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 22, 2012, 09:07:04 AM
Just figured out how to do this, and it was pretty simple.  Preview pic attached below

You can preview it live, here on my site. (Left side 2nd Block)   http://www.smashdomain.net/index.php

I will share the edits.  But first, I need to ask NIBOGO's permission to share the edit, out of respect.  And ask him if it would even be compatible with Likes Lite version of the MOD.
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Kobar on October 22, 2012, 11:25:39 AM
ok
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 22, 2012, 09:33:43 PM

Here ya go.

Here are the 3 simple edits for this.

Sources/PortalBlocks.php

Find
Code: [Select]
'casino' => $txt['sp_topStatsMember_Casino'],
Add AFTER
Code: [Select]
'likes' => $txt['Likes'],
Find
Code: [Select]
'casino' => array(
'name' => 'Casino Cash',
'mod_id' => 1641,
'field' => 'mem.cash',
'order' => 'mem.cash',
'output_text' => '%cash%',
'enabled' => file_exists($sourcedir . 'casino/Casino.php'),
'error_msg' => $txt['sp_sashop_no_exist'],
),

Add AFTER
Code: [Select]
'likes' => array(
'name' => 'Likes',
'field' => 'mem.liked',
'order' => 'mem.liked',
'output_text' => '%liked% ' . $txt['Likes'],
'enabled' => file_exists($sourcedir . '/Likes.php'),
'error_msg' => $txt['sp_likes_no_exist'],
),

/languages/SPortal.english.php

Add Before the ?>  at the bottom of the file
Code: [Select]
$txt['Likes'] = 'Likes';
$txt['sp_likes_no_exist'] = 'Likes Pro MOD not found';


How To Create the Block

Now after you made the edits, when making a "New Block"  use the Block Option "Top Member Stats".  You'll now see the option to select Likes at the bottom of the drop down list of options.  Select the number of Top Liked members you'd like displayed (5), and rename the Block Title.

Enjoy!
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Kobar on October 23, 2012, 12:12:57 PM
Thanks!

But my error log get's full or:

Code: [Select]
website../forum/index.php?action=admin;area=portalblocks;sa=edit
Apply Filter: Only show the errors with the same message
8: A non well formed numeric value encountered
Apply Filter: Only show the errors from this file
File: /var/www/vhosts/website../httpdocs/forum/Sources/Subs.php
Line: 742
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 23, 2012, 05:13:00 PM
That's strange.  I'm using the same code and no errors in my error log from it.

How did you set your options when creating the box?  couls possibly come from you adding "Remove Inactive members from the List"  option.  that can't be used.

Attached is my settings.
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 23, 2012, 09:51:40 PM
Also, I have a custom php block I'm working on, so you won't need to make any file edits.  But it only shows Avatars that are linked in profiles, not avatars uploaded as attachments.

If anyone could look at it and help me out.

Code: [Select]
global $smcFunc, $scripturl, $context, $txt;

$dbresult = $smcFunc['db_query']('', '
   SELECT real_name, avatar, liked, member_name, id_member
   FROM {db_prefix}members
   ORDER BY liked DESC
   LIMIT 5');
while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
   echo'<table width="100%"><tr width="100%"><td width="50"><img src="'.$row['avatar'].'" width="45" /></td><td><a href="'.$scripturl.'?action=profile;u='.$row['id_member'].'" />'.$row['real_name'].'</a><br>  '.$row['liked'].'  '.$txt['Likes'].' </td></tr></table>';
}
$smcFunc['db_free_result']($dbresult);


Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Chen Zhen on October 23, 2012, 10:49:01 PM
hcfwesker,

I do not have that like mod installed to test but try this for the user avatars:

Code: [Select]
global $smcFunc, $scripturl, $context, $txt, $boardurl;

$result = $smcFunc['db_query']('', '
   SELECT mem.real_name, mem.avatar, mem.liked, mem.member_name, mem.id_member, att.id_attach, att.filename
   FROM {db_prefix}members AS mem
   LEFT JOIN {db_prefix}attachments AS att ON (att.id_member = mem.id_member)
   ORDER BY liked DESC
   LIMIT 5');
while ($row = $smcFunc['db_fetch_assoc']($result))
{

if (!$row['avatar'] && !$row['filename'])
$avatar = $boardurl . '/avatars/noavatar.gif';
elseif (!$row['avatar'])
$avatar = $scripturl . '?action=dlattach;attach='.$row['id_attach'].';type=avatar';
elseif (substr($row['avatar'], 0, 4) != 'http')
$avatar = $boardurl .'/avatars/' . $row['avatar'];
else
$avatar = $row['avatar'];

echo'
<table width="100%">
<tr>
<td width="50"><img src="'.$avatar.'" style="width:45px;" /></td>
<td><a href="'.$scripturl.'?action=profile;u='.$row['id_member'].'" />'.$row['real_name'].'</a><br />  '.$row['liked'].'  '.$txt['Likes'].' </td>
</tr>
</table>';
}
$smcFunc['db_free_result']($result);

Edit -> Fixed block code.
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 23, 2012, 10:57:39 PM
Thanx a lot.  I tried the code and it has the same behavior as my attempt.  Doesn't display attached avatars.
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 23, 2012, 11:05:50 PM
Think I got it! 

Had to change $user to $row  here
Code: [Select]
$avatar = $scripturl . '?action=dlattach;attach='.$user['id_attach'].';type=avatar';
thanx Underdog!  :)


Here;s the PHP custom Block code ( thanx to UnderDog for pro support)

Code: [Select]
global $smcFunc, $scripturl, $context, $txt, $boardurl;

$result = $smcFunc['db_query']('', '
   SELECT mem.real_name, mem.avatar, mem.liked, mem.member_name, mem.id_member, att.id_attach, att.filename
   FROM {db_prefix}members AS mem
   LEFT JOIN {db_prefix}attachments AS att ON (att.id_member = mem.id_member)
   ORDER BY liked DESC
   LIMIT 5');
while ($row = $smcFunc['db_fetch_assoc']($result))
{

if (!$row['avatar'] && !$row['filename'])
$avatar = $boardurl . '/avatars/noavatar.gif';
elseif (!$row['avatar'])
$avatar = $scripturl . '?action=dlattach;attach='.$row['id_attach'].';type=avatar';
elseif (substr($row['avatar'], 0, 4) != 'http')
$avatar = $boardurl .'/avatars/' . $row['avatar'];
else
$avatar = $row['avatar'];

echo'
<table width="100%">
<tr>
<td width="50"><img src="'.$avatar.'" style="width:45px;" /></td>
<td><a href="'.$scripturl.'?action=profile;u='.$row['id_member'].'" />'.$row['real_name'].'</a><br />  '.$row['liked'].'  '.$txt['Likes'].' </td>
</tr>
</table>';
}
$smcFunc['db_free_result']($result);
 

Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Chen Zhen on October 23, 2012, 11:15:36 PM
hcfwesker,

Yes I made a typo.. edited & corrected it.
Glad to see you got it functioning as you wish.


Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Kobar on October 24, 2012, 04:41:11 AM
Thanks! But now I don't have the borders anymore around the avatars..

Code: [Select]
width="40" style="border: 1px solid #D8D8D8; padding: 5px; background: white;" />
EDIT:

I got it now. With 2px for border around the avatar it should be something like this:

Code: [Select]
global $smcFunc, $scripturl, $context, $txt, $boardurl;

$result = $smcFunc['db_query']('', '
   SELECT mem.real_name, mem.avatar, mem.liked, mem.member_name, mem.id_member, att.id_attach, att.filename
   FROM {db_prefix}members AS mem
   LEFT JOIN {db_prefix}attachments AS att ON (att.id_member = mem.id_member)
   ORDER BY liked DESC
   LIMIT 5');
while ($row = $smcFunc['db_fetch_assoc']($result))
{

if (!$row['avatar'] && !$row['filename'])
$avatar = $boardurl . '/avatars/noavatar.gif';
elseif (!$row['avatar'])
$avatar = $scripturl . '?action=dlattach;attach='.$row['id_attach'].';type=avatar';
elseif (substr($row['avatar'], 0, 4) != 'http')
$avatar = $boardurl .'/avatars/' . $row['avatar'];
else
$avatar = $row['avatar'];

echo'
<table width="100%">
<tr>
<td width="50"><img src="'.$avatar.'" width="40" style="border: 2px solid #D8D8D8; padding: 5px; background: white;"" /></td>
<td><a href="'.$scripturl.'?action=profile;u='.$row['id_member'].'" />'.$row['real_name'].'</a><br />  '.$row['liked'].'  '.$txt['Likes'].' </td>
</tr>
</table>';
}
$smcFunc['db_free_result']($result);
 

EDIT #2:
How is this custom mod compatible with the member color link?
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Chen Zhen on October 24, 2012, 03:33:33 PM
Kobar,

  This includes the member color & some of the code is corrected.

Code: [Select]
global $smcFunc, $scripturl, $context, $txt, $boardurl;

$result = $smcFunc['db_query']('', '
SELECT mem.real_name, mem.avatar, mem.liked, mem.member_name, mem.id_member, att.id_attach, att.filename, gp.online_color
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}attachments AS att ON (att.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS gp ON (gp.id_group = mem.id_group)
ORDER BY liked DESC
LIMIT 5');
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if (!$row['avatar'] && !$row['filename'])
$avatar = $boardurl . '/avatars/noavatar.gif';
elseif (!$row['avatar'])
$avatar = $scripturl . '?action=dlattach;attach='.$row['id_attach'].';type=avatar';
elseif (substr($row['avatar'], 0, 4) != 'http')
$avatar = $boardurl .'/avatars/' . $row['avatar'];
else
$avatar = $row['avatar'];

if ((!empty($row['online_color'])) && $row['online_color'])
$name = '<span style="color:'.$row['online_color'].'">'.$row['real_name'].'</span>';
else
$name = '<span>' . $row['real_name']. '</span>';

echo'
<table width="100%">
<tr>
<td style="width:50%;"><img src="'.$avatar.'" style="width:40px;border: 2px solid #D8D8D8; padding: 5px; background: white;" alt="" title="'.$row['real_name'].'" /></td>
<td><a href="'.$scripturl.'?action=profile;u='.$row['id_member'].'">',$name,'</a><br />&nbsp;&nbsp;',$row['liked'],'&nbsp;&nbsp;',$txt['Likes'],'</td>
</tr>
</table>';
}
$smcFunc['db_free_result']($result);
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Kobar on October 24, 2012, 04:17:59 PM
Thank you, it is. But now the text is centered..

(http://i48.tinypic.com/e5free.png)
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 24, 2012, 06:36:00 PM
I never needed any changes for the color links to show for members.  Possibly you're using the olf Member Color Link MOD.  Not sure if you know, but this MOD is an updated version that replaces any member link on the forum anywhere it is place.  http://custom.simplemachines.org/mods/index.php?mod=3067

It uses hooks so there are no file edits at all.

To fix the issue of the space between avatar and names.

Code: [Select]
<td style="width:50%;">
Change 50 to  something lower until it lines up how you want it.  maybe 40 or 45

Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Chen Zhen on October 24, 2012, 08:13:53 PM
Kobar,

I put spaces in the html (... &nbsp;) as the block you posted had them as literal.
You can adjust the percentage for the first cell as hcfwesker suggested if you wish or you can change it to pixels (px) to match the avatar width (ie. 40px).

The block code below will align the text to the left without spaces between the avatar & text. If you want the blocks to look uniform in alignment of images & text compared to your top poster block, you can opt to adjust the top poster block code or perhaps adjust the style attributes you added to this block for the images.

Code: [Select]
global $smcFunc, $scripturl, $txt, $boardurl;

$result = $smcFunc['db_query']('', '
SELECT mem.real_name, mem.avatar, mem.liked, mem.member_name, mem.id_member, att.id_attach, att.filename, gp.online_color
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}attachments AS att ON (att.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS gp ON (gp.id_group = mem.id_group)
ORDER BY liked DESC
LIMIT 5');
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if (!$row['avatar'] && !$row['filename'])
$avatar = $boardurl . '/avatars/noavatar.gif';
elseif (!$row['avatar'])
$avatar = $scripturl . '?action=dlattach;attach='.$row['id_attach'].';type=avatar';
elseif (substr($row['avatar'], 0, 4) != 'http')
$avatar = $boardurl .'/avatars/' . $row['avatar'];
else
$avatar = $row['avatar'];

if ((!empty($row['online_color'])) && $row['online_color'])
$name = '<span style="color:'.$row['online_color'].'">'.$row['real_name'].'</span>';
else
$name = '<span>' . $row['real_name']. '</span>';

$likes[] = array('avatar' => $avatar, 'real_name' => $row['real_name'], 'id_member' => $row['id_member'], 'liked' => $row['liked'], 'name' => $name);
}
$smcFunc['db_free_result']($result);
 
foreach ($likes as $like => $data)
echo'
<table width="100%">
<tr>
<td style="width:50px;"><img src="'.$data['avatar'].'" style="width:40px;border: 2px solid #D8D8D8; padding: 5px; background: white;" alt="" title="'.$data['real_name'].'" /></td>
<td style="text-align:left;"><a href="'.$scripturl.'?action=profile;u='.$data['id_member'].'">',$data['name'],'</a><br />',$data['liked'],'&nbsp',$txt['Likes'],'</td>
</tr>
</table>';


The image may appear larger when compared to the top posters block as in your image attachments, imo this is due to the extra style attributes you added for the image. Unless you have already adjusted your top poster source code.
 
Edit -> Display data after the db query.
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 24, 2012, 10:29:00 PM
^ the man is too legit!

Also, I have one block my members have been requesting, and it's gonan be extensive cause its going to require at least 3 database table calls.  But im working on it now.  Not sure if you're interested but it'll display the most recent Liked Posts/Topics in a block. 
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Kobar on October 25, 2012, 05:50:52 AM
Thanks!! :D
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 25, 2012, 05:26:12 PM
Hey, Underdog, was wondering if you could look this one over for me.  It works perfectly, the main issue is it causes heavy load time when the block is displayed, or when modifying it and clicking the 'Preview' button.  Load time goes back to normal when the block is not displayed.  Not sure if I've got unnecessary coding in there or it's just written in a way it is causing stress to the database calls.

Preview:
(http://i47.tinypic.com/v7e2kj.jpg)


Code: [Select]
global $smcFunc, $scripturl, $context, $settings, $txt, $boardurl;

$result = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.real_name, lm.id_member, lm.id_message, lm.timestamp, msg.id_msg, msg.subject, msg.id_topic
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}likes AS lm ON (lm.id_member = mem.id_member)
LEFT JOIN {db_prefix}messages AS msg ON (msg.id_msg = lm.id_message)
ORDER BY timestamp DESC
LIMIT 5');

while ($row = $smcFunc['db_fetch_assoc']($result))
{
echo'<img src="', $settings['default_images_url'], '/admin/custom_like.png" height="10" />&nbsp;<a href="'.$scripturl.'?action=profile;u='.$row['id_member'].'">'.$row['real_name'].'</a><font size="1"> Liked </font> <a href="'.$scripturl.'?topic='.$row['id_topic'].'.msg'.$row['id_message'].'#msg'.$row['id_message'].'" />' . $row['subject'] . '</a><br><hr>';
}
$smcFunc['db_free_result']($result);

Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Chen Zhen on October 26, 2012, 12:38:03 AM
hcfwesker & kobar,

  I meant to mention to the both of you that attempting to display data smack in the middle of a db query is taboo. It is more prudent to put the needed data into an array, free the query & then do whatever you want with the array. I will skip back to the previous block code & edit it to be correct.



hcfwesker,

  I downloaded that mod to test this but the likes table did not contain all the columns you are selecting. I will assume you have edited the mod or perhaps are using its pro version. With that said, I was not able to test the code shown below. HTML & the db query were corrected.

Code: [Select]
global $smcFunc, $scripturl, $settings;

$result = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.real_name, lm.id_message, lm.timestamp, msg.subject, msg.id_topic
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}likes AS lm ON (lm.id_member = mem.id_member)
LEFT JOIN {db_prefix}messages AS msg ON (msg.id_msg = lm.id_message)
ORDER BY timestamp DESC
LIMIT 5');

while ($row = $smcFunc['db_fetch_assoc']($result))
$likes[] = array('id_member' => $row['id_member'],'name' => $row['real_name'], 'topic' => $row['id_topic'], 'id_message' => $row['id_message'], 'subject' => $row['subject']);

$smcFunc['db_free_result']($result);

foreach ($likes as $mem => $data)
echo '<img src="', $settings['default_images_url'], '/admin/custom_like.png" style="height:10px;" />&nbsp;<a href="'.$scripturl.'?action=profile;u='.$data['id_member'].'">',$data['name'],'</a><span style="font-size:1em;"> Liked </span><a href="'.$scripturl.'?topic='.$data['topic'].'.msg'.$data['id_message'].'#msg'.$data['id_message'].'">' . $data['subject'] . '</a><br /><hr />';
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: hcfwesker on October 26, 2012, 02:24:18 AM
I'm new to retrieving info from the database, so to leanr I'm using other codes I see from MODs, and some in here for other blocks.

Thanx for the info, will keep that noted on future attempts.  :)

And, Yes, I am using the Pro Likes version, the Lite version doesn't allow you to like posts, just first post of a topic.  And I'm not sure if it keeps track of the timestamp either.

Thanx for your kind help and guidance.
Title: Re: [SMF 2.0.2] Block 'top 5 most 'liked' members
Post by: Kobar on October 26, 2012, 04:10:29 AM
Thank you so much, both of you!
SimplePortal 2.3.8 © 2008-2024, SimplePortal