xref: /dokuwiki/feed.php (revision 97896972a750e072c38bfdc2096a39d7da307194)
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
132abe2b13Ssplitbrainuse 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;
200cba610bSSatoshi Saharause dokuwiki\Search\FulltextSearch;
210c3a5702SAndreas Gohr
22b1f206e1SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
23ed7b5f09Sandirequire_once(DOKU_INC . 'inc/init.php');
24f3f0262cSandi
257131b668SAndreas Gohr//close session
268746e727Sandisession_write_close();
278746e727Sandi
2854be1338SGerrit Uitslag//feed disabled?
2954be1338SGerrit Uitslagif (!actionOK('rss')) {
30b09b9f47SGerrit Uitslag    http_status(404);
3154be1338SGerrit Uitslag    echo '<error>RSS feed is disabled.</error>';
3254be1338SGerrit Uitslag    exit;
3354be1338SGerrit Uitslag}
3454be1338SGerrit Uitslag
3572c714a3Ssplitbrain$options = new FeedCreatorOptions();
36f3f0262cSandi
37*867da04dSAndreas Gohr// we only cache the recent cache, but do so based on dynamic parameters
38*867da04dSAndreas Gohr// other modes are never cached and always created on the fly
39*867da04dSAndreas Gohr$cache = null;
40*867da04dSAndreas Gohr$cacheKey = $options->getCacheKey([
41fe9d054bSAndreas Gohr    $INPUT->server->str('REMOTE_USER'),
42fe9d054bSAndreas Gohr    $INPUT->server->str('HTTP_HOST'),
43*867da04dSAndreas Gohr    $INPUT->server->str('SERVER_PORT'),
44fe9d054bSAndreas Gohr]);
45*867da04dSAndreas Gohrif ($cacheKey !== null) {
46*867da04dSAndreas Gohr    $cache = new Cache($cacheKey, '.feed');
470d67055cSMichael Klier
480d67055cSMichael Klier    // prepare cache depends
490d67055cSMichael Klier    $depends['files'] = getConfigFiles('main');
500d67055cSMichael Klier    $depends['age'] = $conf['rss_update'];
518fbb9b14SAndreas Gohr    $depends['purge'] = $INPUT->bool('purge');
52*867da04dSAndreas Gohr}
53f3f0262cSandi
547131b668SAndreas Gohr// check cacheage and deliver if nothing has changed since last
55fbf82939SBen Coburn// time or the update interval has not passed, also handles conditional requests
56fbf82939SBen Coburnheader('Cache-Control: must-revalidate, post-check=0, pre-check=0');
57fbf82939SBen Coburnheader('Pragma: public');
587e23bd08SAndreas Gohrheader('Content-Type: ' . $options->getMimeType());
5950ddb617SAndreas Gohrheader('X-Robots-Tag: noindex');
60*867da04dSAndreas Gohrif ($cache?->useCache($depends)) {
61d2f1d7a1SMichael Große    http_conditionalRequest($cache->getTime());
620d67055cSMichael Klier    if ($conf['allowdebug']) header("X-CacheUsed: $cache->cache");
6326dfc232SAndreas Gohr    echo $cache->retrieveCache();
647131b668SAndreas Gohr    exit;
65fbf82939SBen Coburn} else {
66fbf82939SBen Coburn    http_conditionalRequest(time());
677131b668SAndreas Gohr}
687131b668SAndreas Gohr
697131b668SAndreas Gohr// create new feed
70fe9d054bSAndreas Gohrtry {
712abe2b13Ssplitbrain    $feed = (new FeedCreator($options))->build();
72*867da04dSAndreas Gohr    $cache?->storeCache($feed);
73fe9d054bSAndreas Gohr    echo $feed;
74fe9d054bSAndreas Gohr} catch (Exception $e) {
75fe9d054bSAndreas Gohr    http_status(500);
76fe9d054bSAndreas Gohr    echo '<error>' . hsc($e->getMessage()) . '</error>';
77b5a0be43SAdrian Lang    exit;
784bf3df7cSGina Haeussge}
79