PageRenderTime 1658ms CodeModel.GetById 232ms app.highlight 619ms RepoModel.GetById 696ms app.codeStats 1ms

/trunk/includes/fun.php

https://gitlab.com/BGCX261/zhuoao-svn-to-git
PHP | 1866 lines | 1621 code | 118 blank | 127 comment | 230 complexity | 9a323b458adadb092154fe3a6505e47e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * $Author: BEESCMS $
   4 * ============================================================================
   5 * 网站地址: http://www.beescms.com
   6 * 您只能在不用于商业目的的前提下对程序代码进行修改和使用;
   7 * 不允许对程序代码以任何形式任何目的的再发布。
   8 * ============================================================================
   9*/
  10
  11/*
  12*转义函数
  13*
  14*@param   $value   array || string
  15*@return  array || string
  16*/
  17function addsl($value)
  18{
  19    if (empty($value))
  20    {
  21        return $value;
  22    }
  23    else
  24    {	
  25        return is_array($value) ? array_map('addsl', $value) : addslashes($value);
  26    }
  27}
  28
  29
  30/*
  31*
  32*跳转页面操作
  33*
  34*/
  35function go_url($fun){
  36	if(!function_exists($fun)){
  37		err('没有相关操作');
  38	}
  39	$fun();
  40}
  41
  42/*
  43*
  44*判断数字
  45*
  46*/
  47function is_num($str){
  48	if(strlen($str)>0){
  49	return preg_match('/[\d]/',$str);
  50	}
  51}
  52
  53function check_str($str,$ereg){
  54	if(empty($str)){
  55		return false;
  56	}else{
  57		return preg_match($ereg,$str);
  58	}
  59	
  60}
  61
  62/*
  63*自动返回操作信息
  64*$url-返回地址    $message-详细信息
  65*return $string
  66*/
  67function msg($message,$url="javascript:window.history.back(-1);",$is_time=1,$break='true',$tpl='template/message.html'){
  68	$message="<p style=\"font-weight:bold;color:#1566B3\">".$message."</p>";
  69	$message.="<p>页面将在<span id=\"is_time\"></span>秒后自动返回</p>";
  70	if(!empty($url)){
  71		$message.="<p id=\"time_url\"><a href=\"".$url."\">返回上一页</a></p>";
  72		$message.=($is_time)?"<script type=\"text/javascript\">time_go();</script>":'';
  73	}
  74	//$message.="</div></div>";
  75	include($tpl);
  76	if($break){
  77		exit;
  78	}
  79}
  80//错误信息
  81function err($message,$url="javascript:history.go(-1);",$break='true',$tpl='template/message.html'){
  82	$message="<div style=\"font-size:12px;\"><p>".$message."</p>";
  83	if(!empty($url)){
  84		$message.="<p id=\"time_url\"><a href=\"".$url."\" style=\"text-decration:none\">返回</a>";
  85	}
  86	$tpl=CMS_PATH.ADMINDIR.'/'.$tpl;
  87	$message.="</div>";
  88	die($message);
  89}
  90//生成html提示
  91function show_htm($message,$url="javascript:history.go(-1);",$is_time=1,$break='true',$tpl='template/show_htm.html'){
  92	$message="<p>".$message."</p>";
  93	$message.="<p>页面将在<span id=\"is_time\"></span>秒后自动更新,如果没反应点击下面链接</p>";
  94	if(!empty($url)){
  95		$message.="<p id=\"time_url\"><a href=\"".$url."\">返回</a>";
  96		$message.=($is_time)?"<script type=\"text/javascript\">time_go();</script>":'';
  97	}
  98	include($tpl);
  99	if($break){
 100		exit;
 101	}
 102}
 103
 104function copy_lang($lang){
 105	if(isset($lang)){
 106		if(!$fp=@fopen(LANG_PATH.'lang_cn.php','r')){
 107			msg('基本语言包不能操作,请检查是否有操作文件的权限','javascript:history.go(-1);');
 108		}
 109		$fl=fread($fp,filesize(LANG_PATH.'lang_cn.php'));
 110		unset($fp);
 111		$fp2=@fopen(LANG_PATH.'lang_'.$lang.'.php','w');
 112		return fwrite($fp2,$fl);
 113	}
 114}
 115//生成配置文件
 116function creat_inc($fl,$str){
 117	if(file_exists($fl)){@unlink($fl);}
 118	if(!$fp=@fopen($fl,'w')){
 119		msg('文件打开失败,请检查是否有足够的权限操作文件');
 120	}
 121	flock($fp,LOCK_EX);
 122	if(!fwrite($fp,$str)){
 123		msg('写入文件失败,请检查是否有足够的权限操作文件');
 124	}
 125	flock($fp,LOCK_UN);
 126	unset($fp);
 127}
 128
 129//判断文件可写
 130function check_dir_write($path){
 131	if(!file_exists($path)){return false;}
 132	$file=$path.'write.txt';
 133	if(!$fp=@fopen($file,'w')){return false;}
 134	if(!@fwrite($fp,'write')){return false;}
 135	fclose($fp);
 136	@unlink($file);
 137	return true;
 138}
 139function image_type($arr){
 140	return is_array($arr)?array_map('image_type',$arr):'image/'.$arr;
 141}
 142
 143function cate_list($parent,$arr){
 144	if(isset($arr['p'.$parent])){
 145		echo "<div id=\"catagory\"><p class=\"left\"><span class=\"exp\"></span><input type=\"checkbox\" style=\"\" name=\"sel[]\"/><span class=\"cata\">{$arr['p'.$parent]['cate_name']}</span></p><p class=\"right\"><span class=\"caozuo\"><a href=\"?action=child&parent=11\">增加下级栏目</a>|<a href=\"\">本栏目内容</a>|<a href=\"\">修改</a>|<a href=\"\">移动栏目</a>|<a href=\"\">删除</a></span><input style=\"width:20px;\" name=\"order\" value=\"11\"/></p><div style=\"clear:both\"></div></div>";
 146		cate_list($arr['p'.$parent]['id'],$arr);	
 147	}
 148}
 149
 150function del_cate_child($parent,$lang){
 151	$num=$GLOBALS['mysql']->fetch_rows("select id from ".DB_PRE."category where cate_parent=".$parent." and lang='".$lang."'");
 152	if(!empty($num)){
 153	msg('请先删除下级栏目');
 154		/*foreach($num as $key=>$value){
 155			del_cate_child($value['id'],$lang);
 156			$GLOBALS['mysql']->query("delete from ".DB_PRE."category where id=".$value['id']." and lang='".$lang."'");
 157		}*/
 158	}
 159		/*if(file_exists(DATA_PATH.'cache_cate/cache_category'.$parent.'_'.$lang.'.php')){
 160				unlink(DATA_PATH.'cache_cate/cache_category'.$parent.'_'.$lang.'.php');
 161			}*/
 162
 163}
 164
 165function content_fields($id,$v_arr='',$edit='false'){
 166	if(file_exists(DATA_PATH."cache_channel/cache_fields.php")){
 167		include(DATA_PATH."cache_channel/cache_fields.php");
 168	}
 169	$str="";
 170	//取出频道下的字段
 171	if(!empty($field)){
 172		foreach($field as $key=>$value){
 173			if($value['is_disable']){continue;}
 174			$v=$value['field_value'];
 175			if(!empty($v_arr)){
 176				$v=isset($v_arr[$value['field_name']])?$v_arr[$value['field_name']]:'';
 177			}
 178			if($value['channel_id']==$id){
 179				if(!in_array($value['field_type'],array('checkbox','radio'))){
 180				$help=empty($value['info'])?"":"<span title=\"{$value['field_info']}\" class=\"help\">&nbsp;</span>";
 181				$field_box=($value['field_type']=='select')?$value['field_type']($value['field_name'],$value['field_value'],$v):$value['field_type']($value['field_name'],$v);
 182				$str.="<tr><td class=\"w1\" style=\"width:20%;text-align:center\">{$help}{$value['use_name']}:</td><td style=\"width:80%\">".$field_box."</td></tr>";
 183				}else{
 184				if($edit=='false'){$v='';}
 185				$str.="<tr><td class=\"w1\" style=\"width:20%\"><span title=\"{$value['field_info']}\" class=\"help\"></span>{$value['use_name']}:</td><td style=\"width:80%\">".$value['field_type']($value['field_name'],$value['field_value'],$v)."</td></tr>";
 186				}
 187			}
 188		}
 189	}
 190	return $str;
 191}
 192
 193
 194//表单
 195function form_fields($id,$path='',$edit='false'){
 196	if(file_exists(DATA_PATH."cache_form/field.php")){
 197		include(DATA_PATH."cache_form/field.php");
 198	}
 199	if(file_exists(DATA_PATH."cache_form/form.php")){
 200		include(DATA_PATH."cache_form/form.php");
 201	}
 202	if(!empty($form)){
 203	foreach($form as $k=>$v){
 204		if($v['id']==$id){
 205			if($v['is_disable']){return;}
 206		$form=$v;break;
 207		}
 208	}
 209	}
 210	global $content,$cat_id,$pr_id;
 211	$str='';
 212	$f_id=empty($content['id'])?$cat_id:$content['id'];
 213	unset($content);
 214	if(!empty($field)){
 215	//获取提交的页面
 216	if(!empty($pr_id)){
 217		$arc_rel=$GLOBALS['mysql']->fetch_asc("select title from ".DB_PRE."maintb where id=".$pr_id);
 218		$arc_title=$arc_rel[0]['title'];
 219	}
 220	if($arc_title){$f_id=$pr_id;}
 221	$js='';
 222	$opt='';
 223		foreach($field as $key=>$value){
 224			$v=$value['field_value'];
 225			if(!empty($v_arr)){
 226				$v=$v_arr[$value['field_name']];
 227			}
 228			
 229			if($value['form_id']==$id){
 230				$note='';
 231				if(!$value['is_empty']){
 232				if($value['field_type']=='text'||$value['field_type']=='textarea'){
 233					$note="<span style=\"color:red\">*</span>";
 234					$js.="if(document.getElementById('".$value['field_name']."').value==''){alert('".$value['use_name']."不能为空');return false;}";
 235				}
 236				}
 237				if(!in_array($value['field_type'],array('checkbox','radio'))){
 238				$help=empty($value['info'])?"":"<span title=\"{$value['field_info']}\" class=\"help\"></span>";
 239				$opt.="<tr><td class=\"w1\" style=\"width:30%\">{$help}{$value['use_name']}:</td><td style=\"width:70%\">".$value['field_type']($value['field_name'],$v,1)."{$note}</td></tr>";
 240				}else{
 241				if($edit=='false'){$v='';}
 242				$opt.="<tr><td class=\"w1\" style=\"width:30%\"><span title=\"{$value['field_info']}\" class=\"help\"></span>{$value['use_name']}:</td><td style=\"width:70%\">".$value['field_type']($value['field_name'],$value['field_value'],$v)."{$note}</td></tr>";
 243				}
 244			}
 245		}
 246	$str.="<script type=\"text/javascript\">function check_form(){";
 247	$str.=$js;
 248	$str.="}</script>";
 249	$str.="<form action=\"{$path}order/order_save.php\" class=\"order_form\" name=\"form_form\" method=\"post\" onsubmit=\"return check_form();\">";
 250	$str.="<input type=\"hidden\" name=\"form_id\" value=\"{$id}\"/>";
 251	$str.="<p>{$form['form_name']}</p>";
 252	$str.="<table width=\"100%\" border=\"0\" ceillpadding=\"0\" ceillspacing=\"0\">";
 253	if($arc_title){	
 254		$str.="<tr><td style=\"width:30%\" class=\"w1\">产品(职位):</td><td style=\"width:70%\">{$arc_title}</td></tr>";
 255	}
 256	$str.=$opt;	
 257	$str.="<tr><td style=\"width:30%\"></td><td style=\"width:70%\"><input type=\"hidden\" value=\"{$f_id}\" name=\"f_id\"/><input type=\"submit\" name=\"submit\" class=\"pt_go\" value=\"提交\"/><input type=\"reset\" name=\"reset\" class=\"pt_reset\" value=\"重置\"/></td></tr>";
 258	$str.="</table></form>";
 259	}
 260	return $str;
 261}
 262
 263function text($f_name,$f_value,$style=0){
 264	$s=($style)?'':"style=\"width:50%\"";
 265	$str="<input name=fields[{$f_name}] id=\"{$f_name}\" {$s} value=\"{$f_value}\" />";
 266	return $str;
 267}
 268function textarea($f_name,$f_value,$style=0){
 269	$s=($style)?'':"style=\"width:50%; height:50px;\"";
 270	$str="<textarea name=\"fields[{$f_name}]\" id=\"{$f_name}\" {$s}>{$f_value}</textarea>";
 271	return $str;
 272}
 273function html($f_name,$f_value){
 274
 275	$str=$GLOBALS['CKEditor']->editor("fields[".$f_name."]", $f_value,$GLOBALS['fck_config']);
 276	 return $str;
 277
 278}
 279//单图上传
 280function upload_pic($f_name,$f_value){
 281		$pic_str=empty($f_value)?'../upload/no_pc.gif':'../upload/'.$f_value;
 282		$str='<input name="fields['.$f_name.']" value="'.$f_value.'" style="width:30%; display:block; float:left; margin-top:55px;" id="'.$f_name.'" />
 283		  <p style="margin-top:55px;" class="admin_up_pic"><a href="admin_pic_upload.php?type=radio&get='.$f_name.'" id="pic_'.$f_name.'">上传图片</a></p><span id="show_'.$f_name.'" class="admin_show_pic"><img src="'.$pic_str.'"  height="120" width="120"/></span><script type="text/javascript">$(\'#pic_'.$f_name.'\').wBox({title:\'附件\',requestType: "iframe",target:$(\'#pic_'.$f_name.'\').attr(\'href\'),iframeWH:{width:800,height:400}});</script>';
 284	return $str;
 285}
 286//多图上传
 287function upload_pic_more($f_name,$f_value){
 288    $pic="";
 289	$str="";
 290	if(!empty($f_value)){$value=explode(',',$f_value);$n=count($value);}
 291	if(!empty($value)){
 292	$i=0;
 293	foreach($value as $k=>$v){
 294	if(empty($v)){continue;}
 295	if($n==$i){break;}
 296	$pic_rel=$GLOBALS['mysql']->fetch_asc("select * from ".DB_PRE."uppics where id=".$v);
 297	$pic_path=$pic_rel[0]['pic_path'].$pic_rel[0]['pic_name'].'.'.$pic_rel[0]['pic_ext'];
 298	$pic.="<li id=\"pic_{$pic_rel[0]['id']}\"><a href=\"../".$pic_path."\" target=\"_blank\"><img src=\"../".$pic_path."\" border=\"0\" height=\"120\" width=\"120\"/><input type=\"hidden\" name=\"fields[{$f_name}][]\" value=\"".$v."\"/></a><p><input type=\"text\" style=\"width:100px;\" name=\"alt\" id=\"alt\" value=\"".$pic_rel[0]['pic_alt']."\"/><img src=\"template/images/c_alt.gif\" style=\"border:0;cursor:point;\" onclick=\"change_alt(this,'".$v."')\" border=\"0\"/></p><span onclick=\"javascript:del_pic('".$v."',this);\">删除</span></li>";
 299	$i=$i+1;
 300	}
 301	}
 302	
 303		$str='<div class="lang_sl_btn"><a href="admin_pic_upload.php?type=checkbox&get='.$f_name.'&lang='.$GLOBALS['lang'].'&keepThis=true&TB_iframe=true&height=400&width=800" id="more_pic'.$f_name.'">选择或上传产品图片</a></div><script type="text/javascript">$(\'#more_pic'.$f_name.'\').wBox({title:\'缩略图\',requestType: "iframe",target:$(\'#more_pic'.$f_name.'\').attr(\'href\'),iframeWH:{width:800,height:400}});</script>';
 304		$str.="<ul class=\"m_show_pic\" id=\"show_pic".$f_name."\">{$pic}</ul>";
 305	return $str;
 306}
 307function upload_file($f_name,$f_value){
 308	$str="<input name=\"fields[{$f_name}]\" value=\"{$f_value}\" style=\"width:30%;margin-right:8px;\" id=\"{$f_name}\"/>";
 309		$str.='<span class="lang_sl_btn"><a id="upload_file_'.$f_name.'" href="admin_file_upload.php?get='.$f_name.'&lang='.$GLOBALS['lang'].'">选择或上传文件</a></span><script type="text/javascript">$(\'#upload_file_'.$f_name.'\').wBox({title:\'附件\',requestType: "iframe",target:$(\'#upload_file_'.$f_name.'\').attr(\'href\'),iframeWH:{width:800,height:400}});</script>';
 310	return $str;
 311}
 312function select($f_name,$f_value,$e_value=""){
 313	if(!empty($f_value)){
 314		$value=preg_split('/,/',$f_value);
 315	
 316	$str="<select id=\"{$f_name}\" name=\"fields[{$f_name}]\">";
 317	foreach($value as $key=>$val){
 318		$ck='';
 319		if($e_value==$val){$ck="selected=\"selected\"";}
 320		$str.="<option value=\"{$val}\" {$ck}>{$val}</option>";
 321	}
 322	$str.="</select>";
 323	}
 324	return $str;
 325}
 326function radio($f_name,$f_value,$e_value=""){
 327	$str='';
 328	if(!empty($f_value)){
 329		$value=preg_split('/,/',$f_value);
 330	foreach($value as $key=>$val){
 331		$ck="";
 332		if($key==0){$ck="checked=\"checked\"";}
 333		if($e_value==$val){$ck="checked=\"checked\"";}
 334		$str.="<input type=\"radio\" value=\"{$val}\" name=\"fields[{$f_name}]\" {$ck} style=\"margin:0 5px;border:0\"/>{$val}";
 335	}
 336	}
 337	return $str;
 338}
 339/*
 340*$f_name-字段名,$f_value-字段默认值,$e_value-字段填写值,修改的时候使用
 341*/
 342function checkbox($f_name,$f_value,$e_value=","){
 343	if(!empty($f_value)){
 344		$value=preg_split('/,/',$f_value);
 345		$e=preg_split('/,/',$e_value);
 346	foreach($value as $key=>$val){
 347		$ck="";
 348		if(in_array($val,$e)){$ck="checked=\"checked\"";}
 349		$str.="<input type=\"checkbox\" value=\"{$val}\" name=\"fields[{$f_name}][]\" {$ck} style=\"margin:0 5px;border:0\"/>{$val}";
 350	}
 351	}
 352	return $str;
 353}
 354//生成频道列表
 355function get_channel_list($id=''){
 356	$fl_path=DATA_PATH."cache_channel/cache_channel_all.php";
 357	$str="<select id=\"channel\" name=\"cate_channel\">";
 358	if(file_exists($fl_path)){
 359		include($fl_path);
 360		if(!empty($channel)){
 361		foreach($channel as $key=>$value){
 362			if($value['is_disable']){continue;}
 363			if(empty($id)){
 364			$ck=($value['channel_mark']=='article')?"selected=\"selected\"":"";
 365			}else{
 366			$ck=($value['id']==$id)?"selected=\"selected\"":"";
 367			}
 368			$str.="<option title=\"{$value['channel_mark']}\" value=\"{$value['id']}\" {$ck}>{$value['channel_name']}</option>";
 369		}
 370		}
 371	}
 372	$ck=($id=='-9')?"selected=\"selected\"":'';
 373	$str.="<option title=\"order\" value=\"-9\" {$ck}>表单模块</option>";
 374	$str.="</select>";
 375	return $str;
 376}
 377//生成栏目列表
 378function get_catelist($channel_id,$lang){
 379	$fl_path=DATA_PATH."cache_cate/cache_category".$channel_id."_".$lang.".php";
 380	$str="<select name=\"category\"><option value=\"\">请选择栏目</option>";
 381	if(file_exists($fl_path)){
 382		include($fl_path);
 383		if(!empty($fl_path)){
 384		foreach($category as $key=>$value){
 385			if($value['cate_tpl']==2){
 386				continue;
 387			}
 388			if($value['cate_tpl']==1){
 389				$str.="<option value=\"index\">{$value['cate_name']}(频道页,不可发布内容)</option>";
 390			}
 391			$str.="<option value=\"{$value['id']}\">{$value['cate_name']}</option>";
 392		}
 393		}
 394	}
 395	$str.="</select>";
 396	return $str;
 397}
 398
 399//缓存频道栏目
 400function cache_channel_category($lang){
 401	$fl_path=DATA_PATH."cache_channel/cache_channel_".$lang.".php";
 402	if(file_exists($fl_path)){
 403	include($fl_path);
 404	if(!empty($channel)){
 405		foreach($channel as $key=>$value){
 406			$GLOBALS['cache']->cache_channel_cate($value['id']);
 407		}
 408	}
 409	}
 410}
 411
 412//发布内容栏目列表
 413function get_post_catelist($lang,$channel,$cate_id=''){
 414	$file=DATA_PATH."cache_cate/cate_list_".$lang.".php";
 415	if(file_exists($file)){
 416		include($file);
 417	}
 418	//过滤频道下顶级栏目
 419	if(!empty($cate_list)){
 420		foreach($cate_list as $k=>$v){
 421			//if($v['cate_channel']==$channel){
 422				$cate[]=$v;
 423			//}
 424		}
 425	}
 426	
 427	//取出栏目
 428	if(!empty($cate)){
 429		foreach($cate as $k=>$v){
 430		if($v['cate_tpl']=='2'){continue;}
 431		//if(in_array($v['cate_name'],$filt)){continue;}
 432		
 433		if($v['cate_parent']==0){
 434		$ck=($cate_id==$v['id'])?"selected=\"selected\"":"";
 435		if($v['cate_channel']==$channel){
 436			echo "<option ";
 437			if($v['cate_tpl']==1){
 438				echo "value=\"index\">{$v['cate_name']}(不能发布内容)";
 439			}elseif($v['cate_hide']){
 440				echo "value=\"{$v['id']}\" {$ck}>{$v['cate_name']}(隐藏栏目不会显示)";
 441			}else{
 442				echo "value=\"{$v['id']}\" {$ck}>{$v['cate_name']}";
 443				echo "</option>";
 444			}
 445		}	
 446			//unset($cate[$k]);
 447			get_post_catechild($cate,$v['haschild'],$v['id'],$level=0,$cate_id,$channel);
 448		}
 449		}
 450		//return $str;
 451	}
 452	
 453}
 454
 455//发布栏目子栏目
 456function get_post_catechild($cate,$has_child,$parent,$level,$cate_id,$channel){
 457	if($has_child){
 458	$level=$level+1;
 459		if(!empty($cate)){
 460			foreach($cate as $k=>$v){
 461			if($v['cate_tpl']=='2'){continue;}
 462			$level_str=post_level($level);
 463			$cate_name=$level_str.$v['cate_name'];
 464			if($v['cate_parent']==$parent){
 465			$ck=($cate_id==$v['id'])?"selected=\"selected\"":"";
 466				if($v['cate_channel']==$channel){
 467				echo"<option ";
 468				
 469				if($v['cate_tpl']==1){
 470					echo "value=\"index\">{$cate_name}(频道栏目,不能发布内容)";
 471				}elseif($v['cate_hide']){
 472					echo "value=\"{$v['id']}\" {$ck}>{$cate_name}(隐藏栏目不会显示)";
 473				}else{
 474					echo "value=\"{$v['id']}\" {$ck}>{$cate_name}";	
 475				}
 476				echo "</option>";
 477				}
 478				//unset($GLOBALS['cate'][$k]);
 479				get_post_catechild($cate,$v['haschild'],$v['id'],$level,$cate_id,$channel);
 480			}
 481			}
 482		}
 483		
 484	}
 485
 486}
 487
 488function post_level($level){
 489	$str="——";
 490	for($i=0;$i<$level;$i++){
 491		$str.="——";
 492	}
 493	//$str=$str.'——';
 494	return $str;
 495}
 496
 497function show_child_catelist($parent,$space,$channel,$cate_id){
 498	$fl_path=DATA_PATH."cache_cate/cache_category".$parent."_cn.php";
 499	if(file_exists($fl_path)){
 500		include($fl_path);
 501		if(!empty($category)){
 502		foreach($category as $ke=>$value){
 503			if($value['cate_channel']==$channel){
 504				if($value['cate_tpl']==1){
 505					$str.="<option value=\"index\">{$space}{$value['cate_name']}(频道栏目,不能发布内容)</option>";
 506				}elseif($value['cate_tpl']==0){
 507				if($cate_id==$value['id']){$ck="selected=\"selected\"";}
 508					$str.="<option value=\"{$value['id']}\" {$ck}>{$space}{$value['cate_name']}</option>";
 509				}else{
 510					continue;
 511				}
 512			$str.=show_child_catelist($value['id'],"&nbsp;".$space,$channel);
 513			}
 514		}
 515		}
 516	}
 517	return $str;
 518}
 519
 520function show_catelist($channel,$cate_id=''){
 521	$fl_path=DATA_PATH."cache_cate/cache_channel".$channel."_cate.php";
 522	if(file_exists($fl_path)){
 523		include($fl_path);
 524		if(!empty($channel_cate)){
 525		foreach($channel_cate as $key=>$value){
 526		$arr[]=$value['id'];
 527		if(in_array($value['cate_parent'],$arr)){continue;}
 528		
 529			if($value['cate_tpl']==1){
 530				$str.="<option value=\"index\">{$value['cate_name']}(频道栏目,不能发布内容)</option>";
 531			}elseif($value['cate_tpl']==0){
 532				if($cate_id==$value['id']){$ck="selected=\"selected\"";}
 533				$str.="<option value=\"{$value['id']}\" {$ck}>{$value['cate_name']}</option>";
 534			}else{
 535				continue;
 536			}
 537			$space="└─";
 538			$str.=show_child_catelist($value['id'],"&nbsp;".$space,$channel,$cate_id);
 539		}
 540		}
 541	}
 542	return $str;
 543}
 544
 545/*
 546*上传图片
 547*$url=远程图片,$file-上传文件,$size-允许大小,$type-上传文件类型,$thumb-缩略图,$thumb_width-缩略图宽度,$mark-水印,$mark_type-水印类型,$mark_file-水印图片或文字,$mark_width-水印宽度,$mark_height-水印高度
 548*return $arr-原始图和缩略图
 549*/
 550function up_img($file,$size,$type,$thumb=0,$thumb_width='',$thumb_height='',$logo=1){
 551		if(file_exists(DATA_PATH.'sys_info.php')){include(DATA_PATH.'sys_info.php');}
 552		if(is_uploaded_file($file['tmp_name'])){
 553		if($file['size']>$size){
 554			msg('图片超过'.$size.'大小');
 555		}
 556		$pic_name=pathinfo($file['name']);//图片信息
 557		$file_type=$file['type'];
 558		if(!in_array(strtolower($file_type),$type)){
 559			msg('上传图片格式不正确');
 560		}
 561		$path_name="upload/img/".date('Ymd').'/';
 562		$path=CMS_PATH.$path_name;
 563		if(!file_exists($path)){
 564			mkdir($path);
 565		}
 566		$up_file_name=date('YmdHis').rand(1,10000);
 567		$file_name=$path.$up_file_name.'.'.$pic_name['extension'];
 568		$return_name['up_pic_size']=$file['size'];//上传图片大小
 569		$return_name['up_pic_ext']=$pic_name['extension'];//上传文件扩展名
 570		$return_name['up_pic_name']=$up_file_name;//上传图片名
 571		$return_name['up_pic_path']=$path_name;//上传图片路径
 572		$return_name['up_pic_time']=time();//上传时间
 573		unset($pic_name);
 574		//开始上传
 575		if(!move_uploaded_file($file['tmp_name'],$file_name)){
 576			msg('图片上传失败','',0);
 577		}
 578		$file_info=getimagesize($file_name);
 579			switch($file_info[2]){
 580 			case 1:
 581 			$php_file=imagecreatefromgif($file_name);
 582 			break;
 583 			case 2:
 584 			$php_file=imagecreatefromjpeg($file_name);
 585 			break;
 586 			case 3:
 587 			$php_file=imagecreatefrompng($file_name);
 588 			break;
 589 			}
 590	    //生成水印
 591		if($_sys['image_is'][0]&&$logo){		
 592			//文字
 593			if(!$_sys['image_type'][0]){
 594				$mark_img=$php_file;
 595				$t_color=empty($_sys['image_text_color'])?array("255","255","255"):explode(',',$_sys['image_text_color']);
 596				$text_color=imagecolorallocate($php_file,$t_color[0],$t_color[1],$t_color[2]);
 597				$text_content=iconv("UTF-8","UTF-8",empty($_sys['image_text'])?'BEESCMS':$_sys['image_text']);
 598				$text_size=empty($_sys['image_text_size'])?"12":$_sys['image_text_size'];
 599				$font=DATA_PATH."font/arial.ttf";
 600				$text_arr=@imagettfbbox($text_size,0,$font,$text_content);
 601        		$text_width=max($text_arr[2],$text_arr[4])-min($text_arr[0],$text_arr[6]);
 602       		 	$text_height=max($text_arr[1],$text_arr[3])-min($text_arr[5],$text_arr[7]);
 603				switch($_sys['image_position'][0]){
 604				case '1':
 605				$position=array("5","5");
 606				break;
 607				case '2':
 608				$position=array(($file_info[0]-$text_width)/2,"5");
 609				break;
 610				case '3':
 611				$position=array($file_info[0]-$text_width-5,"5");
 612				break;
 613				case '4':
 614				$position=array("5",($file_info[1]-$text_height)/2);
 615				break;
 616				case '5':
 617				$position=array(($file_info[0]-$text_width)/2,($file_info[1]-$text_height)/2);
 618				break;
 619				case 6:
 620				$position=array($file_info[0]-$text_width-5,($file_info[1]-$text_height)/2);
 621				break;
 622				case 7:
 623				$position=array("3",$file_info[1]-$text_height-5);
 624				break;
 625				case 8:
 626				$position=array(($file_info[0]-$text_width)/2,$file_info[1]-$text_height-5);
 627				break;
 628				case 9:
 629				$position=array($file_info[0]-$text_width-10,$file_info[1]-$text_height-10);
 630				break;
 631				}
 632				imagettftext($mark_img,$text_size,0,($position[0]+$text_size),($position[1]+$text_size),$text_color,$font,$text_content);
 633				switch($file_info[2]){
 634				case 1:
 635				imagegif($mark_img,$file_name);
 636				break;
 637				case 2:
 638				imagejpeg($mark_img,$file_name);
 639				break;
 640				case 3:
 641				imagepng($mark_img,$file_name);
 642				break;
 643				}
 644			}
 645			//图片
 646			if($_sys['image_type'][0]){
 647				$logo=CMS_PATH.'upload/'.$_sys['pic'];
 648				$logo_info=getimagesize($logo);
 649				switch($logo_info[2]){
 650 				case 1:
 651 				$logo_file=imagecreatefromgif($logo);
 652 				break;
 653 				case 2:
 654 				$logo_file=imagecreatefromjpeg($logo);
 655 				break;
 656 				case 3:
 657 				$logo_file=imagecreatefrompng($logo);
 658 				break;
 659 				}
 660				switch($_sys['image_position'][0]){
 661				case '1':
 662				$position=array("5","5");
 663				break;
 664				case '2':
 665				$position=array(($file_info[0]-$logo_info[0])/2,"5");
 666				break;
 667				case '3':
 668				$position=array($file_info[0]-$logo_info[0]-5,"5");
 669				break;
 670				case '4':
 671				$position=array("5",($file_info[1]-$logo_info[1])/2);
 672				break;
 673				case '5':
 674				$position=array(($file_info[0]-$logo_info[0])/2,($file_info[1]-$logo_info[1])/2);
 675				break;
 676				case 6:
 677				$position=array($file_info[0]-$logo_info[0]-5,($file_info[1]-$logo_info[1])/2);
 678				break;
 679				case 7:
 680				$position=array("3",$file_info[1]-$logo_info[1]-5);
 681				break;
 682				case 8:
 683				$position=array(($file_info[0]-$logo_info[0])/2,$file_info[1]-$logo_info[1]-5);
 684				break;
 685				case 9:
 686				$position=array($file_info[0]-$logo_info[0]-10,$file_info[1]-$logo_info[1]-10);
 687				break;
 688				}
 689				$logo_img=$php_file;
 690				imagecopy($logo_img,$logo_file,$position[0],$position[1],0,0,$logo_info[0],$logo_info[1]);
 691				switch($file_info[2]){
 692				case 1:
 693				imagegif($logo_img,$file_name);
 694				break;
 695				case 2:
 696				imagejpeg($logo_img,$file_name);
 697				break;
 698				case 3:
 699				imagepng($logo_img,$file_name);
 700				break;
 701				}
 702				
 703			}
 704		}
 705		//生成缩略图
 706		if($thumb){
 707			$new_img=imagecreatetruecolor($thumb_width,$thumb_height);
 708			$src_img=$php_file;
 709			imagecopyresized($new_img,$src_img,0,0,0,0,$thumb_width,$thumb_height,$file_info[0],$file_info[1]);
 710			switch($file_info[2]){
 711			case 1:
 712			imagegif($new_img,$path.$up_file_name.'_thumb.gif');
 713			$return_name['thumb']=str_replace(CMS_PATH."upload/","",$path.$up_file_name.'_thumb.gif');
 714			break;
 715			case 2:
 716			imagejpeg($new_img,$path.$up_file_name.'_thumb.jpeg');
 717			$return_name['thumb']=str_replace(CMS_PATH."upload/","",$path.$up_file_name.'_thumb.jpeg');
 718			break;
 719			case 3:
 720			imagepng($new_img,$path.$up_file_name.'_thumb.png');
 721			$return_name['thumb']=str_replace(CMS_PATH."upload/","",$path.$up_file_name.'_thumb.png');
 722			break;
 723			}
 724		}
 725		$return_name['pic']=str_replace(CMS_PATH."upload/","",$file_name);
 726		
 727		}
 728	return $return_name;
 729}
 730
 731function up_file($file,$size,$type,$path='',$name=''){
 732		$return_arr=array();
 733		if(is_uploaded_file($file['tmp_name'])){
 734		if($file['size']>$size){msg('文件超过'.$size.'大小');}
 735		$pic_name=pathinfo($file['name']);
 736		$file_type=$pic_name['extension'];
 737		$return_arr['ext'] = $pic_name['extension'];//扩展名
 738		$return_arr['size'] = $file['size'];//大小
 739		if(!in_array($file_type,$type)){msg('上传文件格式不正确'.$file_type);}
 740		$path=empty($path)?CMS_PATH."upload/file/".date('Ymd').'/':CMS_PATH.$path.'/';
 741		if(!file_exists($path)){
 742			@mkdir($path);
 743		}
 744		$name=empty($name)?date('YmdHis'):$name;
 745		$file_name=$path.$name.'.'.$pic_name['extension'];
 746		unset($pic_name);
 747		if(!move_uploaded_file($file['tmp_name'],$file_name)){
 748			msg('文件上传失败');
 749		}
 750		$return_name=str_replace(CMS_PATH,"",$file_name);
 751		//$return_name=CMS_SELF.$return_name;
 752		$return_arr['file'] = $return_name;//上传文件路径
 753		$return_arr['time'] = time();//上传时间
 754		}else{
 755			msg('文件不能为空');
 756		}
 757		//存储相关信息
 758		
 759	return $return_arr;
 760}
 761
 762//缩略图
 763function pic_thumb($file_name,$thumb_width,$thumb_height,$path=''){
 764if(empty($file_name)&&empty($thumb_width)&&$thumb_height){return;}
 765if(empty($thumb_width)||empty($thumb_height)){return;}
 766$new_img=imagecreatetruecolor($thumb_width,$thumb_height);
 767			$file_info=getimagesize($file_name);
 768			switch($file_info[2]){
 769 			case 1:
 770 			$php_file=imagecreatefromgif($file_name);
 771 			break;
 772 			case 2:
 773 			$php_file=imagecreatefromjpeg($file_name);
 774 			break;
 775 			case 3:
 776 			$php_file=imagecreatefrompng($file_name);
 777 			break;
 778			case 15:
 779			$php_file=imagecreatefromwbmp($file_name);
 780			break;
 781			default:
 782			return;
 783 			}
 784			$src_img=$php_file;
 785			imagecopyresized($new_img,$src_img,0,0,0,0,$thumb_width,$thumb_height,$file_info[0],$file_info[1]);
 786			$th_path=$path.date('YmdHis');
 787			switch($file_info[2]){
 788			case 1:
 789			$thumb=$th_path.'_thumb.gif';
 790			imagegif($new_img,$thumb);
 791			return $thumb=str_replace("../upload/","",$thumb);
 792			break;
 793			case 2:
 794			$thumb=$th_path.'_thumb.jpeg';
 795			imagejpeg($new_img,$thumb);
 796			return $thumb=str_replace("../upload/","",$thumb);
 797			break;
 798			case 3:
 799			$thumb=$th_path.'_thumb.png';
 800			imagepng($new_img,$thumb);
 801			return $thumb=str_replace("../upload/","",$thumb);
 802			break;
 803			case 15:
 804			$thumb=$th_path.'_thumb.png';
 805			imagewbmp($new_img,$thumb);
 806			return $thumb=str_replace("../upload/","",$thumb);
 807			break;
 808			}
 809}
 810
 811
 812function get_cate($id){
 813	$rel="<span style=\"color:red\">未知错误,栏目已经被删除</span>";
 814	if($GLOBALS['mysql']->fetch_rows("select id from ".DB_PRE."category where id=".$id)){
 815	$rel=$GLOBALS['mysql']->get_row("select cate_name from ".DB_PRE."category where id=".$id);
 816	}
 817	return $rel;
 818}
 819
 820//列表页分页函数
 821function page($url='',$page,$query='',$totalnum,$totalpages,$cate_id='',$ishtml=0){
 822	global $language,$_confing;
 823	$str="";
 824	$op="";
 825	$pre_page=($page-1<0)?1:($page-1);
 826	$next_page=($page+1>$totalpages)?$totalpages:($page+1);
 827	$page_count=7;
 828    $offset = 3;//页码个数左右偏移量
 829	if($_confing['web_html'][0]&&!$ishtml){
 830		//静态分页
 831		if(file_exists(DATA_PATH.'cache_cate/cache_category_all.php')){include(DATA_PATH.'cache_cate/cache_category_all.php');}
 832		$cate_info=get_cate_info($cate_id,$category);
 833		
 834		$str.=($page>1)?'<a href="'.CMS_URL.'htm/'.$cate_info['cate_fold_name'].'/index.html">'.$language['pagehome'].'</a>':'<span class="off">'.$language['pagehome'].'</span>';
 835		if($page>1){
 836			
 837			if(($page-1)==1){
 838				$str.='<a class="p" href="'.CMS_URL.'htm/'.$cate_info['cate_fold_name'].'/index.html">'.$language['pagapre'].'</a>';
 839			}else{
 840				$str.='<a class="p" href="'.CMS_URL.'htm/'.$cate_info['cate_fold_name'].'/list_'.$pre_page.'.html">'.$language['pagapre'].'</a>';
 841			}
 842		}else{
 843			$str.='<span class="off">'.$language['pagapre'].'</span>';
 844		}
 845		
 846		
 847		if($totalpages>$page_count){
 848			if($page<=$offset){
 849				$page_star=1;
 850				$page_end=$page_count;
 851			}else{
 852				if($page+$offset>=$totalpages+1){
 853					$page_star=$totalpages-$page_count+1;
 854					$page_end=$totalpages;
 855				}else{
 856					$page_star=$page-$offset;
 857					$page_end=$page+$offset;
 858				}
 859			}
 860		}else{
 861			$page_star=1;
 862			$page_end=$totalpages;
 863		}
 864		
 865		for($i=$page_star;$i<=$page_end;$i++){
 866			$class=($page==$i)?"focus":"";
 867			if($i==$page_star&&$i!=1){$str.='...';}
 868			if($i==1){
 869				$str.='<a class="'.$class.'" href="'.CMS_URL.'htm/'.$cate_info['cate_fold_name'].'/index.html">1</a>';
 870			}else{
 871				$str.='<a class="'.$class.'" href="'.CMS_URL.'htm/'.$cate_info['cate_fold_name'].'/list_'.$i.'.html">'.$i.'</a>';
 872			}
 873			if($i==$page_end&&$i!=$totalpages){$str.='...';}
 874		}
 875		
 876		for($i=1;$i<=$totalpages;$i++){
 877			$op.=($i==1)?"<option value=\"index.html\" {$sel}>{$i}</option>":"<option value=\"list_{$i}.html\" {$sel}>{$i}</option>";
 878		}
 879		
 880		if($page<$totalpages){
 881			$str.='<a class="p" href="'.CMS_URL.'htm/'.$cate_info['cate_fold_name'].'/list_'.$next_page.'.html">'.$language['pagenext'].'</a>';
 882		}else{
 883			$str.='<span class="off">'.$language['pagenext'].'</span>';
 884		}
 885		$str.=($page<$totalpages)?'<a href="'.CMS_URL.'htm/'.$cate_info['cate_fold_name'].'/list_'.$totalpages.'.html">'.$language['pageend'].'</a>':'<span class="off">'.$language['pageend'].'</span>';
 886		$str.="<span>{$language['pagego']}<select style=\"width:40px;\" onchange=\"location.href=this.options[this.selectedIndex].value;\">".$op."</select></span>";
 887		$str.="<span>{$language['pages']}{$totalnum}{$language['pagesize']},{$language['page']}{$page}/{$totalpages}</span>";
 888	}else{
 889	
 890		//动态分页
 891		$str.=($page>1)?'<a class="p" href="'.$url.'?page=1'.$query.'">'.$language['pagehome'].'</a>':'<span class="off">'.$language['pagehome'].'</span>';
 892		$str.=($page>1)?'<a class="p" href="'.$url.'?page='.$pre_page.$query.'">'.$language['pagapre'].'</a>':'<span class="off">'.$language['pagapre'].'</span>';
 893		
 894		if($totalpages>$page_count){
 895			if($page<=$offset){
 896				$page_star=1;
 897				$page_end=$page_count;
 898			}else{
 899				if($page+$offset>=$totalpages+1){
 900					$page_star=$totalpages-$page_count+1;
 901					$page_end=$totalpages;
 902				}else{
 903					$page_star=$page-$offset;
 904					$page_end=$page+$offset;
 905				}
 906			}
 907		}else{
 908			$page_star=1;
 909			$page_end=$totalpages;
 910		}
 911			
 912		
 913		for($i=$page_star;$i<=$page_end;$i++){
 914			$class=($page==$i)?"focus":"";
 915			if($i==$page_star&&$i!=1){$str.='...';}
 916			$str.='<a class="'.$class.'" href="'.$url.'?page='.$i.$query.'">'.$i.'</a>';
 917			if($i==$page_end&&$i!=$totalpages){$str.='...';}
 918		}
 919		
 920		for($i=1;$i<=$totalpages;$i++){
 921			$op.="<option value=\"?page={$i}{$query}\" {$sel}>{$i}</option>";
 922		}
 923		
 924		$str.=($page<$totalpages)?'<a class="p" href="'.$url.'?page='.$next_page.$query.'">'.$language['pagenext'].'</a>':'<span class="off">'.$language['pagenext'].'</span>';
 925		$str.=($page<$totalpages)?'<a class="p" href="'.$url.'?page='.$totalpages.$query.'">'.$language['pageend'].'</a>':'<span class="off">'.$language['pageend'].'</span>';
 926		$str.="<span>{$language['pagego']}<select style=\"width:40px;\" onchange=\"location.href=this.options[this.selectedIndex].value;\">".$op."</select></span>";
 927		$str.="<span>{$language['pages']}{$totalnum}{$language['pagesize']},{$language['page']}{$page}/{$totalpages}</span>";
 928	}
 929	return $str;
 930}
 931
 932function check_login($user,$password){
 933	$rel=$GLOBALS['mysql']->fetch_asc("select id,admin_name,admin_password,admin_purview,is_disable from ".DB_PRE."admin where admin_name='".$user."' limit 0,1");	
 934	$rel=empty($rel)?'':$rel[0];
 935	if(empty($rel)){
 936		msg('不存在该管理用户','login.php');
 937	}
 938	$password=md5($password);
 939	if($password!=$rel['admin_password']){
 940		msg("输入的密码不正确");
 941	}
 942	if($rel['is_disable']){
 943		msg('该账号已经被锁定,无法登陆');
 944	}
 945	
 946	$_SESSION['admin']=$rel['admin_name'];
 947	$_SESSION['admin_purview']=$rel['admin_purview'];
 948	$_SESSION['admin_id']=$rel['id'];
 949	$_SESSION['admin_time']=time();
 950	$_SESSION['login_in']=1;
 951	$_SESSION['login_time']=time();
 952	$ip=fl_value(get_ip());
 953	$ip=fl_html($ip);
 954	$_SESSION['admin_ip']=$ip;
 955	unset($rel);
 956	header("location:admin.php");
 957}
 958
 959function is_login(){
 960	if($_SESSION['login_in']==1&&$_SESSION['admin']){
 961		if(time()-$_SESSION['login_time']>3600){
 962			login_out();
 963		}else{
 964			$_SESSION['login_time']=time();
 965			@session_regenerate_id();
 966		}
 967		return 1;
 968	}else{
 969		$_SESSION['admin']='';
 970		$_SESSION['admin_purview']='';
 971		$_SESSION['admin_id']='';
 972		$_SESSION['admin_time']='';
 973		$_SESSION['login_in']='';
 974		$_SESSION['login_time']='';
 975		$_SESSION['admin_ip']='';
 976		return 0;
 977	}
 978
 979}
 980
 981function login_out(){
 982	$_SESSION['admin']='';
 983	$_SESSION['login_in']=0;
 984	$_SESSION['purview']='';
 985	if(!empty($_SESSION['admin_ip'])&&!empty($_SESSION['admin_time'])&&!empty($_SESSION['admin_id'])){
 986	$GLOBALS['mysql']->query("update ".DB_PRE."admin set admin_ip='".$_SESSION['admin_ip']."',admin_time='".$_SESSION['admin_time']."' where id=".$_SESSION['admin_id']);
 987	}
 988	$_SESSION['login_time']='';
 989	$_SESSION['admin_time']='';
 990	$_SESSION['admin_ip']='';
 991	$_SESSION['admin_id']='';
 992	msg('已经退出','login.php');
 993}
 994function get_ip(){
 995if(!empty($_SERVER['HTTP_CLIENT_IP']))
 996	{
 997		return $_SERVER['HTTP_CLIENT_IP'];
 998	}
 999	elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
1000	{
1001		return $_SERVER['HTTP_X_FORWARDED_FOR'];
1002	}
1003	else
1004	{
1005		return $_SERVER['REMOTE_ADDR'];
1006	}
1007}
1008//检查权限
1009//$ck_purview-允许的权限
1010function check_purview($ck_purview){
1011	$admin_purview=admin_purview();
1012	if(!$admin_purview||$admin_purview=='all_purview'){
1013		return true;
1014	}
1015	elseif(check_str($admin_purview,'/'.$ck_purview.'/')){
1016		return true;
1017	}elseif($admin_purview=='is_disable'){
1018	   msg('所在的分组已经锁定');
1019	}else{
1020		return false;
1021	}
1022}
1023//取得登陆管理员的权限
1024function admin_purview(){
1025	global $admin_group;
1026	$admin=$_SESSION['admin_purview'];
1027	if(!empty($admin_group)){
1028	foreach($admin_group as $k=>$v){
1029	    $rel=0;
1030		if($v['id']==$admin&&$v['is_disable']==0){
1031			$rel=$v['admin_group_purview'];
1032			break;
1033		}	
1034	}
1035	}
1036	return $rel;
1037}
1038
1039function paser_template($str,$id='',$page='',$size='',$total_page=''){
1040	$str=commen_tag($str);
1041	$str=arclist_tag($str);
1042	$str=list_tag($str,$id,$page,$size);
1043	$str=pages_tag($str,$total_page);
1044	return $str;
1045}
1046//配置标签
1047function commen_tag($str){
1048	if(file_exists(DATA_PATH.'cn_inc.php')){
1049		include(DATA_PATH.'cn_inc.php');
1050	}
1051	preg_match_all('/{common(.*)\/}/',$str,$p_arr);
1052	$search[]='';
1053	$replace[]='';
1054	foreach($p_arr[0] as $k=>$v){
1055		$search[]=$v;
1056		$v=str_replace("'",'',$v);
1057		$v=str_replace('"','',$v);
1058		preg_match_all('/name=(.*)\/}/',$v,$val);
1059		$val_str=$val[1][0];
1060		$replace[]=$_confing[$val[1][0]];
1061	}
1062	$str=str_replace($search,$replace,$str);
1063	return $str;
1064}
1065//列表标签
1066function arclist_tag($str){
1067	preg_match_all('/{catelist(.*){\/catelist}/isU',$str,$p_arr);
1068	foreach($p_arr[0] as $k=>$v){
1069	$list='';
1070	$search='';
1071		$search[]=$v;
1072		preg_match('/{catelist(.*)}(.*){\/catelist}/isU',$v,$p_attr);
1073		$attr=explode(' ',$p_attr[1]);
1074		foreach($attr as $key=>$value){
1075			$attr_v=explode('=',$value);
1076			global $$attr_v[0];
1077			$$attr_v[0]='';
1078			$$attr_v[0]=$attr_v[1];
1079		}
1080		preg_match_all('/{(.*)\/}/isU',$p_attr[2],$list_attr);
1081		$list_attr=$list_attr[1];
1082		$rel_arr=article();//读取数
1083		for($i=0;$i<count($rel_arr);$i++){
1084		$search_rel='';
1085		$replace_rel='';
1086		foreach($rel_arr[$i] as $a=>$b){
1087				if(in_array($a,$list_attr)){
1088					$search_rel[]='{'.$a.'/}';
1089					$replace_rel[]=$b;
1090				}
1091				$search_rel['url']='{url/}';
1092			    $replace_rel['url']='show.php?id='.$rel_arr[$i]['id'];
1093		}
1094			
1095			$list.=str_replace($search_rel,$replace_rel,$p_attr[2]);
1096			
1097		}
1098		
1099		$str=str_replace($search,$list,$str);
1100	}
1101	return $str;
1102}
1103
1104
1105//列表数据
1106function list_tag($str,$id,$p,$row){
1107	preg_match_all('/{list(.*){\/list}/isU',$str,$p_arr);
1108	foreach($p_arr[0] as $k=>$v){
1109		$search='';
1110		$search[]=$v;
1111		
1112		preg_match('/{list(.*)}(.*){\/list}/isU',$v,$p_attr);
1113		
1114		
1115		preg_match_all('/{(.*)\/}/isU',$p_attr[2],$list_attr);
1116		$list_attr=$list_attr[1];
1117		$rel_arr=pagelist($id,$p,$row);
1118		for($i=0;$i<count($rel_arr);$i++){
1119		$search_rel='';
1120		$replace_rel='';
1121		foreach($rel_arr[$i] as $a=>$b){
1122				if(in_array($a,$list_attr)){
1123					$search_rel[]='{'.$a.'/}';
1124					$replace_rel[]=$b;
1125				}
1126				$search_rel['url']='{url/}';
1127			    $replace_rel['url']='show.php?id='.$rel_arr[$i]['id'];
1128		}
1129			
1130			$list.=str_replace($search_rel,$replace_rel,$p_attr[2]);
1131			
1132		}
1133		$str=str_replace($search,$list,$str);
1134		//$page_no=pages_tag($total_page);
1135		//$str=str_replace('{page/}',$page_no,$str);
1136	}
1137	
1138	
1139	return $str;
1140}
1141
1142function pages_tag($str,$total_page){
1143	for($n=0;$n<$total_page;$n++){
1144		if($n==0){
1145			$page_str.='<a href="index.html">1</a>';
1146		}else{
1147			$page_str.="<a href='list_".$n.".html'>".($n+1)."</a>";
1148		}
1149		$str_page="<a href='index.html'>首页</a>".$page_str."<a href='list_".($total_page-1).".html'>尾页</a>";
1150	}
1151	return $str=str_replace('{page/}',$str_page,$str);
1152}
1153
1154function create_folder($folder){
1155	if(!file_exists($folder)){
1156		create_folder(dirname($folder));
1157		mkdir($folder,0777);
1158	}
1159}
1160
1161//生成静态页面
1162function creat_html($htm_file,$err=''){
1163	$htm_data=ob_get_contents();
1164	ob_clean();
1165	$fp=fopen($htm_file,'w');
1166	flock($fp,LOCK_EX);
1167	if(!fwrite($fp,$htm_data)){
1168		echo $err;
1169	}
1170	flock($fp,LOCK_UN);
1171	fclose($fp);
1172}
1173
1174//生成静态页面2.0
1175function creat_html_file($htm_file,$data=''){
1176	$fp=fopen($htm_file,'w');
1177	flock($fp,LOCK_EX);
1178	if(!fwrite($fp,$data)){
1179		echo $err;
1180	}
1181	flock($fp,LOCK_UN);
1182	fclose($fp);
1183}
1184
1185function tpl_display($tpl){
1186	return $GLOBALS['tpl']->display($tpl);
1187}
1188
1189//取得栏目信息
1190function get_cate_info($cate,$category){
1191	if(!empty($category)){
1192	foreach($category as $k=>$v){
1193		if($v['id']==$cate){
1194			$rel= $v;
1195			break;
1196		}
1197	}
1198	}
1199	return empty($rel)?false:$rel;
1200}
1201//栏目缩进
1202function get_kong($n){
1203	for($i=1;$i<=$n;$i++){
1204		$str.="&nbsp;";
1205	}
1206	return $str;
1207}
1208//栏目列表下级栏目
1209function get_cate_list($cate,$parent,$haschild,$level=0){
1210		if($haschild){
1211		$level=$level+1;
1212			foreach($cate as $k=>$v){
1213				if($parent==$v['cate_parent']){
1214				$channel_info=get_cate_info($v['cate_channel'],$GLOBALS['channel']);//获得内容模型信息
1215				$list_php = empty($channel_info['list_php'])?'show_list.php':$channel_info['list_php'];
1216				$list_php = ($v['cate_channel']=='-9')?'order/order.php':$list_php;
1217				if($v['cate_channel']==1){
1218					$is_cate_type = '[<font style="color:red">单页</font>]';
1219				}elseif($v['cate_channel']=='-9'){
1220					$is_cate_type = '[<font style="color:#0000FF">表单</font>]';
1221				}
1222				//$kong=get_kong($level);
1223				$pd=$level*10;
1224				$is_gd=($v['cate_tpl']==1)?'&nbsp;<span style="color:red">引导栏目</span>':'';
1225				echo "<div id=\"catagory\" style=\"display:none\">";
1226				echo "<div id=\"border\" style=\"border-bottom:1px dashed #ccc; padding:2px 0;height:25px; line-height:25px;\"><div class=\"left\" id=\"show\" style=\"padding-left:".$pd."px; cursor:pointer\"><span class=\"exp\" onclick=\"show_list(this);\">&nbsp;</span><span class=\"cata\"><a href=\"".CMS_SELF.$list_php."?id={$v['id']}\" target=\"_blank\">".$is_cate_type.$v['cate_name']."</a>(<span style=\"color:#999\">排序</span><em rel=\"order\" style=\"font-style:normal; padding:0 8px;\" id=\"order_num\"><span id=\"".$v['id']."\">".$v['cate_order']."</span></em>&nbsp;<span style=\"color:#999\">栏目id</span>:".$v['id']."&nbsp;<span style=\"color:#999\">模板标示ID:</span><em rel=\"tpl\" style=\"font-style:normal; padding:0 8px;\" id=\"order_num\"><span id=\"".$v['id']."\">".$v['temp_id']."</span></em>".$is_gd.")";
1227				$cate_nav=empty($v['cate_nav'])?array(''):explode(',',$v['cate_nav']);
1228				echo in_array('2',$cate_nav)?"<span style=\"color:#3366FF\">导航中部显示</span>":"";
1229				echo in_array('3',$cate_nav)?"<span style=\"color:#FFCC66\">导航底部显示</span>":"";
1230				
1231				if($v['cate_hide']){
1232					echo "<span style=\"color:red; padding:0 3px;\">隐藏</span>";
1233				}
1234				$href=($v['cate_channel']==1)?"href=\"admin_content_alone.php?cate_id={$v['id']}&lang={$v['lang']}\"":"href=\"admin_content.php?action=add&id={$v['cate_channel']}&cate={$v['id']}&lang={$v['lang']}\"";
1235				$href2=($v['cate_channel']==1)?"href=\"admin_content_alone.php?action=content_list\"":"href=\"admin_content.php?action=content_list&id={$v['cate_channel']}&cate={$v['id']}&lang={$v['lang']}\"";
1236				echo"</span></div>";
1237				
1238				
1239				echo "<div class=\"right\"><span class=\"caozuo\"><a href=\"?action=child&parent=".$v['id']."&channel_id=".$v['cate_channel']."&lang=".$GLOBALS['lang']."\">增加下级栏目</a>".$add_content_str."|<a href=\"?action=xg&lang=".$GLOBALS['lang']."&id=".$v['id']."&parent=".$v['cate_parent']."\">修改栏目</a>|<a href=\"?action=move_cate&cate=".$v['id']."&lang=".$GLOBALS['lang']."\">移动栏目</a>|<a href=\"javascript:if(confirm('确定要删除么,删除后不可恢复!')){location.href='?action=del&lang=".$GLOBALS['lang']."&id=".$v['id']."&parent=".$parent."';}\">删除栏目</a></span></div>";
1240				echo "<div style=\"clear:both\"></div></div>";
1241				unset($cate[$k]);
1242				get_cate_list($cate,$v['id'],$v['haschild'],$level);
1243				echo "</div>";
1244				}
1245			}
1246		$level=$level-1;	
1247		}
1248		
1249}
1250
1251/*
1252*读取缓存
1253*return array  $file--缓存文件 $arr-返回数组名
1254*/
1255function read_cache($file,$arr){
1256	if(file_exists($file)){
1257		include($file);
1258	}
1259	return $$arr;
1260}
1261
1262//取得第一个频道的id值
1263function get_first_channel($lang){
1264	$cache_file=DATA_PATH."cache_channel/cache_channel_".$lang.".php";
1265	if(file_exists($cache_file)){
1266		include($cache_file);
1267	}
1268	return $channel[0]['id'];
1269}
1270
1271//取得标签的值
1272function get_tag($value,$tag){
1273	preg_match('/'.$tag.'=[\'\"]?+(.*)[\'\"]?+[\n\r\t]*/isU',$value,$v);
1274	return $v[1];
1275}
1276
1277//组合标签
1278function join_tag($tag,$lang){
1279	if(file_exists(DATA_PATH.$lang.'_tpl_info.php')){include(DATA_PATH.$lang.'_tpl_info.php');}
1280	//$num=count($tpl);
1281	if($tag['source']=='article'){
1282		if(!empty($tag['tpl'])){
1283		$arr['type']='article';
1284		$arr['name']=$tag['tpl'];
1285		$arr['info']=$tag['info'];
1286		$is_has=0;
1287		if(!empty($tpl)){
1288			foreach($tpl as $k=>$v){
1289				if($v['name']==$tag['tpl']){
1290					$is_has=1;$tpl[$k]=$arr;
1291				}
1292			}
1293		}
1294		if(!$is_has){
1295		$tpl[]=$arr;
1296		}
1297		$str="<?php\n\$tpl=".var_export($tpl,true).";\n?>";
1298		file_put_contents(DATA_PATH.$lang.'_tpl_info.php',$str);
1299		}
1300		return $tag['source']."('{$tag['titlelen']}','{$tag['flag']}','{$tag['pics']}','{$tag['tpl']}');";
1301	}
1302	if($tag['source']=='cmsinfo'||$tag['source']=='cmspath'||$tag['source']=='sitemap'||$tag['source']=='flash_ad'||$tag['source']=='body_pages'||$tag['source']=='album'||$tag['source']=='langs'||$tag['source']=='page_search'||$tag['source']=='list_search'||$tag['source']=='page_search'){
1303		return $tag['source']."('{$tag['name']}');";
1304	}
1305	if($tag['source']=='tag'||$tag['source']=='list_nav'||$tag['source']=='form'||$tag['source']=='market'){
1306		if(!empty($tag['tpl'])){
1307		$arr['type']=$tag['source'];
1308		$arr['name']=$tag['tpl'];
1309		$arr['info']=$tag['info'];
1310		$is_has=0;
1311		if(!empty($tpl)){
1312			foreach($tpl as $k=>$v){
1313				if($v['name']==$tag['tpl']){
1314					$is_has=1;
1315				}
1316			}
1317		}
1318		if(!$is_has){
1319		$tpl[]=$arr;
1320		$str="<?php\n\$tpl=".var_export($tpl,true).";\n?>";
1321		file_put_contents(DATA_PATH.$lang.'_tpl_info.php',$str);
1322		}
1323		}
1324		return $tag['source']."('{$tag['tpl']}');";
1325	}
1326	
1327	if($tag['source']=='nav_middle'||$tag['source']=='nav_bottom'||$tag['source']=='nav_top'||$tag['source']=='list_article'||$tag['source']=='list_page'||$tag['source']=='position'||$tag['source']=='lang'||$tag['source']=='weblink'||$tag['source']=='hot_key'){
1328		return $tag['source']."('{$tag['row']}');";
1329	}
1330	if($tag['source']=='category'){
1331		return $tag['source']."('{$tag['id']}');";
1332	}
1333	if($tag['source']=='child'){
1334		return $tag['source'].'($v["'.$tag['name'].'"]);';
1335	}
1336	return "'';";
1337	
1338}
1339//添加内容生成html地址
1340function get_ct_path($addtime,$cate_id,$last_id,$c_url=''){
1341	if(file_exists(DATA_PATH.'cache_cate/cache_category_all.php')){
1342		include(DATA_PATH.'cache_cate/cache_category_all.php');
1343	}
1344	$cate_info=get_cate_info($cate_id,$category);
1345	$rel=$GLOBALS['mysql']->fetch_asc("select custom_url from ".DB_PRE."category where id=".$cate_id);
1346	if(empty($c_url)){
1347		if(empty($rel[0]['custom_url'])){
1348			$addtime=date('Y-m-d',$addtime);
1349			$addtime=explode(' ',$addtime);
1350			$addtime_rel=explode('-',$addtime[0]);
1351			return 'htm/'.$cate_info['cate_fold_name'].'/'.$addtime_rel[0].'_'.$addtime_rel[1].$addtime_rel[2].'_'.$last_id.'.html';
1352		}else{
1353			return 'htm/'.$cate_info['cate_fold_name'].'/'.$rel[0]['custom_url'].$last_id.'.html';
1354		}	
1355	}else{
1356		return 'htm/'.$cate_info['cate_fold_name'].'/'.$c_url.$last_id.'.html';
1357	}
1358
1359}
1360//取得位置
1361function get_position($parent,$cate,$path,$list_php=''){
1362	global $_confing;
1363	$str='';
1364	foreach($cate as $k=>$v){
1365		if($v['id']==$parent){
1366			$cate_path=($v['cate_html']&&$_confing['web_html'][0])?$path.'htm/'.$v['cate_fold_name']:$path.$list_php.'?id='.$v['id'];
1367			$str="<a href=\"{$cate_path}\">{$v['cate_name']}</a> > ";
1368			get_position($v['cate_parent'],$cate,$path,$list_php);
1369			break;
1370		}
1371	}
1372	echo $str;
1373}
1374
1375//截取字符
1376function get_substr($string, $length, $start=0) {
1377	if(strlen($string)>$length){ 
1378		$str=null; 
1379		$len=$length; 
1380		for($i=$start;$i<$len;$i++){
1381			//if(ord(substr($string,$i,1))){ 
1382				$str.=substr($string,$n,3);
1383				$n=$n+3;
1384				//$i=$i+2; 
1385			//}else{ 
1386				//$str.=substr($string,$i,1); 
1387			//}
1388			
1389		} 
1390		return $str.'...'; 
1391	}else{ 
1392		return $string; 
1393	} 
1394}
1395
1396function cn_substr($str, $length, $start=0)
1397{
1398	if(strlen($str) < $start+1)
1399	{
1400		return '';
1401	}
1402	preg_match_all("/./su", $str, $ar);
1403	$str = '';
1404	$tstr = '';
1405
1406
1407	for($i=0; isset($ar[0][$i]); $i++)
1408	{
1409		if(strlen($tstr) < $start)
1410		{
1411			$tstr .= $ar[0][$i];
1412		}
1413		else
1414		{
1415			if(strlen($str) < $length + strlen($ar[0][$i]) )
1416			{
1417				$str .= $ar[0][$i];
1418			}
1419			else
1420			{
1421				break;
1422			}
1423		}
1424	}
1425	return $str;
1426}
1427
1428//写入缓存
1429function cache_write($file,$str,$name=''){
1430	$fp=fopen($file,'w+');
1431	flock($fp,LOCK_EX);
1432	if(!fwrite($fp,$str)){
1433		flock($fp,LOCK_UN);
1434		fclose($fp);
1435		err("【{$name}】写入缓存失败");
1436	}
1437	flock($fp,LOCK_UN);
1438	fclose($fp);
1439}
1440
1441//读取缓存
1442function cache_read($file){
1443	if(file_exists($file)){
1444		return include($file);
1445	}
1446}
1447
1448function get_dir_file($file,$dir){
1449	if(!empty($file)){
1450		$path=CMS_URL.$dir;
1451		$info=pathinfo($file);
1452		$info_ex=isset($info['extension'])?$info['extension']:'';
1453		if($info_ex){
1454		$file_arr['size']=(filesize(CMS_PATH.$dir.$file)/1000).'K';
1455		}
1456		$file=iconv('gbk','utf-8',$file);
1457		$flmtime=@filemtime(CMS_PATH.$dir.$file);
1458		$file_arr['mtime']=empty($flmtime)?'':date('Y-m-d H:m:s',$flmtime);
1459		$file_arr['path']='<a class="fl_gif" target="_blank" href="'.$path.$file.'">'.$file.'</a>';
1460		//文件夹
1461			switch($info_ex){
1462				case 'gif':
1463				$file_arr['path']='<a class="fl_gif" target="_blank" href="'.$path.$file.'">'.$file.'</a>';
1464				break;
1465				case 'jpg':
1466				$file_arr['path']='<a class="fl_jpg" target="_blank" href="'.$path.$file.'">'.$file.'</a>';
1467				break;
1468				case 'jpeg':
1469				$file_arr['path']='<a class="fl_jpg" target="_blank" href="'.$path.$file.'">'.$file.'</a>';
1470				break;
1471				case 'png':
1472				$file_arr['path']='<a class="fl_png" target="_blank" href="'.$path.$file.'">'.$file.'</a>';
1473				break;
1474				case 'swf':
1475				$file_arr['path']='<a class="fl_swf" target="_blank" href="'.$path.$file.'">'.$file.'</a>';
1476				break;
1477				case 'html':
1478				$file_arr['path']='<a class="fl_html" target="_blank" href="'.$path.$file.'">'.$file.'</a>';
1479				break;
1480				case '';
1481				$file_arr['path']= '<a class="fl_dir" href="?path='.$dir.$file.'">'.$file.'</a>';
1482				break;
1483		}
1484		
1485	}
1486	return $file_arr;
1487}
1488//删除目录
1489function delete_dir($file,$err=''){
1490	if(!is_dir(CMS_PATH.$file)){
1491		if(!@unlink(CMS_PATH.$file)){
1492			echo "…

Large files files are truncated, but you can click here to view the full file