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

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