<?php
/**
 * @package tikiwiki
 */
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: tiki-forums_rss.php 66117 2018-04-19 19:10:07Z luciash $

require_once('tiki-setup.php');
$rsslib = TikiLib::lib('rss');

$access->check_feature('feature_forums');

if ($prefs['feed_forums'] != 'y') {
	$errmsg = tra("rss feed disabled");
	require_once('tiki-rss_error.php');
}

$res = $access->authorize_rss(['tiki_p_admin_forum','tiki_p_forum_read']);
if ($res) {
	if ($res['header'] == 'y') {
		header('WWW-Authenticate: Basic realm="' . $tikidomain . '"');
		header('HTTP/1.0 401 Unauthorized');
	}
	$errmsg = $res['msg'];
	require_once('tiki-rss_error.php');
}

$feed = "forums";
$uniqueid = $feed;
$output = $rsslib->get_from_cache($uniqueid);

if ($output["data"] == "EMPTY") {
	$title = $prefs['feed_forums_title'];
	$desc = $prefs['feed_forums_desc'];
	$id = 'object';
	$param = "threadId";
	$descId = "data";
	$dateId = "commentDate";
	$authorId = "userName";
	$titleId = "title";
	$readrepl = 'tiki-view_forum_thread.php?forumId=%s&comments_parentId=%s';

	$changes = $tikilib ->list_recent_forum_topics($prefs['feed_forums_max']);
	$output = $rsslib->generate_feed($feed, $uniqueid, '', $changes, $readrepl, $param, $id, $title, $titleId, $desc, $descId, $dateId, $authorId);
}
header("Content-type: " . $output["content-type"]);
print $output["data"];
