国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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