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

1181 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) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license/v6
  9. * @link https://www.dedebiz.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 https://www.dedebiz.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. if(empty($startpage))
  263. {
  264. $startpage = 1;
  265. }
  266. //创建封面模板文件
  267. if($this->TypeLink->TypeInfos['isdefault']==-1)
  268. {
  269. echo '这个类目是动态类目!';
  270. return '../plus/list.php?tid='.$this->TypeLink->TypeInfos['id'];
  271. }
  272. //单独页面
  273. else if($this->TypeLink->TypeInfos['ispart']>0)
  274. {
  275. $reurl = $this->MakePartTemplets();
  276. return $reurl;
  277. }
  278. if(empty($this->TotalResult)) $this->CountRecord();
  279. //初步给固定值的标记赋值
  280. $this->ParseTempletsFirst();
  281. $totalpage = ceil($this->TotalResult/$this->PageSize);
  282. if($totalpage==0)
  283. {
  284. $totalpage = 1;
  285. }
  286. CreateDir(MfTypedir($this->Fields['typedir']));
  287. $murl = '';
  288. if($makepagesize > 0)
  289. {
  290. $endpage = $startpage+$makepagesize;
  291. }
  292. else
  293. {
  294. $endpage = ($totalpage+1);
  295. }
  296. if( $endpage >= $totalpage+1 )
  297. {
  298. $endpage = $totalpage+1;
  299. }
  300. if($endpage==1)
  301. {
  302. $endpage = 2;
  303. }
  304. for($this->PageNo=$startpage; $this->PageNo < $endpage; $this->PageNo++)
  305. {
  306. $this->ParseDMFields($this->PageNo,1);
  307. $makeFile = $this->GetMakeFileRule($this->Fields['id'],'list',$this->Fields['typedir'],'',$this->Fields['namerule2']);
  308. $makeFile = str_replace("{page}", $this->PageNo, $makeFile);
  309. $murl = $makeFile;
  310. if(!preg_match("/^\//", $makeFile))
  311. {
  312. $makeFile = "/".$makeFile;
  313. }
  314. $makeFile = $this->GetTruePath().$makeFile;
  315. $makeFile = preg_replace("/\/{1,}/", "/", $makeFile);
  316. $murl = $this->GetTrueUrl($murl);
  317. $this->dtp->SaveTo($makeFile);
  318. }
  319. if($startpage==1)
  320. {
  321. //如果列表启用封面文件,复制这个文件第一页
  322. if($this->TypeLink->TypeInfos['isdefault']==1
  323. && $this->TypeLink->TypeInfos['ispart']==0)
  324. {
  325. $onlyrule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],'',$this->Fields['namerule2']);
  326. $onlyrule = str_replace("{page}","1",$onlyrule);
  327. $list_1 = $this->GetTruePath().$onlyrule;
  328. $murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];
  329. $indexname = $this->GetTruePath().$murl;
  330. copy($list_1,$indexname);
  331. }
  332. }
  333. return $murl;
  334. }
  335. /**
  336. * 显示列表
  337. *
  338. * @access public
  339. * @return void
  340. */
  341. function Display()
  342. {
  343. if($this->TypeLink->TypeInfos['ispart']>0)
  344. {
  345. $this->DisplayPartTemplets();
  346. return ;
  347. }
  348. $this->CountRecord();
  349. if((empty($this->PageNo) || $this->PageNo==1)
  350. && $this->TypeLink->TypeInfos['ispart']==1)
  351. {
  352. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  353. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  354. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  355. $tempfile = $tmpdir."/".$tempfile;
  356. if ( defined('DEDEMOB') )
  357. {
  358. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  359. }
  360. if(!file_exists($tempfile))
  361. {
  362. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  363. if ( defined('DEDEMOB') )
  364. {
  365. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  366. }
  367. }
  368. $this->dtp->LoadTemplate($tempfile);
  369. }
  370. $this->ParseTempletsFirst();
  371. $this->ParseDMFields($this->PageNo,0);
  372. $this->dtp->Display();
  373. }
  374. /**
  375. * 创建单独模板页面
  376. *
  377. * @access public
  378. * @return string
  379. */
  380. function MakePartTemplets()
  381. {
  382. $this->PartView = new PartView($this->TypeID,false);
  383. $this->PartView->SetTypeLink($this->TypeLink);
  384. $nmfa = 0;
  385. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  386. if($this->Fields['ispart']==1)
  387. {
  388. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  389. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  390. $tempfile = $tmpdir."/".$tempfile;
  391. if ( defined('DEDEMOB') )
  392. {
  393. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  394. }
  395. if(!file_exists($tempfile))
  396. {
  397. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  398. if ( defined('DEDEMOB') )
  399. {
  400. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  401. }
  402. }
  403. $this->PartView->SetTemplet($tempfile);
  404. }
  405. else if($this->Fields['ispart']==2)
  406. {
  407. //跳转网址
  408. return $this->Fields['typedir'];
  409. }
  410. CreateDir(MfTypedir($this->Fields['typedir']));
  411. $makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
  412. $makeUrl = preg_replace("/\/{1,}/", "/", $makeUrl);
  413. $makeFile = $this->GetTruePath().$makeUrl;
  414. if($nmfa==0)
  415. {
  416. $this->PartView->SaveToHtml($makeFile);
  417. }
  418. else
  419. {
  420. if(!file_exists($makeFile))
  421. {
  422. $this->PartView->SaveToHtml($makeFile);
  423. }
  424. }
  425. return $this->GetTrueUrl($makeUrl);
  426. }
  427. /**
  428. * 显示单独模板页面
  429. *
  430. * @access public
  431. * @param string
  432. * @return string
  433. */
  434. function DisplayPartTemplets()
  435. {
  436. $this->PartView = new PartView($this->TypeID,false);
  437. $this->PartView->SetTypeLink($this->TypeLink);
  438. $nmfa = 0;
  439. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  440. if($this->Fields['ispart']==1)
  441. {
  442. //封面模板
  443. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  444. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  445. $tempfile = $tmpdir."/".$tempfile;
  446. if ( defined('DEDEMOB') )
  447. {
  448. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  449. }
  450. if(!file_exists($tempfile))
  451. {
  452. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  453. if ( defined('DEDEMOB') )
  454. {
  455. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  456. }
  457. }
  458. $this->PartView->SetTemplet($tempfile);
  459. }
  460. else if($this->Fields['ispart']==2)
  461. {
  462. //跳转网址
  463. $gotourl = $this->Fields['typedir'];
  464. header("Location:$gotourl");
  465. exit();
  466. }
  467. CreateDir(MfTypedir($this->Fields['typedir']));
  468. $makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
  469. $makeFile = $this->GetTruePath().$makeUrl;
  470. if($nmfa==0)
  471. {
  472. $this->PartView->Display();
  473. }
  474. else
  475. {
  476. if(!file_exists($makeFile))
  477. {
  478. $this->PartView->Display();
  479. }
  480. else
  481. {
  482. include($makeFile);
  483. }
  484. }
  485. }
  486. /**
  487. * 获得站点的真实根路径
  488. *
  489. * @access public
  490. * @return string
  491. */
  492. function GetTruePath()
  493. {
  494. $truepath = $GLOBALS["cfg_basedir"];
  495. return $truepath;
  496. }
  497. /**
  498. * 获得真实连接路径
  499. *
  500. * @access public
  501. * @param string $nurl 地址
  502. * @return string
  503. */
  504. function GetTrueUrl($nurl)
  505. {
  506. if($this->Fields['moresite']==1)
  507. {
  508. if($this->Fields['sitepath']!='')
  509. {
  510. $nurl = preg_replace("/^".$this->Fields['sitepath']."/", '', $nurl);
  511. }
  512. $nurl = $this->Fields['siteurl'].$nurl;
  513. }
  514. return $nurl;
  515. }
  516. /**
  517. * 解析模板,对固定的标记进行初始给值
  518. *
  519. * @access public
  520. * @return string
  521. */
  522. function ParseTempletsFirst()
  523. {
  524. if(isset($this->TypeLink->TypeInfos['reid']))
  525. {
  526. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  527. }
  528. $GLOBALS['envs']['typeid'] = $this->TypeID;
  529. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  530. $GLOBALS['envs']['cross'] = 1;
  531. MakeOneTag($this->dtp,$this);
  532. }
  533. /**
  534. * 解析模板,对内容里的变动进行赋值
  535. *
  536. * @access public
  537. * @param int $PageNo 页数
  538. * @param int $ismake 是否编译
  539. * @return string
  540. */
  541. function ParseDMFields($PageNo,$ismake=1)
  542. {
  543. //替换第二页后的内容
  544. if(($PageNo>1 || strlen($this->Fields['content'])<10 ) && !$this->IsReplace)
  545. {
  546. $this->dtp->SourceString = str_replace('[cmsreplace]','display:none',$this->dtp->SourceString);
  547. $this->IsReplace = true;
  548. }
  549. foreach($this->dtp->CTags as $tagid=>$ctag)
  550. {
  551. if($ctag->GetName()=="list")
  552. {
  553. $limitstart = ($this->PageNo-1) * $this->PageSize;
  554. $row = $this->PageSize;
  555. if(trim($ctag->GetInnerText())=="")
  556. {
  557. $InnerText = GetSysTemplets("list_fulllist.htm");
  558. }
  559. else
  560. {
  561. $InnerText = trim($ctag->GetInnerText());
  562. }
  563. $this->dtp->Assign($tagid,
  564. $this->GetArcList(
  565. $limitstart,
  566. $row,
  567. $ctag->GetAtt("col"),
  568. $ctag->GetAtt("titlelen"),
  569. $ctag->GetAtt("infolen"),
  570. $ctag->GetAtt("imgwidth"),
  571. $ctag->GetAtt("imgheight"),
  572. $ctag->GetAtt("listtype"),
  573. $ctag->GetAtt("orderby"),
  574. $InnerText,
  575. $ctag->GetAtt("tablewidth"),
  576. $ismake,
  577. $ctag->GetAtt("orderway")
  578. )
  579. );
  580. }
  581. else if($ctag->GetName()=="pagelist")
  582. {
  583. $list_len = trim($ctag->GetAtt("listsize"));
  584. $ctag->GetAtt("listitem")=="" ? $listitem="index,pre,pageno,next,end,option" : $listitem=$ctag->GetAtt("listitem");
  585. if($list_len=="")
  586. {
  587. $list_len = 3;
  588. }
  589. if($ismake==0)
  590. {
  591. $this->dtp->Assign($tagid,$this->GetPageListDM($list_len,$listitem));
  592. }
  593. else
  594. {
  595. $this->dtp->Assign($tagid,$this->GetPageListST($list_len,$listitem));
  596. }
  597. }
  598. else if($PageNo!=1 && $ctag->GetName()=='field' && $ctag->GetAtt('display')!='')
  599. {
  600. $this->dtp->Assign($tagid,'');
  601. }
  602. }
  603. }
  604. /**
  605. * 获得要创建的文件名称规则
  606. *
  607. * @access public
  608. * @param int $typeid 栏目ID
  609. * @param string $wname
  610. * @param string $typedir 栏目目录
  611. * @param string $defaultname 默认名称
  612. * @param string $namerule2 栏目规则
  613. * @return string
  614. */
  615. function GetMakeFileRule($typeid,$wname,$typedir,$defaultname,$namerule2)
  616. {
  617. $typedir = MfTypedir($typedir);
  618. if($wname=='index')
  619. {
  620. return $typedir.'/'.$defaultname;
  621. }
  622. else
  623. {
  624. $namerule2 = str_replace('{tid}',$typeid,$namerule2);
  625. $namerule2 = str_replace('{typedir}',$typedir,$namerule2);
  626. return $namerule2;
  627. }
  628. }
  629. /**
  630. * 获得一个单列的文档列表
  631. *
  632. * @access public
  633. * @param int $limitstart 限制开始
  634. * @param int $row 行数
  635. * @param int $col 列数
  636. * @param int $titlelen 标题长度
  637. * @param int $infolen 描述长度
  638. * @param int $imgwidth 图片宽度
  639. * @param int $imgheight 图片高度
  640. * @param string $listtype 列表类型
  641. * @param string $orderby 排列顺序
  642. * @param string $innertext 底层模板
  643. * @param string $tablewidth 表格宽度
  644. * @param string $ismake 是否编译
  645. * @param string $orderWay 排序方式
  646. * @return string
  647. */
  648. function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$infolen=250,
  649. $imgwidth=120,$imgheight=90,$listtype="all",$orderby="default",$innertext="",$tablewidth="100",$ismake=1,$orderWay='desc')
  650. {
  651. global $cfg_list_son,$cfg_digg_update;
  652. $typeid=$this->TypeID;
  653. if($row=='') $row = 10;
  654. if($limitstart=='') $limitstart = 0;
  655. if($titlelen=='') $titlelen = 100;
  656. if($infolen=='') $infolen = 250;
  657. if($imgwidth=='') $imgwidth = 120;
  658. if($imgheight=='') $imgheight = 120;
  659. if($listtype=='') $listtype = 'all';
  660. if($orderWay=='') $orderWay = 'desc';
  661. if($orderby=='') {
  662. $orderby='default';
  663. }
  664. else {
  665. $orderby=strtolower($orderby);
  666. }
  667. $tablewidth = str_replace('%','',$tablewidth);
  668. if($tablewidth=='') $tablewidth=100;
  669. if($col=='') $col=1;
  670. $colWidth = ceil(100/$col);
  671. $tablewidth = $tablewidth.'%';
  672. $colWidth = $colWidth.'%';
  673. $innertext = trim($innertext);
  674. if($innertext=='') {
  675. $innertext = GetSysTemplets('list_fulllist.htm');
  676. }
  677. //排序方式
  678. $ordersql = '';
  679. if($orderby=="senddate" || $orderby=="id") {
  680. $ordersql=" ORDER BY arc.id $orderWay";
  681. }
  682. else if($orderby=="hot" || $orderby=="click") {
  683. $ordersql = " ORDER BY arc.click $orderWay";
  684. }
  685. else if($orderby=="lastpost") {
  686. $ordersql = " ORDER BY arc.lastpost $orderWay";
  687. }
  688. else {
  689. $ordersql=" ORDER BY arc.sortrank $orderWay";
  690. }
  691. //获得附加表的相关信息
  692. $addtable = $this->ChannelUnit->ChannelInfos['addtable'];
  693. if($addtable!="")
  694. {
  695. $addJoin = " LEFT JOIN `$addtable` ON arc.id = ".$addtable.'.aid ';
  696. $addField = '';
  697. $fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);
  698. foreach($fields as $k=>$v)
  699. {
  700. $nfields[$v] = $k;
  701. }
  702. if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))
  703. {
  704. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  705. {
  706. if(isset($nfields[$k]))
  707. {
  708. if(!empty($arr['rename'])) {
  709. $addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];
  710. }
  711. else {
  712. $addField .= ','.$addtable.'.'.$k;
  713. }
  714. }
  715. }
  716. }
  717. }
  718. else
  719. {
  720. $addField = '';
  721. $addJoin = '';
  722. }
  723. //如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)
  724. if(preg_match('/hot|click|lastpost/', $orderby))
  725. {
  726. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,
  727. tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  728. $addField
  729. FROM `#@__archives` arc
  730. LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  731. $addJoin
  732. WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row";
  733. }
  734. //普通情况先从arctiny表查出ID,然后按ID查询(速度非常快)
  735. else
  736. {
  737. $t1 = ExecTime();
  738. $ids = array();
  739. $query = "SELECT id FROM `#@__arctiny` arc WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row ";
  740. $this->dsql->SetQuery($query);
  741. $this->dsql->Execute();
  742. while($arr=$this->dsql->GetArray())
  743. {
  744. $ids[] = $arr['id'];
  745. }
  746. $idstr = join(',',$ids);
  747. if($idstr=='')
  748. {
  749. return '';
  750. }
  751. else
  752. {
  753. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,
  754. tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  755. $addField
  756. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  757. $addJoin
  758. WHERE arc.id in($idstr) $ordersql ";
  759. }
  760. $t2 = ExecTime();
  761. //echo $t2-$t1;
  762. }
  763. $this->dsql->SetQuery($query);
  764. $this->dsql->Execute('al');
  765. $t2 = ExecTime();
  766. //echo $t2-$t1;
  767. $artlist = '';
  768. $this->dtp2->LoadSource($innertext);
  769. $GLOBALS['autoindex'] = 0;
  770. for($i=0;$i<$row;$i++)
  771. {
  772. if($col>1)
  773. {
  774. $artlist .= "<div>\r\n";
  775. }
  776. for($j=0;$j<$col;$j++)
  777. {
  778. if($row = $this->dsql->GetArray("al"))
  779. {
  780. $GLOBALS['autoindex']++;
  781. $ids[$row['id']] = $row['id'];
  782. //处理一些特殊字段
  783. $row['infos'] = cn_substr($row['description'],$infolen);
  784. $row['id'] = $row['id'];
  785. if($cfg_digg_update > 0)
  786. {
  787. $prefix = 'diggCache';
  788. $key = 'aid-'.$row['id'];
  789. $cacherow = GetCache($prefix, $key);
  790. $row['goodpost'] = $cacherow['goodpost'];
  791. $row['badpost'] = $cacherow['badpost'];
  792. $row['scores'] = $cacherow['scores'];
  793. }
  794. if($row['corank'] > 0 && $row['arcrank']==0)
  795. {
  796. $row['arcrank'] = $row['corank'];
  797. }
  798. $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
  799. $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  800. $row['typeurl'] = GetTypeUrl($row['typeid'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],
  801. $row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  802. if($row['litpic'] == '-' || $row['litpic'] == '')
  803. {
  804. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/defaultpic.jpg';
  805. }
  806. if(!preg_match("/^http:\/\//i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  807. {
  808. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  809. }
  810. $row['picname'] = $row['litpic'];
  811. $row['stime'] = GetDateMK($row['pubdate']);
  812. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  813. $row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".preg_replace("/['><]/", "", $row['title'])."'>";
  814. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  815. $row['fulltitle'] = $row['title'];
  816. $row['title'] = cn_substr($row['title'],$titlelen);
  817. if($row['color']!='')
  818. {
  819. $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
  820. }
  821. if(preg_match('/c/', $row['flag']))
  822. {
  823. $row['title'] = "<b>".$row['title']."</b>";
  824. }
  825. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  826. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  827. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  828. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  829. //编译附加表里的数据
  830. foreach($row as $k=>$v)
  831. {
  832. $row[strtolower($k)] = $v;
  833. }
  834. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  835. {
  836. if(isset($row[$k]))
  837. {
  838. $row[$k] = $this->ChannelUnit->MakeField($k,$row[$k]);
  839. }
  840. }
  841. if(is_array($this->dtp2->CTags))
  842. {
  843. foreach($this->dtp2->CTags as $k=>$ctag)
  844. {
  845. if($ctag->GetName()=='array')
  846. {
  847. //传递整个数组,在runphp模式中有特殊作用
  848. $this->dtp2->Assign($k,$row);
  849. }
  850. else
  851. {
  852. if(isset($row[$ctag->GetName()]))
  853. {
  854. $this->dtp2->Assign($k,$row[$ctag->GetName()]);
  855. }
  856. else
  857. {
  858. $this->dtp2->Assign($k,'');
  859. }
  860. }
  861. }
  862. }
  863. $artlist .= $this->dtp2->GetResult();
  864. }//if hasRow
  865. }//Loop Col
  866. if($col>1)
  867. {
  868. $i += $col - 1;
  869. $artlist .= " </div>\r\n";
  870. }
  871. }//Loop Line
  872. $t3 = ExecTime();
  873. //echo ($t3-$t2);
  874. $this->dsql->FreeResult('al');
  875. return $artlist;
  876. }
  877. /**
  878. * 获取静态的分页列表
  879. *
  880. * @access public
  881. * @param string $list_len 列表宽度
  882. * @param string $list_len 列表样式
  883. * @return string
  884. */
  885. function GetPageListST($list_len,$listitem="index,end,pre,next,pageno")
  886. {
  887. $prepage = $nextpage = '';
  888. $prepagenum = $this->PageNo-1;
  889. $nextpagenum = $this->PageNo+1;
  890. if($list_len=='' || preg_match("/[^0-9]/", $list_len))
  891. {
  892. $list_len=3;
  893. }
  894. $totalpage = ceil($this->TotalResult/$this->PageSize);
  895. if($totalpage<=1 && $this->TotalResult>0)
  896. {
  897. 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";
  898. }
  899. if($this->TotalResult == 0)
  900. {
  901. 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";
  902. }
  903. $purl = $this->GetCurUrl();
  904. $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";
  905. $tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);
  906. //获得上一页和主页的链接
  907. if($this->PageNo != 1)
  908. {
  909. $prepage.="<li class='page-item'><a class='page-link' href='".str_replace("{page}",$prepagenum,$tnamerule)."'>上一页</a></li>\r\n";
  910. $indexpage="<li class='page-item'><a class='page-link' href='".str_replace("{page}",1,$tnamerule)."'>首页</a></li>\r\n";
  911. }
  912. else
  913. {
  914. $indexpage="<li class='page-item'><span class='page-link'>首页</span></li>\r\n";
  915. }
  916. //下一页,未页的链接
  917. if($this->PageNo!=$totalpage && $totalpage>1)
  918. {
  919. $nextpage.="<li class='page-item'><a class='page-link' href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>下一页</a></li>\r\n";
  920. $endpage="<li class='page-item'><a class='page-link' href='".str_replace("{page}",$totalpage,$tnamerule)."'>末页</a></li>\r\n";
  921. }
  922. else
  923. {
  924. $endpage="<li class='page-item'><span class='page-link'>末页</span></li>\r\n";
  925. }
  926. //option链接
  927. $optionlist = '';
  928. $optionlen = strlen($totalpage);
  929. $optionlen = $optionlen*12 + 18;
  930. if($optionlen < 36) $optionlen = 36;
  931. if($optionlen > 100) $optionlen = 100;
  932. $optionlist = "<li><select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  933. for($mjj=1;$mjj<=$totalpage;$mjj++)
  934. {
  935. if($mjj==$this->PageNo)
  936. {
  937. $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."' selected>$mjj</option>\r\n";
  938. }
  939. else
  940. {
  941. $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."'>$mjj</option>\r\n";
  942. }
  943. }
  944. $optionlist .= "</select></li>\r\n";
  945. //获得数字链接
  946. $listdd="";
  947. $total_list = $list_len * 2 + 1;
  948. if($this->PageNo >= $total_list)
  949. {
  950. $j = $this->PageNo-$list_len;
  951. $total_list = $this->PageNo+$list_len;
  952. if($total_list>$totalpage)
  953. {
  954. $total_list=$totalpage;
  955. }
  956. }
  957. else
  958. {
  959. $j=1;
  960. if($total_list>$totalpage)
  961. {
  962. $total_list=$totalpage;
  963. }
  964. }
  965. for($j;$j<=$total_list;$j++)
  966. {
  967. if($j==$this->PageNo)
  968. {
  969. $listdd.= "<li class=\"page-item active\"><span class='page-link'>$j</span></li>\r\n";
  970. }
  971. else
  972. {
  973. $listdd.="<li class='page-item'><a class='page-link' href='".str_replace("{page}",$j,$tnamerule)."'>".$j."</a></li>\r\n";
  974. }
  975. }
  976. $plist = '';
  977. if(preg_match('/index/i', $listitem)) $plist .= $indexpage;
  978. if(preg_match('/pre/i', $listitem)) $plist .= $prepage;
  979. if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;
  980. if(preg_match('/next/i', $listitem)) $plist .= $nextpage;
  981. if(preg_match('/end/i', $listitem)) $plist .= $endpage;
  982. if(preg_match('/option/i', $listitem)) $plist .= $optionlist;
  983. if(preg_match('/info/i', $listitem)) $plist .= $maininfo;
  984. return $plist;
  985. }
  986. /**
  987. * 获取动态的分页列表
  988. *
  989. * @access public
  990. * @param string $list_len 列表宽度
  991. * @param string $list_len 列表样式
  992. * @return string
  993. */
  994. function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno")
  995. {
  996. global $cfg_rewrite;
  997. $prepage = $nextpage = '';
  998. $prepagenum = $this->PageNo-1;
  999. $nextpagenum = $this->PageNo+1;
  1000. if($list_len=='' || preg_match("/[^0-9]/", $list_len))
  1001. {
  1002. $list_len=3;
  1003. }
  1004. $totalpage = ceil($this->TotalResult/$this->PageSize);
  1005. if($totalpage<=1 && $this->TotalResult>0)
  1006. {
  1007. return "<li class='d-none d-sm-block page-item disabled'><span class='page-link'>共 1 页/".$this->TotalResult." 条记录</span></li>\r\n";
  1008. }
  1009. if($this->TotalResult == 0)
  1010. {
  1011. return "<li class='d-none d-sm-block page-item disabled'><span class=\"page-link\">共 0 页/".$this->TotalResult." 条记录</span></li>\r\n";
  1012. }
  1013. $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";
  1014. $purl = $this->GetCurUrl();
  1015. // 如果开启为静态,则对规则进行替换
  1016. if($cfg_rewrite == 'Y')
  1017. {
  1018. $nowurls = preg_replace("/\-/", ".php?", $purl);
  1019. $nowurls = explode("?", $nowurls);
  1020. $purl = $nowurls[0];
  1021. }
  1022. $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  1023. $purl .= '?'.$geturl;
  1024. $optionlist = '';
  1025. //$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."'>\r\n";
  1026. //$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
  1027. //获得上一页和下一页的链接
  1028. if($this->PageNo != 1)
  1029. {
  1030. $prepage.="<li class='page-item'><a href='".$purl."PageNo=$prepagenum' class='page-link'>上一页</a></li>\r\n";
  1031. $indexpage="<li class='page-item'><a href='".$purl."PageNo=1' class='page-link'>首页</a></li>\r\n";
  1032. }
  1033. else
  1034. {
  1035. $indexpage="<li class='page-item'><a class='page-link'>首页</a></li>\r\n";
  1036. }
  1037. if($this->PageNo!=$totalpage && $totalpage>1)
  1038. {
  1039. $nextpage.="<li class='page-item'><a href='".$purl."PageNo=$nextpagenum' class='page-link'>下一页</a></li>\r\n";
  1040. $endpage="<li class='page-item'><a href='".$purl."PageNo=$totalpage' class='page-link'>末页</a></li>\r\n";
  1041. }
  1042. else
  1043. {
  1044. $endpage="<li class='page-item'><a class='page-link'>末页</a></li>\r\n";
  1045. }
  1046. //获得数字链接
  1047. $listdd="";
  1048. $total_list = $list_len * 2 + 1;
  1049. if($this->PageNo >= $total_list)
  1050. {
  1051. $j = $this->PageNo-$list_len;
  1052. $total_list = $this->PageNo+$list_len;
  1053. if($total_list>$totalpage)
  1054. {
  1055. $total_list=$totalpage;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. $j=1;
  1061. if($total_list>$totalpage)
  1062. {
  1063. $total_list=$totalpage;
  1064. }
  1065. }
  1066. for($j;$j<=$total_list;$j++)
  1067. {
  1068. if($j==$this->PageNo)
  1069. {
  1070. $listdd.= "<li class=\"page-item active\"><a class='page-link'>$j</a></li>\r\n";
  1071. }
  1072. else
  1073. {
  1074. $listdd.="<li class=\"page-item\"><a href='".$purl."PageNo=$j' class='page-link'>".$j."</a></li>\r\n";
  1075. }
  1076. }
  1077. $plist = '';
  1078. if(preg_match('/index/i', $listitem)) $plist .= $indexpage;
  1079. if(preg_match('/pre/i', $listitem)) $plist .= $prepage;
  1080. if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;
  1081. if(preg_match('/next/i', $listitem)) $plist .= $nextpage;
  1082. if(preg_match('/end/i', $listitem)) $plist .= $endpage;
  1083. if(preg_match('/option/i', $listitem)) $plist .= $optionlist;
  1084. if(preg_match('/info/i', $listitem)) $plist .= $maininfo;
  1085. if($cfg_rewrite == 'Y')
  1086. {
  1087. $plist = str_replace('.php?tid=', '-', $plist);
  1088. $plist = str_replace('&TotalResult=', '-', $plist);
  1089. $plist = preg_replace("/&PageNo=(\d+)/i",'-\\1.html',$plist);
  1090. }
  1091. return $plist;
  1092. }
  1093. /**
  1094. * 获得当前的页面文件的url
  1095. *
  1096. * @access public
  1097. * @return string
  1098. */
  1099. function GetCurUrl()
  1100. {
  1101. if(!empty($_SERVER['REQUEST_URI']))
  1102. {
  1103. $nowurl = $_SERVER['REQUEST_URI'];
  1104. $nowurls = explode('?', $nowurl);
  1105. $nowurl = $nowurls[0];
  1106. }
  1107. else
  1108. {
  1109. $nowurl = $_SERVER['PHP_SELF'];
  1110. }
  1111. return $nowurl;
  1112. }
  1113. }//End Class