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

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