statistics.php
来自「这是php编的论坛的原代码」· PHP 代码 · 共 654 行 · 第 1/2 页
PHP
654 行
for ($i = 0; $i < $topic_count; $i++)
{
$class = ( !($i+1 % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
$template->assign_block_vars('topicreplies', array(
'RANK' => $i+1,
'CLASS' => $class,
'TITLE' => $topic_data[$i]['topic_title'],
'REPLIES' => $topic_data[$i]['topic_replies'],
'URL' => append_sid($phpbb_root_path . 'viewtopic.php?t=' . $topic_data[$i]['topic_id']))
);
}
//
// Most viewed topics SQL
//
$sql = "SELECT topic_id, topic_title, topic_views
FROM " . TOPICS_TABLE . "
WHERE forum_id IN (" . $auth_data_sql . ") AND (topic_status <> 2) AND (topic_views > 0)
ORDER BY topic_views DESC
LIMIT " . $return_limit;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't retrieve topic data", "", __LINE__, __FILE__, $sql);
}
$topic_count = $db->sql_numrows($result);
$topic_data = $db->sql_fetchrowset($result);
for ($i = 0; $i < $topic_count; $i++)
{
$class = ( !($i+1 % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
$template->assign_block_vars('topicviews', array(
'RANK' => $i+1,
'CLASS' => $class,
'TITLE' => $topic_data[$i]['topic_title'],
'VIEWS' => $topic_data[$i]['topic_views'],
'URL' => append_sid($phpbb_root_path . 'viewtopic.php?t=' . $topic_data[$i]['topic_id']))
);
}
//
// Forum Stats
//
$total_posts = get_db_stat('postcount');
$total_users = get_db_stat('usercount');
$total_topics = get_db_stat('topiccount');
$start_date = create_date($board_config['default_dateformat'], $board_config['board_startdate'], $board_config['board_timezone']);
$boarddays = max(1, round( ( time() - $board_config['board_startdate'] ) / 86400 ));
$posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
$topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
$users_per_day = sprintf('%.2f', $total_users / $boarddays);
$avatar_dir_size = 0;
if ($avatar_dir = @opendir($phpbb_root_path . $board_config['avatar_path']))
{
while( $file = @readdir($avatar_dir) )
{
if( $file != '.' && $file != '..' )
{
$avatar_dir_size += @filesize($phpbb_root_path . $board_config['avatar_path'] . '/' . $file);
}
}
@closedir($avatar_dir);
//
// This bit of code translates the avatar directory size into human readable format
// Borrowed the code from the PHP.net annoted manual, origanally written by:
// Jesse (jesse@jess.on.ca)
//
if($avatar_dir_size >= 1048576)
{
$avatar_dir_size = round($avatar_dir_size / 1048576 * 100) / 100 . ' MB';
}
else if($avatar_dir_size >= 1024)
{
$avatar_dir_size = round($avatar_dir_size / 1024 * 100) / 100 . ' KB';
}
else
{
$avatar_dir_size = $avatar_dir_size . ' Bytes';
}
}
else
{
$avatar_dir_size = $lang['Not_available'];
}
if ($posts_per_day > $total_posts)
{
$posts_per_day = $total_posts;
}
if ($topics_per_day > $total_topics)
{
$topics_per_day = $total_topics;
}
if ($users_per_day > $total_users)
{
$users_per_day = $total_users;
}
//
// DB size ... MySQL only
//
// This code is heavily influenced by a similar routine
// in phpMyAdmin 2.2.0
//
if( preg_match("/^mysql/", SQL_LAYER) )
{
$sql = "SELECT VERSION() AS mysql_version";
if($result = $db->sql_query($sql))
{
$row = $db->sql_fetchrow($result);
$version = $row['mysql_version'];
if( preg_match("/^(3\.23|4\.)/", $version) )
{
$db_name = ( preg_match("/^(3\.23\.[6-9])|(3\.23\.[1-9][1-9])|(4\.)/", $version) ) ? "`$dbname`" : $dbname;
$sql = "SHOW TABLE STATUS
FROM " . $db_name;
if($result = $db->sql_query($sql))
{
$tabledata_ary = $db->sql_fetchrowset($result);
$dbsize = 0;
for($i = 0; $i < count($tabledata_ary); $i++)
{
if( $tabledata_ary[$i]['Type'] != "MRG_MyISAM" )
{
if( $table_prefix != "" )
{
if( strstr($tabledata_ary[$i]['Name'], $table_prefix) )
{
$dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length'];
}
}
else
{
$dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length'];
}
}
}
if( $dbsize >= 1048576 )
{
$dbsize = sprintf("%.2f MB", ( $dbsize / 1048576 ));
}
else if( $dbsize >= 1024 )
{
$dbsize = sprintf("%.2f KB", ( $dbsize / 1024 ));
}
else
{
$dbsize = sprintf("%.2f Bytes", $dbsize);
}
} // Else we couldn't get the table status.
}
else
{
$dbsize = $lang['Not_available'];
}
}
else
{
$dbsize = $lang['Not_available'];
}
}
else
{
$dbsize = $lang['Not_available'];
}
//
// Newest user data
//
$newest_userdata = get_db_stat('newestuser');
$newest_user = $newest_userdata['username'];
$newest_uid = $newest_userdata['user_id'];
$sql = "SELECT user_regdate
FROM " . USERS_TABLE . "
WHERE user_id = " . $newest_uid . "
LIMIT 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't retrieve users data", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$newest_user_date = $row['user_regdate'];
//
// Most Online data
//
$sql = "SELECT *
FROM " . CONFIG_TABLE . "
WHERE config_name = 'record_online_users' OR config_name = 'record_online_date'";
if (!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Couldn't retrieve configuration data", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$most_users_date = ($row['config_value'] > 0) ? create_date($board_config['default_dateformat'], $row['config_value'], $board_config['board_timezone']) : $most_users_date = $lang['Not_available'];
$row = $db->sql_fetchrow($result);
$most_users = ($row['config_value'] > 0) ? $row['config_value'] : $lang['Not_available'];
$statistic_array = array($lang['Number_posts'], $lang['Posts_per_day'], $lang['Number_topics'], $lang['Topics_per_day'], $lang['Number_users'], $lang['Users_per_day'], $lang['Board_started'], $lang['Board_Up_Days'], $lang['Database_size'], $lang['Avatar_dir_size'], $lang['Latest_Reg_User_Date'], $lang['Latest_Reg_User'], $lang['Most_Ever_Online_Date'], $lang['Most_Ever_Online'], $lang['Gzip_compression']);
$value_array = array($total_posts, $posts_per_day, $total_topics, $topics_per_day, $total_users, $users_per_day, $start_date, sprintf('%.2f', $boarddays), $dbsize, $avatar_dir_size, create_date($board_config['default_dateformat'], $newest_user_date, $board_config['board_timezone']), sprintf('<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$newest_uid") . '">' . $newest_user . '</a>'), $most_users_date, $most_users, ( $board_config['gzip_compress'] ) ? $lang['Enabled'] : $lang['Disabled']);
//
// Disk Usage, if Attachment Mod is installed
//
if ( defined('ATTACH_VERSION') )
{
include($phpbb_root_path . 'attach_mod/includes/functions_admin.'.$phpEx);
$disk_usage = get_formatted_dirsize();
$statistic_array[] = $lang['Disk_usage'];
$value_array[] = $disk_usage;
}
for ($i = 0; $i < count($statistic_array); $i += 2)
{
$template->assign_block_vars('adminrow', array(
'STATISTIC' => $statistic_array[$i],
'VALUE' => $value_array[$i],
'STATISTIC2' => (isset($statistic_array[$i+1])) ? $statistic_array[$i + 1] : '',
'VALUE2' => (isset($value_array[$i+1])) ? $value_array[$i + 1] : '')
);
}
//
// End forum statistics
//
//
// Most used smilies
//
$sql = "SELECT *
FROM " . SMILIES_TABLE . "
GROUP BY smile_url";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't retrieve smilies data", "", __LINE__, __FILE__, $sql);
}
$all_smilies = array();
$total_smilies = 0;
if ($db->sql_numrows($result) > 0)
{
$smilies = $db->sql_fetchrowset($result);
for ($i = 0; $i < count($smilies); $i++)
{
$count = 0;
$sql = "SELECT post_text
FROM " . POSTS_TEXT_TABLE . "
WHERE post_text LIKE '%" . $smilies[$i]['code'] . "%'";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't retrieve smilies data", "", __LINE__, __FILE__, $sql);
}
if ($smile_pref == 0)
{
$count = $db->sql_numrows($result);
}
else
{
while ($post = $db->sql_fetchrow($result))
{
$count = $count + substring_count($post['post_text'], $smilies[$i]['code']);
}
}
$all_smilies[$i]['count'] = $count;
$all_smilies[$i]['code'] = $smilies[$i]['code'];
$all_smilies[$i]['smile_url'] = $smilies[$i]['smile_url'];
$total_smilies = $total_smilies + $count;
}
}
// Sort array
$all_smilies = sort_multi_array ($all_smilies, 'count', 'DESC');
$limit = ( $return_limit > count($all_smilies) ) ? count($all_smilies) : $return_limit;
for ($i = 0; $i < $limit; $i++)
{
$class = ( !($i+1 % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
do_math($all_smilies[0]['count'], $all_smilies[$i]['count'], $total_smilies);
$template->assign_block_vars('topsmilies', array(
'RANK' => $i+1,
'CLASS' => $class,
'CODE' => $all_smilies[$i]['code'],
'USES' => $all_smilies[$i]['count'],
'PERCENTAGE' => $percentage,
'BAR' => $bar_percent,
'URL' => '<img src="'. $board_config['smilies_path'] . '/' . $all_smilies[$i]['smile_url'] . '" alt="' . $all_smilies[$i]['smile_url'] . '" border="0">')
);
}
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?