<?php
class TopXStats
{
/**#@+
* Registry Object Shortcuts
*
* @access protected
* @var object
*/
protected $registry;
protected $DB;
protected $settings;
protected $lang;
protected $member;
protected $memberData;
protected $statistics;
/**#@-*/
public function __construct()
{
/* Make registry objects */
$this->registry = ipsRegistry::instance();
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->lang = $this->registry->getClass('class_localization');
$this->member = $this->registry->member();
$this->memberData =& $this->registry->member()->fetchMemberData();
$blocks = 0;
for ( $i = 1; $i <= 6; $i ++ )
{
$setting = $this->settings[ "en30_statblock{$i}" ];
if ( $setting != 0 )
{
$blocks++;
}
}
if ( $blocks > 3 )
{
$latestPosts = 11;
}
else
{
$latestPosts = 5;
}
$this->statistics = array(
1 => array(
'key' => 'latest_forum_news',
'select' => array( 'select' => 'tid as id, title, start_date as statistic',
'from' => 'topics',
'where' => 'forum_id IN(' . $this->settings['en30_latestnewsforums'] . ')',
'order' => 'start_date DESC',
'limit' => array( 0, $this->settings['en30_xstats'] )
),
'hover' => 'Date',
'icon' => 'member.png',
'act' => 'showtopic'
),
2 => array(
'key' => 'most_popular_forums',
'select' => array( 'select' => 'id, name as title, posts as statistic',
'from' => 'forums',
'where' => 'parent_id != -1',
'order' => 'posts DESC',
'limit' => array( 0, $this->settings['en30_xstats'] )
),
'hover' => 'Replies',
'icon' => 'forum.png',
'act' => 'showforum'
),
3 => array(
'key' => 'top_posters',
'select' => array( 'select' => 'member_id as id, posts as statistic, members_display_name as title, member_group_id',
'from' => 'members',
'order' => 'posts DESC',
'limit' => array( 0, $this->settings['en30_xstats'] )
),
'hover' => 'Posts',
'icon' => 'member.png',
'act' => 'showuser'
),
4 => array(
'key' => 'top_sheriffs',
'select' => array( 'select' => 'wl.wlog_addedby as id, COUNT(wlog_id) as statistic',
'from' => array( 'warn_logs' => 'wl' ),
'group' => 'wl.wlog_addedby',
'order' => 'COUNT(wlog_id) DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 'm.member_group_id, m.members_display_name as title',
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id = wl.wlog_addedby',
'type' => 'left',
)
)
),
'hover' => 'Warnings Issued',
'icon' => 'member.png',
'act' => 'showuser'
),
5 => array(
'key' => 'most_wanted',
'select' => array( 'select' => 'wl.wlog_mid as id, COUNT(wlog_id) as statistic',
'from' => array( 'warn_logs' => 'wl' ),
'where' => "wl.wlog_type = 'neg'",
'group' => 'wl.wlog_mid',
'order' => 'COUNT(wlog_id) DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 'm.member_group_id, m.members_display_name as title',
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id = wl.wlog_mid',
'type' => 'left',
)
)
),
'hover' => 'Warnings',
'icon' => 'member.png',
'act' => 'showuser'
),
6 => array(
'key' => 'new_members',
'select' => array( 'select' => 'member_id as id, joined as statistic, members_display_name as title, member_group_id',
'from' => 'members',
'order' => 'joined DESC',
'limit' => array( 0, $this->settings['en30_xstats'] )
),
'hover' => 'Date',
'icon' => 'member.png',
'act' => 'showuser'
),
7 => array(
'key' => 'recent_visitors',
'select' => array( 'select' => 'member_id as id, last_visit as statistic, members_display_name as title, member_group_id',
'from' => 'members',
'order' => 'last_visit DESC',
'limit' => array( 0, $this->settings['en30_xstats'] )
),
'hover' => 'Last Visit',
'icon' => 'member.png',
'act' => 'showuser'
),
8 => array(
'key' => 'top_thread_starters',
'select' => array( 'select' => 't.starter_id as id, COUNT(tid) as statistic',
'from' => array( 'topics' => 't' ),
'group' => 't.starter_id',
'order' => 'COUNT(tid) DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 'm.member_group_id, m.members_display_name as title',
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id = t.starter_id',
'type' => 'left',
)
)
),
'hover' => 'Topics',
'icon' => 'member.png',
'act' => 'showuser'
),
9 => array(
'key' => 'recent_name_changes',
'select' => array( 'select' => 'dc.dname_member_id as id, dc.dname_date as statistic, dc.dname_previous, dc.dname_current',
'from' => array( 'dnames_change' => 'dc' ),
'order' => 'dc.dname_date DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 'm.member_group_id',
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id = dc.dname_member_id',
'type' => 'left',
)
)
),
'hover' => 'Date',
'icon' => 'member.png',
'act' => 'showuser'
),
10 => array(
'key' => 'most_popular_members',
'select' => array( 'select' => 'member_id as id, members_profile_views as statistic, members_display_name as title, member_group_id',
'from' => 'members',
'order' => 'members_profile_views DESC',
'limit' => array( 0, $this->settings['en30_xstats'] )
),
'hover' => 'Profile Views',
'icon' => 'member.png',
'act' => 'showuser'
),
11 => array(
'key' => 'latest_profile_comments',
'select' => array( 'select' => 'pc.comment_for_member_id as id, pc.comment_by_member_id, pc.comment_date, pc.comment_content as title',
'from' => array( 'profile_comments' => 'pc' ),
'order' => 'pc.comment_date DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 'm.member_group_id, m.members_display_name as statistic',
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id = pc.comment_by_member_id',
'type' => 'left',
)
)
),
'hover' => 'Commenter',
'icon' => 'post.png',
'act' => 'showuser'
),
12 => array(
'key' => 'top_member_reputation',
'select' => array( 'select' => 'pp.pp_member_id as id, pp.pp_reputation_points as statistic',
'from' => array( 'profile_portal' => 'pp' ),
'order' => 'pp.pp_reputation_points DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 'm.member_group_id, m.members_display_name as title',
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id = pp.pp_member_id',
'type' => 'left',
)
)
),
'hover' => 'Reputation',
'icon' => 'member.png',
'act' => 'showuser'
),
13 => array(
'key' => 'most_views',
'select' => array( 'select' => 'tid as id, title, views as statistic',
'from' => 'topics',
'order' => 'views DESC',
'limit' => array( 0, $this->settings['en30_xstats'] )
),
'hover' => 'Topic Views',
'icon' => 'post.png',
'act' => 'showtopic'
),
14 => array(
'key' => 'latest_polls',
'select' => array( 'select' => 'p.tid as id, p.start_date as statistic, p.poll_question as title',
'from' => array( 'polls' => 'p' ),
'order' => 'p.start_date DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 't.title as title2',
'from' => array( 'topics' => 't' ),
'where' => 't.tid = p.tid',
'type' => 'left',
)
)
),
'hover' => 'Date',
'icon' => 'poll.png',
'act' => 'showtopic'
),
15 => array(
'key' => 'most_replies',
'select' => array( 'select' => 'tid as id, title, posts as statistic',
'from' => 'topics',
'order' => 'posts DESC',
'limit' => array( 0, $this->settings['en30_xstats'] )
),
'hover' => 'Replies',
'icon' => 'post.png',
'act' => 'showtopic'
),
16 => array(
'key' => 'recent_attachments',
'select' => array( 'select' => 'a.attach_file as title, a.attach_rel_id as pid, a.attach_date as statistic',
'from' => array( 'attachments' => 'a' ),
'order' => 'attach_date DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 'p.topic_id as id',
'from' => array( 'posts' => 'p' ),
'where' => 'p.pid = a.attach_rel_id',
'type' => 'left',
)
)
),
'hover' => 'Date',
'icon' => 'attachment.png',
'act' => 'showtopic={tid}&pid={pid}#entry{pid}'
),
17 => array(
'key' => 'top_thread_reputation',
'select' => array( 'select' => 'rc.type_id, rc.rep_points as statistic',
'from' => array( 'reputation_cache' => 'rc' ),
'where' => 'rc.type_id = t.topic_firstpost',
'order' => 'rep_points DESC',
'limit' => array( 0, $this->settings['en30_xstats'] ),
'add_join' => array(
array(
'select' => 't.title, t.tid as id',
'from' => array( 'topics' => 't' ),
'where' => 'rc.type_id = t.topic_firstpost',
'type' => 'left',
)
)
),
'hover' => 'Reputation',
'icon' => 'post.png',
'act' => 'showtopic'
),
18 => array(
'key' => 'latest_posts',
'select' => array( 'select' => 't.tid as id, t.title, t.last_poster_id as id2',
'from' => array( 'topics' => 't' ),
'where' => "t.forum_id NOT IN({$this->settings['en30_topxexcludeforums']}) and (pi.perm_type='forum' and " . $this->DB->buildRegexp( "pi.perm_2", $this->member->perm_id_array ) . ") and t.approved=1 and (t.moved_to='' or t.moved_to" . $this->DB->buildIsNull( true ) . ")",
'order' => 't.last_post DESC',
'limit' => array( 0, $latestPosts ),
'add_join' => array(
array(
'select' => 'm.member_group_id, m.members_display_name as statistic',
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id = t.last_poster_id',
'type' => 'left',
),
array(
'select' => 'pi.perm_2',
'from' => array( 'permission_index' => 'pi' ),
'where' => "pi.app='forums' AND pi.perm_type='forum' AND pi.perm_type_id=t.forum_id",
'type' => 'left',
),
)
),
'hover' => 'Poster',
'icon' => 'post.png',
'act' => 'showtopic'
),
);
}
public function getOutput()
{
if ( !$this->settings['en30_topxstats'] )
{
return;
}
if ( in_array( $this->memberData['member_group_id'], explode( ",", $this->settings['en30_topxexclude'] ) ) )
{
return;
}
$blockCount = 0;
for ( $i = 1; $i <= 6; $i ++ )
{
$setting = $this->settings[ "en30_statblock{$i}" ];
if ( $setting != 0 )
{
$blockCount++;
}
}
$blocks = array();
for ( $i = 1; $i <= 6; $i ++ )
{
$setting = $this->settings[ "en30_statblock{$i}" ];
$blockRow = ( $i <= 3 ) ? 1 : 2;
if ( $setting != 0 )
{
if ( ! is_numeric( $setting ) )
{
return "<br /><h3 style='color: red'>[EN30] Top X Stats v1.0.1 ERROR</h3><span style='font-weight: bold'>You must not select a statistic group heading (e.g. -----MEMBER STATISTICS-----) as a statistic. Please fix this in Admin CP -> Tools & Settings -> Hooks -> [EN30] Top X Stats v1.0.1 -> Block #{$i}.</span>";
}
if ( $setting == 1 && empty( $this->settings['en30_latestnewsforums'] ) )
{
return "<br /><h3 style='color: red'>[EN30] Top X Stats v1.0.1 ERROR</h3><span style='font-weight: bold'>If you have selected
Latest Forum News as a statistic block, you must select at least
1 news forum in Admin CP -> Tools & Settings -> Hooks -> [EN30] Top X Stats v1.0.1 -> News Forums.</span>";
}
$statistics = array();
$class = 'row1';
$this->DB->build( $this->statistics[ $setting ]['select'] );
$this->DB->execute();
while( $row = $this->DB->fetch() )
{
$row['act'] = $this->statistics[ $setting ]['act'];
$row['link'] = "{$row['act']}={$row['id']}";
$row['icon'] = $this->statistics[ $setting ]['icon'];
$row['hover'] = $this->statistics[ $setting ]['hover'];
$row['makeTitleFormatted'] = false;
$row['makeStatisticFormatted'] = false;
if ( $setting == 9 )
{
$row['title'] = "{$row['dname_previous']} - {$row['dname_current']}";
$row['seoTitle'] = IPSText::makeSeoTitle( $row['dname_current'] );
}
else
{
$row['seoTitle'] = IPSText::makeSeoTitle( $row['title'] );
}
if ( $setting == 14 )
{
$row['title'] = ( ! empty( $row['title'] ) ) ? $row['title'] : $row['title2'];
}
if ( $setting == 16 )
{
$row['link'] = str_replace( array( "{tid}", "{pid}" ), array( $row['id'], $row['pid'] ), $row['act'] );
}
if ( $setting == 11 )
{
$row['id2'] = $row['comment_by_member_id'];
$row['seoTitle2'] = IPSText::makeSeoTitle( $row['statistic'] );
}
if ( $row['hover'] == 'Reputation' )
{
$row['statistic'] = "<span class='reputation positive rep_show' style='margin: 0; padding: 0 8px; font-size: 0.8em;' title='Репутация'>{$row['statistic']}</span>";
}
else if ( $row['hover'] == 'Date' )
{
$row['statistic'] = date( $this->settings['en30_statdateformat'], $row['statistic'] );
}
else if ( $row['hover'] == 'Last Visit' )
{
if ( date( 'd' ) != date( 'd', $row['statistic'] ) )
{
$row['statistic'] = date( $this->settings['en30_statdateformat'], $row['statistic'] );
}
else
{
$row['statistic'] = date( 'h:i A', $row['statistic'] );
}
}
else
{
if ( in_array( $row['hover'], array( 'Replies', 'Topic Views', 'Profile Views', 'Topics', 'Warnings', 'Warnings Issued', 'Posts' ) ) )
{
$row['statistic'] = $this->registry->getClass('class_localization')->formatNumber( $row['statistic'] );
}
}
$row['class'] = $class;
if ( $class == 'row1' )
{
$class = 'row2';
}
else
{
$class = 'row1';
}
if ( $this->settings['en30_formatnames'] )
{
if ( in_array( $this->statistics[ $setting ]['key'], array( 'top_posters', 'top_sheriffs', 'most_wanted', 'new_members', 'recent_visitors', 'top_thread_starters', 'most_popular_members', 'top_member_reputation' ) ) )
{
$row['makeTitleFormatted'] = true;
}
if ( $row['hover'] == 'Commenter' )
{
$row['makeStatisticFormatted'] = true;
}
}
$statistics[] = $row;
}
$blocks[] = array( 'lang' => "en30_{$this->statistics[ $setting ]['key']}",
'img' => "{$this->statistics[ $setting ]['key']}.png",
'row' => $blockRow,
'stats' => $statistics,
);
}
else
{
if ( $blockCount > 3 )
{
$blocks[] = array( 'lang' => "en30_spacer",
'img' => "spacer.gif",
'row' => $blockRow,
'stats' => array(),
);
}
}
}
$rowSpan = 0;
if ( count( $blocks ) > 3 )
{
$rowSpan = 3;
}
$latestPosts = array();
$class = 'row1';
$this->DB->build( $this->statistics[18]['select'] );
$this->DB->execute();
while( $row = $this->DB->fetch() )
{
$row['act'] = $this->statistics[ 18 ]['act'];
$row['link'] = "{$row['act']}={$row['id']}";
$row['icon'] = $this->statistics[ 18 ]['icon'];
$row['class'] = $class;
$row['hover'] = $this->statistics[ 18 ]['hover'];
$row['seoTitle'] = IPSText::makeSeoTitle( $row['title'] );
$row['seoTitle2'] = IPSText::makeSeoTitle( $row['statistic'] );
$row['makeTitleFormatted'] = false;
$row['makeStatisticFormatted'] = false;
if ( $class == 'row1' )
{
$class = 'row2';
}
else
{
$class = 'row1';
}
if ( $this->settings['en30_formatnames'] )
{
$row['makeStatisticFormatted'] = true;
}
$latestPosts[] = $row;
}
$this->html = $this->registry->getClass('output')->getTemplate('topxstats')->output( $blocks, $latestPosts, $rowSpan );
return $this->html;
}
}