<?php
/**
* @author Pars (http://MyBBIran.com)
* @copyright 2010
*/
//Add hook for index top posters
$plugins->add_hook('global_intermediate‘ , 'itp‘);
//info for index top poster
function itp_info()
{
return array(
'name' => 'Index Top Posters',
'description' => 'Show Todays/Weekly/Monthly/Forum Top Posters in Index',
'website' => 'http://MyBBIran.com',
'author' => 'Pars, MyBBIran.com',
'authorsite' => 'http://MyBBIran.com',
'version' => '1.0.1',
'compatibility' => '*'
);
}
//actition for MyBB Iran
function itp_activate()
{
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
global $lang, $db, $mybb, $templates, $captcha;
$query = $db->simple_select("settinggroups","COUNT(*) as rows");
$rows = $db->fetch_field($query,"rows");
$itp_group = array('name' => 'itp','title' => 'Index Top Posters','description' => 'Settings for Index Top Posters Plugin','disporder' =>$rows + 1,'isdefault' => '0',);
$db->insert_query('settinggroups',$itp_group);
$gid = $db->insert_id();
$itp_setting_1 = array('name' => 'showitp','title' =>'On/Off','description' =>'Display Index Top Posters in Index?','optionscode' => 'onoff','value' => '1','disporder' => 1,'gid' => intval($gid),);
$itp_setting_2 = array('name' => 'pofitp','title' =>'Position ','description' =>'Where do you want to display Index Top Posters?','optionscode' => 'select\nheader=Header\nfooter=Footer','value' => 'header','disporder' => 2,'gid' => intval($gid),);
$itp_setting_3 = array('name' => 'inbitp','title' =>'Custom text or banner','description' =>'You can enter text or arbitrary code for displayed in below Index Top Posters.','optionscode' => 'textarea','value' => '','disporder' => 3,'gid' => intval($gid),);
$itp_setting_4 = array('name' => 'limititp','title' =>'Number of Users','description' =>'How many users would be displayed?','optionscode' => 'text','value' => '5','disporder' => 4,'gid' => intval($gid),);
$itp_setting_5 = array('name' => 'userstyleitp','title' =>'Username Style','description' =>'Do you want to display Username Style?','optionscode' => 'yesno','value' => '1','disporder' => 5,'gid' => intval($gid),);
$itp_setting_6 = array('name' => 'itpava','title' =>'Display User Avatar','description' =>'Do you want to Display User Avatar?','optionscode' => 'yesno','value' => '0','disporder' => 6,'gid' => intval($gid),);
$db->insert_query('settings',$itp_setting_1);
$db->insert_query('settings',$itp_setting_2);
$db->insert_query('settings',$itp_setting_3);
$db->insert_query('settings',$itp_setting_4);
$db->insert_query('settings',$itp_setting_5);
$db->insert_query('settings',$itp_setting_6);
rebuildsettings();
$itp_template = array(
"title" => 'itp',
"template" => $db->escape_string('<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="4" align="center"><strong>{$lang->itp}</strong></td>
</tr>
<tr>
<td class="tcat" width="25%" align="center"><strong>{$lang->t_itp}</strong></td>
<td class="tcat" width="25%" align="center"><strong>{$lang->w_itp}</strong></td>
<td class="tcat" width="25%" align="center"><strong>{$lang->m_itp}</strong></td>
<td class="tcat" width="25%" align="center"><strong>{$lang->top_itp}</strong></td>
</tr>
<tr>
<td class="trow1" width="25%" valign="top">
{$today_itp}
</td>
<td class="trow2" width="25%" valign="top">
{$week_itp}
</td>
<td class="trow1" width="25%" valign="top">
{$m_itp}
</td>
<td class="trow2" width="25%" valign="top">
{$top_itp}
</td>
</tr>
{$banner}
</table>
<div style="text-align: right; font-size: 10px;"> Top Posters by <a href="http://www.MyBBIran.com" target="blank">MyBBIran.com</a></div> <br />'),
"sid" => "-1",
"version" => "1.0",
"dateline" => "1157735635",
);
$db->insert_query("templates", $itp_template);
find_replace_templatesets("index", '#{\$boardstats}#', "{\$itpf}\n{\$boardstats}");
find_replace_templatesets("index", '#{\$header}#', "{\$header}\n{\$itph}");
}
//Deactive ITP (very good because no change need)
function itp_deactivate()
{
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='itp'");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('showitp', 'itp')");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('pofitp', 'itp')");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('inbitp', 'itp')");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('limititp', 'itp')");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('userstyleitp', 'itp')");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('itpava', 'itp')");
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='itp'");
rebuildsettings();
find_replace_templatesets("index", '#'.preg_quote('{$itpf}').'#', '',0);
find_replace_templatesets("index", '#'.preg_quote('{$itph}').'#', '',0);
}
//Function of ITP really easy (As easy as hot cake)
function itp()
{
global $db, $theme, $mybb, $templates, $lang, $itpf, $itph,$itp;
$lang->load("itp");
if($mybb->settings['showitp'] != 0)
{
//get today
$todaytime = mktime(0, 0, 0, date("n"), date("j"), date("Y"));
$query = $db->query("SELECT u.uid,u.username,u.displaygroup,u.usergroup,u.avatar,COUNT(*) AS ptoday FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid) WHERE p.dateline > $todaytime GROUP BY p.uid ORDER BY ptoday DESC LIMIT 0,".$mybb->settings['limititp']."");
$today_itp = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
while($user = $db->fetch_array($query))
{
$posts = $user['ptoday'];
if($user['avatar'] != '')
{
$user['avatar'] = $user['avatar'];
}
else
{
$user['avatar'] = "./images/default_avatar.gif";
}
if($mybb->settings['userstyleitp'] == 1)
{
$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
}
$userlink = build_profile_link($user['username'], $user['uid']);
if($mybb->settings['itpava'] == 0)
{
$today_itp .= '<tr><td align="left">'.$userlink.'</td><td align="right">'.$posts.'</td></tr>';
}
else
{
$ava = '<img src="'.$user['avatar'].'" width="24px" height="24px">';
$today_itp .= '<tr><td width="30px">'.$ava.'</td><td align="left">'.$userlink.'</td><td align="right">'.$posts.'</td></tr>';
}
}
$today_itp .= '</table>';
//get week
$weektime = TIME_NOW - 604800;
$query = $db->query("SELECT u.uid,u.username,u.displaygroup,u.usergroup, u.avatar ,COUNT(*) AS pweek FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid) WHERE p.dateline > $weektime GROUP BY p.uid ORDER BY pweek DESC LIMIT 0,".$mybb->settings['limititp']."");
$week_itp = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
while($user = $db->fetch_array($query))
{
$posts = $user['pweek'];
if($user['avatar'] != '')
{
$user['avatar'] = $user['avatar'];
}
else
{
$user['avatar'] = "./images/default_avatar.gif";
}
if($mybb->settings['userstyleitp'] == 1)
{
$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
}
$userlink = build_profile_link($user['username'], $user['uid']);
if($mybb->settings['itpava'] == 0)
{
$week_itp .= '<tr><td align="left">'.$userlink.'</td><td align="right">'.$posts.'</td></tr>';
}
else
{
$ava = '<img src="'.$user['avatar'].'" width="24px" height="24px">';
$week_itp .= '<tr><td width="30px"> '.$ava.' </td> <td align="left"> '.$userlink.'</td><td align="right">'.$posts.'</td></tr>';
}
}
$week_itp .= '</table>';
//get month
$mtime = mktime(0, 0, 0, date("n"), 1, date("Y"));
$query = $db->query("SELECT u.uid,u.username,u.displaygroup,u.usergroup,u.avatar,COUNT(*) AS pmonth FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid) WHERE p.dateline > $mtime GROUP BY p.uid ORDER BY pmonth DESC LIMIT 0,".$mybb->settings['limititp']."");
$m_itp = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
while($user = $db->fetch_array($query))
{
$posts = $user['pmonth'];
if($user['avatar'] != '')
{
$user['avatar'] = $user['avatar'];
}
else
{
$user['avatar'] = "./images/default_avatar.gif";
}
if($mybb->settings['userstyleitp'] == 1)
{
$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
}
$userlink = build_profile_link($user['username'], $user['uid']);
if($mybb->settings['itpava'] == 0)
{
$m_itp .= '<tr><td align="left">'.$userlink.'</td><td align="right">'.$posts.'</td></tr>';
}
else
{
$ava = '<img src="'.$user['avatar'].'" width="24px" height="24px">';
$m_itp .= '<tr><td width="30px">'.$ava.'</td><td align="left">'.$userlink.'</td><td align="right">'.$posts.'</td></tr>';
}
}
$m_itp .= '</table>';
//get tops
$mtime = TIME_NOW - 2592000;
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users ORDER BY postnum DESC LIMIT 0,".$mybb->settings['limititp']."");
$top_itp = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
while($user = $db->fetch_array($query))
{
$posts = $user['postnum'];
if($user['avatar'] != '')
{
$user['avatar'] = $user['avatar'];
}
else
{
$user['avatar'] = "./images/default_avatar.gif";
}
if($mybb->settings['userstyleitp'] == 1)
{
$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
}
$userlink = build_profile_link($user['username'], $user['uid']);
if($mybb->settings['itpava'] == 0)
{
$top_itp .= '<tr><td align="left">'.$userlink.'</td><td align="right">'.$posts.'</td></tr>';
}
else
{
$ava = '<img src="'.$user['avatar'].'" width="24px" height="24px">';
$top_itp .= '<tr><td width="30px">'.$ava.'</td><td align="left">'.$userlink.'</td><td align="right">'.$posts.'</td></tr>';
}
}
$top_itp .= '</table>';
//check banner
if($mybb->settings['inbitp'] != '')
{
$banner = '<tr><td colspan="4" class="trow1" align="center">'.$mybb->settings['inbitp'].'</td></tr>';
}
//get template
if($mybb->settings['pofitp'] == 'header')
{
eval("\$itph = \"".$templates->get("itp")."\";");
$itpf = "";
}
else
{
eval("\$itpf = \"".$templates->get("itp")."\";");
$itph = "";
}
}
}
?>