国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

1055 satır
47KB

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