DedeV6移动版
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.

1034 line
46KB

  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 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 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 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. } //!error
  124. }
  125. //php4构造函数
  126. function Archives($aid)
  127. {
  128. $this->__construct($aid);
  129. }
  130. /**
  131. * 解析附加表的文档
  132. *
  133. * @access public
  134. * @return void
  135. */
  136. function ParAddTable()
  137. {
  138. //读取附加表信息,并把附加表的资料经过编译处理后导入到$this->Fields中,以方便在模板中用“{dede:field name='fieldname'/}”标记统一调用
  139. if ($this->ChannelUnit->ChannelInfos['addtable'] != '') {
  140. $row = $this->addTableRow;
  141. if ($this->ChannelUnit->ChannelInfos['issystem'] == -1) {
  142. $this->Fields['title'] = $row['title'];
  143. $this->Fields['senddate'] = $this->Fields['pubdate'] = $row['senddate'];
  144. $this->Fields['mid'] = $this->Fields['adminid'] = $row['mid'];
  145. $this->Fields['ismake'] = 1;
  146. $this->Fields['arcrank'] = 0;
  147. $this->Fields['money'] = 0;
  148. $this->Fields['filename'] = '';
  149. }
  150. if (is_array($row)) {
  151. foreach ($row as $k => $v) $row[strtolower($k)] = stripcslashes($v);
  152. }
  153. if (is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields)) {
  154. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  155. if (isset($row[$k])) {
  156. if (!empty($arr['rename'])) {
  157. $nk = $arr['rename'];
  158. } else {
  159. $nk = $k;
  160. }
  161. $cobj = $this->GetCurTag($k);
  162. if (is_object($cobj)) {
  163. foreach ($this->dtp->CTags as $ctag) {
  164. if ($ctag->GetTagName() == 'field' && $ctag->GetAtt('name') == $k) {
  165. //带标识的专题节点
  166. if ($ctag->GetAtt('noteid') != '') {
  167. $this->Fields[$k.'_'.$ctag->GetAtt('noteid')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  168. }
  169. //带类型的字段节点
  170. else if ($ctag->GetAtt('type') != '') {
  171. $this->Fields[$k.'_'.$ctag->GetAtt('type')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  172. }
  173. //其它字段
  174. else {
  175. $this->Fields[$nk] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  176. }
  177. }
  178. }
  179. } else {
  180. $this->Fields[$nk] = $row[$k];
  181. }
  182. if ($arr['type'] == 'htmltext' && $GLOBALS['cfg_keyword_replace'] == 'Y' && !empty($this->Fields['keywords'])) {
  183. $this->Fields[$nk] = $this->ReplaceKeyword($this->Fields['keywords'], $this->Fields[$nk]);
  184. }
  185. }
  186. } //End foreach
  187. }
  188. //设置全局环境变量
  189. $this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
  190. @SetSysEnv($this->Fields['typeid'], $this->Fields['typename'], $this->Fields['id'], $this->Fields['title'], 'archives');
  191. //文档模型正文图片注释自动为标题
  192. $this->Fields['body'] = str_ireplace(array('alt=""','alt=\'\''),'',$this->Fields['body']);
  193. $this->Fields['body'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU","",$this->Fields['body']);
  194. $this->Fields['body'] = str_ireplace("<img","<img alt=\"".$this->Fields['title']."\" title=\"".$this->Fields['title']."\" ",$this->Fields['body']);
  195. //图片模型正文图片注释自动为标题
  196. if (isset($this->Fields['imgurls']) && is_array($this->Fields['imgurls'])) {
  197. $this->Fields['imgurls'] = str_ireplace(array('alt=""','alt=\'\''),'',$this->Fields['imgurls']);
  198. $this->Fields['imgurls'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU","",$this->Fields['imgurls']);
  199. $this->Fields['imgurls'] = str_ireplace("<img","<img alt=\"".$this->Fields['title']."\" title=\"".$this->Fields['title']."\"",$this->Fields['imgurls']);
  200. }
  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, $m = 0)
  285. {
  286. global $fileFirst, $cfg_basehost;
  287. if ($this->IsError) {
  288. return '';
  289. }
  290. $this->Fields["displaytype"] = "st";
  291. //预编译$th
  292. $this->LoadTemplet($m);//发布文档同步手机端
  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. $filename = GetFileNewName(
  303. $this->ArcID,
  304. $this->Fields['typeid'],
  305. $this->Fields['senddate'],
  306. $this->Fields['title'],
  307. $this->Fields['ismake'],
  308. $this->Fields['arcrank'],
  309. ($m?'/m/':'').$this->TypeLink->TypeInfos['namerule'],
  310. $this->TypeLink->TypeInfos['typedir'],
  311. $this->Fields['money'],
  312. $this->Fields['filename']
  313. );
  314. $filenames = explode(".", $filename);
  315. $this->ShortName = $filenames[count($filenames) - 1];
  316. if ($this->ShortName == '') $this->ShortName = 'html';
  317. $fileFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filename);
  318. $this->Fields['namehand'] = basename($fileFirst);
  319. $filenames = explode("/", $filename);
  320. $this->NameFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filenames[count($filenames) - 1]);
  321. if ($this->NameFirst == '') {
  322. $this->NameFirst = $this->ArcID;
  323. }
  324. //获得当前文档的全名
  325. $filenameFull = GetFileUrl(
  326. $this->ArcID,
  327. $this->Fields['typeid'],
  328. $this->Fields["senddate"],
  329. $this->Fields["title"],
  330. $this->Fields["ismake"],
  331. $this->Fields["arcrank"],
  332. $this->TypeLink->TypeInfos['namerule'],
  333. $this->TypeLink->TypeInfos['typedir'],
  334. $this->Fields["money"],
  335. $this->Fields['filename'],
  336. $this->TypeLink->TypeInfos['moresite'],
  337. $this->TypeLink->TypeInfos['siteurl'],
  338. $this->TypeLink->TypeInfos['sitepath']
  339. );
  340. $this->Fields['arcurl'] = $this->Fields['fullname'] = $filenameFull;
  341. //对于已设置不生成网页的文档直接返回网址
  342. if (
  343. $this->Fields['ismake'] == -1 || $this->Fields['arcrank'] != 0 || $this->Fields['money'] > 0 || ($this->Fields['typeid'] == 0 && $this->Fields['channel'] != -1)) {
  344. return $this->GetTrueUrl($filename);
  345. }
  346. //循环生成网页文件
  347. else {
  348. $seoUrls = array();
  349. for ($i = 1; $i <= $this->TotalPage; $i++) {
  350. if ($this->TotalPage > 1) {
  351. $this->Fields['tmptitle'] = (empty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']);
  352. if ($i > 1) $this->Fields['title'] = $this->Fields['tmptitle']."($i)";
  353. }
  354. if ($i > 1) {
  355. $TRUEfilename = $this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName;
  356. $URLFilename = $fileFirst."_".$i.".".$this->ShortName;
  357. } else {
  358. $TRUEfilename = $this->GetTruePath().$filename;
  359. $URLFilename = $filename;
  360. }
  361. $seoUrls = array_merge($seoUrls, array($cfg_basehost.$URLFilename));
  362. $this->ParseDMFields($i, 1);
  363. $this->dtp->SaveTo($TRUEfilename);
  364. }
  365. }
  366. $this->dsql->ExecuteNoneQuery("UPDATE `#@__archives` SET ismake=1 WHERE id='".$this->ArcID."'");
  367. return $this->GetTrueUrl($filename);
  368. }
  369. /**
  370. * 获得真实连接路径
  371. *
  372. * @access public
  373. * @param string $nurl 连接
  374. * @return string
  375. */
  376. function GetTrueUrl($nurl)
  377. {
  378. return GetFileUrl(
  379. $this->Fields['id'],
  380. $this->Fields['typeid'],
  381. $this->Fields['senddate'],
  382. $this->Fields['title'],
  383. $this->Fields['ismake'],
  384. $this->Fields['arcrank'],
  385. $this->TypeLink->TypeInfos['namerule'],
  386. $this->TypeLink->TypeInfos['typedir'],
  387. $this->Fields['money'],
  388. $this->Fields['filename'],
  389. $this->TypeLink->TypeInfos['moresite'],
  390. $this->TypeLink->TypeInfos['siteurl'],
  391. $this->TypeLink->TypeInfos['sitepath']
  392. );
  393. }
  394. /**
  395. * 获得站点的真实根路径
  396. *
  397. * @access public
  398. * @return string
  399. */
  400. function GetTruePath()
  401. {
  402. $TRUEpath = $GLOBALS["cfg_basedir"];
  403. return $TRUEpath;
  404. }
  405. /**
  406. * 获得指定键值的字段
  407. *
  408. * @access public
  409. * @param string $fname 键名称
  410. * @param object $ctag 标记
  411. * @return string
  412. */
  413. function GetField($fname, $ctag)
  414. {
  415. //所有Field数组 OR 普通Field
  416. if ($fname == 'array') {
  417. return $this->Fields;
  418. }
  419. //指定了ID的节点
  420. else if ($ctag->GetAtt('noteid') != '') {
  421. if (isset($this->Fields[$fname.'_'.$ctag->GetAtt('noteid')])) {
  422. return $this->Fields[$fname.'_'.$ctag->GetAtt('noteid')];
  423. }
  424. }
  425. //指定了type的节点
  426. else if ($ctag->GetAtt('type') != '') {
  427. if (isset($this->Fields[$fname.'_'.$ctag->GetAtt('type')])) {
  428. return $this->Fields[$fname.'_'.$ctag->GetAtt('type')];
  429. }
  430. } else if (isset($this->Fields[$fname])) {
  431. return $this->Fields[$fname];
  432. }
  433. return '';
  434. }
  435. /**
  436. * 获得模板文件位置
  437. *
  438. * @access public
  439. * @return string
  440. */
  441. function GetTempletFile()
  442. {
  443. global $cfg_basedir, $cfg_templets_dir, $cfg_df_style;
  444. $cid = $this->ChannelUnit->ChannelInfos['nid'];
  445. if (!empty($this->Fields['templet'])) {
  446. $filetag = MfTemplet($this->Fields['templet']);
  447. if (!preg_match("#\/#", $filetag)) $filetag = $GLOBALS['cfg_df_style'].'/'.$filetag;
  448. } else {
  449. $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
  450. }
  451. $tid = $this->Fields['typeid'];
  452. $filetag = str_replace('{cid}', $cid, $filetag);
  453. $filetag = str_replace('{tid}', $tid, $filetag);
  454. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  455. if ($cid == 'spec') {
  456. if (!empty($this->Fields['templet'])) {
  457. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  458. } else {
  459. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
  460. }
  461. }
  462. if (defined('DEDEMOB')) {
  463. $tmpfile = str_replace('.htm', '_m.htm', $tmpfile);
  464. }
  465. if (!file_exists($tmpfile)) {
  466. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid == 'spec' ? 'article_spec.htm' : 'article_default.htm');
  467. if (defined('DEDEMOB')) {
  468. $tmpfile = str_replace('.htm', '_m.htm', $tmpfile);
  469. }
  470. }
  471. if (!preg_match("#.htm$#", $tmpfile)) return FALSE;
  472. return $tmpfile;
  473. }
  474. /**
  475. * 动态输出结果
  476. *
  477. * @access public
  478. * @return void
  479. */
  480. function display()
  481. {
  482. global $htmltype;
  483. if ($this->IsError) {
  484. return '';
  485. }
  486. $this->Fields["displaytype"] = "dm";
  487. if ($this->NowPage > 1) $this->Fields["title"] = $this->Fields["title"]."({$this->NowPage})";
  488. //预编译
  489. $this->LoadTemplet();
  490. $this->ParAddTable();
  491. $this->ParseTempletsFirst();
  492. //跳转网址
  493. $this->Fields['flag'] = empty($this->Fields['flag']) ? "" : $this->Fields['flag'];
  494. if (preg_match("#j#", $this->Fields['flag']) && $this->Fields['redirecturl'] != '') {
  495. if ($GLOBALS['cfg_jump_once'] == 'N') {
  496. $pageHtml = "<html>\r\n<head>\r\n<meta charset=".$GLOBALS['cfg_soft_lang']."\">\r\n<title>".$this->Fields['title']."</title>\r\n";
  497. $pageHtml .= "<meta http-equiv=\"refresh\" content=\"3;URL=".$this->Fields['redirecturl']."\">\r\n</head>\r\n<body>\r\n";
  498. $pageHtml .= "正在前往文档:".$this->Fields['title']."<br><br>\r\n文档描述:".$this->Fields['description']."\r\n</body>\r\n</html>\r\n";
  499. echo $pageHtml;
  500. } else {
  501. header("location:{$this->Fields['redirecturl']}");
  502. }
  503. exit();
  504. }
  505. $pageCount = $this->NowPage;
  506. $this->ParseDMFields($pageCount, 0);
  507. $this->dtp->display();
  508. }
  509. /**
  510. * 载入模板
  511. *
  512. * @access public
  513. * @return void
  514. */
  515. function LoadTemplet()
  516. {
  517. if ($this->TempSource == '') {
  518. $tempfile = $this->GetTempletFile();
  519. if (!file_exists($tempfile) || !is_file($tempfile)) {
  520. echo "文档id:{$this->Fields['id']} - {$this->TypeLink->TypeInfos['typename']} - {$this->Fields['title']}<br>";
  521. echo "主题模板文件不存在,无法发布文档";
  522. exit();
  523. }
  524. $this->dtp->LoadTemplate($tempfile);
  525. $this->TempSource = $this->dtp->SourceString;
  526. } else {
  527. $this->dtp->LoadSource($this->TempSource);
  528. }
  529. }
  530. /**
  531. * 解析模板,对固定的标记进行初始给值
  532. *
  533. * @access public
  534. * @return void
  535. */
  536. function ParseTempletsFirst()
  537. {
  538. if (empty($this->Fields['keywords'])) {
  539. $this->Fields['keywords'] = '';
  540. }
  541. if (empty($this->Fields['reid'])) {
  542. $this->Fields['reid'] = 0;
  543. }
  544. $GLOBALS['envs']['tags'] = $this->Fields['tags'];
  545. if (isset($this->TypeLink->TypeInfos['reid'])) {
  546. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  547. }
  548. $GLOBALS['envs']['keyword'] = $this->Fields['keywords'];
  549. $GLOBALS['envs']['typeid'] = $this->Fields['typeid'];
  550. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  551. $GLOBALS['envs']['aid'] = $GLOBALS['envs']['id'] = $this->Fields['id'];
  552. $GLOBALS['envs']['adminid'] = $GLOBALS['envs']['mid'] = isset($this->Fields['mid']) ? $this->Fields['mid'] : 1;
  553. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  554. if ($this->Fields['reid'] > 0) {
  555. $GLOBALS['envs']['typeid'] = $this->Fields['reid'];
  556. }
  557. MakeOneTag($this->dtp, $this, 'N');
  558. }
  559. /**
  560. * 解析模板,对文档里的变动进行赋值
  561. *
  562. * @access public
  563. * @param string $pageNo 页码数
  564. * @param string $ismake 是否生成
  565. * @return string
  566. */
  567. function ParseDMFields($pageNo, $ismake = 1)
  568. {
  569. $this->NowPage = $pageNo;
  570. $this->Fields['nowpage'] = $this->NowPage;
  571. if ($this->SplitPageField != '' && isset($this->Fields[$this->SplitPageField])) {
  572. $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1];
  573. if ($pageNo > 1) $this->Fields['description'] = trim(preg_replace("/[\r\n\t]/", ' ', cn_substr(html2text($this->Fields[$this->SplitPageField]), 200)));
  574. }
  575. //解析模板
  576. if (is_array($this->dtp->CTags)) {
  577. foreach ($this->dtp->CTags as $i => $ctag) {
  578. if ($ctag->GetName() == 'field') {
  579. $this->dtp->Assign($i, $this->GetField($ctag->GetAtt('name'), $ctag));
  580. } else if ($ctag->GetName() == 'pagebreak') {
  581. if ($ismake == 0) {
  582. $this->dtp->Assign($i, $this->GetPagebreakDM($this->TotalPage, $this->NowPage, $this->ArcID));
  583. } else {
  584. $this->dtp->Assign($i, $this->GetPagebreak($this->TotalPage, $this->NowPage, $this->ArcID));
  585. }
  586. } else if ($ctag->GetName() == 'pagetitle') {
  587. if ($ismake == 0) {
  588. $this->dtp->Assign($i, $this->GetPageTitlesDM($ctag->GetAtt("style"), $pageNo));
  589. } else {
  590. $this->dtp->Assign($i, $this->GetPageTitlesST($ctag->GetAtt("style"), $pageNo));
  591. }
  592. } else if ($ctag->GetName() == 'prenext') {
  593. $this->dtp->Assign($i, $this->GetPreNext($ctag->GetAtt('get')));
  594. }
  595. //添加上一篇下一篇标签{dede:prenextdiy get='pre'}{/dede:prenextdiy}{dede:prenextdiy get='next'}{/dede:prenextdiy}
  596. else if ($ctag->GetName()=='prenextdiy')
  597. {
  598. $innertext = trim($ctag->GetInnerText());
  599. if ($innertext) {
  600. $get = $ctag->GetAtt('get');
  601. $diys['diy'] = $this->GetPreNext('diy');
  602. $revalue = '';
  603. $dtp2 = new DedeTagParse();
  604. $dtp2->SetNameSpace('field','[',']');
  605. $dtp2->LoadSource($innertext);
  606. foreach($diys as $row)
  607. {
  608. foreach($dtp2->CTags as $tid=>$ctag2)
  609. {
  610. if (isset($row[$get][$ctag2->GetName()])) {
  611. $dtp2->Assign($tid,$row[$get][$ctag2->GetName()]);
  612. }
  613. }
  614. $revalue .= $dtp2->GetResult();
  615. }
  616. if ($row[$get]['id']) $this->dtp->Assign($i,$revalue);
  617. }
  618. }
  619. else if ($ctag->GetName() == 'fieldlist') {
  620. $innertext = trim($ctag->GetInnerText());
  621. if ($innertext == '') $innertext = GetSysTemplets('tag_fieldlist.htm');
  622. $dtp2 = new DedeTagParse();
  623. $dtp2->SetNameSpace('field', '[', ']');
  624. $dtp2->LoadSource($innertext);
  625. $oldSource = $dtp2->SourceString;
  626. $oldCtags = $dtp2->CTags;
  627. $res = '';
  628. if (is_array($this->ChannelUnit->ChannelFields) && is_array($dtp2->CTags)) {
  629. foreach ($this->ChannelUnit->ChannelFields as $k => $v) {
  630. if (isset($v['autofield']) && empty($v['autofield'])) {
  631. continue;
  632. }
  633. $dtp2->SourceString = $oldSource;
  634. $dtp2->CTags = $oldCtags;
  635. $fname = $v['itemname'];
  636. foreach ($dtp2->CTags as $tid => $ctag2) {
  637. if ($ctag2->GetName() == 'name') {
  638. $dtp2->Assign($tid, $fname);
  639. } else if ($ctag2->GetName() == 'tagname') {
  640. $dtp2->Assign($tid, $k);
  641. } else if ($ctag2->GetName() == 'value') {
  642. if (isset($this->Fields[$k])) {
  643. $this->Fields[$k] = $this->ChannelUnit->MakeField($k, $this->Fields[$k], $ctag2);
  644. @$dtp2->Assign($tid, $this->Fields[$k]);
  645. }
  646. }
  647. }
  648. $res .= $dtp2->GetResult();
  649. }
  650. }
  651. $this->dtp->Assign($i, $res);
  652. } //end case
  653. } //结束模板循环
  654. }
  655. }
  656. /**
  657. * 关闭所占用的资源
  658. *
  659. * @access public
  660. * @return void
  661. */
  662. function Close()
  663. {
  664. $this->FixedValues = '';
  665. $this->Fields = '';
  666. }
  667. /**
  668. * 获取上一篇和下一篇链接
  669. *
  670. * @access public
  671. * @param string $gtype pre为上一篇,preimg为上一篇图片,next为下一篇,nextimg为下一篇图片
  672. * @return string
  673. */
  674. function GetPreNext($gtype = '')
  675. {
  676. $rs = '';
  677. if (count($this->PreNext) < 2) {
  678. $aid = $this->ArcID;
  679. $preR = $this->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' ORDER BY id DESC");
  680. $nextR = $this->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' ORDER BY id ASC");
  681. $next = (is_array($nextR) ? " WHERE arc.id={$nextR['id']} " : ' WHERE 1>2 ');
  682. $pre = (is_array($preR) ? " WHERE arc.id={$preR['id']} " : ' WHERE 1>2 ');
  683. $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 ";
  684. $nextRow = $this->dsql->GetOne($query.$next);
  685. $preRow = $this->dsql->GetOne($query.$pre);
  686. if (is_array($preRow)) {
  687. $mlink = GetFileUrl(
  688. $preRow['id'],
  689. $preRow['typeid'],
  690. $preRow['senddate'],
  691. $preRow['title'],
  692. $preRow['ismake'],
  693. $preRow['arcrank'],
  694. $preRow['namerule'],
  695. $preRow['typedir'],
  696. $preRow['money'],
  697. $preRow['filename'],
  698. $preRow['moresite'],
  699. $preRow['siteurl'],
  700. $preRow['sitepath']
  701. );
  702. $preRow['litpic'] = (empty($preRow['litpic'])) ? $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg' : $preRow['litpic'];
  703. $this->PreNext['diy']['pre']['id'] = $preRow['id'];
  704. $this->PreNext['diy']['pre']['arcurl'] = $mlink;
  705. $this->PreNext['diy']['pre']['title'] = $preRow['title'];
  706. $this->PreNext['diy']['pre']['litpic'] = $preRow['litpic'];
  707. $this->PreNext['diy']['pre']['pubdate'] = $preRow['senddate'];
  708. $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a>";
  709. $this->PreNext['prem'] = "上一篇:<a href='view.php?aid={$preRow['id']}'>{$preRow['title']}</a>";//手机端上一篇
  710. $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$nextRow['title']}\" title=\"{$preRow['title']}\"></a> ";
  711. } else {
  712. $this->PreNext['pre'] = "上一篇:暂无";
  713. $this->PreNext['preimg'] = "";
  714. }
  715. if (is_array($nextRow)) {
  716. $mlink = GetFileUrl(
  717. $nextRow['id'],
  718. $nextRow['typeid'],
  719. $nextRow['senddate'],
  720. $nextRow['title'],
  721. $nextRow['ismake'],
  722. $nextRow['arcrank'],
  723. $nextRow['namerule'],
  724. $nextRow['typedir'],
  725. $nextRow['money'],
  726. $nextRow['filename'],
  727. $nextRow['moresite'],
  728. $nextRow['siteurl'],
  729. $nextRow['sitepath']
  730. );
  731. $nextRow['litpic'] = (empty($nextRow['litpic'])) ? $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg' : $nextRow['litpic'];
  732. $this->PreNext['diy']['next']['id'] = $nextRow['id'];
  733. $this->PreNext['diy']['next']['arcurl'] = $mlink;
  734. $this->PreNext['diy']['next']['title'] = $nextRow['title'];
  735. $this->PreNext['diy']['next']['litpic'] = $nextRow['litpic'];
  736. $this->PreNext['diy']['next']['pubdate'] = $nextRow['senddate'];
  737. $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
  738. $this->PreNext['nextm'] = "下一篇:<a href='view.php?aid={$nextRow['id']}'>{$nextRow['title']}</a>";//手机端下一篇
  739. $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\" title=\"{$preRow['title']}\"></a> ";
  740. } else {
  741. $this->PreNext['next'] = "下一篇:暂无";
  742. $this->PreNext['nextimg'] = "";
  743. }
  744. }
  745. if ($gtype=='diy') {
  746. return $this->PreNext['diy'];
  747. } if ($gtype=='pre') {
  748. $rs = $this->PreNext['pre'];
  749. } else if ($gtype == 'preimg') {
  750. $rs = $this->PreNext['preimg'];
  751. } else if ($gtype == 'next') {
  752. $rs = $this->PreNext['next'];
  753. } else if ($gtype == 'nextimg') {
  754. $rs = $this->PreNext['nextimg'];
  755. } else if ($gtype=='prem') {
  756. $rs = $this->PreNext['prem'];
  757. } else if ($gtype=='nextm') {
  758. $rs = $this->PreNext['nextm'];
  759. } else {
  760. $rs = $this->PreNext['pre']." &nbsp; ".$this->PreNext['next'];
  761. }
  762. return $rs;
  763. }
  764. /**
  765. * 获得动态页面分页列表
  766. *
  767. * @access public
  768. * @param int $totalPage 总页数
  769. * @param int $nowPage 当前页数
  770. * @param int $aid 文档id
  771. * @return string
  772. */
  773. function GetPagebreakDM($totalPage, $nowPage, $aid)
  774. {
  775. global $cfg_rewrite;
  776. if ($totalPage == 1) {
  777. return "";
  778. }
  779. $PageList = "<li class='page-item disabled'><span class='page-link'>".$totalPage."页</span></li>";
  780. $nPage = $nowPage - 1;
  781. $lPage = $nowPage + 1;
  782. if ($nowPage == 1) {
  783. $PageList .= "<li class='page-item disabled'><a class='page-link' href='javascript:;'>上一页</a></li>";
  784. } else {
  785. if ($nPage == 1) {
  786. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>上一页</a></li>";
  787. if ($cfg_rewrite == 'Y' && !defined('DEDEMOB')) {
  788. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  789. }
  790. } else {
  791. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$nPage'>上一页</a></li>";
  792. if ($cfg_rewrite == 'Y' && !defined('DEDEMOB')) {
  793. $PageList = str_replace(".php?aid=", "-", $PageList);
  794. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  795. }
  796. }
  797. }
  798. for ($i = 1; $i <= $totalPage; $i++) {
  799. if ($i == 1) {
  800. if ($nowPage != 1) {
  801. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>1</a></li>";
  802. if ($cfg_rewrite == 'Y' && !defined('DEDEMOB')) {
  803. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  804. }
  805. } else {
  806. $PageList .= "<li class=\"page-item active\"><a class='page-link'>1</a></li>";
  807. }
  808. } else {
  809. $n = $i;
  810. if ($nowPage != $i) {
  811. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$i'>".$n."</a></li>";
  812. if ($cfg_rewrite == 'Y' && !defined('DEDEMOB')) {
  813. $PageList = str_replace(".php?aid=", "-", $PageList);
  814. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  815. }
  816. } else {
  817. $PageList .= "<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  818. }
  819. }
  820. }
  821. if ($lPage <= $totalPage) {
  822. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$lPage'>下一页</a></li>";
  823. if ($cfg_rewrite == 'Y' && !defined('DEDEMOB')) {
  824. $PageList = str_replace(".php?aid=", "-", $PageList);
  825. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  826. }
  827. } else {
  828. $PageList .= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  829. }
  830. return $PageList;
  831. }
  832. /**
  833. * 获得静态页面分页列表
  834. *
  835. * @access public
  836. * @param int $totalPage 总页数
  837. * @param int $nowPage 当前页数
  838. * @param int $aid 文档id
  839. * @return string
  840. */
  841. function GetPagebreak($totalPage, $nowPage, $aid)
  842. {
  843. if ($totalPage == 1) {
  844. return "";
  845. }
  846. $PageList = "<li class='page-item disabled'><span class='page-link'>".$totalPage."页:</span></li>";
  847. $nPage = $nowPage - 1;
  848. $lPage = $nowPage + 1;
  849. if ($nowPage == 1) {
  850. $PageList .= "<li class='page-item disabled'><a class='page-link' href='javascript:;'>上一页</a></li>";
  851. } else {
  852. if ($nPage == 1) {
  853. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>上一页</a></li>";
  854. } else {
  855. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$nPage.".".$this->ShortName."'>上一页</a></li>";
  856. }
  857. }
  858. for ($i = 1; $i <= $totalPage; $i++) {
  859. if ($i == 1) {
  860. if ($nowPage != 1) {
  861. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>1</a></li>";
  862. } else {
  863. $PageList .= "<li class=\"page-item active\"><span class='page-link'>1</span></li>";
  864. }
  865. } else {
  866. $n = $i;
  867. if ($nowPage != $i) {
  868. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$i.".".$this->ShortName."'>".$n."</a></li>";
  869. } else {
  870. $PageList .= "<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  871. }
  872. }
  873. }
  874. if ($lPage <= $totalPage) {
  875. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$lPage.".".$this->ShortName."'>下一页</a></li>";
  876. } else {
  877. $PageList .= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  878. }
  879. return $PageList;
  880. }
  881. /**
  882. * 获得动态页面小标题
  883. *
  884. * @access public
  885. * @param string $styleName 类型名称
  886. * @param string $pageNo 页码数
  887. * @return string
  888. */
  889. function GetPageTitlesDM($styleName, $pageNo)
  890. {
  891. if ($this->TotalPage == 1) {
  892. return "";
  893. }
  894. if (count($this->SplitTitles) == 0) {
  895. return "";
  896. }
  897. $i = 1;
  898. $aid = $this->ArcID;
  899. if ($styleName == 'link') {
  900. $revalue = "";
  901. foreach ($this->SplitTitles as $k => $v) {
  902. if ($i == 1) {
  903. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a>\r\n";
  904. } else {
  905. if ($pageNo == $i) {
  906. $revalue .= " $v \r\n";
  907. } else {
  908. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a>\r\n";
  909. }
  910. }
  911. $i++;
  912. }
  913. } else {
  914. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  915. foreach ($this->SplitTitles as $k => $v) {
  916. if ($i == 1) {
  917. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  918. } else {
  919. if ($pageNo == $i) {
  920. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i' selected>{$i}、{$v}</option>\r\n";
  921. } else {
  922. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  923. }
  924. }
  925. $i++;
  926. }
  927. $revalue .= "</select>\r\n";
  928. }
  929. return $revalue;
  930. }
  931. /**
  932. * 获得静态页面小标题
  933. *
  934. * @access public
  935. * @param string $styleName 类型名称
  936. * @param string $pageNo 页码数
  937. * @return string
  938. */
  939. function GetPageTitlesST($styleName, $pageNo)
  940. {
  941. if ($this->TotalPage == 1) {
  942. return "";
  943. }
  944. if (count($this->SplitTitles) == 0) {
  945. return "";
  946. }
  947. $i = 1;
  948. if ($styleName == 'link') {
  949. $revalue = "";
  950. foreach ($this->SplitTitles as $k => $v) {
  951. if ($i == 1) {
  952. $revalue .= "<a href='".$this->NameFirst.".".$this->ShortName."'>$v</a>\r\n";
  953. } else {
  954. if ($pageNo == $i) {
  955. $revalue .= " $v \r\n";
  956. } else {
  957. $revalue .= "<a href='".$this->NameFirst."_".$i.".".$this->ShortName."'>$v</a>\r\n";
  958. }
  959. }
  960. $i++;
  961. }
  962. } else {
  963. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  964. foreach ($this->SplitTitles as $k => $v) {
  965. if ($i == 1) {
  966. $revalue .= "<option value='".$this->NameFirst.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  967. } else {
  968. if ($pageNo == $i) {
  969. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."' selected>{$i}、{$v}</option>\r\n";
  970. } else {
  971. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  972. }
  973. }
  974. $i++;
  975. }
  976. $revalue .= "</select>\r\n";
  977. }
  978. return $revalue;
  979. }
  980. /**
  981. * 高亮问题修正,排除alt title <a></a>直接的字符替换
  982. *
  983. * @param string $kw
  984. * @param string $body
  985. * @return string
  986. */
  987. function ReplaceKeyword($kw,&$body)
  988. {
  989. $karr = $kaarr = $GLOBALS['replaced'] = array();
  990. //暂时屏蔽超链接
  991. $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
  992. $query = "SELECT * FROM `#@__keywords` WHERE rpurl<>'' ORDER BY `rank` DESC";
  993. $this->dsql->SetQuery($query);
  994. $this->dsql->Execute();
  995. while ($row = $this->dsql->GetArray()) {
  996. $key = trim($row['keyword']);
  997. $key_url = trim($row['rpurl']);
  998. $karr[] = $key;
  999. $kaarr[] = "<a href='$key_url' target='_blank'>$key</a>";
  1000. }
  1001. $GLOBALS['_dd_karr'] = $karr;
  1002. $GLOBALS['_dd_kaarr'] = $kaarr;
  1003. $body = preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlightkeywords", $body);
  1004. //恢复超链接
  1005. $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
  1006. return $body;
  1007. }
  1008. }//End Archives
  1009. function _highlightkeywords($matches)
  1010. {
  1011. return _highlight($matches[2], $GLOBALS['_dd_karr'], $GLOBALS['_dd_kaarr'], $matches[1]);
  1012. }
  1013. //高亮专用
  1014. function _highlight($string, $words, $result, $pre)
  1015. {
  1016. global $cfg_replace_num;
  1017. $string = str_replace('\"', '"', $string);
  1018. if ($cfg_replace_num > 0) {
  1019. foreach ($words as $key => $word) {
  1020. if ($GLOBALS['replaced'][$word] == 1) {
  1021. continue;
  1022. }
  1023. $string = preg_replace("#".preg_quote($word)."#", $result[$key], $string, $cfg_replace_num);
  1024. if (strpos($string, $word) !== FALSE) {
  1025. $GLOBALS['replaced'][$word] = 1;
  1026. }
  1027. }
  1028. } else {
  1029. $string = str_replace($words, $result, $string);
  1030. }
  1031. return $pre.$string;
  1032. }
  1033. ?>