DedeV6移动版
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.

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