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

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