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