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

841 lines
35KB

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