3 * FusionForge RSS feed for Tasks abonnement
6 * Patrick Apel <p.apel@tarent.de>
7 * Thorsten Glaser <t.glaser@tarent.de>
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * RSS feed used in connection with the Tasks Abonnement feature.
28 require_once('../env.inc.php');
29 require_once $gfwww.'include/pre.php';
31 require_once $gfcommon.'include/Error.class.php';
33 require_once $gfcommon.'pm/ProjectTask.class.php';
34 require_once $gfcommon.'pm/ProjectGroup.class.php';
35 require_once $gfcommon.'include/Group.class.php';
36 require_once $gfcommon.'pm/ProjectTaskSqlQueries.php';
38 global $gfwww, $gfcommon;
40 $tid = getIntFromRequest('tid');
42 $tid = util_path_info_last_numeric_component();
44 header("HTTP/1.0 404 Not Found");
45 echo "You forgot to pass the tid.\n";
49 $tinfo = getGroupProjectIdGroupId($tid);
52 header("HTTP/1.0 404 Not Found");
53 echo "There is no task with id ".$tid."!\n";
57 $group_id = $tinfo['group_id'];
58 $group_project_id = $tinfo['group_project_id'];
59 $project_task_id = $tinfo['project_task_id'];
61 $objGroup =& group_get_object($group_id);
62 if (!$objGroup || !is_object($objGroup)) {
64 } elseif ($objGroup->isError()) {
65 exit_error('Error',$objGroup->getErrorMessage());
68 $objProjectGroup = &projectgroup_get_object($group_project_id);
69 if(!$objProjectGroup || !is_object($objProjectGroup)) {
70 exit_error('Error',_('No project group was found for this task.'));
73 $objProjectTask = &projecttask_get_object($project_task_id);
74 if(!$objProjectTask || !is_object($objProjectTask)) {
75 exit_error('Error',_('No project task was found.'));
78 $arrDbMessages = $objProjectTask->getMessages();
79 $arrDbHistory = $objProjectTask->getHistory();
81 $arrMessages = array();
82 $arrHistory = array();
84 while ($arr = db_fetch_array($arrDbMessages)) {
85 //realname|email|user_name|project_message_id|project_task_id|body|posted_by|postdate
86 $arr_ = array($arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], 'message', $arr[6], $arr[7]);
87 array_push($arrMessages, $arr_);
90 while ($arr = db_fetch_array($arrDbHistory)) {
91 //realname|email|user_name|project_history_id|project_task_id|field_name|>>old_value<<|mod_by|mod_date
92 $arr_ = array($arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], $arr[7], $arr[8]);
93 array_push($arrHistory, $arr_);
96 $arrHistoryMessages = array_merge($arrMessages, $arrHistory);
98 /* Bubblesort should be good enough as solution */
99 $j = count($arrHistoryMessages);
102 for($i=0; $i<$j; $i++){
103 for($k=0; $k<$l; $k++){
104 if($arrHistoryMessages[$i][8]<$arrHistoryMessages[$k][8]){
105 $tmp=$arrHistoryMessages[$k];
106 $arrHistoryMessages[$k]=$arrHistoryMessages[$i];
107 $arrHistoryMessages[$i]=$tmp;
112 $updates = array_reverse($arrHistoryMessages);
114 writeRssFeedBegin($objProjectTask, $objGroup, $objProjectGroup);
115 writeRssFeedItem($objProjectTask, $updates);
118 /* the rss feed may not be out of format! Otherwise the rss feed would not be shown correctly
119 * & has to be & because of utf-8 encondig
121 function writeRssFeedBegin($objProjectTask, $objGroup, $objProjectGroup) {
122 //UTF-8 encoded. A special sign like & for example needed to be written like &
123 /* It is possible to format a rss feed with cascading style sheet and xsl, but it does not work with
124 * Firefox version 3.6.6, so I did not make use of it. */
126 header('Content-Type: application/rss+xml; charset=utf-8');
128 print'<?xml version="1.0" encoding="utf-8"?>';
129 print'<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">';
130 print'<rss version="2.0">';
132 print '<link>' . util_make_url("/pm/t_follow.php/" . $objProjectTask->getID()) . '</link>';
134 print $objGroup->getPublicName().' '.' - ';
135 print $objProjectTask->getSummary();
137 print'<description>';
139 printf(_('Update history of the task with the name %1$s and the ID %2$d.') . ' ', $objProjectTask->getSummary(), $objProjectTask->getID());
140 print _('Current values of the task’s…').' => ';
142 print ' '._('Subproject:').' '.$objProjectGroup->getName().' |';
143 print ' '._('Summary:').' '.$objProjectTask->getSummary().' |';
144 print ' '._('Complete:').' '.$objProjectTask->getPercentComplete().'% |';
145 print ' '._('Status:').' '.$objProjectTask->getStatusName().' |';
146 print ' '._('Details:').' '.$objProjectTask->getDetails().' |';
148 print'</description>';
149 //print'<language>en-us</language>';
150 print'<copyright>'.'Copyright 2000-'.date('Y').' '.forge_get_config('forge_name').'</copyright>';
151 print'<webMaster>'.forge_get_config('admin_email').'</webMaster>';
152 print'<lastBuildDate>'.gmdate('D, d M Y G:i:s',time()). ' GMT'.'</lastBuildDate>';
153 print'<docs>http://blogs.law.harvard.edu/tech/rss</docs>';
157 /* Chronological order of updates as rss feed items */
158 function writeRssFeedItem($objProjectTask, $updates) {
160 foreach($updates as $update){
161 $update[6]==='message' ? $title = _('Comment') : $title = $update[5];
162 $update[6]==='message' ? $description = $update[5] : $description = $update[6];
163 $objGfUser = &user_get_object($update[7]);
168 print'<description>';
169 print _('Updated value').': ';
170 print $description.' | ';
171 print _('Posted by').': ';
172 print $objGfUser->getUnixName().' | ';
173 print _('Update time').': ';
174 print gmdate('D, d M Y G:i:s',$update[8]);
175 print'</description>';
176 print '<link>' . util_make_url("/pm/t_follow.php/" . $objProjectTask->getID()) . '</link>';
178 print $objGfUser->getEmail();
180 print '<guid isPermaLink="true">' . util_make_url("/export/rssAboTask.php?tid=" . $objProjectTask->getID()) . '</guid>';
182 print gmdate('D, d M Y G:i:s',$update[8]);
189 function writeRssFeedEnd() {