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

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