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

1048 lines
35KB

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