Widget: Top 5 Posters this Week



Top 5 Posters this Week
Released 22 December 2009

by MicroHellas

1.- Read before use it

  1. I know that the way of this Widget is not following vB's code standards. Has no templates to build, no plugins to add. Honestly, I really like the way that Lynne developed her "Users Online" widget, but I lost a full day yesterday trying to do this widget following her way, but it was impossible. I really spent hours changing Preregister and Register templates, but I had not even a single output. This dosen't means that my widget dosen't works. Actually works super fine and it need minimal time for you to install and use it (maybe less than 2 min).
  2. Why "This Week" and not "Last Week"? The reason (it's always is my own opinion) is "competition". I believe that push the Members to be more active. eg someone who is 3nd and has just 10 posts less than the 2nd, will push hiself to be more active.
2.- Installation

  • Goto Admincp->vBullietin CMS->Widgets->Create New Widget
  • Choose PHP Direct Execution as Widget's Type
  • Place a Title. eg Top 5 this Week. Keep it short as this is what will appear as title on your pages.
  • Click Save
  • Click Configure on the right of the new created widget.
  • Remove the default code that appears. Be sure to not leave behind even a single letter.
  • Copy and Paste the code that you can find below.
  • Leave the template name as is (vbcms_widget_execphp_page)
  • Click Save
  • Goto Admincp->vBullietin CMS->Layout Manager
  • Click Go on the Default Layout
  • Add the Widget to your Layout
  • Click Save
  • That's all !!
3.- PHP Code

 $posts = "Posts";
$starttime = mktime(0, 0, 0, date('n'), date('j'), date('Y')) - ((date('N')-1)*3600*24);
$mostactiveweek_get = vB::$db->query_read("
SELECT ".TABLE_PREFIX."user.userid, ".TABLE_PREFIX."user.username, ".TABLE_PREFIX."user.usertitle,
COUNT(".TABLE_PREFIX."post.postid) AS postcount
ON ".TABLE_PREFIX."post.userid=".TABLE_PREFIX."user.userid
AND dateline>'".$starttime."'
WHERE usergroupid=2
GROUP BY ".TABLE_PREFIX."user.userid
ORDER BY postcount DESC
LIMIT 5");
$topposter = true;
$output_bits = '';
while($user = vB::$db->fetch_array($mostactiveweek_get))
$percentage = round(($user[postcount]/$totalposts[postcount]) * 100);
if($topposter == true)
$avatarurl = fetch_avatar_url($user[userid]);
if (!$avatarurl) {
$useravatar = 'images/misc/avatar.png';
} else {
$useravatar = $avatarurl[0];
$output_bits .='
'.$posts.': '.$user[postcount].'
$topposter = false;
} else {
$output_bits .= ''.$user[username].''.$user[postcount].'
$output = $output_bits;

4.- Code Remarks

  • By default the widget shows only Members belonging to Usegroup 2 (Register Members). I don't think that is a good idea to include Administrators and Moderators as they're always (due to their positions) the most posts. But if you don't agree with this, and you want to include all usergroups, then just remove the line 17 (WHERE usergroupid=2)
  • If you want to use another word instead of "Post", change the first line
5.- Donations

Just in case..... (I know that I'm dreaming now) my PayPal is: maria@terra-travel.gr

Enjoy it