-
Notifications
You must be signed in to change notification settings - Fork 0
/
poetempest.php
59 lines (51 loc) · 1.77 KB
/
poetempest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require_once 'include/config.inc.php';
require_once "Mail.php";
require_once 'TempestWatch.php';
require_once 'TempestCache.php';
/* Two methods to retrieve tempest dataset.
* Initial method is to use the API with PHP DOMDocument as fall back
* if API is unreachable.
*
* API GET call returns a JSON dataset with current tempests.
*/
$API = 'http://poetempest.com/api/v1/current_tempests';
$url = 'http://poetempest.com/';
$votesRequired = '3';
$notifyTempest;
$tempest = new TempestWatch($url, $votesRequired, $API);
$result = $tempest->execute($notifyTempest);
if(count($result) > 0 && $result != -1){
$result[] = time();
if(TempestCache::tempestChanged($result)){
//Sets Notification based on flag
if(EMAIL_NOTIFICATION && SMS_NOTIFICATION){
$to = CONTACT_EMAIL . ', ' . CONTACT_SMS . '@' . CONTACT_SMS_PROVIDER;
}else if(EMAIL_NOTIFICATION){
$to = CONTACT_EMAIL;
}else if(SMS_NOTIFICATION){
$to = CONTACT_SMS . '@' . CONTACT_SMS_PROVIDER;;
}else {
echo 'No notification set. Do nothing!';
exit;
}
//Setup email/SMS header, subject, and message
$subject = 'Tempest Found';
$body = 'Tempest Current Active: '."\n\n";
foreach($result as $map)
if(is_array($map))
$body .= 'Map: '.ucfirst($map[0]).' with '.ucfirst($map[1]).' mod active'."\n";
$headers = array ('From' => '[email protected]', 'To' => $to, 'Subject' => $subject);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
if (PEAR::isError($mail)){
echo 'Failed to send Tempest notification to '.$to;
error_log('Failed to send Tempest notification to '.$to, 0);
} else {
echo 'Tempest notification email successfully sent!';
}
} else
echo 'No New Tempest Found Within The Hour! Check Previous Email!';
} else
echo 'No Tempest found!';
?>