1<?php 2/** 3 * Whups RSS feed. 4 * 5 * Copyright 2007-2017 Horde LLC (http://www.horde.org/) 6 * 7 * See the enclosed file LICENSE for license information (BSD). If you 8 * did not receive this file, see http://www.horde.org/licenses/bsdl.php. 9 * 10 * @author Michael J. Rubinsky <mrubinsk@horde.org> 11 */ 12 13require_once __DIR__ . '/../lib/Application.php'; 14Horde_Registry::appInit('whups'); 15 16// See if we were passed a slug or id. Slug is tried first. 17$slug = Horde_Util::getFormData('slug'); 18if ($slug) { 19 $queue = $whups_driver->getQueueBySlugInternal($slug); 20 // Bad queue slug? 21 if (!count($queue)) { 22 exit; 23 } 24 $id = $queue['id']; 25} else { 26 $id = Horde_Util::getFormData('id'); 27 $queue = $whups_driver->getQueue($id); 28} 29 30// If a specific state_category is not specified, default to returning all 31// open tickets. 32$state_category = Horde_Util::getFormData('state'); 33if ($state_category) { 34 $state_display = Horde_String::ucFirst($state_category); 35 // When specifying an explicit state, limit the feed to 10. 36 $limit = 10; 37 $state_category = array($state_category); 38} else { 39 $state_category = array('unconfirmed', 'new', 'assigned'); 40 $state_display = _("Open"); 41 $limit = 0; 42} 43 44$criteria = array(); 45 46// See if we are requesting a specific type_id (for bug, feature etc...) 47$typeId = Horde_Util::getFormData('type_id'); 48if (is_numeric($typeId)) { 49 try { 50 $type = $whups_driver->getType($typeId); 51 $criteria['type'] = array($typeId); 52 } catch (Whups_Exception $e) { 53 unset($type); 54 } 55} 56 57if (!$id && !$state_category && !$typeId) { 58 exit; 59} 60 61$criteria['category'] = $state_category; 62if ($id) { 63 $criteria['queue'] = $id; 64} 65 66$tickets = $whups_driver->getTicketsByProperties($criteria); 67if (!count($tickets)) { 68 exit; 69} 70 71Whups::sortTickets($tickets, 'date_updated', 'desc'); 72$cnt = 0; 73foreach (array_keys($tickets) as $i) { 74 if ($limit > 0 && $cnt++ == $limit) { 75 break; 76 } 77 $description = 'Type: ' . $tickets[$i]['type_name'] . '; State: ' 78 . $tickets[$i]['state_name']; 79 80 $items[$i]['title'] = htmlspecialchars(sprintf('[%s] %s', 81 $tickets[$i]['id'], 82 $tickets[$i]['summary'])); 83 $items[$i]['description'] = htmlspecialchars($description); 84 $items[$i]['url'] = Whups::urlFor('ticket', $tickets[$i]['id'], true, -1); 85 $items[$i]['pubDate'] = htmlspecialchars(date('r', $tickets[$i]['timestamp'])); 86} 87 88$template = $injector->createInstance('Horde_Template'); 89$template->set('xsl', Horde_Themes::getFeedXsl()); 90$template->set('pubDate', htmlspecialchars(date('r'))); 91if (isset($type) && isset($queue['name'])) { 92 $rss_title = sprintf(_("%s %s tickets in %s"), 93 $state_display, 94 $type['name'], $queue['name']); 95} elseif (isset($type)) { 96 $rss_title = sprintf(_("%s %s tickets in all queues"), 97 $state_display, 98 $type['name']); 99} elseif (isset($queue['name'])) { 100 $rss_title = sprintf(_("%s tickets in %s"), 101 $state_display, 102 $queue['name']); 103} else { 104 $rss_title = sprintf(_("%s tickets in all queues"), $state_display); 105} 106$template->set('title', htmlspecialchars($rss_title)); 107$template->set('items', $items, true); 108$template->set('url', Horde::url('queue/', true, -1)->add('id', $id)); 109$template->set('rss_url', Horde::url('rss.php', true, -1)->add('id', $id)); 110if (isset($queue['name'])) { 111 $description = sprintf(_("Open tickets in %s"), $queue['name']); 112} else { 113 $description = _("Open tickets in all queues."); 114} 115$template->set('description', htmlspecialchars($description)); 116 117$browser->downloadHeaders((isset($queue['name']) ? $queue['name'] : 'horde') . '.rss', 'text/xml', true); 118echo $template->fetch(WHUPS_TEMPLATES . '/rss/items.rss'); 119