//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 = TIME_NOW - 86400;
$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'] != '' || $mybb->user['uid'] != 0)
{
$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 = "";
}
}
}