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

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