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