r876: Adding the Atom feed system
[bugdar.git] / syndicate.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 define('NO_TEMPLATES', 1);
23
24 require_once('./global.php');
25
26 if (in_array($bugsys->in['type'], array('rss', 'atom')))
27 {
28 define('SYND_TYPE', $bugsys->in['type']);
29 }
30
31 if (!defined('SYND_TYPE'))
32 {
33 define('SYND_TYPE', 'atom');
34 }
35
36 // ###################################################################
37 // get the syndicated items and prepare their content
38
39 $timestamp = (can_perform('canviewhidden', 0, fetch_guest_user()) ? 'lastposttime' : 'hiddenlastposttime');
40 $lastupdated = 0;
41 $buglist = array();
42 $bugs_fetch = $db->query("
43 SELECT * FROM " . TABLE_PREFIX . "bug
44 WHERE productid IN (" . fetch_on_bits('canviewbugs', fetch_guest_user()) . ")
45 AND (!hidden OR (hidden AND productid IN (" . fetch_on_bits('canviewhidden', fetch_guest_user()) . ")))
46 ORDER BY " . (can_perform('canviewhidden', 0, fetch_guest_user()) ? "lastposttime" : "hiddenlastposttime") . " DESC
47 LIMIT 10" // #*# let this be a setting
48 );
49 while ($bug = $db->fetch_array($bugs_fetch))
50 {
51 $bug['storytext'] = sprintf($lang->string('<div><strong>Bug ID:</strong> %1$s</div>
52 <div><strong>Summary:</strong> %2$s</div>
53 <div><strong>Product/Component/Version:</strong> %3$s</div>
54 <div><strong>Status:</strong> %4$s</div>
55 <div><strong>Severity:</strong> %5$s</div>'),
56 $bug['bugid'],
57 $bug['summary'],
58 $bugsys->datastore['product']["$bug[productid]"]['title'] . '/' . (($bug['componentid']) ? $bugsys->datastore['product']["$bug[componentid]"]['title'] . '/' : '') . $bugsys->datastore['version']["$bug[versionid]"]['version'],
59 $bugsys->datastore['status']["$bug[status]"]['status'],
60 $bugsys->datastore['severity']["$bug[severity]"]['severity']
61 );
62 $buglist["$bug[bugid]"] = $bug;
63 $lastupdated = $bug["$timestamp"];
64 }
65
66 // ###################################################################
67 // ATOM
68
69 if (SYND_TYPE == 'atom')
70 {
71 $feed = '<?xml version="1.0" encoding="utf-8"?>
72 <feed xmlns="http://www.w3.org/2005/Atom">
73
74 <title>' . sprintf($lang->string('%1$s Syndication Feed'), $bugsys->options['trackertitle']) . '</title>
75 <link href="' . $bugsys->options['trackerurl'] . '"/>
76 <updated>' . $datef->format('Y-m-d\TH:i:s\Z', $lastupdated) . '</updated>
77
78 <!-- entries -->
79 ';
80
81 foreach ($buglist AS $bug)
82 {
83 $feed .= '
84 <entry>
85 <id>' . $bugsys->options['trackertitle'] . '/showreport.php?bugid=' . $bug['bugid'] . '</id>
86 <title>' . $bug['summary'] . '</title>
87 <updated>' . $datef->format('Y-m-d\TH:i:s\Z', $bug["$timestamp"]) . '</updated>
88 <author>
89 <name>' . $bug['username'] . '</name>
90 </author>
91 <content>' . $bug['storytext'] . '</content>
92 <summary>
93 <!-- firstreport goes here -->
94 </summary>
95 <link rel="alternate" href="' . $bugsys->options['trackerurl'] . '/showreport.php?bugid=' . $bug['bugid'] . '"/>
96 </entry>';
97 }
98
99 $feed .= '
100 <!-- / entries -->
101
102 </feed>';
103
104 header('Content-type: application/xml');
105 echo $feed;
106
107 exit;
108 }
109
110 // ###################################################################
111 // RSS
112
113 else if (SYND_TYPE == 'rss')
114 {
115 // not going to be implemented in 1.1 because I don't want to clutter the templates with multiple feed icons and such...
116 }
117
118 /*=====================================================================*\
119 || ###################################################################
120 || # $HeadURL$
121 || # $Id$
122 || ###################################################################
123 \*=====================================================================*/
124 ?>