functions_includes.php
来自「这是php编的论坛的原代码」· PHP 代码 · 共 613 行 · 第 1/2 页
PHP
613 行
<?php
/***************************************************************************
* functions_includes.php
* -------------------
* begin : Sunday, Mar 31, 2002
* copyright : (C) 2002 Meik Sievertsen
* email : acyd.burn@gmx.de
*
* $Id: functions_includes.php,v 1.1.1.1 2003/02/11 22:27:31 wei.gao Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* 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.
*
*
***************************************************************************/
//
// These are functions called directly from phpBB2 Files
//
//
// This function is used to count the queries executed by the Attachment Mod
//
function attach_sql_query($query)
{
global $db, $dbms, $attach_num_queries;
$attach_num_queries++;
if ( defined('ATTACH_QUERY_DEBUG') )
{
global $attach_sql_report, $attach_sql_time, $starttime;
$curtime = explode(' ', microtime());
$curtime = $curtime[0] + $curtime[1] - $starttime;
}
$attach_result = $db->sql_query($query);
if ( defined('ATTACH_QUERY_DEBUG') )
{
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1] - $starttime;
$attach_sql_report .= "<pre>Query:\t" . preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n\t", $query) . "\n\n";
$affected_rows = $db->sql_affectedrows($result);
if ($attach_result)
{
$attach_sql_report .= "Time before: $curtime\nTime after: $endtime\nElapsed time: <b>" . ($endtime - $curtime) . "</b>\n</pre>";
}
else
{
$error = $db->sql_error();
$attach_sql_report .= '<b>FAILED</b> - MySQL Error ' . $error['code'] . ': ' . $error['message'] . '<br><br><pre>';
}
$attach_sql_time += $endtime - $curtime;
if (($dbms == 'mysql') || ($dbms == 'mysql4'))
{
if (preg_match('/^SELECT/', $query))
{
$html_table = FALSE;
if ($result = mysql_query("EXPLAIN $query", $db->db_connect_id))
{
$i = 0;
while ($row = mysql_fetch_assoc($result))
{
$extra = array_pop($row);
if (!$html_table && count($row))
{
$html_table = TRUE;
$attach_sql_report .= "<table width=100% border=1 cellpadding=2 cellspacing=1>\n";
$attach_sql_report .= "<tr>\n<td><b>" . implode("</b></td>\n<td><b>", array_keys($row));
$attach_sql_report .= "</b></td>\n<td><b>affected_rows";
$attach_sql_report .= "</b></td>\n<td><b>Extra" . "</b></td>\n</tr>\n";
}
$attach_sql_report .= "<tr>\n<td>" . implode(" </td>\n<td>", array_values($row));
$attach_sql_report .= " </td>\n<td>" . ( ($i == 0) ? $affected_rows : '' );
$attach_sql_report .= " </td>\n<td>" . $extra . " </td>\n</tr>\n";
$i++;
}
}
if ($html_table)
{
$attach_sql_report .= '</table><br>';
}
}
$attach_sql_report .= "<hr>\n";
}
}
return ($attach_result);
}
//
// Include the FAQ-File (faq.php)
//
function attach_faq_include($lang_file)
{
global $phpbb_root_path, $board_config, $phpEx, $faq, $attach_config;
if (intval($attach_config['disable_mod']))
{
return;
}
if ($lang_file == 'lang_faq')
{
if ( !@file_exists(@amod_realpath($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_faq_attach.'.$phpEx)) )
{
include($phpbb_root_path . 'language/lang_english/lang_faq_attach.'.$phpEx);
}
else
{
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_faq_attach.' . $phpEx);
}
}
}
//
// Setup Basic Authentication (auth.php)
//
function attach_setup_basic_auth($type, &$auth_fields, &$a_sql)
{
switch( $type )
{
case AUTH_ALL:
$a_sql .= ', a.auth_attachments, a.auth_download';
$auth_fields[] = 'auth_attachments';
$auth_fields[] = 'auth_download';
break;
case AUTH_ATTACH:
$a_sql = 'a.auth_attachments';
$auth_fields = array('auth_attachments');
break;
case AUTH_DOWNLOAD:
$a_sql = 'a.auth_download';
$auth_fields = array('auth_download');
break;
default:
break;
}
}
//
// Setup Forum Authentication (admin_forumauth.php)
//
function attach_setup_forum_auth(&$simple_auth_ary, &$forum_auth_fields, &$field_names)
{
global $lang;
//
// Add Attachment Auth
//
// Post Attachments
$simple_auth_ary[0][] = AUTH_MOD;
$simple_auth_ary[1][] = AUTH_MOD;
$simple_auth_ary[2][] = AUTH_MOD;
$simple_auth_ary[3][] = AUTH_MOD;
$simple_auth_ary[4][] = AUTH_MOD;
$simple_auth_ary[5][] = AUTH_MOD;
$simple_auth_ary[6][] = AUTH_MOD;
// Download Attachments
$simple_auth_ary[0][] = AUTH_ALL;
$simple_auth_ary[1][] = AUTH_ALL;
$simple_auth_ary[2][] = AUTH_REG;
$simple_auth_ary[3][] = AUTH_ACL;
$simple_auth_ary[4][] = AUTH_ACL;
$simple_auth_ary[5][] = AUTH_MOD;
$simple_auth_ary[6][] = AUTH_MOD;
$forum_auth_fields[] = 'auth_attachments';
$field_names['auth_attachments'] = $lang['Auth_attach'];
$forum_auth_fields[] = 'auth_download';
$field_names['auth_download'] = $lang['Auth_download'];
}
//
// Setup Usergroup Authentication (admin_ug_auth.php)
//
function attach_setup_usergroup_auth(&$forum_auth_fields, &$auth_field_match, &$field_names)
{
global $lang;
//
// Post Attachments
//
$forum_auth_fields[] = 'auth_attachments';
$auth_field_match['auth_attachments'] = AUTH_ATTACH;
$field_names['auth_attachments'] = $lang['Auth_attach'];
//
// Download Attachments
//
$forum_auth_fields[] = 'auth_download';
$auth_field_match['auth_download'] = AUTH_DOWNLOAD;
$field_names['auth_download'] = $lang['Auth_download'];
}
//
// Setup Viewtopic Authentication for f_access
//
function attach_setup_viewtopic_auth(&$order_sql, &$sql)
{
$order_sql = str_replace('f.auth_attachments', 'f.auth_attachments, f.auth_download, t.topic_attachment', $order_sql);
$sql = str_replace('f.auth_attachments', 'f.auth_attachments, f.auth_download, t.topic_attachment', $sql);
}
//
// Setup s_auth_can in viewforum and viewtopic
//
function attach_build_auth_levels($is_auth, &$s_auth_can)
{
global $lang, $attach_config, $phpEx, $forum_id;
if (intval($attach_config['disable_mod']))
{
return;
}
// If you want to have the rules window link within the forum view too, comment out the two lines, and comment the third line
// $rules_link = '(<a href="attach_mod/attach_rules.' . $phpEx . '?f=' . $forum_id . '" target="_blank">Rules</a>)';
// $s_auth_can .= ( ( $is_auth['auth_attachments'] ) ? $rules_link . ' ' . $lang['Rules_attach_can'] : $lang['Rules_attach_cannot'] ) . '<br />';
$s_auth_can .= ( ( $is_auth['auth_attachments'] && $is_auth['auth_post'] ) ? $lang['Rules_attach_can'] : $lang['Rules_attach_cannot'] ) . '<br />';
$s_auth_can .= ( ( $is_auth['auth_download'] && $is_auth['auth_read'] ) ? $lang['Rules_download_can'] : $lang['Rules_download_cannot'] ) . '<br />';
}
//
// Called from admin_users.php and admin_groups.php in order to process Quota Settings
//
function attachment_quota_settings($admin_mode, $submit = FALSE, $mode)
{
global $template, $db, $HTTP_POST_VARS, $lang, $group_id;
if ($admin_mode == 'user')
{
if (!$submit && $mode != 'save')
{
if( isset( $HTTP_GET_VARS[POST_USERS_URL]) || isset( $HTTP_POST_VARS[POST_USERS_URL]) )
{
$user_id = ( isset( $HTTP_POST_VARS[POST_USERS_URL]) ) ? intval( $HTTP_POST_VARS[POST_USERS_URL]) : intval( $HTTP_GET_VARS[POST_USERS_URL]);
$this_userdata = get_userdata($user_id);
if( !$this_userdata )
{
return;
}
}
else
{
$this_userdata = get_userdata( $HTTP_POST_VARS['username'] );
if( !$this_userdata )
{
return;
}
}
$user_id = $this_userdata['user_id'];
}
else
{
$user_id = intval( $HTTP_POST_VARS['id'] );
$this_userdata = get_userdata($user_id);
if( !$this_userdata )
{
return;
}
}
}
if ($admin_mode == 'user' && !$submit && $mode != 'save')
{
// Show the contents
$sql = "SELECT quota_limit_id, quota_type FROM " . QUOTA_TABLE . " WHERE user_id = " . $user_id;
if( !($result = attach_sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Unable to get Quota Settings', '', __LINE__, __FILE__, $sql);
}
$pm_quota = -1;
$upload_quota = -1;
while ($row = $db->sql_fetchrow($result))
{
if ($row['quota_type'] == QUOTA_UPLOAD_LIMIT)
{
$upload_quota = $row['quota_limit_id'];
}
else if ($row['quota_type'] == QUOTA_PM_LIMIT)
{
$pm_quota = $row['quota_limit_id'];
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?