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

979 lines
38KB

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