<?php
/*******************************************************************
 *[TTTuangou] (C)2005 - 2010 Cenwor Inc.
 *
 * This is NOT a freeware, use is subject to license terms
 *
 * @Filename common.func.php $
 *
 * @Author http://www.tttuangou.net $
 *
 * @Date 2010-07-16 11:17:02 $
 *******************************************************************/ 
 


function position()
{
	global $rewriteHandler;
	$decribe='ÄúµÄÎ»ÖÃ£º';
	$child_symbol=' &gt; ';
	$mod=$_GET['rmod']?$_GET['rmod']:$_GET['mod'];
	if(strpos($mod,'_')!==false)list($mod,$mod_child)=explode('_',$mod);
	$code=$_GET['code'];

	$config = ConfigHandler::get();

	$list['index']="<a href='{$config['site_url']}'>{$config['site_name']}(Ê×Ò³)</a>";
	
	$list['mod']=ConfigHandler::get('header_menu','list',$mod);
	if($list['mod']!=false)
	{
		if($rewriteHandler)$list['mod']['link']=$rewriteHandler->formatURL($list['mod']['link']);
		$list['mod']="<a href='{$list['mod']['link']}'>{$list['mod']['name']}</a>";
	}
	else
	{
		unset($list['mod']);
	}	
	
	$args_list=func_get_args();
	if(is_array($args_list) and count($args_list)>0)
	{
		foreach ($args_list as $key=>$value)
		{
			if(empty($value))continue;
			if(is_string($value))
			{
				if(trim($value)=='')continue;
				$value=preg_replace("~(\s+[/]\s+)|(\-\>)~",$child_symbol,$value);
			}
			else
			{
				if(isset($value['name']))
				{
					$value['url']=($value['url']!='')?$value['url']:$value['link'];
					$url=$value['url'];
					$name=$value['name'];
				}
				else
				{
					$url=current($value);
					$name=key($value);
				}
				if($rewriteHandler)$url=$rewriteHandler->formatURL($url);
				$value="<a href='$url'>$name</a>";
			}
			$list[$key]=$value;
		}
	}
		$position=implode($child_symbol,$list);
	return $decribe.$position;
}



class Obj
{
	function &Obj($name=null)
	{
		Return Obj::_share($name,$null,'get');
	}

	function &_share($name=null,&$mixed,$type='set')
	{
		static $_register=array();
		if($name==null)
		{
			Return $_register;
		}
		if(isset($_register[$name]) and $type==='get')
		{
			Return $_register[$name];
		}
		elseif($type==='set')
		{
			$_register[$name]=&$mixed;
		}
		
		return true;
	}
	
	function register($name,&$obj)
	{
		Obj::_share($name,$obj,"set");
	}
	
	function &registry($name=null)
	{
		Return Obj::_share($name,$null,'get');
	}
	
	function isRegistered($name)
	{
		Return isset($_register[$name]);
	}
}

function ajherrorlog($type='',$log='',$halt=1) {
	$logfile = ROOT_PATH . 'errorlog/'.$type . '-' . date('Y-m').'.php';
	if (!is_file($logfile)) {
		$log ="<? exit; ?>\r\n" . $log; 
	}
	$log = "[".my_date_format(time(),"Y-m-d H:i:s")."]" . $log . "\r\n"; 
	
	global $IoHandler;
	if(is_null($IoHandler)) {
		Load::lib('io');
		$IoHandler = new IoHandler();
		$log = " \r\n ------------------------------------------------------ \r\n " . $log;
	}
	if (!is_dir(dirname($logfile))) {
		$IoHandler->MakeDir(dirname($logfile));
	}
	
	$IoHandler->WriteFile($logfile,$log,'a');
	
	if($halt) {
		exit();
	}
}

function error($type, $message, $file = null, $line = 0) { if(E_NOTICE==$type)return true; require_once(LIB_PATH."error.han.php"); if(false == class_exists("ErrorHandler"))return false; $ErrorHandler = new ErrorHandler($type, $message, $file, $line); if(error_reporting() && $type)exit($ErrorHandler->fatal()); return true; }



?>