国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

978 Zeilen
38KB

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