forum_rss.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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: forum_rss.php 33056 2013-04-15 06:44:56Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. error_reporting(E_ALL ^ E_NOTICE);
  12. define('IN_DISCUZ', TRUE);
  13. define('DISCUZ_ROOT', '');
  14. loadcache('forums');
  15. if(!$_G['setting']['rssstatus']) {
  16. exit('RSS Disabled');
  17. }
  18. $ttl = $_G['setting']['rssttl'] ? $_G['setting']['rssttl']: 30;
  19. $num = 20;
  20. $_G['groupid'] = 7;
  21. $_G['uid'] = 0;
  22. $_G['username'] = $_G['member']['password'] = '';
  23. $rssfid = empty($_GET['fid']) ? 0 : intval($_GET['fid']);
  24. $forumname = '';
  25. if(empty($rssfid)) {
  26. foreach($_G['cache']['forums'] as $fid => $forum) {
  27. if(rssforumperm($forum)) {
  28. $fidarray[] = $fid;
  29. }
  30. }
  31. } else {
  32. $forum = isset($_G['cache']['forums'][$rssfid]) && $_G['cache']['forums'][$rssfid]['type'] != 'group' ? $_G['cache']['forums'][$rssfid] : array();
  33. if(!isset($_G['cache']['forums'][$rssfid])) {
  34. $forum = $_G['cache']['forums'][$rssfid] = array();
  35. $subforum = C::t('forum_forum')->fetch_info_by_fid($rssfid);
  36. if($subforum['type'] == 'sub') {
  37. $forum = $_G['cache']['forums'][$rssfid] = $subforum;
  38. }
  39. }
  40. if($forum && rssforumperm($forum)) {
  41. $fidarray = array($rssfid);
  42. $forumname = dhtmlspecialchars($_G['cache']['forums'][$rssfid]['name']);
  43. } else {
  44. exit('Specified forum not found');
  45. }
  46. }
  47. $frewriteflag = $trewriteflag = 0;
  48. $havedomain = implode('', $_G['setting']['domain']['app']);
  49. if(is_array($_G['setting']['rewritestatus']) && in_array('forum_forumdisplay', $_G['setting']['rewritestatus'])) {
  50. $frewriteflag = 1;
  51. }
  52. if(is_array($_G['setting']['rewritestatus']) && in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
  53. $trewriteflag = 1;
  54. }
  55. $charset = $_G['config']['output']['charset'];
  56. dheader("Content-type: application/xml");
  57. echo "<?xml version=\"1.0\" encoding=\"".$charset."\"?>\n".
  58. "<rss version=\"2.0\">\n".
  59. " <channel>\n".
  60. (count($fidarray) > 1 ?
  61. " <title>{$_G[setting][bbname]}</title>\n".
  62. " <link>{$_G[siteurl]}forum.php</link>\n".
  63. " <description>Latest $num threads of all forums</description>\n"
  64. :
  65. " <title>{$_G[setting][bbname]} - $forumname</title>\n".
  66. " <link>{$_G[siteurl]}".($frewriteflag ? rewriteoutput('forum_forumdisplay', 1, '', $rssfid) : "forum.php?mod=forumdisplay&amp;fid=$rssfid")."</link>\n".
  67. " <description>Latest $num threads of $forumname</description>\n"
  68. ).
  69. " <copyright>Copyright(C) {$_G[setting][bbname]}</copyright>\n".
  70. " <generator>Discuz! Board by Comsenz Inc.</generator>\n".
  71. " <lastBuildDate>".gmdate('r', TIMESTAMP)."</lastBuildDate>\n".
  72. " <ttl>$ttl</ttl>\n".
  73. " <image>\n".
  74. " <url>{$_G[siteurl]}static/image/common/logo_88_31.gif</url>\n".
  75. " <title>{$_G[setting][bbname]}</title>\n".
  76. " <link>{$_G[siteurl]}</link>\n".
  77. " </image>\n";
  78. if($fidarray) {
  79. $alldata = C::t('forum_rsscache')->fetch_all_by_fid($fidarray, $num);
  80. if($alldata) {
  81. foreach($alldata as $thread) {
  82. if(TIMESTAMP - $thread['lastupdate'] > $ttl * 60) {
  83. updatersscache($num);
  84. break;
  85. } else {
  86. list($thread['description'], $attachremote, $attachfile, $attachsize) = explode("\t", $thread['description']);
  87. if($attachfile) {
  88. if($attachremote) {
  89. $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attachfile;
  90. } else {
  91. $filename = (!strstr($_G['setting']['attachurl'], '://') ? $_G['siteurl'] : '').$_G['setting']['attachurl'].'forum/'.$attachfile;
  92. }
  93. }
  94. echo " <item>\n".
  95. " <title>".$thread['subject']."</title>\n".
  96. " <link>$_G[siteurl]".($trewriteflag ? rewriteoutput('forum_viewthread', 1, '', $thread['tid']) : "forum.php?mod=viewthread&amp;tid=$thread[tid]")."</link>\n".
  97. " <description><![CDATA[".dhtmlspecialchars($thread['description'])."]]></description>\n".
  98. " <category>".dhtmlspecialchars($thread['forum'])."</category>\n".
  99. " <author>".dhtmlspecialchars($thread['author'])."</author>\n".
  100. ($attachfile ? '<enclosure url="'.$filename.'" length="'.$attachsize.'" type="image/jpeg" />' : '').
  101. " <pubDate>".gmdate('r', $thread['dateline'])."</pubDate>\n".
  102. " </item>\n";
  103. }
  104. }
  105. } else {
  106. updatersscache($num);
  107. }
  108. }
  109. echo " </channel>\n".
  110. "</rss>";
  111. function updatersscache($num) {
  112. global $_G;
  113. $processname = 'forum_rss_cache';
  114. if(discuz_process::islocked($processname, 600)) {
  115. return false;
  116. }
  117. C::t('forum_rsscache')->truncate();
  118. require_once libfile('function/post');
  119. foreach($_G['cache']['forums'] as $fid => $forum) {
  120. if($forum['type'] != 'group') {
  121. $forum['name'] = addslashes($forum['name']);
  122. foreach(C::t('forum_thread')->fetch_all_by_fid_displayorder($fid, 0, null, null, 0, $num, 'tid') as $thread) {
  123. $thread['author'] = $thread['author'] != '' ? addslashes($thread['author']) : 'Anonymous';
  124. $thread['subject'] = addslashes($thread['subject']);
  125. $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($thread['tid']);
  126. $attachdata = '';
  127. $thread['message'] = $post['message'];
  128. $thread['status'] = $post['status'];
  129. $thread['description'] = $thread['readperm'] > 0 || $thread['price'] > 0 || $thread['status'] & 1 ? '' : addslashes(messagecutstr($thread['message'], 250 - strlen($attachdata)).$attachdata);
  130. C::t('forum_rsscache')->insert(array(
  131. 'lastupdate'=>$_G['timestamp'],
  132. 'fid'=>$fid,
  133. 'tid'=>$thread['tid'],
  134. 'dateline'=>$thread['dateline'],
  135. 'forum'=>$forum['name'],
  136. 'author'=>$thread['author'],
  137. 'subject'=>$thread['subject'],
  138. 'description'=>$thread['description']
  139. ), false, true);
  140. }
  141. }
  142. }
  143. discuz_process::unlock($processname);
  144. return true;
  145. }
  146. ?>