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