From: Steve Sutton Date: Fri, 2 May 2014 12:59:38 +0000 (+0000) Subject: Setup the weather on website X-Git-Tag: v1.0~42 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=8770eb68c1399c685ea4762953c773883112c9a0;p=web%2FCedarvilleMarine.git Setup the weather on website station id is Sault Ste Marie - KANJ --- diff --git a/Toolkit/Weather.php b/Toolkit/Weather.php new file mode 100755 index 0000000..1d2a482 --- /dev/null +++ b/Toolkit/Weather.php @@ -0,0 +1,242 @@ + + * @copyright 2008 Gaslight Media + * @license http://www.gaslightmedia.com/license.txt The Gaslight License + * @version CVS: $Id: Weather.php,v 1.7 2010/08/16 17:41:03 jamie Exp $ + * @link <> + */ + +/** + * Weather class for Gaslight Media + * + * You can get the stationId for weather at + * http://www.weather.gov/xml/current_obs/seek.php?state=mi + * Uses NOAA for getting the rss feed for weather + * + * @category Toolkit + * @package Weather + * @author Steve Sutton + * @copyright 2008 Gaslight Media + * @license http://www.gaslightmedia.com/license.txt The Gaslight License + * @link <> + */ +class Toolkit_Weather +{ + //{{{ __Class Properties + + + /** + * The xml file used for caching the feed + * @var $_weatherFile string + * @access private + */ + private $_weatherFile; + + /** + * Station identifier for the feed + * @link http://w1.weather.gov/xml/current_obs/seek.php?state=mi + * + * @var $_stationId string + * @access private + */ + private $_stationId = 'KANJ'; + + + /** + * XMLReader object for parsing feed + * @var $_xml object + * @access private + */ + private $_xml; + + /** + * Description for private + * @var $_assoc array + * @access private + */ + private $_assoc; + + /** + * Storage array for the current conditions + * @var $currendCond array + * @access public + */ + public $currentCond; + + /** + * Boolean if the file exists or not + * @var $_cacheFileExist boolean + * @access private + */ + private $_cacheFileExist = false; + + + /** + * Interger for the number of min before reloading file + * @var int + * @access private + */ + private $_interval; + //}}} + + //{{{ __construct() + + /** + * Class Constructer + * + * @return void + * @access public + */ + function __construct() + { + $currentErrorMask = ini_get('error_reporting'); + error_reporting(0); + $this->_weatherFile = BASE.'weather-feed.xml'; + $this->_interval = 25; // interval in minutes for page cache + $this->fetchWeather(); + $this->setCurrentCond(); + error_reporting($currentErrorMask); + } + + //}}} + //{{{ fetchWeather() + + + /** + * fetchWeather + * + * THis will use curl to grab the weather feed using + * the $_weatherFile as destination + * and the $_stationId for the xml file name + * + * @return void + * @access public + */ + function fetchWeather() + { + if (is_file($this->_weatherFile)) { + $timeintervalago = mktime( + date('H'), + date('i') - $this->_interval, + date('s'), + date('m'), + date('d'), + date('Y') + ); + $file_time = filemtime($this->_weatherFile); + if ($file_time < $timeintervalago) { + $this->grabFeedUrl(); + } + if (is_file($this->_weatherFile)) { + $this->_cacheFileExist = true; + } + } else { + $this->grabFeedUrl(); + if (is_file($this->_weatherFile)) { + $this->_cacheFileExist = true; + } + } + } + + //}}} + // {{{ grabFeedUrl() + + + /** + * grabFeedUrl + * + * @return void + * @access public + */ + function grabFeedUrl() + { + // the NOAA xml feed url to be used + // from the _stationId + $feed_url = 'http://w1.weather.gov/xml/current_obs/' + .$this->_stationId.'.xml'; + // Curl Options used for connection + $curlOptions = array( + CURLOPT_URL => $feed_url, + CURLOPT_HEADER => 0, + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_TIMEOUT => 15, + CURLOPT_CONNECTTIMEOUT => 5, + CURLOPT_FAILONERROR => 1, + ); + // start curl object + $ch = curl_init(); + // set options + curl_setopt_array($ch, $curlOptions); + // assign the response to a string variable + $response = curl_exec($ch); + // grab the connection info to check for http_code = 200 + $info = curl_getinfo($ch); + curl_close($ch); + if ($info['http_code'] == '200') { + file_put_contents($this->_weatherFile, $response); + $oldmask = umask(0); + chmod($this->_weatherFile, 0666); + umask($oldmask); + } else { + @touch($this->_weatherFile); + } + } + + + // }}} + //{{{ setCurrentCond() + + /** + * Set currentCond + * + * Set the currentCond clas var up with variables from the xml file + * from the weather feed + * + * @return void + * @access public + */ + function setCurrentCond() + { + $xml = new XML_Unserializer(); + $xml->unserialize($this->_weatherFile, true); + $this->currentCond = $xml->getUnserializedData(); + } + + //}}} + //{{{ + /** + * Getter for _interval + * + * @return Int + * @access public + */ + public function get_interval() { + return $this->_interval; + } + + //}}} + //{{{ + /** + * Setter for _stationId + * + * @param string $_stationId Station ID + * + * @return void + * @access public + */ + public function set_stationId($_stationId) { + $this->_stationId = $_stationId; + } + + + + +} +?> diff --git a/config/application.ini b/config/application.ini index f6ef5cb..88622f6 100644 --- a/config/application.ini +++ b/config/application.ini @@ -114,7 +114,7 @@ photo_gallery.application = On rotating_images.application = On ; Turn the weather application On or Off -weather.application = Off +weather.application = On ; Turn the gift certificate application On or Off gift_certificates.application = Off diff --git a/templates/template.html b/templates/template.html index fc80d6d..20cbcaa 100644 --- a/templates/template.html +++ b/templates/template.html @@ -72,9 +72,9 @@
Get Directions
- - 52.0° - Sunny + + {tempF}° + {weather}
Find us on Facebook