国内流行的内容管理系统(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 < -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 .= "<p>正在前往文档:".$this->Fields['title']."<p>\r\n<p>文档描述:".$this->Fields['description']."</p>\r\n</body>\r\n</html>";
  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->Fields['title']},主题模板文件不存在,无法更新文档";
  515. exit();
  516. }
  517. $this->dtp->LoadTemplate($tempfile);
  518. $this->TempSource = $this->dtp->SourceString;
  519. } else {
  520. $this->dtp->LoadSource($this->TempSource);
  521. }
  522. }
  523. /**
  524. * 解析模板,对固定的标记进行初始给值
  525. *
  526. * @access public
  527. * @return void
  528. */
  529. function ParseTempletsFirst()
  530. {
  531. if (empty($this->Fields['keywords'])) {
  532. $this->Fields['keywords'] = '';
  533. }
  534. if (empty($this->Fields['reid'])) {
  535. $this->Fields['reid'] = 0;
  536. }
  537. $GLOBALS['envs']['tags'] = $this->Fields['tags'];
  538. if (isset($this->TypeLink->TypeInfos['reid'])) {
  539. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  540. }
  541. $GLOBALS['envs']['keyword'] = $this->Fields['keywords'];
  542. $GLOBALS['envs']['typeid'] = $this->Fields['typeid'];
  543. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  544. $GLOBALS['envs']['aid'] = $GLOBALS['envs']['id'] = $this->Fields['id'];
  545. $GLOBALS['envs']['adminid'] = $GLOBALS['envs']['mid'] = isset($this->Fields['mid']) ? $this->Fields['mid'] : 1;
  546. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  547. if ($this->Fields['reid'] > 0) {
  548. $GLOBALS['envs']['typeid'] = $this->Fields['reid'];
  549. }
  550. MakeOneTag($this->dtp, $this, 'N');
  551. }
  552. /**
  553. * 解析模板,对文档里的变动进行赋值
  554. *
  555. * @access public
  556. * @param string $pageNo 页码数
  557. * @param string $ismake 是否生成
  558. * @return string
  559. */
  560. function ParseDMFields($pageNo, $ismake = 1)
  561. {
  562. $this->NowPage = $pageNo;
  563. $this->Fields['nowpage'] = $this->NowPage;
  564. if ($this->SplitPageField != '' && isset($this->Fields[$this->SplitPageField])) {
  565. $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1];
  566. if ($pageNo > 1) $this->Fields['description'] = trim(preg_replace("/[\r\n\t]/", ' ', cn_substr(html2text($this->Fields[$this->SplitPageField]), 200)));
  567. }
  568. //解析模板
  569. if (is_array($this->dtp->CTags)) {
  570. foreach ($this->dtp->CTags as $i => $ctag) {
  571. if ($ctag->GetName() == 'field') {
  572. $this->dtp->Assign($i, $this->GetField($ctag->GetAtt('name'), $ctag));
  573. } else if ($ctag->GetName() == 'pagebreak') {
  574. if ($ismake == 0) {
  575. $this->dtp->Assign($i, $this->GetPagebreakDM($this->TotalPage, $this->NowPage, $this->ArcID));
  576. } else {
  577. $this->dtp->Assign($i, $this->GetPagebreak($this->TotalPage, $this->NowPage, $this->ArcID));
  578. }
  579. } else if ($ctag->GetName() == 'pagetitle') {
  580. if ($ismake == 0) {
  581. $this->dtp->Assign($i, $this->GetPageTitlesDM($ctag->GetAtt("style"), $pageNo));
  582. } else {
  583. $this->dtp->Assign($i, $this->GetPageTitlesST($ctag->GetAtt("style"), $pageNo));
  584. }
  585. } else if ($ctag->GetName() == 'prenext') {
  586. $this->dtp->Assign($i, $this->GetPreNext($ctag->GetAtt('get')));
  587. }
  588. //添加上一篇下一篇标签{dede:prenextdiy get='pre'}{/dede:prenextdiy}{dede:prenextdiy get='next'}{/dede:prenextdiy}
  589. else if ($ctag->GetName()=='prenextdiy')
  590. {
  591. $innertext = trim($ctag->GetInnerText());
  592. if ($innertext) {
  593. $get = $ctag->GetAtt('get');
  594. $diys['diy'] = $this->GetPreNext('diy');
  595. $revalue = '';
  596. $dtp2 = new DedeTagParse();
  597. $dtp2->SetNameSpace('field','[',']');
  598. $dtp2->LoadSource($innertext);
  599. foreach($diys as $row)
  600. {
  601. foreach($dtp2->CTags as $tid=>$ctag2)
  602. {
  603. if (isset($row[$get][$ctag2->GetName()])) {
  604. $dtp2->Assign($tid,$row[$get][$ctag2->GetName()]);
  605. }
  606. }
  607. $revalue .= $dtp2->GetResult();
  608. }
  609. if ($row[$get]['id']) $this->dtp->Assign($i,$revalue);
  610. }
  611. }
  612. else if ($ctag->GetName() == 'fieldlist') {
  613. $innertext = trim($ctag->GetInnerText());
  614. if ($innertext == '') $innertext = GetSysTemplets('tag_fieldlist.htm');
  615. $dtp2 = new DedeTagParse();
  616. $dtp2->SetNameSpace('field', '[', ']');
  617. $dtp2->LoadSource($innertext);
  618. $oldSource = $dtp2->SourceString;
  619. $oldCtags = $dtp2->CTags;
  620. $res = '';
  621. if (is_array($this->ChannelUnit->ChannelFields) && is_array($dtp2->CTags)) {
  622. foreach ($this->ChannelUnit->ChannelFields as $k => $v) {
  623. if (isset($v['autofield']) && empty($v['autofield'])) {
  624. continue;
  625. }
  626. $dtp2->SourceString = $oldSource;
  627. $dtp2->CTags = $oldCtags;
  628. $fname = $v['itemname'];
  629. foreach ($dtp2->CTags as $tid => $ctag2) {
  630. if ($ctag2->GetName() == 'name') {
  631. $dtp2->Assign($tid, $fname);
  632. } else if ($ctag2->GetName() == 'tagname') {
  633. $dtp2->Assign($tid, $k);
  634. } else if ($ctag2->GetName() == 'value') {
  635. if (isset($this->Fields[$k])) {
  636. $this->Fields[$k] = $this->ChannelUnit->MakeField($k, $this->Fields[$k], $ctag2);
  637. @$dtp2->Assign($tid, $this->Fields[$k]);
  638. }
  639. }
  640. }
  641. $res .= $dtp2->GetResult();
  642. }
  643. }
  644. $this->dtp->Assign($i, $res);
  645. } //end case
  646. } //结束模板循环
  647. }
  648. }
  649. /**
  650. * 关闭所占用的资源
  651. *
  652. * @access public
  653. * @return void
  654. */
  655. function Close()
  656. {
  657. $this->FixedValues = '';
  658. $this->Fields = '';
  659. }
  660. /**
  661. * 获取上一篇和下一篇链接
  662. *
  663. * @access public
  664. * @param string $gtype pre为上一篇,preimg为上一篇图片,next为下一篇,nextimg为下一篇图片
  665. * @return string
  666. */
  667. function GetPreNext($gtype = '')
  668. {
  669. $rs = '';
  670. if (count($this->PreNext) < 2) {
  671. $aid = $this->ArcID;
  672. $preR = $this->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' ORDER BY id DESC");
  673. $nextR = $this->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' ORDER BY id ASC");
  674. $next = (is_array($nextR) ? " WHERE arc.id={$nextR['id']} " : ' WHERE 1>2 ');
  675. $pre = (is_array($preR) ? " WHERE arc.id={$preR['id']} " : ' WHERE 1>2 ');
  676. $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 ";
  677. $nextRow = $this->dsql->GetOne($query.$next);
  678. $preRow = $this->dsql->GetOne($query.$pre);
  679. if (is_array($preRow)) {
  680. $mlink = GetFileUrl(
  681. $preRow['id'],
  682. $preRow['typeid'],
  683. $preRow['senddate'],
  684. $preRow['title'],
  685. $preRow['ismake'],
  686. $preRow['arcrank'],
  687. $preRow['namerule'],
  688. $preRow['typedir'],
  689. $preRow['money'],
  690. $preRow['filename'],
  691. $preRow['moresite'],
  692. $preRow['siteurl'],
  693. $preRow['sitepath']
  694. );
  695. $preRow['litpic'] = (empty($preRow['litpic'])) ? $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg' : $preRow['litpic'];
  696. $this->PreNext['diy']['pre']['id'] = $preRow['id'];
  697. $this->PreNext['diy']['pre']['arcurl'] = $mlink;
  698. $this->PreNext['diy']['pre']['title'] = $preRow['title'];
  699. $this->PreNext['diy']['pre']['litpic'] = $preRow['litpic'];
  700. $this->PreNext['diy']['pre']['pubdate'] = $preRow['senddate'];
  701. $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a>";
  702. $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$preRow['title']}\" title=\"{$preRow['title']}\"></a> ";
  703. } else {
  704. $this->PreNext['pre'] = "上一篇:暂无";
  705. $this->PreNext['preimg'] = "";
  706. }
  707. if (is_array($nextRow)) {
  708. $mlink = GetFileUrl(
  709. $nextRow['id'],
  710. $nextRow['typeid'],
  711. $nextRow['senddate'],
  712. $nextRow['title'],
  713. $nextRow['ismake'],
  714. $nextRow['arcrank'],
  715. $nextRow['namerule'],
  716. $nextRow['typedir'],
  717. $nextRow['money'],
  718. $nextRow['filename'],
  719. $nextRow['moresite'],
  720. $nextRow['siteurl'],
  721. $nextRow['sitepath']
  722. );
  723. $nextRow['litpic'] = (empty($nextRow['litpic'])) ? $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg' : $nextRow['litpic'];
  724. $this->PreNext['diy']['next']['id'] = $nextRow['id'];
  725. $this->PreNext['diy']['next']['arcurl'] = $mlink;
  726. $this->PreNext['diy']['next']['title'] = $nextRow['title'];
  727. $this->PreNext['diy']['next']['litpic'] = $nextRow['litpic'];
  728. $this->PreNext['diy']['next']['pubdate'] = $nextRow['senddate'];
  729. $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
  730. $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\" title=\"{$nextRow['title']}\"></a> ";
  731. } else {
  732. $this->PreNext['next'] = "下一篇:暂无";
  733. $this->PreNext['nextimg'] = "";
  734. }
  735. }
  736. if ($gtype=='diy') {
  737. return $this->PreNext['diy'];
  738. } if ($gtype=='pre') {
  739. $rs = $this->PreNext['pre'];
  740. } else if ($gtype == 'preimg') {
  741. $rs = $this->PreNext['preimg'];
  742. } else if ($gtype == 'next') {
  743. $rs = $this->PreNext['next'];
  744. } else if ($gtype == 'nextimg') {
  745. $rs = $this->PreNext['nextimg'];
  746. } else {
  747. $rs = $this->PreNext['pre']." &nbsp; ".$this->PreNext['next'];
  748. }
  749. return $rs;
  750. }
  751. /**
  752. * 获得静态文档分页标题
  753. *
  754. * @access public
  755. * @param string $styleName 类型名称
  756. * @param string $pageNo 页码数
  757. * @return string
  758. */
  759. function GetPageTitlesST($styleName, $pageNo)
  760. {
  761. if ($this->TotalPage == 1) {
  762. return "";
  763. }
  764. if (count($this->SplitTitles) == 0) {
  765. return "";
  766. }
  767. $i = 1;
  768. if ($styleName == 'link') {
  769. $revalue = "";
  770. foreach ($this->SplitTitles as $k => $v) {
  771. if ($i == 1) {
  772. $revalue .= "<a href='".$this->NameFirst.".".$this->ShortName."'>$v</a>\r\n";
  773. } else {
  774. if ($pageNo == $i) {
  775. $revalue .= " $v \r\n";
  776. } else {
  777. $revalue .= "<a href='".$this->NameFirst."-".$i.".".$this->ShortName."'>$v</a>\r\n";
  778. }
  779. }
  780. $i++;
  781. }
  782. } else {
  783. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  784. foreach ($this->SplitTitles as $k => $v) {
  785. if ($i == 1) {
  786. $revalue .= "<option value='".$this->NameFirst.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  787. } else {
  788. if ($pageNo == $i) {
  789. $revalue .= "<option value='".$this->NameFirst."-".$i.".".$this->ShortName."' selected>{$i}、{$v}</option>\r\n";
  790. } else {
  791. $revalue .= "<option value='".$this->NameFirst."-".$i.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  792. }
  793. }
  794. $i++;
  795. }
  796. $revalue .= "</select>\r\n";
  797. }
  798. return $revalue;
  799. }
  800. /**
  801. * 获得静态文档分页列表
  802. *
  803. * @access public
  804. * @param int $totalPage 总页数
  805. * @param int $nowPage 当前页数
  806. * @param int $aid 文档id
  807. * @return string
  808. */
  809. function GetPagebreak($totalPage, $nowPage, $aid)
  810. {
  811. if ($totalPage == 1) {
  812. return "";
  813. }
  814. $PageList = "<li class='page-item disabled'><span class='page-link'>".$totalPage."页</span></li>";
  815. $nPage = $nowPage - 1;
  816. $lPage = $nowPage + 1;
  817. if ($nowPage == 1) {
  818. $PageList .= "<li class='page-item disabled'><span class='page-link'>上一页</span></li>";
  819. } else {
  820. if ($nPage == 1) {
  821. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>上一页</a></li>";
  822. } else {
  823. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."-".$nPage.".".$this->ShortName."'>上一页</a></li>";
  824. }
  825. }
  826. for ($i = 1; $i <= $totalPage; $i++) {
  827. if ($i == 1) {
  828. if ($nowPage != 1) {
  829. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>1</a></li>";
  830. } else {
  831. $PageList .= "<li class='page-item active'><span class='page-link'>1</span></li>";
  832. }
  833. } else {
  834. $n = $i;
  835. if ($nowPage != $i) {
  836. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."-".$i.".".$this->ShortName."'>{$n}</a></li>";
  837. } else {
  838. $PageList .= "<li class='page-item active'><span class='page-link'>{$n}</span></li>";
  839. }
  840. }
  841. }
  842. if ($lPage <= $totalPage) {
  843. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->NameFirst."-".$lPage.".".$this->ShortName."'>下一页</a></li>";
  844. } else {
  845. $PageList .= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  846. }
  847. return $PageList;
  848. }
  849. /**
  850. * 获得动态文档分页标题
  851. *
  852. * @access public
  853. * @param string $styleName 类型名称
  854. * @param string $pageNo 页码数
  855. * @return string
  856. */
  857. function GetPageTitlesDM($styleName, $pageNo)
  858. {
  859. if ($this->TotalPage == 1) {
  860. return "";
  861. }
  862. if (count($this->SplitTitles) == 0) {
  863. return "";
  864. }
  865. $i = 1;
  866. $aid = $this->ArcID;
  867. if ($styleName == 'link') {
  868. $revalue = "";
  869. foreach ($this->SplitTitles as $k => $v) {
  870. if ($i == 1) {
  871. $revalue .= "<a href='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>$v</a>\r\n";
  872. } else {
  873. if ($pageNo == $i) {
  874. $revalue .= " $v \r\n";
  875. } else {
  876. $revalue .= "<a href='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>$v</a>\r\n";
  877. }
  878. }
  879. $i++;
  880. }
  881. } else {
  882. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  883. foreach ($this->SplitTitles as $k => $v) {
  884. if ($i == 1) {
  885. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  886. } else {
  887. if ($pageNo == $i) {
  888. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i' selected>{$i}、{$v}</option>\r\n";
  889. } else {
  890. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  891. }
  892. }
  893. $i++;
  894. }
  895. $revalue .= "</select>\r\n";
  896. }
  897. return $revalue;
  898. }
  899. /**
  900. * 获得动态文档分页列表
  901. *
  902. * @access public
  903. * @param int $totalPage 总页数
  904. * @param int $nowPage 当前页数
  905. * @param int $aid 文档id
  906. * @return string
  907. */
  908. function GetPagebreakDM($totalPage, $nowPage, $aid)
  909. {
  910. global $cfg_rewrite;
  911. if ($totalPage == 1) {
  912. return "";
  913. }
  914. $PageList = "<li class='page-item disabled'><span class='page-link'>".$totalPage."页</span></li>";
  915. $nPage = $nowPage - 1;
  916. $lPage = $nowPage + 1;
  917. if ($nowPage == 1) {
  918. $PageList .= "<li class='page-item disabled'><span class='page-link'>上一页</span></li>";
  919. } else {
  920. if ($nPage == 1) {
  921. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->Fields['phpurl']."/view.php?aid=$aid'>上一页</a></li>";
  922. if ($cfg_rewrite == 'Y') {
  923. $PageList = preg_replace("#.php\?aid=(\d+)#i", "-\\1-1.html", $PageList);
  924. }
  925. } else {
  926. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$nPage'>上一页</a></li>";
  927. if ($cfg_rewrite == 'Y') {
  928. $PageList = str_replace(".php?aid=", "-", $PageList);
  929. $PageList = preg_replace("#&pageno=(\d+)#i", "-\\1.html", $PageList);
  930. }
  931. }
  932. }
  933. for ($i = 1; $i <= $totalPage; $i++) {
  934. if ($i == 1) {
  935. if ($nowPage != 1) {
  936. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->Fields['phpurl']."/view.php?aid=$aid'>1</a></li>";
  937. if ($cfg_rewrite == 'Y') {
  938. $PageList = preg_replace("#.php\?aid=(\d+)#i", "-\\1-1.html", $PageList);
  939. }
  940. } else {
  941. $PageList .= "<li class='page-item active'><span class='page-link'>1</span></li>";
  942. }
  943. } else {
  944. $n = $i;
  945. if ($nowPage != $i) {
  946. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$n}</a></li>";
  947. if ($cfg_rewrite == 'Y') {
  948. $PageList = str_replace(".php?aid=", "-", $PageList);
  949. $PageList = preg_replace("#&pageno=(\d+)#i", "-\\1.html", $PageList);
  950. }
  951. } else {
  952. $PageList .= "<li class='page-item active'><span class='page-link'>{$n}</span></li>";
  953. }
  954. }
  955. }
  956. if ($lPage <= $totalPage) {
  957. $PageList .= "<li class='page-item'><a class='page-link' href='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$lPage'>下一页</a></li>";
  958. if ($cfg_rewrite == 'Y') {
  959. $PageList = str_replace(".php?aid=", "-", $PageList);
  960. $PageList = preg_replace("#&pageno=(\d+)#i", "-\\1.html", $PageList);
  961. }
  962. } else {
  963. $PageList .= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  964. }
  965. return $PageList;
  966. }
  967. /**
  968. * 高亮问题修正,排除alt、title、<a></a>直接的字符替换
  969. *
  970. * @param string $kw
  971. * @param string $body
  972. * @return string
  973. */
  974. function ReplaceKeyword($kw,&$body)
  975. {
  976. $karr = $kaarr = $GLOBALS['replaced'] = array();
  977. //暂时屏蔽超链接
  978. $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
  979. $query = "SELECT * FROM `#@__keywords` WHERE rpurl<>'' ORDER BY `rank` DESC";
  980. $this->dsql->SetQuery($query);
  981. $this->dsql->Execute();
  982. while ($row = $this->dsql->GetArray()) {
  983. $key = trim($row['keyword']);
  984. $key_url = trim($row['rpurl']);
  985. $karr[] = $key;
  986. $kaarr[] = "<a href='$key_url' target='_blank'>$key</a>";
  987. }
  988. $GLOBALS['_dd_karr'] = $karr;
  989. $GLOBALS['_dd_kaarr'] = $kaarr;
  990. $body = preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlightkeywords", $body);
  991. //恢复超链接
  992. $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
  993. return $body;
  994. }
  995. }//End Archives
  996. function _highlightkeywords($matches)
  997. {
  998. return _highlight($matches[2], $GLOBALS['_dd_karr'], $GLOBALS['_dd_kaarr'], $matches[1]);
  999. }
  1000. //高亮专用
  1001. function _highlight($string, $words, $result, $pre)
  1002. {
  1003. global $cfg_replace_num;
  1004. $string = str_replace('\"', '"', $string);
  1005. if ($cfg_replace_num > 0) {
  1006. foreach ($words as $key => $word) {
  1007. if ($GLOBALS['replaced'][$word] == 1) {
  1008. continue;
  1009. }
  1010. $string = preg_replace("#".preg_quote($word)."#", $result[$key], $string, $cfg_replace_num);
  1011. if (strpos($string, $word) !== FALSE) {
  1012. $GLOBALS['replaced'][$word] = 1;
  1013. }
  1014. }
  1015. } else {
  1016. $string = str_replace($words, $result, $string);
  1017. }
  1018. return $pre.$string;
  1019. }
  1020. ?>