DedeV6移动版
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1040 lines
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. $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. $this->Fields['body'] = preg_replace("/style=\"width\:(.*)\"/","",$this->Fields['body']);
  203. }
  204. //完成附加表信息读取
  205. unset($row);
  206. //处理要分页显示的字段
  207. $this->SplitTitles = array();
  208. if ($this->SplitPageField != '' && $GLOBALS['cfg_arcsptitle'] = 'Y' && isset($this->Fields[$this->SplitPageField])) {
  209. $this->SplitFields = explode("#p#", $this->Fields[$this->SplitPageField]);
  210. $i = 1;
  211. foreach ($this->SplitFields as $k => $v) {
  212. $tmpv = cn_substr($v, 50);
  213. $pos = strpos($tmpv, '#e#');
  214. if ($pos > 0) {
  215. $st = trim(cn_substr($tmpv, $pos));
  216. if ($st == "" || $st == "副标题" || $st == "分页标题") {
  217. $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is", "", $v);
  218. continue;
  219. } else {
  220. $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is", "", $v);
  221. $this->SplitTitles[$k] = $st;
  222. }
  223. } else {
  224. continue;
  225. }
  226. $i++;
  227. }
  228. $this->TotalPage = count($this->SplitFields);
  229. $this->Fields['totalpage'] = $this->TotalPage;
  230. }
  231. //处理默认缩略图等
  232. if (isset($this->Fields['litpic'])) {
  233. if ($this->Fields['litpic'] == '-' || $this->Fields['litpic'] == '') {
  234. $this->Fields['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  235. }
  236. if (!preg_match("#^http:\/\/#i", $this->Fields['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  237. $this->Fields['litpic'] = $GLOBALS['cfg_mainsite'].$this->Fields['litpic'];
  238. }
  239. $this->Fields['picname'] = $this->Fields['litpic'];
  240. //模板里直接使用{dede:field name='image'/}获取缩略图
  241. $this->Fields['image'] = (!preg_match('/jpg|gif|png/i', $this->Fields['picname']) ? '' : "<img src='{$this->Fields['picname']}' />");
  242. }
  243. //处理投票选项
  244. if (isset($this->Fields['voteid']) && !empty($this->Fields['voteid'])) {
  245. $this->Fields['vote'] = '';
  246. $voteid = $this->Fields['voteid'];
  247. $this->Fields['vote'] = "<script src='{$GLOBALS['cfg_cmspath']}/data/vote/vote_{$voteid}.js'></script>";
  248. if ($GLOBALS['cfg_multi_site'] == 'Y') {
  249. $this->Fields['vote'] = "<script src='{$GLOBALS['cfg_mainsite']}/data/vote/vote_{$voteid}.js'></script>";
  250. }
  251. }
  252. if (isset($this->Fields['goodpost']) && isset($this->Fields['badpost'])) {
  253. //digg
  254. if ($this->Fields['goodpost'] + $this->Fields['badpost'] == 0) {
  255. $this->Fields['goodper'] = $this->Fields['badper'] = 0;
  256. } else {
  257. $this->Fields['goodper'] = number_format($this->Fields['goodpost'] / ($this->Fields['goodpost'] + $this->Fields['badpost']), 3) * 100;
  258. $this->Fields['badper'] = 100 - $this->Fields['goodper'];
  259. }
  260. }
  261. }
  262. //获得当前字段参数
  263. function GetCurTag($fieldname)
  264. {
  265. if (!isset($this->dtp->CTags)) {
  266. return '';
  267. }
  268. foreach ($this->dtp->CTags as $ctag) {
  269. if ($ctag->GetTagName() == 'field' && $ctag->GetAtt('name') == $fieldname) {
  270. return $ctag;
  271. } else {
  272. continue;
  273. }
  274. }
  275. return '';
  276. }
  277. /**
  278. * 生成静态网页
  279. *
  280. * @access public
  281. * @param int $isremote 是否远程
  282. * @return string
  283. */
  284. function MakeHtml($isremote = 0)
  285. {
  286. global $fileFirst, $cfg_basehost, $dedebiz_path, $dedebiz_arcrule, $dedebiz_usearc;
  287. if ($this->IsError) {
  288. return '';
  289. }
  290. $this->Fields["displaytype"] = "st";
  291. //预编译$th
  292. $this->LoadTemplet();
  293. $this->ParAddTable();
  294. $this->ParseTempletsFirst();
  295. $this->Fields['senddate'] = empty($this->Fields['senddate']) ? '' : $this->Fields['senddate'];
  296. $this->Fields['title'] = empty($this->Fields['title']) ? '' : $this->Fields['title'];
  297. $this->Fields['arcrank'] = empty($this->Fields['arcrank']) ? 0 : $this->Fields['arcrank'];
  298. $this->Fields['ismake'] = empty($this->Fields['ismake']) ? 0 : $this->Fields['ismake'];
  299. $this->Fields['money'] = empty($this->Fields['money']) ? 0 : $this->Fields['money'];
  300. $this->Fields['filename'] = empty($this->Fields['filename']) ? '' : $this->Fields['filename'];
  301. //文档命名规则
  302. $dedebiz_path = rtrim($dedebiz_path,'/') ? rtrim($dedebiz_path,'/') : '/m';
  303. if ($dedebiz_usearc==0 && $dedebiz_arcrule) {
  304. $this->TypeLink->TypeInfos['namerule'] = $dedebiz_path.$dedebiz_arcrule;
  305. }
  306. else $this->TypeLink->TypeInfos['namerule'] = $dedebiz_path.$this->TypeLink->TypeInfos['namerule'];
  307. //分析要创建的文件名称
  308. $filename = GetFileNewName(
  309. $this->ArcID,
  310. $this->Fields['typeid'],
  311. $this->Fields['senddate'],
  312. $this->Fields['title'],
  313. $this->Fields['ismake'],
  314. $this->Fields['arcrank'],
  315. $this->TypeLink->TypeInfos['namerule'],
  316. $this->TypeLink->TypeInfos['typedir'],
  317. $this->Fields['money'],
  318. $this->Fields['filename']
  319. );
  320. $filenames = explode(".", $filename);
  321. $this->ShortName = $filenames[count($filenames) - 1];
  322. if ($this->ShortName == '') $this->ShortName = 'html';
  323. $fileFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filename);
  324. $this->Fields['namehand'] = basename($fileFirst);
  325. $filenames = explode("/", $filename);
  326. $this->NameFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filenames[count($filenames) - 1]);
  327. if ($this->NameFirst == '') {
  328. $this->NameFirst = $this->arcID;
  329. }
  330. //获得当前文档的全名
  331. $filenameFull = GetFileUrl(
  332. $this->ArcID,
  333. $this->Fields['typeid'],
  334. $this->Fields["senddate"],
  335. $this->Fields["title"],
  336. $this->Fields["ismake"],
  337. $this->Fields["arcrank"],
  338. $this->TypeLink->TypeInfos['namerule'],
  339. $this->TypeLink->TypeInfos['typedir'],
  340. $this->Fields["money"],
  341. $this->Fields['filename'],
  342. $this->TypeLink->TypeInfos['moresite'],
  343. $this->TypeLink->TypeInfos['siteurl'],
  344. $this->TypeLink->TypeInfos['sitepath']
  345. );
  346. $this->Fields['arcurl'] = $this->Fields['fullname'] = $filenameFull;
  347. //对于已设置不生成网页的文档直接返回网址
  348. if (
  349. $this->Fields['ismake'] == -1 || $this->Fields['arcrank'] != 0 || $this->Fields['money'] > 0 || ($this->Fields['typeid'] == 0 && $this->Fields['channel'] != -1)) {
  350. return $this->GetTrueUrl($filename);
  351. }
  352. //循环生成网页文件
  353. else {
  354. $seoUrls = array();
  355. for ($i = 1; $i <= $this->TotalPage; $i++) {
  356. if ($this->TotalPage > 1) {
  357. $this->Fields['tmptitle'] = (empty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']);
  358. if ($i > 1) $this->Fields['title'] = $this->Fields['tmptitle']."($i)";
  359. }
  360. if ($i > 1) {
  361. $TRUEfilename = $this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName;
  362. $URLFilename = $fileFirst."_".$i.".".$this->ShortName;
  363. } else {
  364. $TRUEfilename = $this->GetTruePath().$filename;
  365. $URLFilename = $filename;
  366. }
  367. $seoUrls = array_merge($seoUrls, array($cfg_basehost.$URLFilename));
  368. $this->ParseDMFields($i, 1);
  369. $this->dtp->SaveTo($TRUEfilename);
  370. }
  371. }
  372. $this->dsql->ExecuteNoneQuery("UPDATE `#@__archives` SET ismake=1 WHERE id='".$this->ArcID."'");
  373. return $this->GetTrueUrl($filename);
  374. }
  375. /**
  376. * 获得真实连接路径
  377. *
  378. * @access public
  379. * @param string $nurl 连接
  380. * @return string
  381. */
  382. function GetTrueUrl($nurl)
  383. {
  384. return GetFileUrl(
  385. $this->Fields['id'],
  386. $this->Fields['typeid'],
  387. $this->Fields['senddate'],
  388. $this->Fields['title'],
  389. $this->Fields['ismake'],
  390. $this->Fields['arcrank'],
  391. $this->TypeLink->TypeInfos['namerule'],
  392. $this->TypeLink->TypeInfos['typedir'],
  393. $this->Fields['money'],
  394. $this->Fields['filename'],
  395. $this->TypeLink->TypeInfos['moresite'],
  396. $this->TypeLink->TypeInfos['siteurl'],
  397. $this->TypeLink->TypeInfos['sitepath']
  398. );
  399. }
  400. /**
  401. * 获得站点的真实根路径
  402. *
  403. * @access public
  404. * @return string
  405. */
  406. function GetTruePath()
  407. {
  408. $TRUEpath = $GLOBALS["cfg_basedir"];
  409. return $TRUEpath;
  410. }
  411. /**
  412. * 获得指定键值的字段
  413. *
  414. * @access public
  415. * @param string $fname 键名称
  416. * @param object $ctag 标记
  417. * @return string
  418. */
  419. function GetField($fname, $ctag)
  420. {
  421. //所有Field数组 OR 普通Field
  422. if ($fname == 'array') {
  423. return $this->Fields;
  424. }
  425. //指定了ID的节点
  426. else if ($ctag->GetAtt('noteid') != '') {
  427. if (isset($this->Fields[$fname.'_'.$ctag->GetAtt('noteid')])) {
  428. return $this->Fields[$fname.'_'.$ctag->GetAtt('noteid')];
  429. }
  430. }
  431. //指定了type的节点
  432. else if ($ctag->GetAtt('type') != '') {
  433. if (isset($this->Fields[$fname.'_'.$ctag->GetAtt('type')])) {
  434. return $this->Fields[$fname.'_'.$ctag->GetAtt('type')];
  435. }
  436. } else if (isset($this->Fields[$fname])) {
  437. return $this->Fields[$fname];
  438. }
  439. return '';
  440. }
  441. /**
  442. * 获得模板文件位置
  443. *
  444. * @access public
  445. * @return string
  446. */
  447. function GetTempletFile()
  448. {
  449. global $cfg_basedir, $cfg_templets_dir, $cfg_df_style;
  450. $cid = $this->ChannelUnit->ChannelInfos['nid'];
  451. if (!empty($this->Fields['templet'])) {
  452. $filetag = MfTemplet($this->Fields['templet']);
  453. if (!preg_match("#\/#", $filetag)) $filetag = $GLOBALS['cfg_df_style'].'/'.$filetag;
  454. } else {
  455. $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
  456. }
  457. $tid = $this->Fields['typeid'];
  458. $filetag = str_replace('{cid}', $cid, $filetag);
  459. $filetag = str_replace('{tid}', $tid, $filetag);
  460. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  461. if ($cid == 'spec') {
  462. if (!empty($this->Fields['templet'])) {
  463. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  464. } else {
  465. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
  466. }
  467. }
  468. if ($this->is_mobile) {
  469. $tmpfile = str_replace('.htm', '_m.htm', $tmpfile);
  470. }
  471. if (!file_exists($tmpfile)) {
  472. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid == 'spec' ? 'article_spec.htm' : 'article_default.htm');
  473. if ($this->is_mobile) {
  474. $tmpfile = str_replace('.htm', '_m.htm', $tmpfile);
  475. }
  476. }
  477. if (!preg_match("#.htm$#", $tmpfile)) return FALSE;
  478. return $tmpfile;
  479. }
  480. /**
  481. * 动态输出结果
  482. *
  483. * @access public
  484. * @return void
  485. */
  486. function display()
  487. {
  488. global $htmltype;
  489. if ($this->IsError) {
  490. return '';
  491. }
  492. $this->Fields["displaytype"] = "dm";
  493. if ($this->NowPage > 1) $this->Fields["title"] = $this->Fields["title"]."({$this->NowPage})";
  494. //预编译
  495. $this->LoadTemplet();
  496. $this->ParAddTable();
  497. $this->ParseTempletsFirst();
  498. //跳转网址
  499. $this->Fields['flag'] = empty($this->Fields['flag']) ? "" : $this->Fields['flag'];
  500. if (preg_match("#j#", $this->Fields['flag']) && $this->Fields['redirecturl'] != '') {
  501. if ($GLOBALS['cfg_jump_once'] == 'N') {
  502. $pageHtml = "<html>\r\n<head>\r\n<meta charset=".$GLOBALS['cfg_soft_lang']."\">\r\n<title>".$this->Fields['title']."</title>\r\n";
  503. $pageHtml .= "<meta http-equiv=\"refresh\" content=\"3;URL=".$this->Fields['redirecturl']."\">\r\n</head>\r\n<body>\r\n";
  504. $pageHtml .= "正在跳转文档:".$this->Fields['title']."<br><br>\r\n文档描述:".$this->Fields['description']."\r\n</body>\r\n</html>\r\n";
  505. echo $pageHtml;
  506. } else {
  507. header("location:{$this->Fields['redirecturl']}");
  508. }
  509. exit();
  510. }
  511. $pageCount = $this->NowPage;
  512. $this->ParseDMFields($pageCount, 0);
  513. $this->dtp->display();
  514. }
  515. /**
  516. * 载入模板
  517. *
  518. * @access public
  519. * @return void
  520. */
  521. function LoadTemplet()
  522. {
  523. if ($this->TempSource == '') {
  524. $tempfile = $this->GetTempletFile();
  525. if (!file_exists($tempfile) || !is_file($tempfile)) {
  526. echo "文档id:{$this->Fields['id']} - {$this->TypeLink->TypeInfos['typename']} - {$this->Fields['title']}<br>";
  527. echo "主题模板文件不存在,无法发布文档";
  528. exit();
  529. }
  530. $this->dtp->LoadTemplate($tempfile);
  531. $this->TempSource = $this->dtp->SourceString;
  532. } else {
  533. $this->dtp->LoadSource($this->TempSource);
  534. }
  535. }
  536. /**
  537. * 解析模板,对固定的标记进行初始给值
  538. *
  539. * @access public
  540. * @return void
  541. */
  542. function ParseTempletsFirst()
  543. {
  544. if (empty($this->Fields['keywords'])) {
  545. $this->Fields['keywords'] = '';
  546. }
  547. if (empty($this->Fields['reid'])) {
  548. $this->Fields['reid'] = 0;
  549. }
  550. $GLOBALS['envs']['tags'] = $this->Fields['tags'];
  551. if (isset($this->TypeLink->TypeInfos['reid'])) {
  552. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  553. }
  554. $GLOBALS['envs']['keyword'] = $this->Fields['keywords'];
  555. $GLOBALS['envs']['typeid'] = $this->Fields['typeid'];
  556. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  557. $GLOBALS['envs']['aid'] = $GLOBALS['envs']['id'] = $this->Fields['id'];
  558. $GLOBALS['envs']['adminid'] = $GLOBALS['envs']['mid'] = isset($this->Fields['mid']) ? $this->Fields['mid'] : 1;
  559. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  560. if ($this->Fields['reid'] > 0) {
  561. $GLOBALS['envs']['typeid'] = $this->Fields['reid'];
  562. }
  563. MakeOneTag($this->dtp, $this, 'N');
  564. }
  565. /**
  566. * 解析模板,对文档里的变动进行赋值
  567. *
  568. * @access public
  569. * @param string $pageNo 页码数
  570. * @param string $ismake 是否生成
  571. * @return string
  572. */
  573. function ParseDMFields($pageNo, $ismake = 1)
  574. {
  575. $this->NowPage = $pageNo;
  576. $this->Fields['nowpage'] = $this->NowPage;
  577. if ($this->SplitPageField != '' && isset($this->Fields[$this->SplitPageField])) {
  578. $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1];
  579. if ($pageNo > 1) $this->Fields['description'] = trim(preg_replace("/[\r\n\t]/", ' ', cn_substr(html2text($this->Fields[$this->SplitPageField]), 200)));
  580. }
  581. //解析模板
  582. if (is_array($this->dtp->CTags)) {
  583. foreach ($this->dtp->CTags as $i => $ctag) {
  584. if ($ctag->GetName() == 'field') {
  585. $this->dtp->Assign($i, $this->GetField($ctag->GetAtt('name'), $ctag));
  586. } else if ($ctag->GetName() == 'pagebreak') {
  587. if ($ismake == 0) {
  588. $this->dtp->Assign($i, $this->GetPagebreakDM($this->TotalPage, $this->NowPage, $this->ArcID));
  589. } else {
  590. $this->dtp->Assign($i, $this->GetPagebreak($this->TotalPage, $this->NowPage, $this->ArcID));
  591. }
  592. } else if ($ctag->GetName() == 'pagetitle') {
  593. if ($ismake == 0) {
  594. $this->dtp->Assign($i, $this->GetPageTitlesDM($ctag->GetAtt("style"), $pageNo));
  595. } else {
  596. $this->dtp->Assign($i, $this->GetPageTitlesST($ctag->GetAtt("style"), $pageNo));
  597. }
  598. } else if ($ctag->GetName() == 'prenext') {
  599. $this->dtp->Assign($i, $this->GetPreNext($ctag->GetAtt('get')));
  600. }
  601. //添加上一篇下一篇标签{dede:prenextdiy get='pre'}{/dede:prenextdiy}{dede:prenextdiy get='next'}{/dede:prenextdiy}
  602. else if ($ctag->GetName()=='prenextdiy')
  603. {
  604. $innertext = trim($ctag->GetInnerText());
  605. if ($innertext) {
  606. $get = $ctag->GetAtt('get');
  607. $diys['diy'] = $this->GetPreNext('diy');
  608. $revalue = '';
  609. $dtp2 = new DedeTagParse();
  610. $dtp2->SetNameSpace('field','[',']');
  611. $dtp2->LoadSource($innertext);
  612. foreach($diys as $row)
  613. {
  614. foreach($dtp2->CTags as $tid=>$ctag2)
  615. {
  616. if (isset($row[$get][$ctag2->GetName()])) {
  617. $dtp2->Assign($tid,$row[$get][$ctag2->GetName()]);
  618. }
  619. }
  620. $revalue .= $dtp2->GetResult();
  621. }
  622. if ($row[$get]['id']) $this->dtp->Assign($i,$revalue);
  623. }
  624. }
  625. else if ($ctag->GetName() == 'fieldlist') {
  626. $innertext = trim($ctag->GetInnerText());
  627. if ($innertext == '') $innertext = GetSysTemplets('tag_fieldlist.htm');
  628. $dtp2 = new DedeTagParse();
  629. $dtp2->SetNameSpace('field', '[', ']');
  630. $dtp2->LoadSource($innertext);
  631. $oldSource = $dtp2->SourceString;
  632. $oldCtags = $dtp2->CTags;
  633. $res = '';
  634. if (is_array($this->ChannelUnit->ChannelFields) && is_array($dtp2->CTags)) {
  635. foreach ($this->ChannelUnit->ChannelFields as $k => $v) {
  636. if (isset($v['autofield']) && empty($v['autofield'])) {
  637. continue;
  638. }
  639. $dtp2->SourceString = $oldSource;
  640. $dtp2->CTags = $oldCtags;
  641. $fname = $v['itemname'];
  642. foreach ($dtp2->CTags as $tid => $ctag2) {
  643. if ($ctag2->GetName() == 'name') {
  644. $dtp2->Assign($tid, $fname);
  645. } else if ($ctag2->GetName() == 'tagname') {
  646. $dtp2->Assign($tid, $k);
  647. } else if ($ctag2->GetName() == 'value') {
  648. if (isset($this->Fields[$k])) {
  649. $this->Fields[$k] = $this->ChannelUnit->MakeField($k, $this->Fields[$k], $ctag2);
  650. @$dtp2->Assign($tid, $this->Fields[$k]);
  651. }
  652. }
  653. }
  654. $res .= $dtp2->GetResult();
  655. }
  656. }
  657. $this->dtp->Assign($i, $res);
  658. } //end case
  659. } //结束模板循环
  660. }
  661. }
  662. /**
  663. * 关闭所占用的资源
  664. *
  665. * @access public
  666. * @return void
  667. */
  668. function Close()
  669. {
  670. $this->FixedValues = '';
  671. $this->Fields = '';
  672. }
  673. /**
  674. * 获取上一篇和下一篇链接
  675. *
  676. * @access public
  677. * @param string $gtype pre为上一篇,preimg为上一篇图片,next为下一篇,nextimg为下一篇图片
  678. * @return string
  679. */
  680. function GetPreNext($gtype = '')
  681. {
  682. $rs = '';
  683. if (count($this->PreNext) < 2) {
  684. $aid = $this->ArcID;
  685. $preR = $this->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' ORDER BY id DESC");
  686. $nextR = $this->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' ORDER BY id ASC");
  687. $next = (is_array($nextR) ? " WHERE arc.id={$nextR['id']} " : ' WHERE 1>2 ');
  688. $pre = (is_array($preR) ? " WHERE arc.id={$preR['id']} " : ' WHERE 1>2 ');
  689. $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 ";
  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. $preRow['litpic'] = (empty($preRow['litpic'])) ? $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg' : $preRow['litpic'];
  709. $this->PreNext['diy']['pre']['id'] = $preRow['id'];
  710. $this->PreNext['diy']['pre']['arcurl'] = $mlink;
  711. $this->PreNext['diy']['pre']['title'] = $preRow['title'];
  712. $this->PreNext['diy']['pre']['litpic'] = $preRow['litpic'];
  713. $this->PreNext['diy']['pre']['pubdate'] = $preRow['senddate'];
  714. $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a>";
  715. $this->PreNext['prem'] = "上一篇:<a href='view.php?aid={$preRow['id']}'>{$preRow['title']}</a>";//手机端上一篇
  716. $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$nextRow['title']}\" title=\"{$preRow['title']}\"></a> ";
  717. } else {
  718. $this->PreNext['pre'] = "上一篇:暂无";
  719. $this->PreNext['preimg'] = "";
  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. $nextRow['litpic'] = (empty($nextRow['litpic'])) ? $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg' : $nextRow['litpic'];
  738. $this->PreNext['diy']['next']['id'] = $nextRow['id'];
  739. $this->PreNext['diy']['next']['arcurl'] = $mlink;
  740. $this->PreNext['diy']['next']['title'] = $nextRow['title'];
  741. $this->PreNext['diy']['next']['litpic'] = $nextRow['litpic'];
  742. $this->PreNext['diy']['next']['pubdate'] = $nextRow['senddate'];
  743. $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
  744. $this->PreNext['nextm'] = "下一篇:<a href='view.php?aid={$nextRow['id']}'>{$nextRow['title']}</a>";//手机端下一篇
  745. $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\" title=\"{$preRow['title']}\"></a> ";
  746. } else {
  747. $this->PreNext['next'] = "下一篇:暂无";
  748. $this->PreNext['nextimg'] = "";
  749. }
  750. }
  751. if ($gtype=='diy') {
  752. return $this->PreNext['diy'];
  753. } if ($gtype=='pre') {
  754. $rs = $this->PreNext['pre'];
  755. } else if ($gtype == 'preimg') {
  756. $rs = $this->PreNext['preimg'];
  757. } else if ($gtype == 'next') {
  758. $rs = $this->PreNext['next'];
  759. } else if ($gtype == 'nextimg') {
  760. $rs = $this->PreNext['nextimg'];
  761. } else if ($gtype=='prem') {
  762. $rs = $this->PreNext['prem'];
  763. } else if ($gtype=='nextm') {
  764. $rs = $this->PreNext['nextm'];
  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 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 disabled'><a class='page-link' href='javascript:;'>上一页</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' && !defined('DEDEMOB')) {
  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' && !defined('DEDEMOB')) {
  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' && !defined('DEDEMOB')) {
  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' && !defined('DEDEMOB')) {
  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' && !defined('DEDEMOB')) {
  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 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 disabled'><a class='page-link' href='javascript:;'>上一页</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. $karr = $kaarr = $GLOBALS['replaced'] = array();
  996. //暂时屏蔽超链接
  997. $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
  998. $query = "SELECT * FROM `#@__keywords` WHERE rpurl<>'' ORDER BY `rank` DESC";
  999. $this->dsql->SetQuery($query);
  1000. $this->dsql->Execute();
  1001. while ($row = $this->dsql->GetArray()) {
  1002. $key = trim($row['keyword']);
  1003. $key_url = trim($row['rpurl']);
  1004. $karr[] = $key;
  1005. $kaarr[] = "<a href='$key_url' target='_blank'>$key</a>";
  1006. }
  1007. $GLOBALS['_dd_karr'] = $karr;
  1008. $GLOBALS['_dd_kaarr'] = $kaarr;
  1009. $body = preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlightkeywords", $body);
  1010. //恢复超链接
  1011. $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
  1012. return $body;
  1013. }
  1014. }//End Archives
  1015. function _highlightkeywords($matches)
  1016. {
  1017. return _highlight($matches[2], $GLOBALS['_dd_karr'], $GLOBALS['_dd_kaarr'], $matches[1]);
  1018. }
  1019. //高亮专用,替换多次是可能不能达到最多次
  1020. function _highlight($string, $words, $result, $pre)
  1021. {
  1022. global $cfg_replace_num;
  1023. $string = str_replace('\"', '"', $string);
  1024. if ($cfg_replace_num > 0) {
  1025. foreach ($words as $key => $word) {
  1026. if ($GLOBALS['replaced'][$word] == 1) {
  1027. continue;
  1028. }
  1029. $string = preg_replace("#".preg_quote($word)."#", $result[$key], $string, $cfg_replace_num);
  1030. if (strpos($string, $word) !== FALSE) {
  1031. $GLOBALS['replaced'][$word] = 1;
  1032. }
  1033. }
  1034. } else {
  1035. $string = str_replace($words, $result, $string);
  1036. }
  1037. return $pre.$string;
  1038. }
  1039. ?>