示例#1
0
 /**
  * TempestCache::tempestChanged($incoming) to check if incoming data array matches cache
  *
  * @param array[] $incoming Array structure of current dataset that needs to be compared to the cache.
  *
  * @return boolean True if datasets are different or timestamp is not within in the hour. Cache resets every hour.
  * 				   returns false if incoming data set is the same as cache.
  */
 static function tempestChanged($incoming)
 {
     if (NULL == self::$instance) {
         self::$instance = new TempestCache();
         if (!file_exists(self::$tempest)) {
             self::setCache($incoming);
             return true;
         } else {
             $fp = fopen(self::$tempest, 'r');
             self::$cache = json_decode(fgets($fp));
             fclose($fp);
         }
     }
     //Write cache and return true when current cache is empty or timestamp are different hour or incoming data set is different than cache
     if (empty(self::$cache) || !self::checkTimeStamp($incoming) || !self::checkDataSet($incoming)) {
         self::setCache($incoming);
         return true;
     }
     return false;
 }
示例#2
0
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;
                }
            }
        }