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

598 lines
20KB

  1. <?php if(!defined('DEDEINC')) exit('Request Error!');
  2. /**
  3. * Tag列表类
  4. *
  5. * @version $Id: arc.taglist.class.php 1 18:17 2010年7月7日Z tianya $
  6. * @package DedeCMS.Libraries
  7. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. require_once(DEDEINC.'/channelunit.class.php');
  12. require_once(DEDEINC.'/typelink.class.php');
  13. @set_time_limit(0);
  14. /**
  15. * Tag列表类
  16. *
  17. * @package TagList
  18. * @subpackage DedeCMS.Libraries
  19. * @link http://www.dedecms.com
  20. */
  21. class TagList
  22. {
  23. var $dsql;
  24. var $dtp;
  25. var $dtp2;
  26. var $TypeLink;
  27. var $PageNo;
  28. var $TotalPage;
  29. var $TotalResult;
  30. var $PageSize;
  31. var $ListType;
  32. var $Fields;
  33. var $Tag;
  34. var $Templet;
  35. var $TagInfos;
  36. var $TempletsFile;
  37. /**
  38. * php5构造函数
  39. *
  40. * @access public
  41. * @param string $keyword 关键词
  42. * @param string $templet 模板
  43. * @return void
  44. */
  45. function __construct($keyword, $templet)
  46. {
  47. global $dsql;
  48. $this->Templet = $templet;
  49. $this->Tag = $keyword;
  50. $this->dsql = $dsql;
  51. $this->dtp = new DedeTagParse();
  52. $this->dtp->SetRefObj($this);
  53. $this->dtp->SetNameSpace("dede","{","}");
  54. $this->dtp2 = new DedeTagParse();
  55. $this->dtp2->SetNameSpace("field","[","]");
  56. $this->TypeLink = new TypeLink(0);
  57. $this->Fields['tag'] = $keyword;
  58. $this->Fields['title'] = $keyword;
  59. $this->TempletsFile = '';
  60. //设置一些全局参数的值
  61. foreach($GLOBALS['PubFields'] as $k=>$v) $this->Fields[$k] = $v;
  62. //读取Tag信息
  63. if($this->Tag!='')
  64. {
  65. $this->TagInfos = $this->dsql->GetOne("Select * From `#@__tagindex` where tag like '{$this->Tag}' ");
  66. if(!is_array($this->TagInfos))
  67. {
  68. $fullsearch = $GLOBALS['cfg_phpurl']."/search.php?keyword=".$this->Tag."&searchtype=titlekeyword";
  69. $msg = "系统无此标签,可能已经移除!<br /><br />你还可以尝试通过搜索程序去搜索这个关键字:<a href='$fullsearch'>前往搜索&gt;&gt;</a>";
  70. ShowMsg($msg,"-1");
  71. exit();
  72. }
  73. }
  74. //初始化模板
  75. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style'].'/'.$this->Templet;
  76. if(!file_exists($tempfile)||!is_file($tempfile))
  77. {
  78. echo "模板文件不存在,无法解析文档!";
  79. exit();
  80. }
  81. $this->dtp->LoadTemplate($tempfile);
  82. $this->TempletsFile = preg_replace("#^".$GLOBALS['cfg_basedir']."#", '', $tempfile);
  83. }
  84. //php4构造函数
  85. function TagList($keyword,$templet)
  86. {
  87. $this->__construct($keyword,$templet);
  88. }
  89. //关闭相关资源
  90. function Close()
  91. {
  92. @$this->dsql->Close();
  93. @$this->TypeLink->Close();
  94. }
  95. /**
  96. * 统计列表里的记录
  97. *
  98. * @access private
  99. * @return void
  100. */
  101. function CountRecord()
  102. {
  103. //统计数据库记录
  104. $this->TotalResult = -1;
  105. if(isset($GLOBALS['TotalResult']))
  106. {
  107. $this->TotalResult = $GLOBALS['TotalResult'];
  108. }
  109. if(isset($GLOBALS['PageNo']))
  110. {
  111. $this->PageNo = $GLOBALS['PageNo'];
  112. }
  113. else
  114. {
  115. $this->PageNo = 1;
  116. }
  117. if($this->TotalResult==-1)
  118. {
  119. $cquery = "SELECT COUNT(*) AS dd FROM `#@__taglist` WHERE tid = '{$this->TagInfos['id']}' AND arcrank >-1 ";
  120. $row = $this->dsql->GetOne($cquery);
  121. $this->TotalResult = $row['dd'];
  122. //更新Tag信息
  123. $ntime = time();
  124. //更新浏览量和记录数
  125. $upquery = "UPDATE `#@__tagindex` SET total='{$row['dd']}',count=count+1,weekcc=weekcc+1,monthcc=monthcc+1 WHERE tag LIKE '{$this->Tag}' ";
  126. $this->dsql->ExecuteNoneQuery($upquery);
  127. $oneday = 24 * 3600;
  128. //周统计
  129. if(ceil( ($ntime - $this->TagInfos['weekup'])/$oneday ) > 7)
  130. {
  131. $this->dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET weekcc=0,weekup='{$ntime}' WHERE tag LIKE '{$this->Tag}' ");
  132. }
  133. //月统计
  134. if(ceil( ($ntime - $this->TagInfos['monthup'])/$oneday ) > 30)
  135. {
  136. $this->dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET monthcc=0,monthup='{$ntime}' WHERE tag LIKE '{$this->Tag}' ");
  137. }
  138. }
  139. $ctag = $this->dtp->GetTag("page");
  140. if(!is_object($ctag))
  141. {
  142. $ctag = $this->dtp->GetTag("list");
  143. }
  144. if(!is_object($ctag))
  145. {
  146. $this->PageSize = 25;
  147. }
  148. else
  149. {
  150. if($ctag->GetAtt("pagesize")!='')
  151. {
  152. $this->PageSize = $ctag->GetAtt("pagesize");
  153. }
  154. else
  155. {
  156. $this->PageSize = 25;
  157. }
  158. }
  159. $this->TotalPage = ceil($this->TotalResult/$this->PageSize);
  160. }
  161. /**
  162. * 显示列表
  163. *
  164. * @access public
  165. * @return void
  166. */
  167. function Display()
  168. {
  169. if($this->Tag!='')
  170. {
  171. $this->CountRecord();
  172. }
  173. $this->ParseTempletsFirst();
  174. if($this->Tag!='')
  175. {
  176. $this->ParseDMFields($this->PageNo,0);
  177. }
  178. $this->Close();
  179. $this->dtp->Display();
  180. }
  181. /**
  182. * 解析模板,对固定的标记进行初始给值
  183. *
  184. * @access private
  185. * @return void
  186. */
  187. function ParseTempletsFirst()
  188. {
  189. MakeOneTag($this->dtp,$this);
  190. }
  191. /**
  192. * 解析模板,对内容里的变动进行赋值
  193. *
  194. * @access public
  195. * @param int $PageNo 页码
  196. * @param int $ismake 是否编译
  197. * @return string
  198. */
  199. function ParseDMFields($PageNo, $ismake=1)
  200. {
  201. foreach($this->dtp->CTags as $tagid=>$ctag){
  202. if($ctag->GetName()=="list")
  203. {
  204. $limitstart = ($this->PageNo-1) * $this->PageSize;
  205. if($limitstart<0)
  206. {
  207. $limitstart = 0;
  208. }
  209. $row = $this->PageSize;
  210. if(trim($ctag->GetInnerText())=="")
  211. {
  212. $InnerText = GetSysTemplets("list_fulllist.htm");
  213. }
  214. else
  215. {
  216. $InnerText = trim($ctag->GetInnerText());
  217. }
  218. $this->dtp->Assign($tagid,
  219. $this->GetArcList(
  220. $limitstart,
  221. $row,
  222. $ctag->GetAtt("col"),
  223. $ctag->GetAtt("titlelen"),
  224. $ctag->GetAtt("infolen"),
  225. $ctag->GetAtt("imgwidth"),
  226. $ctag->GetAtt("imgheight"),
  227. $ctag->GetAtt("listtype"),
  228. $ctag->GetAtt("orderby"),
  229. $InnerText,
  230. $ctag->GetAtt("tablewidth"),
  231. $ismake,
  232. $ctag->GetAtt("orderway")
  233. )
  234. );
  235. }
  236. else if($ctag->GetName()=="pagelist")
  237. {
  238. $list_len = trim($ctag->GetAtt("listsize"));
  239. $ctag->GetAtt("listitem")=="" ? $listitem="info,index,pre,pageno,next,end,option" : $listitem=$ctag->GetAtt("listitem");
  240. if($list_len=="")
  241. {
  242. $list_len = 3;
  243. }
  244. if($ismake==0)
  245. {
  246. $this->dtp->Assign($tagid,$this->GetPageListDM($list_len,$listitem));
  247. }
  248. else
  249. {
  250. $this->dtp->Assign($tagid,$this->GetPageListST($list_len,$listitem));
  251. }
  252. }
  253. }
  254. }
  255. /**
  256. * 获得一个单列的文档列表
  257. *
  258. * @access public
  259. * @param int $limitstart 限制开始
  260. * @param int $row 行数
  261. * @param int $col 列数
  262. * @param int $titlelen 标题长度
  263. * @param int $infolen 描述长度
  264. * @param int $imgwidth 图片宽度
  265. * @param int $imgheight 图片高度
  266. * @param string $listtype 列表类型
  267. * @param string $orderby 排列顺序
  268. * @param string $innertext 底层模板
  269. * @param string $tablewidth 表格宽度
  270. * @param string $ismake 是否编译
  271. * @param string $orderWay 排序方式
  272. * @return string
  273. */
  274. function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$infolen=250,
  275. $imgwidth=120,$imgheight=90,$listtype="all",$orderby="default",$innertext="",$tablewidth="100",$ismake=1,$orderWay='desc')
  276. {
  277. $getrow = ($row=='' ? 10 : $row);
  278. if($limitstart=='') $limitstart = 0;
  279. if($titlelen=='') $titlelen = 100;
  280. if($infolen=='') $infolen = 250;
  281. if($imgwidth=='') $imgwidth = 120;
  282. if($imgheight=='') $imgheight = 120;
  283. if($listtype=='') $listtype = 'all';
  284. $orderby = ($orderby=='' ? 'default' : strtolower($orderby) );
  285. if($orderWay=='') $orderWay = 'desc';
  286. $tablewidth = str_replace("%", "", $tablewidth);
  287. if($tablewidth=='') $tablewidth=100;
  288. if($col=='') $col=1;
  289. $colWidth = ceil(100/$col);
  290. $tablewidth = $tablewidth."%";
  291. $colWidth = $colWidth."%";
  292. $innertext = trim($innertext);
  293. if($innertext=='') $innertext = GetSysTemplets("list_fulllist.htm");
  294. $idlists = $ordersql = '';
  295. $this->dsql->SetQuery("SELECT aid FROM `#@__taglist` WHERE tid = '{$this->TagInfos['id']}' AND arcrank>-1 LIMIT $limitstart,$getrow");
  296. $this->dsql->Execute();
  297. while($row=$this->dsql->GetArray())
  298. {
  299. $idlists .= ($idlists=='' ? $row['aid'] : ','.$row['aid']);
  300. }
  301. if($idlists=='') return '';
  302. //按不同情况设定SQL条件
  303. $orwhere = " se.id IN($idlists) ";
  304. //排序方式
  305. if($orderby=="sortrank")
  306. {
  307. $ordersql = " ORDER BY se.sortrank $orderWay";
  308. }
  309. else
  310. {
  311. $ordersql=" ORDER BY se.id $orderWay";
  312. }
  313. $query = "SELECT se.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  314. FROM `#@__archives` se LEFT JOIN `#@__arctype` tp ON se.typeid=tp.id WHERE $orwhere $ordersql ";
  315. $this->dsql->SetQuery($query);
  316. $this->dsql->Execute('al');
  317. $row = $this->PageSize / $col;
  318. $artlist = '';
  319. $this->dtp2->LoadSource($innertext);
  320. $GLOBALS['autoindex'] = 0;
  321. for($i=0; $i<$row; $i++)
  322. {
  323. if($col > 1)
  324. {
  325. $artlist .= "<div>\r\n";
  326. }
  327. for($j=0; $j<$col; $j++)
  328. {
  329. if($row = $this->dsql->GetArray("al"))
  330. {
  331. $GLOBALS['autoindex']++;
  332. $ids[$row['id']] = $row['id'];
  333. //处理一些特殊字段
  334. $row['infos'] = cn_substr($row['description'],$infolen);
  335. $row['id'] = $row['id'];
  336. $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],
  337. $row['ismake'],
  338. $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],
  339. $row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  340. $row['typeurl'] = GetTypeUrl($row['typeid'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],
  341. $row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  342. if($row['litpic'] == '-' || $row['litpic'] == '')
  343. {
  344. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/defaultpic.gif';
  345. }
  346. if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  347. {
  348. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  349. }
  350. $row['picname'] = $row['litpic'];
  351. $row['stime'] = GetDateMK($row['pubdate']);
  352. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  353. $row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".preg_replace("/['><]/", "", $row['title'])."'>";
  354. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  355. $row['fulltitle'] = $row['title'];
  356. $row['title'] = cn_substr($row['title'],$titlelen);
  357. if($row['color']!='')
  358. {
  359. $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
  360. }
  361. if(preg_match('/c/', $row['flag']))
  362. {
  363. $row['title'] = "<b>".$row['title']."</b>";
  364. }
  365. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  366. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  367. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  368. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  369. if(is_array($this->dtp2->CTags))
  370. {
  371. foreach($this->dtp2->CTags as $k=>$ctag)
  372. {
  373. if($ctag->GetName()=='array')
  374. {
  375. //传递整个数组,在runphp模式中有特殊作用
  376. $this->dtp2->Assign($k,$row);
  377. }
  378. else
  379. {
  380. if(isset($row[$ctag->GetName()]))
  381. {
  382. $this->dtp2->Assign($k,$row[$ctag->GetName()]);
  383. }
  384. else
  385. {
  386. $this->dtp2->Assign($k,'');
  387. }
  388. }
  389. }
  390. }
  391. $artlist .= $this->dtp2->GetResult();
  392. }//if hasRow
  393. }//Loop Col
  394. if($col>1)
  395. {
  396. $i += $col - 1;
  397. $artlist .= " </div>\r\n";
  398. }
  399. }//Loop Line
  400. $this->dsql->FreeResult('al');
  401. return $artlist;
  402. }
  403. /**
  404. * 获取动态的分页列表
  405. *
  406. * @access public
  407. * @param int $list_len 列表宽度
  408. * @param string $listitem 列表样式
  409. * @return string
  410. */
  411. function GetPageListDM($list_len,$listitem="info,index,end,pre,next,pageno")
  412. {
  413. $prepage="";
  414. $nextpage="";
  415. $prepagenum = $this->PageNo - 1;
  416. $nextpagenum = $this->PageNo + 1;
  417. if($list_len == "" || preg_match("/[^0-9]/", $list_len))
  418. {
  419. $list_len = 3;
  420. }
  421. $totalpage = $this->TotalPage;
  422. if($totalpage <= 1 && $this->TotalResult > 0)
  423. {
  424. return "<span class=\"pageinfo\">共1页/".$this->TotalResult."条</span>";
  425. }
  426. if($this->TotalResult == 0)
  427. {
  428. return "<span class=\"pageinfo\">共0页/".$this->TotalResult."条</span>";
  429. }
  430. $maininfo = "<span class=\"pageinfo\">共{$totalpage}页/".$this->TotalResult."条</span>\r\n";
  431. $purl = $this->GetCurUrl();
  432. $purl .= "?/".urlencode($this->Tag);
  433. //获得上一页和下一页的链接
  434. if($this->PageNo != 1)
  435. {
  436. $prepage.="<li><a href='".$purl."/$prepagenum/'>上一页</a></li>\r\n";
  437. $indexpage="<li><a href='".$purl."/1/'>首页</a></li>\r\n";
  438. }
  439. else
  440. {
  441. $indexpage="<li><a>首页</a></li>\r\n";
  442. }
  443. if($this->PageNo!=$totalpage && $totalpage>1)
  444. {
  445. $nextpage.="<li><a href='".$purl."/$nextpagenum/'>下一页</a></li>\r\n";
  446. $endpage="<li><a href='".$purl."/$totalpage/'>末页</a></li>\r\n";
  447. }
  448. else
  449. {
  450. $endpage="<li><a>末页</a></li>\r\n";
  451. }
  452. //获得数字链接
  453. $listdd="";
  454. $total_list = $list_len * 2 + 1;
  455. if($this->PageNo >= $total_list)
  456. {
  457. $j = $this->PageNo - $list_len;
  458. $total_list = $this->PageNo + $list_len;
  459. if($total_list > $totalpage)
  460. {
  461. $total_list = $totalpage;
  462. }
  463. }
  464. else
  465. {
  466. $j=1;
  467. if($total_list > $totalpage)
  468. {
  469. $total_list = $totalpage;
  470. }
  471. }
  472. for($j; $j<=$total_list; $j++)
  473. {
  474. if($j == $this->PageNo)
  475. {
  476. $listdd.= "<li class=\"thisclass\"><a>$j</a></li>\r\n";
  477. }
  478. else
  479. {
  480. $listdd.="<li><a href='".$purl."/$j/'>".$j."</a></li>\r\n";
  481. }
  482. }
  483. $plist = '';
  484. if(preg_match('/info/i', $listitem))
  485. {
  486. $plist .= $maininfo.' ';
  487. }
  488. if(preg_match('/index/i', $listitem))
  489. {
  490. $plist .= $indexpage.' ';
  491. }
  492. if(preg_match('/pre/i', $listitem))
  493. {
  494. $plist .= $prepage.' ';
  495. }
  496. if(preg_match('/pageno/i', $listitem))
  497. {
  498. $plist .= $listdd.' ';
  499. }
  500. if(preg_match('/next/i', $listitem))
  501. {
  502. $plist .= $nextpage.' ';
  503. }
  504. if(preg_match('/end/i', $listitem))
  505. {
  506. $plist .= $endpage.' ';
  507. }
  508. return $plist;
  509. }
  510. /**
  511. * 获得一个指定的频道的链接
  512. *
  513. * @access private
  514. * @param int $typeid 栏目ID
  515. * @param string $typedir 栏目目录
  516. * @param int $isdefault 是否为默认
  517. * @param string $defaultname 默认名称
  518. * @param int $ispart 栏目属性
  519. * @param string $namerule2 栏目规则
  520. * @param string $siteurl 站点地址
  521. * @return string
  522. */
  523. function GetListUrl($typeid,$typedir,$isdefault,$defaultname,$ispart,$namerule2,$siteurl="")
  524. {
  525. return GetTypeUrl($typeid,MfTypedir($typedir),$isdefault,$defaultname,$ispart,$namerule2,$siteurl);
  526. }
  527. /**
  528. * 获得一个指定档案的链接
  529. *
  530. * @access private
  531. * @param int $aid 文档ID
  532. * @param int $typeid 栏目ID
  533. * @param int $timetag 时间戳
  534. * @param string $title 标题
  535. * @param int $ismake 是否生成静态
  536. * @param int $rank 浏览权限
  537. * @param string $namerule 命名规则
  538. * @param string $artdir 文档路径
  539. * @param int $money 需要金币
  540. * @param string $filename 文件名称
  541. * @return string
  542. */
  543. function GetArcUrl($aid,$typeid,$timetag,$title,$ismake=0,$rank=0,$namerule="",$artdir="",$money=0,$filename='')
  544. {
  545. return GetFileUrl($aid,$typeid,$timetag,$title,$ismake,$rank,$namerule,$artdir,$money,$filename);
  546. }
  547. /**
  548. * 获得当前的页面文件的url
  549. *
  550. * @access private
  551. * @return string
  552. */
  553. function GetCurUrl()
  554. {
  555. if(!empty($_SERVER["REQUEST_URI"]))
  556. {
  557. $nowurl = $_SERVER["REQUEST_URI"];
  558. $nowurls = explode("?",$nowurl);
  559. $nowurl = $nowurls[0];
  560. }
  561. else
  562. {
  563. $nowurl = $_SERVER["PHP_SELF"];
  564. }
  565. return $nowurl;
  566. }
  567. }//End Class