From: Steve Sutton Date: Thu, 14 Aug 2014 19:48:06 +0000 (-0400) Subject: Weather X-Git-Tag: V1.0^2~71 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=831ce387145d47a0c64791da9bc6257c262ea769;p=web%2FKeweenaw.git Weather Setup weather for template --- diff --git a/Toolkit/Weather.php b/Toolkit/Weather.php new file mode 100755 index 0000000..5713f9d --- /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 = 'KCMX'; + + + /** + * 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 a1e2780..2278d8a 100644 --- a/config/application.ini +++ b/config/application.ini @@ -115,7 +115,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/styles.css b/styles.css index 6f44f0a..f932795 100644 --- a/styles.css +++ b/styles.css @@ -1016,3 +1016,29 @@ footer .copyright .separator { .xls { background-image: url(images/file-ext/xls.gif);} .zip { background-image: url(images/file-ext/zip.png);} .rar { background-image: url(images/file-ext/rar.gif);} +/*Weather*/ +#weather { + color: black; + display: block; + width: 185px; + height: 80px; + background-color: #fff; + font-size: 12px; + text-align: center; + line-height: 180%; +} +#weather img { + height: 48px; + width: 48px; + float: left; + margin: 8px; + padding-top:8px; +} +#weather .weatherHdr { + padding-top: 5px; + font-size: 13px; + font-weight: bold; +} +#weather .weatherTmp { + font-size: 20px; +} \ No newline at end of file diff --git a/templates/template.html b/templates/template.html index 3e733a1..813af48 100644 --- a/templates/template.html +++ b/templates/template.html @@ -170,8 +170,13 @@
+
+ +

Current Weather

+

{tempF}°

+

{weather}

+
- Find more about Weather in Houghton, MI