<?php if(!defined('DEDEINC')) exit("Request Error!");require_once(DEDEINC.'/dedetag.class.php');require_once(DEDEINC.'/typelink.class.php');require_once(DEDEINC.'/channelunit.func.php');require_once(DEDEINC.'/ftp.class.php');@set_time_limit(0);class RssView{ var $dsql; var $TypeID; var $TypeLink; var $TypeFields; var $MaxRow; var $dtp; var $ftp; var $ac; var $remoteDir; var $Next_page; /** * php5构造函数 * * @access public * @param int $typeid 栏目ID * @param int $max_row 最大显示行数 * @return string */ function __construct($ac,$maxMsg,$cur_page,$pagesize,$cur_date) { global $ftp; $this->dtp = new DedeTagParse(); $this->dtp->refObj = $this; $this->cur_page = $cur_page; $templetfiles01 = $GLOBALS['cfg_basedir']."/control/templets/plus/guidang_list.htm"; $templetfiles02 = $GLOBALS['cfg_basedir']."/control/templets/plus/guidang_index.htm"; if($ac == 1){ $this->dtp->LoadTemplate($templetfiles02); }elseif($ac == 2){ $this->dtp->LoadTemplate($templetfiles01); } $this->remoteDir = ''; $this->dsql = $GLOBALS['dsql']; $this->ftp = &$ftp; $this->pagesize = $pagesize; $this->ac = $ac; $thsi->maxMsg = $maxMsg; $this->cur_date = $cur_date; $this->ParseTemplet(); } //php4构造函数 function RssView($ac,$cur_date = null) { $this->__construct($ac,$cur_date = null); } //关闭相关资源 function Close() { } /** * 显示列表 * * @access public * @return void */ function Display() { $this->dtp->Display(); } /** * 开始创建列表 * * @access public * @param string $isremote 是否远程 * @return string */ function MakeRss($isremote=0) { global $cfg_remote_site; $murl = "/".$this->cur_date.".html"; $mfile = $GLOBALS['cfg_basedir'].$murl; $this->dtp->SaveTo($mfile); return $murl; } /** * 解析模板 * * @access public * @return void */ function ParseTemplet() { foreach($this->dtp->CTags as $tid => $ctag) { if($ctag->GetName()=="field") { $this->dtp->Assign($tid,$this->TypeFields[$ctag->GetAtt('name')]); } else if($ctag->GetName()=="fenyehtml") { $this->dtp->Assign($tid, $this->GetPageListST() ); } else if($ctag->GetName()=="seotitle") { $this->dtp->Assign($tid, "第".$this->cur_page."页" ); if($this->ac == 2){ $this->dtp->Assign($tid,$this->cur_date); } } else if($ctag->GetName()=="datelist") { $this->dtp->Assign($tid, $this->GetArcList($ctag->GetInnerText()) ); } else if($ctag->GetName()=="dateitem") { $this->dtp->Assign($tid, $this->GetDateList($ctag->GetInnerText()) ); } } } /** * 获得下一页的页码 * * @access public * @param string $innertext 底层模板 * @return string */ function NextPage(){ return $this->Next_page; } function NextPageIndex(){ return $this->Next_page; } /** * 创建索引 * * @access public * @param string $innertext 底层模板 * @return string */ function MakeIndex(){ global $cfg_remote_site; if($this->cur_page == 1){ $murl = "/index_guidang.html"; }else{ $murl = "/index_guidang".$this->cur_page.".html"; } $mfile = $GLOBALS['cfg_basedir'].$murl; $this->dtp->SaveTo($mfile); return $murl; } /** * 获得文档列表 * * @access public * @param string $innertext 底层模板 * @return string */ function GetArcList($innertext="") { $innertext = trim($innertext); if($innertext=="") { $innertext = GetSysTemplets("guidang_list.htm"); } $orwhere = " arc.arcrank > -1 and FROM_UNIXTIME(pubdate, '%Y-%m') = '".$this->cur_date."'"; $ordersql=" ORDER BY arc.id desc"; $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault, tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id WHERE $orwhere $ordersql"; $this->dsql->SetQuery($query); $this->dsql->Execute('al'); $artlist = ''; $dtp2 = new DedeTagParse(); $dtp2->SetNameSpace('field','[',']'); $dtp2->LoadSource($innertext); while($row = $this->dsql->GetArray('al')) { //处理一些特殊字段 if($row['litpic'] == '-' || $row['litpic'] == '') { $row['litpic'] = $GLOBALS['cfg_basehost'].'/images/defaultpic.gif'; } if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') { $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic']; } $row['picname'] = $row['litpic']; $row["arcurl"] = GetFileUrl($row["id"],$row["typeid"],$row["senddate"],$row["title"], $row["ismake"],$row["arcrank"],$row["namerule"],$row["typedir"],$row["money"],$row['filename'],$row["moresite"],$row["siteurl"],$row["sitepath"]); $row["typeurl"] = GetTypeUrl($row["typeid"],$row["typedir"],$row["isdefault"],$row["defaultname"],$row["ispart"], $row["namerule2"],$row["moresite"],$row["siteurl"],$row["sitepath"]); $row["info"] = $row["description"]; $row["filename"] = $row["arcurl"]; $row["stime"] = GetDateMK($row["pubdate"]); $row["image"] = "<img src='".$row["picname"]."' border='0'>"; $row["fullurl"] = $GLOBALS["cfg_basehost"].$row["arcurl"]; // 2011-6-20 启用多站点RSS输出存在的路径问题(by:织梦的鱼) if($GLOBALS['cfg_multi_site'] == 'Y') $row["fullurl"] = $row["arcurl"]; $row["phpurl"] = $GLOBALS["cfg_plus_dir"]; $row["templeturl"] = $GLOBALS["cfg_templets_dir"]; if($row["source"]=='') { $row["source"] = $GLOBALS['cfg_webname']; } if($row["writer"]=='') { $row["writer"] = "秩名"; } foreach($row as $k=>$v) { $row[$k] = htmlspecialchars($v); } if(is_array($dtp2->CTags)) { foreach($dtp2->CTags as $k=>$ctag) { if($ctag->GetName()=='array') { //传递整个数组,在runphp模式中有特殊作用 $dtp2->Assign($k,$row); } else { if(isset($row[$ctag->GetName()])) { $dtp2->Assign($k,$row[$ctag->GetName()]); } else { $dtp2->Assign($k,''); } } } } $artlist .= $dtp2->GetResult()."\r\n"; } $this->Next_page = $this->cur_page + 1; $this->dsql->FreeResult('al'); return $artlist; } /** * 获得日期索引文档列表 * * @access public * @param string $innertext 底层模板 * @return string */ function GetDateList($innertext="") { $innertext = trim($innertext); if($innertext=="") { $innertext = GetSysTemplets("arc.htm"); } $pagesize = $this->pagesize; $limit = $this->cur_page - 1; $limit = $limit*$pagesize; $query = "SELECT FROM_UNIXTIME(pubdate, '%Y-%m') AS d,count(*) as c FROM `#@__archives` GROUP BY FROM_UNIXTIME(pubdate, '%Y-%m') order by d desc LIMIT ".$limit.",".$pagesize; $this->dsql->SetQuery($query); $this->dsql->Execute('al'); $artlist = ''; $dtp2 = new DedeTagParse(); $dtp2->SetNameSpace('field','[',']'); $dtp2->LoadSource($innertext); while($row = $this->dsql->GetArray('al')) { $row["phpurl"] = $GLOBALS["cfg_plus_dir"]; $row["templeturl"] = $GLOBALS["cfg_templets_dir"]; $row["arcurl"] = "".$row["d"].".html"; foreach($row as $k=>$v) { $row[$k] = htmlspecialchars($v); } if(is_array($dtp2->CTags)) { foreach($dtp2->CTags as $k=>$ctag) { if($ctag->GetName()=='array') { //传递整个数组,在runphp模式中有特殊作用 $dtp2->Assign($k,$row); } else { if(isset($row[$ctag->GetName()])) { $dtp2->Assign($k,$row[$ctag->GetName()]); } else { $dtp2->Assign($k,''); } } } } $artlist .= $dtp2->GetResult()."\r\n"; } $this->Next_page = $this->cur_page + 1; $this->dsql->FreeResult('al'); return $artlist; } function getcount(){ if($this->ac == 1){ $this->dsql->SetQuery("SELECT count(*) AS cc FROM `#@__archives` GROUP BY FROM_UNIXTIME(pubdate, '%Y-%m')"); $this->dsql->Execute(); $msgarr = array(); while($row = $this->dsql->GetArray()) { $msgarr[] = $row; } $maxMsg = count($msgarr); }else{ } return $maxMsg; } /** * 获得分页HTML * * @access public * @param string $innertext 底层模板 * @return string */ function GetPageListST($page = 5,$offset = 2){ if($this->ac == 1){ $this->url = "/index_guidang"; } $mpurl = $this->url; $curr_page = $this->cur_page; $perpage = $this->pagesize; $Suffix = ".html"; $num=$this->getcount();//总记录数 $multipage = ""; if ($num > $perpage){ $pages = ceil($num / $perpage); $from = $curr_page - $offset; $to = $curr_page + $page - $offset - 1; if ($page > $pages){ $from = 1; $to = $pages; }else{ if ($from < 1){ $to = $curr_page + 1-$from; $from = 1; if (($to - $from) < $page && ($to - $from) < $pages){ $to = $page; } }elseif ($to > $pages){ $from = $curr_page - $pages + $to; $to = $pages; if (($to - $from) < $page && ($to - $from) < $pages){ $from = $pages - $page + 1; } } } $multipage .= "<div id=\"dz_pages\">"; $multipage .= "<a class=\"p_total\"> 共 ".$num." 页 </a>\n"; $multipage .= "<a class=\"p_pages\"> ".$curr_page."/".$pages." </a>\n"; if ($curr_page - $offset > 1){ $multipage .= "<a class=\"p_redirect\" href=\"".$mpurl."1.html\" title='首页'>第一页</a>\n"; } if ($curr_page != 1){ $multipage .= "<a class=\"p_next\" href=\"".$mpurl.($curr_page-1).".html\" title='上一页'>上一页</a>\n"; } for ($i = $from; $i <= $to; $i++){ if ($i != $curr_page){ $multipage .= "<a class=\"p_num\" href=\"".$mpurl.$i.".html\" title='第".$i."页'>".$i."</a>\n"; }else{ $multipage .= "<a class=\"p_curpage\">".$i."</a>\n"; } } if ($curr_page != $pages){ $multipage .= "<a class=\"p_next\" href=\"".$mpurl.($curr_page+1).".html\" title='下一页'>下一页</a>\n"; } if ($curr_page + $offset < $pages){ $multipage .= "<a class=\"p_redirect\" href=\"".$mpurl."$pages.html\" title='尾页'>最后一页</a>\n"; } //使用跳转页的时候使用 //$multipage .= "<input class=\"p_input\" title=\"输入页数,按回车跳转\" name=\"pageGo\" id=\"pageGo\" onKeydown=\"if(event.keyCode == 13) {gotoPage(this.value);return false;}\">\n"; $multipage .= "<a class=\"p_total\">".$perpage."条/页</a>\n"; $multipage .= "</div>"; } if($this->ac == 1){ $multipage = str_replace("index1.html","index.html",$multipage); } return $multipage; } }//End Class