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

1125 lines
39KB

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