xref: /dokuwiki/feed.php (revision 867da04d85140736fab69e0df2be0abb55719386)
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;
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
36*867da04dSAndreas Gohr// we only cache the recent cache, but do so based on dynamic parameters
37*867da04dSAndreas Gohr// other modes are never cached and always created on the fly
38*867da04dSAndreas Gohr$cache = null;
39*867da04dSAndreas Gohr$cacheKey = $options->getCacheKey([
40fe9d054bSAndreas Gohr    $INPUT->server->str('REMOTE_USER'),
41fe9d054bSAndreas Gohr    $INPUT->server->str('HTTP_HOST'),
42*867da04dSAndreas Gohr    $INPUT->server->str('SERVER_PORT'),
43fe9d054bSAndreas Gohr]);
44*867da04dSAndreas Gohrif ($cacheKey !== null) {
45*867da04dSAndreas Gohr    $cache = new Cache($cacheKey, '.feed');
460d67055cSMichael Klier
470d67055cSMichael Klier    // prepare cache depends
480d67055cSMichael Klier    $depends['files'] = getConfigFiles('main');
490d67055cSMichael Klier    $depends['age'] = $conf['rss_update'];
508fbb9b14SAndreas Gohr    $depends['purge'] = $INPUT->bool('purge');
51*867da04dSAndreas Gohr}
52f3f0262cSandi
537131b668SAndreas Gohr// check cacheage and deliver if nothing has changed since last
54fbf82939SBen Coburn// time or the update interval has not passed, also handles conditional requests
55fbf82939SBen Coburnheader('Cache-Control: must-revalidate, post-check=0, pre-check=0');
56fbf82939SBen Coburnheader('Pragma: public');
577e23bd08SAndreas Gohrheader('Content-Type: ' . $options->getMimeType());
5850ddb617SAndreas Gohrheader('X-Robots-Tag: noindex');
59*867da04dSAndreas Gohrif ($cache?->useCache($depends)) {
60d2f1d7a1SMichael Große    http_conditionalRequest($cache->getTime());
610d67055cSMichael Klier    if ($conf['allowdebug']) header("X-CacheUsed: $cache->cache");
6226dfc232SAndreas Gohr    echo $cache->retrieveCache();
637131b668SAndreas Gohr    exit;
64fbf82939SBen Coburn} else {
65fbf82939SBen Coburn    http_conditionalRequest(time());
667131b668SAndreas Gohr}
677131b668SAndreas Gohr
687131b668SAndreas Gohr// create new feed
69fe9d054bSAndreas Gohrtry {
702abe2b13Ssplitbrain    $feed = (new FeedCreator($options))->build();
71*867da04dSAndreas Gohr    $cache?->storeCache($feed);
72fe9d054bSAndreas Gohr    echo $feed;
73fe9d054bSAndreas Gohr} catch (Exception $e) {
74fe9d054bSAndreas Gohr    http_status(500);
75fe9d054bSAndreas Gohr    echo '<error>' . hsc($e->getMessage()) . '</error>';
76b5a0be43SAdrian Lang    exit;
774bf3df7cSGina Haeussge}
78