r876: Adding the Atom feed system
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 29 Jun 2006 03:28:28 +0000 (03:28 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 29 Jun 2006 03:28:28 +0000 (03:28 +0000)
syndicate.php [new file with mode: 0644]

diff --git a/syndicate.php b/syndicate.php
new file mode 100644 (file)
index 0000000..13695fb
--- /dev/null
@@ -0,0 +1,124 @@
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # Bugdar [#]version[#]
+|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+define('NO_TEMPLATES', 1);
+
+require_once('./global.php');
+
+if (in_array($bugsys->in['type'], array('rss', 'atom')))
+{
+       define('SYND_TYPE', $bugsys->in['type']);
+}
+
+if (!defined('SYND_TYPE'))
+{
+       define('SYND_TYPE', 'atom');
+}
+
+// ###################################################################
+// get the syndicated items and prepare their content
+
+$timestamp = (can_perform('canviewhidden', 0, fetch_guest_user()) ? 'lastposttime' : 'hiddenlastposttime');
+$lastupdated = 0;
+$buglist = array();
+$bugs_fetch = $db->query("
+       SELECT * FROM " . TABLE_PREFIX . "bug
+       WHERE productid IN (" . fetch_on_bits('canviewbugs', fetch_guest_user()) . ")
+               AND (!hidden OR (hidden AND productid IN (" . fetch_on_bits('canviewhidden', fetch_guest_user()) . ")))
+       ORDER BY " . (can_perform('canviewhidden', 0, fetch_guest_user()) ? "lastposttime" : "hiddenlastposttime") . " DESC
+       LIMIT 10" // #*# let this be a setting
+);
+while ($bug = $db->fetch_array($bugs_fetch))
+{
+       $bug['storytext'] = sprintf($lang->string('<div><strong>Bug ID:</strong> %1$s</div>
+<div><strong>Summary:</strong> %2$s</div>
+<div><strong>Product/Component/Version:</strong> %3$s</div>
+<div><strong>Status:</strong> %4$s</div>
+<div><strong>Severity:</strong> %5$s</div>'),
+               $bug['bugid'],
+               $bug['summary'],
+               $bugsys->datastore['product']["$bug[productid]"]['title'] . '/' . (($bug['componentid']) ? $bugsys->datastore['product']["$bug[componentid]"]['title'] . '/' : '') . $bugsys->datastore['version']["$bug[versionid]"]['version'],
+               $bugsys->datastore['status']["$bug[status]"]['status'],
+               $bugsys->datastore['severity']["$bug[severity]"]['severity']
+       );
+       $buglist["$bug[bugid]"] = $bug;
+       $lastupdated = $bug["$timestamp"];
+}
+
+// ###################################################################
+// ATOM
+
+if (SYND_TYPE == 'atom')
+{
+       $feed = '<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+       <title>' . sprintf($lang->string('%1$s Syndication Feed'), $bugsys->options['trackertitle']) . '</title>
+       <link href="' . $bugsys->options['trackerurl'] . '"/>
+       <updated>' . $datef->format('Y-m-d\TH:i:s\Z', $lastupdated) . '</updated>
+       
+       <!-- entries -->
+       ';
+       
+       foreach ($buglist AS $bug)
+       {
+               $feed .= '
+       <entry>
+               <id>' . $bugsys->options['trackertitle'] . '/showreport.php?bugid=' . $bug['bugid'] . '</id>
+               <title>' . $bug['summary'] . '</title>
+               <updated>' . $datef->format('Y-m-d\TH:i:s\Z', $bug["$timestamp"]) . '</updated>
+               <author>
+                       <name>' . $bug['username'] . '</name>
+               </author>
+               <content>' . $bug['storytext'] . '</content>
+               <summary>
+                       <!-- firstreport goes here -->
+               </summary>
+               <link rel="alternate" href="' . $bugsys->options['trackerurl'] . '/showreport.php?bugid=' . $bug['bugid'] . '"/>
+       </entry>';
+       }
+       
+       $feed .= '
+       <!-- / entries -->
+
+</feed>';
+       
+       header('Content-type: application/xml');
+       echo $feed;
+       
+       exit;
+}
+
+// ###################################################################
+// RSS
+
+else if (SYND_TYPE == 'rss')
+{
+       // not going to be implemented in 1.1 because I don't want to clutter the templates with multiple feed icons and such...
+}
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file