PageRenderTime 62ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 1ms

/e/class/functions.php

https://github.com/westeast/xwdede
PHP | 5626 lines | 5435 code | 50 blank | 141 comment | 161 complexity | 9f83a73e9c55885693e5955cc96ccf8e MD5 | raw file

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

  1. <?php
  2. define('InEmpireCMSHfun',TRUE);
  3. //-------------- 公共区 ----------------------
  4. //返回后台风格
  5. function EcmsReturnAdminStyle(){
  6. global $public_r;
  7. $adminstyle=(int)getcvar('loginadminstyleid',1);
  8. if(!strstr($public_r['adminstyle'],','.$adminstyle.','))
  9. {
  10. $adminstyle=$public_r['defadminstyle']?$public_r['defadminstyle']:1;
  11. }
  12. return $adminstyle;
  13. }
  14. //返回后台管理信息栏目导航字符串
  15. function AdminReturnClassLink($classid){
  16. global $class_r,$editor,$fun_r;
  17. if($editor==1)
  18. {
  19. $addurl='../';
  20. }
  21. if(empty($class_r[$classid][featherclass]))
  22. {
  23. $class_r[$classid][featherclass]="|";
  24. }
  25. $r=explode("|",$class_r[$classid][featherclass].$classid."|");
  26. $string="<a href=\"".$addurl."ListAllInfo.php?tbname=".$class_r[$classid][tbname]."\">".$fun_r['AdminInfo']."</a>";
  27. $count=count($r)-1;
  28. for($i=1;$i<$count;$i++)
  29. {
  30. $curl=$class_r[$r[$i]][islast]?"ListNews.php?classid=".$r[$i]:"ListAllInfo.php?tbname=".$class_r[$r[$i]][tbname]."&classid=".$r[$i];
  31. $string.="&nbsp;>&nbsp;<a href=\"".$addurl."$curl\">".$class_r[$r[$i]][classname]."</a>";
  32. }
  33. return $string;
  34. }
  35. //加验证代码
  36. function AddCheckViewCode(){
  37. $code="if(!defined('InEmpireCMS'))
  38. {
  39. exit();
  40. }";
  41. return $code;
  42. }
  43. //加模板验证代码
  44. function AddCheckViewTempCode(){
  45. $code="<?php
  46. if(!defined('InEmpireCMS'))
  47. {
  48. exit();
  49. }
  50. ?>";
  51. return $code;
  52. }
  53. //后台分页
  54. function page2($num,$line,$page_line,$start,$page,$search){
  55. global $fun_r;
  56. if($num<=$line)
  57. {
  58. return '<span class="epages"><a title="'.$fun_r['admintrecord'].'">&nbsp;<b>'.$num.'</b> </a>&nbsp;&nbsp;</span>';
  59. }
  60. $search=htmlspecialchars($search,ENT_QUOTES);
  61. $url=$_SERVER['PHP_SELF'].'?page';
  62. $snum=2;//最小页数
  63. $totalpage=ceil($num/$line);//取得总页数
  64. $firststr='<a title="'.$fun_r['admintrecord'].'">&nbsp;<b>'.$num.'</b> </a>&nbsp;&nbsp;';
  65. //上一页
  66. if($page<>0)
  67. {
  68. $toppage='<a href="'.$url.'=0'.$search.'">'.$fun_r['adminstartpage'].'</a>&nbsp;';
  69. $pagepr=$page-1;
  70. $prepage='<a href="'.$url.'='.$pagepr.$search.'">'.$fun_r['adminpripage'].'</a>';
  71. }
  72. //下一页
  73. if($page!=$totalpage-1)
  74. {
  75. $pagenex=$page+1;
  76. $nextpage='&nbsp;<a href="'.$url.'='.$pagenex.$search.'">'.$fun_r['adminnextpage'].'</a>';
  77. $lastpage='&nbsp;<a href="'.$url.'='.($totalpage-1).$search.'">'.$fun_r['adminlastpage'].'</a>';
  78. }
  79. $starti=$page-$snum<0?0:$page-$snum;
  80. $no=0;
  81. for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
  82. {
  83. $no++;
  84. if($page==$i)
  85. {
  86. $is_1="<b>";
  87. $is_2="</b>";
  88. }
  89. else
  90. {
  91. $is_1='<a href="'.$url.'='.$i.$search.'">';
  92. $is_2="</a>";
  93. }
  94. $pagenum=$i+1;
  95. $returnstr.="&nbsp;".$is_1.$pagenum.$is_2;
  96. }
  97. $returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage;
  98. return '<span class="epages">'.$returnstr.'</span>';
  99. }
  100. //后台分页
  101. function postpage($num,$line,$page_line,$start,$page,$form){
  102. global $fun_r;
  103. if($num<=$line)
  104. {
  105. return '';
  106. }
  107. $snum=2;//最小页数
  108. $totalpage=ceil($num/$line);//取得总页数
  109. $firststr='<a title="'.$fun_r['admintrecord'].'">&nbsp;<b>'.$num.'</b> </a>&nbsp;&nbsp;';
  110. //上一页
  111. if($page<>0)
  112. {
  113. $toppage='<a href="#ecms" onclick="javascript:GotoPostPage(0,0);">'.$fun_r['adminstartpage'].'</a>&nbsp;';
  114. $pagepr=$page-1;
  115. $prepage='<a href="#ecms" onclick="javascript:GotoPostPage('.$pagepr.',0);">'.$fun_r['adminpripage'].'</a>';
  116. }
  117. //下一页
  118. if($page!=$totalpage-1)
  119. {
  120. $pagenex=$page+1;
  121. $nextpage='&nbsp;<a href="#ecms" onclick="javascript:GotoPostPage('.$pagenex.',0);">'.$fun_r['adminnextpage'].'</a>';
  122. $lastpage='&nbsp;<a href="#ecms" onclick="javascript:GotoPostPage('.($totalpage-1).',0);">'.$fun_r['adminlastpage'].'</a>';
  123. }
  124. $starti=$page-$snum<0?0:$page-$snum;
  125. $no=0;
  126. for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
  127. {
  128. $no++;
  129. if($page==$i)
  130. {
  131. $is_1="<b>";
  132. $is_2="</b>";
  133. }
  134. else
  135. {
  136. $is_1='<a href="#ecms" onclick="javascript:GotoPostPage('.$i.',0);">';
  137. $is_2="</a>";
  138. }
  139. $pagenum=$i+1;
  140. $returnstr.="&nbsp;".$is_1.$pagenum.$is_2;
  141. }
  142. $returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage;
  143. $returnstr.="<script>
  144. function GotoPostPage(page,start){
  145. ".$form.".page.value=page;
  146. ".$form.".start.value=start;
  147. ".$form.".submit();
  148. }
  149. </script>";
  150. return $returnstr;
  151. }
  152. //取得模型表名
  153. function GetModTable($mid){
  154. global $empire,$dbtbpre;
  155. $r=$empire->fetch1("select tid,tbname from {$dbtbpre}enewsmod where mid='$mid'");
  156. return $r;
  157. }
  158. //建立专题目录
  159. function CreateZtPath($ztpath){
  160. $createpath=ECMS_PATH.$ztpath;
  161. $mk=DoMkdir($createpath);
  162. }
  163. //建立栏目目录
  164. function CreateClassPath($classpath){
  165. $createpath=ECMS_PATH.$classpath;
  166. $mk=DoMkdir($createpath);
  167. $createfilepath=ECMS_PATH.'d/file/'.$classpath;//建立附件目录
  168. $mk1=DoMkdir($createfilepath);
  169. }
  170. //删除栏目缓存文件
  171. function DelListEnews(){
  172. $file=ECMS_PATH."e/data/fc/ListEnews.php";
  173. DelFiletext($file);
  174. $file1=ECMS_PATH."e/data/fc/ListClass0.php";
  175. DelFiletext($file1);
  176. $file2=ECMS_PATH."e/data/fc/ListClass1.php";
  177. DelFiletext($file2);
  178. }
  179. //删除模板临时缓存文件
  180. function DelOneTempTmpfile($classid){
  181. $file=ECMS_PATH.'e/data/tmp/dt_temp'.$classid.'.php';
  182. if(file_exists($file))
  183. {
  184. DelFiletext($file);
  185. }
  186. }
  187. //替换php代码
  188. function RepPhpAspJspcode($string){
  189. global $public_r;
  190. if(!$public_r[candocode]){
  191. //$string=str_replace("<?xml","[!--ecms.xml--]",$string);
  192. $string=str_replace("<\\","&lt;\\",$string);
  193. $string=str_replace("<?","&lt;?",$string);
  194. $string=str_replace("<%","&lt;%",$string);
  195. if(stristr($string,' language'))
  196. {
  197. $string=preg_replace(array('!<script!i','!</script>!i'),array('&lt;script','&lt;/script&gt;'),$string);
  198. }
  199. //$string=str_replace("[!--ecms.xml--]","<?xml",$string);
  200. }
  201. return $string;
  202. }
  203. //替换php代码
  204. function RepPhpAspJspcodeText($string){
  205. //$string=str_replace("<?xml","[!--ecms.xml--]",$string);
  206. $string=str_replace("<\\","&lt;\\",$string);
  207. $string=str_replace("<?","&lt;?",$string);
  208. $string=str_replace("<%","&lt;%",$string);
  209. if(stristr($string,' language'))
  210. {
  211. $string=preg_replace(array('!<script!i','!</script>!i'),array('&lt;script','&lt;/script&gt;'),$string);
  212. }
  213. //$string=str_replace("[!--ecms.xml--]","<?xml",$string);
  214. $string=str_replace("<!--code.start-->","&lt;!--code.start--&gt;",$string);
  215. $string=str_replace("<!--code.end-->","&lt;!--code.end--&gt;",$string);
  216. return $string;
  217. }
  218. //替换文件前缀
  219. function RepFilenameQz($qz,$ecms=0){
  220. if(empty($ecms))
  221. {
  222. $qz=str_replace("/","",$qz);
  223. $qz=str_replace("\\","",$qz);
  224. }
  225. $qz=str_replace("#","",$qz);
  226. $qz=str_replace("&","",$qz);
  227. $qz=str_replace(":","",$qz);
  228. $qz=str_replace(";","",$qz);
  229. $qz=str_replace("<","",$qz);
  230. $qz=str_replace(">","",$qz);
  231. $qz=str_replace("?","",$qz);
  232. $qz=str_replace("*","",$qz);
  233. $qz=str_replace("%","",$qz);
  234. $qz=str_replace("|","",$qz);
  235. $qz=str_replace("\"","",$qz);
  236. $qz=str_replace("'","",$qz);
  237. $qz=str_replace(".","",$qz);
  238. return $qz;
  239. }
  240. //替换目录值
  241. function RepPathStr($path){
  242. $path=str_replace("\\","",$path);
  243. $path=str_replace("/","",$path);
  244. return $path;
  245. }
  246. //返回替换字符
  247. function ReturnCheckDoRep(){
  248. global $empire,$dbtbpre;
  249. //信息来源
  250. $befrom=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbefrom");
  251. //作者
  252. $writer=$empire->gettotal("select count(*) as total from {$dbtbpre}enewswriter");
  253. //替换字符
  254. $words=$empire->gettotal("select count(*) as total from {$dbtbpre}enewswords");
  255. //内容关键字
  256. $key=$empire->gettotal("select count(*) as total from {$dbtbpre}enewskey");
  257. $str=",$befrom,$writer,$words,$key,";
  258. return $str;
  259. }
  260. //返回替换验证
  261. function ReturnCheckDoRepStr(){
  262. global $public_r;
  263. return explode(',',$public_r[checkdorepstr]);
  264. }
  265. //取得栏目目录名称
  266. function GetPathname($classname){
  267. $c=explode("/",$classname);
  268. $count=count($c)-1;
  269. $cr[0]=$c[$count];//栏目目录名
  270. $len=strlen($cr[0]);
  271. //上级栏目目录名
  272. $cr[1]=substr($classname,0,strlen($classname)-$len);
  273. return $cr;
  274. }
  275. //更新缓存
  276. function ChangeEnewsData($userid,$username){
  277. //操作权限
  278. CheckLevel($userid,$username,$classid,"changedata");
  279. //更新参数设置
  280. GetConfig(1);
  281. //更新类别
  282. GetClass();
  283. //更新会员组
  284. GetMemberLevel();
  285. //更新全站搜索数据表
  286. GetSearchAllTb();
  287. //操作日志
  288. insert_dolog("");
  289. printerror("ChangeDataSuccess","history.go(-1)");
  290. }
  291. //返回文件名
  292. function ReturnPathFile($filename){
  293. $fr=explode("/",$filename);
  294. $count=count($fr)-1;
  295. return $fr[$count];
  296. }
  297. //返回栏目链接(无缓存)
  298. function sys_ReturnBqClassUrl($r){
  299. global $public_r;
  300. //外部栏目
  301. if($r[wburl])
  302. {
  303. $classurl=$r[wburl];
  304. }
  305. //动态列表
  306. elseif($r['listdt'])
  307. {
  308. $classurl=$public_r['newsurl']."e/action/ListInfo/?classid=$r[classid]";
  309. }
  310. elseif($r['classurl'])
  311. {
  312. $classurl=$r['classurl'];
  313. }
  314. else
  315. {
  316. $classurl=$public_r['newsurl'].$r['classpath']."/";
  317. }
  318. return $classurl;
  319. }
  320. //返回专题链接(无缓存)
  321. function sys_ReturnBqZtUrl($r){
  322. global $public_r;
  323. if($r['zturl'])
  324. {
  325. $zturl=$r['zturl'];
  326. }
  327. else
  328. {
  329. $zturl=$public_r['newsurl'].$r['ztpath']."/";
  330. }
  331. return $zturl;
  332. }
  333. //组合两数组
  334. function TogTwoArray($r,$ra){
  335. $returnr=array_merge($r,$ra);
  336. return $returnr;
  337. }
  338. //下载
  339. function DownLoadFile($file,$filepath,$ecms=0){
  340. if(empty($file))
  341. {
  342. printerror("FileNotExist","history.go(-1)");
  343. }
  344. if(!file_exists($filepath))
  345. {
  346. printerror("FileNotExist","");
  347. }
  348. $filesize=@filesize($filepath);
  349. //下载
  350. Header("Content-type: application/octet-stream");
  351. Header("Accept-Ranges: bytes");
  352. Header("Accept-Length: ".$filesize);
  353. Header("Content-Disposition: attachment; filename=".$file);
  354. echo ReadFiletext($filepath);
  355. if($ecms==1)
  356. {
  357. DelFiletext($filepath);
  358. }
  359. }
  360. //取得缓存文件内容
  361. function GetFcfiletext($file){
  362. $str1="document.write(\"";
  363. $str2="\");";
  364. $text=ReadFiletext($file);
  365. $text=stripSlashes(str_replace($str2,"",str_replace($str1,"",$text)));
  366. return $text;
  367. }
  368. //验证模板组是否存在
  369. function CheckTempGroup($gid){
  370. global $empire,$dbtbpre;
  371. if(empty($gid))
  372. {
  373. $gid=GetDoTempGid();
  374. }
  375. $r=$empire->fetch1("select gid,gname from {$dbtbpre}enewstempgroup where gid='$gid'");
  376. if(empty($r['gid']))
  377. {
  378. printerror("ErrorUrl","");
  379. }
  380. return $r['gname'];
  381. }
  382. //附加隐藏表单项
  383. function ReturnFormHidden($vname,$value){
  384. $value=htmlspecialchars(ClearAddsData($value));
  385. return "<input type=hidden name=\"".$vname."\" value=\"".$value."\">";
  386. }
  387. //-------------- 信息处理区 ----------------------
  388. //替换关键字
  389. function ReplaceKey($newstext){
  390. global $empire,$dbtbpre,$public_r;
  391. if(empty($newstext))
  392. {return $newstext;}
  393. $sql=$empire->query("select keyname,keyurl from {$dbtbpre}enewskey");
  394. while($r=$empire->fetch($sql))
  395. {
  396. $newstext=empty($public_r[repkeynum])?str_replace($r[keyname],'<a href='.$r[keyurl].' target=_blank class=infotextkey>'.$r[keyname].'</a>',$newstext):preg_replace('/'.$r[keyname].'/','<a href='.$r[keyurl].' target=_blank class=infotextkey>'.$r[keyname].'</a>',$newstext,$public_r[repkeynum]);
  397. }
  398. return $newstext;
  399. }
  400. //替换禁用字符
  401. function ReplaceWord($newstext){
  402. global $empire,$dbtbpre;
  403. if(empty($newstext))
  404. {return $newstext;}
  405. $sql=$empire->query("select newword,oldword from {$dbtbpre}enewswords");
  406. while($r=$empire->fetch($sql))
  407. {
  408. $newstext=str_replace($r[oldword],$r[newword],$newstext);
  409. }
  410. return $newstext;
  411. }
  412. //编辑信息时替换关键字和过滤字符
  413. function DoReplaceKeyAndWord($newstext,$dokey){
  414. global $public_r;
  415. $docheckrep=ReturnCheckDoRepStr();//返回替换验证字符
  416. if($public_r['dorepword']==1&&$docheckrep[3])//过滤字符
  417. {
  418. $newstext=ReplaceWord($newstext);
  419. }
  420. if($public_r['dorepkey']==1&&$docheckrep[4]&&!empty($dokey))//内容关键字
  421. {
  422. $newstext=ReplaceKey($newstext);
  423. }
  424. return $newstext;
  425. }
  426. //重命名列表文件
  427. function RenameListfile($classid,$lencord,$num,$type,$newtype,$classpath){
  428. $page=ceil($num/$lencord);
  429. for($j=1;$j<=$page;$j++)
  430. {
  431. if($j==1)
  432. {
  433. $listfile=ECMS_PATH.$classpath."/index";
  434. }
  435. else
  436. {
  437. $listfile=ECMS_PATH.$classpath."/index_".$j;
  438. }
  439. @rename($listfile.$type,$listfile.$newtype);
  440. }
  441. }
  442. //组合标题属性
  443. function TitleFont($titlefont,$titlecolor=''){
  444. $add=$titlecolor.',';
  445. if($titlecolor=='no')
  446. {
  447. $add='';
  448. }
  449. if($titlefont[b])//粗体
  450. {$add.='b|';}
  451. if($titlefont[i])//斜体
  452. {$add.='i|';}
  453. if($titlefont[s])//删除线
  454. {$add.='s|';}
  455. if($add==',')
  456. {
  457. $add='';
  458. }
  459. return $add;
  460. }
  461. //组合专题ID
  462. function ZtId($ztid){
  463. for($i=0;$i<count($ztid);$i++)
  464. {
  465. $myztid.=intval($ztid[$i]).'|';
  466. }
  467. if($myztid)
  468. {
  469. $myztid='|'.$myztid;
  470. }
  471. return $myztid;
  472. }
  473. //信息送审
  474. function InfoInsertToWorkflow($id,$classid,$wfid,$userid,$username){
  475. global $empire,$dbtbpre,$class_r;
  476. $wfitemr=$empire->fetch1("select tid,tno,groupid,userclass,username,tstatus from {$dbtbpre}enewsworkflowitem where wfid='$wfid' order by tno limit 1");
  477. //状态更新
  478. $empire->query("insert into {$dbtbpre}enewswfinfo(id,classid,wfid,tid,groupid,userclass,username,checknum,tstatus,checktno) values('$id','$classid','$wfid','$wfitemr[tid]','$wfitemr[groupid]','$wfitemr[userclass]','$wfitemr[username]',1,'$wfitemr[tstatus]',0);");
  479. //日志
  480. InsertWfLog($classid,$id,$wfid,0,$username,'',1,0);
  481. }
  482. //信息返工送审
  483. function InfoUpdateToWorkflow($id,$classid,$wfid,$userid,$username){
  484. global $empire,$dbtbpre,$class_r;
  485. $wfinfor=$empire->fetch1("select checknum,wfid,tid,checktno from {$dbtbpre}enewswfinfo where id='$id' and classid='$classid' limit 1");
  486. if($wfinfor[checktno]!='101')
  487. {
  488. return '';
  489. }
  490. if($wfinfor[tid])
  491. {
  492. $ywfitemr=$empire->fetch1("select tno from {$dbtbpre}enewsworkflowitem where tid='$wfinfor[tid]'");
  493. $wfitemr=$empire->fetch1("select tid,tno,groupid,userclass,username,tstatus from {$dbtbpre}enewsworkflowitem where wfid='$wfinfor[wfid]' and tno>$ywfitemr[tno] order by tno limit 1");
  494. }
  495. else
  496. {
  497. $wfitemr=$empire->fetch1("select tid,tno,groupid,userclass,username,tstatus from {$dbtbpre}enewsworkflowitem where wfid='$wfinfor[wfid]' order by tno limit 1");
  498. }
  499. //状态更新
  500. $empire->query("update {$dbtbpre}enewswfinfo set tid='$wfitemr[tid]',groupid='$wfitemr[groupid]',userclass='$wfitemr[userclass]',username='$wfitemr[username]',checknum=checknum+1,tstatus='$wfitemr[tstatus]',checktno='0' where id='$id' and classid='$classid' limit 1");
  501. //日志
  502. InsertWfLog($classid,$id,$wfinfor[wfid],0,$username,'',$wfinfor[checknum],0);
  503. }
  504. //写入签发日志
  505. function InsertWfLog($classid,$id,$wfid,$tid,$username,$checktext,$checknum,$checktype){
  506. global $empire,$dbtbpre,$class_r,$lur;
  507. $checktime=time();
  508. $checktext=RepPostStr($checktext);
  509. $empire->query("insert into {$dbtbpre}enewswfinfolog(id,classid,wfid,tid,username,checktime,checktext,checknum,checktype) values('$id','$classid','$wfid','$tid','$username','$checktime','$checktext','$checknum','$checktype');");
  510. }
  511. //加入TAG表
  512. function eInsertTags($tags,$classid,$id,$newstime){
  513. global $empire,$dbtbpre,$class_r;
  514. if(!trim($tags))
  515. {
  516. return '';
  517. }
  518. $tags=RepPostVar($tags);
  519. $classid=(int)$classid;
  520. $id=(int)$id;
  521. $mid=(int)$class_r[$classid][modid];
  522. $tr=explode(',',$tags);
  523. $count=count($tr);
  524. for($i=0;$i<$count;$i++)
  525. {
  526. $tagname=$tr[$i];
  527. if(empty($tagname))
  528. {
  529. continue;
  530. }
  531. $r=$empire->fetch1("select tagid from {$dbtbpre}enewstags where tagname='$tagname' limit 1");
  532. if($r[tagid])
  533. {
  534. $datar=$empire->fetch1("select tagid,classid,newstime from {$dbtbpre}enewstagsdata where tagid='$r[tagid]' and id='$id' and mid='$mid' limit 1");
  535. if($datar[tagid])
  536. {
  537. if($datar[classid]!=$classid||$datar[newstime]!=$newstime)
  538. {
  539. $empire->query("update {$dbtbpre}enewstagsdata set classid='$classid',newstime='$newstime' where tagid='$r[tagid]' and id='$id' and mid='$mid' limit 1");
  540. }
  541. }
  542. else
  543. {
  544. $empire->query("update {$dbtbpre}enewstags set num=num+1 where tagid='$r[tagid]'");
  545. $empire->query("insert into {$dbtbpre}enewstagsdata(tagid,classid,id,newstime,mid) values('$r[tagid]','$classid','$id','$newstime','$mid');");
  546. }
  547. }
  548. else
  549. {
  550. $empire->query("insert into {$dbtbpre}enewstags(tagname,num,isgood,cid) values('$tagname',1,0,0);");
  551. $tagid=$empire->lastid();
  552. $empire->query("insert into {$dbtbpre}enewstagsdata(tagid,classid,id,newstime,mid) values('$tagid','$classid','$id','$newstime','$mid');");
  553. }
  554. }
  555. }
  556. //返回信息TAGS
  557. function eReturnInfoTags($classid,$id,$mid){
  558. global $empire,$dbtbpre,$class_r;
  559. if(!$mid||!$id)
  560. {
  561. return '';
  562. }
  563. $tags='';
  564. $dh='';
  565. $sql=$empire->query("select tagid from {$dbtbpre}enewstagsdata where id='$id' and mid='$mid' order by tagid");
  566. while($r=$empire->fetch($sql))
  567. {
  568. $tr=$empire->fetch1("select tagname from {$dbtbpre}enewstags where tagid='$r[tagid]'");
  569. $tags.=$dh.$tr[tagname];
  570. $dh=',';
  571. }
  572. return $tags;
  573. }
  574. //返回命名方式
  575. function ReturnInfoFilename($classid,$id,$filenameqz){
  576. global $class_r;
  577. if($class_r[$classid][filename]==1) //time命名
  578. {
  579. $filename=$class_r[$classid][filename_qz].time().$id;
  580. }
  581. elseif($class_r[$classid][filename]==2) //md5命名
  582. {
  583. $filename=$class_r[$classid][filename_qz].md5(uniqid(microtime()));
  584. }
  585. elseif($class_r[$classid][filename]==3) //目录
  586. {
  587. $filename=$class_r[$classid][filename_qz].$id.'/index';
  588. }
  589. else //id
  590. {
  591. $filename=$class_r[$classid][filename_qz].$id;
  592. }
  593. $filename=$filenameqz.$filename;
  594. return $filename;
  595. }
  596. //更新相应的附件
  597. function UpdateTheFile($id,$checkpass){
  598. global $empire,$dbtbpre;
  599. if(empty($id)||empty($checkpass))
  600. {
  601. return "";
  602. }
  603. $id=(int)$id;
  604. $checkpass=(int)$checkpass;
  605. $sql=$empire->query("update {$dbtbpre}enewsfile set id=$id,cjid=0 where cjid=$checkpass");
  606. }
  607. //修改时更新附件
  608. function UpdateTheFileEdit($classid,$id){
  609. global $empire,$dbtbpre;
  610. $sql=$empire->query("update {$dbtbpre}enewsfile set cjid=0 where id='$id' and classid='$classid'");
  611. }
  612. //更新ispic标识
  613. function UpdateTheIspic($classid,$id){
  614. global $empire,$dbtbpre,$class_r;
  615. $r=$empire->fetch1("select titlepic,ispic from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' limit 1");
  616. $ispic=$r['titlepic']?1:0;
  617. if($ispic<>$r['ispic'])
  618. {
  619. $empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set ispic='$ispic' where id='$id'");
  620. }
  621. }
  622. //取第几张图片
  623. function GetFpicToTpic($classid,$id,$num=1,$getfirsttitlespic=0,$swidth=0,$sheight=0){
  624. global $empire,$dbtbpre,$public_r,$class_r;
  625. $num=$num-1;
  626. $picr=$empire->fetch1("select fileid,filename,path,id,classid,no,fpath from {$dbtbpre}enewsfile where id=$id and classid=$classid and type=1 order by fileid limit $num,1");
  627. $firsttitlepic="";
  628. if($picr['fileid'])
  629. {
  630. $rpath=$picr['path']?$picr['path'].'/':$picr['path'];
  631. $fspath=ReturnFileSavePath($picr[classid],$picr[fpath]);
  632. if($getfirsttitlespic==1&&$swidth&&$sheight)//缩略图
  633. {
  634. $path="../../".$fspath['filepath'].$rpath;
  635. $yname=$path.$picr[filename];
  636. $filetype=GetFiletype($picr[filename]);
  637. $insertfile=substr($picr[filename],0,strlen($picr[filename])-strlen($filetype)).time();
  638. $name=$path."small".$insertfile;
  639. $sfiler=GetMySmallImg($classid,$picr[no],$insertfile,$picr[path],$yname,$swidth,$sheight,$name,$add['filepass'],$add['filepass'],$userid,$username);
  640. $firsttitlepic=$fspath['fileurl'].$rpath."small".$insertfile.$sfiler['filetype'];
  641. }
  642. else
  643. {
  644. $firsttitlepic=$fspath['fileurl'].$rpath.$picr[filename];
  645. }
  646. }
  647. return $firsttitlepic;
  648. }
  649. //更新替换图片下一页链接内容
  650. function UpdateImgNexturl($classid,$id){
  651. global $empire,$dbtbpre,$class_r,$public_r,$emod_r;
  652. $mid=$class_r[$classid][modid];
  653. $tbname=$class_r[$classid][tbname];
  654. $pf=$emod_r[$mid]['pagef'];
  655. $stf=$emod_r[$mid]['savetxtf'];
  656. if(!$pf)
  657. {
  658. return '';
  659. }
  660. //分页字段
  661. $tbdataf=strstr($emod_r[$mid]['tbdataf'],','.$pf.',')?1:0;
  662. if($tbdataf)
  663. {
  664. $r=$empire->fetch1("select id,classid,titleurl,groupid,newspath,filename,stb from {$dbtbpre}ecms_".$tbname." where id='$id'");
  665. $finfor=$empire->fetch1("select ".$pf." from {$dbtbpre}ecms_".$tbname."_data_".$r[stb]." where id='$id'");
  666. $r[$pf]=$finfor[$pf];
  667. }
  668. else
  669. {
  670. $r=$empire->fetch1("select id,classid,titleurl,groupid,newspath,filename,".$pf." from {$dbtbpre}ecms_".$tbname." where id='$id'");
  671. }
  672. //存文本
  673. if($stf&&$stf==$pf)
  674. {
  675. $newstextfile=$r[$stf];
  676. $r[$stf]=GetTxtFieldText($r[$stf]);
  677. }
  678. if(!$r[$pf])
  679. {
  680. return '';
  681. }
  682. $newstext=RepNewstextImgLink($r[$pf],$r);
  683. if(empty($newstext))
  684. {
  685. return '';
  686. }
  687. //存文本
  688. if($stf&&$stf==$pf)
  689. {
  690. EditTxtFieldText($newstextfile,$newstext);
  691. return '';
  692. }
  693. if($tbdataf)
  694. {
  695. $empire->query("update {$dbtbpre}ecms_".$tbname."_data_".$r[stb]." set ".$pf."='$newstext' where id='$id'");
  696. }
  697. else
  698. {
  699. $empire->query("update {$dbtbpre}ecms_".$tbname." set ".$pf."='$newstext' where id='$id'");
  700. }
  701. }
  702. //给图片加下一页链接
  703. function RepNewstextImgLink($newstext,$add){
  704. global $public_r;
  705. $expage='[!--empirenews.page--]';//分页符
  706. if(!stristr($newstext,$expage)||!stristr($newstext,'<img '))
  707. {
  708. return '';
  709. }
  710. $newstext=stripSlashes($newstext);
  711. $repurl='[!--empirecms.rep.nextpageurl--]';
  712. $newstext=DoRepImgLink($newstext,$repurl);
  713. $nr=explode($expage,$newstext);
  714. $count=count($nr);
  715. //页面地址
  716. $urlqzr=ReturnInfoPageQz($add);
  717. $lastpageurl=$public_r['newsurl'].'e/public/ClassUrl/?classid='.$add['classid']; //最后一页链接地址
  718. $new_newstext='';
  719. $addexpage='';
  720. for($i=0;$i<$count;$i++)
  721. {
  722. $thispagetext=$nr[$i];
  723. if(stristr($thispagetext,'<img '))
  724. {
  725. if($i==$count-1)
  726. {
  727. $newurl=$lastpageurl;
  728. }
  729. else
  730. {
  731. //下一页链接
  732. if($urlqzr['nametype']==1)
  733. {
  734. $newurl=$urlqzr['titleurl'].'&page='.($i+1);
  735. }
  736. else
  737. {
  738. $newurl=$urlqzr['titleurl'].'_'.($i+2).$urlqzr['filetype'];
  739. }
  740. }
  741. $thispagetext=str_replace($repurl,$newurl,$thispagetext);
  742. }
  743. $new_newstext.=$addexpage.$thispagetext;
  744. $addexpage=$expage;
  745. }
  746. return addslashes($new_newstext);
  747. }
  748. //返回相关链接信息ID
  749. function GetKeyid($keyboard,$classid,$id,$link_num){
  750. global $empire,$public_r,$class_r,$fun_r,$dbtbpre,$eyh_r,$etable_r;
  751. if($keyboard)
  752. {
  753. if(empty($link_num))
  754. {
  755. return '';
  756. }
  757. $keyboard=RepDyh($keyboard);
  758. $r=explode(",",$keyboard);
  759. for($i=0;$i<count($r);$i++)
  760. {
  761. if($i==0)
  762. {
  763. $or="";
  764. }
  765. else
  766. {
  767. $or=" or ";
  768. }
  769. $repadd.=$or."[!--f--!]"." like '%".$r[$i]."%'";
  770. }
  771. //搜索范围
  772. if($public_r['newslink']==1)
  773. {
  774. $add='('.str_replace('[!--f--!]','keyboard',$repadd).')';
  775. }
  776. elseif($public_r['newslink']==2)
  777. {
  778. $add='('.str_replace('[!--f--!]','keyboard',$repadd).' or '.str_replace('[!--f--!]','title',$repadd).')';
  779. }
  780. else
  781. {
  782. $add='('.str_replace('[!--f--!]','title',$repadd).')';
  783. }
  784. //模型
  785. if(!empty($class_r[$classid][modid]))
  786. {
  787. $mr=$empire->fetch1("select sonclass from {$dbtbpre}enewsmod where mid='".$class_r[$classid][modid]."'");
  788. $where=" and (".ReturnClass($mr[sonclass]).")";
  789. }
  790. //优化
  791. $tbname=$class_r[$classid][tbname];
  792. $yhvar='otherlink';
  793. $yhid=$etable_r[$tbname][yhid];
  794. $yhadd='';
  795. if($yhid)
  796. {
  797. $yhadd=ReturnYhSql($yhid,$yhvar);
  798. }
  799. //ID声名
  800. $keyid="";
  801. $first=0;
  802. $key_sql=$empire->query("select id from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$yhadd.$add.$where." and id<>$id and checked=1 order by newstime desc limit $link_num");
  803. while($link_r=$empire->fetch($key_sql))
  804. {
  805. if(empty($first))
  806. {
  807. $dh="";
  808. $first=1;
  809. }
  810. else
  811. {
  812. $dh=",";
  813. }
  814. $keyid.=$dh.$link_r[id];
  815. }
  816. }
  817. else
  818. {
  819. $keyid="";
  820. }
  821. return $keyid;
  822. }
  823. //删除信息附件
  824. function DelNewsTheFile($id,$classid,$delpl=0){
  825. global $empire,$dbtbpre;
  826. if(empty($id))
  827. {
  828. return "";
  829. }
  830. $i=0;
  831. $sql=$empire->query("select classid,filename,path,fpath from {$dbtbpre}enewsfile where id='$id' and classid='$classid'");
  832. while($r=$empire->fetch($sql))
  833. {
  834. $i=1;
  835. DoDelFile($r);
  836. }
  837. if($i)
  838. {
  839. $empire->query("delete from {$dbtbpre}enewsfile where id='$id' and classid='$classid'");
  840. }
  841. //删除评论
  842. if($delpl==0)
  843. {
  844. $empire->query("delete from {$dbtbpre}enewspl where id='$id' and classid='$classid'");
  845. $tbr=$empire->fetch1("select pldatatbs from {$dbtbpre}enewspublic limit 1");
  846. if($tbr['pldatatbs'])
  847. {
  848. $dtbr=explode(',',$tbr['pldatatbs']);
  849. $count=count($dtbr)-1;
  850. for($i=1;$i<$count;$i++)
  851. {
  852. $empire->query("delete from {$dbtbpre}enewspl_data_".$dtbr[$i]." where id='$id' and classid='$classid'");
  853. }
  854. }
  855. }
  856. }
  857. //删除信息文件
  858. function DelNewsFile($filename,$newspath,$classid,$newstext,$groupid=0){
  859. global $class_r,$addgethtmlpath;
  860. //文件类型
  861. if($groupid)
  862. {
  863. $filetype=".php";
  864. }
  865. else
  866. {
  867. $filetype=$class_r[$classid][filetype];
  868. }
  869. //是否有日期目录
  870. if(empty($newspath))
  871. {
  872. $mynewspath="";
  873. }
  874. else
  875. {
  876. $mynewspath=$newspath."/";
  877. }
  878. $iclasspath=ReturnSaveInfoPath($classid,$id);
  879. $r=explode("[!--empirenews.page--]",$newstext);
  880. for($i=1;$i<=count($r);$i++)
  881. {
  882. if(strstr($filename,'/'))
  883. {
  884. DelPath(ECMS_PATH.$iclasspath.$mynewspath.ReturnInfoSPath($filename));
  885. }
  886. else
  887. {
  888. if($i==1)
  889. {
  890. $file=ECMS_PATH.$iclasspath.$mynewspath.$filename.$filetype;
  891. }
  892. else
  893. {
  894. $file=ECMS_PATH.$iclasspath.$mynewspath.$filename."_".$i.$filetype;
  895. }
  896. DelFiletext($file);
  897. }
  898. }
  899. }
  900. //替换图片标签
  901. function RepImg($text,$copyflash){
  902. global $saveurlimgclearurl;
  903. $exp1="[--copyimg--]";
  904. $exp2="[/--copyimg--]";
  905. //去掉图片链接
  906. if($saveurlimgclearurl==1)
  907. {
  908. $zz2="/\<(a|A) (.*?)(href|Href)=('|\"|\\\\\"|)(.+?)><(img|IMG) (.*?)(src|SRC)=('|\"|\\\\\"|)(.+?)(.jpg|.JPG|.gif|.GIF|.png|.PNG|.bmp|.BMP|.jpeg|.JPEG)(.*?)><\/(a|A)>/is";
  909. $text=preg_replace($zz2,"<\\6 \\7\\8=\\9\\10\\11\\12>",$text);
  910. }
  911. $zz1="/\<(img|IMG) (.*?)(src|SRC)=('|\"|\\\\\"|)(.+?)(.jpg|.JPG|.gif|.GIF|.png|.PNG|.bmp|.BMP|.jpeg|.JPEG)(.*?)>/is";
  912. $text=preg_replace($zz1,"<\\1 \\2\\3=\\4".$exp1."\\5\\6".$exp2."\\7>",$text);
  913. return $text;
  914. }
  915. //替换flash标签
  916. function RepFlash($text,$copyflash){
  917. $exp1="[--copyimg--]";
  918. $exp2="[/--copyimg--]";
  919. //去掉flash多余链接
  920. $zz2="/\<(embed|EMBED) (.*?)(src|SRC)=('|\"|\\\\\"|)(.+?)(.swf|.SWF)(.*?)>(.*?)<\/(embed|EMBED)>/is";
  921. $text=preg_replace($zz2,"",$text);
  922. $zz3="/\<(param|PARAM) (name|NAME)=\"(Src|src|SRC)\" (.*?)(value|VALUE)=('|\"|\\\\\"|)(.+?)(.swf|.SWF)(.*?)>/is";
  923. $text=preg_replace($zz3,"",$text);
  924. $zz1="/\<(param|PARAM) (.*?)(name|NAME)=\"(movie|MOVIE)\" (.*?)(value|VALUE)=('|\"|\\\\\"|)(.+?)(.swf|.SWF)(.*?)>/is";
  925. $text=preg_replace($zz1,"<\\1 \\2\\3=\"\\4\" \\5\\6=\\7".$exp1."\\8\\9".$exp2."\\10>",$text);
  926. return $text;
  927. }
  928. //替换图片链接
  929. function DoRepImgLink($text,$newurl){
  930. //去掉图片链接
  931. $zz2="/\<(a|A) (.*?)(href|Href)=('|\"|\\\\\"|)(.+?)><(img|IMG) (.*?)(src|SRC)=('|\"|\\\\\"|)(.*?)><\/(a|A)>/is";
  932. $text=preg_replace($zz2,"<\\6 \\7\\8=\\9\\10>",$text);
  933. //新链接
  934. $zz1="/\<(img|IMG) (.*?)(src|SRC)=('|\"|\\\\\"|)(.*?)>/is";
  935. $text=preg_replace($zz1,"<a href=\"".$newurl."\"><\\1 \\2\\3=\\4\\5></a>",$text);
  936. return $text;
  937. }
  938. //截取图片
  939. function CopyImg($text,$copyimg,$copyflash,$classid,$qz,$username,$theid,$cjid,$mark){
  940. global $empire,$public_r,$cjnewsurl,$navtheid,$dbtbpre;
  941. if(empty($text))
  942. {return "";}
  943. if($copyimg)
  944. {
  945. $text=RepImg($text,$copyflash);
  946. }
  947. if($copyflash)
  948. {$text=RepFlash($text,$copyflash);}
  949. $exp1="[--copyimg--]";
  950. $exp2="[/--copyimg--]";
  951. $r=explode($exp1,$text);
  952. for($i=1;$i<count($r);$i++)
  953. {
  954. $r1=explode($exp2,$r[$i]);
  955. if(strstr($r1[0],"http://")||strstr($r1[0],"https://"))
  956. {
  957. $dourl=$r1[0];
  958. }
  959. else
  960. {
  961. //是否是本地址
  962. if(!strstr($r1[0],"/")&&$cjnewsurl)
  963. {
  964. $fileqz_r=GetPageurlQz($cjnewsurl);
  965. $fileqz=$fileqz_r['selfqz'];
  966. $dourl=$fileqz.$r1[0];
  967. }
  968. else
  969. {
  970. $dourl=$qz.$r1[0];
  971. }
  972. }
  973. $return_r=DoTranUrl($dourl,$classid);
  974. $text=str_replace($exp1.$r1[0].$exp2,$return_r[url],$text);
  975. if($return_r[tran])
  976. {
  977. //记录数据库
  978. $filetime=date("Y-m-d H:i:s");
  979. //变量处理
  980. $return_r[filesize]=(int)$return_r[filesize];
  981. $classid=(int)$classid;
  982. $return_r[type]=(int)$return_r[type];
  983. $theid=(int)$theid;
  984. $cjid=(int)$cjid;
  985. $sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$return_r[filename]',$return_r[filesize],'$username','$return_r[filepath]','$filetime',$classid,'[URL]".$return_r[filename]."',$return_r[type],$theid,$cjid,0,'$public_r[fpath]');");
  986. //加水
  987. if($mark&&$return_r[type]==1)
  988. {
  989. GetMyMarkImg($return_r['yname']);
  990. }
  991. }
  992. }
  993. return $text;
  994. }
  995. //生成缩略图
  996. function GetMySmallImg($classid,$no,$insertfile,$filepath,$yname,$maxwidth,$maxheight,$name,$id,$cjid,$userid,$username){
  997. global $empire,$dbtbpre,$public_r,$efileftp_fr;
  998. if(empty($yname))
  999. {
  1000. return "";
  1001. }
  1002. $no="[s]".$no;
  1003. $filer=ResizeImage($yname,$name,$maxwidth,$maxheight,$public_r['spickill']);
  1004. if($filer['file'])
  1005. {
  1006. $insertfile="small".$insertfile.$filer['filetype'];
  1007. $filesize=@filesize($filer['file']);
  1008. //写入数据库
  1009. $filetime=date("Y-m-d H:i:s");
  1010. //变量处理
  1011. $filesize=(int)$filesize;
  1012. $classid=(int)$classid;
  1013. $id=(int)$id;
  1014. $cjid=(int)$cjid;
  1015. $sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$insertfile',$filesize,'$username','$filepath','$filetime',$classid,'$no',1,$id,$cjid,0,'$public_r[fpath]');");
  1016. //FileServer
  1017. if($public_r['openfileserver'])
  1018. {
  1019. $efileftp_fr[]=$name.$filer['filetype'];
  1020. }
  1021. }
  1022. return $filer;
  1023. }
  1024. //图片加水印
  1025. function GetMyMarkImg($groundImage){
  1026. global $public_r;
  1027. if(empty($groundImage))
  1028. {
  1029. return "";
  1030. }
  1031. imageWaterMark($groundImage,$public_r['markpos'],$public_r['markimg'],$public_r['marktext'],$public_r['markfontsize'],$public_r['markfontcolor'],$public_r['markfont'],$public_r['markpct'],$public_r['jpgquality']);
  1032. }
  1033. //投票组合
  1034. function ReturnVote($votename,$votenum,$delvid,$vid,$enews=0){
  1035. global $empire,$dbtbpre;
  1036. $f_exp="::::::";
  1037. $r_exp="\r\n";
  1038. $returnstr="";
  1039. //增加投票
  1040. if(empty($enews))
  1041. {
  1042. for($i=0;$i<count($votename);$i++)
  1043. {
  1044. //替换非法字符
  1045. $name=str_replace($f_exp,"",$votename[$i]);
  1046. $name=str_replace($r_exp,"",$votename[$i]);
  1047. $num=str_replace($f_exp,"",$votenum[$i]);
  1048. $num=str_replace($r_exp,"",$votenum[$i]);
  1049. if($name)
  1050. {
  1051. if(empty($num))
  1052. {$num=0;}
  1053. $returnstr.=$name.$f_exp.$num.$r_exp;
  1054. }
  1055. }
  1056. }
  1057. //修改投票
  1058. else
  1059. {
  1060. for($i=0;$i<count($votename);$i++)
  1061. {
  1062. //删除下载地址
  1063. $del=0;
  1064. for($j=0;$j<count($delvid);$j++)
  1065. {
  1066. if($delvid[$j]==$vid[$i])
  1067. {$del=1;}
  1068. }
  1069. if($del)
  1070. {continue;}
  1071. //替换非法字符
  1072. $name=str_replace($f_exp,"",$votename[$i]);
  1073. $name=str_replace($r_exp,"",$votename[$i]);
  1074. $num=str_replace($f_exp,"",$votenum[$i]);
  1075. $num=str_replace($r_exp,"",$votenum[$i]);
  1076. if($name)
  1077. {
  1078. if(empty($num))
  1079. {$num=0;}
  1080. $returnstr.=$name.$f_exp.$num.$r_exp;
  1081. }
  1082. }
  1083. }
  1084. /*
  1085. if(empty($returnstr))
  1086. {printerror("EmptyVotenum","history.go(-1)");}
  1087. */
  1088. //去掉最后的字符
  1089. $returnstr=substr($returnstr,0,strlen($returnstr)-2);
  1090. return $returnstr;
  1091. }
  1092. //显示无限级栏目[增加栏目时]
  1093. function ShowClass_AddClass($adminclass,$obclassid,$bclassid,$exp,$modid,$enews=0,$addminfocid=''){
  1094. global $empire,$dbtbpre;
  1095. if(empty($bclassid))
  1096. {
  1097. $bclassid=0;
  1098. $exp="|-";
  1099. if($enews==2)
  1100. {
  1101. $modr=$empire->fetch1("select sonclass from {$dbtbpre}enewsmod where mid='$modid'");
  1102. $addminfocid=$modr['sonclass'];
  1103. }
  1104. }
  1105. else
  1106. {$exp="&nbsp;&nbsp;".$exp;}
  1107. $sql=$empire->query("select classid,classname,bclassid,islast,openadd,modid,sonclass from {$dbtbpre}enewsclass where bclassid='$bclassid' and wburl='' order by myorder,classid");
  1108. $returnstr="";
  1109. while($r=$empire->fetch($sql))
  1110. {
  1111. //投稿显示
  1112. if($enews==2)
  1113. {
  1114. if($r[openadd])
  1115. {
  1116. continue;
  1117. }
  1118. if(CheckHaveInClassid($r,$addminfocid)==0)
  1119. {
  1120. continue;
  1121. }
  1122. }
  1123. if($r[islast])
  1124. {
  1125. if(empty($enews)||$enews==2||$enews==3||$enews==4)
  1126. {
  1127. $color=" style='background:#99C4E3'";
  1128. }
  1129. //隐藏不能投稿的栏目
  1130. if($enews==2)
  1131. {
  1132. if($modid)
  1133. {
  1134. if($r[modid]<>$modid)
  1135. {continue;}
  1136. }
  1137. }
  1138. //模型
  1139. if($enews==4)
  1140. {
  1141. if($r[modid]<>$modid)
  1142. {continue;}
  1143. }
  1144. }
  1145. else
  1146. {$color="";}
  1147. if($r[classid]==$obclassid)
  1148. {$select=" selected";}
  1149. else
  1150. {$select="";}
  1151. //-----------增加用户时
  1152. if($enews==3)
  1153. {
  1154. $c=explode("|".$r[classid]."|",$adminclass);
  1155. if(count($c)>1)
  1156. {$select=" selected";}
  1157. else
  1158. {$select="";}
  1159. }
  1160. $returnstr.="<option value=".$r[classid].$select.$color.">".$exp.$r[classname]."</option>";
  1161. if(empty($r[islast]))
  1162. {
  1163. $returnstr.=ShowClass_AddClass($adminclass,$obclassid,$r[classid],$exp,$modid,$enews,$addminfocid);
  1164. }
  1165. }
  1166. return $returnstr;
  1167. }
  1168. //设置伸缩
  1169. function SetDisplayClass($open){
  1170. $time=time()+365*24*3600;
  1171. $set=esetcookie("displayclass",$open,$time,1);
  1172. echo"<script>self.location.href='ListClass.php';</script>";
  1173. exit();
  1174. }
  1175. //删除目录函数
  1176. function DelPath($DelPath){
  1177. if($DelPath=="../../"||$DelPath=="../../d/file/")
  1178. {return "";}
  1179. $wm_chief=new del_path();
  1180. $wm_chief_ok=$wm_chief->wm_chief_delpath($DelPath);
  1181. return $wm_chief_ok;
  1182. }
  1183. //复制目录
  1184. function CopyPath($oldpath,$newpath){
  1185. $wm_chief=new copy_path();
  1186. $wm_chief_ok=$wm_chief->wm_chief_copypath($oldpath,$newpath);
  1187. return $wm_chief_ok;
  1188. }
  1189. //移动目录
  1190. function MovePath($oldpath,$newpath){
  1191. //复制
  1192. CopyPath($oldpath,$newpath);
  1193. //删除
  1194. DelPath($oldpath);
  1195. }
  1196. //替换字符
  1197. function RepInfoZZ($text,$exp,$enews=0){
  1198. $text=str_replace(".","\\.",$text);
  1199. $text=str_replace("(","\\(",$text);
  1200. $text=str_replace(")","\\)",$text);
  1201. $text=str_replace("?","\\?",$text);
  1202. $text=str_replace("*","(.*?)",$text);
  1203. $text=str_replace("[!--".$exp."--]","(.*?)",$text);
  1204. //$text=str_replace("\\","\\\\",$text);
  1205. //$text=str_replace("\"","\"",$text);
  1206. $text=str_replace("/","\\/",$text);
  1207. $text=str_replace("-","\\-",$text);
  1208. $text=str_replace("|","\\|",$text);
  1209. $text=str_replace("+","\\+",$text);
  1210. $text=str_replace("^","\\^",$text);
  1211. $text=str_replace("{","\\{",$text);
  1212. $text=str_replace("}","\\}",$text);
  1213. $text=str_replace("[","\\[",$text);
  1214. $text=str_replace("]","\\]",$text);
  1215. $text=str_replace("\$","\\\$",$text);
  1216. $text="/".$text."/is";
  1217. return $text;
  1218. }
  1219. //取得地址前缀
  1220. function GetPageurlQz($self){
  1221. $sr=explode("/",$self);
  1222. $count=count($sr)-1;
  1223. $sfile=$sr[$count];
  1224. $r[selfqz]=substr($self,0,strlen($self)-strlen($sfile));
  1225. //取得域名
  1226. $sr1=explode("http://",$self);
  1227. $sr2=explode("/",$sr1[1]);
  1228. $r[domain]="http://".$sr2[0];
  1229. return $r;
  1230. }
  1231. //去掉单引号
  1232. function RepDyh($text){
  1233. //$text=str_replace("\'","\\\'",stripSlashes($text));
  1234. $text=addslashes(stripSlashes($text));
  1235. return $text;
  1236. }
  1237. //补零
  1238. function AddNumZero($no,$endno){
  1239. $len=strlen($endno);
  1240. $forlen=$len-strlen($no);
  1241. for($i=1;$i<=$forlen;$i++)
  1242. {
  1243. $no="0".$no;
  1244. }
  1245. return $no;
  1246. }
  1247. //自动分页
  1248. function AutoDoPage($mybody,$spsize){
  1249. $sptag="[!--empirenews.page--]";
  1250. if(strlen($mybody)<$spsize) return $mybody;
  1251. $bds = explode('<',$mybody);
  1252. $npageBody = "";
  1253. $istable = 0;
  1254. $mybody = "";
  1255. foreach($bds as $i=>$k)
  1256. {
  1257. if($i==0){ $npageBody .= $bds[$i]; continue;}
  1258. $bds[$i] = "<".$bds[$i];
  1259. if(strlen($bds[$i])>6){
  1260. $tname = substr($bds[$i],1,5);
  1261. if(strtolower($tname)=='table') $istable++;
  1262. else if(strtolower($tname)=='/tabl') $istable--;
  1263. if($istable>0){ $npageBody .= $bds[$i]; continue; }
  1264. else $npageBody .= $bds[$i];
  1265. }else{
  1266. $npageBody .= $bds[$i];
  1267. }
  1268. if(strlen($npageBody)>$spsize){
  1269. $mybody .= $npageBody.$sptag;
  1270. $npageBody = "";
  1271. }
  1272. }
  1273. if($npageBody!="") $mybody .= $npageBody;
  1274. return $mybody;
  1275. }
  1276. //-------------- 模板区 ----------------------
  1277. //取得模型ID
  1278. function GetListtempMid($tempid){
  1279. global $empire;
  1280. $r=$empire->fetch1("select modid from ".GetTemptb("enewslisttemp")." where tempid='$tempid'");
  1281. return $r[modid];
  1282. }
  1283. //替换模板JS地址
  1284. function RepTemplateJsUrl($temp,$classid,$enews=0){
  1285. global $public_r,$class_r,$class_zr;
  1286. $allpath='[!--news.url--]d/js/js/';
  1287. $temp=str_replace("[!--hotnews--]","<script src='".$allpath."hotnews.js'></script>",$temp);
  1288. $temp=str_replace("[!--newnews--]","<script src='".$allpath."newnews.js'></script>",$temp);
  1289. $temp=str_replace("[!--goodnews--]","<script src='".$allpath."goodnews.js'></script>",$temp);
  1290. $temp=str_replace("[!--hotplnews--]","<script src='".$allpath."hotplnews.js'></script>",$temp);
  1291. $temp=str_replace("[!--firstnews--]","<script src='".$allpath."firstnews.js'></script>",$temp);
  1292. if(!empty($classid))
  1293. {
  1294. $path=$enews==1?'[!--news.url--]d/js/class/zt[!--self.classid--]_':'[!--news.url--]d/js/class/class[!--self.classid--]_';
  1295. $temp=str_replace("[!--self.hotnews--]","<script src='".$path."hotnews.js'></script>",$temp);
  1296. $temp=str_replace("[!--self.newnews--]","<script src='".$path."newnews.js'></script>",$temp);
  1297. $temp=str_replace("[!--self.goodnews--]","<script src='".$path."goodnews.js'></script>",$temp);
  1298. $temp=str_replace("[!--self.hotplnews--]","<script src='".$path."hotplnews.js'></script>",$temp);
  1299. $temp=str_replace("[!--self.firstnews--]","<script src='".$path."firstnews.js'></script>",$temp);
  1300. }
  1301. return $temp;
  1302. }
  1303. //-------------- 生成区 ----------------------
  1304. //取得列表模板
  1305. function GetListTemp($tempid){
  1306. global $empire;
  1307. $r=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle,docode from ".GetTemptb("enewslisttemp")." where tempid='$tempid'");
  1308. $r[temptext]=InfoNewsBq('list'.$tempid,$r[temptext]);
  1309. return $r;
  1310. }
  1311. //取得封面模板
  1312. function GetClassTemp($tempid){
  1313. global $empire;
  1314. $r=$empire->fetch1("select temptext from ".GetTemptb("enewsclasstemp")." where tempid='$tempid'");
  1315. return $r['temptext'];
  1316. }
  1317. //取得栏目页面内容
  1318. function GetClassText($classid){
  1319. global $empire,$dbtbpre;
  1320. $r=$empire->fetch1("select classtext from {$dbtbpre}enewsclassadd where classid='$classid'");
  1321. return $r['classtext'];
  1322. }
  1323. //取得专题页面内容
  1324. function GetZtText($ztid){
  1325. global $empire,$dbtbpre;
  1326. $r=$empire->fetch1("select classtext from {$dbtbpre}enewsztadd where ztid='$ztid'");
  1327. return $r['classtext'];
  1328. }
  1329. //取得首页模板
  1330. function GetIndextemp(){
  1331. global $empire,$dbtbpre,$public_r;
  1332. if($public_r['indexpageid'])
  1333. {
  1334. $r=$empire->fetch1("select temptext from {$dbtbpre}enewsindexpage where tempid='".$public_r['indexpageid']."'");
  1335. return $r['temptext'];
  1336. }
  1337. $r=$empire->fetch1("select indextemp from ".GetTemptb("enewspubtemp")." limit 1");
  1338. return $r['indextemp'];
  1339. }
  1340. //取得内容模板
  1341. function GetNewsTemp($newstempid){
  1342. global $empire,$public_r;
  1343. $r=$empire->fetch1("select temptext,showdate from ".GetTemptb("enewsnewstemp")." where tempid='$newstempid'");
  1344. $r[temptext]=InfoNewsBq('news'.$newstempid,$r[temptext]);
  1345. if($public_r[opennotcj])//启用反采集
  1346. {
  1347. $r[temptext]=ReturnNotcj($r[temptext]);
  1348. }
  1349. return $r;
  1350. }
  1351. //取得js模板
  1352. function GetTheJstemp($tempid){
  1353. global $empire;
  1354. $r=$empire->fetch1("select temptext,showdate,modid,subnews,subtitle from ".GetTemptb("enewsjstemp")." where tempid='$tempid'");
  1355. return $r;
  1356. }
  1357. //替换全局模板变量
  1358. function ReplaceTempvar($temp){
  1359. global $empire;
  1360. if(empty($temp))
  1361. {return $temp;}
  1362. $sql=$empire->query("select myvar,varvalue from ".GetTemptb("enewstempvar")." where isclose=0 order by myorder desc,varid");
  1363. while($r=$empire->fetch($sql))
  1364. {
  1365. $temp=str_replace('[!--temp.'.$r[myvar].'--]',$r[varvalue],$temp);;
  1366. }
  1367. return $temp;
  1368. }
  1369. //栏目页替换公共标记
  1370. function Class_ReplaceSvars($temp,$url,$classid,$title,$key,$des,$classimg,$add,$enews=0){
  1371. global $public_r,$class_r,$class_zr;
  1372. $temp=str_replace('[!--class.menu--]',$public_r['classnavs'],$temp);//栏目导航
  1373. $temp=str_replace('[!--pagetitle--]',$title,$temp);
  1374. $temp=str_replace('[!--pagekey--]',$key,$temp);
  1375. $temp=str_replace('[!--pagedes--]',$des,$temp);
  1376. $temp=str_replace('[!--class.intro--]',$des,$temp);
  1377. $temp=str_replace('[!--class.keywords--]',$key,$temp);
  1378. $temp=str_replace('[!--class.classimg--]',$classimg,$temp);
  1379. $temp=str_replace('[!--self.classid--]',$classid,$temp);
  1380. if($enews==0)//栏目
  1381. {
  1382. $temp=str_replace('[!--class.name--]',$class_r[$classid]['classname'],$temp);
  1383. $bclassid=$class_r[$classid]['bclassid'];
  1384. $temp=str_replace('[!--bclass.id--]',$bclassid,$temp);
  1385. $temp=str_replace('[!--bclass.name--]',$class_r[$bclassid]['classname'],$temp);
  1386. $path=$public_r['newsurl'].'d/js/class/class'.$classid.'_';
  1387. }
  1388. else//专题
  1389. {
  1390. $temp=str_replace('[!--class.name--]',$class_zr[$classid]['ztname'],$temp);
  1391. $path=$public_r['newsurl'].'d/js/class/zt'.$classid.'_';
  1392. }
  1393. $allpath=$public_r[newsurl].'d/js/js/';
  1394. //热门文章
  1395. $temp=str_replace("[!--hotnews--]","<script src='".$allpath."hotnews.js'></script>",$temp);
  1396. $temp=str_replace("[!--self.hotnews--]","<script src='".$path."hotnews.js'></script>",$temp);
  1397. //点击排行
  1398. $temp=str_replace("[!--newnews--]","<script src='".$allpath."newnews.js'></script>",$temp);
  1399. $temp=str_replace("[!--self.newnews--]","<script src='".$path."newnews.js'></script>",$temp);
  1400. //推荐
  1401. $temp=str_replace("[!--goodnews--]","<script src='".$allpath."goodnews.js'></script>",$temp);
  1402. $temp=str_replace("[!--self.goodnews--]","<script src='".$path."goodnews.js'></script>",$temp);
  1403. //评论排行
  1404. $temp=str_replace("[!--hotplnews--]","<script src='".$allpath."hotplnews.js'></script>",$temp);
  1405. $temp=str_replace("[!--self.hotplnews--]","<script src='".$path."hotplnews.js'></script>",$temp);
  1406. //头条排行
  1407. $temp=str_replace("[!--firstnews--]","<script src='".$allpath."firstnews.js'></script>",$temp);
  1408. $temp=str_replace("[!--self.firstnews--]","<script src='".$path."firstnews.js'></script>",$temp);
  1409. $temp=str_replace('[!--news.url--]',$public_r['newsurl'],$temp);
  1410. return $temp;
  1411. }
  1412. //内容页替换公共标记
  1413. function Info_ReplaceSvars($temp,$url,$classid,$title,$key,$des){
  1414. global $public_r,$class_r;
  1415. $temp=str_replace('[!--class.menu--]',$public_r['classnavs'],$temp);//栏目导航
  1416. $temp=str_replace('[!--newsnav--]',$url,$temp);//位置导航
  1417. $temp=str_replace('[!--pagetitle--]',$title,$temp);
  1418. $temp=str_replace('[!--pagekey--]',$key,$temp);
  1419. $temp=str_replace('[!--pagedes--]',$des,$temp);
  1420. $temp=str_replace('[!--self.classid--]',$classid,$temp);
  1421. $bclassid=$class_r[$classid]['bclassid'];
  1422. $temp=str_replace('[!--bclass.id--]',$bclassid,$temp);
  1423. $temp=str_replace('[!--bclass.name--]',$class_r[$bclassid]['classname'],$temp);
  1424. $temp=str_replace('[!--news.url--]',$public_r['newsurl'],$temp);
  1425. return $temp;
  1426. }
  1427. //替换搜索模板文件
  1428. function ReplaceStemp($temptext,$class,$url,$classid,$title,$key,$des,$repvar=1){
  1429. global $public_r;
  1430. if($repvar==1)//全局模板变量
  1431. {
  1432. $temptext=ReplaceTempvar($temptext);
  1433. }
  1434. $temptext=str_replace('[!--class.menu--]',$public_r['classnavs'],$temptext);//栏目导航
  1435. $temptext=str_replace("[!--class--]",$class,$temptext);
  1436. $temptext=str_replace('[!--pagetitle--]',$title,$temptext);
  1437. $temptext=str_replace('[!--pagekey--]',$key,$temptext);
  1438. $temptext=str_replace('[!--pagedes--]',$des,$temptext);
  1439. $temptext=str_replace('[!--self.classid--]',$classid,$temptext);
  1440. //热门文章
  1441. $temptext=str_replace("[!--hotnews--]","<script src='".$public_r[newsurl]."d/js/js/hotnews.js'></script>",$temptext);
  1442. //点击排行
  1443. $temptext=str_replace("[!--newnews--]","<script src='".$public_r[newsurl]."d/js/js/newnews.js'></script>",$temptext);
  1444. //推荐
  1445. $temptext=str_replace("[!--goodnews--]","<script src='".$public_r[newsurl]."d/js/js/goodnews.js'></script>",$temptext);
  1446. //评论排行
  1447. $temptext=str_replace("[!--hotplnews--]","<script src='".$public_r[newsurl]."d/js/js/hotplnews.js'></script>",$temptext);
  1448. //导航条
  1449. $temptext=str_replace("[!--url--]",$url,$temptext);
  1450. $temptext=str_replace('[!--newsnav--]',$url,$temptext);//位置导航
  1451. $temptext=str_replace("[!--news.url--]",$public_r[newsurl],$temptext);
  1452. $temptext=str_replace("[!--newsurl--]",$public_r[newsurl],$temptext);
  1453. return $temptext;
  1454. }
  1455. //栏目页验证
  1456. function AddCheckClassLevel($classid,$groupid,$classpath){
  1457. $classpath=ReturnSaveClassPath($classid);
  1458. $pr=explode('/',$classpath);
  1459. $pcount=count($pr);
  1460. for($i=0;$i<$pcount;$i++)
  1461. {
  1462. $include.='../';
  1463. }
  1464. $include1=$include;
  1465. $include.='e/class/CheckClassLevel.php';
  1466. $addlevel="<?php
  1467. define('empirecms','wm_chief');
  1468. \$check_groupid=\"".$groupid."\";
  1469. \$check_classid=".$classid.";
  1470. \$check_path=\"".$include1."\";
  1471. require(\"".$include."\");
  1472. ?>";
  1473. return $addlevel;
  1474. }
  1475. //生成栏目绑定信息页面
  1476. function ReClassBdInfo($classid){
  1477. global $empire,$dbtbpre;
  1478. $cr=$empire->fetch1("select classid,bdinfoid from {$dbtbpre}enewsclass where classid='$classid'");
  1479. if(!$cr['classid']||!$cr['bdinfoid'])
  1480. {
  1481. return '';
  1482. }
  1483. $infor=explode(',',$cr['bdinfoid']);
  1484. $infofile=GetInfoFilename(intval($infor[0]),intval($infor[1]));
  1485. $classtext='';
  1486. if($infofile)
  1487. {
  1488. $classtext=ReadFiletext($infofile);
  1489. }
  1490. $classfile=ECMS_PATH.ReturnSaveClassPath($classid,1);
  1491. WriteFiletext_n($classfile,$classtext);
  1492. }
  1493. //标签替换
  1494. function NewsBq($classid,$indextext,$enews=0,$doing=0){
  1495. global $empire,$dbtbpre,$public_r,$emod_r,$class_r,$class_zr,$fun_r,$navclassid,$navinfor,$class_tr,$level_r,$etable_r;
  1496. $indextext=stripSlashes($indextext);
  1497. $indextext=ReplaceTempvar($indextext);//替换全局模板变量
  1498. $classlevel='';
  1499. if($enews==0)//生成大栏目
  1500. {
  1501. if($class_r[$classid]['listdt']||$class_r[$classid]['wburl']||strstr($public_r['nreclass'],','.$classid.','))//不生成栏目
  1502. {
  1503. return '';
  1504. }
  1505. $GLOBALS['navclassid']=$classid;
  1506. $url=ReturnClassLink($classid);//导航
  1507. $cf=$doing==1?',classpath,classtype,classname':'';
  1508. $cr=$empire->fetch1("select classpagekey,intro,classimg,cgroupid".$cf." from {$dbtbpre}enewsclass where classid='$classid'");
  1509. if(!empty($cf))
  1510. {
  1511. $class_r[$classid][classpath]=$cr[classpath];
  1512. $class_r[$classid][classtype]=$cr[classtype];
  1513. $class_r[$classid][classname]=$cr[classname];
  1514. }
  1515. //权限
  1516. if($cr['cgroupid'])
  1517. {
  1518. $classlevel=AddCheckClassLevel($classid,$cr['cgroupid'],'');
  1519. }
  1520. //页面
  1521. $pagetitle=htmlspecialchars($class_r[$classid][classname]);
  1522. $pagekey=htmlspecialchars($cr['classpagekey']);
  1523. $pagedes=htmlspecialchars($cr['intro']);
  1524. $classimg=$cr['classimg'];
  1525. $onclick="<script src=".$public_r[newsurl]."e/public/onclick?enews=doclass&classid=$classid></script>";
  1526. $truefile=ECMS_PATH.ReturnSaveClassPath($classid,1);
  1527. $file=ECMS_PATH.'e/data/tmp/class'.$classid.'.php';
  1528. $indextext=str_replace("[!--newsnav--]",$url,$indextext);//位置导航
  1529. $indextext=Class_ReplaceSvars($indextext,$url,$classid,$pagetitle,$pagekey,$pagedes,$classimg,$add,0);
  1530. }
  1531. elseif($enews==3)//专题
  1532. {
  1533. $GLOBALS['navclassid']=$classid;
  1534. $url=ReturnZtLink($classid);//导航
  1535. $cf=$doing==1?',ztpath,zttype,ztname':'';
  1536. $cr=$empire->fetch1("select ztpagekey,intro,ztimg".$cf." from {$dbtbpre}enewszt where ztid='$classid'");
  1537. if(!empty($cf))
  1538. {
  1539. $class_zr[$classid][ztpath]=$cr[ztpath];
  1540. $class_zr[$classid][zttype]=$cr[zttype];
  1541. $class_zr[$classid][ztname]=$cr[ztname];
  1542. }
  1543. $pagetitle=htmlspecialchars($class_zr[$classid][ztname]);
  1544. $pagekey=htmlspecialchars($cr['ztpagekey']);
  1545. $pagedes=htmlspecialchars($cr['intro']);
  1546. $classimg=$cr['ztimg'];
  1547. $onclick="<script src=".$public_r[newsurl]."e/public/onclick?enews=dozt&ztid=$ztid></script>";
  1548. $truefile=ECMS_PATH.ReturnSaveZtPath($classid,1);
  1549. $file=ECMS_PATH.'e/data/tmp/zt'.$classid.'.php';
  1550. $indextext=str_replace("[!--newsnav--]",$url,$indextext);//位置导航
  1551. $indextext=Class_ReplaceSvars($indextext,$url,$classid,$pagetitle,$pagekey,$pagedes,$classimg,$add,1);
  1552. }
  1553. elseif($enews==1)//生成首页文件
  1554. {
  1555. $pr=$empire->fetch1("select sitekey,siteintro,indexpagedt from {$dbtbpre}enewspublic limit 1");
  1556. if($pr['indexpagedt'])
  1557. {
  1558. return '';
  1559. }
  1560. //页面
  1561. $pagetitle=htmlspecialchars($public_r['sitename']);
  1562. $pagekey=htmlspecialchars($pr['sitekey']);
  1563. $pagedes=htmlspecialchars($pr['siteintro']);
  1564. $url="<a href=\"".$public_r[newsurl]."\">".$fun_r['index']."</a>";//栏目导航
  1565. $onclick='';
  1566. $truefile=ECMS_PATH.ReturnSaveIndexFile();
  1567. $file=ECMS_PATH.'e/data/tmp/index.php';
  1568. $indextext=ReplaceSvars($indextext,$url,0,$pagetitle,$pagekey,$pagedes,$add,0);
  1569. }
  1570. $indextext=str_replace("[!--page.stats--]",$onclick,$indextext);
  1571. //替换标签
  1572. $indextext=DoRepEcmsLoopBq($indextext);
  1573. $indextext=RepBq($indextext);
  1574. //写文件
  1575. WriteFiletext($file,AddCheckViewTempCode().$indextext);
  1576. //读取文件内容
  1577. ob_start();
  1578. include($file);
  1579. $string=ob_get_contents

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