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

1182 lines
42KB

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