introduce a template function to output a inline script
[dokuwiki.git] / feed.php
blobe6fefbca7f985b88ac41678b617264f2e7b968e9
1 <?php
3 /**
4 * XML feed export
6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author Andreas Gohr <andi@splitbrain.org>
9 * @global array $conf
10 * @global Input $INPUT
13 use dokuwiki\Feed\FeedCreator;
14 use dokuwiki\Feed\FeedCreatorOptions;
15 use dokuwiki\Cache\Cache;
16 use dokuwiki\ChangeLog\MediaChangeLog;
17 use dokuwiki\ChangeLog\PageChangeLog;
18 use dokuwiki\Extension\AuthPlugin;
19 use dokuwiki\Extension\Event;
21 if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
22 require_once(DOKU_INC . 'inc/init.php');
24 //close session
25 session_write_close();
27 //feed disabled?
28 if (!actionOK('rss')) {
29 http_status(404);
30 echo '<error>RSS feed is disabled.</error>';
31 exit;
34 $options = new FeedCreatorOptions();
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');
46 // prepare cache depends
47 $depends['files'] = getConfigFiles('main');
48 $depends['age'] = $conf['rss_update'];
49 $depends['purge'] = $INPUT->bool('purge');
51 // check cacheage and deliver if nothing has changed since last
52 // time or the update interval has not passed, also handles conditional requests
53 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
54 header('Pragma: public');
55 header('Content-Type: ' . $options->getMimeType());
56 header('X-Robots-Tag: noindex');
57 if ($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());
66 // create new feed
67 try {
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;