dokuwiki/feed.php

76 lines
2.0 KiB
PHP
Raw Permalink Normal View History

<?php
2022-01-27 00:07:01 +01:00
/**
* XML feed export
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
2012-06-24 14:59:43 +02:00
*
* @global array $conf
2012-06-24 15:17:38 +02:00
* @global Input $INPUT
*/
2024-01-30 09:44:03 +01:00
use dokuwiki\Feed\FeedCreator;
2024-01-26 15:24:41 +01:00
use dokuwiki\Feed\FeedCreatorOptions;
use dokuwiki\Cache\Cache;
use dokuwiki\ChangeLog\MediaChangeLog;
use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\Extension\AuthPlugin;
use dokuwiki\Extension\Event;
2023-08-30 14:48:22 +02:00
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
require_once(DOKU_INC . 'inc/init.php');
//close session
session_write_close();
2014-03-18 13:19:05 +01:00
//feed disabled?
2022-01-27 00:07:01 +01:00
if (!actionOK('rss')) {
2014-03-18 14:02:01 +01:00
http_status(404);
2014-03-18 13:19:05 +01:00
echo '<error>RSS feed is disabled.</error>';
exit;
}
2024-01-26 15:24:41 +01:00
$options = new FeedCreatorOptions();
// the feed is dynamic - we need a cache for each combo
// (but most people just use the default feed so it's still effective)
$key = implode('$', [
$options->getCacheKey(),
$INPUT->server->str('REMOTE_USER'),
$INPUT->server->str('HTTP_HOST'),
$INPUT->server->str('SERVER_PORT')
]);
$cache = new Cache($key, '.feed');
// prepare cache depends
$depends['files'] = getConfigFiles('main');
2023-08-31 00:55:36 +02:00
$depends['age'] = $conf['rss_update'];
2012-06-24 15:17:38 +02:00
$depends['purge'] = $INPUT->bool('purge');
// check cacheage and deliver if nothing has changed since last
// time or the update interval has not passed, also handles conditional requests
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Type: ' . $options->getMimeType());
header('X-Robots-Tag: noindex');
2022-01-27 00:07:01 +01:00
if ($cache->useCache($depends)) {
http_conditionalRequest($cache->getTime());
2022-01-27 00:07:01 +01:00
if ($conf['allowdebug']) header("X-CacheUsed: $cache->cache");
2023-08-31 22:00:27 +02:00
echo $cache->retrieveCache();
exit;
} else {
http_conditionalRequest(time());
2012-06-24 14:59:43 +02:00
}
// create new feed
try {
2024-01-30 09:44:03 +01:00
$feed = (new FeedCreator($options))->build();
$cache->storeCache($feed);
echo $feed;
} catch (Exception $e) {
http_status(500);
echo '<error>' . hsc($e->getMessage()) . '</error>';
exit;
}