portal_rss.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: portal_rss.php 24992 2011-10-20 09:41:00Z liulanbo $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(!$_G['setting']['rssstatus']) {
  12. exit('RSS Disabled');
  13. }
  14. $ttl = $_G['setting']['rssttl'] ? $_G['setting']['rssttl']: 30;
  15. $num = 20;
  16. $_G['groupid'] = 7;
  17. $_G['uid'] = 0;
  18. $_G['username'] = $_G['member']['password'] = '';
  19. $rsscatid = empty($_GET['catid']) ? 0 : intval($_GET['catid']);
  20. $catname = '';
  21. if(empty($rsscatid)) {
  22. foreach($_G['cache']['portalcategory'] as $catid => $category) {
  23. $catarray[] = $catid;
  24. }
  25. } else {
  26. if(isset($_G['cache']['portalcategory'][$rsscatid])) {
  27. $catarray = array($rsscatid);
  28. $catname = dhtmlspecialchars($_G['cache']['portalcategory'][$rsscatid]['catname']);
  29. } else {
  30. exit('Specified article not found');
  31. }
  32. }
  33. $rewriteflag = 0;
  34. $havedomain = implode('', $_G['setting']['domain']['app']);
  35. if(is_array($_G['setting']['rewritestatus']) && in_array('portal_article', $_G['setting']['rewritestatus'])) {
  36. $rewriteflag = 1;
  37. }
  38. $charset = $_G['config']['output']['charset'];
  39. dheader("Content-type: application/xml");
  40. echo "<?xml version=\"1.0\" encoding=\"".$charset."\"?>\n".
  41. "<rss version=\"2.0\">\n".
  42. " <channel>\n".
  43. (count($catarray) > 1 ?
  44. " <title>{$_G[setting][bbname]}</title>\n".
  45. " <link>{$_G[siteurl]}forum.php</link>\n".
  46. " <description>Latest $num articles of all categories</description>\n"
  47. :
  48. " <title>{$_G[setting][bbname]} - $catname</title>\n".
  49. " <link>{$_G[siteurl]}portal.php?mod=list&amp;catid=$rsscatid</link>\n".
  50. " <description>Latest $num articles of $catname</description>\n"
  51. ).
  52. " <copyright>Copyright(C) {$_G[setting][bbname]}</copyright>\n".
  53. " <generator>Discuz! Board by Comsenz Inc.</generator>\n".
  54. " <lastBuildDate>".gmdate('r', TIMESTAMP)."</lastBuildDate>\n".
  55. " <ttl>$ttl</ttl>\n".
  56. " <image>\n".
  57. " <url>{$_G[siteurl]}static/image/common/logo_88_31.gif</url>\n".
  58. " <title>{$_G[setting][bbname]}</title>\n".
  59. " <link>{$_G[siteurl]}</link>\n".
  60. " </image>\n";
  61. if($catarray) {
  62. $alldata = C::t('portal_rsscache')->fetch_all_by_catid($catarray, $num);
  63. if($alldata) {
  64. foreach($alldata as $article) {
  65. if(TIMESTAMP - $article['lastupdate'] > $ttl * 60) {
  66. updatersscache($num);
  67. break;
  68. } else {
  69. list($article['description'], $attachremote, $attachfile, $attachsize) = explode("\t", $article['description']);
  70. if($attachfile) {
  71. if($attachremote) {
  72. $filename = $_G['setting']['ftp']['attachurl'].'portal/'.$attachfile;
  73. } else {
  74. $filename = $_G['siteurl'].$_G['setting']['attachurl'].'portal/'.$attachfile;
  75. }
  76. }
  77. echo " <item>\n".
  78. " <title>".$article['subject']."</title>\n".
  79. " <link>$_G[siteurl]".($rewriteflag ? rewriteoutput('portal_article', 1, '', $article[aid]) : "portal.php?mod=view&amp;aid=$article[aid]")."</link>\n".
  80. " <description><![CDATA[".dhtmlspecialchars($article['description'])."]]></description>\n".
  81. " <category>".dhtmlspecialchars($article['catname'])."</category>\n".
  82. " <author>".dhtmlspecialchars($article['author'])."</author>\n".
  83. ($attachfile ? '<enclosure url="'.$filename.'" length="'.$attachsize.'" type="image/jpeg" />'."\n" : '').
  84. " <pubDate>".gmdate('r', $article['dateline'])."</pubDate>\n".
  85. " </item>\n";
  86. }
  87. }
  88. } else {
  89. updatersscache($num);
  90. }
  91. }
  92. echo " </channel>\n".
  93. "</rss>";
  94. function updatersscache($num) {
  95. global $_G;
  96. $processname = 'portal_rss_cache';
  97. if(discuz_process::islocked($processname, 600)) {
  98. return false;
  99. }
  100. C::t('portal_rsscache')->truncate();
  101. require_once libfile('function/post');
  102. foreach($_G['cache']['portalcategory'] as $catid => $catarray) {
  103. $query = C::t('portal_article_title')->fetch_all_for_cat($catid, 0, 1, 0, $num);
  104. $catarray['catname'] = addslashes($catarray['catname']);
  105. foreach($query as $article) {
  106. $article['author'] = $article['author'] != '' ? addslashes($article['author']) : ($article['username'] ? addslashes($article['username']) : 'Anonymous');
  107. $article['title'] = addslashes($article['title']);
  108. $articleattach = C::t('portal_attachment')->fetch_by_aid_image($article['aid']);
  109. $attachdata = '';
  110. if(!empty($articleattach)) {
  111. $attachdata = "\t".$articleattach['remote']."\t".$articleattach['attachment']."\t".$articleattach['filesize'];
  112. }
  113. $article['description'] = addslashes(messagecutstr($article['summary'], 250 - strlen($attachdata)).$attachdata);
  114. C::t('portal_rsscache')->insert(array(
  115. 'lastupdate'=>$_G['timestamp'],
  116. 'catid'=>$catid,
  117. 'aid'=>$article['aid'],
  118. 'dateline'=>$article['dateline'],
  119. 'catname'=>$catarray['catname'],
  120. 'author'=>$article['author'],
  121. 'subject'=>$article['title'],
  122. 'description'=>$article['description']
  123. ));
  124. }
  125. }
  126. discuz_process::unlock($processname);
  127. return true;
  128. }
  129. ?>