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

887 lines
37KB

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