1<?php
2# MantisBT - A PHP based bugtracking system
3
4# MantisBT is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 2 of the License, or
7# (at your option) any later version.
8#
9# MantisBT is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Generate News Feed RSS
19 *
20 * @package MantisBT
21 * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
22 * @copyright Copyright 2002  MantisBT Team - mantisbt-dev@lists.sourceforge.net
23 * @link http://www.mantisbt.org
24 *
25 * @uses core.php
26 * @uses access_api.php
27 * @uses config_api.php
28 * @uses constant_inc.php
29 * @uses gpc_api.php
30 * @uses lang_api.php
31 * @uses news_api.php
32 * @uses project_api.php
33 * @uses rss_api.php
34 * @uses string_api.php
35 * @uses user_api.php
36 * @uses utility_api.php
37 * @uses rssbuilder/class.RSSBuilder.inc.php
38 */
39
40require_once( 'core.php' );
41require_api( 'access_api.php' );
42require_api( 'config_api.php' );
43require_api( 'constant_inc.php' );
44require_api( 'gpc_api.php' );
45require_api( 'lang_api.php' );
46require_api( 'news_api.php' );
47require_api( 'project_api.php' );
48require_api( 'rss_api.php' );
49require_api( 'string_api.php' );
50require_api( 'user_api.php' );
51require_api( 'utility_api.php' );
52require_lib( 'rssbuilder' . DIRECTORY_SEPARATOR . 'class.RSSBuilder.inc.php' );
53
54$f_username = gpc_get_string( 'username', null );
55$f_key = gpc_get_string( 'key', null );
56$f_project_id = gpc_get_int( 'project_id', ALL_PROJECTS );
57
58news_ensure_enabled();
59
60# make sure RSS syndication is enabled.
61if( OFF == config_get( 'rss_enabled' ) ) {
62	access_denied();
63}
64
65# authenticate the user
66if( $f_username !== null ) {
67	if( !rss_login( $f_username, $f_key ) ) {
68		access_denied();
69	}
70} else {
71	if( !auth_anonymous_enabled() ) {
72		access_denied();
73	}
74}
75
76# Make sure that the current user has access to the selected project (if not ALL PROJECTS).
77if( $f_project_id != ALL_PROJECTS ) {
78	access_ensure_project_level( config_get( 'view_bug_threshold', null, null, $f_project_id ), $f_project_id );
79}
80
81# construct rss file
82
83$t_encoding = 'utf-8';
84$t_about = config_get_global( 'path' );
85$t_title = string_rss_links( config_get( 'window_title' ) . ' - ' . lang_get( 'news' ) );
86
87if( $f_username !== null ) {
88	$t_title .= ' - (' . $f_username . ')';
89}
90
91$t_description = $t_title;
92$t_image_link = config_get_global( 'path' ) . config_get_global( 'logo_image' );;
93
94# only rss 2.0
95$t_category = string_rss_links( project_get_name( $f_project_id ) );
96
97# in minutes (only rss 2.0)
98$t_cache = '60';
99
100$t_rssfile = new RSSBuilder( $t_encoding, $t_about, $t_title, $t_description,
101				$t_image_link, $t_category, $t_cache );
102
103# person, an organization, or a service
104$t_publisher = '';
105
106# person, an organization, or a service
107$t_creator = '';
108
109$t_date = (string)date( 'r' );
110$t_language = lang_get( 'phpmailer_language' );
111$t_rights = '';
112
113# spatial location , temporal period or jurisdiction
114$t_coverage = (string)'';
115
116# person, an organization, or a service
117$t_contributor = (string)'';
118
119$t_rssfile->addDCdata( $t_publisher, $t_creator, $t_date, $t_language, $t_rights, $t_coverage, $t_contributor );
120
121# hourly / daily / weekly / ...
122$t_period = (string)'daily';
123
124# every X hours/days/...
125$t_frequency = (int)1;
126
127$t_base = (string)date( 'Y-m-d\TH:i:sO' );
128
129# add missing : in the O part of the date.  @todo PHP 5 supports a 'c' format which will output the format
130# exactly as we want it.
131# 2002-10-02T10:00:00-0500 -> 2002-10-02T10:00:00-05:00
132$t_base = mb_substr( $t_base, 0, 22 ) . ':' . mb_substr( $t_base, -2 );
133
134$t_rssfile->addSYdata( $t_period, $t_frequency, $t_base );
135
136$t_news_rows = news_get_limited_rows( 0, $f_project_id );
137$t_news_count = count( $t_news_rows );
138
139# Loop through results
140for( $i = 0; $i < $t_news_count; $i++ ) {
141	$t_row = $t_news_rows[$i];
142	extract( $t_row, EXTR_PREFIX_ALL, 'v' );
143
144	# skip news item if private, or
145	# belongs to a private project (will only happen
146	if( VS_PRIVATE == $v_view_state ) {
147		continue;
148	}
149
150	$v_headline 	= string_rss_links( $v_headline );
151	$v_body 	= string_rss_links( $v_body );
152
153	$t_about = $t_link = config_get_global( 'path' ) . 'news_view_page.php?news_id=' . $v_id;
154	$t_title = $v_headline;
155	$t_description = $v_body;
156
157	# optional DC value
158	$t_subject = $t_title;
159
160	# optional DC value
161	$t_date = $v_date_posted;
162
163	# author of item
164	$t_author = '';
165	if( access_has_global_level( config_get( 'show_user_email_threshold' ) ) ) {
166		$t_author_name = string_rss_links( user_get_name( $v_poster_id ) );
167		$t_author_email = user_get_field( $v_poster_id, 'email' );
168
169		if( !is_blank( $t_author_email ) ) {
170			if( !is_blank( $t_author_name ) ) {
171				$t_author = $t_author_name . ' &lt;' . $t_author_email . '&gt;';
172			} else {
173				$t_author = $t_author_email;
174			}
175		}
176	}
177
178	# $comments = 'http://www.example.com/sometext.php?somevariable=somevalue&comments=1';	# url to comment page rss 2.0 value
179	$t_comments = '';
180
181	# optional mod_im value for dispaying a different pic for every item
182	$t_image = '';
183
184	$t_rssfile->addRSSItem( $t_about, $t_title, $t_link, $t_description, $t_subject, $t_date, $t_author, $t_comments, $t_image );
185}
186
187# @todo consider making this a configuration option - 0.91 / 1.0 / 2.0
188$t_version = '2.0';
189
190$t_rssfile->outputRSS( $t_version );
191