SimplePortal

Customization => Custom Coding => Topic started by: FireDitto on September 23, 2012, 06:37:03 AM

Title: Top Ten Posters
Post by: FireDitto on September 23, 2012, 06:37:03 AM
I got the code from here (http://portamx.com/1564/block-top-poster-this-week-block-for-smf-2-0/msg9131/#msg9131) and it was written by samozin. I asked for help there, but no one has responded.

I was hoping someone here could help me.

This code is for the Top Ten posters in the last 7 days.

What I would like is a Top Ten posts from Day 1 to Last Day of the given month, preferably with the ability to choose only from two selected membergroups (male character, female character) I've been playing with it, but I am unable to get it to do what I want. Any help would be amazing.

I had a dig around This Mod (http://custom.simplemachines.org/mods/index.php?mod=1231) on SMF too, for adding Top Ten to the Stats page but I just want the posters and I'd prefer it in a block, and restricted to the two mentioned membergroups.

Thank you.


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

// Top 10 Posters so far this week  (starts sunday)
$starttime = mktime(0, 0, 0, date("n"), date("j"), date("Y")) - (date("N")*3600*24);
// Offset based on forum time
$starttime = forum_time(false, $starttime);

$request = $smcFunc['db_query']('', '
SELECT me.id_member, me.real_name, COUNT(*) as count_posts
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}members AS me ON (me.id_member = m.id_member)
WHERE m.poster_time > {int:start_time}
AND m.id_member != 0
GROUP BY me.id_member
ORDER BY count_posts DESC
LIMIT 10',
array(
'start_time' => $starttime,
)
);

$context['top_posters_week'] = array();
$max_num_posts = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($request))
{
$context['top_posters_week'][] = array(
'name' => $row_members['real_name'],
'id' => $row_members['id_member'],
'num_posts' => $row_members['count_posts'],
'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
);

if ($max_num_posts < $row_members['count_posts'])
$max_num_posts = $row_members['count_posts'];
}
$smcFunc['db_free_result']($request);

foreach ($context['top_posters_week'] as $i => $j)
$context['top_posters_week'][$i]['post_percent'] = round(($j['num_posts'] * 100) / $max_num_posts);

// Tidy up
unset($max_num_posts, $row_members, $j, $i);

echo '
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
<th>Member</td>
<th colspan="2" style="text-align: right;">Posts</td>
</tr>';

foreach ($context['top_posters_week'] as $poster)
echo '
<tr>
<td width="60%" valign="top">', $poster['link'], '</td>
<td width="20%" align="left" valign="top">', $poster['num_posts'] > 0 ? '<img src="' . $settings['images_url'] . '/bar.gif" width="' . $poster['post_percent'] . '" height="15" alt="" />' : '&nbsp;', '</td>
<td width="20%" align="right" valign="top">', $poster['num_posts'], '</td>
</tr>';
echo '
</table>';
Title: Re: Top Ten Posters
Post by: FrizzleFried on September 23, 2012, 11:44:01 AM
BTW... the code above is supposed to show some sort of "bar" but doesn't... you can see attempt to do so and then disappear.
SimplePortal 2.3.8 © 2008-2024, SimplePortal