DedeV6移动版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1026 linhas
45KB

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