⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functions.php

📁 国外非常不错的论坛
💻 PHP
📖 第 1 页 / 共 4 页
字号:
<?php/*	Copyright (C) 2003-2005 UseBB Team	http://www.usebb.net		$Header: /cvsroot/usebb/UseBB/sources/functions.php,v 1.225 2005/08/23 11:14:12 pc_freak Exp $		This file is part of UseBB.		UseBB 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.		UseBB is distributed in the hope that it will be useful,	but WITHOUT ANY WARRANTY; without even the implied warranty of	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	GNU General Public License for more details.		You should have received a copy of the GNU General Public License	along with UseBB; if not, write to the Free Software	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*///// Die when called directly in browser//if ( !defined('INCLUDED') )	exit();//// Add slashes to and trim variables//function slash_trim_global($global) {		if ( is_array($global) ) {				foreach ( $global as $key => $val ) {						if ( is_array($val) ) {								$global[$key] = slash_trim_global($val);						} else {								if ( !get_magic_quotes_gpc() )					$val = addslashes($val);				$global[$key] = trim($val);							}					}			}		return $global;	}//// Replacement for htmlspecialchars()// Doesn't mess up Cyrillic (and other) characters// which are sent in entities by a browser//function unhtml($string) {		return preg_replace(array('#&#', '#&amp;\#([0-9]+)#', '#&\#(160|173|8192|8193|8194|8195|8196|8197|8198|8199|8120|8201|8202|8203|8204|8205|8206|8207)#', '#<#', '#>#', '#"#'), array('&amp;', '&#\\1', '&amp;#\\1', '&lt;', '&gt;', '&quot;'), $string);	}//// Find the length of a string containing entities//function entities_strlen($string) {		return strlen(preg_replace('#&\#?[a-z0-9]+;#', '.', $string));	}//// Check if a value is a valid integer string// Obtained from http://phpsec.org/projects/guide/1.html//function valid_int($string) {		if ( $string == strval(intval($string)) )		return true;	else		return false;	}class functions {		var $board_config;	var $board_config_original;	var $statistics = array();	var $languages = array();	var $language_sections = array();	var $mod_auth;	var $badwords;	var $updated_forums;	var $available = array('templates' => array(), 'languages' => array());		//	// General error die function	//	function usebb_die($errno, $error, $file, $line) {				global $db, $dbs;				//		// Don't show various errors on PHP5		//		if ( intval(substr(phpversion(), 0, 1)) > 4 ) {						$ignore_warnings = array(				'var: Deprecated. Please use the public/private/protected modifiers',				'Trying to get property of non-object',			);			if ( in_array($error, $ignore_warnings) )				return;					}				$errtypes = array(			1 => 'E_ERROR',			2 => 'E_WARNING',			4 => 'E_PARSE',			8 => 'E_NOTICE',			16 => 'E_CORE_ERROR',			32 => 'E_CORE_WARNING',			64 => 'E_COMPILE_ERROR',			128 => 'E_COMPILE_WARNING',			256 => 'E_USER_ERROR',			512 => 'E_USER_WARNING',			1024 => 'E_USER_NOTICE',			2048 => 'E_STRICT'		);		$errtype = ( preg_match('#^SQL: #', $error) ) ? 'SQL_ERROR' : $errtypes[$errno];				if ( $errtype == 'SQL_ERROR' )			$error = ( $this->get_config('debug') >= 2 ) ? substr($error, 5) : 'Fatal SQL error!';				$log_msg = '[UseBB Error] ['.date('D M d G:i:s Y').'] ['.$errtype.' - '.$error.'] ['.$file.':'.$line.']';		error_log($log_msg);				$html_msg  = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">	<head>		<title>UseBB General Error</title>		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />		<style type="text/css">			body {				font-family: sans-serif;				font-size: 10pt;			}			h1 {				color: #336699;			}			blockquote {				width: 50%;				border-top: 2px solid silver;				border-bottom: 2px solid silver;				font-family: monospace;				font-size: 8pt;			}		</style>	</head>	<body>		<h1>UseBB General Error</h1>		<p>An error was encoutered. We apologize for any inconvenience.</p>		<blockquote>			<p>In file <strong>'.substr(str_replace(dirname($file), '', $file), 1).'</strong> on line <strong>'.$line.'</strong>:</p><p><em>'.$errtype.'</em> - '.$error.'</p>';						if ( $errtype == 'SQL_ERROR' ) {						//			// FIXME			// Needs to be done this way due to bug(?): http://bugs.php.net/bug.php?id=33643			//			$used_queries = $db->get_used_queries();						if ( count($used_queries) ) {								if ( $this->get_config('debug') >= 2 )					$html_msg .= '				<p>SQL query causing the error:<br /><textarea rows="6" cols="60" readonly="readonly">'.end($used_queries).'</textarea></p>';				else 					$html_msg .= '				<p>Enable debug mode level 2 to see the error and erroneous SQL query.</p>';							}					}				$html_msg .= '		</blockquote>		<p>This error should probably not have occured, so please report it to the webmaster. Thank you for your help.</p>		<p>If you are the webmaster of this board and you believe this is a bug, please send a bug report.</p>	</body></html>';		die($html_msg);			}		//	// Get configuration variables	//	function get_config($setting) {				global $session;				if ( !isset($this->board_config) ) {						$this->board_config = $GLOBALS['conf'];			$this->board_config_original = $GLOBALS['conf'];			unset($GLOBALS['conf']);					}				//		// Member preferences		//		if ( count($session->sess_info) && $session->sess_info['user_id'] && array_key_exists($setting, $session->sess_info['user_info']) ) {						$keep_default = false;						if ( $setting == 'language' ) {								if ( !in_array($session->sess_info['user_info'][$setting], $this->get_language_packs()) )					$keep_default = true;							} elseif ( $setting == 'template' ) {								if ( !in_array($session->sess_info['user_info'][$setting], $this->get_template_sets()) )					$keep_default = true;							}						if ( !$keep_default )				$this->board_config[$setting] = stripslashes($session->sess_info['user_info'][$setting]);					}				if ( $setting == 'board_url' && empty($this->board_config['board_url']) ) {						$path_parts = pathinfo($_SERVER['SCRIPT_NAME']);			$protocol = ( isset($_SERVER['HTTPS']) ) ? 'https' : 'http';			return $protocol.'://'.$_SERVER['HTTP_HOST'].$path_parts['dirname'].'/';					} elseif ( $setting == 'cookie_path' && empty($this->board_config['cookie_path']) ) {						$path_parts = pathinfo($_SERVER['SCRIPT_NAME']);			return $path_parts['dirname'];					} elseif ( array_key_exists($setting, $this->board_config) ) {						return $this->board_config[$setting];					} else {						if ( isset($this->board_config['hide_undefined_config_setting_warnings']) && !$this->board_config['hide_undefined_config_setting_warnings'] )				trigger_error('Unable to get configuration value "'.$setting.'"!');			else				return false;					}			}		//	// Get board statistics	//	function get_stats($stat) {				global $db;				if ( $stat == 'categories' ) {						//			// Get the category count			//			if ( !array_key_exists($stat, $this->statistics) ) {								$result = $db->query("SELECT COUNT(id) AS count FROM ".TABLE_PREFIX."cats");				$out = $db->fetch_result($result);				$this->statistics[$stat] = $out['count'];							}						return $this->statistics[$stat];					} elseif ( $stat == 'forums' || $stat == 'viewable_forums' ) {						//			// Get the forums			//			if ( !array_key_exists($stat, $this->statistics) ) {								$result = $db->query("SELECT id, auth FROM ".TABLE_PREFIX."forums");				$this->statistics['forums'] = 0;				$this->statistics['viewable_forums'] = 0;								while ( $forumdata = $db->fetch_result($result) ) {										//					// We also set the other statistic: (viewable_)forums					// This might save a query					//										// forums					$this->statistics['forums']++;										// viewable_forums					if ( $this->auth($forumdata['auth'], 'view', $forumdata['id']) )						$this->statistics['viewable_forums']++;									}							}						return $this->statistics[$stat];					} elseif ( $stat == 'latest_member' ) {						//			// Get the latest member			//			if ( !array_key_exists($stat, $this->statistics) ) {								$result = $db->query("SELECT id, displayed_name, regdate FROM ".TABLE_PREFIX."members ORDER BY id DESC LIMIT 1");				$this->statistics[$stat] = $db->fetch_result($result);							}						return $this->statistics[$stat];					} else {						if ( !array_key_exists($stat, $this->statistics) ) {								$result = $db->query("SELECT name, content FROM ".TABLE_PREFIX."stats");				while ( $out = $db->fetch_result($result) )					$this->statistics[$out['name']] = $out['content'];							}						if ( array_key_exists($stat, $this->statistics) )				return $this->statistics[$stat];			else				trigger_error('The statistic variable "'.$stat.'" does not exist!');					}			}		//	// Interactive URL builder	//	function make_url($filename, $vars=array(), $html=true) {				global $session;				if ( $this->get_config('friendly_urls') && $filename != 'admin.php' ) {						//			// Friendly URL's			//			$url = preg_replace('#\.php$#', '', $filename);			foreach ( $vars as $key => $val ) {								if ( in_array($key, array('forum', 'topic', 'post', 'quotepost', 'al')) )					$url .= '-'.urlencode($key.$val);				else					$url .= '-'.urlencode($val);							}			$url .= ( $filename == 'rss.php' ) ? '.xml' : '.html';					} else {						$url = $filename;			$vars = ( is_array($vars) ) ? $vars : array();			if ( isset($vars[$this->get_config('session_name').'_sid']) )				unset($vars[$this->get_config('session_name').'_sid']);						//			// Pass session ID's			//			$SID = SID;			$SID_parts = explode('=', $SID, 2);						if ( !empty($SID) && !preg_match('#'.preg_quote(gethostbyaddr($session->sess_info['ip_addr']), '#').'#', 'googlebot.com$') && ( !$html || ( $html && !@ini_get('session.use_trans_sid') ) ) )				$vars[$SID_parts[0]] = $SID_parts[1];						if ( count($vars) ) {								$url .= '?';								if ( $html ) {										foreach ( $vars as $key => $val )						$safe[] = urlencode($key).'='.urlencode($val);					$url .= join('&amp;', $safe);									} else {										foreach ( $vars as $key => $val )						$safe[] = $key.'='.$val;					$url .= join('&', $safe);									}							}					}				return $url;			}		//	// Attaches a SID to URLs which should contain one (e.g. referer URLs)	//	function attach_sid($url) {				$SID = SID;		if ( !$this->get_config('friendly_urls') && !empty($SID) && !preg_match('/'.preg_quote($SID, '/').'$/', $url) ) {						if ( strpos($url, '?') )				return $url.'&'.$SID;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -