r1036: Try using htmlspecialchars()
[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 (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 if (!can_perform('canviewbugs'))
37 {
38 $message->error_permission();
39 }
40
41 // ###################################################################
42 // get the syndicated items and prepare their content
43
44 $timestamp = (can_perform('canviewhidden', 0, fetch_guest_user()) ? 'lastposttime' : 'hiddenlastposttime');
45 $lastupdated = 0;
46 $buglist = array();
47 $bugs_fetch = $db->query("
48 SELECT bug.*, comment.comment_parsed
49 FROM " . TABLE_PREFIX . "bug
50 LEFT JOIN " . TABLE_PREFIX . "comment
51 ON (bug.initialreport = comment.commentid)
52 WHERE bug.product IN (" . fetch_on_bits('canviewbugs', fetch_guest_user()) . ")
53 AND (!bug.hidden OR (bug.hidden AND bug.product IN (" . fetch_on_bits('canviewhidden', fetch_guest_user()) . ")))
54 ORDER BY " . (can_perform('canviewhidden', 0, fetch_guest_user()) ? "bug.lastposttime" : "bug.hiddenlastposttime") . " DESC
55 LIMIT " . $bugsys->options['syndicateditems']
56 );
57 while ($bug = $db->fetch_array($bugs_fetch))
58 {
59 $bug['storytext'] = htmlspecialchars(sprintf(
60 $lang->string('<table cellspacing="0" cellpadding="3" border="0">
61 <tr>
62 <td><strong>Bug ID:</strong></td>
63 <td>%1$s</td>
64 </tr>
65 <tr>
66 <td><strong>Summary:</strong></td>
67 <td>%2$s</td>
68 </tr>
69 <tr>
70 <td><strong>Product/Component/Version:</strong></td>
71 <td>%3$s</td>
72 </tr>
73 <tr>
74 <td><strong>Status:</strong></td>
75 <td>%4$s</td>
76 </tr>
77 <tr>
78 <td><strong>Severity:</strong></td>
79 <td>%5$s</td>
80 </table>
81
82 <p>%6$s</p>'),
83 $bug['bugid'],
84 $bug['summary'],
85 $bugsys->datastore['product']["$bug[product]"]['title'] . '/' . (($bug['component']) ? $bugsys->datastore['product']["$bug[component]"]['title'] . '/' : '') . $bugsys->datastore['version']["$bug[version]"]['version'],
86 $bugsys->datastore['status']["$bug[status]"]['status'],
87 $bugsys->datastore['severity']["$bug[severity]"]['severity'],
88 $bug['comment_parsed']
89 ));
90 $buglist["$bug[bugid]"] = $bug;
91 $lastupdated = $bug["$timestamp"];
92 }
93
94 // ###################################################################
95 // ATOM
96
97 if (SYND_TYPE == 'atom')
98 {
99 header('Content-type: application/xml');
100
101 echo '<?xml version="1.0" encoding="utf-8"?>
102 <feed xmlns="http://www.w3.org/2005/Atom">
103
104 <title>' . sprintf($lang->string('%1$s Syndication Feed'), $bugsys->options['trackertitle']) . '</title>
105 <link href="' . $bugsys->options['trackerurl'] . '"/>
106 <updated>' . gmdate('Y-m-d\TH:i:s\Z', $lastupdated) . '</updated>
107
108 <!-- entries -->
109 ';
110
111 foreach ($buglist AS $bug)
112 {
113 echo '
114 <entry>
115 <id>' . $bugsys->options['trackertitle'] . '/showreport.php?bugid=' . $bug['bugid'] . '</id>
116 <title>' . $bug['summary'] . '</title>
117 <updated>' . gmdate('Y-m-d\TH:i:s\Z', $bug["$timestamp"]) . '</updated>
118 <author>
119 <name>' . $bug['username'] . '</name>
120 </author>
121 <content>' . $bug['storytext'] . '</content>
122 <link rel="alternate" href="' . $bugsys->options['trackerurl'] . '/showreport.php?bugid=' . $bug['bugid'] . '"/>
123 </entry>';
124 }
125
126 echo '
127 <!-- / entries -->
128
129 </feed>';
130
131 exit;
132 }
133
134 // ###################################################################
135 // RSS
136
137 else if (SYND_TYPE == 'rss')
138 {
139 // not going to be implemented in 1.1 because I don't want to clutter the templates with multiple feed icons and such...
140 }
141
142 /*=====================================================================*\
143 || ###################################################################
144 || # $HeadURL$
145 || # $Id$
146 || ###################################################################
147 \*=====================================================================*/
148 ?>