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

1277 lines
46KB

  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. * @license http://help.dedecms.com/usersguide/license.html
  10. * @link http://www.dedecms.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 http://www.dedecms.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.gif';
  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 $cfg_remote_site,$fileFirst;
  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. for($i=1;$i<=$this->TotalPage;$i++)
  386. {
  387. if($this->TotalPage > 1) {
  388. $this->Fields['tmptitle'] = (empty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']);
  389. if($i>1) $this->Fields['title'] = $this->Fields['tmptitle']."($i)";
  390. }
  391. if($i>1)
  392. {
  393. $TRUEfilename = $this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName;
  394. }
  395. else
  396. {
  397. $TRUEfilename = $this->GetTruePath().$filename;
  398. }
  399. $this->ParseDMFields($i,1);
  400. $this->dtp->SaveTo($TRUEfilename);
  401. //如果启用远程发布则需要进行判断
  402. if($cfg_remote_site=='Y' && $isremote == 1)
  403. {
  404. //分析远程文件路径
  405. $remotefile = str_replace(DEDEROOT, '', $TRUEfilename);
  406. $localfile = '..'.$remotefile;
  407. //创建远程文件夹
  408. $remotedir = preg_replace("#[^\/]*\.html#", '', $remotefile);
  409. $this->ftp->rmkdir($remotedir);
  410. $this->ftp->upload($localfile, $remotefile, 'ascii');
  411. }
  412. }
  413. }
  414. $this->dsql->ExecuteNoneQuery("Update `#@__archives` SET ismake=1 WHERE id='".$this->ArcID."'");
  415. return $this->GetTrueUrl($filename);
  416. }
  417. /**
  418. * 获得真实连接路径
  419. *
  420. * @access public
  421. * @param string $nurl 连接
  422. * @return string
  423. */
  424. function GetTrueUrl($nurl)
  425. {
  426. return GetFileUrl
  427. (
  428. $this->Fields['id'],
  429. $this->Fields['typeid'],
  430. $this->Fields['senddate'],
  431. $this->Fields['title'],
  432. $this->Fields['ismake'],
  433. $this->Fields['arcrank'],
  434. $this->TypeLink->TypeInfos['namerule'],
  435. $this->TypeLink->TypeInfos['typedir'],
  436. $this->Fields['money'],
  437. $this->Fields['filename'],
  438. $this->TypeLink->TypeInfos['moresite'],
  439. $this->TypeLink->TypeInfos['siteurl'],
  440. $this->TypeLink->TypeInfos['sitepath']
  441. );
  442. }
  443. /**
  444. * 获得站点的真实根路径
  445. *
  446. * @access public
  447. * @return string
  448. */
  449. function GetTruePath()
  450. {
  451. $TRUEpath = $GLOBALS["cfg_basedir"];
  452. return $TRUEpath;
  453. }
  454. /**
  455. * 获得指定键值的字段
  456. *
  457. * @access public
  458. * @param string $fname 键名称
  459. * @param string $ctag 标记
  460. * @return string
  461. */
  462. function GetField($fname, $ctag)
  463. {
  464. //所有Field数组 OR 普通Field
  465. if($fname=='array')
  466. {
  467. return $this->Fields;
  468. }
  469. //指定了ID的节点
  470. else if($ctag->GetAtt('noteid') != '')
  471. {
  472. if( isset($this->Fields[$fname.'_'.$ctag->GetAtt('noteid')]) )
  473. {
  474. return $this->Fields[$fname.'_'.$ctag->GetAtt('noteid')];
  475. }
  476. }
  477. //指定了type的节点
  478. else if($ctag->GetAtt('type') != '')
  479. {
  480. if( isset($this->Fields[$fname.'_'.$ctag->GetAtt('type')]) )
  481. {
  482. return $this->Fields[$fname.'_'.$ctag->GetAtt('type')];
  483. }
  484. }
  485. else if( isset($this->Fields[$fname]) )
  486. {
  487. return $this->Fields[$fname];
  488. }
  489. return '';
  490. }
  491. /**
  492. * 获得模板文件位置
  493. *
  494. * @access public
  495. * @return string
  496. */
  497. function GetTempletFile()
  498. {
  499. global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
  500. $cid = $this->ChannelUnit->ChannelInfos['nid'];
  501. if(!empty($this->Fields['templet']))
  502. {
  503. $filetag = MfTemplet($this->Fields['templet']);
  504. if( !preg_match("#\/#", $filetag) ) $filetag = $GLOBALS['cfg_df_style'].'/'.$filetag;
  505. }
  506. else
  507. {
  508. $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
  509. }
  510. $tid = $this->Fields['typeid'];
  511. $filetag = str_replace('{cid}', $cid,$filetag);
  512. $filetag = str_replace('{tid}', $tid,$filetag);
  513. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  514. if($cid=='spec')
  515. {
  516. if( !empty($this->Fields['templet']) )
  517. {
  518. $tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  519. }
  520. else
  521. {
  522. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
  523. }
  524. }
  525. if ( defined('DEDEMOB') )
  526. {
  527. $tmpfile =str_replace('.htm','_m.htm',$tmpfile);
  528. }
  529. if(!file_exists($tmpfile))
  530. {
  531. $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid=='spec' ? 'article_spec.htm' : 'article_default.htm');
  532. if ( defined('DEDEMOB') )
  533. {
  534. $tmpfile =str_replace('.htm','_m.htm',$tmpfile);
  535. }
  536. }
  537. if (!preg_match("#.htm$#", $tmpfile)) return FALSE;
  538. return $tmpfile;
  539. }
  540. /**
  541. * 动态输出结果
  542. *
  543. * @access public
  544. * @return void
  545. */
  546. function display()
  547. {
  548. global $htmltype;
  549. if($this->IsError)
  550. {
  551. return '';
  552. }
  553. $this->Fields["displaytype"] = "dm";
  554. if($this->NowPage > 1) $this->Fields["title"] = $this->Fields["title"]."({$this->NowPage})";
  555. //预编译
  556. $this->LoadTemplet();
  557. $this->ParAddTable();
  558. $this->ParseTempletsFirst();
  559. //跳转网址
  560. $this->Fields['flag']=empty($this->Fields['flag'])? "" : $this->Fields['flag'];
  561. if(preg_match("#j#", $this->Fields['flag']) && $this->Fields['redirecturl'] != '')
  562. {
  563. if($GLOBALS['cfg_jump_once']=='N')
  564. {
  565. $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";
  566. $pageHtml .= "<meta http-equiv=\"refresh\" content=\"3;URL=".$this->Fields['redirecturl']."\">\r\n</head>\r\n<body>\r\n";
  567. $pageHtml .= "现在正在转向:".$this->Fields['title'].",请稍候...<br/><br/>\r\n转向内容简介:".$this->Fields['description']."\r\n</body>\r\n</html>\r\n";
  568. echo $pageHtml;
  569. }
  570. else
  571. {
  572. header("location:{$this->Fields['redirecturl']}");
  573. }
  574. exit();
  575. }
  576. $pageCount = $this->NowPage;
  577. $this->ParseDMFields($pageCount,0);
  578. $this->dtp->display();
  579. }
  580. /**
  581. * 载入模板
  582. *
  583. * @access public
  584. * @return void
  585. */
  586. function LoadTemplet()
  587. {
  588. if($this->TempSource=='')
  589. {
  590. $tempfile = $this->GetTempletFile();
  591. if(!file_exists($tempfile) || !is_file($tempfile))
  592. {
  593. echo "文档ID:{$this->Fields['id']} - {$this->TypeLink->TypeInfos['typename']} - {$this->Fields['title']}<br />";
  594. echo "模板文件不存在,无法解析文档!";
  595. exit();
  596. }
  597. $this->dtp->LoadTemplate($tempfile);
  598. $this->TempSource = $this->dtp->SourceString;
  599. }
  600. else
  601. {
  602. $this->dtp->LoadSource($this->TempSource);
  603. }
  604. }
  605. /**
  606. * 解析模板,对固定的标记进行初始给值
  607. *
  608. * @access public
  609. * @return void
  610. */
  611. function ParseTempletsFirst()
  612. {
  613. if(empty($this->Fields['keywords']))
  614. {
  615. $this->Fields['keywords'] = '';
  616. }
  617. if(empty($this->Fields['reid']))
  618. {
  619. $this->Fields['reid'] = 0;
  620. }
  621. $GLOBALS['envs']['tags'] = $this->Fields['tags'];
  622. if(isset($this->TypeLink->TypeInfos['reid']))
  623. {
  624. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  625. }
  626. $GLOBALS['envs']['keyword'] = $this->Fields['keywords'];
  627. $GLOBALS['envs']['typeid'] = $this->Fields['typeid'];
  628. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  629. $GLOBALS['envs']['aid'] = $GLOBALS['envs']['id'] = $this->Fields['id'];
  630. $GLOBALS['envs']['adminid'] = $GLOBALS['envs']['mid'] = isset($this->Fields['mid'])? $this->Fields['mid'] : 1;
  631. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  632. if($this->Fields['reid']>0)
  633. {
  634. $GLOBALS['envs']['typeid'] = $this->Fields['reid'];
  635. }
  636. MakeOneTag($this->dtp, $this, 'N');
  637. }
  638. /**
  639. * 解析模板,对内容里的变动进行赋值
  640. *
  641. * @access public
  642. * @param string $pageNo 页码数
  643. * @param string $ismake 是否生成
  644. * @return string
  645. */
  646. function ParseDMFields($pageNo, $ismake=1)
  647. {
  648. $this->NowPage = $pageNo;
  649. $this->Fields['nowpage'] = $this->NowPage;
  650. if($this->SplitPageField!='' && isset($this->Fields[$this->SplitPageField]))
  651. {
  652. $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1];
  653. if($pageNo>1) $this->Fields['description'] = trim(preg_replace("/[\r\n\t]/", ' ', cn_substr(html2text($this->Fields[$this->SplitPageField]), 200)));
  654. }
  655. //解析模板
  656. if(is_array($this->dtp->CTags))
  657. {
  658. foreach($this->dtp->CTags as $i=>$ctag)
  659. {
  660. if($ctag->GetName()=='field')
  661. {
  662. $this->dtp->Assign($i, $this->GetField($ctag->GetAtt('name'), $ctag) );
  663. }
  664. else if($ctag->GetName()=='pagebreak')
  665. {
  666. if($ismake==0)
  667. {
  668. $this->dtp->Assign($i,$this->GetPagebreakDM($this->TotalPage,$this->NowPage,$this->ArcID));
  669. }
  670. else
  671. {
  672. $this->dtp->Assign($i,$this->GetPagebreak($this->TotalPage,$this->NowPage,$this->ArcID));
  673. }
  674. }
  675. else if($ctag->GetName()=='pagetitle')
  676. {
  677. if($ismake==0)
  678. {
  679. $this->dtp->Assign($i,$this->GetPageTitlesDM($ctag->GetAtt("style"),$pageNo));
  680. }
  681. else
  682. {
  683. $this->dtp->Assign($i,$this->GetPageTitlesST($ctag->GetAtt("style"),$pageNo));
  684. }
  685. }
  686. else if($ctag->GetName()=='prenext')
  687. {
  688. $this->dtp->Assign($i,$this->GetPreNext($ctag->GetAtt('get')));
  689. }
  690. else if($ctag->GetName()=='fieldlist')
  691. {
  692. $innertext = trim($ctag->GetInnerText());
  693. if($innertext=='') $innertext = GetSysTemplets('tag_fieldlist.htm');
  694. $dtp2 = new DedeTagParse();
  695. $dtp2->SetNameSpace('field','[',']');
  696. $dtp2->LoadSource($innertext);
  697. $oldSource = $dtp2->SourceString;
  698. $oldCtags = $dtp2->CTags;
  699. $res = '';
  700. if(is_array($this->ChannelUnit->ChannelFields) && is_array($dtp2->CTags))
  701. {
  702. foreach($this->ChannelUnit->ChannelFields as $k=>$v)
  703. {
  704. if(isset($v['autofield']) && empty($v['autofield'])) {
  705. continue;
  706. }
  707. $dtp2->SourceString = $oldSource;
  708. $dtp2->CTags = $oldCtags;
  709. $fname = $v['itemname'];
  710. foreach($dtp2->CTags as $tid=>$ctag2)
  711. {
  712. if($ctag2->GetName()=='name')
  713. {
  714. $dtp2->Assign($tid,$fname);
  715. }
  716. else if($ctag2->GetName()=='tagname')
  717. {
  718. $dtp2->Assign($tid,$k);
  719. }
  720. else if($ctag2->GetName()=='value')
  721. {
  722. $this->Fields[$k] = $this->ChannelUnit->MakeField($k,$this->Fields[$k],$ctag2);
  723. @$dtp2->Assign($tid,$this->Fields[$k]);
  724. }
  725. }
  726. $res .= $dtp2->GetResult();
  727. }
  728. }
  729. $this->dtp->Assign($i,$res);
  730. }//end case
  731. }//结束模板循环
  732. }
  733. }
  734. /**
  735. * 关闭所占用的资源
  736. *
  737. * @access public
  738. * @return void
  739. */
  740. function Close()
  741. {
  742. $this->FixedValues = '';
  743. $this->Fields = '';
  744. }
  745. /**
  746. * 获取上一篇,下一篇链接
  747. *
  748. * @access public
  749. * @param string $gtype 获取类型
  750. * pre:上一篇 preimg:上一篇图片 next:下一篇 nextimg:下一篇图片
  751. * @return string
  752. */
  753. function GetPreNext($gtype='')
  754. {
  755. $rs = '';
  756. if(count($this->PreNext)<2)
  757. {
  758. $aid = $this->ArcID;
  759. $preR = $this->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id desc");
  760. $nextR = $this->dsql->GetOne("Select id From `#@__arctiny` where id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id asc");
  761. $next = (is_array($nextR) ? " where arc.id={$nextR['id']} " : ' where 1>2 ');
  762. $pre = (is_array($preR) ? " where arc.id={$preR['id']} " : ' where 1>2 ');
  763. $query = "Select arc.id,arc.title,arc.shorttitle,arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,arc.filename,arc.litpic,
  764. t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath
  765. from `#@__archives` arc left join #@__arctype t on arc.typeid=t.id ";
  766. $nextRow = $this->dsql->GetOne($query.$next);
  767. $preRow = $this->dsql->GetOne($query.$pre);
  768. if(is_array($preRow))
  769. {
  770. if ( defined('DEDEMOB') )
  771. {
  772. $mlink = 'view.php?aid='.$preRow['id'];
  773. } else {
  774. $mlink = GetFileUrl($preRow['id'],$preRow['typeid'],$preRow['senddate'],$preRow['title'],$preRow['ismake'],$preRow['arcrank'],
  775. $preRow['namerule'],$preRow['typedir'],$preRow['money'],$preRow['filename'],$preRow['moresite'],$preRow['siteurl'],$preRow['sitepath']);
  776. }
  777. $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> ";
  778. $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$preRow['title']}\"/></a> ";
  779. }
  780. else
  781. {
  782. $this->PreNext['pre'] = "上一篇:没有了 ";
  783. $this->PreNext['preimg'] ="<img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有上一图集了!\"/>";
  784. }
  785. if(is_array($nextRow))
  786. {
  787. if ( defined('DEDEMOB') )
  788. {
  789. $mlink = 'view.php?aid='.$preRow['id'];
  790. } else {
  791. $mlink = GetFileUrl($nextRow['id'],$nextRow['typeid'],$nextRow['senddate'],$nextRow['title'],$nextRow['ismake'],$nextRow['arcrank'],
  792. $nextRow['namerule'],$nextRow['typedir'],$nextRow['money'],$nextRow['filename'],$nextRow['moresite'],$nextRow['siteurl'],$nextRow['sitepath']);
  793. }
  794. $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
  795. $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\"/></a> ";
  796. }
  797. else
  798. {
  799. $this->PreNext['next'] = "下一篇:没有了 ";
  800. $this->PreNext['nextimg'] ="<a href='javascript:void(0)' alt=\"\"><img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有下一图集了!\"/></a>";
  801. }
  802. }
  803. if($gtype=='pre')
  804. {
  805. $rs = $this->PreNext['pre'];
  806. }
  807. else if($gtype=='preimg'){
  808. $rs = $this->PreNext['preimg'];
  809. }
  810. else if($gtype=='next')
  811. {
  812. $rs = $this->PreNext['next'];
  813. }
  814. else if($gtype=='nextimg'){
  815. $rs = $this->PreNext['nextimg'];
  816. }
  817. else
  818. {
  819. $rs = $this->PreNext['pre']." &nbsp; ".$this->PreNext['next'];
  820. }
  821. return $rs;
  822. }
  823. /**
  824. * 获得动态页面分页列表
  825. *
  826. * @access public
  827. * @param int $totalPage 总页数
  828. * @param int $nowPage 当前页数
  829. * @param int $aid 文档id
  830. * @return string
  831. */
  832. function GetPagebreakDM($totalPage, $nowPage, $aid)
  833. {
  834. global $cfg_rewrite;
  835. if($totalPage==1)
  836. {
  837. return "";
  838. }
  839. $PageList = "<li><a>共".$totalPage."页: </a></li>";
  840. $nPage = $nowPage-1;
  841. $lPage = $nowPage+1;
  842. if($nowPage==1)
  843. {
  844. $PageList.="<li><a href='#'>上一页</a></li>";
  845. }
  846. else
  847. {
  848. if($nPage==1)
  849. {
  850. $PageList.="<li><a href='view.php?aid=$aid'>上一页</a></li>";
  851. if($cfg_rewrite == 'Y')
  852. {
  853. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  854. }
  855. }
  856. else
  857. {
  858. $PageList.="<li><a href='view.php?aid=$aid&pageno=$nPage'>上一页</a></li>";
  859. if($cfg_rewrite == 'Y')
  860. {
  861. $PageList = str_replace(".php?aid=", "-", $PageList);
  862. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  863. }
  864. }
  865. }
  866. for($i=1;$i<=$totalPage;$i++)
  867. {
  868. if($i==1)
  869. {
  870. if($nowPage!=1)
  871. {
  872. $PageList.="<li><a href='view.php?aid=$aid'>1</a></li>";
  873. if($cfg_rewrite == 'Y')
  874. {
  875. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  876. }
  877. }
  878. else
  879. {
  880. $PageList.="<li class=\"thisclass\"><a>1</a></li>";
  881. }
  882. }
  883. else
  884. {
  885. $n = $i;
  886. if($nowPage!=$i)
  887. {
  888. $PageList.="<li><a href='view.php?aid=$aid&pageno=$i'>".$n."</a></li>";
  889. if($cfg_rewrite == 'Y')
  890. {
  891. $PageList = str_replace(".php?aid=", "-", $PageList);
  892. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  893. }
  894. }
  895. else
  896. {
  897. $PageList.="<li class=\"thisclass\"><a href='#'>{$n}</a></li>";
  898. }
  899. }
  900. }
  901. if($lPage <= $totalPage)
  902. {
  903. $PageList.="<li><a href='view.php?aid=$aid&pageno=$lPage'>下一页</a></li>";
  904. if($cfg_rewrite == 'Y')
  905. {
  906. $PageList = str_replace(".php?aid=", "-", $PageList);
  907. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  908. }
  909. }
  910. else
  911. {
  912. $PageList.= "<li><a href='#'>下一页</a></li>";
  913. }
  914. return $PageList;
  915. }
  916. /**
  917. * 获得静态页面分页列表
  918. *
  919. * @access public
  920. * @param int $totalPage 总页数
  921. * @param int $nowPage 当前页数
  922. * @param int $aid 文档id
  923. * @return string
  924. */
  925. function GetPagebreak($totalPage, $nowPage, $aid)
  926. {
  927. if($totalPage==1)
  928. {
  929. return "";
  930. }
  931. $PageList = "<li><a>共".$totalPage."页: </a></li>";
  932. $nPage = $nowPage-1;
  933. $lPage = $nowPage+1;
  934. if($nowPage==1)
  935. {
  936. $PageList.="<li><a href='#'>上一页</a></li>";
  937. }
  938. else
  939. {
  940. if($nPage==1)
  941. {
  942. $PageList.="<li><a href='".$this->NameFirst.".".$this->ShortName."'>上一页</a></li>";
  943. }
  944. else
  945. {
  946. $PageList.="<li><a href='".$this->NameFirst."_".$nPage.".".$this->ShortName."'>上一页</a></li>";
  947. }
  948. }
  949. for($i=1;$i<=$totalPage;$i++)
  950. {
  951. if($i==1)
  952. {
  953. if($nowPage!=1)
  954. {
  955. $PageList.="<li><a href='".$this->NameFirst.".".$this->ShortName."'>1</a></li>";
  956. }
  957. else
  958. {
  959. $PageList.="<li class=\"thisclass\"><a href='#'>1</a></li>";
  960. }
  961. }
  962. else
  963. {
  964. $n = $i;
  965. if($nowPage!=$i)
  966. {
  967. $PageList.="<li><a href='".$this->NameFirst."_".$i.".".$this->ShortName."'>".$n."</a></li>";
  968. }
  969. else
  970. {
  971. $PageList.="<li class=\"thisclass\"><a href='#'>{$n}</a></li>";
  972. }
  973. }
  974. }
  975. if($lPage <= $totalPage)
  976. {
  977. $PageList.="<li><a href='".$this->NameFirst."_".$lPage.".".$this->ShortName."'>下一页</a></li>";
  978. }
  979. else
  980. {
  981. $PageList.= "<li><a href='#'>下一页</a></li>";
  982. }
  983. return $PageList;
  984. }
  985. /**
  986. * 获得动态页面小标题
  987. *
  988. * @access public
  989. * @param string $styleName 类型名称
  990. * @param string $pageNo 页码数
  991. * @return string
  992. */
  993. function GetPageTitlesDM($styleName, $pageNo)
  994. {
  995. if($this->TotalPage==1)
  996. {
  997. return "";
  998. }
  999. if(count($this->SplitTitles)==0)
  1000. {
  1001. return "";
  1002. }
  1003. $i=1;
  1004. $aid = $this->ArcID;
  1005. if($styleName=='link')
  1006. {
  1007. $revalue = "";
  1008. foreach($this->SplitTitles as $k=>$v)
  1009. {
  1010. if($i==1)
  1011. {
  1012. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> \r\n";
  1013. }
  1014. else
  1015. {
  1016. if($pageNo==$i)
  1017. {
  1018. $revalue .= " $v \r\n";
  1019. }
  1020. else
  1021. {
  1022. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> \r\n";
  1023. }
  1024. }
  1025. $i++;
  1026. }
  1027. }
  1028. else
  1029. {
  1030. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  1031. foreach($this->SplitTitles as $k=>$v)
  1032. {
  1033. if($i==1)
  1034. {
  1035. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  1036. }
  1037. else
  1038. {
  1039. if($pageNo==$i)
  1040. {
  1041. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i' selected>{$i}、{$v}</option>\r\n";
  1042. }
  1043. else
  1044. {
  1045. $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  1046. }
  1047. }
  1048. $i++;
  1049. }
  1050. $revalue .= "</select>\r\n";
  1051. }
  1052. return $revalue;
  1053. }
  1054. /**
  1055. * 获得静态页面小标题
  1056. *
  1057. * @access public
  1058. * @param string $styleName 类型名称
  1059. * @param string $pageNo 页码数
  1060. * @return string
  1061. */
  1062. function GetPageTitlesST($styleName, $pageNo)
  1063. {
  1064. if($this->TotalPage==1)
  1065. {
  1066. return "";
  1067. }
  1068. if(count($this->SplitTitles)==0)
  1069. {
  1070. return "";
  1071. }
  1072. $i=1;
  1073. if($styleName=='link')
  1074. {
  1075. $revalue = "";
  1076. foreach($this->SplitTitles as $k=>$v)
  1077. {
  1078. if($i==1)
  1079. {
  1080. $revalue .= "<a href='".$this->NameFirst.".".$this->ShortName."'>$v</a> \r\n";
  1081. }
  1082. else
  1083. {
  1084. if($pageNo==$i)
  1085. {
  1086. $revalue .= " $v \r\n";
  1087. }
  1088. else
  1089. {
  1090. $revalue .= "<a href='".$this->NameFirst."_".$i.".".$this->ShortName."'>$v</a> \r\n";
  1091. }
  1092. }
  1093. $i++;
  1094. }
  1095. }
  1096. else
  1097. {
  1098. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  1099. foreach($this->SplitTitles as $k=>$v)
  1100. {
  1101. if($i==1)
  1102. {
  1103. $revalue .= "<option value='".$this->NameFirst.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  1104. }
  1105. else
  1106. {
  1107. if($pageNo==$i)
  1108. {
  1109. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."' selected>{$i}、{$v}</option>\r\n";
  1110. }
  1111. else
  1112. {
  1113. $revalue .= "<option value='".$this->NameFirst."_".$i.".".$this->ShortName."'>{$i}、{$v}</option>\r\n";
  1114. }
  1115. }
  1116. $i++;
  1117. }
  1118. $revalue .= "</select>\r\n";
  1119. }
  1120. return $revalue;
  1121. }
  1122. /**
  1123. * 高亮问题修正, 排除alt title <a></a>直接的字符替换
  1124. *
  1125. * @param string $kw
  1126. * @param string $body
  1127. * @return string
  1128. */
  1129. function ReplaceKeyword($kw,&$body)
  1130. {
  1131. global $cfg_cmspath;
  1132. $maxkey = 5;
  1133. $kws = explode(",",trim($kw)); //以分好为间隔符
  1134. $i=0;
  1135. $karr = $kaarr = $GLOBALS['replaced'] = array();
  1136. //暂时屏蔽超链接
  1137. $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
  1138. /*
  1139. foreach($kws as $k)
  1140. {
  1141. $k = trim($k);
  1142. if($k!="")
  1143. {
  1144. if($i > $maxkey)
  1145. {
  1146. break;
  1147. }
  1148. $myrow = $this->dsql->GetOne("SELECT * FROM #@__keywords WHERE keyword='$k' AND rpurl<>'' ");
  1149. if(is_array($myrow))
  1150. {
  1151. $karr[] = $k;
  1152. $GLOBALS['replaced'][$k] = 0;
  1153. $kaarr[] = "<a href='{$myrow['rpurl']}'><u>$k</u></a>";
  1154. }
  1155. $i++;
  1156. }
  1157. }
  1158. */
  1159. $query = "SELECT * FROM #@__keywords WHERE rpurl<>'' ORDER BY rank DESC";
  1160. $this->dsql->SetQuery($query);
  1161. $this->dsql->Execute();
  1162. while($row = $this->dsql->GetArray())
  1163. {
  1164. $key = trim($row['keyword']);
  1165. $key_url=trim($row['rpurl']);
  1166. $karr[] = $key;
  1167. $kaarr[] = "<a href='$key_url' target='_blank'><u>$key</u></a>";
  1168. }
  1169. // 这里可能会有错误
  1170. if (version_compare(PHP_VERSION, '5.5.0', '>='))
  1171. {
  1172. $body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
  1173. } else {
  1174. $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
  1175. }
  1176. //恢复超链接
  1177. $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
  1178. return $body;
  1179. }
  1180. }//End Archives
  1181. //高亮专用, 替换多次是可能不能达到最多次
  1182. function _highlight($string, $words, $result, $pre)
  1183. {
  1184. global $cfg_replace_num;
  1185. if (version_compare(PHP_VERSION, '5.5.0', '>='))
  1186. {
  1187. $string = $string[0];
  1188. $pre = $pre[0];
  1189. }
  1190. $string = str_replace('\"', '"', $string);
  1191. if($cfg_replace_num > 0)
  1192. {
  1193. foreach ($words as $key => $word)
  1194. {
  1195. if($GLOBALS['replaced'][$word] == 1)
  1196. {
  1197. continue;
  1198. }
  1199. $string = preg_replace("#".preg_quote($word)."#", $result[$key], $string, $cfg_replace_num);
  1200. if(strpos($string, $word) !== FALSE)
  1201. {
  1202. $GLOBALS['replaced'][$word] = 1;
  1203. }
  1204. }
  1205. }
  1206. else
  1207. {
  1208. $string = str_replace($words, $result, $string);
  1209. }
  1210. return $pre.$string;
  1211. }