1<?php
2/**
3 * EGroupware - Webpage news admin
4 *
5 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
6 * @package news_admin
7 * @link http://www.egroupware.org
8 * @maintainer Cornelius Weiss <nelius@cwtech.de>
9 * @version $Id$
10 */
11
12use EGroupware\Api;
13
14/**
15 * Check if we allow anon access and with which creditials
16 *
17 * @param array &$anon_account anon account_info with keys 'login', 'passwd' and optional 'passwd_type'
18 * @return boolean true if we allow anon access, false otherwise
19 */
20function registration_check_anon_access(&$anon_account)	{
21	// quick hack for std installations to reach news stand alone
22	// via egroupware/news_admin/website/export.php
23	$anon_account = array(
24		'login'  => 'anonymous',
25		'passwd' => 'anonymous',
26		'passwd_type' => 'text',
27	);
28	return true;
29}
30
31// check if we are loaded via sitemgr's news_module
32if (!(isset($GLOBALS['egw_info']) && isset($GLOBALS['egw_info']['flags']) && isset($GLOBALS['egw_info']['flags']['currentapp']) && $GLOBALS['egw_info']['flags']['currentapp'] == 'sitemgr-link')) {
33	$GLOBALS['egw_info']['flags'] = array(
34		'noheader'  => True,
35		'nonavbar' => True,
36		'currentapp' => 'sitemgr-link',
37		'autocreate_session_callback' => 'registration_check_anon_access',
38	);
39	include('../../header.inc.php');
40}
41
42$news_obj = new news_admin_bo();
43$export_obj = CreateObject('news_admin.soexport');
44$tpl = new Api\Framework\Template();
45
46$cat_id = (int)$_GET['cat_id'];
47$limit	= (isset($_GET['limit']) ? trim($_GET['limit']) : 10);
48$reqFormat = (isset($_GET['format']) ? strtolower(trim($_GET['format'])) : null);
49
50$filter = $cat_id > 0 ? array('cat_id' => $cat_id) : false;
51$news = $news_obj->search('',false,'news_date DESC','','',false,'AND',array(0,$limit),$filter);
52
53if (empty($news)) {
54	die('
55		There are no news, sorry! Either this system is missconfigured,
56		you are trying something nasty, or there are really no news.
57
58		Ask the webmaster to make shure, the access permissions in the
59		news_admin application are set in a way website visitors can access news.
60	');
61}
62$formats = array(
63	1 => 'rss091',
64	2 => 'rss1',
65	3 => 'rss2'
66);
67
68$itemsyntaxs = array(
69	0 => '?item=',
70	1 => '&amp;item=',
71	2 => '?news%5Bitem%5D=',
72	3 => '&amp;news%5Bitem%5D='
73);
74
75$feedConf = $export_obj->readconfig($cat_id);
76
77$format = $reqFormat ? $reqFormat : (
78	$formats[$feedConf['type']] ? $formats[$feedConf['type']] : (
79	'rss2' ));
80
81$feedConf['title'] = $feedConf['title'] ? $feedConf['title'] : (
82	$sitemgr_info['site_name'] ? $sitemgr_info['site_name'] : (
83	$GLOBALS['egw_info']['server']['site_title'] ? $GLOBALS['egw_info']['server']['site_title'] :
84	lang('News')));
85
86$feedConf['link'] = $feedConf['link'] ? $feedConf['link'] :
87	( $GLOBALS['sitemgr_info']['site_url'] ? ( stripos($GLOBALS['sitemgr_info']['site_url'],'http') !== false ? $GLOBALS['sitemgr_info']['site_url'] : (
88		( stripos($_SERVER['SERVER_PROTOCOL'],'https') !== false ? 'https' : 'http'). '://'. $_SERVER['HTTP_HOST']. $GLOBALS['sitemgr_info']['site_url'] )) :
89	'' /* add link to news_admin here... maybe we could add an item support in export.php? */ );
90
91if ( !$feedConf['description'] ) {
92	if ( $cat_id > 0 ) {
93		$cat = Api\Categories::read($cat_id);
94		$feedConf['description'] = $cat['description'];
95	} else {
96		$feedConf['description'] = $feedConf['title'];
97	}
98}
99// keep already set itemsyntax from included news_admin module
100if ($feedConf && isset($itemsyntaxs[$feedConf['itemsyntax']]) || $_REQUEST['itemsyntax']==$itemsyntax)	// gard against register_globals=On
101{
102	$itemsyntax = $itemsyntaxs[$feedConf['itemsyntax']];
103}
104$tpl->root = EGW_SERVER_ROOT. '/news_admin/website/templates/';
105$tpl->set_file(array('news' => $format . '.tpl'));
106$tpl->set_block('news', 'item', 'items');
107if($format == 'rss1') {
108	$tpl->set_block('news', 'seq', 'seqs');
109}
110
111$tpl->set_var('encoding', Api\Translation::charset());
112$tpl->set_var($feedConf);
113
114
115if(is_array($news))	{
116	foreach($news as $news_data) {
117		$tpl->set_var('content',$news_data['news_content']);
118		$tpl->set_var('subject',$news_data['news_headline']);
119		$tpl->set_var('teaser',$format == 'rss2' && $news_data['news_content'] ? '<p><b>'.$news_data['news_teaser']."</b></p>\n" :
120			$news_data['news_content']);
121
122		$tpl->set_var('item_link',htmlspecialchars($news_data['link'] ? $news_data['link'] : $feedConf['link'] . $itemsyntax . $news_data['news_id']));
123		$tpl->set_var('pub_date', date("r",$news_data['news_date']));
124		if($format == 'rss1')
125		{
126			$tpl->parse('seqs','seq',True);
127		}
128
129		$tpl->parse('items','item',True);
130	}
131}
132else {
133	$tpl->set_var('items', '');
134}
135
136header('Content-type: text/xml; charset='.Api\Translation::charset());
137$tpl->pparse('out','news');
138