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

866 lines
35KB

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