Source for file browse_rss.act.php

Documentation is available at browse_rss.act.php

  1. <?php
  2. /**
  3. * @since 8/7/06
  4. * @package polyphony.logging
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: browse_rss.act.php,v 1.5 2007/09/19 14:04:56 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/RSSAction.class.php");
  13.  
  14. /**
  15. * <##>
  16. *
  17. * @since 8/7/06
  18. * @package polyphony.logging
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: browse_rss.act.php,v 1.5 2007/09/19 14:04:56 adamfranco Exp $
  24. */
  25. class browse_rssAction
  26. extends RSSAction
  27. {
  28. /**
  29. * Check Authorizations
  30. *
  31. * @return boolean
  32. * @access public
  33. * @since 8/8/06
  34. */
  35. function isExecutionAuthorized () {
  36. // Check for authorization
  37. $authZManager = Services::getService("AuthZ");
  38. $idManager = Services::getService("IdManager");
  39. if ($authZManager->isUserAuthorized(
  40. $idManager->getId("edu.middlebury.authorization.view"),
  41. $idManager->getId("edu.middlebury.authorization.root")))
  42. {
  43. return TRUE;
  44. } else {
  45. return FALSE;
  46. }
  47. }
  48. /**
  49. * Answer the HTTP Authentication 'Relm' to present to the user for authentication.
  50. *
  51. * @return mixed string or null
  52. * @access public
  53. * @since 8/7/06
  54. */
  55. function getRelm () {
  56. return 'Concerto'; // Override for custom relm.
  57. }
  58. /**
  59. * Build the rss feed
  60. *
  61. * @return void
  62. * @access public
  63. * @since 8/8/06
  64. */
  65. function buildFeed () {
  66. $defaultTextDomain = textdomain("polyphony");
  67. $harmoni = Harmoni::instance();
  68. $harmoni->request->startNamespace("polyphony-logs");
  69. $harmoni->request->passthrough('log', 'priority',
  70. 'startYear', 'startMonth', 'startDay', 'startHour',
  71. 'endYear', 'endMonth', 'endDay', 'endHour',
  72. 'agent_id', 'node_id', 'category');
  73. $agentManager = Services::getService("Agent");
  74. $idManager = Services::getService("Id");
  75. $hierarchyManager = Services::getService("Hierarchy");
  76. $loggingManager = Services::getService("Logging");
  77. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  78. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  79. if (RequestContext::value("log"))
  80. $currentLogName = RequestContext::value("log");
  81. else {
  82. $logNames =$loggingManager->getLogNamesForReading();
  83. $currentLogName = $logNames->next();
  84. }
  85. // --- The Current log ---
  86. if (isset($currentLogName) && $currentLogName) {
  87. $log =$loggingManager->getLogForReading($currentLogName);
  88. // Priority Type
  89. if (RequestContext::value("priority")) {
  90. $currentPriorityType = Type::fromString(
  91. RequestContext::value("priority"));
  92. } else {
  93. $priorityTypes =$loggingManager->getPriorityTypes();
  94. $currentPriorityType =$priorityTypes->next();
  95. }
  96. // --- The Current log with Priority type ---
  97. if (isset($currentPriorityType) && $currentPriorityType) {
  98. // Do a search if needed
  99. if (RequestContext::value('agent_id')
  100. || RequestContext::value('node_id')
  101. || RequestContext::value('category'))
  102. {
  103. $criteria = array();
  104. $criteria['start'] =$this->minDate();
  105. $criteria['end'] = DateAndTime::tomorrow();
  106. if (RequestContext::value('agent_id'))
  107. $criteria['agent_id'] =$idManager->getId(
  108. RequestContext::value('agent_id'));
  109. if (RequestContext::value('node_id'))
  110. $criteria['node_id'] =$idManager->getId(
  111. RequestContext::value('node_id'));
  112. if (RequestContext::value('category'))
  113. $criteria['category'] = urldecode(RequestContext::value('category'));
  114. $searchType = new Type("logging_search", "edu.middlebury", "Date-Range/Agent/Node");
  115. $entries =$log->getEntriesBySearch($criteria, $searchType,
  116. $formatType, $currentPriorityType);
  117. if ($entries->hasNext())
  118. $firstEntry =$entries->next();
  119. $entries =$log->getEntriesBySearch($criteria, $searchType,
  120. $formatType, $currentPriorityType);
  121. } else {
  122. $entries =$log->getEntries($formatType, $currentPriorityType);
  123. if ($entries->hasNext())
  124. $firstEntry =$entries->next();
  125. $entries =$log->getEntries($formatType, $currentPriorityType);
  126. }
  127. }
  128. }
  129. $this->setTitle($currentLogName." ".$currentPriorityType->getKeyword()." "._("Logs"));
  130. $this->setLink($harmoni->request->quickURL('logs', 'browse'));
  131. $this->addCategory("Logs");
  132. ob_start();
  133. print $currentLogName." "._("logs of priority,");
  134. print " ".$currentPriorityType->getKeyword();
  135. if (RequestContext::value('agent_id')) {
  136. print "\n<p style='text-indent: 0.5in'>";
  137. print _("Limited to agent: ");
  138. $id =$idManager->getId(RequestContext::value('agent_id'));
  139. $agent =$agentManager->getAgent($id);
  140. print $agent->getDisplayName();
  141. print "</p>";
  142. }
  143. if (RequestContext::value('node_id')) {
  144. print "\n<p style='text-indent: 0.5in'>";
  145. print _("Limited to node: ");
  146. $id =$idManager->getId(RequestContext::value('node_id'));
  147. $node =$hierarchyManager->getNode($id);
  148. if ($node->getDisplayName())
  149. print $node->getDisplayName();
  150. else
  151. print _("Id: ").$nodeId->getIdString();
  152. print "</p>";
  153. }
  154. if (RequestContext::value('category')) {
  155. print "\n<p style='text-indent: 0.5in'>";
  156. print _("Limited to category: ");
  157. print urldecode(RequestContext::value('category'));
  158. print "</p>";
  159. }
  160. $this->setDescription(ob_get_clean());
  161. $i = 0;
  162. while ($entries->hasNext() && $i < 30) {
  163. $this->addEntry($entries->next());
  164. $i++;
  165. }
  166. textdomain($defaultTextDomain);
  167. }
  168. /**
  169. * Print out a log entry
  170. *
  171. * @param object Entry $entry
  172. * @return void
  173. * @access public
  174. * @since 8/7/06
  175. */
  176. function addEntry ( $entry ) {
  177. $rssItem =$this->addItem(new RSSItem);
  178. $harmoni = Harmoni::instance();
  179. $agentManager = Services::getService("Agent");
  180. $hierarchyManager = Services::getService("Hierarchy");
  181. $timestamp =$entry->getTimestamp();
  182. $timestamp =$timestamp->asTimestamp();
  183. $item =$entry->getItem();
  184. $desc = HtmlString::fromString($item->getDescription());
  185. // a title
  186. $rssItem->setTitle($desc->stripTagsAndTrim(5));
  187. // Date of occurance
  188. $rssItem->setPubDate($timestamp);
  189. // A unique id...
  190. $rssItem->setGUID(
  191. md5($timestamp->asUnixTimeStamp()
  192. .$item->getDescription()
  193. .$item->getBacktrace()),
  194. false);
  195. // Category
  196. $rssItem->addCategory($item->getCategory());
  197. // Agent / 'author'
  198. $agentList = '';
  199. $agentIds =$item->getAgentIds(true);
  200. while ($agentIds->hasNext()) {
  201. $agentId =$agentIds->next();
  202. if ($agentManager->isAgent($agentId) || $agentManager->isGroup($agentId)) {
  203. $agent =$agentManager->getAgent($agentId);
  204. $agentList .= $agent->getDisplayName();
  205. } else
  206. $agentList .= _("Id: ").$agentId->getIdString();
  207. if ($agentIds->hasNext())
  208. $agentList .= ", ";
  209. }
  210. $rssItem->setAuthor($agentList);
  211. // Agents with links
  212. ob_start();
  213. $agentIds =$item->getAgentIds(true);
  214. $authorList = '';
  215. while ($agentIds->hasNext()) {
  216. $agentId =$agentIds->next();
  217. if ($agentManager->isAgent($agentId) || $agentManager->isGroup($agentId)) {
  218. $agent =$agentManager->getAgent($agentId);
  219. print "<a href='";
  220. print $harmoni->request->quickURL("logs", "browse",
  221. array( "agent_id" => $agentId->getIdString()));
  222. print "'>";
  223. print $agent->getDisplayName();
  224. print "</a>";
  225. $authorList .= $agent->getDisplayName();
  226. } else {
  227. print _("Id: ").$agentId->getIdString();
  228. $authorList .= _("Id: ").$agentId->getIdString();
  229. }
  230. if ($agentIds->hasNext()) {
  231. print ", <br/>";
  232. $authorList .= ", ";
  233. }
  234. }
  235. $agentList = ob_get_clean();
  236. // Nodes
  237. ob_start();
  238. $nodeIds =$item->getNodeIds(true);
  239. while ($nodeIds->hasNext()) {
  240. $nodeId =$nodeIds->next();
  241. print "<a href='";
  242. print $harmoni->request->quickURL("logs", "browse",
  243. array( "node_id" => $nodeId->getIdString()));
  244. print "'>";
  245. if ($hierarchyManager->nodeExists($nodeId)) {
  246. $node =$hierarchyManager->getNode($nodeId);
  247. if ($node->getDisplayName())
  248. print $node->getDisplayName();
  249. else
  250. print _("Id: ").$nodeId->getIdString();
  251. } else {
  252. print _("Id: ").$nodeId->getIdString();
  253. }
  254. print "</a>";
  255. if ($nodeIds->hasNext())
  256. print ", <br/>";
  257. }
  258. $nodeList = ob_get_clean();
  259. // Description text
  260. ob_start();
  261. print "\n\t\t\t\t<dl>";
  262. print "\n\t\t\t\t\t<dt style='font-weight: bold;'>"._("Date: ")."</dt>";
  263. print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>";
  264. print $timestamp->monthName()." ";
  265. print $timestamp->dayOfMonth().", ";
  266. print $timestamp->year()." ";
  267. print $timestamp->hmsString();
  268. print "</dd>";
  269. print "\n\t\t\t\t\t<dt style='font-weight: bold;'>"._("Category: ")."</dt>";
  270. print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>".$item->getCategory()."</dd>";
  271. print "\n\t\t\t\t\t<dt style='font-weight: bold;'>"._("Description: ")."</dt>";
  272. $desc->clean();
  273. print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>".$desc->asString()."</dd>";
  274. print "\n\t\t\t\t\t<dt style='font-weight: bold;'>"._("Agents: ")."</dt>";
  275. print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>".$agentList."</dd>";
  276. print "\n\t\t\t\t\t<dt style='font-weight: bold;'>"._("Nodes: ")."</dt>";
  277. print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>".$nodeList."</dd>";
  278. print "\n\t\t\t\t\t<dt style='font-weight: bold;'>"._("Backtrace: ")."</dt>";
  279. print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>".$item->getBacktrace()."</dd>";
  280. print "\n\t\t\t\t</dl>";
  281. $rssItem->setDescription(ob_get_clean());
  282. }
  283. /**
  284. * Answer the minumum date to display
  285. *
  286. * @return object DateAndTime
  287. * @access public
  288. * @since 3/8/06
  289. */
  290. function minDate () {
  291. return DateAndTime::withYearDay(2000, 1);
  292. }
  293. }
  294.  
  295. ?>

Documentation generated on Wed, 19 Sep 2007 10:21:55 -0400 by phpDocumentor 1.3.0RC3