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

📄 common.php

📁 flashget43的源代码 一个比较常用的下载程序
💻 PHP
字号:
<?php
	
	error_reporting( 0 );
	@ini_set('zend.ze1_compatibility_mode', '1');// for PHP 5 compatibility
	
	//--- error reporting
	if( $GLOBALS['fc_config']['errorReports'] )
	{
		// we will do our own error handling
		$old_error_handler = set_error_handler("userErrorHandler");
	}

	//---
	//error_reporting(E_ALL ^ E_NOTICE);
	//---
	
	define('INC_DIR', dirname(__FILE__) . '/');
	
	define('SPY_USERID', -1);

	define('ROLE_NOBODY', 0);
	define('ROLE_USER', 1);
	define('ROLE_ADMIN', 2);
	define('ROLE_SPY', 4);
	define('ROLE_CUSTOMER', 8);
	define('ROLE_ANY', -1);

	define('BAN_BYROOMID', 1);
	define('BAN_BYUSERID', 2);
	define('BAN_BYIP', 3);

	define('LEFT', 2);
	define('RIGHT', 1);
	define('TOP', 2);
	define('BOTTOM', 1);

	if(!isset($GLOBALS['fc_config_stop'])) $GLOBALS['fc_config_stop'] = false;

	include_once( INC_DIR . 'config.php' );
	include_once( INC_DIR . 'config.srv.php' );
	
	//path to files where application data is stored (MUST be writeable!)
	$GLOBALS['fc_config']['appdata_path']  = './appdata/appTime.txt'; 
	$GLOBALS['fc_config']['botsdata_path'] = './appdata/bots.txt';
	$GLOBALS['clientId'] 				   = -1;
		
	include_once( INC_DIR . 'badwords.php' );

	include_once( INC_DIR . 'classes/db.php' );
	include_once( INC_DIR . 'classes/messageQueue.php' );
	include_once( INC_DIR . 'classes/message.php' );
	include_once( INC_DIR . 'classes/connection.php' );
	include_once( INC_DIR . 'classes/chatServer.php' );
	include_once( INC_DIR . 'classes/functions_utils.php' );

	//---CMS	
	$f_cms = INC_DIR . 'cmses/' . $GLOBALS['fc_config']['CMSsystem'] . '.php';
	
	if( !file_exists($f_cms) || !is_file($f_cms) )
	{
		include_once(INC_DIR . 'cmses/statelessCMS.php');//free for all users
	}
	else
	{
		include_once( $f_cms );
	}
	//---end CMS
	//-----------------------------------------------------------------------
		
	//Bots future enabling
	if($GLOBALS['fc_config']['enableBots'])
	{
		include_once( INC_DIR.'../bot/bot_class.php' );
		
		$GLOBALS['fc_config']['bot'] =& new Bot();
	}
	
	//Socket Server future enabling config
	if($GLOBALS['fc_config']['enableSocketServer'])
	{
		include_once( INC_DIR.'patServer/config.socketSrv.php' );
		include_once( INC_DIR.'patServer/myxml.inc.php' ); 
		
		require_once( INC_DIR.'patServer/patServer.php' );
		require_once( INC_DIR.'patServer/patXMLServer_Dom.php' );
		require_once( INC_DIR.'patServer/socketServer.php' );
	}
	
	$_REQUEST['errors'] = '';

	function addError($error) {
		$_REQUEST['errors'] .= "<error><![CDATA[{$error}]]></error>";
	}

	function getErrors() {
		return $_REQUEST['errors'];
	}

	function htmlColor($color) {
		return sprintf("#%06X", $color);
	}

	function convert_timestamp($timestamp, $timezoneOffset=0) {
		$replacements = array(  '-' => '', 
								' ' => '', 
								':' => ''); 
		$timestamp = strtr($timestamp, $replacements); 
		
		return $timestamp?mktime(
			substr($timestamp,8,2),
			substr($timestamp,10,2) - $timezoneOffset + $GLOBALS['fc_config']['timeOffset'],
			substr($timestamp,12,2),
			substr($timestamp,4,2),
			substr($timestamp,6,2),
			substr($timestamp,0,4)
		):0;
	}

	function format_Timestamp($timestamp, $tzoffset) {
		return gmdate($GLOBALS['fc_config']['timeStampFormat'], convert_timestamp($timestamp, $tzoffset));
	}

	function array2attrs($arr) {
		$ret = '';
		foreach($arr as $k => $v) {
			if(!is_array($v)) $ret .= " $k=\"$v\"";
		}

		return $ret;
	}

	function array2attrsHtml($arr) {
		$ret = '';
		foreach($arr as $k => $v) {
			if(!is_array($v)) $ret .= " $k=\"".htmlspecialchars($v)."\"";
		}

		return $ret;
	}

//------------------------------------------------------------------------------------------------------------------------------//
	function toLog($title, $str)
	{
		if( !$GLOBALS['fc_config']['errorReports'] ) return;
		
		$fname = 'log.txt';
		if( (!is_writable( $fname ) && file_exists( $fname )) || !is_writable( '.' ) ) return;

		$fp = @fopen($fname,"a");
		@fwrite($fp,"\n//-----------------------------------------------------");
		@fwrite($fp,"\n//----$title");
		@fwrite($fp,"\n//-----------------------------------------------------");

		if( is_array( $str ) )
		{
			ob_start();
			print_r( $str );
			$str = ob_get_contents();
			ob_end_clean();
		}

		@fwrite ( $fp,"\n".$str);
		@fclose( $fp );
	}

//-------------------------------------------------
//Error handler function
//-------------------------------------------------
// user defined error handling function
function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars)
{
	$send_to_mail = "you@domain.com";

    // timestamp for the error entry
    $dt = date("Y-m-d H:i:s (T)");

    // define an assoc array of error string
    // in reality the only entries we should
    // consider are 2,8,256,512 and 1024
    $errortype = array (
                1   =>  "Error",
                2   =>  "Warning",
                4   =>  "Parsing Error",
                8   =>  "Notice",
                16  =>  "Core Error",
                32  =>  "Core Warning",
                64  =>  "Compile Error",
                128 =>  "Compile Warning",
                256 =>  "User Error",
                512 =>  "User Warning",
                1024=>  "User Notice"
                );
    // set of errors for which a var trace will be saved
    $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);

    $err = "<errorentry>\n";
    $err .= "\t<datetime>".$dt."</datetime>\n";
    $err .= "\t<errornum>".$errno."</errornum>\n";
    $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n";
    $err .= "\t<errormsg>".$errmsg."</errormsg>\n";
    $err .= "\t<scriptname>".$filename."</scriptname>\n";
    $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n";

	/*
    	if (in_array($errno, $user_errors)) $err .= "\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n";
	*/ 
    $err .= "</errorentry>\n\n";

	if ($errno != 8)
	{
    	toLog($errmsg, $err);//save error message to log file
     	//mail($send_to_mail , "-error handler-$errortype[$errno]-$errmsg", $err);//send error by mail
	}
}
//------------------------------------------------------------------------------------------------------------------------------//
	function getmicrotime()
	{
    	list($usec, $sec) = explode(" ", microtime());
	    return ((float)$usec + (float)$sec);
	}
//------------------------------------------------------------------------------------------------------------------------------//
	
	// check for Turck MMCache
	if (function_exists('mmcache_rm_page')) mmcache_rm_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET));
?>

⌨️ 快捷键说明

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