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 $gfcommon.'include/pre.php';
30 require_once $gfcommon.'include/FFError.class.php';
31 require_once $gfcommon.'pm/ProjectTask.class.php';
32 require_once $gfcommon.'pm/ProjectGroup.class.php';
33 require_once $gfcommon.'include/Group.class.php';
34 require_once $gfcommon.'pm/ProjectTaskSqlQueries.php';
36 global $gfwww, $gfcommon;
38 $tid = getIntFromRequest('tid');
40 $tid = util_path_info_last_numeric_component();
42 header("HTTP/1.0 404 Not Found");
43 echo "You forgot to pass the tid.\n";
47 $tinfo = getGroupProjectIdGroupId($tid);
50 header("HTTP/1.0 404 Not Found");
51 echo "There is no task with id ".$tid."!\n";
55 $group_id = $tinfo['group_id'];
56 $group_project_id = $tinfo['group_project_id'];
57 $project_task_id = $tinfo['project_task_id'];
59 $objGroup = group_get_object($group_id);
60 if (!$objGroup || !is_object($objGroup)) {
62 } elseif ($objGroup->isError()) {
63 exit_error('Error',$objGroup->getErrorMessage());
66 $objProjectGroup = projectgroup_get_object($group_project_id);
67 if(!$objProjectGroup || !is_object($objProjectGroup)) {
68 exit_error('Error',_('No project group was found for this task.'));
71 $objProjectTask = projecttask_get_object($project_task_id);
72 if(!$objProjectTask || !is_object($objProjectTask)) {
73 exit_error('Error',_('No project task was found.'));
76 $arrDbMessages = $objProjectTask->getMessages();
77 $arrDbHistory = $objProjectTask->getHistory();
79 $arrMessages = array();
80 $arrHistory = array();
82 while ($arr = db_fetch_array($arrDbMessages)) {
83 //realname|email|user_name|project_message_id|project_task_id|body|posted_by|postdate
84 $arr_ = array($arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], 'message', $arr[6], $arr[7]);
85 array_push($arrMessages, $arr_);
88 while ($arr = db_fetch_array($arrDbHistory)) {
89 //realname|email|user_name|project_history_id|project_task_id|field_name|>>old_value<<|mod_by|mod_date
90 $arr_ = array($arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], $arr[7], $arr[8]);
91 array_push($arrHistory, $arr_);
94 $arrHistoryMessages = array_merge($arrMessages, $arrHistory);
96 /* Bubblesort should be good enough as solution */
97 $j = count($arrHistoryMessages);
100 for($i=0; $i<$j; $i++){
101 for($k=0; $k<$l; $k++){
102 if($arrHistoryMessages[$i][8]<$arrHistoryMessages[$k][8]){
103 $tmp=$arrHistoryMessages[$k];
104 $arrHistoryMessages[$k]=$arrHistoryMessages[$i];
105 $arrHistoryMessages[$i]=$tmp;
110 $updates = array_reverse($arrHistoryMessages);
112 writeRssFeedBegin($objProjectTask, $objGroup, $objProjectGroup);
113 writeRssFeedItem($objProjectTask, $updates);
116 /* the rss feed may not be out of format! Otherwise the rss feed would not be shown correctly
117 * & has to be & because of utf-8 encondig
119 function writeRssFeedBegin($objProjectTask, $objGroup, $objProjectGroup) {
120 //UTF-8 encoded. A special sign like & for example needed to be written like &
121 /* It is possible to format a rss feed with cascading style sheet and xsl, but it does not work with
122 * Firefox version 3.6.6, so I did not make use of it. */
124 header('Content-Type: application/rss+xml; charset=utf-8');
126 print'<?xml version="1.0" encoding="utf-8"?>';
127 print'<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">';
128 print'<rss version="2.0">';
130 print '<link>' . util_make_url("/pm/t_follow.php/" . $objProjectTask->getID()) . '</link>';
132 print $objGroup->getPublicName().' '.' - ';
133 print $objProjectTask->getSummary();
135 print'<description>';
137 printf(_('Update history of the task with the name %1$s and the ID %2$d.') . ' ', $objProjectTask->getSummary(), $objProjectTask->getID());
138 print _('Current values of the task’s…').' => ';
140 print ' '._('Subproject')._(': ').$objProjectGroup->getName().' |';
141 print ' '._('Summary')._(': ').$objProjectTask->getSummary().' |';
142 print ' '._('Complete')._(': ').$objProjectTask->getPercentComplete().'% |';
143 print ' '._('Status')._(': ').$objProjectTask->getStatusName().' |';
144 print ' '._('Details')._(': ').$objProjectTask->getDetails().' |';
146 print'</description>';
147 //print'<language>en-us</language>';
148 print'<copyright>'.'Copyright 2000-'.date('Y').' '.forge_get_config('forge_name').'</copyright>';
149 print'<webMaster>'.forge_get_config('admin_email').'</webMaster>';
150 print'<lastBuildDate>'.gmdate('D, d M Y G:i:s',time()). ' GMT'.'</lastBuildDate>';
151 print'<docs>http://blogs.law.harvard.edu/tech/rss</docs>';
155 /* Chronological order of updates as rss feed items */
156 function writeRssFeedItem($objProjectTask, $updates) {
158 foreach($updates as $update){
159 $update[6]==='message' ? $title = _('Comment') : $title = $update[5];
160 $update[6]==='message' ? $description = $update[5] : $description = $update[6];
161 $objGfUser = user_get_object($update[7]);
166 print'<description>';
167 print _('Updated value')._(': ');
168 print $description.' | ';
169 print _('Posted by')._(': ');
170 print $objGfUser->getUnixName().' | ';
171 print _('Update time')._(': ');
172 print gmdate('D, d M Y G:i:s',$update[8]);
173 print'</description>';
174 print '<link>' . util_make_url("/pm/t_follow.php/" . $objProjectTask->getID()) . '</link>';
176 print $objGfUser->getEmail();
178 print '<guid isPermaLink="true">' . util_make_url("/export/rssAboTask.php?tid=" . $objProjectTask->getID()) . '</guid>';
180 print gmdate('D, d M Y G:i:s',$update[8]);
187 function writeRssFeedEnd() {