Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UNL_Alert
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Experience Group
UNL_Alert
Commits
2e651ee3
Commit
2e651ee3
authored
11 years ago
by
Kevin Abel
Browse files
Options
Downloads
Patches
Plain Diff
Convert the scripts to use the new ArrayObject for generating CAP Alert
parent
45f66d7d
Branches
main
No related tags found
1 merge request
!1
Implement RAVE RSS feed a source of proxied alerts
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
scripts/exportCAPAlert.php
+4
-57
4 additions, 57 deletions
scripts/exportCAPAlert.php
scripts/exportJSONAlert.php
+8
-12
8 additions, 12 deletions
scripts/exportJSONAlert.php
scripts/functions.inc.php
+52
-0
52 additions, 0 deletions
scripts/functions.inc.php
with
64 additions
and
69 deletions
scripts/exportCAPAlert.php
+
4
−
57
View file @
2e651ee3
<?php
require_once
dirname
(
__FILE__
)
.
'/../config.inc.php'
;
require_once
'functions.inc.php'
;
function
exportCAPAlert
()
{
$output
=
getCAPData
()
;
file_put_contents
(
dirname
(
__FILE__
)
.
'/../www/xml/unlcap.xml'
,
$output
->
toXML
(
'alert'
,
'urn:oasis:names:tc:emergency:cap:1.2'
));
$output
=
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<alert xmlns:cap="http://www.incident.com/cap/1.0">
<identifier>University of Nebraska-Lincoln '
.
date
(
'Y-m-d\TH:i:sO'
)
.
'</identifier>
<sender>police.unl.edu</sender>
<sent>'
.
date
(
'Y-m-d\TH:i:sO'
)
.
'</sent>
<status>Actual</status>
<msgType>Alert</msgType>
<scope>Public</scope>
<note>
Current Watches, Warnings and Advisories for UNL Issued by University Police
</note>
<references>
http://www.unl.edu/
</references>'
;
try
{
// Get the RSS feed
$alerts
=
new
UNL_Alert_TwitterAlert
();
// Create the filter
$filtered
=
new
UNL_Alert_RecentPubDateFilter
(
$alerts
);
foreach
(
$filtered
as
$item
)
{
$effective
=
DateTime
::
createFromFormat
(
'U'
,
strtotime
(
$item
->
created_at
));
$effective
->
setTimezone
(
new
DateTimeZone
(
date_default_timezone_get
()));
$output
.
=
'
<info>
<category>Safety</category>
<event>University of Nebraska-Lincoln Alert</event>
<urgency>Immediate</urgency>
<severity>Extreme</severity>
<certainty>Likely</certainty>
<headline>UNL ALERT</headline>
<description>'
.
$item
->
text
.
'</description>
<effective>'
.
date
(
'Y-m-d\TH:i:sO'
,
$effective
->
getTimestamp
())
.
'</effective>
<web>http://www.unl.edu/</web>
<parameter>
<valueName>id</valueName>
<value>'
.
md5
(
$item
->
id
)
.
'</value>
</parameter>
<area>
<areaDesc>Lincoln (Nebraska)</areaDesc>
<geocode>031111</geocode>
</area>
</info>'
;
}
}
catch
(
Exception
$e
)
{
echo
$e
;
}
$output
.
=
PHP_EOL
.
'</alert>'
.
PHP_EOL
;
return
$output
;
}
$xmlCAP
=
exportCAPAlert
();
file_put_contents
(
dirname
(
__FILE__
)
.
'/../www/xml/unlcap.xml'
,
$xmlCAP
);
require
dirname
(
__FILE__
)
.
'/exportJSONAlert.php'
;
include
dirname
(
__FILE__
)
.
'/exportJSONAlert.php'
;
This diff is collapsed.
Click to expand it.
scripts/exportJSONAlert.php
+
8
−
12
View file @
2e651ee3
<?php
require_once
dirname
(
__FILE__
)
.
'/../src/xml2json/xml2json.php'
;
require_once
dirname
(
__FILE__
)
.
'/../config.inc.php'
;
require_once
'functions.inc.php'
;
$file
=
dirname
(
__FILE__
)
.
'/../www/xml/unlcap.xml'
;
if
(
!
isset
(
$output
))
{
$output
=
getCAPData
();
}
//Read the XML alert info from the file.
file_exists
(
$file
)
or
die
(
'Could not find file '
);
$xmlStringContents
=
file_get_contents
(
$file
);
$jsonContents
=
''
;
$nl
=
"
\n
"
;
// Convert it to JSON now.
// xml2json simply takes a String containing XML contents as input.
$jsonContents
=
xml2json
::
transformXmlStringToJson
(
$xmlStringContents
);
$jsonContents
=
$output
->
toJSON
(
'alert'
);
$jsonContents
=
'unlAlerts.data = '
.
$jsonContents
.
$nl
;
$jsonContents
=
'unlAlerts.data = '
.
$jsonContents
.
"
\n
"
;
$jsonContents
.
=
'try {
unlAlerts.server.init();
} catch(e) {}'
.
$nl
;
} catch(e) {}'
.
"
\n
"
;
file_put_contents
(
dirname
(
__FILE__
)
.
'/../www/json/unlcap.js'
,
$jsonContents
);
This diff is collapsed.
Click to expand it.
scripts/functions.inc.php
0 → 100644
+
52
−
0
View file @
2e651ee3
<?php
function
getCAPData
()
{
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
;
}
$output
=
array
(
'identifier'
=>
md5
((
string
)
$item
->
children
(
'dc'
,
true
)
->
date
),
'sender'
=>
'police.unl.edu'
,
'sent'
=>
(
new
DateTime
((
string
)
$item
->
children
(
'dc'
,
true
)
->
date
))
->
format
(
DateTime
::
ATOM
),
'status'
=>
$isTest
?
'Test'
:
'Actual'
,
'msgType'
=>
'Alert'
,
'scope'
=>
'Public'
,
);
if
(
$isTest
)
{
$output
[
'note'
]
=
'This is only a test'
;
}
$output
[
'info'
]
=
array
();
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/'
,
);
}
}
else
{
$output
=
array
();
}
}
catch
(
Exception
$e
)
{
$output
=
array
();
}
return
new
UNL_Alert_ArrayObject
(
$output
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment