PageRenderTime 72ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

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