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

1030 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)] = stripcslashes($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 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 pre为上一篇 preimg为上一篇图片 next为下一篇 nextimg为下一篇图片
  669. * @return string
  670. */
  671. function GetPreNext($gtype = '')
  672. {
  673. $rs = '';
  674. if (count($this->PreNext) < 2) {
  675. $aid = $this->ArcID;
  676. $preR = $this->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' ORDER BY id DESC");
  677. $nextR = $this->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' ORDER BY id ASC");
  678. $next = (is_array($nextR) ? " WHERE arc.id={$nextR['id']} " : ' WHERE 1>2 ');
  679. $pre = (is_array($preR) ? " WHERE arc.id={$preR['id']} " : ' WHERE 1>2 ');
  680. $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 ";
  681. $nextRow = $this->dsql->GetOne($query.$next);
  682. $preRow = $this->dsql->GetOne($query.$pre);
  683. if (is_array($preRow)) {
  684. $mlink = GetFileUrl(
  685. $preRow['id'],
  686. $preRow['typeid'],
  687. $preRow['senddate'],
  688. $preRow['title'],
  689. $preRow['ismake'],
  690. $preRow['arcrank'],
  691. $preRow['namerule'],
  692. $preRow['typedir'],
  693. $preRow['money'],
  694. $preRow['filename'],
  695. $preRow['moresite'],
  696. $preRow['siteurl'],
  697. $preRow['sitepath']
  698. );
  699. //二次开发上一篇属性
  700. $preRow['litpic'] = (empty($preRow['litpic'])) ? $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg' : $preRow['litpic'];
  701. $this->PreNext['diy']['pre']['id'] = $preRow['id'];
  702. $this->PreNext['diy']['pre']['arcurl'] = $mlink;
  703. $this->PreNext['diy']['pre']['title'] = $preRow['title'];
  704. $this->PreNext['diy']['pre']['litpic'] = $preRow['litpic'];
  705. $this->PreNext['diy']['pre']['pubdate'] = $preRow['senddate'];
  706. $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a>";
  707. $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$nextRow['title']}\" title=\"{$preRow['title']}\"></a> ";
  708. } else {
  709. $this->PreNext['pre'] = "上一篇:暂无";
  710. $this->PreNext['preimg'] = "";
  711. }
  712. if (is_array($nextRow)) {
  713. $mlink = GetFileUrl(
  714. $nextRow['id'],
  715. $nextRow['typeid'],
  716. $nextRow['senddate'],
  717. $nextRow['title'],
  718. $nextRow['ismake'],
  719. $nextRow['arcrank'],
  720. $nextRow['namerule'],
  721. $nextRow['typedir'],
  722. $nextRow['money'],
  723. $nextRow['filename'],
  724. $nextRow['moresite'],
  725. $nextRow['siteurl'],
  726. $nextRow['sitepath']
  727. );
  728. //二次开发下一篇属性
  729. $nextRow['litpic'] = (empty($nextRow['litpic'])) ? $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg' : $nextRow['litpic'];
  730. $this->PreNext['diy']['next']['id'] = $nextRow['id'];
  731. $this->PreNext['diy']['next']['arcurl'] = $mlink;
  732. $this->PreNext['diy']['next']['title'] = $nextRow['title'];
  733. $this->PreNext['diy']['next']['litpic'] = $nextRow['litpic'];
  734. $this->PreNext['diy']['next']['pubdate'] = $nextRow['senddate'];
  735. $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
  736. $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\" title=\"{$preRow['title']}\"></a> ";
  737. } else {
  738. $this->PreNext['next'] = "下一篇:暂无";
  739. $this->PreNext['nextimg'] = "";
  740. }
  741. }
  742. //二次开发上一篇下一篇
  743. if ($gtype=='diy')
  744. {
  745. return $this->PreNext['diy'];
  746. }
  747. if ($gtype=='pre')
  748. {
  749. $rs = $this->PreNext['pre'];
  750. } else if ($gtype == 'preimg') {
  751. $rs = $this->PreNext['preimg'];
  752. } else if ($gtype == 'next') {
  753. $rs = $this->PreNext['next'];
  754. } else if ($gtype == 'nextimg') {
  755. $rs = $this->PreNext['nextimg'];
  756. } else {
  757. $rs = $this->PreNext['pre']." &nbsp; ".$this->PreNext['next'];
  758. }
  759. return $rs;
  760. }
  761. /**
  762. * 获得动态页面分页列表
  763. *
  764. * @access public
  765. * @param int $totalPage 总页数
  766. * @param int $nowPage 当前页数
  767. * @param int $aid 文档id
  768. * @return string
  769. */
  770. function GetPagebreakDM($totalPage, $nowPage, $aid)
  771. {
  772. global $cfg_rewrite;
  773. if ($totalPage == 1) {
  774. return "";
  775. }
  776. $PageList = "<li class='page-item disabled'><span class='page-link'>".$totalPage."页</span></li>";
  777. $nPage = $nowPage - 1;
  778. $lPage = $nowPage + 1;
  779. if ($nowPage == 1) {
  780. $PageList .= "<li class='page-item disabled'><a class='page-link' href='javascript:;'>上一页</a></li>";
  781. } else {
  782. if ($nPage == 1) {
  783. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>上一页</a></li>";
  784. if ($cfg_rewrite == 'Y') {
  785. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  786. }
  787. } else {
  788. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$nPage'>上一页</a></li>";
  789. if ($cfg_rewrite == 'Y') {
  790. $PageList = str_replace(".php?aid=", "-", $PageList);
  791. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  792. }
  793. }
  794. }
  795. for ($i = 1; $i <= $totalPage; $i++) {
  796. if ($i == 1) {
  797. if ($nowPage != 1) {
  798. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>1</a></li>";
  799. if ($cfg_rewrite == 'Y') {
  800. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  801. }
  802. } else {
  803. $PageList .= "<li class=\"page-item active\"><a class='page-link'>1</a></li>";
  804. }
  805. } else {
  806. $n = $i;
  807. if ($nowPage != $i) {
  808. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$i'>".$n."</a></li>";
  809. if ($cfg_rewrite == 'Y') {
  810. $PageList = str_replace(".php?aid=", "-", $PageList);
  811. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  812. }
  813. } else {
  814. $PageList .= "<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  815. }
  816. }
  817. }
  818. if ($lPage <= $totalPage) {
  819. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$lPage'>下一页</a></li>";
  820. if ($cfg_rewrite == 'Y') {
  821. $PageList = str_replace(".php?aid=", "-", $PageList);
  822. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  823. }
  824. } else {
  825. $PageList .= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  826. }
  827. return $PageList;
  828. }
  829. /**
  830. * 获得静态页面分页列表
  831. *
  832. * @access public
  833. * @param int $totalPage 总页数
  834. * @param int $nowPage 当前页数
  835. * @param int $aid 文档id
  836. * @return string
  837. */
  838. function GetPagebreak($totalPage, $nowPage, $aid)
  839. {
  840. if ($totalPage == 1) {
  841. return "";
  842. }
  843. $PageList = "<li class='page-item disabled'><span class='page-link'>".$totalPage."页:</span></li>";
  844. $nPage = $nowPage - 1;
  845. $lPage = $nowPage + 1;
  846. if ($nowPage == 1) {
  847. $PageList .= "<li class='page-item disabled'><a class='page-link' href='javascript:;'>上一页</a></li>";
  848. } else {
  849. if ($nPage == 1) {
  850. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>上一页</a></li>";
  851. } else {
  852. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$nPage.".".$this->ShortName."'>上一页</a></li>";
  853. }
  854. }
  855. for ($i = 1; $i <= $totalPage; $i++) {
  856. if ($i == 1) {
  857. if ($nowPage != 1) {
  858. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>1</a></li>";
  859. } else {
  860. $PageList .= "<li class=\"page-item active\"><span class='page-link'>1</span></li>";
  861. }
  862. } else {
  863. $n = $i;
  864. if ($nowPage != $i) {
  865. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$i.".".$this->ShortName."'>".$n."</a></li>";
  866. } else {
  867. $PageList .= "<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  868. }
  869. }
  870. }
  871. if ($lPage <= $totalPage) {
  872. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$lPage.".".$this->ShortName."'>下一页</a></li>";
  873. } else {
  874. $PageList .= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  875. }
  876. return $PageList;
  877. }
  878. /**
  879. * 获得动态页面小标题
  880. *
  881. * @access public
  882. * @param string $styleName 类型名称
  883. * @param string $pageNo 页码数
  884. * @return string
  885. */
  886. function GetPageTitlesDM($styleName, $pageNo)
  887. {
  888. if ($this->TotalPage == 1) {
  889. return "";
  890. }
  891. if (count($this->SplitTitles) == 0) {
  892. return "";
  893. }
  894. $i = 1;
  895. $aid = $this->ArcID;
  896. if ($styleName == 'link') {
  897. $revalue = "";
  898. foreach ($this->SplitTitles as $k => $v) {
  899. if ($i == 1) {
  900. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a>\r\n";
  901. } else {
  902. if ($pageNo == $i) {
  903. $revalue .= " $v \r\n";
  904. } else {
  905. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a>\r\n";
  906. }
  907. }
  908. $i++;
  909. }
  910. } else {
  911. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  912. foreach ($this->SplitTitles as $k => $v) {
  913. if ($i == 1) {
  914. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  915. } else {
  916. if ($pageNo == $i) {
  917. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i' selected>{$i}、{$v}</option>\r\n";
  918. } else {
  919. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  920. }
  921. }
  922. $i++;
  923. }
  924. $revalue .= "</select>\r\n";
  925. }
  926. return $revalue;
  927. }
  928. /**
  929. * 获得静态页面小标题
  930. *
  931. * @access public
  932. * @param string $styleName 类型名称
  933. * @param string $pageNo 页码数
  934. * @return string
  935. */
  936. function GetPageTitlesST($styleName, $pageNo)
  937. {
  938. if ($this->TotalPage == 1) {
  939. return "";
  940. }
  941. if (count($this->SplitTitles) == 0) {
  942. return "";
  943. }
  944. $i = 1;
  945. if ($styleName == 'link') {
  946. $revalue = "";
  947. foreach ($this->SplitTitles as $k => $v) {
  948. if ($i == 1) {
  949. $revalue .= "<a href='".$this->NameFirst.".".$this->ShortName."'>$v</a>\r\n";
  950. } else {
  951. if ($pageNo == $i) {
  952. $revalue .= " $v \r\n";
  953. } else {
  954. $revalue .= "<a href='".$this->NameFirst."_".$i.".".$this->ShortName."'>$v</a>\r\n";
  955. }
  956. }
  957. $i++;
  958. }
  959. } else {
  960. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  961. foreach ($this->SplitTitles as $k => $v) {
  962. if ($i == 1) {
  963. $revalue .= "<option value='".$this->NameFirst.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  964. } else {
  965. if ($pageNo == $i) {
  966. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."' selected>{$i}、{$v}</option>\r\n";
  967. } else {
  968. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  969. }
  970. }
  971. $i++;
  972. }
  973. $revalue .= "</select>\r\n";
  974. }
  975. return $revalue;
  976. }
  977. /**
  978. * 高亮问题修正,排除alt title <a></a>直接的字符替换
  979. *
  980. * @param string $kw
  981. * @param string $body
  982. * @return string
  983. */
  984. function ReplaceKeyword($kw,&$body)
  985. {
  986. $karr = $kaarr = $GLOBALS['replaced'] = array();
  987. //暂时屏蔽超链接
  988. $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
  989. $query = "SELECT * FROM `#@__keywords` WHERE rpurl<>'' ORDER BY `rank` DESC";
  990. $this->dsql->SetQuery($query);
  991. $this->dsql->Execute();
  992. while ($row = $this->dsql->GetArray()) {
  993. $key = trim($row['keyword']);
  994. $key_url = trim($row['rpurl']);
  995. $karr[] = $key;
  996. $kaarr[] = "<a href='$key_url' target='_blank'>$key</a>";
  997. }
  998. $GLOBALS['_dd_karr'] = $karr;
  999. $GLOBALS['_dd_kaarr'] = $kaarr;
  1000. $body = preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlightkeywords", $body);
  1001. //恢复超链接
  1002. $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
  1003. return $body;
  1004. }
  1005. }//End Archives
  1006. function _highlightkeywords($matches){
  1007. return _highlight($matches[2], $GLOBALS['_dd_karr'], $GLOBALS['_dd_kaarr'], $matches[1]);
  1008. }
  1009. //高亮专用,替换多次是可能不能达到最多次
  1010. function _highlight($string, $words, $result, $pre)
  1011. {
  1012. global $cfg_replace_num;
  1013. $string = str_replace('\"', '"', $string);
  1014. if ($cfg_replace_num > 0) {
  1015. foreach ($words as $key => $word) {
  1016. if ($GLOBALS['replaced'][$word] == 1) {
  1017. continue;
  1018. }
  1019. $string = preg_replace("#".preg_quote($word)."#", $result[$key], $string, $cfg_replace_num);
  1020. if (strpos($string, $word) !== FALSE) {
  1021. $GLOBALS['replaced'][$word] = 1;
  1022. }
  1023. }
  1024. } else {
  1025. $string = str_replace($words, $result, $string);
  1026. }
  1027. return $pre.$string;
  1028. }
  1029. ?>