Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

User

Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Select language:

Community



Stats


  • *Total Posts: 16389
  • *Total Topics: 2501
  • *Online Today: 14
  • *Most Online: 292
(12.11.16, 09:37:31)
  • *Users: 0
  • *Guests: 0
  • *Spiders: 3
  • *Total: 3

  • *Baidu (3)

Author Topic: [Block] Top Poster This Week Block for SMF 2.0  (Read 30319 times)

0 Members and 0 Guests are viewing this topic.

Offline samozin

  • Newbie
  • *
  • Posts: 18
  • Gender: Male
    • الحب الحقيقى
[Block] Top Poster This Week Block for SMF 2.0
« on: 27.02.10, 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>';

Offline samozin

  • Newbie
  • *
  • Posts: 18
  • Gender: Male
    • الحب الحقيقى
Re: [Block] Top Poster This Week Block for SMF 2.0
« Reply #1 on: 03.03.10, 20:32:38 »
still waiting :(

Offline Cool

  • Free Tibet
  • PortaMx Supporter
  • *
  • Posts: 744
  • Gender: Male
  • I Hate Chinas Authority
Re: [Block] Top Poster This Week Block for SMF 2.0
« Reply #2 on: 04.03.10, 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

Offline samozin

  • Newbie
  • *
  • Posts: 18
  • Gender: Male
    • الحب الحقيقى
Re: [Block] Top Poster This Week Block for SMF 2.0
« Reply #3 on: 05.03.10, 12:26:20 »
oh sorry  it supposed to wait someone to reply me here
http://portamx.com/topic_1562.msg9125.html#msg9125
sorry wrong post :(

Offline azhriel

  • Newbie
  • *
  • Posts: 7
  • Gender: Male
    • Buhay-Noypi
Re: [Block] Top Poster This Week Block for SMF 2.0
« Reply #4 on: 07.07.10, 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

Offline BradToxicBlonde

  • Newbie
  • *
  • Posts: 1
  • Gender: Male
Re: [Block] Top Poster This Week Block for SMF 2.0
« Reply #5 on: 21.01.12, 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>';

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 69
  • Gender: Female
    • ThirdWorldNetwor.org
Re: [Block] Top Poster This Week Block for SMF 2.0
« Reply #6 on: 17.09.12, 11:03:04 »
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

  • Guest
Re: [Block] Top Poster This Week Block for SMF 2.0
« Reply #7 on: 16.12.12, 05:08:12 »
Nice code, but takes 8 seconds to refresh, too long of a wait

Offline markf

  • Newbie
  • *
  • Posts: 19
  • Gender: Male
Re: [Block] Top Poster This Week Block for SMF 2.0
« Reply #8 on: 22.04.15, 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.