r1143: Remove the whole second-type syndication stuff; we're Atom-only and RSS2 sound...
[bugdar.git] / syndicate.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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 (!can_perform('canviewbugs'))
27 {
28 $message->error_permission();
29 }
30
31 // ###################################################################
32 // get the syndicated items and prepare their content
33
34 $timestamp = (can_perform('canviewhidden', 0, fetch_guest_user()) ? 'lastposttime' : 'hiddenlastposttime');
35 $lastupdated = 0;
36 $buglist = array();
37 $bugs_fetch = $db->query("
38 SELECT bug.*, comment.comment_parsed
39 FROM " . TABLE_PREFIX . "bug
40 LEFT JOIN " . TABLE_PREFIX . "comment
41 ON (bug.initialreport = comment.commentid)
42 WHERE bug.product IN (" . fetch_on_bits('canviewbugs', fetch_guest_user()) . ")
43 AND (!bug.hidden OR (bug.hidden AND bug.product IN (" . fetch_on_bits('canviewhidden', fetch_guest_user()) . ")))
44 ORDER BY " . (can_perform('canviewhidden', 0, fetch_guest_user()) ? "bug.lastposttime" : "bug.hiddenlastposttime") . " DESC
45 LIMIT " . $bugsys->options['syndicateditems']
46 );
47 while ($bug = $db->fetch_array($bugs_fetch))
48 {
49 $bug['storytext'] = htmlspecialchars(sprintf(
50 _('<table cellspacing="0" cellpadding="3" border="0">
51 <tr>
52 <td><strong>Bug ID:</strong></td>
53 <td>%1$s</td>
54 </tr>
55 <tr>
56 <td><strong>Summary:</strong></td>
57 <td>%2$s</td>
58 </tr>
59 <tr>
60 <td><strong>Product/Component/Version:</strong></td>
61 <td>%3$s</td>
62 </tr>
63 <tr>
64 <td><strong>Status:</strong></td>
65 <td>%4$s</td>
66 </tr>
67 <tr>
68 <td><strong>Severity:</strong></td>
69 <td>%5$s</td>
70 </table>
71
72 <p>%6$s</p>'),
73 $bug['bugid'],
74 $bug['summary'],
75 $bugsys->datastore['product']["$bug[product]"]['title'] . '/' . (($bug['component']) ? $bugsys->datastore['product']["$bug[component]"]['title'] . '/' : '') . $bugsys->datastore['version']["$bug[version]"]['version'],
76 $bugsys->datastore['status']["$bug[status]"]['status'],
77 $bugsys->datastore['severity']["$bug[severity]"]['severity'],
78 $bug['comment_parsed']
79 ));
80 $buglist["$bug[bugid]"] = $bug;
81 $lastupdated = $bug["$timestamp"];
82 }
83
84 // ###################################################################
85 // generate the actual feed
86
87 header('Content-type: application/xml');
88
89 echo '<?xml version="1.0" encoding="utf-8"?>
90 <feed xmlns="http://www.w3.org/2005/Atom">
91
92 <title>' . sprintf(_('%1$s Syndication Feed'), $bugsys->options['trackertitle']) . '</title>
93 <link href="' . $bugsys->options['trackerurl'] . '"/>
94 <updated>' . gmdate('Y-m-d\TH:i:s\Z', $lastupdated) . '</updated>
95
96 <!-- entries -->
97 ';
98
99 foreach ($buglist AS $bug)
100 {
101 echo '
102 <entry>
103 <id>' . $bugsys->options['trackertitle'] . '/showreport.php?bugid=' . $bug['bugid'] . '</id>
104 <title>' . $bug['summary'] . '</title>
105 <updated>' . gmdate('Y-m-d\TH:i:s\Z', $bug["$timestamp"]) . '</updated>
106 <author>
107 <name>' . $bug['username'] . '</name>
108 </author>
109 <content type="html">' . $bug['storytext'] . '</content>
110 <summary type="text">' . htmlspecialchars($bug['comment_parsed']) . '</summary>
111 <link rel="alternate" href="' . $bugsys->options['trackerurl'] . '/showreport.php?bugid=' . $bug['bugid'] . '"/>
112 </entry>';
113 }
114
115 echo '
116 <!-- / entries -->
117
118 </feed>';
119
120 /*=====================================================================*\
121 || ###################################################################
122 || # $HeadURL$
123 || # $Id$
124 || ###################################################################
125 \*=====================================================================*/
126 ?>