Code: Select all
<?php
/**
*
* @package phpBB3
* @version $Id: functions_top_stats.php v1.0.9 20011/25/12 Stoker $
* @copyright (c) 2011 PhpBB3 BBCodes
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Include only once.
*/
if (!defined('INCLUDES_FUNCTIONS_TOP_STATS_PHP'))
{
define('INCLUDES_FUNCTIONS_TOP_STATS_PHP', true);
$flist = $auth->acl_getf('f_read', true);
$flist = array_unique(array_keys($flist));
// Recent Active Topics
if (!empty($config['tsrat_enable']) && sizeof($flist))
{
$sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_time, t.topic_views, t.topic_poster, t.topic_replies, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time, t.topic_last_view_time, t.topic_last_poster_id, f.forum_name, f.forum_image
FROM ' . TOPICS_TABLE . ' t
LEFT JOIN ' . FORUMS_TABLE . ' f ON (t.forum_id = f.forum_id)
WHERE ' . $db->sql_in_set('t.forum_id', $flist) . ' AND t.topic_moved_id = 0 AND t.topic_approved = 1
ORDER BY t.topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $config['tsrat_number']);
while ($row = $db->sql_fetchrow($result))
{
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']);
$view_last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']);
$view_first_poster = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile' . '&u=' . $row['topic_poster']);
$view_last_poster = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile' . '&u=' . $row['topic_last_poster_id']);
$view_viewforum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
$template->assign_block_vars('recent_active', array(
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_TIME' => $user->format_date($row['topic_time']),
'TOPIC_VIEWS' => $row['topic_views'],
'TOPIC_REPLIES' => $row['topic_replies'],
'TOPIC_FIRST_POSTER_NAME' => $row['topic_first_poster_name'],
'TOPIC_FIRST_POSTER_COLOUR' => $row['topic_first_poster_colour'],
'TOPIC_LAST_POSTER_NAME' => $row['topic_last_poster_name'],
'TOPIC_LAST_POSTER_COLOUR' => $row['topic_last_poster_colour'],
'TOPIC_LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
'TOPIC_LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
'U_FIRST_TOPIC' => $view_topic_url,
'U_LAST_TOPIC' => $view_last_post_url,
'USERNAME_FIRST' => $view_first_poster,
'USERNAME_LAST' => $view_last_poster,
'FORUM_NAME' => $row['forum_name'],
'FORUM_IMAGE' => $row['forum_image'],
'FORUM_URL' => $view_viewforum_url,
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'JSSCROLL_SPEED' => $config['tsjss_speed'],
'JSSCROLL_INTERVAL' => $config['tsjss_interval'],
'TSRAT_NUMBER' => $config['tsrat_number'],
'TS_JSSCROLL_DIRECTION' => $config['ts_jsscroll_direction'],
'TS_JSSCROLL_PAUSE' => $config['ts_jsscroll_pause'],
'TS_JSSCROLL_NAVIGATION' => $config['ts_jsscroll_navigation'],
'S_TSRAT_ENABLE' => $config['tsrat_enable'],
'S_TS_JSSCROLL' => $config['ts_jsscroll'],
'S_TS_TICKER' => $config['ts_ticker_enable'],
));
}
// Most viewed topics
if (!empty($config['tsmvt_enable']) && sizeof($flist))
{
$sql = 'SELECT topic_id, forum_id, topic_title, topic_views, topic_time, topic_first_poster_name, topic_first_poster_colour, topic_poster, topic_last_poster_id
FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $flist) . '
ORDER BY topic_views DESC';
$result = $db->sql_query_limit($sql, $config['tsmvt_number']);
while ($row = $db->sql_fetchrow($result))
{
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']);
$view_first_poster = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile' . '&u=' . $row['topic_poster']);
$view_last_poster = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile' . '&u=' . $row['topic_last_poster_id']);
$template->assign_block_vars('most_viewed', array(
'TOPIC_ID' => $row['topic_id'],
'FORUM_ID' => $row['forum_id'],
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_VIEWS' => $row['topic_views'],
'TOPIC_TIME' => $user->format_date($row['topic_time']),
'TOPIC_FIRST_POSTER_NAME' => $row['topic_first_poster_name'],
'TOPIC_FIRST_POSTER_COLOUR' => $row['topic_first_poster_colour'],
'U_FIRST_TOPIC' => $view_topic_url,
'USERNAME_FIRST' => $view_first_poster,
'USERNAME_LAST' => $view_last_poster,
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'S_TSMVT_ENABLE' => $config['tsmvt_enable'],
'TSMVT_NUMBER' => $config['tsmvt_number'],
));
}
// Most replied topics
if (!empty($config['tsmrt_enable']) && sizeof($flist))
{
$sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_time, topic_first_poster_name, topic_first_poster_colour, topic_poster, topic_last_poster_id
FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $flist) . '
ORDER BY topic_replies DESC';
$result = $db->sql_query_limit($sql, $config['tsmrt_number']);
while ($row = $db->sql_fetchrow($result))
{
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']);
$view_first_poster = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile' . '&u=' . $row['topic_poster']);
$view_last_poster = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile' . '&u=' . $row['topic_last_poster_id']);
$template->assign_block_vars('most_replied', array(
'TOPIC_ID' => $row['topic_id'],
'FORUM_ID' => $row['forum_id'],
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_REPLIES' => $row['topic_replies'],
'TOPIC_TIME' => $user->format_date($row['topic_time']),
'TOPIC_FIRST_POSTER_NAME' => $row['topic_first_poster_name'],
'TOPIC_FIRST_POSTER_COLOUR' => $row['topic_first_poster_colour'],
'U_FIRST_TOPIC' => $view_topic_url,
'USERNAME_FIRST' => $view_first_poster,
'USERNAME_LAST' => $view_last_poster,
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'S_TSMRT_ENABLE' => $config['tsmrt_enable'],
'TSMRT_NUMBER' => $config['tsmrt_number'],
));
}
// Most active users
if (!empty($config['tsmau_enable']))
{
if( ( $active_users = $cache->get('_ts_most_active_users') ) === false )
{
$sql = 'SELECT user_id, username, user_posts, user_colour, user_regdate
FROM ' . USERS_TABLE . ' WHERE user_inactive_time = 0 AND group_id <> 11
ORDER BY user_posts DESC';
$result = $db->sql_query_limit($sql, $config['tsmau_number']);
$active_users = array();
while ($row = $db->sql_fetchrow($result))
{
$active_users[] = $row;
}
$db->sql_freeresult($result);
// Cache for 1 hour
$cache->put('_ts_most_active_users', $active_users, 3600);
}
foreach( $active_users as $row )
{
$most_active_user = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile' . '&u=' . $row['user_id']);
$most_active_user_search = append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $row['user_id'] . '&sr=posts');
$most_active_user_percent = ($row['user_posts'] * 100) / $total_posts;
$template->assign_block_vars('most_active_users', array(
'USER_ID' => $most_active_user,
'USER_POST_SEARCH' => $most_active_user_search,
'USER_POST_PERCENT' => number_format($most_active_user_percent, 2),
'USERNAME' => $row['username'],
'USER_REG' => $user->format_date($row['user_regdate']),
'USER_POSTS' => $row['user_posts'],
'USER_COLOUR' => $row['user_colour'],
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'S_TSMAU_ENABLE' => $config['tsmau_enable'],
'TSMAU_NUMBER' => $config['tsmau_number'],
));
}
// Most active forums
if (!empty($config['tsmaf_enable']) && sizeof($flist))
{
$sql = 'SELECT forum_id, forum_name, forum_posts, forum_desc
FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $flist) . ' AND forum_type = ' . FORUM_POST . '
ORDER BY forum_posts DESC';
$result = $db->sql_query_limit($sql, $config['tsmaf_number']);
while ($row = $db->sql_fetchrow($result))
{
$most_active_forums = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
$most_active_forums_percent = ($row['forum_posts'] * 100) / $total_posts;
$template->assign_block_vars('most_active_forums', array(
'FORUM_URL' => $most_active_forums,
'FORUM_POSTS_PERCENT' => number_format($most_active_forums_percent, 2),
'FORUM_ID' => $row['forum_id'],
'FORUM_NAME' => $row['forum_name'],
'FORUM_DESC' => (utf8_strlen($row['forum_desc']) > 41) ? truncate_string($row['forum_desc'], 40) . "\xE2\x80\xA6" : $row['forum_desc'],
'FORUM_POSTS' => $row['forum_posts'],
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'S_TSMAF_ENABLE' => $config['tsmaf_enable'],
'TSMAF_NUMBER' => $config['tsmaf_number'],
));
}
// Last visited Bots
if (!empty($config['tslvb_enable']))
{
if( ( $last_bots = $cache->get('_ts_last_visited_bots') ) === false )
{
$sql = 'SELECT user_id, username, user_lastvisit, user_colour
FROM ' . USERS_TABLE . ' WHERE user_inactive_time = 0 AND user_ip = 0
ORDER BY user_lastvisit DESC';
$result = $db->sql_query_limit($sql, $config['tslvb_number']);
$last_bots = array();
while ($row = $db->sql_fetchrow($result))
{
$last_bots[] = $row;
}
$db->sql_freeresult($result);
// Cache for 5 minutes
$cache->put('_ts_last_visited_bots', $last_bots, 300);
}
foreach( $last_bots as $row )
{
$template->assign_block_vars('last_visited_bots', array(
'USERNAME' => $row['username'],
'USER_COLOUR' => $row['user_colour'],
'USER_LAST_VISIT' => $user->format_date($row['user_lastvisit']),
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'S_TSLVB_ENABLE' => $config['tslvb_enable'],
'TSLVB_NUMBER' => $config['tslvb_number'],
));
}
// Last registered Users
if (!empty($config['tslru_enable']))
{
if( ( $last_users = $cache->get('_ts_last_registered_users') ) === false )
{
$sql = 'SELECT user_id, username, user_colour, user_regdate
FROM ' . USERS_TABLE . ' WHERE user_inactive_time = 0
ORDER BY user_regdate DESC';
$result = $db->sql_query_limit($sql, $config['tslru_number']);
$last_users = array();
while ($row = $db->sql_fetchrow($result))
{
$last_users[] = $row;
}
$db->sql_freeresult($result);
// Cache for 5 minutes
$cache->put('_ts_last_registered_users', $last_users, 300);
}
foreach( $last_users as $row )
{
$last_registered_user = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile' . '&u=' . $row['user_id']);
$template->assign_block_vars('last_registered_user', array(
'USER_URL' => $last_registered_user,
'USERNAME' => $row['username'],
'USER_COLOUR' => $row['user_colour'],
'USER_REGISTERED' => $user->format_date($row['user_regdate']),
));
}
$template->assign_vars(array(
'S_TSLRU_ENABLE' => $config['tslru_enable'],
'TSLRU_NUMBER' => $config['tslru_number'],
));
}
// Most Downloaded Attachments
if (!empty($config['tsmdax_enable']) && sizeof($flist))
{
if( ( $most_downloaded = $cache->get('_ts_most_downloaded_attachments') ) === false )
{
$sql = 'SELECT t.forum_id, a.post_msg_id, a.real_filename, a.download_count, a.filesize, a.filetime
FROM ' . ATTACHMENTS_TABLE . ' a
LEFT JOIN ' . FORUMS_TABLE . ' f ON (t.forum_id = f.forum_id)
WHERE ' . $db->sql_in_set('t.forum_id', $flist) . '
ORDER BY a.download_count DESC';
$result = $db->sql_query_limit($sql, $config['tsmda_number']);
$most_downloaded = array();
while ($row = $db->sql_fetchrow($result))
{
$most_downloaded[] = $row;
}
$db->sql_freeresult($result);
// Cache for 60 minutes
$cache->put('_ts_most_downloaded_attachments', $most_downloaded, 3600);
}
foreach( $most_downloaded as $row )
{
$most_downloaded_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_msg_id'] . '#p' . $row['post_msg_id']);
$template->assign_block_vars('most_downloaded_attachments', array(
'USER_URL' => $most_downloaded_url,
'DOWNLOAD_COUNT' => $row['download_count'],
'FILE_NAME' => $row['real_filename'],
'FILE_SIZE' => number_format($row['filesize']),
'FILE_TIME' => $user->format_date($row['filetime']),
));
}
$template->assign_vars(array(
'S_TSMDA_ENABLE' => $config['tsmda_enable'],
'TSMDA_NUMBER' => $config['tsmda_number'],
));
}
}
?>