Skip to content
Snippets Groups Projects
Commit b61b8927 authored by Kevin Abel's avatar Kevin Abel
Browse files

Move RSS to CAP data logic into new class

parent def81a25
No related branches found
No related tags found
No related merge requests found
<?php
function getCAPData()
function getCAPData($config)
{
try {
$alerts = new UNL_Alert_RaveRSS('http://www.getrave.com/rss/unl/channel1');
$filtered = new UNL_Alert_RecentPubDateFilter($alerts->getIterator());
$filtered->rewind();
if ($filtered->valid()) {
$item = $filtered->current();
$isTest = false;
if (stripos($item->description, 'test')) {
$isTest = true;
}
$pubDate = (string) $item->children('dc', true)->date;
$pubDateTime = new DateTime($pubDate);
$output = array(
'identifier' => md5($pubDate),
'sender' => 'police.unl.edu',
'sent' => $pubDateTime->format(DateTime::ATOM),
'status' => $isTest ? 'Test' : 'Actual',
'msgType' => 'Alert',
'scope' => 'Public',
);
if ($isTest) {
$output['note'] = 'This is only a test';
}
$output['info'] = array();
$url = isset($config['proxyUrl']) ? $config['proxyUrl'] :'http://www.getrave.com/rss/unl/channel1';
$alerts = new UNL_Alert_RaveRSS($url);
foreach ($filtered as $item) {
$output['info'][] = array(
'category' => 'Safety',
'event' => 'UNL Alert',
'ugency' => 'Immediate',
'severity' => 'Extreme',
'certainty' => 'Observed',
'headline' => (string) $item->title,
'description' => (string) $item->description,
'web' => 'http://www.unl.edu/',
);
}
if (!empty($config['recentTimeframe'])) {
$filtered = new UNL_Alert_RecentPubDateFilter($alerts->getIterator(), $config['recentTimeframe']);
} else {
$output = array();
$filtered = new UNL_Alert_RecentPubDateFilter($alerts->getIterator());
}
$data = new UNL_Alert_RSSToCAP($filtered);
$output = $data->getData();
} catch (Exception $e) {
$output = array();
}
......
<?php
class UNL_Alert_RSSToCAP
{
protected $iterator;
public function __construct(Iterator $items)
{
$this->iterator = $items;
}
public function getData()
{
$output = array();
$this->iterator->rewind();
if ($this->iterator->valid()) {
$item = $this->iterator->current();
$isTest = false;
if (stripos($item->description, 'test')) {
$isTest = true;
}
$pubDate = (string) $item->children('dc', true)->date;
$pubDateTime = new DateTime($pubDate);
$output = array(
'identifier' => md5($pubDate),
'sender' => 'police.unl.edu',
'sent' => $pubDateTime->format(DateTime::ATOM),
'status' => $isTest ? 'Test' : 'Actual',
'msgType' => 'Alert',
'scope' => 'Public',
);
if ($isTest) {
$output['note'] = 'This is only a test';
}
$output['info'] = array();
foreach ($this->iterator as $item) {
$output['info'][] = array(
'category' => 'Safety',
'event' => 'UNL Alert',
'ugency' => 'Immediate',
'severity' => 'Extreme',
'certainty' => 'Observed',
'headline' => (string) $item->title,
'description' => (string) $item->description,
'web' => 'http://www.unl.edu/',
);
}
}
return $output;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment