statistics.php
来自「这是php编的论坛的原代码」· PHP 代码 · 共 654 行 · 第 1/2 页
PHP
654 行
<?php
/***************************************************************************
* statistics.php
* -------------------
* begin : Saturday, Apr 20, 2002
* copyright : (C) 2002 Meik Sievertsen
* email : acyd.burn@gmx.de
*
* $Id: statistics.php,v 1.1.1.1 2003/02/11 22:27:28 wei.gao Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* This php-file has many contents from the statistics.php file from
* Billy Sauls ((C) Nivisic.com - admin@nivisec.com)
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
//
// Start user modifiable variables
//
//
// Set smile_pref to 0, if you want that smilies are only counted once per post.
// This means that, if the same smilie is entered ten times in a message, only one is counted in that message.
//
$smile_pref = 1;
//
// Define the Number of topics/smilies/users in statistics output
//
$return_limit = 10;
$vote_left = "images/vote_lcap.gif";
$vote_right = "images/vote_rcap.gif";
$vote_bar = "images/voting_bar.gif";
//
// End user modifiable variables
//
$percentage = 0;
$bar_percent = 0;
//
// Functions
//
//
// Do the math ;)
//
function do_math($firstval, $value, $total)
{
global $percentage, $bar_percent;
$cst = ($firstval > 0) ? 90 / $firstval : 90;
if ( $value != 0 )
{
$percentage = ( $total ) ? round( min(100, ($value / $total) * 100)) : 0;
}
else
{
$percentage = 0;
}
$bar_percent = round($value * $cst);
}
if ( !defined('ATTACH_VERSION') )
{
//
// sort multi-dimensional array - from File Attachment Mod
//
function sort_multi_array ($sort_array, $key, $sort_order)
{
$last_element = count($sort_array) - 1;
$string_sort = ( is_string($sort_array[$last_element-1][$key]) ) ? TRUE : FALSE;
for ($i = 0; $i < $last_element; $i++)
{
$num_iterations = $last_element - $i;
for ($j = 0; $j < $num_iterations; $j++)
{
$next = 0;
//
// do checks based on key
//
$switch = FALSE;
if ( !($string_sort) )
{
if ( ( ($sort_order == "DESC") && (intval($sort_array[$j][$key]) < intval($sort_array[$j + 1][$key])) ) || ( ($sort_order == "ASC") && (intval($sort_array[$j][$key]) > intval($sort_array[$j + 1][$key])) ) )
{
$switch = TRUE;
}
}
else
{
if ( ( ($sort_order == "DESC") && (strcasecmp($sort_array[$j][$key], $sort_array[$j + 1][$key]) < 0) ) || ( ($sort_order == "ASC") && (strcasecmp($sort_array[$j][$key], $sort_array[$j + 1][$key]) > 0) ) )
{
$switch = TRUE;
}
}
if ($switch)
{
$temp = $sort_array[$j];
$sort_array[$j] = $sort_array[$j + 1];
$sort_array[$j + 1] = $temp;
}
}
}
return ($sort_array);
}
}
//
// for compatibility (from php.net i think)
//
function substring_count($haystack, $needle, $offset = 0)
{
$i = 0;
$count = 0;
while ($i == 0)
{
$longueur = strlen($haystack);
$position = strpos($haystack, $needle, $offset);
if ($position && ($offset + strlen($needle)) < $longueur)
{
$offset = $position + strlen($needle);
$count++;
}
else
{
$i++;
}
}
return $count;
}
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
// include 'language'
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx);
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_statistics.' . $phpEx);
$page_title = $lang['Statistics'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->set_filenames(array(
'body' => 'statistics.tpl')
);
$template->assign_vars(array(
'L_ADMIN_STATISTICS' => $lang['Admin_Stats'],
'L_TOP_SMILIES' => $lang['Top_Smilies'],
'L_MOST_ACTIVE' => $lang['Most_Active_Topics'],
'L_MOST_VIEWED' => $lang['Most_Viewed_Topics'],
'L_TOP_POSTERS' => $lang['Top_Posting_Users'],
'L_USES' => $lang['Uses'],
'L_RANK' => $lang['Rank'],
'L_PERCENTAGE' => $lang['Percent'],
'L_GRAPH' => $lang['Graph'],
'L_REPLIES' => $lang['Replies'],
'L_TOPIC' => $lang['Topic'],
'L_VIEWS' => $lang['Views'],
'L_USERNAME' => $lang['Username'],
'L_POSTS' => $lang['Posts'],
'L_STATISTIC' => $lang['Statistic'],
'L_VALUE' => $lang['Value'],
'L_IMAGE' => $lang['smiley_url'],
'L_CODE' => $lang['smiley_code'],
'PAGE_NAME' => $lang['Statistics'])
);
//
// Authorization SQL - forum-based
//
$auth_data_sql = '';
$sql = "SELECT forum_id
FROM " . FORUMS_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't retrieve forum_id data", "", __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result))
{
$is_auth = auth('auth_view', $row['forum_id'], $userdata);
if ($is_auth['auth_view'])
{
$auth_data_sql .= ( $auth_data_sql != '') ? ', ' . $row['forum_id'] : $row['forum_id'];
}
}
//
// Getting voting bar info
//
if( !$board_config['override_user_style'] )
{
if( ($userdata['user_id'] != ANONYMOUS) && (isset($userdata['user_style'])) )
{
$style = $userdata['user_style'];
if( !$theme )
{
$style = $board_config['default_style'];
}
}
else
{
$style = $board_config['default_style'];
}
}
else
{
$style = $board_config['default_style'];
}
$sql = "SELECT *
FROM " . THEMES_TABLE . "
WHERE themes_id = $style";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, "Couldn't query database for theme info.");
}
if( !$row = $db->sql_fetchrow($result) )
{
message_die(CRITICAL_ERROR, "Couldn't get theme data for themes_id=$style.");
}
$current_template_path = 'templates/' . $row['template_name'] . '/';
$template->assign_vars(array(
'LEFT_GRAPH_IMAGE' => $current_template_path . $vote_left,
'RIGHT_GRAPH_IMAGE' => $current_template_path . $vote_right,
'GRAPH_IMAGE' => $current_template_path . $vote_bar)
);
//
// Top posters SQL
//
$sql = "SELECT user_id, username, user_posts
FROM " . USERS_TABLE . "
WHERE (user_id <> " . ANONYMOUS . " ) AND (user_posts > 0)
ORDER BY user_posts DESC
LIMIT " . $return_limit;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't retrieve users data", "", __LINE__, __FILE__, $sql);
}
$user_count = $db->sql_numrows($result);
$user_data = $db->sql_fetchrowset($result);
$firstcount = $user_data[0]['user_posts'];
for ($i = 0; $i < $user_count; $i++)
{
$class = ( !($i+1 % 2) ) ? $theme['td_class2'] : $theme['td_class1'];
do_math($firstcount, $user_data[$i]['user_posts'], get_db_stat('postcount'));
$template->assign_block_vars('users', array(
'RANK' => $i+1,
'CLASS' => $class,
'USERNAME' => $user_data[$i]['username'],
'PERCENTAGE' => $percentage,
'BAR' => $bar_percent,
'URL' => append_sid($phpbb_root_path . 'profile.php?mode=viewprofile&u=' . $user_data[$i]['user_id']),
'POSTS' => $user_data[$i]['user_posts'])
);
}
//
// Most active topics SQL
//
$sql = "SELECT topic_id, topic_title, topic_replies
FROM " . TOPICS_TABLE . "
WHERE forum_id IN (" . $auth_data_sql . ") AND (topic_status <> 2) AND (topic_replies > 0)
ORDER BY topic_replies 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);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?