国内流行的内容管理系统(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.

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