To use this website completely, it is necessary to store cookies on your computer.
 

* Navigator

Expand - Collapse

* Recent Topics

by feline, [2017 May 23, 06:07:59]

* Statistic

  • *Total Members: 4452
  • *Latest: wintstar

  • *Total Posts: 16688
  • *Total Topics: 2558
  • *Online Today: 11
  • *Most Online: 292
(2016 November 12, 09:37:31)
  • *Users: 1
  • *Guests: 0
  • *Spiders: 2
  • *Total: 3

[Block] Top Poster This Week Block for SMF 2.0

Started by samozin, 2010 February 27, 12:00:32

previous topic - next topic

0 Members and 0 Guests are viewing this topic.

samozin

2010 February 27, 12:00:32
Top 10 Posters Today

SMF 2.x:

Code Select
global $smcFunc, $scripturl, $context, $settings;

// Top 10 Posters so far today
// Change the time depending on server time offset
list($year, $month, $day) = explode('-', date('Y-m-d'));
    $starttime = mktime(0, 0, 0, $month, $day, $year);
// 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_day'] = array();
$max_num_posts = 1;
while ($row_members = $smcFunc['db_fetch_assoc']($request))
{
$context['top_posters_day'][] = 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_day'] as $i => $j)
$context['top_posters_day'][$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_day'] 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>';


Top 10 Posters This Week

SMF 2.x:

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>';

samozin

#1
2010 March 03, 20:32:38
still waiting :(

Cool

#2
2010 March 04, 04:22:50
waiting for what?
 |I Use: SMF 2.0.5 | PortaMx 1.51
Q: What do you do when you see a bear in the woods?
A: Play Dead!
H-A-H-L = Happy Admins Have Linux

samozin

#3
2010 March 05, 12:26:20
oh sorry  it supposed to wait someone to reply me here
https://www.portamx.com/topic_1562.msg9125.html#msg9125
sorry wrong post :(

azhriel

#4
2010 July 07, 06:03:54
how can i make this a top 10 poster or top 5 not just by week.

& How can i make names appear in color based on their ranks

Thanks & Godbless

BradToxicBlonde

#5
2012 January 21, 18:42:06
I know this is a sort of old topic but I just found it today and I used the code in my forum and it work wonderfully.  I was wondering I have the following code I use which shows the top posters of all time along with their avatars.  Is there a way to use your code but add the avatars to it for Top Posters of the Day and Top Posters of the Week?

Code Select
global $smcFunc, $scripturl, $modSettings;

// Height and width of avatar
$width = '40px';
$height = '40px';
// Number of top posters displayed
$topPoster = 10;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, mem.avatar, a.id_attach, a.attachment_type, a.filename
FROM ({db_prefix}members as mem)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE show_online = 1
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topPoster)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$users[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => $row['posts'],
'show' => $row['show_online'],
'avatar' => array(
    'image' => empty($row['avatar']) ? ($row['id_attach'] > 0 ? 'src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
    ),
);
}

$smcFunc['db_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>';

FireDitto

2012 September 17, 11:03:04 Last Edit: 2012 September 19, 12:01:08 by FireDitto
Hrm, this is very nice.

How would I exclude selected member groups? Eg, the admin or staff from the inclusion?


EDIT: And make it from Day 1 to current/Last Day of each month, rather than per week?

Thedukeisnotdead

#7
2012 December 16, 05:08:12
Nice code, but takes 8 seconds to refresh, too long of a wait

markf

#8
2015 April 22, 18:46:52
Old thread I know, but I just started using php blocks and this is nice.
The only issue is there's a missing percent sign in the output for the bar graphic:

Code Select

... $poster['post_percent'] . '%" ...


Putting the percent between the single quote and double scales the bar down to the allowable 20% area of the table, otherwise it's a number and treated as pixels, so extends beyond bounds.