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

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