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

923 lines
35KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 自由列表类
  5. *
  6. * @version $Id: arc.freelist.class.php 3 15:15 2010年7月7日Z tianya $
  7. * @package DedeBIZ.Libraries
  8. * @copyright Copyright (c) 2022, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once DEDEINC.'/arc.partview.class.php';
  13. @set_time_limit(0);
  14. /**
  15. * 自由列表类
  16. *
  17. * @package FreeList
  18. * @subpackage DedeBIZ.Libraries
  19. * @link https://www.dedebiz.com
  20. */
  21. class FreeList
  22. {
  23. var $dsql;
  24. var $dtp;
  25. var $TypeID;
  26. var $TypeLink;
  27. var $PageNo;
  28. var $TotalPage;
  29. var $TotalResult;
  30. var $PageSize;
  31. var $ChannelUnit;
  32. var $Fields;
  33. var $PartView;
  34. var $FLInfos;
  35. var $ListObj;
  36. var $TempletsFile;
  37. var $maintable;
  38. //php5构造函数
  39. function __construct($fid)
  40. {
  41. global $dsql;
  42. $this->FreeID = $fid;
  43. $this->TypeLink = new TypeLink(0);
  44. $this->dsql = $dsql;
  45. $this->maintable = '#@__archives';
  46. $this->TempletsFile = '';
  47. $this->FLInfos = $this->dsql->GetOne("SELECT * FROM `#@__freelist` WHERE aid='$fid' ");
  48. $liststr = $this->FLInfos['listtag'];
  49. $this->FLInfos['maxpage'] = (empty($this->FLInfos['maxpage']) ? 100 : $this->FLInfos['maxpage']);
  50. //载入数据里保存的列表属性信息
  51. $ndtp = new DedeTagParse();
  52. $ndtp->SetNameSpace("dede", "{", "}");
  53. $ndtp->LoadString($liststr);
  54. $this->ListObj = $ndtp->GetTag('list');
  55. $this->PageSize = $this->ListObj->GetAtt('pagesize');
  56. if (empty($this->PageSize)) {
  57. $this->PageSize = 30;
  58. }
  59. $channelid = $this->ListObj->GetAtt('channel');
  60. /*
  61. if(empty($channelid))
  62. {
  63. showmsg('必须指定频道','-1');exit();
  64. }
  65. else
  66. {
  67. $channelid = intval($channelid);
  68. $channelinfo = $this->dsql->getone("select maintable from #@__channeltype where id='$channelid'");
  69. $this->maintable = $channelinfo['maintable'];
  70. }
  71. */
  72. $channelid = intval($channelid);
  73. $this->maintable = '#@__archives';
  74. //全局模板解析器
  75. $this->dtp = new DedeTagParse();
  76. $this->dtp->SetNameSpace("dede", "{", "}");
  77. $this->dtp->SetRefObj($this);
  78. //设置一些全局参数的值
  79. $this->Fields['aid'] = $this->FLInfos['aid'];
  80. $this->Fields['title'] = $this->FLInfos['title'];
  81. $this->Fields['position'] = "<li class=\"breadcrumb-item\">{$this->FLInfos['title']}</li>";
  82. $this->Fields['keywords'] = $this->FLInfos['keywords'];
  83. $this->Fields['description'] = $this->FLInfos['description'];
  84. $channelid = $this->ListObj->GetAtt('channel');
  85. if (!empty($channelid)) {
  86. $this->Fields['channeltype'] = $channelid;
  87. $this->ChannelUnit = new ChannelUnit($channelid);
  88. } else {
  89. $this->Fields['channeltype'] = 0;
  90. }
  91. foreach ($GLOBALS['PubFields'] as $k => $v) {
  92. $this->Fields[$k] = $v;
  93. }
  94. $this->PartView = new PartView();
  95. $this->CountRecord();
  96. }
  97. //php4构造函数
  98. function FreeList($fid)
  99. {
  100. $this->__construct($fid);
  101. }
  102. //关闭相关资源
  103. function Close()
  104. {
  105. }
  106. /**
  107. * 统计列表里的记录
  108. *
  109. * @access private
  110. * @return void
  111. */
  112. function CountRecord()
  113. {
  114. global $cfg_list_son, $cfg_needsontype;
  115. //统计数据库记录
  116. $this->TotalResult = -1;
  117. if (isset($GLOBALS['TotalResult'])) {
  118. $this->TotalResult = $GLOBALS['TotalResult'];
  119. }
  120. if (isset($GLOBALS['PageNo'])) {
  121. $this->PageNo = $GLOBALS['PageNo'];
  122. } else {
  123. $this->PageNo = 1;
  124. }
  125. //已经有总记录的值
  126. if ($this->TotalResult == -1) {
  127. $addSql = " arcrank > -1 AND channel>-1 ";
  128. $typeid = $this->ListObj->GetAtt('typeid');
  129. $subday = $this->ListObj->GetAtt('subday');
  130. $listtype = $this->ListObj->GetAtt('type');
  131. $att = $this->ListObj->GetAtt('att');
  132. $channelid = $this->ListObj->GetAtt('channel');
  133. if (empty($channelid)) {
  134. $channelid = 0;
  135. }
  136. //是否指定栏目条件
  137. if (!empty($typeid)) {
  138. if ($cfg_list_son == 'N') {
  139. $addSql .= " AND (typeid='$typeid') ";
  140. } else {
  141. $addSql .= " AND typeid in (".GetSonIds($typeid, 0, TRUE).") ";
  142. }
  143. }
  144. //自定义属性条件
  145. if ($att != '') {
  146. $flags = explode(',', $att);
  147. for ($i = 0; isset($flags[$i]); $i++) $addSql .= " AND FIND_IN_SET('{$flags[$i]}',flag)>0 ";
  148. }
  149. //文档的频道模型
  150. if ($channelid > 0 && !preg_match("#spec#i", $listtype)) {
  151. $addSql .= " AND channel = '$channelid' ";
  152. }
  153. //推荐文档 带缩略图 专题文档
  154. if (preg_match("#commend#i", $listtype)) {
  155. $addSql .= " AND FIND_IN_SET('c',flag) > 0 ";
  156. }
  157. if (preg_match("#image#i", $listtype)) {
  158. $addSql .= " AND litpic <> '' ";
  159. }
  160. if (preg_match("#spec#i", $listtype) || $channelid == -1) {
  161. $addSql .= " AND channel = -1 ";
  162. }
  163. if (!empty($subday)) {
  164. $starttime = time() - $subday * 86400;
  165. $addSql .= " AND senddate > $starttime ";
  166. }
  167. $keyword = $this->ListObj->GetAtt('keyword');
  168. if (!empty($keyword)) {
  169. $addSql .= " AND CONCAT(title,keywords) REGEXP '$keyword' ";
  170. }
  171. $cquery = "SELECT COUNT(*) AS dd FROM `{$this->maintable}` WHERE $addSql";
  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. $this->TotalPage = ceil($this->TotalResult / $this->PageSize);
  180. if ($this->TotalPage > $this->FLInfos['maxpage']) {
  181. $this->TotalPage = $this->FLInfos['maxpage'];
  182. $this->TotalResult = $this->TotalPage * $this->PageSize;
  183. }
  184. }
  185. /**
  186. * 载入模板
  187. *
  188. * @access public
  189. * @return void
  190. */
  191. function LoadTemplet()
  192. {
  193. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  194. $tempfile = str_replace("{style}", $GLOBALS['cfg_df_style'], $this->FLInfos['templet']);
  195. $tempfile = $tmpdir."/".$tempfile;
  196. if (!file_exists($tempfile)) {
  197. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/list_free.htm";
  198. }
  199. $this->dtp->LoadTemplate($tempfile);
  200. $this->TempletsFile = preg_replace("#^".$GLOBALS['cfg_basedir']."#", '', $tempfile);
  201. }
  202. /**
  203. * 列表创建HTML
  204. *
  205. * @access public
  206. * @param string $startpage 开始页面
  207. * @param string $makepagesize 生成的页码数
  208. * @return string
  209. */
  210. function MakeHtml($startpage = 1, $makepagesize = 0)
  211. {
  212. $this->LoadTemplet();
  213. $murl = "";
  214. if (empty($startpage)) {
  215. $startpage = 1;
  216. }
  217. $this->ParseTempletsFirst();
  218. $totalpage = ceil($this->TotalResult / $this->PageSize);
  219. if ($totalpage == 0) {
  220. $totalpage = 1;
  221. }
  222. if ($makepagesize > 0) {
  223. $endpage = $startpage + $makepagesize;
  224. } else {
  225. $endpage = ($totalpage + 1);
  226. }
  227. if ($endpage > ($totalpage + 1)) {
  228. $endpage = $totalpage;
  229. }
  230. $firstFile = '';
  231. for ($this->PageNo = $startpage; $this->PageNo < $endpage; $this->PageNo++) {
  232. $this->ParseDMFields($this->PageNo, 1);
  233. //文件名
  234. $makeFile = $this->GetMakeFileRule();
  235. if (!preg_match("#^\/#", $makeFile)) {
  236. $makeFile = "/".$makeFile;
  237. }
  238. $makeFile = str_replace('{page}', $this->PageNo, $makeFile);
  239. $murl = $makeFile;
  240. $makeFile = $GLOBALS['cfg_basedir'].$makeFile;
  241. $makeFile = preg_replace("#\/{1,}#", "/", $makeFile);
  242. if ($this->PageNo == 1) {
  243. $firstFile = $makeFile;
  244. }
  245. //保存文件
  246. $this->dtp->SaveTo($makeFile);
  247. echo "<div class=\"alert alert-success\" role=\"alert\">成功创建:<a href='".preg_replace("#\/{1,}#", "/", $murl)."' target='_blank'>".preg_replace("#\/{1,}#", "/", $murl)."</a></div><br/>";
  248. }
  249. if ($this->FLInfos['nodefault'] == 0) {
  250. $murl = '/'.str_replace('{cmspath}', $GLOBALS['cfg_cmspath'], $this->FLInfos['listdir']);
  251. $murl .= '/'.$this->FLInfos['defaultpage'];
  252. $indexfile = $GLOBALS['cfg_basedir'].$murl;
  253. $murl = preg_replace("#\/{1,}#", "/", $murl);
  254. echo "<div class=\"alert alert-success\" role=\"alert\">复制:$firstFile 为 ".$this->FLInfos['defaultpage']."</div><br/>";
  255. copy($firstFile, $indexfile);
  256. }
  257. $this->Close();
  258. return $murl;
  259. }
  260. /**
  261. * 显示列表
  262. *
  263. * @access public
  264. * @return void
  265. */
  266. function Display()
  267. {
  268. $this->LoadTemplet();
  269. $this->ParseTempletsFirst();
  270. $this->ParseDMFields($this->PageNo, 0);
  271. $this->dtp->Display();
  272. }
  273. /**
  274. * 显示单独模板页面
  275. *
  276. * @access public
  277. * @return void
  278. */
  279. function DisplayPartTemplets()
  280. {
  281. $nmfa = 0;
  282. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  283. if ($this->Fields['ispart'] == 1) {
  284. $tempfile = str_replace("{tid}", $this->FreeID, $this->Fields['tempindex']);
  285. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  286. $tempfile = $tmpdir."/".$tempfile;
  287. if (!file_exists($tempfile)) {
  288. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  289. }
  290. $this->PartView->SetTemplet($tempfile);
  291. } else if ($this->Fields['ispart'] == 2) {
  292. $tempfile = str_replace("{tid}", $this->FreeID, $this->Fields['tempone']);
  293. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  294. if (is_file($tmpdir."/".$tempfile)) {
  295. $this->PartView->SetTemplet($tmpdir."/".$tempfile);
  296. } else {
  297. $this->PartView->SetTemplet("这是没有使用模板的单独页", "string");
  298. $nmfa = 1;
  299. }
  300. }
  301. CreateDir($this->Fields['typedir']);
  302. $makeUrl = $this->GetMakeFileRule($this->Fields['id'], "index", $this->Fields['typedir'], $this->Fields['defaultname'], $this->Fields['namerule2']);
  303. $makeFile = $this->GetTruePath().$makeUrl;
  304. if ($nmfa == 0) {
  305. $this->PartView->Display();
  306. } else {
  307. if (!file_exists($makeFile)) {
  308. $this->PartView->Display();
  309. } else {
  310. include($makeFile);
  311. }
  312. }
  313. }
  314. /**
  315. * 解析模板,对固定的标记进行初始给值
  316. *
  317. * @access public
  318. * @return void
  319. */
  320. function ParseTempletsFirst()
  321. {
  322. MakeOneTag($this->dtp, $this);
  323. }
  324. /**
  325. * 解析模板,对内容里的变动进行赋值
  326. *
  327. * @access public
  328. * @param string $PageNo 页码
  329. * @param string $ismake 是否编译
  330. * @return string
  331. */
  332. function ParseDMFields($PageNo, $ismake = 1)
  333. {
  334. foreach ($this->dtp->CTags as $tagid => $ctag) {
  335. if ($ctag->GetName() == "freelist") {
  336. $limitstart = ($this->PageNo - 1) * $this->PageSize;
  337. if ($this->PageNo > $this->FLInfos['maxpage']) $this->dtp->Assign($tagid, '已经超过了最大允许列出的页面');
  338. else $this->dtp->Assign($tagid, $this->GetList($limitstart, $ismake));
  339. } else if ($ctag->GetName() == "pagelist") {
  340. $list_len = trim($ctag->GetAtt("listsize"));
  341. $ctag->GetAtt("listitem") == "" ? $listitem = "info,index,pre,pageno,next,end,option" : $listitem = $ctag->GetAtt("listitem");
  342. if ($list_len == "") {
  343. $list_len = 3;
  344. }
  345. if ($ismake == 0) {
  346. $this->dtp->Assign($tagid, $this->GetPageListDM($list_len, $listitem));
  347. } else {
  348. $this->dtp->Assign($tagid, $this->GetPageListST($list_len, $listitem));
  349. }
  350. } else if ($ctag->GetName() == "pageno") {
  351. $this->dtp->Assign($tagid, $PageNo);
  352. }
  353. }
  354. }
  355. /**
  356. * 获得要创建的文件名称规则
  357. *
  358. * @access public
  359. * @return string
  360. */
  361. function GetMakeFileRule()
  362. {
  363. $okfile = '';
  364. $namerule = $this->FLInfos['namerule'];
  365. $listdir = $this->FLInfos['listdir'];
  366. $listdir = str_replace('{cmspath}', $GLOBALS['cfg_cmspath'], $listdir);
  367. $okfile = str_replace('{listid}', $this->FLInfos['aid'], $namerule);
  368. $okfile = str_replace('{listdir}', $listdir, $okfile);
  369. $okfile = str_replace("\\", "/", $okfile);
  370. $mdir = preg_replace("#/([^/]*)$#", "", $okfile);
  371. if (!preg_match("#\/#", $mdir) && preg_match("#\.#", $mdir)) {
  372. return $okfile;
  373. } else {
  374. CreateDir($mdir, '', '');
  375. return $okfile;
  376. }
  377. }
  378. /**
  379. * 获得一个单列的文档列表
  380. *
  381. * @access public
  382. * @param string $limitstart 开始限制
  383. * @param string $ismake 是否编译
  384. * @return string
  385. */
  386. function GetList($limitstart, $ismake = 1)
  387. {
  388. global $cfg_list_son, $cfg_needsontype;
  389. $col = $this->ListObj->GetAtt('col');
  390. if (empty($col)) {
  391. $col = 1;
  392. }
  393. $titlelen = $this->ListObj->GetAtt('titlelen');
  394. $infolen = $this->ListObj->GetAtt('infolen');
  395. $imgwidth = $this->ListObj->GetAtt('imgwidth');
  396. $imgheight = $this->ListObj->GetAtt('imgheight');
  397. $titlelen = AttDef($titlelen, 60);
  398. $infolen = AttDef($infolen, 250);
  399. $imgwidth = AttDef($imgwidth, 80);
  400. $imgheight = AttDef($imgheight, 80);
  401. $innertext = trim($this->ListObj->GetInnerText());
  402. if (empty($innertext)) $innertext = GetSysTemplets("list_fulllist.htm");
  403. $tablewidth = 100;
  404. if ($col == "") $col = 1;
  405. $colWidth = ceil(100 / $col);
  406. $tablewidth = $tablewidth."%";
  407. $colWidth = $colWidth."%";
  408. //按不同情况设定SQL条件
  409. $orwhere = " arc.arcrank > -1 AND channel>-1 ";
  410. $typeid = $this->ListObj->GetAtt('typeid');
  411. $subday = $this->ListObj->GetAtt('subday');
  412. $listtype = $this->ListObj->GetAtt('type');
  413. $att = $this->ListObj->GetAtt('att');
  414. $channelid = $this->ListObj->GetAtt('channel');
  415. if (empty($channelid)) $channelid = 0;
  416. //是否指定栏目条件
  417. if (!empty($typeid)) {
  418. if ($cfg_list_son == 'N') {
  419. $orwhere .= " AND (arc.typeid='$typeid') ";
  420. } else {
  421. $orwhere .= " AND arc.typeid IN (".GetSonIds($typeid, 0, TRUE).") ";
  422. }
  423. }
  424. //自定义属性条件
  425. if ($att != '') {
  426. $flags = explode(',', $att);
  427. for ($i = 0; isset($flags[$i]); $i++) $orwhere .= " AND FIND_IN_SET('{$flags[$i]}',flag)>0 ";
  428. }
  429. //文档的频道模型
  430. if ($channelid > 0 && !preg_match("#spec#i", $listtype)) {
  431. $orwhere .= " AND arc.channel = '$channelid' ";
  432. }
  433. //推荐文档 带缩略图 专题文档
  434. if (preg_match("#commend#i", $listtype)) {
  435. $orwhere .= " AND FIND_IN_SET('c',flag) > 0 ";
  436. }
  437. if (preg_match("#image#i", $listtype)) {
  438. $orwhere .= " AND arc.litpic <> '' ";
  439. }
  440. if (preg_match("#spec#i", $listtype) || $channelid == -1) {
  441. $orwhere .= " AND arc.channel = -1 ";
  442. }
  443. if (!empty($subday)) {
  444. $starttime = time() - $subday * 86400;
  445. $orwhere .= " AND arc.senddate > $starttime ";
  446. }
  447. $keyword = $this->ListObj->GetAtt('keyword');
  448. if (!empty($keyword)) {
  449. $orwhere .= " AND CONCAT(arc.title,arc.keywords) REGEXP '$keyword' ";
  450. }
  451. $orderby = $this->ListObj->GetAtt('orderby');
  452. $orderWay = $this->ListObj->GetAtt('orderway');
  453. //排序方式
  454. $ordersql = "";
  455. if ($orderby == "senddate") {
  456. $ordersql = " ORDER BY arc.senddate $orderWay";
  457. } else if ($orderby == "pubdate") {
  458. $ordersql = " ORDER BY arc.pubdate $orderWay";
  459. } else if ($orderby == "id") {
  460. $ordersql = " ORDER BY arc.id $orderWay";
  461. } else if ($orderby == "hot" || $orderby == "click") {
  462. $ordersql = " ORDER BY arc.click $orderWay";
  463. } else if ($orderby == "lastpost") {
  464. $ordersql = " ORDER BY arc.lastpost $orderWay";
  465. } else if ($orderby == "scores") {
  466. $ordersql = " ORDER BY arc.scores $orderWay";
  467. } else if ($orderby == "rand") {
  468. $ordersql = " ORDER BY rand()";
  469. } else {
  470. $ordersql = " ORDER BY arc.sortrank $orderWay";
  471. }
  472. //获得附加表的相关信息
  473. $addField = "";
  474. $addJoin = "";
  475. if (is_object($this->ChannelUnit)) {
  476. $addtable = $this->ChannelUnit->ChannelInfos['addtable'];
  477. if ($addtable != "") {
  478. $addJoin = " LEFT JOIN $addtable ON arc.id = ".$addtable.".aid ";
  479. $addField = "";
  480. $fields = explode(",", $this->ChannelUnit->ChannelInfos['listfields']);
  481. foreach ($fields as $k => $v) {
  482. $nfields[$v] = $k;
  483. }
  484. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  485. if (isset($nfields[$k])) {
  486. if (!empty($arr['rename'])) {
  487. $addField .= ",".$addtable.".".$k." as ".$arr['rename'];
  488. } else {
  489. $addField .= ",".$addtable.".".$k;
  490. }
  491. }
  492. }
  493. }
  494. }
  495. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,
  496. tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  497. $addField
  498. FROM {$this->maintable} arc
  499. LEFT JOIN #@__arctype tp ON arc.typeid=tp.id
  500. $addJoin
  501. WHERE $orwhere $ordersql LIMIT $limitstart,".$this->PageSize;
  502. $this->dsql->SetQuery($query);
  503. $this->dsql->Execute("al");
  504. $artlist = "";
  505. if ($col > 1) {
  506. $artlist = "<table width='$tablewidth' border='0' cellspacing='0' cellpadding='0'>\r\n";
  507. }
  508. $indtp = new DedeTagParse();
  509. $indtp->SetNameSpace("field", "[", "]");
  510. $indtp->LoadSource($innertext);
  511. $GLOBALS['autoindex'] = 0;
  512. for ($i = 0; $i < $this->PageSize; $i++) {
  513. if ($col > 1) {
  514. $artlist .= "<tr>\r\n";
  515. }
  516. for ($j = 0; $j < $col; $j++) {
  517. if ($col > 1) {
  518. $artlist .= "<td width='$colWidth'>\r\n";
  519. }
  520. if ($row = $this->dsql->GetArray("al")) {
  521. $GLOBALS['autoindex']++;
  522. //处理一些特殊字段
  523. $row['id'] = $row['id'];
  524. $row['arcurl'] = $this->GetArcUrl(
  525. $row['id'],
  526. $row['typeid'],
  527. $row['senddate'],
  528. $row['title'],
  529. $row['ismake'],
  530. $row['arcrank'],
  531. $row['namerule'],
  532. $row['typedir'],
  533. $row['money'],
  534. $row['filename'],
  535. $row['moresite'],
  536. $row['siteurl'],
  537. $row['sitepath']
  538. );
  539. $row['typeurl'] = GetTypeUrl(
  540. $row['typeid'],
  541. $row['typedir'],
  542. $row['isdefault'],
  543. $row['defaultname'],
  544. $row['ispart'],
  545. $row['namerule2'],
  546. $row['siteurl'],
  547. $row['sitepath']
  548. );
  549. if ($ismake == 0 && $GLOBALS['cfg_multi_site'] == 'Y') {
  550. if ($row["siteurl"] == "") {
  551. $row["siteurl"] = $GLOBALS['cfg_mainsite'];
  552. }
  553. }
  554. $row['description'] = cn_substr($row['description'], $infolen);
  555. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  556. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/defaultpic.gif';
  557. }
  558. if (!preg_match("#^http:\/\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  559. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  560. }
  561. $row['picname'] = $row['litpic'];
  562. $row['info'] = $row['description'];
  563. $row['filename'] = $row['arcurl'];
  564. $row['stime'] = GetDateMK($row['pubdate']);
  565. $row['textlink'] = "<a href='".$row['filename']."' title='".str_replace("'", "", $row['title'])."'>".$row['title']."</a>";
  566. $row['typelink'] = "<a href='".$row['typeurl']."'>[".$row['typename']."]</a>";
  567. $row['imglink'] = "<a href='".$row['filename']."'><img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".str_replace("'", "", $row['title'])."'></a>";
  568. $row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".str_replace("'", "", $row['title'])."'>";
  569. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  570. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  571. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  572. $row['title'] = cn_substr($row['title'], $titlelen);
  573. if ($row['color'] != "") {
  574. $row['title'] = "<span style='".$row['color']."'>".$row['title']."</span>";
  575. }
  576. if (preg_match("#c#", $row['flag'])) {
  577. $row['title'] = "<b>".$row['title']."</b>";
  578. }
  579. //编译附加表里的数据
  580. if (is_object($this->ChannelUnit)) {
  581. foreach ($row as $k => $v) {
  582. if (preg_match("#[A-Z]#", $k)) {
  583. $row[strtolower($k)] = $v;
  584. }
  585. }
  586. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  587. if (isset($row[$k])) {
  588. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  589. }
  590. }
  591. }
  592. //解析单条记录
  593. if (is_array($indtp->CTags)) {
  594. foreach ($indtp->CTags as $k => $ctag) {
  595. $_f = $ctag->GetName();
  596. if ($_f == 'array') {
  597. //传递整个数组,在runphp模式中有特殊作用
  598. $indtp->Assign($k, $row);
  599. } else {
  600. if (isset($row[$_f])) {
  601. $indtp->Assign($k, $row[$_f]);
  602. } else {
  603. $indtp->Assign($k, "");
  604. }
  605. }
  606. }
  607. }
  608. $artlist .= $indtp->GetResult();
  609. } //if hasRow
  610. else {
  611. $artlist .= "";
  612. }
  613. if ($col > 1) {
  614. $artlist .= " </td>\r\n";
  615. }
  616. } //Loop Col
  617. if ($col > 1) {
  618. $i += $col - 1;
  619. }
  620. if ($col > 1) {
  621. $artlist .= " </tr>\r\n";
  622. }
  623. } //Loop Line
  624. if ($col > 1) {
  625. $artlist .= "</table>\r\n";
  626. }
  627. $this->dsql->FreeResult("al");
  628. return $artlist;
  629. }
  630. /**
  631. * 获取静态的分页列表
  632. *
  633. * @access public
  634. * @param string $list_len 列表尺寸
  635. * @param string $listitem 列表项目
  636. * @return string
  637. */
  638. function GetPageListST($list_len, $listitem = "info,index,end,pre,next,pageno")
  639. {
  640. $prepage = "";
  641. $nextpage = "";
  642. $prepagenum = $this->PageNo - 1;
  643. $nextpagenum = $this->PageNo + 1;
  644. if ($list_len == "" || preg_match("#[^0-9]#", $list_len)) {
  645. $list_len = 3;
  646. }
  647. $totalpage = ceil($this->TotalResult / $this->PageSize);
  648. if ($totalpage <= 1 && $this->TotalResult > 0) {
  649. return "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共1页/".$this->TotalResult."条记录</span></li>";
  650. }
  651. if ($this->TotalResult == 0) {
  652. return "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共0页/".$this->TotalResult."条记录</span></li>";
  653. }
  654. $maininfo = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共{$totalpage}页/".$this->TotalResult."条记录</span></li>";
  655. $purl = $this->GetCurUrl();
  656. $tnamerule = $this->GetMakeFileRule();
  657. $tnamerule = preg_replace("#^(.*)\/#", '', $tnamerule);
  658. //获得上一页和主页的链接
  659. if ($this->PageNo != 1) {
  660. $prepage .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $prepagenum, $tnamerule)."'>上一页</a></li>\r\n";
  661. $indexpage = "<li class='page-item'><a class='page-link' href='".str_replace("{page}", 1, $tnamerule)."'>首页</a></li>\r\n";
  662. } else {
  663. $indexpage = "<li class='page-item'><span class='page-link'>首页</span></li>\r\n";
  664. }
  665. //下一页,未页的链接
  666. if ($this->PageNo != $totalpage && $totalpage > 1) {
  667. $nextpage .= "<a href='".str_replace("{page}", $nextpagenum, $tnamerule)."'>下一页</a>\r\n";
  668. $endpage = "<a href='".str_replace("{page}", $totalpage, $tnamerule)."'>末页</a>\r\n";
  669. } else {
  670. $endpage = "<li class='page-item'><span class='page-link'>末页</span></li>\r\n";
  671. }
  672. //option链接
  673. $optionlen = strlen($totalpage);
  674. $optionlen = $optionlen * 12 + 18;
  675. if ($optionlen < 36) $optionlen = 36;
  676. if ($optionlen > 100) $optionlen = 100;
  677. $optionlist = "<select name='sldd' style='width:$optionlen' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  678. for ($fl = 1; $fl <= $totalpage; $fl++) {
  679. if ($fl == $this->PageNo) {
  680. $optionlist .= "<option value='".str_replace("{page}", $fl, $tnamerule)."' selected>$fl</option>\r\n";
  681. } else {
  682. $optionlist .= "<option value='".str_replace("{page}", $fl, $tnamerule)."'>$fl</option>\r\n";
  683. }
  684. }
  685. $optionlist .= "</select>";
  686. //获得数字链接
  687. $listdd = "";
  688. $total_list = $list_len * 2 + 1;
  689. if ($this->PageNo >= $total_list) {
  690. $j = $this->PageNo - $list_len;
  691. $total_list = $this->PageNo + $list_len;
  692. if ($total_list > $totalpage) {
  693. $total_list = $totalpage;
  694. }
  695. } else {
  696. $j = 1;
  697. if ($total_list > $totalpage) {
  698. $total_list = $totalpage;
  699. }
  700. }
  701. for ($j; $j <= $total_list; $j++) {
  702. if ($j == $this->PageNo) {
  703. $listdd .= "<li class=\"page-item active\"><span class='page-link'>{$j}</span></li>\r\n";
  704. } else {
  705. $listdd .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $j, $tnamerule)."'>".$j."</a></li>\r\n";
  706. }
  707. }
  708. $plist = "";
  709. if (preg_match('#info#i', $listitem)) {
  710. $plist .= $maininfo.' ';
  711. }
  712. if (preg_match('#index#i', $listitem)) {
  713. $plist .= $indexpage.' ';
  714. }
  715. if (preg_match('#pre#i', $listitem)) {
  716. $plist .= $prepage.' ';
  717. }
  718. if (preg_match('#pageno#i', $listitem)) {
  719. $plist .= $listdd.' ';
  720. }
  721. if (preg_match('#next#i', $listitem)) {
  722. $plist .= $nextpage.' ';
  723. }
  724. if (preg_match('#end#i', $listitem)) {
  725. $plist .= $endpage.' ';
  726. }
  727. if (preg_match('#option#i', $listitem)) {
  728. $plist .= $optionlist;
  729. }
  730. return $plist;
  731. }
  732. /**
  733. * 获取动态的分页列表
  734. *
  735. * @access public
  736. * @param string $list_len 列表尺寸
  737. * @param string $listitem 列表项目
  738. * @return string
  739. */
  740. function GetPageListDM($list_len, $listitem = "index,end,pre,next,pageno")
  741. {
  742. $prepage = "";
  743. $nextpage = "";
  744. $prepagenum = $this->PageNo - 1;
  745. $nextpagenum = $this->PageNo + 1;
  746. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  747. $list_len = 3;
  748. }
  749. $totalpage = ceil($this->TotalResult / $this->PageSize);
  750. if ($totalpage <= 1 && $this->TotalResult > 0) {
  751. return "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共1页/".$this->TotalResult."条记录</span></li>";
  752. }
  753. if ($this->TotalResult == 0) {
  754. return "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共0页/".$this->TotalResult."条记录</span></li>";
  755. }
  756. $maininfo = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共{$totalpage}页/".$this->TotalResult."条记录</span></li>";
  757. $purl = $this->GetCurUrl();
  758. $geturl = "lid=".$this->FreeID."&TotalResult=".$this->TotalResult."&";
  759. $hidenform = "<input type='hidden' name='lid' value='".$this->FreeID."' />\r\n";
  760. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."' />\r\n";
  761. $purl .= "?".$geturl;
  762. //获得上一页和下一页的链接
  763. if ($this->PageNo != 1) {
  764. $prepage .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$prepagenum'>上一页</a>\r\n";
  765. $indexpage = "<li class='page-item'><a class='page-link' href='".$purl."PageNo=1'>首页</a>\r\n";
  766. } else {
  767. $indexpage = "<li class='page-item'><span class='page-link'>首页</span></li>\r\n";
  768. }
  769. if ($this->PageNo != $totalpage && $totalpage > 1) {
  770. $nextpage .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$nextpagenum'>下一页</a>\r\n";
  771. $endpage = "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$totalpage'>末页</a>\r\n";
  772. } else {
  773. $endpage = "<li class='page-item'><span class='page-link'>末页</span></li>\r\n";
  774. }
  775. //获得数字链接
  776. $listdd = "";
  777. $total_list = $list_len * 2 + 1;
  778. if ($this->PageNo >= $total_list) {
  779. $j = $this->PageNo - $list_len;
  780. $total_list = $this->PageNo + $list_len;
  781. if ($total_list > $totalpage) $total_list = $totalpage;
  782. } else {
  783. $j = 1;
  784. if ($total_list > $totalpage) $total_list = $totalpage;
  785. }
  786. for ($j; $j <= $total_list; $j++) {
  787. if ($j == $this->PageNo) {
  788. $listdd .= "<li class=\"page-item active\"><span class='page-link'>$j</span></li>\r\n";
  789. } else {
  790. $listdd .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
  791. }
  792. }
  793. $plist = "<form name='pagelist' action='".$this->GetCurUrl()."'>$hidenform";
  794. $plist .= $maininfo.$indexpage.$prepage.$listdd.$nextpage.$endpage;
  795. if ($totalpage > $total_list) {
  796. $plist .= "<input type='text' name='PageNo' value='".$this->PageNo."' style='width:30px' />\r\n";
  797. $plist .= "<input type='submit' name='plistgo' value='GO' />\r\n";
  798. }
  799. $plist .= "</form>\r\n";
  800. return $plist;
  801. }
  802. /**
  803. * 获得一个指定档案的链接
  804. *
  805. * @access public
  806. * @param int $aid 文档ID
  807. * @param int $typeid 栏目ID
  808. * @param int $timetag 时间戳
  809. * @param string $title 标题
  810. * @param int $ismake 是否生成
  811. * @param int $rank 阅读权限
  812. * @param string $namerule 名称规则
  813. * @param string $typedir 栏目dir
  814. * @param string $money 需要金币
  815. * @param string $filename 文件名称
  816. * @param string $moresite 多站点
  817. * @param string $siteurl 站点地址
  818. * @param string $sitepath 站点路径
  819. * @return string
  820. */
  821. function GetArcUrl(
  822. $aid,
  823. $typeid,
  824. $timetag,
  825. $title,
  826. $ismake = 0,
  827. $rank = 0,
  828. $namerule = '',
  829. $artdir = '',
  830. $money = 0,
  831. $filename = '',
  832. $moresite = '',
  833. $siteurl = '',
  834. $sitepath = ''
  835. ) {
  836. return GetFileUrl(
  837. $aid,
  838. $typeid,
  839. $timetag,
  840. $title,
  841. $ismake,
  842. $rank,
  843. $namerule,
  844. $artdir,
  845. $money,
  846. $filename,
  847. $moresite,
  848. $siteurl,
  849. $sitepath
  850. );
  851. }
  852. /**
  853. * 获得当前的页面文件的url
  854. *
  855. * @access public
  856. * @return void
  857. */
  858. function GetCurUrl()
  859. {
  860. if (!empty($_SERVER["REQUEST_URI"])) {
  861. $nowurl = $_SERVER["REQUEST_URI"];
  862. $nowurls = explode("?", $nowurl);
  863. $nowurl = $nowurls[0];
  864. } else {
  865. $nowurl = $_SERVER["PHP_SELF"];
  866. }
  867. return $nowurl;
  868. }
  869. }//End Class