DedeV6移动版
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1042 рядки
46KB

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