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

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