SimplePortal

Customization => Custom Coding => Topic started by: dabeer on January 08, 2009, 07:32:11 AM

Title: Thank-o-matic block
Post by: dabeer on January 08, 2009, 07:32:11 AM
Hello everyone

First of all, thank a lot for that magnificent piece of software and the friendly support you´re providing here.

Now, my SMF 1.1.7 site has Thank-o-matic mod (1.2.5) installed and I´m wondering if it would be possible to create a ¨Most thanks received¨ block for the Portal (2.0.5), which would display who received the most thanks in Thank-o-matic, in a similar fashion to "Top 5 posters" block.

Any hints on how to achieve this?

Cheers.
Title: Re: Thank-o-matic block
Post by: ???1031 on January 08, 2009, 05:21:49 PM
i think i can make a php block for this ;)
Title: Re: Thank-o-matic block
Post by: dabeer on January 08, 2009, 05:32:25 PM
I'd be very much obliged  :holding-flower:
Title: Re: Thank-o-matic block
Post by: ???1031 on January 09, 2009, 12:34:02 AM
The easiest way is :)

Most Thank Yo Given:
Code: [Select]
global $boarddir;
require_once($boarddir.'/SSI.php');
ssi_thankYouPostTopGiven(5);

Most Thanks You's resived:
Code: [Select]
global $boarddir;
require_once($boarddir.'/SSI.php');
ssi_thankYouPostTopResived(5);

You can change the 5 to the number you like to see :).

Bye
DIN1031
Title: Re: Thank-o-matic block
Post by: dabeer on January 09, 2009, 01:55:11 AM
Thank you, it worked, however I had to change line 2 of the code to:
Code: [Select]
require_once($boarddir.'/SSI.php');(slash was missing)

Also, shouldn't the name of the function be ssi_thankYouPostTopReceived instead of ssi_thankYouPostTopResived?

Anyone got an idea how to display avatars there as well?
Title: Re: Thank-o-matic block
Post by: ???1031 on January 10, 2009, 03:54:47 PM
Yes that was a mistake in my first version... but i could not change it because so many use it when i saw it xD.

Hmmm avatars is not so easy, but i will see if i can do that :X.

Bye
DIN1031
Title: Re: Thank-o-matic block
Post by: dabeer on January 12, 2009, 04:57:08 PM
Hmmm avatars is not so easy, but i will see if i can do that :X.

Actually, I'm really glad to have got it working the way it does now, but if you ever come up with code that shows avatars as well, I'll be delighted.
Title: Re: Thank-o-matic block
Post by: dabeer on January 15, 2009, 05:40:30 AM
While we're at Thank-o-matic code, another thing worth considering would be a kind of "top 5 thanks received posts" which would display X posts with most thanks received (so the most valuable ones, the mod could actually be called "5 Most Valuable posts")

What do you reckon?

Any easy way of implementing that?
Title: Re: Thank-o-matic block
Post by: ???1031 on January 31, 2009, 01:13:10 PM
It's not so easy, because it's the standard ssi version :X
Title: Re: Thank-o-matic block
Post by: [SiNaN] on February 02, 2009, 04:13:52 PM
TopGiven with avatars:

Code: [Select]
global $boarddir, $memberContext;

require_once($boarddir.'/SSI.php');

$top_given = ssi_thankYouPostTopGiven(5, 'array');

echo '
<table>';

foreach ($top_given as $member)
{
loadMemberData($member['id']);
loadMemberContext($member['id']);

echo '
<tr>
<td style="width: 55px; text-align: center;">', !empty($memberContext[$member['id']]['avatar']['href']) ? '
<img src="' . $memberContext[$member['id']]['avatar']['href'] . '" alt="' . $member['name'] . '" width="50" />' : '', '
</td>
<td>
', $member['link'], '<br />
<span class="smalltext">
<strong>', $txt['thank_you_post_made_display'], ':</strong> ', $member['thank_you_post_made'], '<br />
<strong>', $txt['thank_you_post_became_display'], ':</strong> ', $member['thank_you_post_became'], '
</span>
</td>
</tr>';
}
echo '
</table>';

If you want it to be top recieved, just change 'TopGiven' to 'TopResived'.

Top Thanked Posts:

Code: [Select]
global $db_prefix, $scripturl, $user_info, $txt;

$request = db_query("
SELECT
m.ID_MSG, m.ID_TOPIC, m.ID_MEMBER, m.subject, COUNT(*) AS thanks,
IFNULL(mem.realName, m.posterName) AS posterName
FROM {$db_prefix}thank_you_post AS ty
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_MSG = ty.ID_MSG)
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = m.ID_BOARD)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE $user_info[query_see_board]
AND b.thank_you_post_enable = 0
GROUP BY ID_MSG
ORDER BY thanks DESC
LIMIT 10", __FILE__, __LINE__);
$return = array();
while ($row = mysql_fetch_assoc($request))
$return[] = array(
'id' => $row['ID_MSG'],
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => empty($row['ID_MEMBER']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
),
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
'thanks' => $row['thanks'],
);
mysql_free_result($request);

echo '
<ol>';

foreach ($return as $post)
echo '
<li>', $post['link'], ' <span class="smalltext">', $txt[525], ' ', $post['poster']['link'], '<br />', $txt['thank_you_post_thx_display'], ': ', $post['thanks'], '</li>';

echo '
</ol>';
Title: Re: Thank-o-matic block
Post by: dabeer on February 15, 2009, 10:53:49 AM
Thanks, Blue Dream! Exactly what I had in mind  ;D

In Top Thanks Given/Received the only problem is that the strings $txt['thank_you_post_made_display'] and $txt['thank_you_post_become_display'] are not displayed. Both strings are defined in index.MYLANGUAGE.php and they are both displayed without problems in other mods. Any idea what I'm missing?
Title: Re: Thank-o-matic block
Post by: [SiNaN] on February 15, 2009, 10:56:08 AM
Find:

Code: [Select]
global $boarddir, $memberContext;
Repace:

Code: [Select]
global $boarddir, $memberContext, $txt;
Title: Re: Thank-o-matic block
Post by: dabeer on February 15, 2009, 11:17:47 AM
Thanks, it worked!
SimplePortal 2.3.8 © 2008-2024, SimplePortal