[Phphtmllib-devel] SF.net SVN: phphtmllib:[3407] trunk/open2300/lib
Status: Beta
Brought to you by:
hemna
From: <he...@us...> - 2010-03-03 16:58:58
|
Revision: 3407 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3407&view=rev Author: hemna Date: 2010-03-03 16:58:52 +0000 (Wed, 03 Mar 2010) Log Message: ----------- added new remote metar fetcher for the dynamic banner image replacement Modified Paths: -------------- trunk/open2300/lib/autoload.inc trunk/open2300/lib/core/page/open2300Page.inc Added Paths: ----------- trunk/open2300/lib/modules/home/widgets/RemoteMetarConditions.inc Modified: trunk/open2300/lib/autoload.inc =================================================================== --- trunk/open2300/lib/autoload.inc 2010-03-03 16:57:32 UTC (rev 3406) +++ trunk/open2300/lib/autoload.inc 2010-03-03 16:58:52 UTC (rev 3407) @@ -1,7 +1,7 @@ <?php /** * This is an auto-generated file. Please do not modify! - * Generated on 2010-02-27T10:41:33-08:00 by AutoloadGenerator + * Generated on 2010-03-02T10:13:35-08:00 by AutoloadGenerator * * @package open2300 */ @@ -199,6 +199,7 @@ 'ProjectGenerator'=>'external/phphtmllib/src/generator/ProjectGenerator.inc', 'RainLineGraph'=>'modules/graphs/RainLineGraph.inc', 'RedTheme'=>'external/phphtmllib/data/css/RedTheme.inc', +'RemoteMetarConditions'=>'modules/home/widgets/RemoteMetarConditions.inc', 'RemoteUpdate'=>'modules/api/RemoteUpdate.inc', 'Request'=>'external/phphtmllib/src/request/Request.inc', 'RequestBuilder'=>'external/phphtmllib/src/request/RequestBuilder.inc', @@ -301,6 +302,7 @@ 'rain-line-graph'=>'RainLineGraph', 'red-theme'=>'RedTheme', 'remote-update'=>'RemoteUpdate', +'rmetar'=>'RemoteMetarConditions', 'round-title-table'=>'RoundTitleTable', 'standard-dialog-w'=>'StandardDialogWidget', 'standard-theme'=>'StandardTheme', @@ -383,6 +385,7 @@ 'RainLineGraph'=>'rain-line-graph', 'RedTheme'=>'red-theme', 'RemoteUpdate'=>'remote-update', +'RemoteMetarConditions'=>'rmetar', 'RoundTitleTable'=>'round-title-table', 'StandardDialogWidget'=>'standard-dialog-w', 'StandardTheme'=>'standard-theme', Modified: trunk/open2300/lib/core/page/open2300Page.inc =================================================================== --- trunk/open2300/lib/core/page/open2300Page.inc 2010-03-03 16:57:32 UTC (rev 3406) +++ trunk/open2300/lib/core/page/open2300Page.inc 2010-03-03 16:58:52 UTC (rev 3407) @@ -124,8 +124,8 @@ $this->add_js_link( 'http://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js' ); $this->add_js_link( 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1/scriptaculous.js' ); $this->add_js_link( '/js/ajax.js' ); - $this->add_js_link( '/js/main.js' ); - $this->add_js_link( '/js/ticker.js' ); + $this->add_js_link( '/js/main.js' ); + $this->add_js_link( '/js/banner.js' ); } protected function header_block() { @@ -133,9 +133,7 @@ if ($this->include_ticker) { - $script = SCRIPTtag::factory(); - $script->add("Event.observe(window, 'load', start_ticker);"); - $header->add($script); + $this->add_js_link( '/js/ticker.js' ); } Added: trunk/open2300/lib/modules/home/widgets/RemoteMetarConditions.inc =================================================================== --- trunk/open2300/lib/modules/home/widgets/RemoteMetarConditions.inc (rev 0) +++ trunk/open2300/lib/modules/home/widgets/RemoteMetarConditions.inc 2010-03-03 16:58:52 UTC (rev 3407) @@ -0,0 +1,193 @@ +<?php +/** + * This file contains the Metar conditions + * for our local area. + */ + + +/** + * We need to do this due to cross domain js issues. + * We can't make a direct js ajax call to the url, unless + * we are running in the same domain as the url. + * + * @author waboring + * + */ +class RemoteMetarConditions extends JSONWidget { + + const TOD_MORNING = "morning"; + const TOD_MIDDAY = "midday"; + const TOD_AFTERNOON = "afternoon"; + const TOD_EVENING = "evening"; + const TOD_NIGHT = "night"; + + + public static $tod_lookup = array(0=> RemoteMetarConditions::TOD_NIGHT, + 1=>RemoteMetarConditions::TOD_MORNING, + 2=>RemoteMetarConditions::TOD_MIDDAY, + 3=>RemoteMetarConditions::TOD_AFTERNOON, + 4=>RemoteMetarConditions::TOD_EVENING); + + public static $cloud_lookup = array(0 => "clear", + 1 => "few", + 2 => "scattered", + 3 => "broken", + 4 => "overcast"); + + const ID = "rmetar"; + + protected $url="http://api.itimeteo.com/metar.ims?icao=kaun&format=json&decoded=true"; + + /** + * Class Constructor + * + */ + public function init() { + + } + + + + public function build_object() { + + $proxy = $GLOBALS["config"]->get("proxy"); + if (!empty($proxy)) { + $context = stream_context_create(array("http" => array("proxy" => "tcp://web-proxy.rose.hp.com:8088"))); + } else { + $context = null; + } + + $json = file_get_contents($this->url,0, $context); + Log::singleton()->debug("json returned is ".$json); + $metar = json_decode($json); + //echo var_export($metar, true)."\n"; + $metar->season = "Spring"; + Log::singleton()->debug(var_export($metar, true)); + + $conditions = array(); + $conditions["season"] = $GLOBALS["config"]->get("season"); + $clouds = $this->decode_clouds($metar->Metar->DecodeLine0->Clouds); + $conditions["clouds"] = $clouds; + $rained = $this->has_rained(); + $conditions["rained"] = $rained; + $conditions["banner"] = $this->get_banner_filename($conditions["season"], $clouds, $rained); + + return $conditions; + //return $metar; + } + + private function decode_clouds($cloudVar, $offset=null) { + $clouds = 0; + + if ($cloudVar->Overcast) { + $clouds = 4; + } else if ($cloudVar->Broken) { + $clouds = 3; + } else if ($cloudVar->Scattered) { + $clouds = 2; + } else if ($cloudVar->Few) { + $clouds = 1; + } else { + $clouds = 0; + } + + if (!is_null($offset)) { + $clouds += $offset; + + if ($clouds > 4) { + $clouds = 0; + } else if ($clouds < 0) { + $clouds = 4; + } + } + + return RemoteMetarConditions::$cloud_lookup[$clouds]; + } + + private function get_time_of_day($offset=null) { + $hour = date("G"); + $tod = null; + + if ($hour == 00 || $hour > 0 && $hour <6) { + $tod = 0; + } else if ($hour >= 6 && $hour <11) { + $tod = 1; + } else if ($hour >=11 && $hour < 16 ) { + $tod = 2; + } else if ($hour >=16 && $hour <19) { + $tod = 3; + } else if ($hour >=19 && $hour <24) { + $tod = 4; + } + + if (!is_null($offset)) { + $tod += $offset; + echo "tod = ".$tod." "; + + if ($tod > 4) { + $tod = 0; + } else if ($tod < 0) { + $tod = 4; + } + + echo "tod2 = ".$tod."\n"; + } + + return RemoteMetarConditions::$tod_lookup[$tod]; + } + + + private function get_banner_filename($season, $clouds, $rain, $offset=null) { + return null; + $tod = $this->get_time_of_day($offset); + //echo (var_export($tod, true)."\n"); + $filename = "/images/banners/".$season."/".$tod."_"; + + if ($rain) { + $filename .= "rain.jpg"; + } else { + $filename .= $clouds.".jpg"; + } + + //echo var_export($filename, true)."\n"; + if (file_exists($GLOBALS['path_base']."/htdocs".$filename)) { + return $filename; + } else { + return null; +// if (!is_null($offset)) { +// $offset += 1; +// } else { +// $offset = 1; +// } +// return $this->get_banner_filename($season, $clouds, $rain, $offset); + } + } + + /** + * Has it rained in the last 2 hours? + * If so, we are in "rain" mode. + * + * @return unknown_type + */ + private function has_rained() { + $db = open2300DB::singleton(); + $today = date("Y-m-d"); + + $sql = "select rain_1h from weather where datetime like :date order by datetime desc limit 0,1"; + $stmt = $db->queryBindOneRow($sql, array(":date" => $today."%")); + + //echo var_export($stmt->rain_1h,true)."\n"; + + if ( !is_null($stmt) ) { + $rain = $stmt->rain_1h; + if ($rain > 0) { + return true; + } else { + return false; + } + } else { + return false; + } + } +} +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |