1f3f0262cSandi<?php 2140bc872Sjpedryc 315fae107Sandi/** 415fae107Sandi * XML feed export 515fae107Sandi * 615fae107Sandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 8f9aa73bfSAndreas Gohr * 9f9aa73bfSAndreas Gohr * @global array $conf 108fbb9b14SAndreas Gohr * @global Input $INPUT 1115fae107Sandi */ 1215fae107Sandi 13*2abe2b13Ssplitbrainuse dokuwiki\Feed\FeedCreator; 1472c714a3Ssplitbrainuse dokuwiki\Feed\FeedCreatorOptions; 150db5771eSMichael Großeuse dokuwiki\Cache\Cache; 160c3a5702SAndreas Gohruse dokuwiki\ChangeLog\MediaChangeLog; 170c3a5702SAndreas Gohruse dokuwiki\ChangeLog\PageChangeLog; 18e1d9dcc8SAndreas Gohruse dokuwiki\Extension\AuthPlugin; 19e1d9dcc8SAndreas Gohruse dokuwiki\Extension\Event; 200c3a5702SAndreas Gohr 21b1f206e1SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/'); 22ed7b5f09Sandirequire_once(DOKU_INC . 'inc/init.php'); 23f3f0262cSandi 247131b668SAndreas Gohr//close session 258746e727Sandisession_write_close(); 268746e727Sandi 2754be1338SGerrit Uitslag//feed disabled? 2854be1338SGerrit Uitslagif (!actionOK('rss')) { 29b09b9f47SGerrit Uitslag http_status(404); 3054be1338SGerrit Uitslag echo '<error>RSS feed is disabled.</error>'; 3154be1338SGerrit Uitslag exit; 3254be1338SGerrit Uitslag} 3354be1338SGerrit Uitslag 3472c714a3Ssplitbrain$options = new FeedCreatorOptions(); 35f3f0262cSandi 367131b668SAndreas Gohr// the feed is dynamic - we need a cache for each combo 377131b668SAndreas Gohr// (but most people just use the default feed so it's still effective) 38fe9d054bSAndreas Gohr$key = implode('$', [ 39fe9d054bSAndreas Gohr $options->getCacheKey(), 40fe9d054bSAndreas Gohr $INPUT->server->str('REMOTE_USER'), 41fe9d054bSAndreas Gohr $INPUT->server->str('HTTP_HOST'), 42fe9d054bSAndreas Gohr $INPUT->server->str('SERVER_PORT') 43fe9d054bSAndreas Gohr]); 440db5771eSMichael Große$cache = new Cache($key, '.feed'); 450d67055cSMichael Klier 460d67055cSMichael Klier// prepare cache depends 470d67055cSMichael Klier$depends['files'] = getConfigFiles('main'); 480d67055cSMichael Klier$depends['age'] = $conf['rss_update']; 498fbb9b14SAndreas Gohr$depends['purge'] = $INPUT->bool('purge'); 50f3f0262cSandi 517131b668SAndreas Gohr// check cacheage and deliver if nothing has changed since last 52fbf82939SBen Coburn// time or the update interval has not passed, also handles conditional requests 53fbf82939SBen Coburnheader('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 54fbf82939SBen Coburnheader('Pragma: public'); 55fe9d054bSAndreas Gohrheader('Content-Type: ' . $options->get('mime_type')); 5650ddb617SAndreas Gohrheader('X-Robots-Tag: noindex'); 570d67055cSMichael Klierif ($cache->useCache($depends)) { 58d2f1d7a1SMichael Große http_conditionalRequest($cache->getTime()); 590d67055cSMichael Klier if ($conf['allowdebug']) header("X-CacheUsed: $cache->cache"); 6026dfc232SAndreas Gohr echo $cache->retrieveCache(); 617131b668SAndreas Gohr exit; 62fbf82939SBen Coburn} else { 63fbf82939SBen Coburn http_conditionalRequest(time()); 647131b668SAndreas Gohr} 657131b668SAndreas Gohr 667131b668SAndreas Gohr// create new feed 67fe9d054bSAndreas Gohrtry { 68*2abe2b13Ssplitbrain $feed = (new FeedCreator($options))->build(); 69fe9d054bSAndreas Gohr $cache->storeCache($feed); 70fe9d054bSAndreas Gohr echo $feed; 71fe9d054bSAndreas Gohr} catch (Exception $e) { 72fe9d054bSAndreas Gohr http_status(500); 73fe9d054bSAndreas Gohr echo '<error>' . hsc($e->getMessage()) . '</error>'; 74b5a0be43SAdrian Lang exit; 754bf3df7cSGina Haeussge} 76