<?php
/*******************************************************************************
* Ourphp - CMS建站系统
* Copyright (C) 2014 ourphp.net
* 开发者：哈尔滨伟成科技有限公司
*******************************************************************************/
if(!defined('OURPHPNO')){exit('no!');}

/*
 *	防注入函数
 */
function dowith_sql($ourphpstr){
	$ourphpstr = addslashes($ourphpstr);
	$ourphpstr = str_ireplace(" and ","**",$ourphpstr);
	$ourphpstr = str_ireplace(" or ","**",$ourphpstr);
	$ourphpstr = str_ireplace("&&","**",$ourphpstr);
	$ourphpstr = str_ireplace("||","**",$ourphpstr);
	$ourphpstr = str_ireplace("<script","**",$ourphpstr);
	$ourphpstr = str_ireplace("<iframe","**",$ourphpstr);
	$ourphpstr = str_ireplace("<embed","**",$ourphpstr);
	$ourphpstr = str_ireplace("<","&lt;",$ourphpstr);
	$ourphpstr = str_ireplace(">","&gt;",$ourphpstr);
	$ourphpstr = str_ireplace("&","&amp;",$ourphpstr);
	$ourphpstr = str_ireplace('--',"**",$ourphpstr);
	$ourphpstr = str_ireplace("%","\%",$ourphpstr);
	$ourphpstr = str_ireplace("'","**",$ourphpstr);
	$ourphpstr = str_ireplace("ascii","<span>ascii</span>",$ourphpstr);
	$ourphpstr = str_ireplace("alert","<span>alert</span>",$ourphpstr);
	$ourphpstr = str_ireplace("count","<span>count</span>",$ourphpstr);
	$ourphpstr = str_ireplace("chr","<span>chr</span>",$ourphpstr);
	$ourphpstr = str_ireplace("char","<span>char</span>",$ourphpstr);
	$ourphpstr = str_ireplace("concat","<span>concat</span>",$ourphpstr);
	$ourphpstr = str_ireplace("columns","<span>columns</span>",$ourphpstr);
	$ourphpstr = str_ireplace("declare","<span>declare</span>",$ourphpstr);
	$ourphpstr = str_ireplace("delete","<span>delete</span>",$ourphpstr);
	$ourphpstr = str_ireplace("document","<span>document</span>",$ourphpstr);
	$ourphpstr = str_ireplace("database","<span>database</span>",$ourphpstr);
	$ourphpstr = str_ireplace("execute","<span>execute</span>",$ourphpstr);
	$ourphpstr = str_ireplace("extractvalue","<span>extractvalue</span>",$ourphpstr);
	$ourphpstr = str_ireplace("eval","<span>eval</span>",$ourphpstr);
	$ourphpstr = str_ireplace("encode","<span>encode</span>",$ourphpstr);
	$ourphpstr = str_ireplace("from","<span>from</span>",$ourphpstr);
	$ourphpstr = str_ireplace("group_concat","<span>group_concat</span>",$ourphpstr);
	$ourphpstr = str_ireplace("information_schema","<span>information_schema</span>",$ourphpstr);
	$ourphpstr = str_ireplace("insert","<span>insert</span>",$ourphpstr);
	$ourphpstr = str_ireplace("if","<span>if</span>",$ourphpstr);
	$ourphpstr = str_ireplace("join","<span>join</span>",$ourphpstr);
	$ourphpstr = str_ireplace("length","<span>length</span>",$ourphpstr);
	$ourphpstr = str_ireplace("limit","<span>limit</span>",$ourphpstr);
	$ourphpstr = str_ireplace("onmouseover","<span>onmouseover</span>",$ourphpstr);
	$ourphpstr = str_ireplace("print","<span>print</span>",$ourphpstr);
	$ourphpstr = str_ireplace("password","<span>password</span>",$ourphpstr);
	$ourphpstr = str_ireplace("replace","<span>replace</span>",$ourphpstr);
	$ourphpstr = str_ireplace("regexp_replace","<span>regexp_replace</span>",$ourphpstr);
	$ourphpstr = str_ireplace("substr","<span>substr</span>",$ourphpstr);
	$ourphpstr = str_ireplace("sleep","<span>sleep</span>",$ourphpstr);
	$ourphpstr = str_ireplace("select","<span>select</span>",$ourphpstr);
	$ourphpstr = str_ireplace("truncate","<span>truncate</span>",$ourphpstr);
	$ourphpstr = str_ireplace("tables","<span>tables</span>",$ourphpstr);
	$ourphpstr = str_ireplace("union","<span>union</span>",$ourphpstr);
	$ourphpstr = str_ireplace("updatexml","<span>updatexml</span>",$ourphpstr);
	$ourphpstr = str_ireplace("username","<span>username</span>",$ourphpstr);
	$ourphpstr = str_ireplace("update","<span>update</span>",$ourphpstr);
	$ourphpstr = str_ireplace("where","<span>where</span>",$ourphpstr);
	return $ourphpstr;
}

function admin_sql($ourphpstr){
	$ourphpstr = str_ireplace("'","",$ourphpstr);
	$ourphpstr = str_ireplace(" and ","<span>and</span>",$ourphpstr);
	$ourphpstr = str_ireplace(" or ","<span>or</span>",$ourphpstr);
	$ourphpstr = str_ireplace("&&","<span>&&</span>",$ourphpstr);
	$ourphpstr = str_ireplace("||","<span>||</span>",$ourphpstr);
	$ourphpstr = str_ireplace("ascii","<span>ascii</span>",$ourphpstr);
	$ourphpstr = str_ireplace("columns","<span>columns</span>",$ourphpstr);
	$ourphpstr = str_ireplace("count","<span>count</span>",$ourphpstr);
	$ourphpstr = str_ireplace("concat","<span>concat</span>",$ourphpstr);
	$ourphpstr = str_ireplace("database","<span>database</span>",$ourphpstr);
	$ourphpstr = str_ireplace("delete","<span>delete</span>",$ourphpstr);
	$ourphpstr = str_ireplace("execute","<span>execute</span>",$ourphpstr);
	$ourphpstr = str_ireplace("encode","<span>encode</span>",$ourphpstr);
	$ourphpstr = str_ireplace("from","<span>from</span>",$ourphpstr);
	$ourphpstr = str_ireplace("group_concat","<span>group_concat</span>",$ourphpstr);
	$ourphpstr = str_ireplace("information_schema","<span>information_schema</span>",$ourphpstr);
	$ourphpstr = str_ireplace("insert","<span>insert</span>",$ourphpstr);
	$ourphpstr = str_ireplace("if","<span>if</span>",$ourphpstr);
	$ourphpstr = str_ireplace("join","<span>join</span>",$ourphpstr);
	$ourphpstr = str_ireplace("length","<span>length</span>",$ourphpstr);
	$ourphpstr = str_ireplace("print","<span>print</span>",$ourphpstr);
	$ourphpstr = str_ireplace("password","<span>password</span>",$ourphpstr);
	$ourphpstr = str_ireplace("replace","<span>replace</span>",$ourphpstr);
	$ourphpstr = str_ireplace("regexp_replace","<span>regexp_replace</span>",$ourphpstr);
	$ourphpstr = str_ireplace("substr","<span>substr</span>",$ourphpstr);
	$ourphpstr = str_ireplace("sleep","<span>sleep</span>",$ourphpstr);
	$ourphpstr = str_ireplace("select","<span>select</span>",$ourphpstr);
	$ourphpstr = str_ireplace("tables","<span>tables</span>",$ourphpstr);
	$ourphpstr = str_ireplace("union","<span>union</span>",$ourphpstr);
	$ourphpstr = str_ireplace("updatexml","<span>updatexml</span>",$ourphpstr);
	$ourphpstr = str_ireplace("username","<span>username</span>",$ourphpstr);
	$ourphpstr = str_ireplace("update","<span>update</span>",$ourphpstr);
	$ourphpstr = str_ireplace("where","<span>where</span>",$ourphpstr);
	$ourphpstr = str_ireplace("white-space:n<span>or</span>mal;","white-space:normal;",$ourphpstr);
	$ourphpstr = str_ireplace("data-<span>or</span>iginal","data-original",$ourphpstr);
	return $ourphpstr;
}


spl_autoload_register("ourphp_auto");

function ourphp_auto($className)
{
	$file = WEB_ROOT.'/function/'.str_replace('\\', '/', $className).'.php';
	if(file_exists($file)){
		include $file;
	}
}

/*
* 格式化时间
*/
function newtime($t){
		$now_time = date("Y-m-d H:i:s", time());  
		$now_time = strtotime($now_time);  
		$show_time = strtotime($t);  
		$dur = $now_time - $show_time;  
		if ($dur < 0) {  
			return $t;  
		} else {  
			if ($dur < 60) {  
				return $dur . '秒前';  
			} else {  
				if ($dur < 3600) {  
					return floor($dur / 60) . '分钟前';  
				} else {  
					if ($dur < 86400) {  
						return floor($dur / 3600) . '小时前';  
					} else {  
						if ($dur < 259200) { //3天内  
							return floor($dur / 86400) . '天前';  
						} else {  
							return $t;
						}  
					}  
				}  
			}  
		}  
}
/*
* 过虑URL中的ID ?ch-list-article-$id.html
* $str=substr($str,7);//去除前面
*/
function ourphp_Cut($ourphpstr){
	$n = strpos($ourphpstr,'.');
	if ($n) $ourphpstr = substr($ourphpstr,0,$n);
	return $ourphpstr;
}
/*
* 截取$code之后的所有字符并替换空
*/
function ourphp_urlcut($str,$code)
{

	$a = strstr($str, $code);
	$b = strlen($code);
	$c = substr($a, $b);
	return str_replace($c,"",$str);
}

/*
 * @param string $str 被截取的字符串 
 * @param integer $start 起始位置 
 * @param integer $length 截取长度(每个汉字为3字节) 
 */
function utf8_strcut($str, $start, $length=null){  
	preg_match_all('/./us', $str, $match);  
	$chars = is_null($length)? array_slice($match[0], $start ) : array_slice($match[0], $start, $length);  
	unset($str);
	return implode('', $chars);  
}

/*
 * @param string $str 被截取的字符串 
 * @param integer $s 起始位置 
 * @param integer $e 截取长度
 */
function ourphp_mb_substr($str = '',$s = 0, $e = ''){
	if(empty($str) || empty($e)){
		return false;
	}else{
		return mb_substr($str, $s, $e, 'utf-8');
	}
}

/*
 * 随机生成一组32位字符，可用于验证
 * 调用方式randomkeys(18)
 */  
function randomkeys($length, $type = 1){
	$key = "";
	$pattern = '1234567890abcdefghijklmnopqrstuvwxyz';
	for($i=0;$i<$length;$i++){
		$key .= $pattern[mt_rand(0,35)];
	}
	if($type == 1){
		return $key.date("YmdHis");
	}else{
		return $key;
	}
}

/*
 * 根据$num参数生成一个指定位数的推广码
 * $num传过来的ID，$type 1纯数字 2带字母  $end补齐位数，例如你的$num是一位数，$end自动补齐剩余7位数
 */ 
function promotionuid($num = 0, $type = 1, $end = 8){
	
	if($type == 1)
	{
		$rand = rand(0000000000,9999999999);
	}
	if($type == 2)
	{
		$rand = randomkeys(10,2);
	}
	$newid = ($end - strlen($num));
	$newid = $num.substr($rand,0,$newid);
	if(strlen($num) >= $end)
	{
		return $num;
	}else{
		return strtoupper($newid);
	}	
	
}

/*
 * 压缩html : 清除换行符,清除制表符,去掉注释标记  
 * @param $string  
 * @return  压缩后的$string 
 */
function compress_html($string, $k = 1) {  
    $string = str_replace("\r\n", '', $string); //清除换行符  
    $string = str_replace("\n", '', $string); //清除换行符  
    $string = str_replace("\t", '', $string); //清除制表符 
	if($k == 1){
		$string = str_replace(" ", '', $string); //清除空格
	}
    $pattern = array (  
		"/> *([^ ]*) *</", //去掉注释标记  
		"/[\s]+/",  
		"/<!--[^!]*-->/",  
		"/\" /",  
		"/ \"/",  
		"'/\*[^*]*\*/'"  
    );  
    $replace = array (  
		">\\1<",  
		" ",  
		"",  
		"\"",  
		"\"",  
		""  
    );  
    return preg_replace($pattern, $replace, $string);  
}

/*
 * 替换中间字符为 ***   
 */
function half_replace($str){
    $len = strlen($str)/2;
    return substr_replace($str,str_repeat('*',$len),ceil(($len)/2),$len);
}

/*
 * 插件类
 * plugs静态方法 $a = plugsclass::plugs($id); 获取参数：$a[0];
 */
class plugsclass{
	
	public $db;
	public $ourphp;
	
	public static function webupdate()
	{
		return "0";
	}
	
	public static function plugs($id)
	{
		global $db;
		$rs = $db -> select("`OP_Key`","`ourphp_api`","where `id` = ".intval($id));
		$api = explode('|',$rs[0]);
		switch($api[1]){
			case "1":
				return $api;
			break;
			case "2":
				return false;
			break;
		}
	}
	
	public static function webdeploy($info)
	{
		global $db;
		$rs = $db -> select("OP_Login,OP_Empower,OP_Empowerlist,OP_Empowerright","`ourphp_webdeploy`","where `id` = 1");
		switch($info){
			case "OP_Login":
				return $rs[0];
			break;
			case "OP_Empower":
				return $rs[1];
			break;
			case "OP_Empowerlist":
				return $rs[2];
			break;
			case "OP_Empowerright":
				return $rs[3];
			break;
		}
	}
	
	/*
	 * 日志
	 */
	public static function logs($content = '', $account = '', $time = '')
	{
		global $db;
		if($content != '')
		{
			if(getenv('HTTP_CLIENT_IP'))
			{ 
				$ip = getenv('HTTP_CLIENT_IP');
			}elseif(getenv('HTTP_X_FORWARDED_FOR')){ 
				$ip = getenv('HTTP_X_FORWARDED_FOR');
			} elseif(getenv('REMOTE_ADDR')){ 
				$ip = getenv('REMOTE_ADDR');
			} else { 
				$ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
			}
			
			if($time == '')
			{
				$time = date("Y-m-d H:i:s");
			}else{
				$time = $time;
			}
			
			$db -> insert("ourphp_logs","
				`OP_Logscontent` = '".admin_sql(compress_html($content))."',
				`OP_Logsaccount` = '".admin_sql(compress_html($account))."',
				`OP_Logsip` = '".admin_sql(compress_html($ip))."',
				`time` = '".admin_sql($time)."'
			","");
			
			return true;
		}else{
			return false;
		}
	}
	
	public function plushtmlfile($html = '')
	{
		global $db,$ourphp;
		$html = str_replace("，",",",$html);
		$html = explode(",",$html);
		$htmlcode = $ourphp['webpath'].'function/plugs/';
		$htmllist = '';
		foreach($html as $op)
		{
			if($op == 'YIQI-UI'): $htmllist .= '
				<link rel="stylesheet" href="'.$htmlcode.'YIQI-UI/YIQI-UI.min.css" type="text/css" />
				<link rel="stylesheet" href="'.$htmlcode.'YIQI-UI/font/YIQI-UI-iconfont.min.css" type="text/css" />
			'; endif;
			
			if($op == 'jquery'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'jquery/2.1.1/jquery-2.1.1.min.js"></script>
			'; endif;
			
			if($op == 'jquery1.8.3'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'jquery/1.8.3/jquery-1.8.3.min.js"></script>
			'; endif;

			if($op == 'jquery1.7.2'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'jquery/1.7.2/jquery-1.7.2.min.js"></script>
			'; endif;
			
			if($op == 'layer'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'layer3.1.0/layer.js"></script>
			'; endif;
			
			if($op == 'laydate'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'laydate/laydate.js"></script>
			'; endif;
			
			if($op == 'lazyload'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'lazyload/jquery.lazyload.js"></script>
				<script type="text/javascript">
				$(document).ready(function() { 
					$("img").lazyload({ 
						effect: "fadeIn",
						threshold: 100
					});
				});
				</script>
			'; endif;
			
			if($op == 'Validform'): $htmllist .= '
				<link rel="stylesheet" href="'.$htmlcode.'Validform/style.css" type="text/css" />
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'Validform/Validform_v5.3.2.js"></script>
				<script type="text/javascript">
				$(function(){
					$(".registerform").Validform();
				})
				</script>
			'; endif;
			
			if($op == 'city'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'city/jquery.cityselect.js"></script>
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'city/city.min.js"></script>
			'; endif;
			
			if($op == 'context'): $htmllist .= '
				<link rel="stylesheet" type="text/css" href="'.$htmlcode.'context/context.standalone.css">
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'context/context.js"></script>
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'context/demo.js"></script>
			'; endif;
			
			if($op == 'copyplus'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'copyplus/clipboard.min.js"></script>
				<script>
					var clipboard = new Clipboard(".copyplus");
					clipboard.on("success", function(e) {
						alert("复制成功!");
					});
				</script>
			'; endif;
			
			if($op == 'dragsort'): $htmllist .= '
				<script language="JavaScript" type="text/javascript" src="'.$htmlcode.'dragsort/jquery.dragsort-0.5.1.min.js"></script>
			'; endif;
			
		}
		return $htmllist;
	}
	
	public function plushtml($title = '', $html = 'head', $arr = '')
	{
		global $db,$ourphp;
		$material = '';
		if($arr != '')
		{
			$material = $this -> plushtmlfile($arr);
		}
		$return = array(
			"head" => '
				<!DOCTYPE html>
				<html lang="zh-cmn-Hans">
				<head>
				<!-- 声明文档使用的字符编码 -->
				<meta charset="utf-8">
				<!-- 优先使用 IE 最新版本和 Chrome -->
				<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
				<!-- 页面描述 -->
				<meta name="description" content="'.$title.'"/>
				<!-- 页面关键词 -->
				<meta name="keywords" content="'.$title.'"/>
				<!-- 网页作者 -->
				<meta name="author" content="www.ourphp.net"/>
				<!-- 为移动设备添加 viewport -->
				<meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
				<!-- `width=device-width` 会导致 iPhone 5 添加到主屏后以 WebApp 全屏模式打开页面时出现黑边 http://bigc.at/ios-webapp-viewport-meta.orz -->
				<meta name="apple-mobile-web-app-title" content="'.$title.'">
				<!-- 添加到主屏后的标题（iOS 6 新增） -->
				<meta name="apple-mobile-web-app-capable" content="yes"/>
				<!-- 是否启用 WebApp 全屏模式，删除苹果默认的工具栏和菜单栏 -->
				<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
				<!-- 设置苹果工具栏颜色 -->
				<!-- 启用360浏览器的极速模式(webkit) -->
				<meta name="renderer" content="webkit">
				<!-- 避免IE使用兼容模式 -->
				<meta http-equiv="X-UA-Compatible" content="IE=edge">
				<!-- 不让百度转码 -->
				<meta http-equiv="Cache-Control" content="no-siteapp" />
				<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
				<meta name="HandheldFriendly" content="true">
				<!-- 微软的老式浏览器 -->
				<meta name="MobileOptimized" content="320">
				<!-- uc强制竖屏 -->
				<meta name="screen-orientation" content="portrait">
				<!-- QQ强制竖屏 -->
				<meta name="x5-orientation" content="portrait">
				<!-- UC强制全屏 -->
				<meta name="full-screen" content="yes">
				<!-- QQ强制全屏 -->
				<meta name="x5-fullscreen" content="true">
				<!-- UC应用模式 -->
				<meta name="browsermode" content="application">
				<!-- QQ应用模式 -->
				<meta name="x5-page-mode" content="app">
				<!-- windows phone 点击无高光 -->
				<meta name="msapplication-tap-highlight" content="no">
				<title>'.$title.'</title>
				'.$material.'
				<style type="text/css">
					*{ margin:0 auto; font-size:12px; font-family:"Airal,微软雅黑"; }
					html,body{width:100%; height:100%;}
					.clear{clear:both;}
					div,ul,li,dl,dt,dd,form{list-style:none; }
					#tabs0 {height: auto; width: 90%; margin:0 auto; }
					.menu0{width: 960px; }
					.menu0 li{display:block; float: left; width:150px; height:30px; line-height:30px; text-align: center; cursor:pointer; background: #f4f4f4; }
					.menu0 li.hover{color:#FFFFFF; background: #488fcd; }
					#main0 ul{display: none; padding:0px; background: #F5F5F5; }
					#main0 ul.block{display: block; }
					.input{border:1px #e5e5e5 solid; background:#e5e5e5; border-radius:4px; padding:5px;}
					.input:hover{background:#fff; outline-color:#abd7fd;}
					.input:focus{background:#fff; outline-color:#abd7fd;}
					.button { background:URL(../../manage/templates/images/ourphp-anniu.png) no-repeat; width:100px; height:25px; font-size:12px; line-height:25px; border:0px;}
					.button:hover { background:URL(../../manage/templates/images/ourphp-anniu2.png) no-repeat; width:100px; height:25px; font-size:12px; line-height:25px; border:0px;}
				</style>
				</head>
				<body id="YIQI-UI">
			',
			"bottom" => $material.'
				</body>
				</html>
			',
		);
		
		return $return[$html];
	}
	
}


/*
 * 判断手机或电脑   
 */
function isMobile($type = ''){
	global $ourphp,$db;
	$useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';  
	$useragent_commentsblock = preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';  	  
	function CheckSubstrs($substrs,$text){  
		foreach($substrs as $substr)
			if(false !== strpos($text,$substr)){  
				return true;
			}
			return false;
	}
	$mobile_os_list = array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
	$mobile_token_list = array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
	$found_mobile = CheckSubstrs($mobile_os_list,$useragent_commentsblock) || CheckSubstrs($mobile_token_list,$useragent);
	if($type == 'pc'){
		if ($found_mobile){
			return "<script language=javascript>location.replace('".$ourphp['webpath']."client/wap/?".$_SERVER["QUERY_STRING"]."');</script>";
		}else{
			return false;
		}
	}elseif($type == 'wap'){
		if (!$found_mobile){
			$rs = $db -> select("OP_Weburl","ourphp_wap","where id = 1");
			if($rs[0] == 'yes'){
				return false;
			}else{
				return "<script language=javascript>location.replace('".$ourphp['webpath']."?".$_SERVER["QUERY_STRING"]."');</script>";
			}
		}else{
			return false;
		}
	}
}

/*
 * 处理缓存文件 
 */
function ourphp_file($file,$content,$class){
	global $ourphp;
	if($ourphp['cache'] == 'open')
	{
		$of = fopen(WEB_ROOT.'/'.$file,'w');
		if($of){
			$con = fwrite($of,$content);
		}
		return $con;
		fclose($of);		
	}
	return;
}

/*
 * 处理json传递的数组 
 */
function object_array($array){
	if(is_object($array)){
		$array = (array)$array;
	}
	if(is_array($array)){
		foreach($array as $key => $value){
			$array[$key] = object_array($value);
		}
	}
	return $array;
}

/*
 * 处理敏感字 
 */
function ourphp_sensitive($content = ''){
	global $db;
	$sensitive = $db -> select("`OP_Sensitive`","`ourphp_webdeploy`","where `id` = 1");
	$var = explode("|",$sensitive[0]);
	$vartwo = array_combine($var,array_fill(0,count($var),'*'));
	return strtr($content, $vartwo);
}

function op($info = ''){
	global $ourphp_O0O0o00o0;
	if($info){
		$api = plugsclass::webdeploy($info);
		$md = authcode($api, $operation = 'DECODE', $key = 'tangwei', $expiry = 0);
	}
	if (!isset($ourphp_O0O0o00o0)){
		return $md;
	}else{
		if($ourphp_O0O0o00o0 == "95d4f8af44"){
			return ;
		}else{
			return $md;
		}
	}
}

/*
 * 处理电脑与移动端返回路径 
 */
function ourphp_pcwapurl($type = '',$pcurl = '',$wapurl = '',$goback = 0,$font = ''){
	global $ourphp;
	if($goback == 0){
		if($type == '' || $type == 'pc'){
			$url = $ourphp['webpath'].'client/user/'.$pcurl;
		}elseif($type == 'wap'){
			$url = $ourphp['webpath'].'client/wap/'.$wapurl;
		}
		if($font != ''){
			$alert = 'alert(\''.$font.'\');';
		}
		return "<script language=javascript>".$alert."location.replace('".$url."');</script>";
	}else{
		return "<script language=javascript>alert('".$font."');history.go(-1);</script>";
	}
}

function quota($num = 0)
{
	global $ourphp_adminfont;
	$f = explode("|",$ourphp_adminfont['quota']);
	$quota = '<span style="color: #dd514c; background-color: #fff; border: 1px solid #dd514c; padding:0 5px; font-size:14px;">'.$f[0].$num.$f[1].'</span>';
	return $quota;
}

function arrend($arr, $op)
{
	return rtrim($arr,$op);
}

function func_new_each(&$array){
   $res = array();
   $key = key($array);
   if($key !== null){
	   next($array); 
	   $res[1] = $res['value'] = $array[$key];
	   $res[0] = $res['key'] = $key;
   }else{
	   $res = false;
   }
   return $res;
}
 
/*
 * 404跳转
 */
function no404()
{
	global $ourphp;
	return '<meta http-equiv="refresh" content="0;url='.$ourphp['webpath'].'?cn-404.html">';
}

$homedeploy = $db -> select("`OP_Home`,`OP_Webupdate`","`ourphp_webdeploy`","where `id` = 1");
$homelang = explode('|',$homedeploy[0]);
?>