Kod:
<?php
//Top Posters Sidebar Mod by Borbole
//Trying to access directly the file, are we :D
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
//Hooking into index_start with our function
$plugins->add_hook("index_start", "top_posters_sidebar");
//Show some info about our mod
function sidebarposters_info()
{
return array(
"name" => "Top Posters Sidebar",
"description" => "It shows a list of the top posters in the sidebar.",
"website" => "http://www.forumservices.eu/mybb",
"version" => "1.0",
"author" => "borbole",
"authorsite" => "http://www.forumservices.eu/mybb",
"compatibility" => "16*",
'guid' => '4cd2c09b4d56e4cc2a9953d655b8608b'
);
}
//Activate it
function sidebarposters_activate()
{
global $db;
//Insert the mod settings in the portal settinggroup
$query = $db->simple_select("settinggroups", "gid", "name='forumhome'");
$gid = $db->fetch_field($query, "gid");
$setting = array(
'name' => 'posters_nr',
'title' => 'Top Postów Sidebar',
'description' => 'Enter here the number of top posters that you would like to show in the sidebar. By default it will show 5 posters.',
'optionscode' => 'text',
'value' => '5',
'disporder' => '99',
'gid' => intval($gid)
);
$db->insert_query('settings',$setting);
rebuild_settings();
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("index", '#'.preg_quote('{$forums}').'#', '<table width="100%" border="0">
<tr>
<td width="75%" valign="top">{$forums}</td>
<td width="25%" valign="top">{$top_posters}</td>
</tr>
</table>');
}
//Don't want to use it anymore? Let 's deactivate it then and drop the settings and the custom template as well
function sidebarposters_deactivate()
{
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='posters_nr'");
rebuild_settings();
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("index", '#'.preg_quote('<table width="100%" border="0">
<tr>
<td width="75%" valign="top">{$forums}</td>
<td width="25%" valign="top">{$top_posters}</td>
</tr>
</table>').'#', '{$forums}',0);
}
function top_posters_sidebar()
{
global $db, $mybb, $forums, $theme, $top_posters;
$top_posters .= '
<table width="50%" cellpadding="5" cellspacing="1" border="0" class="tborder">
<tr>
<td class="thead"><strong>Top Posterow</strong></td>
</tr>';
//Limit how many users to show
$limit = intval($mybb->settings['posters_nr']);
//Query to get top posters
$query = $db->query("
SELECT username, postnum, uid, usergroup, displaygroup
FROM ".TABLE_PREFIX."users
ORDER BY postnum DESC
LIMIT 0,{$limit}
;");
while($row = $db->fetch_array($query))
{
$top_posters .= '
<tr>';
$users = htmlspecialchars_uni($row['username']);
//Trim the usernames if they are over 9 characters
if (strlen($users) > 9)
{
$users = substr($users, 0, 9) . "...";
}
//Get the usernames and make them pretty too with the group styling
$user['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
$user['profilelink'] = build_profile_link($user['username'], $row['uid']);
$users = $user['profilelink'];
//Get the post count
$posts = "<a href=\"search.php?action=finduser&uid={$row['uid']}\">{$row['postnum']}</a>";
$top_posters .= '
<td class="trow1">' . $users . '
<span style="float:right;">' . $posts . '
</span>
</td>
</tr>';
}
$top_posters .= "</table><br />";
}
?>