Example #1
0
	static public function ArrayToXml($array, $level=0, $topTagName='result', $topTagAttr = '')
	{
		if ($topTagName) {
			$xml = str_repeat("\t",$level) . "<$topTagName"."$topTagAttr>\n";
			$level++;
		}

		foreach ($array as $key=>$value) {
			if( is_numeric($key) ){
				$key = self::GetSubTagName($topTagName);
			}

			if($value===false) $value='false';
			if($value===true) $value='true';

			if (is_array($value)) {
				$xml .= self::ArrayToXml($value,$level,$key);
			} else {
				if (thtmlspecialchars($value) != $value || strstr($key, '<[cd]>')) {
                    $key = str_replace('<[cd]>', '', $key);
					$xml .= str_repeat("\t",$level)
						."<$key><![CDATA[$value]]></$key>\n";
				} else {
					$xml .= str_repeat("\t",$level).
						"<$key>$value</$key>\n";
				}
			}
		}

		if ($topTagName) {
			$xml .= str_repeat("\t",($level-1)) . "</$topTagName>\n";
		}
		return $xml;
	}
Example #2
0
function & XML_serialize($data, $level = 0, $prior_key = NULL){
	if($level == 0){ ob_start(); echo '<?xml version="1.0" ?>',"\n"; }
	while(list($key, $value) = each($data))
		if(!strpos($key, ' attr')) #if it's not an attribute
			#we don't treat attributes by themselves, so for an empty element
			# that has attributes you still need to set the element to NULL

			if(is_array($value) and array_key_exists(0, $value)){
				XML_serialize($value, $level, $key);
			}else{
				$tag = $prior_key ? $prior_key : $key;
				echo str_repeat("\t", $level),'<',$tag;
				if(array_key_exists("$key attr", $data)){ #if there's an attribute for this element
					while(list($attr_name, $attr_value) = each($data["$key attr"]))
						echo ' ',$attr_name,'="',thtmlspecialchars($attr_value),'"';
					reset($data["$key attr"]);
				}

				if(is_null($value)) echo " />\n";
				elseif(!is_array($value)) echo '>',thtmlspecialchars($value),"</$tag>\n";
				else echo ">\n",XML_serialize($value, $level+1),str_repeat("\t", $level),"</$tag>\n";
			}
	reset($data);
	if($level == 0){ $str = &ob_get_contents(); ob_end_clean(); return $str; }
}
Example #3
0
	public function __construct($config)
	{
		if (is_file(DATA_PATH.'install.lock'))
		{
			return $this->Alert('您已安装,如需重新安装请先删除 '.DATA_PATH.' 目录下的install.lock文件!');
		}
		if (true == in_array(ini('settings.site_domain'), array('localx.uuland.org', 'dev.tttuangou.net', )))
		{
						ini('settings.site_domain', $_SERVER['HTTP_HOST']);
			ini('settings.site_url', rtrim(thtmlspecialchars('http:/'.'/'.$_SERVER['HTTP_HOST'].preg_replace("/\/+/",'/',str_replace("\\",'/',dirname($_SERVER['PHP_SELF']))."/")),'/'));
		}
		$this->MasterObject($config);
		$runCode = Load::moduleCode($this);
		$this->$runCode();
	}
Example #4
0
	public function login($loginR, $username = '', $password = '')
	{
		$username = thtmlspecialchars($username);
		$password = thtmlspecialchars($password);
		if ($loginR == -1)
		{
			$name = '管理员('.$username.')登录失败,密码错误';
			$extra = '尝试使用密码 <b>'.$this->mosaic($password).'</b> 登录失败!';
		}
		elseif ($loginR == 0)
		{
			$name = '管理员登录失败,账户不存在';
			$extra = '登录用户名:'.$username.'<br/>登录密码:'.$this->mosaic($password);
		}
		elseif ($loginR == 1)
		{
			$name = '管理员('.$username.')登录成功,已经进入后台';
			$extra = '';
		}
		$this->zlogCreate('system', $name, $extra);
	}
Example #5
0
	private function dataCompare($pid, $newData)
	{
		$cString = '';
		$oldData = logic('product')->SrcOne($pid);
		$oldData = array_merge($oldData, $this->getOldExtraData($pid));
		foreach ($newData as $k => $v)
		{
			$ov = isset($oldData[$k]) ? $oldData[$k] : false;
			if (!$ov) continue;
			if ($ov == $v) continue;
			if (is_string($v) && (strlen($ov) > 100 || strlen($v) > 100))
			{
				continue;
			}
			else
			{
				$cString .= '修改了 “<i><b>'.$this->dataFieldName($k).'</b></i>” ,之前是 “<strike>'.thtmlspecialchars($ov).'</strike>” ,现在是 “'.thtmlspecialchars($v).'”';
			}
			$cString .= '<br/>';
		}
		return array('data' => $oldData, 'cstring' => $cString);
	}
Example #6
0
	function Query($sql,$type='SKIP_ERROR')
	{
				if(true===DEBUG)
		{
			$debug_list = debug_backtrace();
			foreach($debug_list as $key => $debug)
			{
				if($debug['file'] != __FILE__ and basename($debug['file']) != 'cache.db.php')
				{
					if($debug['class'] == __CLASS__ or $debug['class'] == 'cachehandler')
					{
						$file = $debug['file'];
						$line = $debug['line'];
					}
				}
			}
			$start = explode(" ", microtime());
			$start = $start[1] + $start[0];
		}
				$cr = dbc(DBCMax)->is_sql_safe($sql);
				$func=$type==='UNBUFFERED'?'mysql_unbuffered_query':'mysql_query';
		$result = @$func($sql, $this->GetConnectionId());
		if($result==false)
		{
			zlog('error')->found('mysql', $this->GetLastErrorString().'<pre>'.thtmlspecialchars($sql).'</pre>');
			if(in_array($this->GetLastErrorNo(), array(2006, 2013)) && substr($type, 0, 5) != 'RETRY') {
				$this->CloseConnection();
				dbc()->Query($sql, 'RETRY'.$type);
			} elseif (in_array($this->GetLastErrorNo(), array(1040)) && substr($type,0,4) != "WAIT" && substr($type,0,5) < "WAIT3") {
				usleep(100000 * max(1,min(6,2 * ((int) substr($type,4,1) + 1))));

				$result = $this->Query($sql, 'WAIT'.++$WAITTIMES.$type);
			} elseif ($type != 'SKIP_ERROR' && substr($type, 5) != 'SKIP_ERROR') {
				return dbc(DBCMax)->alert("MYSQL QUERY ERROR [Driver.100]");
			} else {
				return false;
			}
		}

		if(true===DEBUG)
		{

			$stop = explode(" ", microtime());
			$stop = round(($stop[1] + $stop[0]) - $start, 5);

									$explain="";
			if (substr(trim(strtoupper($sql)),0,6)=="SELECT")
			{
				$explain_id = mysql_query("EXPLAIN $sql", $this->GetConnectionId());
				while($array=mysql_fetch_array($explain_id)) {
					if(!empty($explain)) $explain .="<hr>";
					$explain .= "
					Sql_Table: $array[table]<br />
					Query_type: $array[type]<br />
					possible_keys: $array[possible_keys]<br />
					<font color=red>Query_key: $array[key]<br />
					Query_rows: $array[rows]<br />
					Query_time: $stop</font><br />
					key_len: $array[key_len]<br />
					ref: $array[ref]<br />
					extra: $array[Extra]<br />
				  ";
				}
			}

			$this->SetSqlStore(array('SQL' => $sql, 'TIME' => $stop, "FILE" => $file, "LINE" => $line, "FROM" => "Database", "explain" => $explain));
		}

		return new mysqlQueryIterator($result);
	}
Example #7
0
function thtmlspecialchars($string, $flags = null, $charset = null) {
	if(is_array($string)) {
		foreach($string as $k=>$v) {
			$string[$k] = thtmlspecialchars($string, $flags, $charset);
		}
	} else {
		if(null === $flags) {
			$string = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string);
			if(strpos($string, '&amp;#') !== false) {
				$string = preg_replace('/&amp;((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $string);
			}
		} else {
			if(PHP_VERSION < '5.4.0') {
				$string = htmlspecialchars($string, $flags);
			} else {
				$charset = (is_null($charset) ? ini('settings.charset') : $charset);
				if(strtolower($charset) == 'utf-8') {
					$charset = 'UTF-8';
				} else {
					$charset = 'ISO-8859-1';
				}
				$string = htmlspecialchars($string, $flags, $charset);
			}
		}
	}
	return $string;
}
Example #8
0
					public function alert( $message, $dbo = false )
	{
				$errNum = @mysql_errno($this->_dbc_handle);
		$errMsg = @mysql_error($this->_dbc_handle);
				$dbo && zlog('error')->found('mysql', '['.$errNum.']: '.$errMsg.'<pre>'.thtmlspecialchars($dbo->sql).'</pre>');
				if (!$this->_debug)
		{
			$dbo && $this->free($dbo);
			return false;
		}
				if (!logic('misc')->siteInstalled())
		{
			return false;
		}
				echo '<div style="border:2px solid #000;margin:10px;padding:10px;">';
		echo $message;
		if ($this->_debug)
		{
			$errMsg && print('<hr/>'.$errMsg);
			$dbo->sql && print('<hr/>'.$dbo->sql);
		}
		$btAll = function_exists('debug_backtrace') ? debug_backtrace() : false;
		if ($btAll)
		{
			$btLength = count($btAll);
			$btLength > 7 && $btLength = 7;
			$btString = '';
			$btIII = 0;
			for ($btI = $btLength; $btI > 0; $btI--)
			{
				$btOne = $btAll[$btI-1];
				$btIII ++;
				$btString .= $btIII.'. FILE:'.basename($btOne['file']).' - LINE:'.$btOne['line'].' - FUNC:'.$btOne['function'].'<br/>';
			}
			echo '<hr/>'.$btString;
		}
		echo '</div>';
		exit;
	}
Example #9
0
function page_moyo_request_uri($flag = 'page')
{
	$u = '?';
	foreach ($_GET as $k => $v)
	{
		if ($k != $flag) $u .= thtmlspecialchars($k).'='.urlencode($v).'&';
	}
	return substr($u, 0, -1);
}
Example #10
0
 function txt($val)
 {
     if ($val != '')
     {
         $charset_loops = array();
         if (ENC_IS_GBK)
         {
             $charset_loops[] = 'GB2312';
             $charset_loops[] = 'ISO-8859-1';
         }
         else
         {
             $charset_loops[] = 'UTF-8';
         }
         foreach ($charset_loops as $charset)
         {
             if ('' != $parsed = @thtmlspecialchars($val, ENT_COMPAT, $charset))
             {
                 return $parsed;
             }
         }
         return $val;
     }
     else
     {
         return $val;
     }
 }
Example #11
0
	function getlines($lines)
	{
		$code    = "<ul class=\"code\">";
    	$total   = sizeof($lines);

		for($i = $this->_line - 5; $i <= $this->_line + 5; $i++)
		{
    		if(($i >= 1) && ($i <= $total))
            {
                $codeline = @rtrim(thtmlspecialchars($lines[$i - 1]));
                $codeline = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $codeline);
                $codeline = str_replace(' ',  '&nbsp;',                   $codeline);

                $i = sprintf("%05d", $i);

                $class = $i % 2 == 0 ? 'crowone' : 'crowtwo';

                if($i != $this->_line)
                {
                    $code .= "<li class=\"$class\"><span>{$i}</span> {$codeline}</li>\n";
                }
                else
                {
                    $code .= "<li class=\"mark\"><span>{$i}</span> {$codeline}</li>\n";
                }
            }
		}

        $code .= "</ul>";

		return $code;
	}