国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1301 lines
48KB

  1. <?php
  2. if(!defined('DEDEINC')) exit("Request Error!");
  3. /**
  4. * 文档类
  5. *
  6. * @version $Id: arc.archives.class.php 4 15:13 2010年7月7日Z tianya $
  7. * @package DedeCMS.Libraries
  8. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  9. * @license http://help.dedecms.com/usersguide/license.html
  10. * @link http://www.dedecms.com
  11. */
  12. require_once(DEDEINC."/typelink.class.php");
  13. require_once(DEDEINC."/channelunit.class.php");
  14. require_once(DEDEINC."/downmix.inc.php");
  15. require_once(DEDEINC.'/ftp.class.php');
  16. @set_time_limit(0);
  17. /**
  18. * 主文档类(Archives类)
  19. *
  20. * @package TypeLink
  21. * @subpackage DedeCMS.Libraries
  22. * @link http://www.dedecms.com
  23. */
  24. class Archives
  25. {
  26. var $TypeLink;
  27. var $ChannelUnit;
  28. var $dsql;
  29. var $Fields;
  30. var $dtp;
  31. var $ArcID;
  32. var $SplitPageField;
  33. var $SplitFields;
  34. var $NowPage;
  35. var $TotalPage;
  36. var $NameFirst;
  37. var $ShortName;
  38. var $FixedValues;
  39. var $TempSource;
  40. var $IsError;
  41. var $SplitTitles;
  42. var $PreNext;
  43. var $addTableRow;
  44. var $ftp;
  45. var $remoteDir;
  46. /**
  47. * php5构造函数
  48. *
  49. * @access public
  50. * @param int $aid 文档ID
  51. * @return string
  52. */
  53. function __construct($aid)
  54. {
  55. global $dsql,$ftp;
  56. $this->IsError = FALSE;
  57. $this->ArcID = $aid;
  58. $this->PreNext = array();
  59. $this->dsql = $dsql;
  60. $query = "SELECT channel,typeid FROM `#@__arctiny` WHERE id='$aid' ";
  61. $arr = $this->dsql->GetOne($query);
  62. if(!is_array($arr))
  63. {
  64. $this->IsError = TRUE;
  65. }
  66. else
  67. {
  68. if($arr['channel']==0) $arr['channel']=1;
  69. $this->ChannelUnit = new ChannelUnit($arr['channel'], $aid);
  70. $this->TypeLink = new TypeLink($arr['typeid']);
  71. if($this->ChannelUnit->ChannelInfos['issystem']!=-1)
  72. {
  73. // 如果当前文档不是系统模型,为单表模型
  74. $query = "SELECT arc.*,tp.reid,tp.typedir,ch.addtable
  75. FROM `#@__archives` arc
  76. LEFT JOIN #@__arctype tp on tp.id=arc.typeid
  77. LEFT JOIN #@__channeltype as ch on arc.channel = ch.id
  78. WHERE arc.id='$aid' ";
  79. $this->Fields = $this->dsql->GetOne($query);
  80. }
  81. else
  82. {
  83. $this->Fields['title'] = '';
  84. $this->Fields['money'] = $this->Fields['arcrank'] = 0;
  85. $this->Fields['senddate'] = $this->Fields['pubdate'] = $this->Fields['mid'] = $this->Fields['adminid'] = 0;
  86. $this->Fields['ismake'] = 1;
  87. $this->Fields['filename'] = '';
  88. }
  89. if($this->TypeLink->TypeInfos['corank'] > 0 && $this->Fields['arcrank']==0)
  90. {
  91. $this->Fields['arcrank'] = $this->TypeLink->TypeInfos['corank'];
  92. }
  93. $this->Fields['tags'] = GetTags($aid);
  94. $this->dtp = new DedeTagParse();
  95. $this->dtp->SetRefObj($this);
  96. $this->SplitPageField = $this->ChannelUnit->SplitPageField;
  97. $this->SplitFields = '';
  98. $this->TotalPage = 1;
  99. $this->NameFirst = '';
  100. $this->ShortName = 'html';
  101. $this->FixedValues = '';
  102. $this->TempSource = '';
  103. $this->ftp = &$ftp;
  104. $this->remoteDir = '';
  105. if(empty($GLOBALS['pageno']))
  106. {
  107. $this->NowPage = 1;
  108. }
  109. else
  110. {
  111. $this->NowPage = $GLOBALS['pageno'];
  112. }
  113. //特殊的字段数据处理
  114. $this->Fields['aid'] = $aid;
  115. $this->Fields['id'] = $aid;
  116. $this->Fields['position'] = $this->TypeLink->GetPositionLink(TRUE);
  117. $this->Fields['typeid'] = $arr['typeid'];
  118. //设置一些全局参数的值
  119. foreach($GLOBALS['PubFields'] as $k=>$v)
  120. {
  121. $this->Fields[$k] = $v;
  122. }
  123. //为了减少重复查询,这里直接把附加表查询记录放在 $this->addTableRow 中,在 ParAddTable() 不再查询
  124. if($this->ChannelUnit->ChannelInfos['addtable']!='')
  125. {
  126. $query = "SELECT * FROM `{$this->ChannelUnit->ChannelInfos['addtable']}` WHERE `aid` = '$aid'";
  127. $this->addTableRow = $this->dsql->GetOne($query);
  128. }
  129. //issystem==-1 表示单表模型,单表模型不支持redirecturl这类参数,因此限定内容普通模型才进行下面查询
  130. if($this->ChannelUnit->ChannelInfos['addtable']!='' && $this->ChannelUnit->ChannelInfos['issystem']!=-1)
  131. {
  132. if(is_array($this->addTableRow))
  133. {
  134. $this->Fields['redirecturl'] = $this->addTableRow['redirecturl'];
  135. $this->Fields['templet'] = $this->addTableRow['templet'];
  136. $this->Fields['userip'] = $this->addTableRow['userip'];
  137. }
  138. $this->Fields['templet'] = (empty($this->Fields['templet']) ? '' : trim($this->Fields['templet']));
  139. $this->Fields['redirecturl'] = (empty($this->Fields['redirecturl']) ? '' : trim($this->Fields['redirecturl']));
  140. $this->Fields['userip'] = (empty($this->Fields['userip']) ? '' : trim($this->Fields['userip']));
  141. }
  142. else
  143. {
  144. $this->Fields['templet'] = $this->Fields['redirecturl'] = '';
  145. }
  146. }//!error
  147. }
  148. //php4构造函数
  149. function Archives($aid)
  150. {
  151. $this->__construct($aid);
  152. }
  153. /**
  154. * 解析附加表的内容
  155. *
  156. * @access public
  157. * @return void
  158. */
  159. function ParAddTable()
  160. {
  161. //读取附加表信息,并把附加表的资料经过编译处理后导入到$this->Fields中,以方便在模板中用 {dede:field name='fieldname' /} 标记统一调用
  162. if($this->ChannelUnit->ChannelInfos['addtable']!='')
  163. {
  164. $row = $this->addTableRow;
  165. if($this->ChannelUnit->ChannelInfos['issystem']==-1)
  166. {
  167. $this->Fields['title'] = $row['title'];
  168. $this->Fields['senddate'] = $this->Fields['pubdate'] = $row['senddate'];
  169. $this->Fields['mid'] = $this->Fields['adminid'] = $row['mid'];
  170. $this->Fields['ismake'] = 1;
  171. $this->Fields['arcrank'] = 0;
  172. $this->Fields['money']=0;
  173. $this->Fields['filename'] = '';
  174. }
  175. if(is_array($row))
  176. {
  177. foreach($row as $k=>$v) $row[strtolower($k)] = $v;
  178. }
  179. if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))
  180. {
  181. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  182. {
  183. if(isset($row[$k]))
  184. {
  185. if(!empty($arr['rename']))
  186. {
  187. $nk = $arr['rename'];
  188. }
  189. else
  190. {
  191. $nk = $k;
  192. }
  193. $cobj = $this->GetCurTag($k);
  194. if(is_object($cobj))
  195. {
  196. foreach($this->dtp->CTags as $ctag)
  197. {
  198. if($ctag->GetTagName()=='field' && $ctag->GetAtt('name')==$k)
  199. {
  200. //带标识的专题节点
  201. if($ctag->GetAtt('noteid') != '') {
  202. $this->Fields[$k.'_'.$ctag->GetAtt('noteid')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  203. }
  204. //带类型的字段节点
  205. else if($ctag->GetAtt('type') != '') {
  206. $this->Fields[$k.'_'.$ctag->GetAtt('type')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  207. }
  208. //其它字段
  209. else {
  210. $this->Fields[$nk] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  211. }
  212. }
  213. }
  214. }
  215. else
  216. {
  217. $this->Fields[$nk] = $row[$k];
  218. }
  219. if($arr['type']=='htmltext' && $GLOBALS['cfg_keyword_replace']=='Y' && !empty($this->Fields['keywords']))
  220. {
  221. $this->Fields[$nk] = $this->ReplaceKeyword($this->Fields['keywords'],$this->Fields[$nk]);
  222. }
  223. }
  224. }//End foreach
  225. }
  226. //设置全局环境变量
  227. $this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
  228. @SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');
  229. }
  230. //完成附加表信息读取
  231. unset($row);
  232. //处理要分页显示的字段
  233. $this->SplitTitles = Array();
  234. if($this->SplitPageField!='' && $GLOBALS['cfg_arcsptitle']='Y'
  235. && isset($this->Fields[$this->SplitPageField]))
  236. {
  237. $this->SplitFields = explode("#p#",$this->Fields[$this->SplitPageField]);
  238. $i = 1;
  239. foreach($this->SplitFields as $k=>$v)
  240. {
  241. $tmpv = cn_substr($v,50);
  242. $pos = strpos($tmpv,'#e#');
  243. if($pos>0)
  244. {
  245. $st = trim(cn_substr($tmpv,$pos));
  246. if($st==""||$st=="副标题"||$st=="分页标题")
  247. {
  248. $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is","",$v);
  249. continue;
  250. }
  251. else
  252. {
  253. $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is","",$v);
  254. $this->SplitTitles[$k] = $st;
  255. }
  256. }
  257. else
  258. {
  259. continue;
  260. }
  261. $i++;
  262. }
  263. $this->TotalPage = count($this->SplitFields);
  264. $this->Fields['totalpage'] = $this->TotalPage;
  265. }
  266. //处理默认缩略图等
  267. if (isset($this->Fields['litpic']))
  268. {
  269. if($this->Fields['litpic'] == '-' || $this->Fields['litpic'] == '')
  270. {
  271. $this->Fields['litpic'] = $GLOBALS['cfg_cmspath'].'/static/defaultpic.jpg';
  272. }
  273. if(!preg_match("#^http:\/\/#i", $this->Fields['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  274. {
  275. $this->Fields['litpic'] = $GLOBALS['cfg_mainsite'].$this->Fields['litpic'];
  276. }
  277. $this->Fields['picname'] = $this->Fields['litpic'];
  278. //模板里直接使用{dede:field name='image'/}获取缩略图
  279. $this->Fields['image'] = (!preg_match('/jpg|gif|png/i', $this->Fields['picname']) ? '' : "<img src='{$this->Fields['picname']}' />");
  280. }
  281. // 处理投票选项
  282. if (isset($this->Fields['voteid']) && !empty($this->Fields['voteid']))
  283. {
  284. $this->Fields['vote'] = '';
  285. $voteid = $this->Fields['voteid'];
  286. $this->Fields['vote'] = "<script language='javascript' src='{$GLOBALS['cfg_cmspath']}/data/vote/vote_{$voteid}.js'></script>";
  287. if ($GLOBALS['cfg_multi_site'] == 'Y')
  288. {
  289. $this->Fields['vote'] = "<script language='javascript' src='{$GLOBALS['cfg_mainsite']}/data/vote/vote_{$voteid}.js'></script>";
  290. }
  291. }
  292. if (isset($this->Fields['goodpost']) && isset($this->Fields['badpost']))
  293. {
  294. //digg
  295. if($this->Fields['goodpost'] + $this->Fields['badpost'] == 0)
  296. {
  297. $this->Fields['goodper'] = $this->Fields['badper'] = 0;
  298. }
  299. else
  300. {
  301. $this->Fields['goodper'] = number_format($this->Fields['goodpost']/($this->Fields['goodpost']+$this->Fields['badpost']), 3)*100;
  302. $this->Fields['badper'] = 100 - $this->Fields['goodper'];
  303. }
  304. }
  305. }
  306. //获得当前字段参数
  307. function GetCurTag($fieldname)
  308. {
  309. if(!isset($this->dtp->CTags))
  310. {
  311. return '';
  312. }
  313. foreach($this->dtp->CTags as $ctag)
  314. {
  315. if($ctag->GetTagName()=='field' && $ctag->GetAtt('name')==$fieldname)
  316. {
  317. return $ctag;
  318. }
  319. else
  320. {
  321. continue;
  322. }
  323. }
  324. return '';
  325. }
  326. /**
  327. * 生成静态HTML
  328. *
  329. * @access public
  330. * @param int $isremote 是否远程
  331. * @return string
  332. */
  333. function MakeHtml($isremote=0)
  334. {
  335. global $cfg_remote_site,$fileFirst,$baidu_seo,$cfg_basehost;
  336. if($this->IsError)
  337. {
  338. return '';
  339. }
  340. $this->Fields["displaytype"] = "st";
  341. //预编译$th
  342. $this->LoadTemplet();
  343. $this->ParAddTable();
  344. $this->ParseTempletsFirst();
  345. $this->Fields['senddate'] = empty($this->Fields['senddate'])? '' : $this->Fields['senddate'];
  346. $this->Fields['title'] = empty($this->Fields['title'])? '' : $this->Fields['title'];
  347. $this->Fields['arcrank'] = empty($this->Fields['arcrank'])? 0 : $this->Fields['arcrank'];
  348. $this->Fields['ismake'] = empty($this->Fields['ismake'])? 0 : $this->Fields['ismake'];
  349. $this->Fields['money'] = empty($this->Fields['money'])? 0 : $this->Fields['money'];
  350. $this->Fields['filename'] = empty($this->Fields['filename'])? '' : $this->Fields['filename'];
  351. //分析要创建的文件名称
  352. $filename = GetFileNewName(
  353. $this->ArcID,$this->Fields['typeid'],$this->Fields['senddate'],
  354. $this->Fields['title'],$this->Fields['ismake'],$this->Fields['arcrank'],
  355. $this->TypeLink->TypeInfos['namerule'],$this->TypeLink->TypeInfos['typedir'],$this->Fields['money'],$this->Fields['filename']
  356. );
  357. $filenames = explode(".", $filename);
  358. $this->ShortName = $filenames[count($filenames)-1];
  359. if($this->ShortName=='') $this->ShortName = 'html';
  360. $fileFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filename);
  361. $this->Fields['namehand'] = basename($fileFirst);
  362. $filenames = explode("/", $filename);
  363. $this->NameFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filenames[count($filenames)-1]);
  364. if($this->NameFirst=='')
  365. {
  366. $this->NameFirst = $this->arcID;
  367. }
  368. //获得当前文档的全名
  369. $filenameFull = GetFileUrl(
  370. $this->ArcID,$this->Fields['typeid'],$this->Fields["senddate"],
  371. $this->Fields["title"],$this->Fields["ismake"],
  372. $this->Fields["arcrank"],$this->TypeLink->TypeInfos['namerule'],$this->TypeLink->TypeInfos['typedir'],$this->Fields["money"],$this->Fields['filename'],
  373. $this->TypeLink->TypeInfos['moresite'],$this->TypeLink->TypeInfos['siteurl'],$this->TypeLink->TypeInfos['sitepath']
  374. );
  375. $this->Fields['arcurl'] = $this->Fields['fullname'] = $filenameFull;
  376. //对于已设置不生成HTML的文章直接返回网址
  377. if($this->Fields['ismake']==-1 || $this->Fields['arcrank']!=0 || $this->Fields['money']>0
  378. || ($this->Fields['typeid']==0 && $this->Fields['channel'] != -1) )
  379. {
  380. return $this->GetTrueUrl($filename);
  381. }
  382. //循环生成HTML文件
  383. else
  384. {
  385. $seoUrls = array();
  386. for($i=1;$i<=$this->TotalPage;$i++)
  387. {
  388. if($this->TotalPage > 1) {
  389. $this->Fields['tmptitle'] = (empty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']);
  390. if($i>1) $this->Fields['title'] = $this->Fields['tmptitle']."($i)";
  391. }
  392. if($i>1)
  393. {
  394. $TRUEfilename = $this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName;
  395. $URLFilename = $fileFirst."_".$i.".".$this->ShortName;
  396. }
  397. else
  398. {
  399. $TRUEfilename = $this->GetTruePath().$filename;
  400. $URLFilename = $filename;
  401. }
  402. $seoUrls = array_merge($seoUrls, array($cfg_basehost.$URLFilename));
  403. $this->ParseDMFields($i,1);
  404. $this->dtp->SaveTo($TRUEfilename);
  405. //如果启用远程发布则需要进行判断
  406. if($cfg_remote_site=='Y' && $isremote == 1)
  407. {
  408. //分析远程文件路径
  409. $remotefile = str_replace(DEDEROOT, '', $TRUEfilename);
  410. $localfile = '..'.$remotefile;
  411. //创建远程文件夹
  412. $remotedir = preg_replace("#[^\/]*\.html#", '', $remotefile);
  413. $this->ftp->rmkdir($remotedir);
  414. $this->ftp->upload($localfile, $remotefile, 'ascii');
  415. }
  416. }
  417. if ($baidu_seo == true) {
  418. $api = 'http://data.zz.baidu.com/urls?site=https://www.zixue.cn&token=vXkBb4Ot0yhOFcmP';
  419. $ch = curl_init();
  420. $options = array(
  421. CURLOPT_URL => $api,
  422. CURLOPT_POST => true,
  423. CURLOPT_RETURNTRANSFER => true,
  424. CURLOPT_POSTFIELDS => implode("\n", $seoUrls),
  425. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  426. );
  427. curl_setopt_array($ch, $options);
  428. $result = curl_exec($ch);
  429. $rs = json_decode($result,true);
  430. if ($rs["success"]==1) {
  431. echo "百度搜索引擎提交成功,剩余次数:".$rs["remain"]."<br/>\r\n";
  432. }
  433. }
  434. }
  435. $this->dsql->ExecuteNoneQuery("Update `#@__archives` SET ismake=1 WHERE id='".$this->ArcID."'");
  436. return $this->GetTrueUrl($filename);
  437. }
  438. /**
  439. * 获得真实连接路径
  440. *
  441. * @access public
  442. * @param string $nurl 连接
  443. * @return string
  444. */
  445. function GetTrueUrl($nurl)
  446. {
  447. return GetFileUrl
  448. (
  449. $this->Fields['id'],
  450. $this->Fields['typeid'],
  451. $this->Fields['senddate'],
  452. $this->Fields['title'],
  453. $this->Fields['ismake'],
  454. $this->Fields['arcrank'],
  455. $this->TypeLink->TypeInfos['namerule'],
  456. $this->TypeLink->TypeInfos['typedir'],
  457. $this->Fields['money'],
  458. $this->Fields['filename'],
  459. $this->TypeLink->TypeInfos['moresite'],
  460. $this->TypeLink->TypeInfos['siteurl'],
  461. $this->TypeLink->TypeInfos['sitepath']
  462. );
  463. }
  464. /**
  465. * 获得站点的真实根路径
  466. *
  467. * @access public
  468. * @return string
  469. */
  470. function GetTruePath()
  471. {
  472. $TRUEpath = $GLOBALS["cfg_basedir"];
  473. return $TRUEpath;
  474. }
  475. /**
  476. * 获得指定键值的字段
  477. *
  478. * @access public
  479. * @param string $fname 键名称
  480. * @param string $ctag 标记
  481. * @return string
  482. */
  483. function GetField($fname, $ctag)
  484. {
  485. //所有Field数组 OR 普通Field
  486. if($fname=='array')
  487. {
  488. return $this->Fields;
  489. }
  490. //指定了ID的节点
  491. else if($ctag->GetAtt('noteid') != '')
  492. {
  493. if( isset($this->Fields[$fname.'_'.$ctag->GetAtt('noteid')]) )
  494. {
  495. return $this->Fields[$fname.'_'.$ctag->GetAtt('noteid')];
  496. }
  497. }
  498. //指定了type的节点
  499. else if($ctag->GetAtt('type') != '')
  500. {
  501. if( isset($this->Fields[$fname.'_'.$ctag->GetAtt('type')]) )
  502. {
  503. return $this->Fields[$fname.'_'.$ctag->GetAtt('type')];
  504. }
  505. }
  506. else if( isset($this->Fields[$fname]) )
  507. {
  508. return $this->Fields[$fname];
  509. }
  510. return '';
  511. }
  512. /**
  513. * 获得模板文件位置
  514. *
  515. * @access public
  516. * @return string
  517. */
  518. function GetTempletFile()
  519. {
  520. global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
  521. $cid = $this->ChannelUnit->ChannelInfos['nid'];
  522. if(!empty($this->Fields['templet']))
  523. {
  524. $filetag = MfTemplet($this->Fields['templet']);
  525. if( !preg_match("#\/#", $filetag) ) $filetag = $GLOBALS['cfg_df_style'].'/'.$filetag;
  526. }
  527. else
  528. {
  529. $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
  530. }
  531. $tid = $this->Fields['typeid'];
  532. $filetag = str_replace('{cid}', $cid,$filetag);
  533. $filetag = str_replace('{tid}', $tid,$filetag);
  534. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  535. if($cid=='spec')
  536. {
  537. if( !empty($this->Fields['templet']) )
  538. {
  539. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  540. }
  541. else
  542. {
  543. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
  544. }
  545. }
  546. if ( defined('DEDEMOB') )
  547. {
  548. $tmpfile =str_replace('.htm','_m.htm',$tmpfile);
  549. }
  550. if(!file_exists($tmpfile))
  551. {
  552. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid=='spec' ? 'article_spec.htm' : 'article_default.htm');
  553. if ( defined('DEDEMOB') )
  554. {
  555. $tmpfile =str_replace('.htm','_m.htm',$tmpfile);
  556. }
  557. }
  558. if (!preg_match("#.htm$#", $tmpfile)) return FALSE;
  559. return $tmpfile;
  560. }
  561. /**
  562. * 动态输出结果
  563. *
  564. * @access public
  565. * @return void
  566. */
  567. function display()
  568. {
  569. global $htmltype;
  570. if($this->IsError)
  571. {
  572. return '';
  573. }
  574. $this->Fields["displaytype"] = "dm";
  575. if($this->NowPage > 1) $this->Fields["title"] = $this->Fields["title"]."({$this->NowPage})";
  576. //预编译
  577. $this->LoadTemplet();
  578. $this->ParAddTable();
  579. $this->ParseTempletsFirst();
  580. //跳转网址
  581. $this->Fields['flag']=empty($this->Fields['flag'])? "" : $this->Fields['flag'];
  582. if(preg_match("#j#", $this->Fields['flag']) && $this->Fields['redirecturl'] != '')
  583. {
  584. if($GLOBALS['cfg_jump_once']=='N')
  585. {
  586. $pageHtml = "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$GLOBALS['cfg_soft_lang']."\">\r\n<title>".$this->Fields['title']."</title>\r\n";
  587. $pageHtml .= "<meta http-equiv=\"refresh\" content=\"3;URL=".$this->Fields['redirecturl']."\">\r\n</head>\r\n<body>\r\n";
  588. $pageHtml .= "现在正在转向:".$this->Fields['title'].",请稍候...<br/><br/>\r\n转向内容简介:".$this->Fields['description']."\r\n</body>\r\n</html>\r\n";
  589. echo $pageHtml;
  590. }
  591. else
  592. {
  593. header("location:{$this->Fields['redirecturl']}");
  594. }
  595. exit();
  596. }
  597. $pageCount = $this->NowPage;
  598. $this->ParseDMFields($pageCount,0);
  599. $this->dtp->display();
  600. }
  601. /**
  602. * 载入模板
  603. *
  604. * @access public
  605. * @return void
  606. */
  607. function LoadTemplet()
  608. {
  609. if($this->TempSource=='')
  610. {
  611. $tempfile = $this->GetTempletFile();
  612. if(!file_exists($tempfile) || !is_file($tempfile))
  613. {
  614. echo "文档ID:{$this->Fields['id']} - {$this->TypeLink->TypeInfos['typename']} - {$this->Fields['title']}<br />";
  615. echo "模板文件不存在,无法解析文档!";
  616. exit();
  617. }
  618. $this->dtp->LoadTemplate($tempfile);
  619. $this->TempSource = $this->dtp->SourceString;
  620. }
  621. else
  622. {
  623. $this->dtp->LoadSource($this->TempSource);
  624. }
  625. }
  626. /**
  627. * 解析模板,对固定的标记进行初始给值
  628. *
  629. * @access public
  630. * @return void
  631. */
  632. function ParseTempletsFirst()
  633. {
  634. if(empty($this->Fields['keywords']))
  635. {
  636. $this->Fields['keywords'] = '';
  637. }
  638. if(empty($this->Fields['reid']))
  639. {
  640. $this->Fields['reid'] = 0;
  641. }
  642. $GLOBALS['envs']['tags'] = $this->Fields['tags'];
  643. if(isset($this->TypeLink->TypeInfos['reid']))
  644. {
  645. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  646. }
  647. $GLOBALS['envs']['keyword'] = $this->Fields['keywords'];
  648. $GLOBALS['envs']['typeid'] = $this->Fields['typeid'];
  649. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  650. $GLOBALS['envs']['aid'] = $GLOBALS['envs']['id'] = $this->Fields['id'];
  651. $GLOBALS['envs']['adminid'] = $GLOBALS['envs']['mid'] = isset($this->Fields['mid'])? $this->Fields['mid'] : 1;
  652. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  653. if($this->Fields['reid']>0)
  654. {
  655. $GLOBALS['envs']['typeid'] = $this->Fields['reid'];
  656. }
  657. MakeOneTag($this->dtp, $this, 'N');
  658. }
  659. /**
  660. * 解析模板,对内容里的变动进行赋值
  661. *
  662. * @access public
  663. * @param string $pageNo 页码数
  664. * @param string $ismake 是否生成
  665. * @return string
  666. */
  667. function ParseDMFields($pageNo, $ismake=1)
  668. {
  669. $this->NowPage = $pageNo;
  670. $this->Fields['nowpage'] = $this->NowPage;
  671. if($this->SplitPageField!='' && isset($this->Fields[$this->SplitPageField]))
  672. {
  673. $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1];
  674. if($pageNo>1) $this->Fields['description'] = trim(preg_replace("/[\r\n\t]/", ' ', cn_substr(html2text($this->Fields[$this->SplitPageField]), 200)));
  675. }
  676. //解析模板
  677. if(is_array($this->dtp->CTags))
  678. {
  679. foreach($this->dtp->CTags as $i=>$ctag)
  680. {
  681. if($ctag->GetName()=='field')
  682. {
  683. $this->dtp->Assign($i, $this->GetField($ctag->GetAtt('name'), $ctag) );
  684. }
  685. else if($ctag->GetName()=='pagebreak')
  686. {
  687. if($ismake==0)
  688. {
  689. $this->dtp->Assign($i,$this->GetPagebreakDM($this->TotalPage,$this->NowPage,$this->ArcID));
  690. }
  691. else
  692. {
  693. $this->dtp->Assign($i,$this->GetPagebreak($this->TotalPage,$this->NowPage,$this->ArcID));
  694. }
  695. }
  696. else if($ctag->GetName()=='pagetitle')
  697. {
  698. if($ismake==0)
  699. {
  700. $this->dtp->Assign($i,$this->GetPageTitlesDM($ctag->GetAtt("style"),$pageNo));
  701. }
  702. else
  703. {
  704. $this->dtp->Assign($i,$this->GetPageTitlesST($ctag->GetAtt("style"),$pageNo));
  705. }
  706. }
  707. else if($ctag->GetName()=='prenext')
  708. {
  709. $this->dtp->Assign($i,$this->GetPreNext($ctag->GetAtt('get')));
  710. }
  711. else if($ctag->GetName()=='fieldlist')
  712. {
  713. $innertext = trim($ctag->GetInnerText());
  714. if($innertext=='') $innertext = GetSysTemplets('tag_fieldlist.htm');
  715. $dtp2 = new DedeTagParse();
  716. $dtp2->SetNameSpace('field','[',']');
  717. $dtp2->LoadSource($innertext);
  718. $oldSource = $dtp2->SourceString;
  719. $oldCtags = $dtp2->CTags;
  720. $res = '';
  721. if(is_array($this->ChannelUnit->ChannelFields) && is_array($dtp2->CTags))
  722. {
  723. foreach($this->ChannelUnit->ChannelFields as $k=>$v)
  724. {
  725. if(isset($v['autofield']) && empty($v['autofield'])) {
  726. continue;
  727. }
  728. $dtp2->SourceString = $oldSource;
  729. $dtp2->CTags = $oldCtags;
  730. $fname = $v['itemname'];
  731. foreach($dtp2->CTags as $tid=>$ctag2)
  732. {
  733. if($ctag2->GetName()=='name')
  734. {
  735. $dtp2->Assign($tid,$fname);
  736. }
  737. else if($ctag2->GetName()=='tagname')
  738. {
  739. $dtp2->Assign($tid,$k);
  740. }
  741. else if($ctag2->GetName()=='value')
  742. {
  743. $this->Fields[$k] = $this->ChannelUnit->MakeField($k,$this->Fields[$k],$ctag2);
  744. @$dtp2->Assign($tid,$this->Fields[$k]);
  745. }
  746. }
  747. $res .= $dtp2->GetResult();
  748. }
  749. }
  750. $this->dtp->Assign($i,$res);
  751. }//end case
  752. }//结束模板循环
  753. }
  754. }
  755. /**
  756. * 关闭所占用的资源
  757. *
  758. * @access public
  759. * @return void
  760. */
  761. function Close()
  762. {
  763. $this->FixedValues = '';
  764. $this->Fields = '';
  765. }
  766. /**
  767. * 获取上一篇,下一篇链接
  768. *
  769. * @access public
  770. * @param string $gtype 获取类型
  771. * pre:上一篇 preimg:上一篇图片 next:下一篇 nextimg:下一篇图片
  772. * @return string
  773. */
  774. function GetPreNext($gtype='')
  775. {
  776. $rs = '';
  777. if(count($this->PreNext)<2)
  778. {
  779. $aid = $this->ArcID;
  780. $preR = $this->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id desc");
  781. $nextR = $this->dsql->GetOne("Select id From `#@__arctiny` where id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id asc");
  782. $next = (is_array($nextR) ? " where arc.id={$nextR['id']} " : ' where 1>2 ');
  783. $pre = (is_array($preR) ? " where arc.id={$preR['id']} " : ' where 1>2 ');
  784. $query = "Select arc.id,arc.title,arc.shorttitle,arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,arc.filename,arc.litpic,
  785. t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath
  786. from `#@__archives` arc left join #@__arctype t on arc.typeid=t.id ";
  787. $nextRow = $this->dsql->GetOne($query.$next);
  788. $preRow = $this->dsql->GetOne($query.$pre);
  789. if(is_array($preRow))
  790. {
  791. if ( defined('DEDEMOB') )
  792. {
  793. $mlink = 'view.php?aid='.$preRow['id'];
  794. } else {
  795. $mlink = GetFileUrl($preRow['id'],$preRow['typeid'],$preRow['senddate'],$preRow['title'],$preRow['ismake'],$preRow['arcrank'],
  796. $preRow['namerule'],$preRow['typedir'],$preRow['money'],$preRow['filename'],$preRow['moresite'],$preRow['siteurl'],$preRow['sitepath']);
  797. }
  798. $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> ";
  799. $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$preRow['title']}\"/></a> ";
  800. }
  801. else
  802. {
  803. $this->PreNext['pre'] = "上一篇:没有了 ";
  804. $this->PreNext['preimg'] ="<img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有上一图集了!\"/>";
  805. }
  806. if(is_array($nextRow))
  807. {
  808. if ( defined('DEDEMOB') )
  809. {
  810. $mlink = 'view.php?aid='.$preRow['id'];
  811. } else {
  812. $mlink = GetFileUrl($nextRow['id'],$nextRow['typeid'],$nextRow['senddate'],$nextRow['title'],$nextRow['ismake'],$nextRow['arcrank'],
  813. $nextRow['namerule'],$nextRow['typedir'],$nextRow['money'],$nextRow['filename'],$nextRow['moresite'],$nextRow['siteurl'],$nextRow['sitepath']);
  814. }
  815. $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
  816. $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\"/></a> ";
  817. }
  818. else
  819. {
  820. $this->PreNext['next'] = "下一篇:没有了 ";
  821. $this->PreNext['nextimg'] ="<a href='javascript:void(0)' alt=\"\"><img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有下一图集了!\"/></a>";
  822. }
  823. }
  824. if($gtype=='pre')
  825. {
  826. $rs = $this->PreNext['pre'];
  827. }
  828. else if($gtype=='preimg'){
  829. $rs = $this->PreNext['preimg'];
  830. }
  831. else if($gtype=='next')
  832. {
  833. $rs = $this->PreNext['next'];
  834. }
  835. else if($gtype=='nextimg'){
  836. $rs = $this->PreNext['nextimg'];
  837. }
  838. else
  839. {
  840. $rs = $this->PreNext['pre']." &nbsp; ".$this->PreNext['next'];
  841. }
  842. return $rs;
  843. }
  844. /**
  845. * 获得动态页面分页列表
  846. *
  847. * @access public
  848. * @param int $totalPage 总页数
  849. * @param int $nowPage 当前页数
  850. * @param int $aid 文档id
  851. * @return string
  852. */
  853. function GetPagebreakDM($totalPage, $nowPage, $aid)
  854. {
  855. global $cfg_rewrite;
  856. if($totalPage==1)
  857. {
  858. return "";
  859. }
  860. $PageList = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共".$totalPage."页: </span></li>";
  861. $nPage = $nowPage-1;
  862. $lPage = $nowPage+1;
  863. if($nowPage==1)
  864. {
  865. $PageList.="<li class='page-item d-none d-sm-block disabled'><a class='page-link' href='#'>上一页</a></li>";
  866. }
  867. else
  868. {
  869. if($nPage==1)
  870. {
  871. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>上一页</a></li>";
  872. if($cfg_rewrite == 'Y')
  873. {
  874. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  875. }
  876. }
  877. else
  878. {
  879. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$nPage'>上一页</a></li>";
  880. if($cfg_rewrite == 'Y')
  881. {
  882. $PageList = str_replace(".php?aid=", "-", $PageList);
  883. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  884. }
  885. }
  886. }
  887. for($i=1;$i<=$totalPage;$i++)
  888. {
  889. if($i==1)
  890. {
  891. if($nowPage!=1)
  892. {
  893. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>1</a></li>";
  894. if($cfg_rewrite == 'Y')
  895. {
  896. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  897. }
  898. }
  899. else
  900. {
  901. $PageList.="<li class=\"page-item active\"><a class='page-link'>1</a></li>";
  902. }
  903. }
  904. else
  905. {
  906. $n = $i;
  907. if($nowPage!=$i)
  908. {
  909. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$i'>".$n."</a></li>";
  910. if($cfg_rewrite == 'Y')
  911. {
  912. $PageList = str_replace(".php?aid=", "-", $PageList);
  913. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  914. }
  915. }
  916. else
  917. {
  918. $PageList.="<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  919. }
  920. }
  921. }
  922. if($lPage <= $totalPage)
  923. {
  924. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$lPage'>下一页</a></li>";
  925. if($cfg_rewrite == 'Y')
  926. {
  927. $PageList = str_replace(".php?aid=", "-", $PageList);
  928. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  929. }
  930. }
  931. else
  932. {
  933. $PageList.= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  934. }
  935. return $PageList;
  936. }
  937. /**
  938. * 获得静态页面分页列表
  939. *
  940. * @access public
  941. * @param int $totalPage 总页数
  942. * @param int $nowPage 当前页数
  943. * @param int $aid 文档id
  944. * @return string
  945. */
  946. function GetPagebreak($totalPage, $nowPage, $aid)
  947. {
  948. if($totalPage==1)
  949. {
  950. return "";
  951. }
  952. $PageList = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共".$totalPage."页: </span></li>";
  953. $nPage = $nowPage-1;
  954. $lPage = $nowPage+1;
  955. if($nowPage==1)
  956. {
  957. $PageList.="<li class='page-item d-none d-sm-block disabled'><a class='page-link' href='#'>上一页</a></li>";
  958. }
  959. else
  960. {
  961. if($nPage==1)
  962. {
  963. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>上一页</a></li>";
  964. }
  965. else
  966. {
  967. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$nPage.".".$this->ShortName."'>上一页</a></li>";
  968. }
  969. }
  970. for($i=1;$i<=$totalPage;$i++)
  971. {
  972. if($i==1)
  973. {
  974. if($nowPage!=1)
  975. {
  976. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>1</a></li>";
  977. }
  978. else
  979. {
  980. $PageList.="<li class=\"page-item active\"><span class='page-link'>1</span></li>";
  981. }
  982. }
  983. else
  984. {
  985. $n = $i;
  986. if($nowPage!=$i)
  987. {
  988. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$i.".".$this->ShortName."'>".$n."</a></li>";
  989. }
  990. else
  991. {
  992. $PageList.="<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  993. }
  994. }
  995. }
  996. if($lPage <= $totalPage)
  997. {
  998. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$lPage.".".$this->ShortName."'>下一页</a></li>";
  999. }
  1000. else
  1001. {
  1002. $PageList.= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  1003. }
  1004. return $PageList;
  1005. }
  1006. /**
  1007. * 获得动态页面小标题
  1008. *
  1009. * @access public
  1010. * @param string $styleName 类型名称
  1011. * @param string $pageNo 页码数
  1012. * @return string
  1013. */
  1014. function GetPageTitlesDM($styleName, $pageNo)
  1015. {
  1016. if($this->TotalPage==1)
  1017. {
  1018. return "";
  1019. }
  1020. if(count($this->SplitTitles)==0)
  1021. {
  1022. return "";
  1023. }
  1024. $i=1;
  1025. $aid = $this->ArcID;
  1026. if($styleName=='link')
  1027. {
  1028. $revalue = "";
  1029. foreach($this->SplitTitles as $k=>$v)
  1030. {
  1031. if($i==1)
  1032. {
  1033. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> \r\n";
  1034. }
  1035. else
  1036. {
  1037. if($pageNo==$i)
  1038. {
  1039. $revalue .= " $v \r\n";
  1040. }
  1041. else
  1042. {
  1043. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> \r\n";
  1044. }
  1045. }
  1046. $i++;
  1047. }
  1048. }
  1049. else
  1050. {
  1051. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  1052. foreach($this->SplitTitles as $k=>$v)
  1053. {
  1054. if($i==1)
  1055. {
  1056. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  1057. }
  1058. else
  1059. {
  1060. if($pageNo==$i)
  1061. {
  1062. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i' selected>{$i}、{$v}</option>\r\n";
  1063. }
  1064. else
  1065. {
  1066. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  1067. }
  1068. }
  1069. $i++;
  1070. }
  1071. $revalue .= "</select>\r\n";
  1072. }
  1073. return $revalue;
  1074. }
  1075. /**
  1076. * 获得静态页面小标题
  1077. *
  1078. * @access public
  1079. * @param string $styleName 类型名称
  1080. * @param string $pageNo 页码数
  1081. * @return string
  1082. */
  1083. function GetPageTitlesST($styleName, $pageNo)
  1084. {
  1085. if($this->TotalPage==1)
  1086. {
  1087. return "";
  1088. }
  1089. if(count($this->SplitTitles)==0)
  1090. {
  1091. return "";
  1092. }
  1093. $i=1;
  1094. if($styleName=='link')
  1095. {
  1096. $revalue = "";
  1097. foreach($this->SplitTitles as $k=>$v)
  1098. {
  1099. if($i==1)
  1100. {
  1101. $revalue .= "<a href='".$this->NameFirst.".".$this->ShortName."'>$v</a> \r\n";
  1102. }
  1103. else
  1104. {
  1105. if($pageNo==$i)
  1106. {
  1107. $revalue .= " $v \r\n";
  1108. }
  1109. else
  1110. {
  1111. $revalue .= "<a href='".$this->NameFirst."_".$i.".".$this->ShortName."'>$v</a> \r\n";
  1112. }
  1113. }
  1114. $i++;
  1115. }
  1116. }
  1117. else
  1118. {
  1119. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  1120. foreach($this->SplitTitles as $k=>$v)
  1121. {
  1122. if($i==1)
  1123. {
  1124. $revalue .= "<option value='".$this->NameFirst.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  1125. }
  1126. else
  1127. {
  1128. if($pageNo==$i)
  1129. {
  1130. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."' selected>{$i}、{$v}</option>\r\n";
  1131. }
  1132. else
  1133. {
  1134. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  1135. }
  1136. }
  1137. $i++;
  1138. }
  1139. $revalue .= "</select>\r\n";
  1140. }
  1141. return $revalue;
  1142. }
  1143. /**
  1144. * 高亮问题修正, 排除alt title <a></a>直接的字符替换
  1145. *
  1146. * @param string $kw
  1147. * @param string $body
  1148. * @return string
  1149. */
  1150. function ReplaceKeyword($kw,&$body)
  1151. {
  1152. global $cfg_cmspath;
  1153. $maxkey = 5;
  1154. $kws = explode(",",trim($kw)); //以分好为间隔符
  1155. $i=0;
  1156. $karr = $kaarr = $GLOBALS['replaced'] = array();
  1157. //暂时屏蔽超链接
  1158. $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
  1159. /*
  1160. foreach($kws as $k)
  1161. {
  1162. $k = trim($k);
  1163. if($k!="")
  1164. {
  1165. if($i > $maxkey)
  1166. {
  1167. break;
  1168. }
  1169. $myrow = $this->dsql->GetOne("SELECT * FROM #@__keywords WHERE keyword='$k' AND rpurl<>'' ");
  1170. if(is_array($myrow))
  1171. {
  1172. $karr[] = $k;
  1173. $GLOBALS['replaced'][$k] = 0;
  1174. $kaarr[] = "<a href='{$myrow['rpurl']}'><u>$k</u></a>";
  1175. }
  1176. $i++;
  1177. }
  1178. }
  1179. */
  1180. $query = "SELECT * FROM #@__keywords WHERE rpurl<>'' ORDER BY rank DESC";
  1181. $this->dsql->SetQuery($query);
  1182. $this->dsql->Execute();
  1183. while($row = $this->dsql->GetArray())
  1184. {
  1185. $key = trim($row['keyword']);
  1186. $key_url=trim($row['rpurl']);
  1187. $karr[] = $key;
  1188. $kaarr[] = "<a href='$key_url' target='_blank'><u>$key</u></a>";
  1189. }
  1190. // 这里可能会有错误
  1191. if (version_compare(PHP_VERSION, '5.5.0', '>='))
  1192. {
  1193. $body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
  1194. } else {
  1195. $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
  1196. }
  1197. //恢复超链接
  1198. $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
  1199. return $body;
  1200. }
  1201. }//End Archives
  1202. //高亮专用, 替换多次是可能不能达到最多次
  1203. function _highlight($string, $words, $result, $pre)
  1204. {
  1205. global $cfg_replace_num;
  1206. if (version_compare(PHP_VERSION, '5.5.0', '>='))
  1207. {
  1208. $string = $string[0];
  1209. $pre = $pre[0];
  1210. }
  1211. $string = str_replace('\"', '"', $string);
  1212. if($cfg_replace_num > 0)
  1213. {
  1214. foreach ($words as $key => $word)
  1215. {
  1216. if($GLOBALS['replaced'][$word] == 1)
  1217. {
  1218. continue;
  1219. }
  1220. $string = preg_replace("#".preg_quote($word)."#", $result[$key], $string, $cfg_replace_num);
  1221. if(strpos($string, $word) !== FALSE)
  1222. {
  1223. $GLOBALS['replaced'][$word] = 1;
  1224. }
  1225. }
  1226. }
  1227. else
  1228. {
  1229. $string = str_replace($words, $result, $string);
  1230. }
  1231. return $pre.$string;
  1232. }