国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1035 lines
46KB

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