PageRenderTime 24ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/feed.php

https://github.com/VSEphpbb/phpbb
PHP | 256 lines | 160 code | 47 blank | 49 comment | 34 complexity | d21b30460de677c3b9ea3bfdab5f2c39 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. * Idea and original RSS Feed 2.0 MOD (Version 1.0.8/9) by leviatan21
  13. * Original MOD: http://www.phpbb.com/community/viewtopic.php?f=69&t=1214645
  14. * MOD Author Profile: http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=345763
  15. * MOD Author Homepage: http://www.mssti.com/phpbb3/
  16. *
  17. **/
  18. /**
  19. * @ignore
  20. **/
  21. define('IN_PHPBB', true);
  22. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  23. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  24. include($phpbb_root_path . 'common.' . $phpEx);
  25. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  26. if (!$config['feed_enable'])
  27. {
  28. trigger_error('NO_FEED_ENABLED');
  29. }
  30. // Start session
  31. $user->session_begin();
  32. if (!empty($config['feed_http_auth']) && request_var('auth', '') == 'http')
  33. {
  34. phpbb_http_login(array(
  35. 'auth_message' => 'Feed',
  36. 'viewonline' => request_var('viewonline', true),
  37. ));
  38. }
  39. $auth->acl($user->data);
  40. $user->setup('viewtopic');
  41. // Initial var setup
  42. $forum_id = request_var('f', 0);
  43. $topic_id = request_var('t', 0);
  44. $mode = request_var('mode', '');
  45. // We do not use a template, therefore we simply define the global template variables here
  46. $global_vars = $item_vars = array();
  47. $feed_updated_time = 0;
  48. // Generate params array for use in append_sid() to correctly link back to this page
  49. $params = false;
  50. if ($forum_id || $topic_id || $mode)
  51. {
  52. $params = array(
  53. 'f' => ($forum_id) ? $forum_id : NULL,
  54. 't' => ($topic_id) ? $topic_id : NULL,
  55. 'mode' => ($mode) ? $mode : NULL,
  56. );
  57. }
  58. // This boards URL
  59. $phpbb_feed_helper = $phpbb_container->get('feed.helper');
  60. $board_url = $phpbb_feed_helper->get_board_url();
  61. // Get correct feed object
  62. $phpbb_feed_factory = $phpbb_container->get('feed.factory');
  63. $feed = $phpbb_feed_factory->get_feed($mode, $forum_id, $topic_id);
  64. // No feed found
  65. if ($feed === false)
  66. {
  67. trigger_error('NO_FEED');
  68. }
  69. // Open Feed
  70. $feed->open();
  71. // Iterate through items
  72. while ($row = $feed->get_item())
  73. {
  74. /**
  75. * Event to modify the feed row
  76. *
  77. * @event core.feed_modify_feed_row
  78. * @var int forum_id Forum ID
  79. * @var string mode Feeds mode (forums|topics|topics_new|topics_active|news)
  80. * @var array row Array with feed data
  81. * @var int topic_id Topic ID
  82. *
  83. * @since 3.1.10-RC1
  84. */
  85. $vars = array('forum_id', 'mode', 'row', 'topic_id');
  86. extract($phpbb_dispatcher->trigger_event('core.feed_modify_feed_row', compact($vars)));
  87. // BBCode options to correctly disable urls, smilies, bbcode...
  88. if ($feed->get('options') === NULL)
  89. {
  90. // Allow all combinations
  91. $options = 7;
  92. if ($feed->get('enable_bbcode') !== NULL && $feed->get('enable_smilies') !== NULL && $feed->get('enable_magic_url') !== NULL)
  93. {
  94. $options = (($row[$feed->get('enable_bbcode')]) ? OPTION_FLAG_BBCODE : 0) + (($row[$feed->get('enable_smilies')]) ? OPTION_FLAG_SMILIES : 0) + (($row[$feed->get('enable_magic_url')]) ? OPTION_FLAG_LINKS : 0);
  95. }
  96. }
  97. else
  98. {
  99. $options = $row[$feed->get('options')];
  100. }
  101. $title = (isset($row[$feed->get('title')]) && $row[$feed->get('title')] !== '') ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : '');
  102. $published = ($feed->get('published') !== NULL) ? (int) $row[$feed->get('published')] : 0;
  103. $updated = ($feed->get('updated') !== NULL) ? (int) $row[$feed->get('updated')] : 0;
  104. $display_attachments = ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && isset($row['post_attachment']) && $row['post_attachment']) ? true : false;
  105. $item_row = array(
  106. 'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '',
  107. 'published' => ($published > 0) ? $phpbb_feed_helper->format_date($published) : '',
  108. 'updated' => ($updated > 0) ? $phpbb_feed_helper->format_date($updated) : '',
  109. 'link' => '',
  110. 'title' => censor_text($title),
  111. 'category' => ($config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '',
  112. 'category_name' => ($config['feed_item_statistics'] && isset($row['forum_name'])) ? $row['forum_name'] : '',
  113. 'description' => censor_text($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], ($display_attachments ? $feed->get_attachments($row['post_id']) : array()))),
  114. 'statistics' => '',
  115. );
  116. // Adjust items, fill link, etc.
  117. $feed->adjust_item($item_row, $row);
  118. $item_vars[] = $item_row;
  119. $feed_updated_time = max($feed_updated_time, $published, $updated);
  120. }
  121. // If we do not have any items at all, sending the current time is better than sending no time.
  122. if (!$feed_updated_time)
  123. {
  124. $feed_updated_time = time();
  125. }
  126. // Some default assignments
  127. // FEED_IMAGE is not used (atom)
  128. $global_vars = array_merge($global_vars, array(
  129. 'FEED_IMAGE' => '',
  130. 'SELF_LINK' => $phpbb_feed_helper->append_sid('feed.' . $phpEx, $params),
  131. 'FEED_LINK' => $board_url . '/index.' . $phpEx,
  132. 'FEED_TITLE' => $config['sitename'],
  133. 'FEED_SUBTITLE' => $config['site_desc'],
  134. 'FEED_UPDATED' => $phpbb_feed_helper->format_date($feed_updated_time),
  135. 'FEED_LANG' => $user->lang['USER_LANG'],
  136. 'FEED_AUTHOR' => $config['sitename'],
  137. ));
  138. $feed->close();
  139. // Output page
  140. // gzip_compression
  141. if ($config['gzip_compress'])
  142. {
  143. if (@extension_loaded('zlib') && !headers_sent())
  144. {
  145. ob_start('ob_gzhandler');
  146. }
  147. }
  148. // IF debug extra is enabled and admin want to "explain" the page we need to set other headers...
  149. if (defined('DEBUG') && request_var('explain', 0) && $auth->acl_get('a_'))
  150. {
  151. header('Content-type: text/html; charset=UTF-8');
  152. header('Cache-Control: private, no-cache="set-cookie"');
  153. header('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
  154. $mtime = explode(' ', microtime());
  155. $totaltime = $mtime[0] + $mtime[1] - $starttime;
  156. if (method_exists($db, 'sql_report'))
  157. {
  158. $db->sql_report('display');
  159. }
  160. garbage_collection();
  161. exit_handler();
  162. }
  163. header("Content-Type: application/atom+xml; charset=UTF-8");
  164. header("Last-Modified: " . gmdate('D, d M Y H:i:s', $feed_updated_time) . ' GMT');
  165. if (!empty($user->data['is_bot']))
  166. {
  167. // Let reverse proxies know we detected a bot.
  168. header('X-PHPBB-IS-BOT: yes');
  169. }
  170. echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  171. echo '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="' . $global_vars['FEED_LANG'] . '">' . "\n";
  172. echo '<link rel="self" type="application/atom+xml" href="' . $global_vars['SELF_LINK'] . '" />' . "\n\n";
  173. echo (!empty($global_vars['FEED_TITLE'])) ? '<title>' . $global_vars['FEED_TITLE'] . '</title>' . "\n" : '';
  174. echo (!empty($global_vars['FEED_SUBTITLE'])) ? '<subtitle>' . $global_vars['FEED_SUBTITLE'] . '</subtitle>' . "\n" : '';
  175. echo (!empty($global_vars['FEED_LINK'])) ? '<link href="' . $global_vars['FEED_LINK'] .'" />' . "\n" : '';
  176. echo '<updated>' . $global_vars['FEED_UPDATED'] . '</updated>' . "\n\n";
  177. echo '<author><name><![CDATA[' . $global_vars['FEED_AUTHOR'] . ']]></name></author>' . "\n";
  178. echo '<id>' . $global_vars['SELF_LINK'] . '</id>' . "\n";
  179. foreach ($item_vars as $row)
  180. {
  181. echo '<entry>' . "\n";
  182. if (!empty($row['author']))
  183. {
  184. echo '<author><name><![CDATA[' . $row['author'] . ']]></name></author>' . "\n";
  185. }
  186. echo '<updated>' . ((!empty($row['updated'])) ? $row['updated'] : $row['published']) . '</updated>' . "\n";
  187. if (!empty($row['published']))
  188. {
  189. echo '<published>' . $row['published'] . '</published>' . "\n";
  190. }
  191. echo '<id>' . $row['link'] . '</id>' . "\n";
  192. echo '<link href="' . $row['link'] . '"/>' . "\n";
  193. echo '<title type="html"><![CDATA[' . $row['title'] . ']]></title>' . "\n\n";
  194. if (!empty($row['category']) && isset($row['category_name']) && $row['category_name'] !== '')
  195. {
  196. echo '<category term="' . $row['category_name'] . '" scheme="' . $row['category'] . '" label="' . $row['category_name'] . '"/>' . "\n";
  197. }
  198. echo '<content type="html" xml:base="' . $row['link'] . '"><![CDATA[' . "\n";
  199. echo $row['description'];
  200. if (!empty($row['statistics']))
  201. {
  202. echo '<p>' . $user->lang['STATISTICS'] . ': ' . $row['statistics'] . '</p>';
  203. }
  204. echo '<hr />' . "\n" . ']]></content>' . "\n";
  205. echo '</entry>' . "\n";
  206. }
  207. echo '</feed>';
  208. garbage_collection();
  209. exit_handler();