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

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