Weather
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 14 Aug 2014 19:48:06 +0000 (15:48 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 14 Aug 2014 19:48:06 +0000 (15:48 -0400)
Setup weather for template

Toolkit/Weather.php [new file with mode: 0755]
config/application.ini
styles.css
templates/template.html

diff --git a/Toolkit/Weather.php b/Toolkit/Weather.php
new file mode 100755 (executable)
index 0000000..5713f9d
--- /dev/null
@@ -0,0 +1,242 @@
+<?php
+/**
+ * Weather.php
+ *
+ * PHP version 5
+ *
+ * @category  Toolkit
+ * @package   Weather
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @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 <steve@gaslightmedia.com>
+ * @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;
+    }
+
+
+
+
+}
+?>
index a1e2780..2278d8a 100644 (file)
@@ -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
index 6f44f0a..f932795 100644 (file)
@@ -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
index 3e733a1..813af48 100644 (file)
               </div>
               <div class="small-12 medium-6 large-3 columns weather">
                 <div class="right">
+                    <section flexy:if="hasWeather" id="weather">
+                        <img src="{fullIconUrl:h}" alt="" width="48" height="48">
+                        <p class="weatherHdr">Current Weather</p>
+                        <p class="weatherTmp">{tempF}&#176;</p>
+                        <p class="weather">{weather} </p>
+                    </section><!-- /#weather -->
                   <!-- WeatherUnderground widget -->
-                  <span style="display: block !important; width: 180px; text-align: center; font-family: sans-serif; font-size: 12px;"><a href="http://www.wunderground.com/cgi-bin/findweather/getForecast?query=zmw:49921.1.99999&bannertypeclick=wu_simplewhite" title="Houghton, Michigan Weather Forecast" target="_blank"><img src="http://weathersticker.wunderground.com/weathersticker/cgi-bin/banner/ban/wxBanner?bannertype=wu_simplewhite&airportcode=KCMX&ForcedCity=Dodgeville&ForcedState=MI&zip=49921&language=EN" alt="Find more about Weather in Houghton, MI" width="160" /></a></span>
                 </div>
               </div>