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

873 lines
36KB

  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. $this->ParseTempletsFirst();
  297. $this->ParseDMFields($this->PageNo, 0);
  298. $this->dtp->Display();
  299. }
  300. /**
  301. * 创建单独模板页面
  302. *
  303. * @access public
  304. * @return string
  305. */
  306. function MakePartTemplets()
  307. {
  308. $this->PartView = new PartView($this->TypeID, false);
  309. $this->PartView->SetTypeLink($this->TypeLink);
  310. $nmfa = 0;
  311. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  312. if ($this->Fields['ispart'] == 1) {
  313. $tempfile = str_replace("{tid}", $this->TypeID, $this->Fields['tempindex']);
  314. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  315. $tempfile = $tmpdir."/".$tempfile;
  316. if (!file_exists($tempfile)) {
  317. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
  318. }
  319. $this->PartView->SetTemplet($tempfile);
  320. } else if ($this->Fields['ispart'] == 2) {
  321. //跳转网址
  322. return $this->Fields['typedir'];
  323. }
  324. CreateDir(MfTypedir($this->Fields['typedir']));
  325. $makeUrl = $this->GetMakeFileRule($this->Fields['id'], "index", MfTypedir($this->Fields['typedir']), $this->Fields['defaultname'], $this->Fields['namerule2']);
  326. $makeUrl = preg_replace("/\/{1,}/", "/", $makeUrl);
  327. $makeFile = $this->GetTruePath().$makeUrl;
  328. if ($nmfa == 0) {
  329. $this->PartView->SaveToHtml($makeFile);
  330. } else {
  331. if (!file_exists($makeFile)) {
  332. $this->PartView->SaveToHtml($makeFile);
  333. }
  334. }
  335. return $this->GetTrueUrl($makeUrl);
  336. }
  337. /**
  338. * 显示单独模板页面
  339. *
  340. * @access public
  341. * @return void
  342. */
  343. function DisplayPartTemplets()
  344. {
  345. $this->PartView = new PartView($this->TypeID, false);
  346. $this->PartView->SetTypeLink($this->TypeLink);
  347. $nmfa = 0;
  348. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  349. if ($this->Fields['ispart'] == 1) {
  350. //封面模板
  351. $tempfile = str_replace("{tid}", $this->TypeID, $this->Fields['tempindex']);
  352. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  353. $tempfile = $tmpdir."/".$tempfile;
  354. if (!file_exists($tempfile)) {
  355. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
  356. }
  357. $this->PartView->SetTemplet($tempfile);
  358. } else if ($this->Fields['ispart'] == 2) {
  359. //跳转网址
  360. $gotourl = $this->Fields['typedir'];
  361. header("Location:$gotourl");
  362. exit();
  363. }
  364. CreateDir(MfTypedir($this->Fields['typedir']));
  365. $makeUrl = $this->GetMakeFileRule($this->Fields['id'], "index", MfTypedir($this->Fields['typedir']), $this->Fields['defaultname'], $this->Fields['namerule2']);
  366. $makeFile = $this->GetTruePath().$makeUrl;
  367. if ($nmfa == 0) {
  368. $this->PartView->Display();
  369. } else {
  370. if (!file_exists($makeFile)) {
  371. $this->PartView->Display();
  372. } else {
  373. include($makeFile);
  374. }
  375. }
  376. }
  377. /**
  378. * 获得站点的真实根路径
  379. *
  380. * @access public
  381. * @return string
  382. */
  383. function GetTruePath()
  384. {
  385. $truepath = $GLOBALS["cfg_basedir"];
  386. return $truepath;
  387. }
  388. /**
  389. * 获得真实连接路径
  390. *
  391. * @access public
  392. * @param string $nurl 连接地址
  393. * @return string
  394. */
  395. function GetTrueUrl($nurl)
  396. {
  397. if (preg_match("/^http[s]?:\/\//", $nurl)) return $nurl;
  398. if ($this->Fields['moresite'] == 1) {
  399. if ($this->Fields['sitepath'] != '') {
  400. $nurl = preg_replace("/^".$this->Fields['sitepath']."/", '', $nurl);
  401. }
  402. $nurl = $this->Fields['siteurl'].$nurl;
  403. }
  404. return $nurl;
  405. }
  406. /**
  407. * 解析模板,对固定的标记进行初始给值
  408. *
  409. * @access private
  410. * @return void
  411. */
  412. function ParseTempletsFirst()
  413. {
  414. if (isset($this->TypeLink->TypeInfos['reid'])) {
  415. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  416. }
  417. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  418. $GLOBALS['envs']['typeid'] = $this->TypeID;
  419. $GLOBALS['envs']['cross'] = 1;
  420. MakeOneTag($this->dtp, $this);
  421. }
  422. /**
  423. * 解析模板,对内容里的变动进行赋值
  424. *
  425. * @access public
  426. * @param int $PageNo 页码
  427. * @param int $ismake 是否编译
  428. * @return void
  429. */
  430. function ParseDMFields($PageNo, $ismake = 1)
  431. {
  432. //替换第二页后的内容
  433. if (($PageNo > 1 || strlen($this->Fields['content']) < 10) && !$this->IsReplace) {
  434. $this->dtp->SourceString = str_replace('[cmsreplace]', 'display:none', $this->dtp->SourceString);
  435. $this->IsReplace = true;
  436. }
  437. foreach ($this->dtp->CTags as $tagid => $ctag) {
  438. if ($ctag->GetName() == "list") {
  439. $limitstart = ($this->PageNo - 1) * $this->pagesize;
  440. $row = $this->pagesize;
  441. if (trim($ctag->GetInnerText()) == "") {
  442. $InnerText = GetSysTemplets("list_fulllist.htm");
  443. } else {
  444. $InnerText = trim($ctag->GetInnerText());
  445. }
  446. $this->dtp->Assign(
  447. $tagid,
  448. $this->GetArcList(
  449. $limitstart,
  450. $row,
  451. $ctag->GetAtt("col"),
  452. $ctag->GetAtt("titlelen"),
  453. $ctag->GetAtt("listtype"),
  454. $ctag->GetAtt("orderby"),
  455. $InnerText,
  456. $ctag->GetAtt("tablewidth"),
  457. $ismake,
  458. $ctag->GetAtt("orderway")
  459. )
  460. );
  461. } else if ($ctag->GetName() == "pagelist") {
  462. $list_len = trim($ctag->GetAtt("listsize"));
  463. $ctag->GetAtt("listitem") == "" ? $listitem = "index,pre,pageno,next,end,option" : $listitem = $ctag->GetAtt("listitem");
  464. if ($list_len == "") {
  465. $list_len = 3;
  466. }
  467. if ($ismake == 0) {
  468. $this->dtp->Assign($tagid, $this->GetPageListDM($list_len, $listitem));
  469. } else {
  470. $this->dtp->Assign($tagid, $this->GetPageListST($list_len, $listitem));
  471. }
  472. } else if ($PageNo != 1 && $ctag->GetName() == 'field' && $ctag->GetAtt('display') != '') {
  473. $this->dtp->Assign($tagid, '');
  474. }
  475. }
  476. }
  477. /**
  478. * 获得要创建的文件名称规则
  479. *
  480. * @access public
  481. * @param string $typeid 栏目ID
  482. * @param string $wname
  483. * @param string $typedir 栏目目录
  484. * @param string $defaultname 默认名称
  485. * @param string $namerule2 名称规则
  486. * @return string
  487. */
  488. function GetMakeFileRule($typeid, $wname, $typedir, $defaultname, $namerule2)
  489. {
  490. $typedir = MfTypedir($typedir);
  491. if ($wname == 'index') {
  492. return $typedir.'/'.$defaultname;
  493. } else {
  494. $namerule2 = str_replace('{tid}', $typeid, $namerule2);
  495. $namerule2 = str_replace('{typedir}', $typedir, $namerule2);
  496. return $namerule2;
  497. }
  498. }
  499. /**
  500. * 获得一个单列的文档列表
  501. *
  502. * @access public
  503. * @param int $limitstart 限制开始
  504. * @param int $row 行数
  505. * @param int $col 列数
  506. * @param int $titlelen 标题长度
  507. * @param int $infolen 描述长度
  508. * @param int $imgwidth 图片宽度
  509. * @param int $imgheight 图片高度
  510. * @param string $listtype 列表类型
  511. * @param string $orderby 排列顺序
  512. * @param string $innertext 底层模板
  513. * @param string $tablewidth 表格宽度
  514. * @param string $ismake 是否编译
  515. * @param string $orderWay 排序方式
  516. * @return string
  517. */
  518. function GetArcList($limitstart = 0, $row = 10, $col = 1, $titlelen = 30, $listtype = "all", $orderby = "default", $innertext = "", $tablewidth = "100", $ismake = 1, $orderWay = 'desc')
  519. {
  520. global $cfg_list_son;
  521. $typeid = $this->TypeID;
  522. if ($row == '') $row = 10;
  523. if ($limitstart == '') $limitstart = 0;
  524. if ($titlelen == '') $titlelen = 100;
  525. if ($listtype == '') $listtype = "all";
  526. if ($orderby == '') $orderby = 'id';
  527. else $orderby = strtolower($orderby);
  528. if ($orderWay == '') $orderWay = 'desc';
  529. $tablewidth = str_replace("%", "", $tablewidth);
  530. if ($tablewidth == '') $tablewidth = 100;
  531. if ($col == '') $col = 1;
  532. $colWidth = ceil(100 / $col);
  533. $tablewidth = $tablewidth."%";
  534. $colWidth = $colWidth."%";
  535. $innertext = trim($innertext);
  536. if ($innertext == '') $innertext = GetSysTemplets('list_sglist.htm');
  537. //排序方式
  538. $ordersql = '';
  539. if ($orderby == 'senddate' || $orderby == 'id') {
  540. $ordersql = " ORDER BY arc.aid $orderWay";
  541. } else if ($orderby == 'hot' || $orderby == 'click') {
  542. $ordersql = " ORDER BY arc.click $orderWay";
  543. } else {
  544. $ordersql = " ORDER BY arc.aid $orderWay";
  545. }
  546. $addField = 'arc.'.join(',arc.', $this->ListFields);
  547. //如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)
  548. if (preg_match('/hot|click/', $orderby) || $this->sAddTable) {
  549. $query = "SELECT tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,
  550. tp.ispart,tp.moresite,tp.siteurl,tp.sitepath,arc.aid,arc.aid AS id,arc.typeid,
  551. $addField
  552. FROM `{$this->AddTable}` arc
  553. LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  554. WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row";
  555. }
  556. //普通情况先从arctiny表查出ID,然后按ID查询(速度非常快)
  557. else {
  558. $t1 = ExecTime();
  559. $ids = array();
  560. $nordersql = str_replace('.aid', '.id', $ordersql);
  561. $query = "SELECT id From `#@__arctiny` arc WHERE {$this->addSql} $nordersql LIMIT $limitstart,$row ";
  562. $this->dsql->SetQuery($query);
  563. $this->dsql->Execute();
  564. while ($arr = $this->dsql->GetArray()) {
  565. $ids[] = $arr['id'];
  566. }
  567. $idstr = join(',', $ids);
  568. if ($idstr == '') {
  569. return '';
  570. } else {
  571. $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,
  572. $addField
  573. FROM `{$this->AddTable}` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  574. WHERE arc.aid IN($idstr) AND arc.arcrank >-1 $ordersql ";
  575. }
  576. $t2 = ExecTime();
  577. //echo $t2-$t1;
  578. }
  579. $this->dsql->SetQuery($query);
  580. $this->dsql->Execute('al');
  581. $t2 = ExecTime();
  582. //echo $t2-$t1;
  583. $artlist = '';
  584. $this->dtp2->LoadSource($innertext);
  585. $GLOBALS['autoindex'] = 0;
  586. for ($i = 0; $i < $row; $i++) {
  587. if ($col > 1) {
  588. $artlist .= "<div>\r\n";
  589. }
  590. for ($j = 0; $j < $col; $j++) {
  591. if ($row = $this->dsql->GetArray("al")) {
  592. $GLOBALS['autoindex']++;
  593. $ids[$row['aid']] = $row['id'] = $row['aid'];
  594. //处理一些特殊字段
  595. $row['ismake'] = 1;
  596. $row['money'] = 0;
  597. $row['arcrank'] = 0;
  598. $row['filename'] = '';
  599. $row['filename'] = $row['arcurl'] = GetFileUrl(
  600. $row['id'],
  601. $row['typeid'],
  602. $row['senddate'],
  603. $row['title'],
  604. $row['ismake'],
  605. $row['arcrank'],
  606. $row['namerule'],
  607. $row['typedir'],
  608. $row['money'],
  609. $row['filename'],
  610. $row['moresite'],
  611. $row['siteurl'],
  612. $row['sitepath']
  613. );
  614. $row['typeurl'] = GetTypeUrl(
  615. $row['typeid'],
  616. MfTypedir($row['typedir']),
  617. $row['isdefault'],
  618. $row['defaultname'],
  619. $row['ispart'],
  620. $row['namerule2'],
  621. $row['moresite'],
  622. $row['siteurl'],
  623. $row['sitepath']
  624. );
  625. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  626. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/defaultpic.jpg';
  627. }
  628. if (!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  629. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  630. }
  631. $row['picname'] = $row['litpic'];
  632. $row['pubdate'] = $row['senddate'];
  633. $row['stime'] = GetDateMK($row['pubdate']);
  634. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  635. $row['fulltitle'] = $row['title'];
  636. $row['title'] = cn_substr($row['title'], $titlelen);
  637. if (preg_match('/b/', $row['flag'])) {
  638. $row['title'] = "".$row['title']."";
  639. }
  640. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  641. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  642. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  643. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  644. //编译附加表里的数据
  645. foreach ($row as $k => $v) $row[strtolower($k)] = $v;
  646. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  647. if (isset($row[$k])) {
  648. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  649. }
  650. }
  651. if (is_array($this->dtp2->CTags)) {
  652. foreach ($this->dtp2->CTags as $k => $ctag) {
  653. if ($ctag->GetName() == 'array') {
  654. //传递整个数组,在runphp模式中有特殊作用
  655. $this->dtp2->Assign($k, $row);
  656. } else {
  657. if (isset($row[$ctag->GetName()])) {
  658. $this->dtp2->Assign($k, $row[$ctag->GetName()]);
  659. } else {
  660. $this->dtp2->Assign($k, '');
  661. }
  662. }
  663. }
  664. }
  665. $artlist .= $this->dtp2->GetResult();
  666. } //if hasRow
  667. } //Loop Col
  668. if ($col > 1) {
  669. $i += $col - 1;
  670. $artlist .= " </div>\r\n";
  671. }
  672. } //Loop Line
  673. $t3 = ExecTime();
  674. //echo ($t3-$t2);
  675. $this->dsql->FreeResult('al');
  676. return $artlist;
  677. }
  678. /**
  679. * 获取静态的分页列表
  680. *
  681. * @access public
  682. * @param int $list_len 列表宽度
  683. * @param string $listitem 列表样式
  684. * @return string
  685. */
  686. function GetPageListST($list_len, $listitem = "index,end,pre,next,pageno")
  687. {
  688. $prepage = "";
  689. $nextpage = "";
  690. $prepagenum = $this->PageNo - 1;
  691. $nextpagenum = $this->PageNo + 1;
  692. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  693. $list_len = 3;
  694. }
  695. $totalpage = ceil($this->TotalResult / $this->pagesize);
  696. if ($totalpage <= 1 && $this->TotalResult > 0) {
  697. return "<li class='page-item d-none d-sm-block disabled'><span class='page-link'>1页".$this->TotalResult."条</span></li>";
  698. }
  699. if ($this->TotalResult == 0) {
  700. return "<li class='page-item d-none d-sm-block disabled'><span class='page-link'>0页".$this->TotalResult."条</span></li>";
  701. }
  702. $purl = $this->GetCurUrl();
  703. $maininfo = "<li class='page-item d-none d-sm-block disabled'><span class='page-link'>{$totalpage}页".$this->TotalResult."条</span></li>";
  704. $tnamerule = $this->GetMakeFileRule($this->Fields['id'], "list", $this->Fields['typedir'], $this->Fields['defaultname'], $this->Fields['namerule2']);
  705. $tnamerule = preg_replace("/^(.*)\//", '', $tnamerule);
  706. //获得上一页和主页的链接
  707. if ($this->PageNo != 1) {
  708. $prepage .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $prepagenum, $tnamerule)."'>上一页</a></li>\r\n";
  709. $indexpage = "<li class='page-item'><a class='page-link' href='".str_replace("{page}", 1, $tnamerule)."'>首页</a></li>\r\n";
  710. } else {
  711. $indexpage = "<li class='page-item'>首页</li>\r\n";
  712. }
  713. //下一页,未页的链接
  714. if ($this->PageNo != $totalpage && $totalpage > 1) {
  715. $nextpage .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $nextpagenum, $tnamerule)."'>下一页</a></li>\r\n";
  716. $endpage = "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $totalpage, $tnamerule)."'>末页</a></li>\r\n";
  717. } else {
  718. $endpage = "<li class='page-item'><a class='page-link'>末页</a></li>";
  719. }
  720. //option链接
  721. $optionlist = "";
  722. /*
  723. $optionlen = strlen($totalpage);
  724. $optionlen = $optionlen*10+18;
  725. $optionlist = "<li><select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  726. for($mjj=1;$mjj<=$totalpage;$mjj++)
  727. {
  728. if($mjj==$this->PageNo)
  729. {
  730. $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."' selected>$mjj</option>\r\n";
  731. } else {
  732. $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."'>$mjj</option>\r\n";
  733. }
  734. }
  735. $optionlist .= "</select><li>";
  736. */
  737. //获得数字链接
  738. $listdd = "";
  739. $total_list = $list_len * 2 + 1;
  740. if ($this->PageNo >= $total_list) {
  741. $j = $this->PageNo - $list_len;
  742. $total_list = $this->PageNo + $list_len;
  743. if ($total_list > $totalpage) {
  744. $total_list = $totalpage;
  745. }
  746. } else {
  747. $j = 1;
  748. if ($total_list > $totalpage) {
  749. $total_list = $totalpage;
  750. }
  751. }
  752. for ($j; $j <= $total_list; $j++) {
  753. if ($j == $this->PageNo) {
  754. $listdd .= "<li class='page-item active'><a class='page-link'>$j</a></li>\r\n";
  755. } else {
  756. $listdd .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $j, $tnamerule)."'>".$j."</a></li>\r\n";
  757. }
  758. }
  759. $plist = "";
  760. if (preg_match('/info/i', $listitem)) {
  761. $plist .= $maininfo.' ';
  762. }
  763. if (preg_match('/index/i', $listitem)) {
  764. $plist .= $indexpage.' ';
  765. }
  766. if (preg_match('/pre/i', $listitem)) {
  767. $plist .= $prepage.' ';
  768. }
  769. if (preg_match('/pageno/i', $listitem)) {
  770. $plist .= $listdd.' ';
  771. }
  772. if (preg_match('/next/i', $listitem)) {
  773. $plist .= $nextpage.' ';
  774. }
  775. if (preg_match('/end/i', $listitem)) {
  776. $plist .= $endpage.' ';
  777. }
  778. if (preg_match('/option/i', $listitem)) {
  779. $plist .= $optionlist;
  780. }
  781. return $plist;
  782. }
  783. /**
  784. * 获取动态的分页列表
  785. *
  786. * @access public
  787. * @param int $list_len 列表宽度
  788. * @param string $listitem 列表样式
  789. * @return string
  790. */
  791. function GetPageListDM($list_len, $listitem = "index,end,pre,next,pageno")
  792. {
  793. global $nativeplace, $infotype, $keyword;
  794. if (empty($nativeplace)) $nativeplace = 0;
  795. if (empty($infotype)) $infotype = 0;
  796. if (empty($keyword)) $keyword = '';
  797. $prepage = $nextpage = '';
  798. $prepagenum = $this->PageNo - 1;
  799. $nextpagenum = $this->PageNo + 1;
  800. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  801. $list_len = 3;
  802. }
  803. $totalpage = ceil($this->TotalResult / $this->pagesize);
  804. if ($totalpage <= 1 && $this->TotalResult > 0) {
  805. return "<li class='page-item d-none d-sm-block disabled'><span class='page-link'>1页".$this->TotalResult."条</span></li>";
  806. }
  807. if ($this->TotalResult == 0) {
  808. return "<li class='page-item d-none d-sm-block disabled'><span class='page-link'>0页".$this->TotalResult."条</span></li>";
  809. }
  810. $purl = $this->GetCurUrl();
  811. $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&nativeplace=$nativeplace&infotype=$infotype&keyword=".urlencode($keyword)."&";
  812. $hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."' />\r\n";
  813. $hidenform = "<input type='hidden' name='nativeplace' value='$nativeplace' />\r\n";
  814. $hidenform = "<input type='hidden' name='infotype' value='$infotype' />\r\n";
  815. $hidenform = "<input type='hidden' name='keyword' value='$keyword' />\r\n";
  816. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."' />\r\n";
  817. $purl .= "?".$geturl;
  818. //获得上一页和下一页的链接
  819. if ($this->PageNo != 1) {
  820. $prepage .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
  821. $indexpage = "<li class='page-item'><a class='page-link' href='".$purl."PageNo=1'>首页</a></li>\r\n";
  822. } else {
  823. $indexpage = "<li class='page-item disabled'><a class='page-link'>首页</a></li>\r\n";
  824. }
  825. if ($this->PageNo != $totalpage && $totalpage > 1) {
  826. $nextpage .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
  827. $endpage = "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
  828. } else {
  829. $endpage = "<li class='page-item disabled'><a class='page-link'>末页</a></li>";
  830. }
  831. //获得数字链接
  832. $listdd = "";
  833. $total_list = $list_len * 2 + 1;
  834. if ($this->PageNo >= $total_list) {
  835. $j = $this->PageNo - $list_len;
  836. $total_list = $this->PageNo + $list_len;
  837. if ($total_list > $totalpage) {
  838. $total_list = $totalpage;
  839. }
  840. } else {
  841. $j = 1;
  842. if ($total_list > $totalpage) {
  843. $total_list = $totalpage;
  844. }
  845. }
  846. for ($j; $j <= $total_list; $j++) {
  847. if ($j == $this->PageNo) {
  848. $listdd .= "<li class='page-item active'><a class='page-link'>$j</a></li>\r\n";
  849. } else {
  850. $listdd .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
  851. }
  852. }
  853. $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;
  854. return $plist;
  855. }
  856. /**
  857. * 获得当前的页面文件的url
  858. *
  859. * @access private
  860. * @return string
  861. */
  862. function GetCurUrl()
  863. {
  864. if (!empty($_SERVER["REQUEST_URI"])) {
  865. $nowurl = $_SERVER["REQUEST_URI"];
  866. $nowurls = explode("?", $nowurl);
  867. $nowurl = $nowurls[0];
  868. } else {
  869. $nowurl = $_SERVER["PHP_SELF"];
  870. }
  871. return $nowurl;
  872. }
  873. }//End Class