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

1226 lines
44KB

  1. <?php if(!defined('DEDEINC')) exit('Request Error!');
  2. /**
  3. * 文档列表类
  4. *
  5. * @version $Id: arc.listview.class.php 2 15:15 2010年7月7日Z tianya $
  6. * @package DedeCMS.Libraries
  7. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. require_once(DEDEINC.'/arc.partview.class.php');
  12. require_once(DEDEINC.'/ftp.class.php');
  13. helper('cache');
  14. @set_time_limit(0);
  15. /**
  16. * 自由列表类
  17. *
  18. * @package ListView
  19. * @subpackage DedeCMS.Libraries
  20. * @link http://www.dedecms.com
  21. */
  22. class ListView
  23. {
  24. var $dsql;
  25. var $dtp;
  26. var $dtp2;
  27. var $TypeID;
  28. var $TypeLink;
  29. var $PageNo;
  30. var $TotalPage;
  31. var $TotalResult;
  32. var $PageSize;
  33. var $ChannelUnit;
  34. var $ListType;
  35. var $Fields;
  36. var $PartView;
  37. var $upPageType;
  38. var $addSql;
  39. var $IsError;
  40. var $CrossID;
  41. var $IsReplace;
  42. var $ftp;
  43. var $remoteDir;
  44. /**
  45. * php5构造函数
  46. *
  47. * @access public
  48. * @param int $typeid 栏目ID
  49. * @param int $uppage 上一页
  50. * @return string
  51. */
  52. function __construct($typeid, $uppage=1)
  53. {
  54. global $dsql,$ftp;
  55. $this->TypeID = $typeid;
  56. $this->dsql = &$dsql;
  57. $this->CrossID = '';
  58. $this->IsReplace = false;
  59. $this->IsError = false;
  60. $this->dtp = new DedeTagParse();
  61. $this->dtp->SetRefObj($this);
  62. $this->dtp->SetNameSpace("dede", "{", "}");
  63. $this->dtp2 = new DedeTagParse();
  64. $this->dtp2->SetNameSpace("field","[","]");
  65. $this->TypeLink = new TypeLink($typeid);
  66. $this->upPageType = $uppage;
  67. $this->ftp = &$ftp;
  68. $this->remoteDir = '';
  69. $this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";
  70. if(!is_array($this->TypeLink->TypeInfos))
  71. {
  72. $this->IsError = true;
  73. }
  74. if(!$this->IsError)
  75. {
  76. $this->ChannelUnit = new ChannelUnit($this->TypeLink->TypeInfos['channeltype']);
  77. $this->Fields = $this->TypeLink->TypeInfos;
  78. $this->Fields['id'] = $typeid;
  79. $this->Fields['position'] = $this->TypeLink->GetPositionLink(true);
  80. $this->Fields['title'] = preg_replace("/[<>]/", " / ", $this->TypeLink->GetPositionLink(false));
  81. //设置一些全局参数的值
  82. foreach($GLOBALS['PubFields'] as $k=>$v) $this->Fields[$k] = $v;
  83. $this->Fields['rsslink'] = $GLOBALS['cfg_cmsurl']."/data/rss/".$this->TypeID.".xml";
  84. //设置环境变量
  85. SetSysEnv($this->TypeID,$this->Fields['typename'],0,'','list');
  86. $this->Fields['typeid'] = $this->TypeID;
  87. //获得交叉栏目ID
  88. if($this->TypeLink->TypeInfos['cross']>0 && $this->TypeLink->TypeInfos['ispart']==0)
  89. {
  90. $selquery = '';
  91. if($this->TypeLink->TypeInfos['cross']==1)
  92. {
  93. $selquery = "SELECT id,topid FROM `#@__arctype` WHERE typename LIKE '{$this->Fields['typename']}' AND id<>'{$this->TypeID}' AND topid<>'{$this->TypeID}' ";
  94. }
  95. else
  96. {
  97. $this->Fields['crossid'] = preg_replace('/[^0-9,]/', '', trim($this->Fields['crossid']));
  98. if($this->Fields['crossid']!='')
  99. {
  100. $selquery = "SELECT id,topid FROM `#@__arctype` WHERE id in({$this->Fields['crossid']}) AND id<>{$this->TypeID} AND topid<>{$this->TypeID} ";
  101. }
  102. }
  103. if($selquery!='')
  104. {
  105. $this->dsql->SetQuery($selquery);
  106. $this->dsql->Execute();
  107. while($arr = $this->dsql->GetArray())
  108. {
  109. $this->CrossID .= ($this->CrossID=='' ? $arr['id'] : ','.$arr['id']);
  110. }
  111. }
  112. }
  113. }//!error
  114. }
  115. //php4构造函数
  116. function ListView($typeid,$uppage=0){
  117. $this->__construct($typeid,$uppage);
  118. }
  119. //关闭相关资源
  120. function Close()
  121. {
  122. }
  123. /**
  124. * 统计列表里的记录
  125. *
  126. * @access public
  127. * @param string
  128. * @return string
  129. */
  130. function CountRecord()
  131. {
  132. global $cfg_list_son,$cfg_need_typeid2,$cfg_cross_sectypeid;
  133. if(empty($cfg_need_typeid2)) $cfg_need_typeid2 = 'N';
  134. //统计数据库记录
  135. $this->TotalResult = -1;
  136. if(isset($GLOBALS['TotalResult'])) $this->TotalResult = $GLOBALS['TotalResult'];
  137. if(isset($GLOBALS['PageNo'])) $this->PageNo = $GLOBALS['PageNo'];
  138. else $this->PageNo = 1;
  139. $this->addSql = " arc.arcrank > -1 ";
  140. $typeid2like = " '%,{$this->TypeID},%' ";
  141. if($cfg_list_son=='N')
  142. {
  143. if($cfg_need_typeid2=='N')
  144. {
  145. if($this->CrossID=='') $this->addSql .= " AND (arc.typeid='".$this->TypeID."') ";
  146. else $this->addSql .= " AND (arc.typeid in({$this->CrossID},{$this->TypeID})) ";
  147. }
  148. else
  149. {
  150. if($this->CrossID=='')
  151. {
  152. $this->addSql .= " AND ( (arc.typeid='".$this->TypeID."') OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like) ";
  153. } else {
  154. if($cfg_cross_sectypeid == 'Y')
  155. {
  156. $typeid2Clike = " '%,{$this->CrossID},%' ";
  157. $this->addSql .= " AND ( arc.typeid IN({$this->CrossID},{$this->TypeID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2Clike)";
  158. } else {
  159. $this->addSql .= " AND ( arc.typeid IN({$this->CrossID},{$this->TypeID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like)";
  160. }
  161. }
  162. }
  163. }
  164. else
  165. {
  166. $sonids = GetSonIds($this->TypeID,$this->Fields['channeltype']);
  167. if(!preg_match("/,/", $sonids)) {
  168. $sonidsCon = " arc.typeid = '$sonids' ";
  169. }
  170. else {
  171. $sonidsCon = " arc.typeid IN($sonids) ";
  172. }
  173. if($cfg_need_typeid2=='N')
  174. {
  175. if($this->CrossID=='') $this->addSql .= " AND ( $sonidsCon ) ";
  176. else $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) ) ";
  177. }
  178. else
  179. {
  180. if($this->CrossID=='')
  181. {
  182. $this->addSql .= " AND ( $sonidsCon OR CONCAT(',', arc.typeid2, ',') like $typeid2like ) ";
  183. } else {
  184. if($cfg_cross_sectypeid == 'Y')
  185. {
  186. $typeid2Clike = " '%,{$this->CrossID},%' ";
  187. $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2Clike) ";
  188. } else {
  189. $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like) ";
  190. }
  191. }
  192. }
  193. }
  194. if($this->TotalResult==-1)
  195. {
  196. $cquery = "SELECT COUNT(*) AS dd FROM `#@__arctiny` arc WHERE ".$this->addSql;
  197. $row = $this->dsql->GetOne($cquery);
  198. if(is_array($row))
  199. {
  200. $this->TotalResult = $row['dd'];
  201. }
  202. else
  203. {
  204. $this->TotalResult = 0;
  205. }
  206. }
  207. //初始化列表模板,并统计页面总数
  208. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist'];
  209. $tempfile = str_replace("{tid}", $this->TypeID, $tempfile);
  210. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  211. if ( defined('DEDEMOB') )
  212. {
  213. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  214. }
  215. if(!file_exists($tempfile))
  216. {
  217. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default.htm";
  218. if ( defined('DEDEMOB') )
  219. {
  220. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  221. }
  222. }
  223. if(!file_exists($tempfile)||!is_file($tempfile))
  224. {
  225. echo "模板文件不存在,无法解析文档!";
  226. exit();
  227. }
  228. $this->dtp->LoadTemplate($tempfile);
  229. $ctag = $this->dtp->GetTag("page");
  230. if(!is_object($ctag))
  231. {
  232. $ctag = $this->dtp->GetTag("list");
  233. }
  234. if(!is_object($ctag))
  235. {
  236. $this->PageSize = 20;
  237. }
  238. else
  239. {
  240. if($ctag->GetAtt("pagesize")!="")
  241. {
  242. $this->PageSize = $ctag->GetAtt("pagesize");
  243. }
  244. else
  245. {
  246. $this->PageSize = 20;
  247. }
  248. }
  249. $this->TotalPage = ceil($this->TotalResult/$this->PageSize);
  250. }
  251. /**
  252. * 列表创建HTML
  253. *
  254. * @access public
  255. * @param string $startpage 开始页面
  256. * @param string $makepagesize 创建文件数目
  257. * @param string $isremote 是否为远程
  258. * @return string
  259. */
  260. function MakeHtml($startpage=1, $makepagesize=0, $isremote=0)
  261. {
  262. global $cfg_remote_site;
  263. if(empty($startpage))
  264. {
  265. $startpage = 1;
  266. }
  267. //创建封面模板文件
  268. if($this->TypeLink->TypeInfos['isdefault']==-1)
  269. {
  270. echo '这个类目是动态类目!';
  271. return '../plus/list.php?tid='.$this->TypeLink->TypeInfos['id'];
  272. }
  273. //单独页面
  274. else if($this->TypeLink->TypeInfos['ispart']>0)
  275. {
  276. $reurl = $this->MakePartTemplets();
  277. return $reurl;
  278. }
  279. if(empty($this->TotalResult)) $this->CountRecord();
  280. //初步给固定值的标记赋值
  281. $this->ParseTempletsFirst();
  282. $totalpage = ceil($this->TotalResult/$this->PageSize);
  283. if($totalpage==0)
  284. {
  285. $totalpage = 1;
  286. }
  287. CreateDir(MfTypedir($this->Fields['typedir']));
  288. $murl = '';
  289. if($makepagesize > 0)
  290. {
  291. $endpage = $startpage+$makepagesize;
  292. }
  293. else
  294. {
  295. $endpage = ($totalpage+1);
  296. }
  297. if( $endpage >= $totalpage+1 )
  298. {
  299. $endpage = $totalpage+1;
  300. }
  301. if($endpage==1)
  302. {
  303. $endpage = 2;
  304. }
  305. for($this->PageNo=$startpage; $this->PageNo < $endpage; $this->PageNo++)
  306. {
  307. $this->ParseDMFields($this->PageNo,1);
  308. $makeFile = $this->GetMakeFileRule($this->Fields['id'],'list',$this->Fields['typedir'],'',$this->Fields['namerule2']);
  309. $makeFile = str_replace("{page}", $this->PageNo, $makeFile);
  310. $murl = $makeFile;
  311. if(!preg_match("/^\//", $makeFile))
  312. {
  313. $makeFile = "/".$makeFile;
  314. }
  315. $makeFile = $this->GetTruePath().$makeFile;
  316. $makeFile = preg_replace("/\/{1,}/", "/", $makeFile);
  317. $murl = $this->GetTrueUrl($murl);
  318. $this->dtp->SaveTo($makeFile);
  319. //如果启用远程发布则需要进行判断
  320. if($cfg_remote_site=='Y'&& $isremote == 1)
  321. {
  322. //分析远程文件路径
  323. $remotefile = str_replace(DEDEROOT, '',$makeFile);
  324. $localfile = '..'.$remotefile;
  325. $remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);
  326. //不相等则说明已经切换目录则可以创建镜像
  327. $this->ftp->rmkdir($remotedir);
  328. $this->ftp->upload($localfile, $remotefile, 'acii');
  329. }
  330. }
  331. if($startpage==1)
  332. {
  333. //如果列表启用封面文件,复制这个文件第一页
  334. if($this->TypeLink->TypeInfos['isdefault']==1
  335. && $this->TypeLink->TypeInfos['ispart']==0)
  336. {
  337. $onlyrule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],'',$this->Fields['namerule2']);
  338. $onlyrule = str_replace("{page}","1",$onlyrule);
  339. $list_1 = $this->GetTruePath().$onlyrule;
  340. $murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];
  341. //如果启用远程发布则需要进行判断
  342. if($cfg_remote_site=='Y'&& $isremote == 1)
  343. {
  344. //分析远程文件路径
  345. $remotefile = $murl;
  346. $localfile = '..'.$remotefile;
  347. $remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);
  348. //不相等则说明已经切换目录则可以创建镜像
  349. $this->ftp->rmkdir($remotedir);
  350. $this->ftp->upload($localfile, $remotefile, 'acii');
  351. }
  352. $indexname = $this->GetTruePath().$murl;
  353. copy($list_1,$indexname);
  354. }
  355. }
  356. return $murl;
  357. }
  358. /**
  359. * 显示列表
  360. *
  361. * @access public
  362. * @return void
  363. */
  364. function Display()
  365. {
  366. if($this->TypeLink->TypeInfos['ispart']>0)
  367. {
  368. $this->DisplayPartTemplets();
  369. return ;
  370. }
  371. $this->CountRecord();
  372. if((empty($this->PageNo) || $this->PageNo==1)
  373. && $this->TypeLink->TypeInfos['ispart']==1)
  374. {
  375. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  376. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  377. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  378. $tempfile = $tmpdir."/".$tempfile;
  379. if ( defined('DEDEMOB') )
  380. {
  381. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  382. }
  383. if(!file_exists($tempfile))
  384. {
  385. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  386. if ( defined('DEDEMOB') )
  387. {
  388. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  389. }
  390. }
  391. $this->dtp->LoadTemplate($tempfile);
  392. }
  393. $this->ParseTempletsFirst();
  394. $this->ParseDMFields($this->PageNo,0);
  395. $this->dtp->Display();
  396. }
  397. /**
  398. * 创建单独模板页面
  399. *
  400. * @access public
  401. * @return string
  402. */
  403. function MakePartTemplets()
  404. {
  405. $this->PartView = new PartView($this->TypeID,false);
  406. $this->PartView->SetTypeLink($this->TypeLink);
  407. $nmfa = 0;
  408. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  409. if($this->Fields['ispart']==1)
  410. {
  411. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  412. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  413. $tempfile = $tmpdir."/".$tempfile;
  414. if ( defined('DEDEMOB') )
  415. {
  416. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  417. }
  418. if(!file_exists($tempfile))
  419. {
  420. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  421. if ( defined('DEDEMOB') )
  422. {
  423. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  424. }
  425. }
  426. $this->PartView->SetTemplet($tempfile);
  427. }
  428. else if($this->Fields['ispart']==2)
  429. {
  430. //跳转网址
  431. return $this->Fields['typedir'];
  432. }
  433. CreateDir(MfTypedir($this->Fields['typedir']));
  434. $makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
  435. $makeUrl = preg_replace("/\/{1,}/", "/", $makeUrl);
  436. $makeFile = $this->GetTruePath().$makeUrl;
  437. if($nmfa==0)
  438. {
  439. $this->PartView->SaveToHtml($makeFile);
  440. //如果启用远程发布则需要进行判断
  441. if($GLOBALS['cfg_remote_site']=='Y'&& $isremote == 1)
  442. {
  443. //分析远程文件路径
  444. $remotefile = str_replace(DEDEROOT, '',$makeFile);
  445. $localfile = '..'.$remotefile;
  446. $remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);
  447. //不相等则说明已经切换目录则可以创建镜像
  448. $this->ftp->rmkdir($remotedir);
  449. $this->ftp->upload($localfile, $remotefile, 'acii');
  450. }
  451. }
  452. else
  453. {
  454. if(!file_exists($makeFile))
  455. {
  456. $this->PartView->SaveToHtml($makeFile);
  457. //如果启用远程发布则需要进行判断
  458. if($cfg_remote_site=='Y'&& $isremote == 1)
  459. {
  460. //分析远程文件路径
  461. $remotefile = str_replace(DEDEROOT, '',$makeFile);
  462. $localfile = '..'.$remotefile;
  463. $remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);
  464. //不相等则说明已经切换目录则可以创建镜像
  465. $this->ftp->rmkdir($remotedir);
  466. $this->ftp->upload($localfile, $remotefile, 'acii');
  467. }
  468. }
  469. }
  470. return $this->GetTrueUrl($makeUrl);
  471. }
  472. /**
  473. * 显示单独模板页面
  474. *
  475. * @access public
  476. * @param string
  477. * @return string
  478. */
  479. function DisplayPartTemplets()
  480. {
  481. $this->PartView = new PartView($this->TypeID,false);
  482. $this->PartView->SetTypeLink($this->TypeLink);
  483. $nmfa = 0;
  484. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  485. if($this->Fields['ispart']==1)
  486. {
  487. //封面模板
  488. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  489. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  490. $tempfile = $tmpdir."/".$tempfile;
  491. if ( defined('DEDEMOB') )
  492. {
  493. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  494. }
  495. if(!file_exists($tempfile))
  496. {
  497. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  498. if ( defined('DEDEMOB') )
  499. {
  500. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  501. }
  502. }
  503. $this->PartView->SetTemplet($tempfile);
  504. }
  505. else if($this->Fields['ispart']==2)
  506. {
  507. //跳转网址
  508. $gotourl = $this->Fields['typedir'];
  509. header("Location:$gotourl");
  510. exit();
  511. }
  512. CreateDir(MfTypedir($this->Fields['typedir']));
  513. $makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
  514. $makeFile = $this->GetTruePath().$makeUrl;
  515. if($nmfa==0)
  516. {
  517. $this->PartView->Display();
  518. }
  519. else
  520. {
  521. if(!file_exists($makeFile))
  522. {
  523. $this->PartView->Display();
  524. }
  525. else
  526. {
  527. include($makeFile);
  528. }
  529. }
  530. }
  531. /**
  532. * 获得站点的真实根路径
  533. *
  534. * @access public
  535. * @return string
  536. */
  537. function GetTruePath()
  538. {
  539. $truepath = $GLOBALS["cfg_basedir"];
  540. return $truepath;
  541. }
  542. /**
  543. * 获得真实连接路径
  544. *
  545. * @access public
  546. * @param string $nurl 地址
  547. * @return string
  548. */
  549. function GetTrueUrl($nurl)
  550. {
  551. if($this->Fields['moresite']==1)
  552. {
  553. if($this->Fields['sitepath']!='')
  554. {
  555. $nurl = preg_replace("/^".$this->Fields['sitepath']."/", '', $nurl);
  556. }
  557. $nurl = $this->Fields['siteurl'].$nurl;
  558. }
  559. return $nurl;
  560. }
  561. /**
  562. * 解析模板,对固定的标记进行初始给值
  563. *
  564. * @access public
  565. * @return string
  566. */
  567. function ParseTempletsFirst()
  568. {
  569. if(isset($this->TypeLink->TypeInfos['reid']))
  570. {
  571. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  572. }
  573. $GLOBALS['envs']['typeid'] = $this->TypeID;
  574. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  575. $GLOBALS['envs']['cross'] = 1;
  576. MakeOneTag($this->dtp,$this);
  577. }
  578. /**
  579. * 解析模板,对内容里的变动进行赋值
  580. *
  581. * @access public
  582. * @param int $PageNo 页数
  583. * @param int $ismake 是否编译
  584. * @return string
  585. */
  586. function ParseDMFields($PageNo,$ismake=1)
  587. {
  588. //替换第二页后的内容
  589. if(($PageNo>1 || strlen($this->Fields['content'])<10 ) && !$this->IsReplace)
  590. {
  591. $this->dtp->SourceString = str_replace('[cmsreplace]','display:none',$this->dtp->SourceString);
  592. $this->IsReplace = true;
  593. }
  594. foreach($this->dtp->CTags as $tagid=>$ctag)
  595. {
  596. if($ctag->GetName()=="list")
  597. {
  598. $limitstart = ($this->PageNo-1) * $this->PageSize;
  599. $row = $this->PageSize;
  600. if(trim($ctag->GetInnerText())=="")
  601. {
  602. $InnerText = GetSysTemplets("list_fulllist.htm");
  603. }
  604. else
  605. {
  606. $InnerText = trim($ctag->GetInnerText());
  607. }
  608. $this->dtp->Assign($tagid,
  609. $this->GetArcList(
  610. $limitstart,
  611. $row,
  612. $ctag->GetAtt("col"),
  613. $ctag->GetAtt("titlelen"),
  614. $ctag->GetAtt("infolen"),
  615. $ctag->GetAtt("imgwidth"),
  616. $ctag->GetAtt("imgheight"),
  617. $ctag->GetAtt("listtype"),
  618. $ctag->GetAtt("orderby"),
  619. $InnerText,
  620. $ctag->GetAtt("tablewidth"),
  621. $ismake,
  622. $ctag->GetAtt("orderway")
  623. )
  624. );
  625. }
  626. else if($ctag->GetName()=="pagelist")
  627. {
  628. $list_len = trim($ctag->GetAtt("listsize"));
  629. $ctag->GetAtt("listitem")=="" ? $listitem="index,pre,pageno,next,end,option" : $listitem=$ctag->GetAtt("listitem");
  630. if($list_len=="")
  631. {
  632. $list_len = 3;
  633. }
  634. if($ismake==0)
  635. {
  636. $this->dtp->Assign($tagid,$this->GetPageListDM($list_len,$listitem));
  637. }
  638. else
  639. {
  640. $this->dtp->Assign($tagid,$this->GetPageListST($list_len,$listitem));
  641. }
  642. }
  643. else if($PageNo!=1 && $ctag->GetName()=='field' && $ctag->GetAtt('display')!='')
  644. {
  645. $this->dtp->Assign($tagid,'');
  646. }
  647. }
  648. }
  649. /**
  650. * 获得要创建的文件名称规则
  651. *
  652. * @access public
  653. * @param int $typeid 栏目ID
  654. * @param string $wname
  655. * @param string $typedir 栏目目录
  656. * @param string $defaultname 默认名称
  657. * @param string $namerule2 栏目规则
  658. * @return string
  659. */
  660. function GetMakeFileRule($typeid,$wname,$typedir,$defaultname,$namerule2)
  661. {
  662. $typedir = MfTypedir($typedir);
  663. if($wname=='index')
  664. {
  665. return $typedir.'/'.$defaultname;
  666. }
  667. else
  668. {
  669. $namerule2 = str_replace('{tid}',$typeid,$namerule2);
  670. $namerule2 = str_replace('{typedir}',$typedir,$namerule2);
  671. return $namerule2;
  672. }
  673. }
  674. /**
  675. * 获得一个单列的文档列表
  676. *
  677. * @access public
  678. * @param int $limitstart 限制开始
  679. * @param int $row 行数
  680. * @param int $col 列数
  681. * @param int $titlelen 标题长度
  682. * @param int $infolen 描述长度
  683. * @param int $imgwidth 图片宽度
  684. * @param int $imgheight 图片高度
  685. * @param string $listtype 列表类型
  686. * @param string $orderby 排列顺序
  687. * @param string $innertext 底层模板
  688. * @param string $tablewidth 表格宽度
  689. * @param string $ismake 是否编译
  690. * @param string $orderWay 排序方式
  691. * @return string
  692. */
  693. function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$infolen=250,
  694. $imgwidth=120,$imgheight=90,$listtype="all",$orderby="default",$innertext="",$tablewidth="100",$ismake=1,$orderWay='desc')
  695. {
  696. global $cfg_list_son,$cfg_digg_update;
  697. $typeid=$this->TypeID;
  698. if($row=='') $row = 10;
  699. if($limitstart=='') $limitstart = 0;
  700. if($titlelen=='') $titlelen = 100;
  701. if($infolen=='') $infolen = 250;
  702. if($imgwidth=='') $imgwidth = 120;
  703. if($imgheight=='') $imgheight = 120;
  704. if($listtype=='') $listtype = 'all';
  705. if($orderWay=='') $orderWay = 'desc';
  706. if($orderby=='') {
  707. $orderby='default';
  708. }
  709. else {
  710. $orderby=strtolower($orderby);
  711. }
  712. $tablewidth = str_replace('%','',$tablewidth);
  713. if($tablewidth=='') $tablewidth=100;
  714. if($col=='') $col=1;
  715. $colWidth = ceil(100/$col);
  716. $tablewidth = $tablewidth.'%';
  717. $colWidth = $colWidth.'%';
  718. $innertext = trim($innertext);
  719. if($innertext=='') {
  720. $innertext = GetSysTemplets('list_fulllist.htm');
  721. }
  722. //排序方式
  723. $ordersql = '';
  724. if($orderby=="senddate" || $orderby=="id") {
  725. $ordersql=" ORDER BY arc.id $orderWay";
  726. }
  727. else if($orderby=="hot" || $orderby=="click") {
  728. $ordersql = " ORDER BY arc.click $orderWay";
  729. }
  730. else if($orderby=="lastpost") {
  731. $ordersql = " ORDER BY arc.lastpost $orderWay";
  732. }
  733. else {
  734. $ordersql=" ORDER BY arc.sortrank $orderWay";
  735. }
  736. //获得附加表的相关信息
  737. $addtable = $this->ChannelUnit->ChannelInfos['addtable'];
  738. if($addtable!="")
  739. {
  740. $addJoin = " LEFT JOIN `$addtable` ON arc.id = ".$addtable.'.aid ';
  741. $addField = '';
  742. $fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);
  743. foreach($fields as $k=>$v)
  744. {
  745. $nfields[$v] = $k;
  746. }
  747. if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))
  748. {
  749. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  750. {
  751. if(isset($nfields[$k]))
  752. {
  753. if(!empty($arr['rename'])) {
  754. $addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];
  755. }
  756. else {
  757. $addField .= ','.$addtable.'.'.$k;
  758. }
  759. }
  760. }
  761. }
  762. }
  763. else
  764. {
  765. $addField = '';
  766. $addJoin = '';
  767. }
  768. //如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)
  769. if(preg_match('/hot|click|lastpost/', $orderby))
  770. {
  771. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,
  772. tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  773. $addField
  774. FROM `#@__archives` arc
  775. LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  776. $addJoin
  777. WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row";
  778. }
  779. //普通情况先从arctiny表查出ID,然后按ID查询(速度非常快)
  780. else
  781. {
  782. $t1 = ExecTime();
  783. $ids = array();
  784. $query = "SELECT id FROM `#@__arctiny` arc WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row ";
  785. $this->dsql->SetQuery($query);
  786. $this->dsql->Execute();
  787. while($arr=$this->dsql->GetArray())
  788. {
  789. $ids[] = $arr['id'];
  790. }
  791. $idstr = join(',',$ids);
  792. if($idstr=='')
  793. {
  794. return '';
  795. }
  796. else
  797. {
  798. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,
  799. tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  800. $addField
  801. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  802. $addJoin
  803. WHERE arc.id in($idstr) $ordersql ";
  804. }
  805. $t2 = ExecTime();
  806. //echo $t2-$t1;
  807. }
  808. $this->dsql->SetQuery($query);
  809. $this->dsql->Execute('al');
  810. $t2 = ExecTime();
  811. //echo $t2-$t1;
  812. $artlist = '';
  813. $this->dtp2->LoadSource($innertext);
  814. $GLOBALS['autoindex'] = 0;
  815. for($i=0;$i<$row;$i++)
  816. {
  817. if($col>1)
  818. {
  819. $artlist .= "<div>\r\n";
  820. }
  821. for($j=0;$j<$col;$j++)
  822. {
  823. if($row = $this->dsql->GetArray("al"))
  824. {
  825. $GLOBALS['autoindex']++;
  826. $ids[$row['id']] = $row['id'];
  827. //处理一些特殊字段
  828. $row['infos'] = cn_substr($row['description'],$infolen);
  829. $row['id'] = $row['id'];
  830. if($cfg_digg_update > 0)
  831. {
  832. $prefix = 'diggCache';
  833. $key = 'aid-'.$row['id'];
  834. $cacherow = GetCache($prefix, $key);
  835. $row['goodpost'] = $cacherow['goodpost'];
  836. $row['badpost'] = $cacherow['badpost'];
  837. $row['scores'] = $cacherow['scores'];
  838. }
  839. if($row['corank'] > 0 && $row['arcrank']==0)
  840. {
  841. $row['arcrank'] = $row['corank'];
  842. }
  843. $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
  844. $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  845. $row['typeurl'] = GetTypeUrl($row['typeid'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],
  846. $row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  847. if($row['litpic'] == '-' || $row['litpic'] == '')
  848. {
  849. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/defaultpic.jpg';
  850. }
  851. if(!preg_match("/^http:\/\//i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  852. {
  853. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  854. }
  855. $row['picname'] = $row['litpic'];
  856. $row['stime'] = GetDateMK($row['pubdate']);
  857. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  858. $row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".preg_replace("/['><]/", "", $row['title'])."'>";
  859. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  860. $row['fulltitle'] = $row['title'];
  861. $row['title'] = cn_substr($row['title'],$titlelen);
  862. if($row['color']!='')
  863. {
  864. $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
  865. }
  866. if(preg_match('/c/', $row['flag']))
  867. {
  868. $row['title'] = "<b>".$row['title']."</b>";
  869. }
  870. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  871. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  872. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  873. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  874. //编译附加表里的数据
  875. foreach($row as $k=>$v)
  876. {
  877. $row[strtolower($k)] = $v;
  878. }
  879. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  880. {
  881. if(isset($row[$k]))
  882. {
  883. $row[$k] = $this->ChannelUnit->MakeField($k,$row[$k]);
  884. }
  885. }
  886. if(is_array($this->dtp2->CTags))
  887. {
  888. foreach($this->dtp2->CTags as $k=>$ctag)
  889. {
  890. if($ctag->GetName()=='array')
  891. {
  892. //传递整个数组,在runphp模式中有特殊作用
  893. $this->dtp2->Assign($k,$row);
  894. }
  895. else
  896. {
  897. if(isset($row[$ctag->GetName()]))
  898. {
  899. $this->dtp2->Assign($k,$row[$ctag->GetName()]);
  900. }
  901. else
  902. {
  903. $this->dtp2->Assign($k,'');
  904. }
  905. }
  906. }
  907. }
  908. $artlist .= $this->dtp2->GetResult();
  909. }//if hasRow
  910. }//Loop Col
  911. if($col>1)
  912. {
  913. $i += $col - 1;
  914. $artlist .= " </div>\r\n";
  915. }
  916. }//Loop Line
  917. $t3 = ExecTime();
  918. //echo ($t3-$t2);
  919. $this->dsql->FreeResult('al');
  920. return $artlist;
  921. }
  922. /**
  923. * 获取静态的分页列表
  924. *
  925. * @access public
  926. * @param string $list_len 列表宽度
  927. * @param string $list_len 列表样式
  928. * @return string
  929. */
  930. function GetPageListST($list_len,$listitem="index,end,pre,next,pageno")
  931. {
  932. $prepage = $nextpage = '';
  933. $prepagenum = $this->PageNo-1;
  934. $nextpagenum = $this->PageNo+1;
  935. if($list_len=='' || preg_match("/[^0-9]/", $list_len))
  936. {
  937. $list_len=3;
  938. }
  939. $totalpage = ceil($this->TotalResult/$this->PageSize);
  940. if($totalpage<=1 && $this->TotalResult>0)
  941. {
  942. return "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共 <strong>1</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li>\r\n";
  943. }
  944. if($this->TotalResult == 0)
  945. {
  946. return "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共 <strong>0</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li>\r\n";
  947. }
  948. $purl = $this->GetCurUrl();
  949. $maininfo = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";
  950. $tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);
  951. //获得上一页和主页的链接
  952. if($this->PageNo != 1)
  953. {
  954. $prepage.="<li class='page-item'><a class='page-link' href='".str_replace("{page}",$prepagenum,$tnamerule)."'>上一页</a></li>\r\n";
  955. $indexpage="<li class='page-item'><a class='page-link' href='".str_replace("{page}",1,$tnamerule)."'>首页</a></li>\r\n";
  956. }
  957. else
  958. {
  959. $indexpage="<li class='page-item'><span class='page-link'>首页</span></li>\r\n";
  960. }
  961. //下一页,未页的链接
  962. if($this->PageNo!=$totalpage && $totalpage>1)
  963. {
  964. $nextpage.="<li class='page-item'><a class='page-link' href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>下一页</a></li>\r\n";
  965. $endpage="<li class='page-item'><a class='page-link' href='".str_replace("{page}",$totalpage,$tnamerule)."'>末页</a></li>\r\n";
  966. }
  967. else
  968. {
  969. $endpage="<li class='page-item'><span class='page-link'>末页</span></li>\r\n";
  970. }
  971. //option链接
  972. $optionlist = '';
  973. $optionlen = strlen($totalpage);
  974. $optionlen = $optionlen*12 + 18;
  975. if($optionlen < 36) $optionlen = 36;
  976. if($optionlen > 100) $optionlen = 100;
  977. $optionlist = "<li><select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  978. for($mjj=1;$mjj<=$totalpage;$mjj++)
  979. {
  980. if($mjj==$this->PageNo)
  981. {
  982. $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."' selected>$mjj</option>\r\n";
  983. }
  984. else
  985. {
  986. $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."'>$mjj</option>\r\n";
  987. }
  988. }
  989. $optionlist .= "</select></li>\r\n";
  990. //获得数字链接
  991. $listdd="";
  992. $total_list = $list_len * 2 + 1;
  993. if($this->PageNo >= $total_list)
  994. {
  995. $j = $this->PageNo-$list_len;
  996. $total_list = $this->PageNo+$list_len;
  997. if($total_list>$totalpage)
  998. {
  999. $total_list=$totalpage;
  1000. }
  1001. }
  1002. else
  1003. {
  1004. $j=1;
  1005. if($total_list>$totalpage)
  1006. {
  1007. $total_list=$totalpage;
  1008. }
  1009. }
  1010. for($j;$j<=$total_list;$j++)
  1011. {
  1012. if($j==$this->PageNo)
  1013. {
  1014. $listdd.= "<li class=\"page-item active\"><span class='page-link'>$j</span></li>\r\n";
  1015. }
  1016. else
  1017. {
  1018. $listdd.="<li class='page-item'><a class='page-link' href='".str_replace("{page}",$j,$tnamerule)."'>".$j."</a></li>\r\n";
  1019. }
  1020. }
  1021. $plist = '';
  1022. if(preg_match('/index/i', $listitem)) $plist .= $indexpage;
  1023. if(preg_match('/pre/i', $listitem)) $plist .= $prepage;
  1024. if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;
  1025. if(preg_match('/next/i', $listitem)) $plist .= $nextpage;
  1026. if(preg_match('/end/i', $listitem)) $plist .= $endpage;
  1027. if(preg_match('/option/i', $listitem)) $plist .= $optionlist;
  1028. if(preg_match('/info/i', $listitem)) $plist .= $maininfo;
  1029. return $plist;
  1030. }
  1031. /**
  1032. * 获取动态的分页列表
  1033. *
  1034. * @access public
  1035. * @param string $list_len 列表宽度
  1036. * @param string $list_len 列表样式
  1037. * @return string
  1038. */
  1039. function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno")
  1040. {
  1041. global $cfg_rewrite;
  1042. $prepage = $nextpage = '';
  1043. $prepagenum = $this->PageNo-1;
  1044. $nextpagenum = $this->PageNo+1;
  1045. if($list_len=='' || preg_match("/[^0-9]/", $list_len))
  1046. {
  1047. $list_len=3;
  1048. }
  1049. $totalpage = ceil($this->TotalResult/$this->PageSize);
  1050. if($totalpage<=1 && $this->TotalResult>0)
  1051. {
  1052. return "<li class='d-none d-sm-block page-item disabled'><span class='page-link'>共 1 页/".$this->TotalResult." 条记录</span></li>\r\n";
  1053. }
  1054. if($this->TotalResult == 0)
  1055. {
  1056. return "<li class='d-none d-sm-block page-item disabled'><span class=\"page-link\">共 0 页/".$this->TotalResult." 条记录</span></li>\r\n";
  1057. }
  1058. $maininfo = "<li class='d-none d-sm-block page-item disabled'><span class=\"page-link\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>\r\n";
  1059. $purl = $this->GetCurUrl();
  1060. // 如果开启为静态,则对规则进行替换
  1061. if($cfg_rewrite == 'Y')
  1062. {
  1063. $nowurls = preg_replace("/\-/", ".php?", $purl);
  1064. $nowurls = explode("?", $nowurls);
  1065. $purl = $nowurls[0];
  1066. }
  1067. $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  1068. $purl .= '?'.$geturl;
  1069. $optionlist = '';
  1070. //$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."'>\r\n";
  1071. //$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
  1072. //获得上一页和下一页的链接
  1073. if($this->PageNo != 1)
  1074. {
  1075. $prepage.="<li class='page-item'><a href='".$purl."PageNo=$prepagenum' class='page-link'>上一页</a></li>\r\n";
  1076. $indexpage="<li class='page-item'><a href='".$purl."PageNo=1' class='page-link'>首页</a></li>\r\n";
  1077. }
  1078. else
  1079. {
  1080. $indexpage="<li class='page-item'><a class='page-link'>首页</a></li>\r\n";
  1081. }
  1082. if($this->PageNo!=$totalpage && $totalpage>1)
  1083. {
  1084. $nextpage.="<li class='page-item'><a href='".$purl."PageNo=$nextpagenum' class='page-link'>下一页</a></li>\r\n";
  1085. $endpage="<li class='page-item'><a href='".$purl."PageNo=$totalpage' class='page-link'>末页</a></li>\r\n";
  1086. }
  1087. else
  1088. {
  1089. $endpage="<li class='page-item'><a class='page-link'>末页</a></li>\r\n";
  1090. }
  1091. //获得数字链接
  1092. $listdd="";
  1093. $total_list = $list_len * 2 + 1;
  1094. if($this->PageNo >= $total_list)
  1095. {
  1096. $j = $this->PageNo-$list_len;
  1097. $total_list = $this->PageNo+$list_len;
  1098. if($total_list>$totalpage)
  1099. {
  1100. $total_list=$totalpage;
  1101. }
  1102. }
  1103. else
  1104. {
  1105. $j=1;
  1106. if($total_list>$totalpage)
  1107. {
  1108. $total_list=$totalpage;
  1109. }
  1110. }
  1111. for($j;$j<=$total_list;$j++)
  1112. {
  1113. if($j==$this->PageNo)
  1114. {
  1115. $listdd.= "<li class=\"page-item active\"><a class='page-link'>$j</a></li>\r\n";
  1116. }
  1117. else
  1118. {
  1119. $listdd.="<li class=\"page-item\"><a href='".$purl."PageNo=$j' class='page-link'>".$j."</a></li>\r\n";
  1120. }
  1121. }
  1122. $plist = '';
  1123. if(preg_match('/index/i', $listitem)) $plist .= $indexpage;
  1124. if(preg_match('/pre/i', $listitem)) $plist .= $prepage;
  1125. if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;
  1126. if(preg_match('/next/i', $listitem)) $plist .= $nextpage;
  1127. if(preg_match('/end/i', $listitem)) $plist .= $endpage;
  1128. if(preg_match('/option/i', $listitem)) $plist .= $optionlist;
  1129. if(preg_match('/info/i', $listitem)) $plist .= $maininfo;
  1130. if($cfg_rewrite == 'Y')
  1131. {
  1132. $plist = str_replace('.php?tid=', '-', $plist);
  1133. $plist = str_replace('&TotalResult=', '-', $plist);
  1134. $plist = preg_replace("/&PageNo=(\d+)/i",'-\\1.html',$plist);
  1135. }
  1136. return $plist;
  1137. }
  1138. /**
  1139. * 获得当前的页面文件的url
  1140. *
  1141. * @access public
  1142. * @return string
  1143. */
  1144. function GetCurUrl()
  1145. {
  1146. if(!empty($_SERVER['REQUEST_URI']))
  1147. {
  1148. $nowurl = $_SERVER['REQUEST_URI'];
  1149. $nowurls = explode('?', $nowurl);
  1150. $nowurl = $nowurls[0];
  1151. }
  1152. else
  1153. {
  1154. $nowurl = $_SERVER['PHP_SELF'];
  1155. }
  1156. return $nowurl;
  1157. }
  1158. }//End Class