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

📄 functions.php

📁 这是php编的论坛的原代码
💻 PHP
📖 第 1 页 / 共 2 页
字号:

	if ( $row = $db->sql_fetchrow($result) )
	{
		do 
		{
			$orig_word[] = '#\b(' . str_replace('\*', '\w*?', phpbb_preg_quote($row['word'], '#')) . ')\b#i';
			$replacement_word[] = $row['replacement'];
		}
		while ( $row = $db->sql_fetchrow($result) );
	}

	return true;
}

//
// This is general replacement for die(), allows templated
// output in users (or default) language, etc.
//
// $msg_code can be one of these constants:
//
// GENERAL_MESSAGE : Use for any simple text message, eg. results 
// of an operation, authorisation failures, etc.
//
// GENERAL ERROR : Use for any error which occurs _AFTER_ the 
// common.php include and session code, ie. most errors in 
// pages/functions
//
// CRITICAL_MESSAGE : Used when basic config data is available but 
// a session may not exist, eg. banned users
//
// CRITICAL_ERROR : Used when config data cannot be obtained, eg
// no database connection. Should _not_ be used in 99.5% of cases
//
function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
{
	global $db, $template, $board_config, $theme, $lang, $phpEx, $phpbb_root_path, $nav_links, $gen_simple_header, $images;
	global $userdata, $user_ip, $session_length;
	global $starttime;

	if(defined('HAS_DIED'))
	{
		die("message_die() was called multiple times. This isn't supposed to happen. Was message_die() used in page_tail.php?");
	}
	
	define(HAS_DIED, 1);
	

	$sql_store = $sql;
	
	//
	// Get SQL error if we are debugging. Do this as soon as possible to prevent 
	// subsequent queries from overwriting the status of sql_error()
	//
	if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
	{
		$sql_error = $db->sql_error();

		$debug_text = '';

		if ( $sql_error['message'] != '' )
		{
			$debug_text .= '<br /><br />SQL Error : ' . $sql_error['code'] . ' ' . $sql_error['message'];
		}

		if ( $sql_store != '' )
		{
			$debug_text .= "<br /><br />$sql_store";
		}

		if ( $err_line != '' && $err_file != '' )
		{
			$debug_text .= '</br /><br />Line : ' . $err_line . '<br />File : ' . $err_file;
		}
	}

	if( empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) )
	{
		$userdata = session_pagestart($user_ip, PAGE_INDEX);
		init_userprefs($userdata);
	}

	//
	// If the header hasn't been output then do it
	//
	if ( !defined('HEADER_INC') && $msg_code != CRITICAL_ERROR )
	{
		if ( empty($lang) )
		{
			if ( !empty($board_config['default_lang']) )
			{
				include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx);
			}
			else
			{
				include($phpbb_root_path . 'language/lang_english/lang_main.'.$phpEx);
			}
		}

		if ( empty($template) )
		{
			$template = new Template($phpbb_root_path . 'templates/' . $board_config['board_template']);
		}
		if ( empty($theme) )
		{
			$theme = setup_style($board_config['default_style']);
		}

		//
		// Load the Page Header
		//
		if ( !defined('IN_ADMIN') )
		{
			include($phpbb_root_path . 'includes/page_header.'.$phpEx);
		}
		else
		{
			include($phpbb_root_path . 'admin/page_header_admin.'.$phpEx);
		}
	}

	switch($msg_code)
	{
		case GENERAL_MESSAGE:
			if ( $msg_title == '' )
			{
				$msg_title = $lang['Information'];
			}
			break;

		case CRITICAL_MESSAGE:
			if ( $msg_title == '' )
			{
				$msg_title = $lang['Critical_Information'];
			}
			break;

		case GENERAL_ERROR:
			if ( $msg_text == '' )
			{
				$msg_text = $lang['An_error_occured'];
			}

			if ( $msg_title == '' )
			{
				$msg_title = $lang['General_Error'];
			}
			break;

		case CRITICAL_ERROR:
			//
			// Critical errors mean we cannot rely on _ANY_ DB information being
			// available so we're going to dump out a simple echo'd statement
			//
			include($phpbb_root_path . 'language/lang_english/lang_main.'.$phpEx);

			if ( $msg_text == '' )
			{
				$msg_text = $lang['A_critical_error'];
			}

			if ( $msg_title == '' )
			{
				$msg_title = 'phpBB : <b>' . $lang['Critical_Error'] . '</b>';
			}
			break;
	}

	//
	// Add on DEBUG info if we've enabled debug mode and this is an error. This
	// prevents debug info being output for general messages should DEBUG be
	// set TRUE by accident (preventing confusion for the end user!)
	//
	if ( DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
	{
		if ( $debug_text != '' )
		{
			$msg_text = $msg_text . '<br /><br /><b><u>DEBUG MODE</u></b>' . $debug_text;
		}
	}

	if ( $msg_code != CRITICAL_ERROR )
	{
		if ( !empty($lang[$msg_text]) )
		{
			$msg_text = $lang[$msg_text];
		}

		if ( !defined('IN_ADMIN') )
		{
			$template->set_filenames(array(
				'message_body' => 'message_body.tpl')
			);
		}
		else
		{
			$template->set_filenames(array(
				'message_body' => 'admin/admin_message_body.tpl')
			);
		}

		$template->assign_vars(array(
			'MESSAGE_TITLE' => $msg_title,
			'MESSAGE_TEXT' => $msg_text)
		);
		$template->pparse('message_body');

		if ( !defined('IN_ADMIN') )
		{
			include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
		}
		else
		{
			include($phpbb_root_path . 'admin/page_footer_admin.'.$phpEx);
		}
	}
	else
	{
		echo "<html>\n<body>\n" . $msg_title . "\n<br /><br />\n" . $msg_text . "</body>\n</html>";
	}

	exit;
}

//
// This function is for compatibility with PHP 4.x's realpath()
// function.  In later versions of PHP, it needs to be called
// to do checks with some functions.  Older versions of PHP don't
// seem to need this, so we'll just return the original value.
// dougk_ff7 <October 5, 2002>
function phpbb_realpath($path)
{
	return (!@function_exists('realpath') || !@realpath($phpbb_root_path . 'includes/functions.'.$phpEx)) ? $path : @realpath($path);
}

function redirect($url)
{
	global $db, $board_config;

	if (!empty($db))
	{
		$db->sql_close();
	}

	$server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
	$server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['server_name']));
	$server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : '';
	$script_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['script_path']));
	$script_name = ($script_name == '') ? $script_name : '/' . $script_name;
	$url = preg_replace('#^\/?(.*?)\/?$#', '/\1', trim($url));

	// Redirect via an HTML form for PITA webservers
	if (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')))
	{
		header('Refresh: 0; URL=' . $server_protocol . $server_name . $server_port . $script_name . $url);
		echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=' . $server_protocol . $server_name . $server_port . $script_name . $url . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="' . $server_protocol . $server_name . $server_port . $script_name . $url . '">HERE</a> to be redirected</div></body></html>';
		exit;
	}

	// Behave as per HTTP/1.1 spec for others
	header('Location: ' . $server_protocol . $server_name . $server_port . $script_name . $url);
	exit;
}

// Add function mkrealdate for Birthday MOD 
// the originate php "mktime()", does not work proberly on all OS, especially when going back in time 
// before year 1970 (year 0), this function "mkrealtime()", has a mutch larger valid date range, 
// from 1901 - 2099. it returns a "like" UNIX timestamp divided by 86400, so 
// calculation from the originate php date and mktime is easy. 
// mkrealdate, returns the number of day (with sign) from 1.1.1970. 

function mkrealdate($day,$month,$birth_year) 
{ 
	// range check months 
	if ($month<1 || $month>12) return "error"; 
	// range check days 
	switch ($month) 
	{ 
	case 1:
		if ($day > 31)
			return "error";
		break; 
	case 2: 
		if ($day > 29) 
			return "error"; 
		$epoch = $epoch + 31;
		break; 
	case 3: 
		if ($day > 31) 
			return "error"; 
		$epoch = $epoch + 59;
		break; 
	case 4: 
		if ($day > 30) 
			return "error" ; 
		$epoch = $epoch + 90;
		break; 
	case 5: 
		if ($day > 31) 
			return "error"; 
		$epoch = $epoch + 120;
		break; 
	case 6: 
		if ($day > 30) 
			return "error"; 
		$epoch = $epoch + 151;
		break; 
	case 7: 
		if ($day > 31) 
			return "error"; 
		$epoch = $epoch + 181;
		break; 
	case 8: 
		if ($day > 31) 
			return "error"; 
		$epoch = $epoch + 212;
		break; 
	case 9: 
		if ($day > 30) 
			return "error"; 
		$epoch = $epoch + 243;
		break; 
	case 10: 
		if ($day > 31) 
			return "error"; 
		$epoch = $epoch + 273;
		break; 
	case 11: 
		if ($day > 30) 
			return "error"; 
		$epoch = $epoch + 304;
		break; 
	case 12: 
		if ($day > 31) 
			return "error"; 
		$epoch = $epoch + 334;
		break; 
	} 
	$epoch = $epoch + $day; 
	$epoch_Y = sqrt(($birth_year - 1970) * ($birth_year - 1970)); 
	$leapyear = round((($epoch_Y + 2) / 4) - .5); 
	if (($epoch_Y + 2) % 4 == 0) 
	{// curent year is leapyear 
		$leapyear --; 
		if ($birth_year > 1970 && $month >= 3)
			$epoch = $epoch + 1; 
		if ($birth_year < 1970 && $month < 3) 
			$epoch = $epoch - 1; 
	} else if ($month == 2 && $day > 28) 
		return "error";//only 28 days in feb. 
	//year 
	if ($birth_year > 1970) 
		$epoch = $epoch + $epoch_Y * 365 - 1 + $leapyear; 
	else 
		$epoch = $epoch - $epoch_Y * 365 - 1 - $leapyear; 
	return $epoch; 
} 

// Add function realdate for Birthday MOD 
// the originate php "date()", does not work proberly on all OS, especially when going back in time 
// before year 1970 (year 0), this function "realdate()", has a mutch larger valid date range, 
// from 1901 - 2099. it returns a "like" UNIX date format (only date, related letters may be used, due to the fact that
// the given date value should already be divided by 86400 - leaving no time information left) 
// a input like a UNIX timestamp divided by 86400 is expected, so 
// calculation from the originate php date and mktime is easy. 
// e.g. realdate ("m d Y", 3) returns the string "1 3 1970" 

// UNIX users should replace this function with the below code, since this should be faster
//
//function realdate($date_syntax="Ymd",$date=0) 
//{ return create_date($date_syntax,$date*86400,$board_config['board_timezone']); }

function realdate($date_syntax="Ymd",$date=0) 
{ 
	global $lang; 
	$i=2;
	if ($date>=0) 
	{
		$year=date%1461;
		$days = $date - $year*1461;
		while ($days > 364) 
	    	{
			$year++;		
			$days-=365; 	
			if ($i++==3)
			{
				$i=0;
				$days--;
			} 
		}
		if (days<=0 && $i==0)
		{
			$days++;
		}
	} else 
	{ 
		$year= -(date%1461);
		$days = $date + $year*1461;
      	while ($days<0) 
	      { 
      	   $year--; 
	         $days+=365; 
      	   if ($i++==3) 
	         { 
      	      $i=0; 
	            $days++; 
      	   } 
	      } 
   	}
	$leap_year = ($i == 0) ? TRUE : FALSE;
	$months_array = ($i == 0) ? 
		array (0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366) :
		array (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365) ;
	for ($month = 1; $month < 12; $month ++)
	{
		if ($days<$months_array[$month])
			break;
	}

	$day = $days - $months_array[$month - 1] + 1;
	//you may gain speed performance by remove som of the below entry's if they are not needed/used
	return strtr ($date_syntax, array(
		'a' => '',
		'A' => '',
		'\\d' => 'd',
		'd' => ($day > 9) ? $day : '0'.$day,
		'\\D' => 'D',
		'D' => $lang['day_short'][($date-3) % 7],
		'\\F' => 'F',
		'F' => $lang['month_long'][$month - 1],
		'g' => '',
		'G' => '',
		'H' => '',
		'h' => '',
		'i' => '',
		'I' => '',
		'\\j' => 'j',
		'j' => $day,
		'\\l' => 'l',
		'l' => $lang['day_long'][($date - 3) % 7],
		'\\L' => 'L',
		'L' => $leap_year,
		'\\m' => 'm',
		'm' => ($month > 9) ? $month : '0'.$month,
		'\\M' => 'M',
		'M' => $lang['month_short'][$month - 1],
		'\\n' => 'n',
		'n' => $month,
		'O' => '',
		's' => '',
		'S' => '',
		'\\t' => 't',
		't' => $months_array[$month] - $months_array[$month - 1],
		'w' => '',
		'\\y' => 'y',
		'y' => ($year > 29) ? $year - 30 : $year + 70,
		'\\Y' => 'Y',
		'Y' => $year + 1970,
		'\\z' => 'z',
		'z' => $days,
		'\\W' => '',
		'W' => '') );
} 

?>

⌨️ 快捷键说明

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