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

1289 lines
47KB

  1. <?php
  2. if(!defined('DEDEINC')) exit("Request Error!");
  3. /**
  4. * 文档类
  5. *
  6. * @version $Id: arc.archives.class.php 4 15:13 2010年7月7日Z tianya $
  7. * @package DedeCMS.Libraries
  8. * @copyright Copyright (c) 2020, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license/v6
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(DEDEINC."/typelink.class.php");
  13. require_once(DEDEINC."/channelunit.class.php");
  14. require_once(DEDEINC."/downmix.inc.php");
  15. require_once(DEDEINC.'/ftp.class.php');
  16. @set_time_limit(0);
  17. /**
  18. * 主文档类(Archives类)
  19. *
  20. * @package TypeLink
  21. * @subpackage DedeCMS.Libraries
  22. * @link https://www.dedebiz.com
  23. */
  24. class Archives
  25. {
  26. var $TypeLink;
  27. var $ChannelUnit;
  28. var $dsql;
  29. var $Fields;
  30. var $dtp;
  31. var $ArcID;
  32. var $SplitPageField;
  33. var $SplitFields;
  34. var $NowPage;
  35. var $TotalPage;
  36. var $NameFirst;
  37. var $ShortName;
  38. var $FixedValues;
  39. var $TempSource;
  40. var $IsError;
  41. var $SplitTitles;
  42. var $PreNext;
  43. var $addTableRow;
  44. var $ftp;
  45. var $remoteDir;
  46. /**
  47. * php5构造函数
  48. *
  49. * @access public
  50. * @param int $aid 文档ID
  51. * @return string
  52. */
  53. function __construct($aid)
  54. {
  55. global $dsql,$ftp;
  56. $this->IsError = FALSE;
  57. $this->ArcID = $aid;
  58. $this->PreNext = array();
  59. $this->dsql = $dsql;
  60. $query = "SELECT channel,typeid FROM `#@__arctiny` WHERE id='$aid' ";
  61. $arr = $this->dsql->GetOne($query);
  62. if(!is_array($arr))
  63. {
  64. $this->IsError = TRUE;
  65. }
  66. else
  67. {
  68. if($arr['channel']==0) $arr['channel']=1;
  69. $this->ChannelUnit = new ChannelUnit($arr['channel'], $aid);
  70. $this->TypeLink = new TypeLink($arr['typeid']);
  71. if($this->ChannelUnit->ChannelInfos['issystem']!=-1)
  72. {
  73. // 如果当前文档不是系统模型,为单表模型
  74. $query = "SELECT arc.*,tp.reid,tp.typedir,ch.addtable
  75. FROM `#@__archives` arc
  76. LEFT JOIN #@__arctype tp on tp.id=arc.typeid
  77. LEFT JOIN #@__channeltype as ch on arc.channel = ch.id
  78. WHERE arc.id='$aid' ";
  79. $this->Fields = $this->dsql->GetOne($query);
  80. }
  81. else
  82. {
  83. $this->Fields['title'] = '';
  84. $this->Fields['money'] = $this->Fields['arcrank'] = 0;
  85. $this->Fields['senddate'] = $this->Fields['pubdate'] = $this->Fields['mid'] = $this->Fields['adminid'] = 0;
  86. $this->Fields['ismake'] = 1;
  87. $this->Fields['filename'] = '';
  88. }
  89. if($this->TypeLink->TypeInfos['corank'] > 0 && $this->Fields['arcrank']==0)
  90. {
  91. $this->Fields['arcrank'] = $this->TypeLink->TypeInfos['corank'];
  92. }
  93. $this->Fields['tags'] = GetTags($aid);
  94. $this->dtp = new DedeTagParse();
  95. $this->dtp->SetRefObj($this);
  96. $this->SplitPageField = $this->ChannelUnit->SplitPageField;
  97. $this->SplitFields = '';
  98. $this->TotalPage = 1;
  99. $this->NameFirst = '';
  100. $this->ShortName = 'html';
  101. $this->FixedValues = '';
  102. $this->TempSource = '';
  103. $this->ftp = &$ftp;
  104. $this->remoteDir = '';
  105. if(empty($GLOBALS['pageno']))
  106. {
  107. $this->NowPage = 1;
  108. }
  109. else
  110. {
  111. $this->NowPage = $GLOBALS['pageno'];
  112. }
  113. //特殊的字段数据处理
  114. $this->Fields['aid'] = $aid;
  115. $this->Fields['id'] = $aid;
  116. $this->Fields['position'] = $this->TypeLink->GetPositionLink(TRUE);
  117. $this->Fields['typeid'] = $arr['typeid'];
  118. //设置一些全局参数的值
  119. foreach($GLOBALS['PubFields'] as $k=>$v)
  120. {
  121. $this->Fields[$k] = $v;
  122. }
  123. //为了减少重复查询,这里直接把附加表查询记录放在 $this->addTableRow 中,在 ParAddTable() 不再查询
  124. if($this->ChannelUnit->ChannelInfos['addtable']!='')
  125. {
  126. $query = "SELECT * FROM `{$this->ChannelUnit->ChannelInfos['addtable']}` WHERE `aid` = '$aid'";
  127. $this->addTableRow = $this->dsql->GetOne($query);
  128. }
  129. //issystem==-1 表示单表模型,单表模型不支持redirecturl这类参数,因此限定内容普通模型才进行下面查询
  130. if($this->ChannelUnit->ChannelInfos['addtable']!='' && $this->ChannelUnit->ChannelInfos['issystem']!=-1)
  131. {
  132. if(is_array($this->addTableRow))
  133. {
  134. $this->Fields['redirecturl'] = $this->addTableRow['redirecturl'];
  135. $this->Fields['templet'] = $this->addTableRow['templet'];
  136. $this->Fields['userip'] = $this->addTableRow['userip'];
  137. }
  138. $this->Fields['templet'] = (empty($this->Fields['templet']) ? '' : trim($this->Fields['templet']));
  139. $this->Fields['redirecturl'] = (empty($this->Fields['redirecturl']) ? '' : trim($this->Fields['redirecturl']));
  140. $this->Fields['userip'] = (empty($this->Fields['userip']) ? '' : trim($this->Fields['userip']));
  141. }
  142. else
  143. {
  144. $this->Fields['templet'] = $this->Fields['redirecturl'] = '';
  145. }
  146. }//!error
  147. }
  148. //php4构造函数
  149. function Archives($aid)
  150. {
  151. $this->__construct($aid);
  152. }
  153. /**
  154. * 解析附加表的内容
  155. *
  156. * @access public
  157. * @return void
  158. */
  159. function ParAddTable()
  160. {
  161. //读取附加表信息,并把附加表的资料经过编译处理后导入到$this->Fields中,以方便在模板中用 {dede:field name='fieldname' /} 标记统一调用
  162. if($this->ChannelUnit->ChannelInfos['addtable']!='')
  163. {
  164. $row = $this->addTableRow;
  165. if($this->ChannelUnit->ChannelInfos['issystem']==-1)
  166. {
  167. $this->Fields['title'] = $row['title'];
  168. $this->Fields['senddate'] = $this->Fields['pubdate'] = $row['senddate'];
  169. $this->Fields['mid'] = $this->Fields['adminid'] = $row['mid'];
  170. $this->Fields['ismake'] = 1;
  171. $this->Fields['arcrank'] = 0;
  172. $this->Fields['money']=0;
  173. $this->Fields['filename'] = '';
  174. }
  175. if(is_array($row))
  176. {
  177. foreach($row as $k=>$v) $row[strtolower($k)] = $v;
  178. }
  179. if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))
  180. {
  181. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  182. {
  183. if(isset($row[$k]))
  184. {
  185. if(!empty($arr['rename']))
  186. {
  187. $nk = $arr['rename'];
  188. }
  189. else
  190. {
  191. $nk = $k;
  192. }
  193. $cobj = $this->GetCurTag($k);
  194. if(is_object($cobj))
  195. {
  196. foreach($this->dtp->CTags as $ctag)
  197. {
  198. if($ctag->GetTagName()=='field' && $ctag->GetAtt('name')==$k)
  199. {
  200. //带标识的专题节点
  201. if($ctag->GetAtt('noteid') != '') {
  202. $this->Fields[$k.'_'.$ctag->GetAtt('noteid')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  203. }
  204. //带类型的字段节点
  205. else if($ctag->GetAtt('type') != '') {
  206. $this->Fields[$k.'_'.$ctag->GetAtt('type')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  207. }
  208. //其它字段
  209. else {
  210. $this->Fields[$nk] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  211. }
  212. }
  213. }
  214. }
  215. else
  216. {
  217. $this->Fields[$nk] = $row[$k];
  218. }
  219. if($arr['type']=='htmltext' && $GLOBALS['cfg_keyword_replace']=='Y' && !empty($this->Fields['keywords']))
  220. {
  221. $this->Fields[$nk] = $this->ReplaceKeyword($this->Fields['keywords'],$this->Fields[$nk]);
  222. }
  223. }
  224. }//End foreach
  225. }
  226. //设置全局环境变量
  227. $this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
  228. @SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');
  229. }
  230. //完成附加表信息读取
  231. unset($row);
  232. //处理要分页显示的字段
  233. $this->SplitTitles = Array();
  234. if($this->SplitPageField!='' && $GLOBALS['cfg_arcsptitle']='Y'
  235. && isset($this->Fields[$this->SplitPageField]))
  236. {
  237. $this->SplitFields = explode("#p#",$this->Fields[$this->SplitPageField]);
  238. $i = 1;
  239. foreach($this->SplitFields as $k=>$v)
  240. {
  241. $tmpv = cn_substr($v,50);
  242. $pos = strpos($tmpv,'#e#');
  243. if($pos>0)
  244. {
  245. $st = trim(cn_substr($tmpv,$pos));
  246. if($st==""||$st=="副标题"||$st=="分页标题")
  247. {
  248. $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is","",$v);
  249. continue;
  250. }
  251. else
  252. {
  253. $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is","",$v);
  254. $this->SplitTitles[$k] = $st;
  255. }
  256. }
  257. else
  258. {
  259. continue;
  260. }
  261. $i++;
  262. }
  263. $this->TotalPage = count($this->SplitFields);
  264. $this->Fields['totalpage'] = $this->TotalPage;
  265. }
  266. //处理默认缩略图等
  267. if (isset($this->Fields['litpic']))
  268. {
  269. if($this->Fields['litpic'] == '-' || $this->Fields['litpic'] == '')
  270. {
  271. $this->Fields['litpic'] = $GLOBALS['cfg_cmspath'].'/static/defaultpic.jpg';
  272. }
  273. if(!preg_match("#^http:\/\/#i", $this->Fields['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  274. {
  275. $this->Fields['litpic'] = $GLOBALS['cfg_mainsite'].$this->Fields['litpic'];
  276. }
  277. $this->Fields['picname'] = $this->Fields['litpic'];
  278. //模板里直接使用{dede:field name='image'/}获取缩略图
  279. $this->Fields['image'] = (!preg_match('/jpg|gif|png/i', $this->Fields['picname']) ? '' : "<img src='{$this->Fields['picname']}' />");
  280. }
  281. // 处理投票选项
  282. if (isset($this->Fields['voteid']) && !empty($this->Fields['voteid']))
  283. {
  284. $this->Fields['vote'] = '';
  285. $voteid = $this->Fields['voteid'];
  286. $this->Fields['vote'] = "<script language='javascript' src='{$GLOBALS['cfg_cmspath']}/data/vote/vote_{$voteid}.js'></script>";
  287. if ($GLOBALS['cfg_multi_site'] == 'Y')
  288. {
  289. $this->Fields['vote'] = "<script language='javascript' src='{$GLOBALS['cfg_mainsite']}/data/vote/vote_{$voteid}.js'></script>";
  290. }
  291. }
  292. if (isset($this->Fields['goodpost']) && isset($this->Fields['badpost']))
  293. {
  294. //digg
  295. if($this->Fields['goodpost'] + $this->Fields['badpost'] == 0)
  296. {
  297. $this->Fields['goodper'] = $this->Fields['badper'] = 0;
  298. }
  299. else
  300. {
  301. $this->Fields['goodper'] = number_format($this->Fields['goodpost']/($this->Fields['goodpost']+$this->Fields['badpost']), 3)*100;
  302. $this->Fields['badper'] = 100 - $this->Fields['goodper'];
  303. }
  304. }
  305. }
  306. //获得当前字段参数
  307. function GetCurTag($fieldname)
  308. {
  309. if(!isset($this->dtp->CTags))
  310. {
  311. return '';
  312. }
  313. foreach($this->dtp->CTags as $ctag)
  314. {
  315. if($ctag->GetTagName()=='field' && $ctag->GetAtt('name')==$fieldname)
  316. {
  317. return $ctag;
  318. }
  319. else
  320. {
  321. continue;
  322. }
  323. }
  324. return '';
  325. }
  326. /**
  327. * 生成静态HTML
  328. *
  329. * @access public
  330. * @param int $isremote 是否远程
  331. * @return string
  332. */
  333. function MakeHtml($isremote=0)
  334. {
  335. global $fileFirst,$baidu_seo,$cfg_basehost;
  336. if($this->IsError)
  337. {
  338. return '';
  339. }
  340. $this->Fields["displaytype"] = "st";
  341. //预编译$th
  342. $this->LoadTemplet();
  343. $this->ParAddTable();
  344. $this->ParseTempletsFirst();
  345. $this->Fields['senddate'] = empty($this->Fields['senddate'])? '' : $this->Fields['senddate'];
  346. $this->Fields['title'] = empty($this->Fields['title'])? '' : $this->Fields['title'];
  347. $this->Fields['arcrank'] = empty($this->Fields['arcrank'])? 0 : $this->Fields['arcrank'];
  348. $this->Fields['ismake'] = empty($this->Fields['ismake'])? 0 : $this->Fields['ismake'];
  349. $this->Fields['money'] = empty($this->Fields['money'])? 0 : $this->Fields['money'];
  350. $this->Fields['filename'] = empty($this->Fields['filename'])? '' : $this->Fields['filename'];
  351. //分析要创建的文件名称
  352. $filename = GetFileNewName(
  353. $this->ArcID,$this->Fields['typeid'],$this->Fields['senddate'],
  354. $this->Fields['title'],$this->Fields['ismake'],$this->Fields['arcrank'],
  355. $this->TypeLink->TypeInfos['namerule'],$this->TypeLink->TypeInfos['typedir'],$this->Fields['money'],$this->Fields['filename']
  356. );
  357. $filenames = explode(".", $filename);
  358. $this->ShortName = $filenames[count($filenames)-1];
  359. if($this->ShortName=='') $this->ShortName = 'html';
  360. $fileFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filename);
  361. $this->Fields['namehand'] = basename($fileFirst);
  362. $filenames = explode("/", $filename);
  363. $this->NameFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filenames[count($filenames)-1]);
  364. if($this->NameFirst=='')
  365. {
  366. $this->NameFirst = $this->arcID;
  367. }
  368. //获得当前文档的全名
  369. $filenameFull = GetFileUrl(
  370. $this->ArcID,$this->Fields['typeid'],$this->Fields["senddate"],
  371. $this->Fields["title"],$this->Fields["ismake"],
  372. $this->Fields["arcrank"],$this->TypeLink->TypeInfos['namerule'],$this->TypeLink->TypeInfos['typedir'],$this->Fields["money"],$this->Fields['filename'],
  373. $this->TypeLink->TypeInfos['moresite'],$this->TypeLink->TypeInfos['siteurl'],$this->TypeLink->TypeInfos['sitepath']
  374. );
  375. $this->Fields['arcurl'] = $this->Fields['fullname'] = $filenameFull;
  376. //对于已设置不生成HTML的文章直接返回网址
  377. if($this->Fields['ismake']==-1 || $this->Fields['arcrank']!=0 || $this->Fields['money']>0
  378. || ($this->Fields['typeid']==0 && $this->Fields['channel'] != -1) )
  379. {
  380. return $this->GetTrueUrl($filename);
  381. }
  382. //循环生成HTML文件
  383. else
  384. {
  385. $seoUrls = array();
  386. for($i=1;$i<=$this->TotalPage;$i++)
  387. {
  388. if($this->TotalPage > 1) {
  389. $this->Fields['tmptitle'] = (empty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']);
  390. if($i>1) $this->Fields['title'] = $this->Fields['tmptitle']."($i)";
  391. }
  392. if($i>1)
  393. {
  394. $TRUEfilename = $this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName;
  395. $URLFilename = $fileFirst."_".$i.".".$this->ShortName;
  396. }
  397. else
  398. {
  399. $TRUEfilename = $this->GetTruePath().$filename;
  400. $URLFilename = $filename;
  401. }
  402. $seoUrls = array_merge($seoUrls, array($cfg_basehost.$URLFilename));
  403. $this->ParseDMFields($i,1);
  404. $this->dtp->SaveTo($TRUEfilename);
  405. }
  406. if ($baidu_seo == true) {
  407. $api = 'http://data.zz.baidu.com/urls?site=https://www.zixue.cn&token=vXkBb4Ot0yhOFcmP';
  408. $ch = curl_init();
  409. $options = array(
  410. CURLOPT_URL => $api,
  411. CURLOPT_POST => true,
  412. CURLOPT_RETURNTRANSFER => true,
  413. CURLOPT_POSTFIELDS => implode("\n", $seoUrls),
  414. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  415. );
  416. curl_setopt_array($ch, $options);
  417. $result = curl_exec($ch);
  418. $rs = json_decode($result,true);
  419. if ($rs["success"]==1) {
  420. echo "百度搜索引擎提交成功,剩余次数:".$rs["remain"]."<br/>\r\n";
  421. }
  422. }
  423. }
  424. $this->dsql->ExecuteNoneQuery("Update `#@__archives` SET ismake=1 WHERE id='".$this->ArcID."'");
  425. return $this->GetTrueUrl($filename);
  426. }
  427. /**
  428. * 获得真实连接路径
  429. *
  430. * @access public
  431. * @param string $nurl 连接
  432. * @return string
  433. */
  434. function GetTrueUrl($nurl)
  435. {
  436. return GetFileUrl
  437. (
  438. $this->Fields['id'],
  439. $this->Fields['typeid'],
  440. $this->Fields['senddate'],
  441. $this->Fields['title'],
  442. $this->Fields['ismake'],
  443. $this->Fields['arcrank'],
  444. $this->TypeLink->TypeInfos['namerule'],
  445. $this->TypeLink->TypeInfos['typedir'],
  446. $this->Fields['money'],
  447. $this->Fields['filename'],
  448. $this->TypeLink->TypeInfos['moresite'],
  449. $this->TypeLink->TypeInfos['siteurl'],
  450. $this->TypeLink->TypeInfos['sitepath']
  451. );
  452. }
  453. /**
  454. * 获得站点的真实根路径
  455. *
  456. * @access public
  457. * @return string
  458. */
  459. function GetTruePath()
  460. {
  461. $TRUEpath = $GLOBALS["cfg_basedir"];
  462. return $TRUEpath;
  463. }
  464. /**
  465. * 获得指定键值的字段
  466. *
  467. * @access public
  468. * @param string $fname 键名称
  469. * @param string $ctag 标记
  470. * @return string
  471. */
  472. function GetField($fname, $ctag)
  473. {
  474. //所有Field数组 OR 普通Field
  475. if($fname=='array')
  476. {
  477. return $this->Fields;
  478. }
  479. //指定了ID的节点
  480. else if($ctag->GetAtt('noteid') != '')
  481. {
  482. if( isset($this->Fields[$fname.'_'.$ctag->GetAtt('noteid')]) )
  483. {
  484. return $this->Fields[$fname.'_'.$ctag->GetAtt('noteid')];
  485. }
  486. }
  487. //指定了type的节点
  488. else if($ctag->GetAtt('type') != '')
  489. {
  490. if( isset($this->Fields[$fname.'_'.$ctag->GetAtt('type')]) )
  491. {
  492. return $this->Fields[$fname.'_'.$ctag->GetAtt('type')];
  493. }
  494. }
  495. else if( isset($this->Fields[$fname]) )
  496. {
  497. return $this->Fields[$fname];
  498. }
  499. return '';
  500. }
  501. /**
  502. * 获得模板文件位置
  503. *
  504. * @access public
  505. * @return string
  506. */
  507. function GetTempletFile()
  508. {
  509. global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
  510. $cid = $this->ChannelUnit->ChannelInfos['nid'];
  511. if(!empty($this->Fields['templet']))
  512. {
  513. $filetag = MfTemplet($this->Fields['templet']);
  514. if( !preg_match("#\/#", $filetag) ) $filetag = $GLOBALS['cfg_df_style'].'/'.$filetag;
  515. }
  516. else
  517. {
  518. $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
  519. }
  520. $tid = $this->Fields['typeid'];
  521. $filetag = str_replace('{cid}', $cid,$filetag);
  522. $filetag = str_replace('{tid}', $tid,$filetag);
  523. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  524. if($cid=='spec')
  525. {
  526. if( !empty($this->Fields['templet']) )
  527. {
  528. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  529. }
  530. else
  531. {
  532. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
  533. }
  534. }
  535. if ( defined('DEDEMOB') )
  536. {
  537. $tmpfile =str_replace('.htm','_m.htm',$tmpfile);
  538. }
  539. if(!file_exists($tmpfile))
  540. {
  541. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid=='spec' ? 'article_spec.htm' : 'article_default.htm');
  542. if ( defined('DEDEMOB') )
  543. {
  544. $tmpfile =str_replace('.htm','_m.htm',$tmpfile);
  545. }
  546. }
  547. if (!preg_match("#.htm$#", $tmpfile)) return FALSE;
  548. return $tmpfile;
  549. }
  550. /**
  551. * 动态输出结果
  552. *
  553. * @access public
  554. * @return void
  555. */
  556. function display()
  557. {
  558. global $htmltype;
  559. if($this->IsError)
  560. {
  561. return '';
  562. }
  563. $this->Fields["displaytype"] = "dm";
  564. if($this->NowPage > 1) $this->Fields["title"] = $this->Fields["title"]."({$this->NowPage})";
  565. //预编译
  566. $this->LoadTemplet();
  567. $this->ParAddTable();
  568. $this->ParseTempletsFirst();
  569. //跳转网址
  570. $this->Fields['flag']=empty($this->Fields['flag'])? "" : $this->Fields['flag'];
  571. if(preg_match("#j#", $this->Fields['flag']) && $this->Fields['redirecturl'] != '')
  572. {
  573. if($GLOBALS['cfg_jump_once']=='N')
  574. {
  575. $pageHtml = "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$GLOBALS['cfg_soft_lang']."\">\r\n<title>".$this->Fields['title']."</title>\r\n";
  576. $pageHtml .= "<meta http-equiv=\"refresh\" content=\"3;URL=".$this->Fields['redirecturl']."\">\r\n</head>\r\n<body>\r\n";
  577. $pageHtml .= "现在正在转向:".$this->Fields['title'].",请稍候...<br/><br/>\r\n转向内容简介:".$this->Fields['description']."\r\n</body>\r\n</html>\r\n";
  578. echo $pageHtml;
  579. }
  580. else
  581. {
  582. header("location:{$this->Fields['redirecturl']}");
  583. }
  584. exit();
  585. }
  586. $pageCount = $this->NowPage;
  587. $this->ParseDMFields($pageCount,0);
  588. $this->dtp->display();
  589. }
  590. /**
  591. * 载入模板
  592. *
  593. * @access public
  594. * @return void
  595. */
  596. function LoadTemplet()
  597. {
  598. if($this->TempSource=='')
  599. {
  600. $tempfile = $this->GetTempletFile();
  601. if(!file_exists($tempfile) || !is_file($tempfile))
  602. {
  603. echo "文档ID:{$this->Fields['id']} - {$this->TypeLink->TypeInfos['typename']} - {$this->Fields['title']}<br />";
  604. echo "模板文件不存在,无法解析文档!";
  605. exit();
  606. }
  607. $this->dtp->LoadTemplate($tempfile);
  608. $this->TempSource = $this->dtp->SourceString;
  609. }
  610. else
  611. {
  612. $this->dtp->LoadSource($this->TempSource);
  613. }
  614. }
  615. /**
  616. * 解析模板,对固定的标记进行初始给值
  617. *
  618. * @access public
  619. * @return void
  620. */
  621. function ParseTempletsFirst()
  622. {
  623. if(empty($this->Fields['keywords']))
  624. {
  625. $this->Fields['keywords'] = '';
  626. }
  627. if(empty($this->Fields['reid']))
  628. {
  629. $this->Fields['reid'] = 0;
  630. }
  631. $GLOBALS['envs']['tags'] = $this->Fields['tags'];
  632. if(isset($this->TypeLink->TypeInfos['reid']))
  633. {
  634. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  635. }
  636. $GLOBALS['envs']['keyword'] = $this->Fields['keywords'];
  637. $GLOBALS['envs']['typeid'] = $this->Fields['typeid'];
  638. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  639. $GLOBALS['envs']['aid'] = $GLOBALS['envs']['id'] = $this->Fields['id'];
  640. $GLOBALS['envs']['adminid'] = $GLOBALS['envs']['mid'] = isset($this->Fields['mid'])? $this->Fields['mid'] : 1;
  641. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  642. if($this->Fields['reid']>0)
  643. {
  644. $GLOBALS['envs']['typeid'] = $this->Fields['reid'];
  645. }
  646. MakeOneTag($this->dtp, $this, 'N');
  647. }
  648. /**
  649. * 解析模板,对内容里的变动进行赋值
  650. *
  651. * @access public
  652. * @param string $pageNo 页码数
  653. * @param string $ismake 是否生成
  654. * @return string
  655. */
  656. function ParseDMFields($pageNo, $ismake=1)
  657. {
  658. $this->NowPage = $pageNo;
  659. $this->Fields['nowpage'] = $this->NowPage;
  660. if($this->SplitPageField!='' && isset($this->Fields[$this->SplitPageField]))
  661. {
  662. $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1];
  663. if($pageNo>1) $this->Fields['description'] = trim(preg_replace("/[\r\n\t]/", ' ', cn_substr(html2text($this->Fields[$this->SplitPageField]), 200)));
  664. }
  665. //解析模板
  666. if(is_array($this->dtp->CTags))
  667. {
  668. foreach($this->dtp->CTags as $i=>$ctag)
  669. {
  670. if($ctag->GetName()=='field')
  671. {
  672. $this->dtp->Assign($i, $this->GetField($ctag->GetAtt('name'), $ctag) );
  673. }
  674. else if($ctag->GetName()=='pagebreak')
  675. {
  676. if($ismake==0)
  677. {
  678. $this->dtp->Assign($i,$this->GetPagebreakDM($this->TotalPage,$this->NowPage,$this->ArcID));
  679. }
  680. else
  681. {
  682. $this->dtp->Assign($i,$this->GetPagebreak($this->TotalPage,$this->NowPage,$this->ArcID));
  683. }
  684. }
  685. else if($ctag->GetName()=='pagetitle')
  686. {
  687. if($ismake==0)
  688. {
  689. $this->dtp->Assign($i,$this->GetPageTitlesDM($ctag->GetAtt("style"),$pageNo));
  690. }
  691. else
  692. {
  693. $this->dtp->Assign($i,$this->GetPageTitlesST($ctag->GetAtt("style"),$pageNo));
  694. }
  695. }
  696. else if($ctag->GetName()=='prenext')
  697. {
  698. $this->dtp->Assign($i,$this->GetPreNext($ctag->GetAtt('get')));
  699. }
  700. else if($ctag->GetName()=='fieldlist')
  701. {
  702. $innertext = trim($ctag->GetInnerText());
  703. if($innertext=='') $innertext = GetSysTemplets('tag_fieldlist.htm');
  704. $dtp2 = new DedeTagParse();
  705. $dtp2->SetNameSpace('field','[',']');
  706. $dtp2->LoadSource($innertext);
  707. $oldSource = $dtp2->SourceString;
  708. $oldCtags = $dtp2->CTags;
  709. $res = '';
  710. if(is_array($this->ChannelUnit->ChannelFields) && is_array($dtp2->CTags))
  711. {
  712. foreach($this->ChannelUnit->ChannelFields as $k=>$v)
  713. {
  714. if(isset($v['autofield']) && empty($v['autofield'])) {
  715. continue;
  716. }
  717. $dtp2->SourceString = $oldSource;
  718. $dtp2->CTags = $oldCtags;
  719. $fname = $v['itemname'];
  720. foreach($dtp2->CTags as $tid=>$ctag2)
  721. {
  722. if($ctag2->GetName()=='name')
  723. {
  724. $dtp2->Assign($tid,$fname);
  725. }
  726. else if($ctag2->GetName()=='tagname')
  727. {
  728. $dtp2->Assign($tid,$k);
  729. }
  730. else if($ctag2->GetName()=='value')
  731. {
  732. $this->Fields[$k] = $this->ChannelUnit->MakeField($k,$this->Fields[$k],$ctag2);
  733. @$dtp2->Assign($tid,$this->Fields[$k]);
  734. }
  735. }
  736. $res .= $dtp2->GetResult();
  737. }
  738. }
  739. $this->dtp->Assign($i,$res);
  740. }//end case
  741. }//结束模板循环
  742. }
  743. }
  744. /**
  745. * 关闭所占用的资源
  746. *
  747. * @access public
  748. * @return void
  749. */
  750. function Close()
  751. {
  752. $this->FixedValues = '';
  753. $this->Fields = '';
  754. }
  755. /**
  756. * 获取上一篇,下一篇链接
  757. *
  758. * @access public
  759. * @param string $gtype 获取类型
  760. * pre:上一篇 preimg:上一篇图片 next:下一篇 nextimg:下一篇图片
  761. * @return string
  762. */
  763. function GetPreNext($gtype='')
  764. {
  765. $rs = '';
  766. if(count($this->PreNext)<2)
  767. {
  768. $aid = $this->ArcID;
  769. $preR = $this->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id desc");
  770. $nextR = $this->dsql->GetOne("Select id From `#@__arctiny` where id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id asc");
  771. $next = (is_array($nextR) ? " where arc.id={$nextR['id']} " : ' where 1>2 ');
  772. $pre = (is_array($preR) ? " where arc.id={$preR['id']} " : ' where 1>2 ');
  773. $query = "Select arc.id,arc.title,arc.shorttitle,arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,arc.filename,arc.litpic,
  774. t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath
  775. from `#@__archives` arc left join #@__arctype t on arc.typeid=t.id ";
  776. $nextRow = $this->dsql->GetOne($query.$next);
  777. $preRow = $this->dsql->GetOne($query.$pre);
  778. if(is_array($preRow))
  779. {
  780. if ( defined('DEDEMOB') )
  781. {
  782. $mlink = 'view.php?aid='.$preRow['id'];
  783. } else {
  784. $mlink = GetFileUrl($preRow['id'],$preRow['typeid'],$preRow['senddate'],$preRow['title'],$preRow['ismake'],$preRow['arcrank'],
  785. $preRow['namerule'],$preRow['typedir'],$preRow['money'],$preRow['filename'],$preRow['moresite'],$preRow['siteurl'],$preRow['sitepath']);
  786. }
  787. $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> ";
  788. $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$preRow['title']}\"/></a> ";
  789. }
  790. else
  791. {
  792. $this->PreNext['pre'] = "上一篇:没有了 ";
  793. $this->PreNext['preimg'] ="<img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有上一图集了!\"/>";
  794. }
  795. if(is_array($nextRow))
  796. {
  797. if ( defined('DEDEMOB') )
  798. {
  799. $mlink = 'view.php?aid='.$preRow['id'];
  800. } else {
  801. $mlink = GetFileUrl($nextRow['id'],$nextRow['typeid'],$nextRow['senddate'],$nextRow['title'],$nextRow['ismake'],$nextRow['arcrank'],
  802. $nextRow['namerule'],$nextRow['typedir'],$nextRow['money'],$nextRow['filename'],$nextRow['moresite'],$nextRow['siteurl'],$nextRow['sitepath']);
  803. }
  804. $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
  805. $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\"/></a> ";
  806. }
  807. else
  808. {
  809. $this->PreNext['next'] = "下一篇:没有了 ";
  810. $this->PreNext['nextimg'] ="<a href='javascript:void(0)' alt=\"\"><img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有下一图集了!\"/></a>";
  811. }
  812. }
  813. if($gtype=='pre')
  814. {
  815. $rs = $this->PreNext['pre'];
  816. }
  817. else if($gtype=='preimg'){
  818. $rs = $this->PreNext['preimg'];
  819. }
  820. else if($gtype=='next')
  821. {
  822. $rs = $this->PreNext['next'];
  823. }
  824. else if($gtype=='nextimg'){
  825. $rs = $this->PreNext['nextimg'];
  826. }
  827. else
  828. {
  829. $rs = $this->PreNext['pre']." &nbsp; ".$this->PreNext['next'];
  830. }
  831. return $rs;
  832. }
  833. /**
  834. * 获得动态页面分页列表
  835. *
  836. * @access public
  837. * @param int $totalPage 总页数
  838. * @param int $nowPage 当前页数
  839. * @param int $aid 文档id
  840. * @return string
  841. */
  842. function GetPagebreakDM($totalPage, $nowPage, $aid)
  843. {
  844. global $cfg_rewrite;
  845. if($totalPage==1)
  846. {
  847. return "";
  848. }
  849. $PageList = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共".$totalPage."页: </span></li>";
  850. $nPage = $nowPage-1;
  851. $lPage = $nowPage+1;
  852. if($nowPage==1)
  853. {
  854. $PageList.="<li class='page-item d-none d-sm-block disabled'><a class='page-link' href='#'>上一页</a></li>";
  855. }
  856. else
  857. {
  858. if($nPage==1)
  859. {
  860. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>上一页</a></li>";
  861. if($cfg_rewrite == 'Y')
  862. {
  863. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  864. }
  865. }
  866. else
  867. {
  868. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$nPage'>上一页</a></li>";
  869. if($cfg_rewrite == 'Y')
  870. {
  871. $PageList = str_replace(".php?aid=", "-", $PageList);
  872. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  873. }
  874. }
  875. }
  876. for($i=1;$i<=$totalPage;$i++)
  877. {
  878. if($i==1)
  879. {
  880. if($nowPage!=1)
  881. {
  882. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>1</a></li>";
  883. if($cfg_rewrite == 'Y')
  884. {
  885. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  886. }
  887. }
  888. else
  889. {
  890. $PageList.="<li class=\"page-item active\"><a class='page-link'>1</a></li>";
  891. }
  892. }
  893. else
  894. {
  895. $n = $i;
  896. if($nowPage!=$i)
  897. {
  898. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$i'>".$n."</a></li>";
  899. if($cfg_rewrite == 'Y')
  900. {
  901. $PageList = str_replace(".php?aid=", "-", $PageList);
  902. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  903. }
  904. }
  905. else
  906. {
  907. $PageList.="<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  908. }
  909. }
  910. }
  911. if($lPage <= $totalPage)
  912. {
  913. $PageList.="<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$lPage'>下一页</a></li>";
  914. if($cfg_rewrite == 'Y')
  915. {
  916. $PageList = str_replace(".php?aid=", "-", $PageList);
  917. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  918. }
  919. }
  920. else
  921. {
  922. $PageList.= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  923. }
  924. return $PageList;
  925. }
  926. /**
  927. * 获得静态页面分页列表
  928. *
  929. * @access public
  930. * @param int $totalPage 总页数
  931. * @param int $nowPage 当前页数
  932. * @param int $aid 文档id
  933. * @return string
  934. */
  935. function GetPagebreak($totalPage, $nowPage, $aid)
  936. {
  937. if($totalPage==1)
  938. {
  939. return "";
  940. }
  941. $PageList = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共".$totalPage."页: </span></li>";
  942. $nPage = $nowPage-1;
  943. $lPage = $nowPage+1;
  944. if($nowPage==1)
  945. {
  946. $PageList.="<li class='page-item d-none d-sm-block disabled'><a class='page-link' href='#'>上一页</a></li>";
  947. }
  948. else
  949. {
  950. if($nPage==1)
  951. {
  952. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>上一页</a></li>";
  953. }
  954. else
  955. {
  956. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$nPage.".".$this->ShortName."'>上一页</a></li>";
  957. }
  958. }
  959. for($i=1;$i<=$totalPage;$i++)
  960. {
  961. if($i==1)
  962. {
  963. if($nowPage!=1)
  964. {
  965. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst.".".$this->ShortName."'>1</a></li>";
  966. }
  967. else
  968. {
  969. $PageList.="<li class=\"page-item active\"><span class='page-link'>1</span></li>";
  970. }
  971. }
  972. else
  973. {
  974. $n = $i;
  975. if($nowPage!=$i)
  976. {
  977. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$i.".".$this->ShortName."'>".$n."</a></li>";
  978. }
  979. else
  980. {
  981. $PageList.="<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  982. }
  983. }
  984. }
  985. if($lPage <= $totalPage)
  986. {
  987. $PageList.="<li class='page-item'><a class='page-link' href='".$this->NameFirst."_".$lPage.".".$this->ShortName."'>下一页</a></li>";
  988. }
  989. else
  990. {
  991. $PageList.= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  992. }
  993. return $PageList;
  994. }
  995. /**
  996. * 获得动态页面小标题
  997. *
  998. * @access public
  999. * @param string $styleName 类型名称
  1000. * @param string $pageNo 页码数
  1001. * @return string
  1002. */
  1003. function GetPageTitlesDM($styleName, $pageNo)
  1004. {
  1005. if($this->TotalPage==1)
  1006. {
  1007. return "";
  1008. }
  1009. if(count($this->SplitTitles)==0)
  1010. {
  1011. return "";
  1012. }
  1013. $i=1;
  1014. $aid = $this->ArcID;
  1015. if($styleName=='link')
  1016. {
  1017. $revalue = "";
  1018. foreach($this->SplitTitles as $k=>$v)
  1019. {
  1020. if($i==1)
  1021. {
  1022. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> \r\n";
  1023. }
  1024. else
  1025. {
  1026. if($pageNo==$i)
  1027. {
  1028. $revalue .= " $v \r\n";
  1029. }
  1030. else
  1031. {
  1032. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> \r\n";
  1033. }
  1034. }
  1035. $i++;
  1036. }
  1037. }
  1038. else
  1039. {
  1040. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  1041. foreach($this->SplitTitles as $k=>$v)
  1042. {
  1043. if($i==1)
  1044. {
  1045. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  1046. }
  1047. else
  1048. {
  1049. if($pageNo==$i)
  1050. {
  1051. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i' selected>{$i}、{$v}</option>\r\n";
  1052. }
  1053. else
  1054. {
  1055. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  1056. }
  1057. }
  1058. $i++;
  1059. }
  1060. $revalue .= "</select>\r\n";
  1061. }
  1062. return $revalue;
  1063. }
  1064. /**
  1065. * 获得静态页面小标题
  1066. *
  1067. * @access public
  1068. * @param string $styleName 类型名称
  1069. * @param string $pageNo 页码数
  1070. * @return string
  1071. */
  1072. function GetPageTitlesST($styleName, $pageNo)
  1073. {
  1074. if($this->TotalPage==1)
  1075. {
  1076. return "";
  1077. }
  1078. if(count($this->SplitTitles)==0)
  1079. {
  1080. return "";
  1081. }
  1082. $i=1;
  1083. if($styleName=='link')
  1084. {
  1085. $revalue = "";
  1086. foreach($this->SplitTitles as $k=>$v)
  1087. {
  1088. if($i==1)
  1089. {
  1090. $revalue .= "<a href='".$this->NameFirst.".".$this->ShortName."'>$v</a> \r\n";
  1091. }
  1092. else
  1093. {
  1094. if($pageNo==$i)
  1095. {
  1096. $revalue .= " $v \r\n";
  1097. }
  1098. else
  1099. {
  1100. $revalue .= "<a href='".$this->NameFirst."_".$i.".".$this->ShortName."'>$v</a> \r\n";
  1101. }
  1102. }
  1103. $i++;
  1104. }
  1105. }
  1106. else
  1107. {
  1108. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  1109. foreach($this->SplitTitles as $k=>$v)
  1110. {
  1111. if($i==1)
  1112. {
  1113. $revalue .= "<option value='".$this->NameFirst.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  1114. }
  1115. else
  1116. {
  1117. if($pageNo==$i)
  1118. {
  1119. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."' selected>{$i}、{$v}</option>\r\n";
  1120. }
  1121. else
  1122. {
  1123. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  1124. }
  1125. }
  1126. $i++;
  1127. }
  1128. $revalue .= "</select>\r\n";
  1129. }
  1130. return $revalue;
  1131. }
  1132. /**
  1133. * 高亮问题修正, 排除alt title <a></a>直接的字符替换
  1134. *
  1135. * @param string $kw
  1136. * @param string $body
  1137. * @return string
  1138. */
  1139. function ReplaceKeyword($kw,&$body)
  1140. {
  1141. global $cfg_cmspath;
  1142. $maxkey = 5;
  1143. $kws = explode(",",trim($kw)); //以分好为间隔符
  1144. $i=0;
  1145. $karr = $kaarr = $GLOBALS['replaced'] = array();
  1146. //暂时屏蔽超链接
  1147. $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
  1148. /*
  1149. foreach($kws as $k)
  1150. {
  1151. $k = trim($k);
  1152. if($k!="")
  1153. {
  1154. if($i > $maxkey)
  1155. {
  1156. break;
  1157. }
  1158. $myrow = $this->dsql->GetOne("SELECT * FROM #@__keywords WHERE keyword='$k' AND rpurl<>'' ");
  1159. if(is_array($myrow))
  1160. {
  1161. $karr[] = $k;
  1162. $GLOBALS['replaced'][$k] = 0;
  1163. $kaarr[] = "<a href='{$myrow['rpurl']}'><u>$k</u></a>";
  1164. }
  1165. $i++;
  1166. }
  1167. }
  1168. */
  1169. $query = "SELECT * FROM #@__keywords WHERE rpurl<>'' ORDER BY rank DESC";
  1170. $this->dsql->SetQuery($query);
  1171. $this->dsql->Execute();
  1172. while($row = $this->dsql->GetArray())
  1173. {
  1174. $key = trim($row['keyword']);
  1175. $key_url=trim($row['rpurl']);
  1176. $karr[] = $key;
  1177. $kaarr[] = "<a href='$key_url' target='_blank'><u>$key</u></a>";
  1178. }
  1179. // 这里可能会有错误
  1180. if (version_compare(PHP_VERSION, '5.5.0', '>='))
  1181. {
  1182. $body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
  1183. } else {
  1184. $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
  1185. }
  1186. //恢复超链接
  1187. $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
  1188. return $body;
  1189. }
  1190. }//End Archives
  1191. //高亮专用, 替换多次是可能不能达到最多次
  1192. function _highlight($string, $words, $result, $pre)
  1193. {
  1194. global $cfg_replace_num;
  1195. if (version_compare(PHP_VERSION, '5.5.0', '>='))
  1196. {
  1197. $string = $string[0];
  1198. $pre = $pre[0];
  1199. }
  1200. $string = str_replace('\"', '"', $string);
  1201. if($cfg_replace_num > 0)
  1202. {
  1203. foreach ($words as $key => $word)
  1204. {
  1205. if($GLOBALS['replaced'][$word] == 1)
  1206. {
  1207. continue;
  1208. }
  1209. $string = preg_replace("#".preg_quote($word)."#", $result[$key], $string, $cfg_replace_num);
  1210. if(strpos($string, $word) !== FALSE)
  1211. {
  1212. $GLOBALS['replaced'][$word] = 1;
  1213. }
  1214. }
  1215. }
  1216. else
  1217. {
  1218. $string = str_replace($words, $result, $string);
  1219. }
  1220. return $pre.$string;
  1221. }