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

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