1. <?php if(!defined('DEDEINC')) exit("Request Error!");
    2. require_once(DEDEINC.'/dedetag.class.php');
    3. require_once(DEDEINC.'/typelink.class.php');
    4. require_once(DEDEINC.'/channelunit.func.php');
    5. require_once(DEDEINC.'/ftp.class.php');
    6. @set_time_limit(0);
    7. class RssView
    8. {
    9. var $dsql;
    10. var $TypeID;
    11. var $TypeLink;
    12. var $TypeFields;
    13. var $MaxRow;
    14. var $dtp;
    15. var $ftp;
    16. var $ac;
    17. var $remoteDir;
    18. var $Next_page;
    19. /**
    20. * php5构造函数
    21. *
    22. * @access public
    23. * @param int $typeid 栏目ID
    24. * @param int $max_row 最大显示行数
    25. * @return string
    26. */
    27. function __construct($ac,$maxMsg,$cur_page,$pagesize,$cur_date)
    28. {
    29. global $ftp;
    30. $this->dtp = new DedeTagParse();
    31. $this->dtp->refObj = $this;
    32. $this->cur_page = $cur_page;
    33. $templetfiles01 = $GLOBALS['cfg_basedir']."/control/templets/plus/guidang_list.htm";
    34. $templetfiles02 = $GLOBALS['cfg_basedir']."/control/templets/plus/guidang_index.htm";
    35. if($ac == 1){
    36. $this->dtp->LoadTemplate($templetfiles02);
    37. }elseif($ac == 2){
    38. $this->dtp->LoadTemplate($templetfiles01);
    39. }
    40. $this->remoteDir = '';
    41. $this->dsql = $GLOBALS['dsql'];
    42. $this->ftp = &$ftp;
    43. $this->pagesize = $pagesize;
    44. $this->ac = $ac;
    45. $thsi->maxMsg = $maxMsg;
    46. $this->cur_date = $cur_date;
    47. $this->ParseTemplet();
    48. }
    49. //php4构造函数
    50. function RssView($ac,$cur_date = null)
    51. {
    52. $this->__construct($ac,$cur_date = null);
    53. }
    54. //关闭相关资源
    55. function Close()
    56. {
    57. }
    58. /**
    59. * 显示列表
    60. *
    61. * @access public
    62. * @return void
    63. */
    64. function Display()
    65. {
    66. $this->dtp->Display();
    67. }
    68. /**
    69. * 开始创建列表
    70. *
    71. * @access public
    72. * @param string $isremote 是否远程
    73. * @return string
    74. */
    75. function MakeRss($isremote=0)
    76. {
    77. global $cfg_remote_site;
    78. $murl = "/".$this->cur_date.".html";
    79. $mfile = $GLOBALS['cfg_basedir'].$murl;
    80. $this->dtp->SaveTo($mfile);
    81. return $murl;
    82. }
    83. /**
    84. * 解析模板
    85. *
    86. * @access public
    87. * @return void
    88. */
    89. function ParseTemplet()
    90. {
    91. foreach($this->dtp->CTags as $tid => $ctag)
    92. {
    93. if($ctag->GetName()=="field")
    94. {
    95. $this->dtp->Assign($tid,$this->TypeFields[$ctag->GetAtt('name')]);
    96. }
    97. else if($ctag->GetName()=="fenyehtml")
    98. {
    99. $this->dtp->Assign($tid,
    100. $this->GetPageListST()
    101. );
    102. }
    103. else if($ctag->GetName()=="seotitle")
    104. {
    105. $this->dtp->Assign($tid,
    106. "第".$this->cur_page."页"
    107. );
    108. if($this->ac == 2){
    109. $this->dtp->Assign($tid,$this->cur_date);
    110. }
    111. }
    112. else if($ctag->GetName()=="datelist")
    113. {
    114. $this->dtp->Assign($tid,
    115. $this->GetArcList($ctag->GetInnerText())
    116. );
    117. }
    118. else if($ctag->GetName()=="dateitem")
    119. {
    120. $this->dtp->Assign($tid,
    121. $this->GetDateList($ctag->GetInnerText())
    122. );
    123. }
    124. }
    125. }
    126. /**
    127. * 获得下一页的页码
    128. *
    129. * @access public
    130. * @param string $innertext 底层模板
    131. * @return string
    132. */
    133. function NextPage(){
    134. return $this->Next_page;
    135. }
    136. function NextPageIndex(){
    137. return $this->Next_page;
    138. }
    139. /**
    140. * 创建索引
    141. *
    142. * @access public
    143. * @param string $innertext 底层模板
    144. * @return string
    145. */
    146. function MakeIndex(){
    147. global $cfg_remote_site;
    148. if($this->cur_page == 1){
    149. $murl = "/index_guidang.html";
    150. }else{
    151. $murl = "/index_guidang".$this->cur_page.".html";
    152. }
    153. $mfile = $GLOBALS['cfg_basedir'].$murl;
    154. $this->dtp->SaveTo($mfile);
    155. return $murl;
    156. }
    157. /**
    158. * 获得文档列表
    159. *
    160. * @access public
    161. * @param string $innertext 底层模板
    162. * @return string
    163. */
    164. function GetArcList($innertext="")
    165. {
    166. $innertext = trim($innertext);
    167. if($innertext=="")
    168. {
    169. $innertext = GetSysTemplets("guidang_list.htm");
    170. }
    171. $orwhere = " arc.arcrank > -1 and FROM_UNIXTIME(pubdate, '%Y-%m') = '".$this->cur_date."'";
    172. $ordersql=" ORDER BY arc.id desc";
    173. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,
    174. tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
    175. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
    176. WHERE $orwhere $ordersql";
    177. $this->dsql->SetQuery($query);
    178. $this->dsql->Execute('al');
    179. $artlist = '';
    180. $dtp2 = new DedeTagParse();
    181. $dtp2->SetNameSpace('field','[',']');
    182. $dtp2->LoadSource($innertext);
    183. while($row = $this->dsql->GetArray('al'))
    184. {
    185. //处理一些特殊字段
    186. if($row['litpic'] == '-' || $row['litpic'] == '')
    187. {
    188. $row['litpic'] = $GLOBALS['cfg_basehost'].'/images/defaultpic.gif';
    189. }
    190. if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
    191. {
    192. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
    193. }
    194. $row['picname'] = $row['litpic'];
    195. $row["arcurl"] = GetFileUrl($row["id"],$row["typeid"],$row["senddate"],$row["title"],
    196. $row["ismake"],$row["arcrank"],$row["namerule"],$row["typedir"],$row["money"],$row['filename'],$row["moresite"],$row["siteurl"],$row["sitepath"]);
    197. $row["typeurl"] = GetTypeUrl($row["typeid"],$row["typedir"],$row["isdefault"],$row["defaultname"],$row["ispart"],
    198. $row["namerule2"],$row["moresite"],$row["siteurl"],$row["sitepath"]);
    199. $row["info"] = $row["description"];
    200. $row["filename"] = $row["arcurl"];
    201. $row["stime"] = GetDateMK($row["pubdate"]);
    202. $row["image"] = "<img src='".$row["picname"]."' border='0'>";
    203. $row["fullurl"] = $GLOBALS["cfg_basehost"].$row["arcurl"];
    204. // 2011-6-20 启用多站点RSS输出存在的路径问题(by:织梦的鱼)
    205. if($GLOBALS['cfg_multi_site'] == 'Y') $row["fullurl"] = $row["arcurl"];
    206. $row["phpurl"] = $GLOBALS["cfg_plus_dir"];
    207. $row["templeturl"] = $GLOBALS["cfg_templets_dir"];
    208. if($row["source"]=='')
    209. {
    210. $row["source"] = $GLOBALS['cfg_webname'];
    211. }
    212. if($row["writer"]=='')
    213. {
    214. $row["writer"] = "秩名";
    215. }
    216. foreach($row as $k=>$v)
    217. {
    218. $row[$k] = htmlspecialchars($v);
    219. }
    220. if(is_array($dtp2->CTags))
    221. {
    222. foreach($dtp2->CTags as $k=>$ctag)
    223. {
    224. if($ctag->GetName()=='array')
    225. {
    226. //传递整个数组,在runphp模式中有特殊作用
    227. $dtp2->Assign($k,$row);
    228. }
    229. else
    230. {
    231. if(isset($row[$ctag->GetName()]))
    232. {
    233. $dtp2->Assign($k,$row[$ctag->GetName()]);
    234. }
    235. else
    236. {
    237. $dtp2->Assign($k,'');
    238. }
    239. }
    240. }
    241. }
    242. $artlist .= $dtp2->GetResult()."\r\n";
    243. }
    244. $this->Next_page = $this->cur_page + 1;
    245. $this->dsql->FreeResult('al');
    246. return $artlist;
    247. }
    248. /**
    249. * 获得日期索引文档列表
    250. *
    251. * @access public
    252. * @param string $innertext 底层模板
    253. * @return string
    254. */
    255. function GetDateList($innertext="")
    256. {
    257. $innertext = trim($innertext);
    258. if($innertext=="")
    259. {
    260. $innertext = GetSysTemplets("arc.htm");
    261. }
    262. $pagesize = $this->pagesize;
    263. $limit = $this->cur_page - 1;
    264. $limit = $limit*$pagesize;
    265. $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;
    266. $this->dsql->SetQuery($query);
    267. $this->dsql->Execute('al');
    268. $artlist = '';
    269. $dtp2 = new DedeTagParse();
    270. $dtp2->SetNameSpace('field','[',']');
    271. $dtp2->LoadSource($innertext);
    272. while($row = $this->dsql->GetArray('al'))
    273. {
    274. $row["phpurl"] = $GLOBALS["cfg_plus_dir"];
    275. $row["templeturl"] = $GLOBALS["cfg_templets_dir"];
    276. $row["arcurl"] = "".$row["d"].".html";
    277. foreach($row as $k=>$v)
    278. {
    279. $row[$k] = htmlspecialchars($v);
    280. }
    281. if(is_array($dtp2->CTags))
    282. {
    283. foreach($dtp2->CTags as $k=>$ctag)
    284. {
    285. if($ctag->GetName()=='array')
    286. {
    287. //传递整个数组,在runphp模式中有特殊作用
    288. $dtp2->Assign($k,$row);
    289. }
    290. else
    291. {
    292. if(isset($row[$ctag->GetName()]))
    293. {
    294. $dtp2->Assign($k,$row[$ctag->GetName()]);
    295. }
    296. else
    297. {
    298. $dtp2->Assign($k,'');
    299. }
    300. }
    301. }
    302. }
    303. $artlist .= $dtp2->GetResult()."\r\n";
    304. }
    305. $this->Next_page = $this->cur_page + 1;
    306. $this->dsql->FreeResult('al');
    307. return $artlist;
    308. }
    309. function getcount(){
    310. if($this->ac == 1){
    311. $this->dsql->SetQuery("SELECT count(*) AS cc FROM `#@__archives` GROUP BY FROM_UNIXTIME(pubdate, '%Y-%m')");
    312. $this->dsql->Execute();
    313. $msgarr = array();
    314. while($row = $this->dsql->GetArray())
    315. {
    316. $msgarr[] = $row;
    317. }
    318. $maxMsg = count($msgarr);
    319. }else{
    320. }
    321. return $maxMsg;
    322. }
    323. /**
    324. * 获得分页HTML
    325. *
    326. * @access public
    327. * @param string $innertext 底层模板
    328. * @return string
    329. */
    330. function GetPageListST($page = 5,$offset = 2){
    331. if($this->ac == 1){
    332. $this->url = "/index_guidang";
    333. }
    334. $mpurl = $this->url;
    335. $curr_page = $this->cur_page;
    336. $perpage = $this->pagesize;
    337. $Suffix = ".html";
    338. $num=$this->getcount();//总记录数
    339. $multipage = "";
    340. if ($num > $perpage){
    341. $pages = ceil($num / $perpage);
    342. $from = $curr_page - $offset;
    343. $to = $curr_page + $page - $offset - 1;
    344. if ($page > $pages){
    345. $from = 1;
    346. $to = $pages;
    347. }else{
    348. if ($from < 1){
    349. $to = $curr_page + 1-$from;
    350. $from = 1;
    351. if (($to - $from) < $page && ($to - $from) < $pages){
    352. $to = $page;
    353. }
    354. }elseif ($to > $pages){
    355. $from = $curr_page - $pages + $to;
    356. $to = $pages;
    357. if (($to - $from) < $page && ($to - $from) < $pages){
    358. $from = $pages - $page + 1;
    359. }
    360. }
    361. }
    362. $multipage .= "<div id=\"dz_pages\">";
    363. $multipage .= "<a class=\"p_total\"> 共 ".$num." 页 </a>\n";
    364. $multipage .= "<a class=\"p_pages\"> ".$curr_page."/".$pages." </a>\n";
    365. if ($curr_page - $offset > 1){
    366. $multipage .= "<a class=\"p_redirect\" href=\"".$mpurl."1.html\" title='首页'>第一页</a>\n";
    367. }
    368. if ($curr_page != 1){
    369. $multipage .= "<a class=\"p_next\" href=\"".$mpurl.($curr_page-1).".html\" title='上一页'>上一页</a>\n";
    370. }
    371. for ($i = $from; $i <= $to; $i++){
    372. if ($i != $curr_page){
    373. $multipage .= "<a class=\"p_num\" href=\"".$mpurl.$i.".html\" title='第".$i."页'>".$i."</a>\n";
    374. }else{
    375. $multipage .= "<a class=\"p_curpage\">".$i."</a>\n";
    376. }
    377. }
    378. if ($curr_page != $pages){
    379. $multipage .= "<a class=\"p_next\" href=\"".$mpurl.($curr_page+1).".html\" title='下一页'>下一页</a>\n";
    380. }
    381. if ($curr_page + $offset < $pages){
    382. $multipage .= "<a class=\"p_redirect\" href=\"".$mpurl."$pages.html\" title='尾页'>最后一页</a>\n";
    383. }
    384. //使用跳转页的时候使用
    385. //$multipage .= "<input class=\"p_input\" title=\"输入页数,按回车跳转\" name=\"pageGo\" id=\"pageGo\" onKeydown=\"if(event.keyCode == 13) {gotoPage(this.value);return false;}\">\n";
    386. $multipage .= "<a class=\"p_total\">".$perpage."条/页</a>\n";
    387. $multipage .= "</div>";
    388. }
    389. if($this->ac == 1){
    390. $multipage = str_replace("index1.html","index.html",$multipage);
    391. }
    392. return $multipage;
    393. }
    394. }//End Class