You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

76 lines
2.0 KiB

  1. <?php
  2. /**
  3. * XML feed export
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Andreas Gohr <andi@splitbrain.org>
  7. *
  8. * @global array $conf
  9. * @global Input $INPUT
  10. */
  11. use dokuwiki\Feed\FeedCreator;
  12. use dokuwiki\Feed\FeedCreatorOptions;
  13. use dokuwiki\Cache\Cache;
  14. use dokuwiki\ChangeLog\MediaChangeLog;
  15. use dokuwiki\ChangeLog\PageChangeLog;
  16. use dokuwiki\Extension\AuthPlugin;
  17. use dokuwiki\Extension\Event;
  18. if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
  19. require_once(DOKU_INC . 'inc/init.php');
  20. //close session
  21. session_write_close();
  22. //feed disabled?
  23. if (!actionOK('rss')) {
  24. http_status(404);
  25. echo '<error>RSS feed is disabled.</error>';
  26. exit;
  27. }
  28. $options = new FeedCreatorOptions();
  29. // the feed is dynamic - we need a cache for each combo
  30. // (but most people just use the default feed so it's still effective)
  31. $key = implode('$', [
  32. $options->getCacheKey(),
  33. $INPUT->server->str('REMOTE_USER'),
  34. $INPUT->server->str('HTTP_HOST'),
  35. $INPUT->server->str('SERVER_PORT')
  36. ]);
  37. $cache = new Cache($key, '.feed');
  38. // prepare cache depends
  39. $depends['files'] = getConfigFiles('main');
  40. $depends['age'] = $conf['rss_update'];
  41. $depends['purge'] = $INPUT->bool('purge');
  42. // check cacheage and deliver if nothing has changed since last
  43. // time or the update interval has not passed, also handles conditional requests
  44. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  45. header('Pragma: public');
  46. header('Content-Type: ' . $options->getMimeType());
  47. header('X-Robots-Tag: noindex');
  48. if ($cache->useCache($depends)) {
  49. http_conditionalRequest($cache->getTime());
  50. if ($conf['allowdebug']) header("X-CacheUsed: $cache->cache");
  51. echo $cache->retrieveCache();
  52. exit;
  53. } else {
  54. http_conditionalRequest(time());
  55. }
  56. // create new feed
  57. try {
  58. $feed = (new FeedCreator($options))->build();
  59. $cache->storeCache($feed);
  60. echo $feed;
  61. } catch (Exception $e) {
  62. http_status(500);
  63. echo '<error>' . hsc($e->getMessage()) . '</error>';
  64. exit;
  65. }