国内流行的内容管理系统(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.

1046 lines
48KB

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