| When In Bandon |
There is so much to see and do! Spend a day, a week, or better yet, buy a home and spend the rest of your life here.
Fishing, Bandon Dunes Golf Resort, Beachcombing, Hiking, Biking, Relaxing and Watching the rest of the World wander by.
Go to the Bandon Chamber of Commerce website @ www.bandon.com for more exciting information on our community. |
|
class xoapWeather
{
#######################################################################################
#xoapWeather - Process XML feeds from weather.com for display on a website #
# keeping with in weather.com's standards for cacheing requests and links#
#Copyright (C) 2003 Brian Paulson #
# #
#This program is free software; you can redistribute it and/or #
#modify it under the terms of the GNU General Public License #
#as published by the Free Software Foundation; either version 2 #
#of the License, or (at your option) any later version. #
# #
#This program is distributed in the hope that it will be useful, #
#but WITHOUT ANY WARRANTY; without even the implied warranty of #
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
#GNU General Public License for more details. #
# #
#You should have received a copy of the GNU General Public License #
#along with this program; if not, write to the Free Software #
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
#######################################################################################
########################################################
# xoapWeather Version 1.2 - April 25, 2004 #
########################################################
########################################################
# Weather Channel Partner Variables #
########################################################
var $xoapKey = 'ce572dce0573e4b0'; //Weather.com xoap Key
var $xoapPar = '1003060961'; //Partner ID
var $product = 'xoap';
//Note: you can get this information for free by signing up at http://www.weather.com
########################################################
# Weather Channel Cache Requirement Variables #
########################################################
var $currentCondCache = 10; //Minutes
var $multiDayforecastCache = 2; //hours
//Note* these are the minimum settings according to The Weather Channel xoap Product Guide
########################################################
# xoap Application Variables #
########################################################
//var $defaultZip = 81007; // Old setting in versions < 1.2
var $sitePath = '/www/htdocs/chaswaldrop/weather'; //set this to the location of xoapWeather i.e. /var/www/weather
var $ccFile = 'cc.xml'; //filename For Current Conditons
var $forecastFile = 'forecast.xml'; //filename For forecastdata
var $cacheDir = "wxCache"; // Folder where the XML files will be stored
var $forecastDays = 10; //How many Days the Extended forecast extends.
var $error; //Error var for catching errors from weather.com
var $units = "s"; // s = standard m = metric;
var $useSocket = false; //set this to true if you want to use sockets instead of php's file function;
var $Administrator = 'webmaster@codegoodies.com';
var $storage = "db"; // db = Database or fl(lowercase L)for flat file storage
var $debug = false; // set this to true to view debug results for troubleshooting
var $instance = 1; //instance of xoap being called used for loading details and forcasts
var $dubugCount = 1; // Leave this setting
var $xoapVersion = 1.2; //Version of xoapApplication
########################################################
# xoap Database Variables #
########################################################
var $host = "localhost"; //Database Host
var $user = "chaswaldrop"; //Datbase user
var $pass = "hBaFdldR3"; //database Password
var $database = "ChasWaldrop"; //Database
var $conditionsTable = "wxConditions"; //Current Conditions Table
var $forecastTable = "wxForecast"; //Forecast Table
//DON'T CHANGE THIS SETTING//
var $newZip = true; //tells the database weather to insert or update
########################################################
# xoapWeather Application #
########################################################
/**
* Perform Setup Actions for class
* @access Private
* @param None
* @return None
*/
function xoapWeather()
{
$this->version();
$this->statusCheck();
}
/**
* Perform Load Applications
* @access Public
* @param $zip - zip code to load weather for
* @return None
*/
function loadXoap($zip,$display="cc")
{
$this->instance = $instance;
$this->setZip($zip);
if($this->storage == "db")
{
$this->dbCheck();
}
else
{
$this->setFiles();
}
$this->cacheControl();
if($this->error != 1)
{
switch($display)
{
case "cc":
$this->currentConditions($this->ccData());
break;
case "cd":
$this->ccDetails($this->ccData());
break;
case "fc":
$this->extForecast($this->forecastData());
break;
case "fd":
$this->detailForecast($this->forecastData(),$_GET['did']);
break;
default:
$this->currentConditions($this->ccData());
break;
}
}
}
/**
* Performs PHP Version Check
* @access Private
* @param None
* @Returns version of php being used
*/
function version()
{
$this->version = phpversion();
if($this->version < "4.1.0")
{
$this->setVars();
}
}
/**
* Performs Conversion of $HTTP_* Vars to $_* vars
* @access Private
* @param None
* @return None
*/
function setVars()
{
if (isset ($HTTP_SERVER_VARS))
{
$_SERVER = &$HTTP_SERVER_VARS;
}
if (isset ($HTTP_GET_VARS))
{
$_GET = &$HTTP_GET_VARS;
}
if (isset ($HTTP_POST_VARS))
{
$_POST = &$HTTP_POST_VARS;
}
if (isset ($HTTP_COOKIE_VARS))
{
$_COOKIE = &$HTTP_COOKIE_VARS;
}
if (isset ($HTTP_POST_FILES))
{
$_FILES = &$HTTP_POST_FILES;
}
if (isset ($HTTP_ENV_VARS))
{
$_ENV = &$HTTP_ENV_VARS;
}
if (isset ($HTTP_SESSION_VARS))
{
$_SESSION = &$HTTP_SESSION_VARS;
}
}
/**
* Sets the Zip code that the program should use
* @access Private
* @param None
* @return None
*/
function setZip($zip)
{
if($this->zip == "")
{
$error .= "Please Specify a Zip code. ";
}
if($_GET['zip'] != "")
{
$zip = urlencode($_GET['zip']);
}
$this->debug($_GET,"setZip");
$this->zip = $zip;
}
/**
* Connection to database
* @access Private
* @param None
* @return Database link Identifier
*/
function dbConnect()
{
$db = mysql_connect($this->host, $this->user, $this->pass);
return $db;
}
/**
* Make Database Query
* @access Private
* @param $sql - query to be run
* @param $database - database to run query against
* @return mysql data source
*/
function dbQuery($sql,$database)
{
$db = $this->dbConnect();
mysql_select_db($database) or die("MySQL Error: ".mysql_errno()." (".mysql_error().") \n$sql ");
$rs = mysql_query($sql) or die("MySQL Error: ".mysql_errno()." (".mysql_error().") \n$sql ");
return $rs;
}
/**
* Check for database and tables before we load the application
* @access Private
* @param none
* @return none
*/
function dbCheck()
{
$conditions = 0;
$forecast = 0;
$db = $this->dbConnect();
$rs = mysql_list_tables($this->database);
if(!$rs)
{
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row=mysql_fetch_row($rs))
{
if($row[0] == $this->conditionsTable)
{
$conditions = 1;
}
elseif($row[0] == $this->forecastTable)
{
$forecast = 1;
}
}
if($forecast == 0 or $conditions == 0)
{
echo "Sorry we were unable to locate the required table in your database, please check the names and try again. ";
exit;
}
}
/**
* Checks the status of certain Variables that are needed to execute
* @access Private
* @param None
* @return None
*/
function statusCheck()
{
if($this->xoapKey == "")
{
$error .= "Your Xoap Key is Empty Please Visit http://www.weather.com and sign-up for their xoapXML Services. ";
}
if($this->xoapPar == "")
{
$error .= "Your Xoap Partner ID is Empty Please Visit http://www.weather.com and sign-up for their xoapXML Services. ";
}
if($this->cacheDir == "" and $this->storage == "fl")
{
$error .= "Please Specify a cache Directory, be sure that data can be written to you cache dir by your web server. ";
}
if($this->sitePath == "")
{
$error .= "Please Specify a Site Path ";
}
if($this->storage == "db")
{
if($this->host == "" or $this->user == "" or $this->pass == "" or $this->database == "" or $this->conditionsTable == "" or $this->forecastTable == "")
{
$error .= "Please Specify your dabase setting all or some of the settings were missing. ";
}
}
if($error != "")
{
echo $error;
exit;
}
}
/**
* Sets the paths and filenames of for Proper cacheing.
* @access Private
* @param None
* @return None
*/
function setFiles()
{
$this->cc = $this->sitePath."/".$this->cacheDir."/".$this->zip.$this->ccFile;
$this->forecast = $this->sitePath."/".$this->cacheDir."/".$this->zip.$this->forecastFile;
}
/**
* Performs all cacheing for the application and file creation
* @access Private
* @param None
* @return None
*/
function cacheControl()
{
if($this->storage == "db")
{
$sql = "SELECT ".$this->conditionsTable.".cache AS cc, ".$this->forecastTable.".cache AS forecast
FROM ".$this->conditionsTable.", ".$this->forecastTable."
WHERE ".$this->conditionsTable.".zip = '".$this->zip."' AND ".$this->forecastTable.".zip = '".$this->zip."'";
$rs = $this->dbQuery($sql,$this->database);
$nrs = mysql_num_rows($rs);
if($nrs == 0)
{
if($this->error != 1)
{
$this->getXMLdata($this->zip,'cc');
}
if($this->error != 1)
{
$this->getXMLdata($this->zip,'forecast');
}
$this->newZip = true;
}
else
{
while($row = mysql_fetch_array($rs))
{
$ccFiletime = $row['cc'];
$forecastFiletime = $row['forecast'];
$cccache = time() - ($this->currentCondCache* 60);
$forecastCache = time() - (60*60*$this->multiDayforecastCache);
$this->newZip = false;
}
}
}
else
{
if(!is_file($this->cc))
{
if($this->error != 1)
{
$this->getXMLdata($this->zip,'cc');
}
if($this->error != 1)
{
$this->getXMLdata($this->zip,'forecast');
}
$this->newZip = true;
}
else
{
$ccFiletime = filemtime($this->cc);
$forecastFiletime = filemtime($this->forecast);
$cccache = time() - ($this->currentCondCache* 60);
$forecastCache = time() - (60*60*$this->multiDayforecastCache);
$this->newZip = false;
}
}
$this->debug("$ccFiletime <= $cccache or $error == True","cacheControl-cache IF");
if($this->newZip != true)
{
if($ccFiletime <= $cccache or $error == True)
{
$this->getXMLdata($this->zip,'cc');
}
if($forecastFiletime <= $forecastCache or $error == True)
{
$this->getXMLdata($this->zip,'forecast');
}
}
$this->cleanCache();
}
/**
* Get XML Data from weather.com
* @access Private
* @param $zip - Zip code to get XML File for
* @param $type cc = current conditions dayf == forcast
* @return none
*/
function getXMLdata($zip,$type)
{
if($type == "cc")
{
$setup = "cc=*";
$file = $this->cc;
$table = $this->conditionsTable;
}
else
{
$setup = "dayf=".$this->forecastDays;
$file = $this->forecast;
$table = $this->forecastTable;
}
$host = "xoap.weather.com";
$path = "/weather/local/".$zip;
$params = $setup.'&link=xoap&unit='.$this->units.'&prod='.$this->product.'&par='.$this->xoapPar.'&key='.$this->xoapKey;
//http://xoap.weather.com/weather/local/cc=*&link=xoap&unit=s&prod=xoap&par=1003524002&key=6196f50b8fb87a21
if($this->useSocket == false)
{
$stream = "http://".$host.$path."?".$params;
$data = @file($stream);
$xmi=join('',$data);
}
else
{
$xmi = $this->getXMLSocket($host,'GET',$path,$params,1);
$xmi = $this->stripResponseHeader($xmi);
}
$error = $this->errorCheck($xmi);
if($error['number'] == 2)
{
$this->error = 1;
$location = $this->locData($zip);
$this->locSearch($location);
}
else
{
if($xmi != "")
{
if($this->storage == "db")
{
if($this->newZip == true)
{
$sql = "insert into ".$table." values('".$this->zip."','".time()."','".addslashes($xmi)."')";
$this->dbQuery($sql,$this->database);
}
else
{
$sql = "update ".$table." set cache = '".time()."',text = '".addslashes($xmi)."' where zip = '".$this->zip."'";
//echo $sql;
$this->dbQuery($sql,$this->database);
}
}
else
{
$open = fopen($file,"w");
fputs($open,$xmi);
fclose($open);
}
}
}
}
/**
* Checks for cache Files/recorde that are older then 24 Hours old and removes them
* @access Private
* @param None
* @return None
*/
function cleanCache()
{
if($this->storage == "db")
{
$sql = "SELECT *
FROM ".$this->conditionsTable.", ".$this->forecastTable;
$rs = $this->dbQuery($sql,$this->database);
while($row = mysql_fetch_array($rs))
{
if($Purge > $row[cache])
{
$sql = "delete from ".$this->conditionsTable." where zip = '".$row['zip']."'";
$this->dbQuery($sql,$this->database);
$sql = "delete from ".$this->forecastTable." where zip = '".$row['zip']."'";
$this->dbQuery($sql,$this->database);
}
}
}
else
{
$dir = $this->sitePath."/".$this->cacheDir;
$open = opendir($dir);
while($file = readdir($open))
{
if($file == "." or $file == "..")
{
}
else
{
$Filetime = filemtime($dir."/".$file);
$Purge = mktime(date("H")-24,date("i"),0,date("m"),date("d"),date("Y"));
if($Purge > $Filetime)
{
unlink($dir."/".$file);
}
}
}
}
}
/**
* Create Socket connection to weather.com to get XML file
* @access Private
* @param $host - Host to conect to xoap.weather.com
* @param $method - GET or POST
* @param $path - path to file /weather/local
* @param $data - params to pass ?zip=81007&unit=s.......
* @param $useragent - default 0 > 0 send IE as useragent
* @return $buf - buffer from socket request including headers.
*/
function getXMLSocket($host,$method,$path,$data,$useragent=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method)) {
$method = 'GET';
}
$method = strtoupper($method);
$fp = @fsockopen($host, 80);
if (!$fp) {
//echo "$errstr ($errno) \n";
} else {
if ($method == 'GET') {
$path .= '?' . $data;
}
fputs($fp, "$method $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n");
if ($useragent) {
fputs($fp, "User-Agent: MSIE\r\n");
}
if ($method == 'POST') {
fputs($fp,"Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
}
fputs($fp, "Connection: close\r\n\r\n");
if ($method == 'POST') {
fputs($fp, $data);
}
while (!feof($fp)) {
$buf .= fgets($fp,128);
}
fclose($fp);
}
$this->debug($buf,"getXMLSocket");
return $buf;
}
/*
* Removes the Response header that's returned from a host after a request is made
* @access private
* @param string $source The html, including the response header, to be stripped
* @return string The source without the response header
*/
function stripResponseHeader($source)
{
$this->debug($source,"StripResponseHeaders - Start");
$start = strpos($source,"");
$total = $stop - $start;
$newSource = substr($source,$start,$total+10);
if($newSource == "")
{
$start = strpos($source,"");
$total = $stop - $start;
$newSource = substr($source,$start,$total+10);
}
$this->debug($newSource,"StripResponseHeaders - end");
return $newSource;
}
/**
* Checks for errors in the XML file and handles them accordingly
* @access Public
* @param $file string filename of the xml file that we are currenly loading
* @return $error string True or NULL for detecting errors in the XML Feed
*/
function errorCheck($file)
{
/*
if there is as problem with the XML file you request The weather channel returns an errror XML File
here we take the errors and Display.
*/
$tree = $this->GetXMLTree($file);
$error['number'] = $tree[ERROR][0][ERR][0][ATTRIBUTES][TYPE];
$error['type'] = $tree[ERROR][0][ERR][0][VALUE];
if($error['type'] != "" or $error['number'] != "")
{
$error['exists'] = True;
}
$this->debug($error,"errorCheck");
return $error;
}
/**
* Displays an the error message in the XML Feed
* @access Public
* @param $errror String True or NULL
* @return None
*/
function errorMsg($error)
{
?>
WARNING: Error Detected Type: echo $error['type']; ?> Number: echo $error['number']; ?>
Please Contact echo $this->Administrator; ?>
}
/**
* Get the Children data from and XML file
* @access Public
* @param $vals Array current Nodes in the XML File
* @param $i Integer current Increment in the process
* @return Return Array Children for Node
*/
function GetChildren($vals, &$i)
{
$children = array(); // Contains node data
/* Node has CDATA before it's children */
if (isset($vals[$i]['value']))
$children['VALUE'] = $vals[$i]['value'];
/* Loop through children */
while (++$i < count($vals))
{
switch ($vals[$i]['type'])
{
/* Node has CDATA after one of it's children
(Add to cdata found before if this is the case) */
case 'cdata':
if (isset($children['VALUE']))
$children['VALUE'] .= $vals[$i]['value'];
else
$children['VALUE'] = $vals[$i]['value'];
break;
/* At end of current branch */
case 'complete':
if (isset($vals[$i]['attributes'])) {
$children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes'];
$index = count($children[$vals[$i]['tag']])-1;
if (isset($vals[$i]['value']))
$children[$vals[$i]['tag']][$index]['VALUE'] = $vals[$i]['value'];
else
$children[$vals[$i]['tag']][$index]['VALUE'] = '';
} else {
if (isset($vals[$i]['value']))
$children[$vals[$i]['tag']][]['VALUE'] = $vals[$i]['value'];
else
$children[$vals[$i]['tag']][]['VALUE'] = '';
}
break;
/* Node has more children */
case 'open':
if (isset($vals[$i]['attributes'])) {
$children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes'];
$index = count($children[$vals[$i]['tag']])-1;
$children[$vals[$i]['tag']][$index] = array_merge($children[$vals[$i]['tag']][$index],$this->GetChildren($vals, $i));
} else {
$children[$vals[$i]['tag']][] = $this->GetChildren($vals, $i);
}
break;
/* End of node, return collected data */
case 'close':
return $children;
}
}
}
/**
* Function will attempt to open the xmlloc as a local file, on fail it will attempt to open it as a web link
* @access Public
* @param string XML File to load
* @return $tree array of data in the XML file
*/
function GetXMLTree($xmlloc)
{
if(is_array($xmlloc))
{
$data = implode('', $xmlloc);
}
else
{
if($this->storage == "db")
{
$data = $xmlloc;
}
else
{
if(file_exists($xmlloc))
{
$data = implode('', file($xmlloc));
}
}
}
$parser = xml_parser_create('ISO-8859-1');
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $vals, $index);
xml_parser_free($parser);
$tree = array();
$i = 0;
if (isset($vals[$i]['attributes']))
{
$tree[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes'];
$index = count($tree[$vals[$i]['tag']])-1;
$tree[$vals[$i]['tag']][$index] = array_merge($tree[$vals[$i]['tag']][$index], $this->GetChildren($vals, $i));
}
else
{
$tree[$vals[$i]['tag']][] = $this->GetChildren($vals, $i);
}
return $tree;
}
/**
* Parses forecast XML file
* @access Public
* @param None
* @return $forecast Array Contains and array with of the data in the forecast XML file
*/
function forecastData()
{
/*
Here we are taking the Array from the XML file and putting it into an manageble array
*/
if($this->storage == "db")
{
$sql = "select * from ".$this->forecastTable." where zip = '".$this->zip."'";
$rs = $this->dbQuery($sql,$this->database);
$row = mysql_fetch_object($rs);
$xmi = $row->text;
}
else
{
$xmi = $this->forecast;
}
$tree = $this->GetXMLTree($xmi);
$days = $tree[WEATHER][0][DAYF][0][DAY];
$error = $this->errorCheck($xmi);
$forecast[0]['loc'] = $tree[WEATHER][0][LOC][0][DNAM][0][VALUE];
$forecast[0]['lsup'] = $tree[WEATHER][0][DAYF][0][LSUP][0][VALUE];
$forecast[0]['unitsTemp'] = $tree[WEATHER][0][HEAD][0][UT][0][VALUE];
$forecast[0]['unitsDistance'] = $tree[WEATHER][0][HEAD][0][UD][0][VALUE];
$forecast[0]['unitsSpeed'] = $tree[WEATHER][0][HEAD][0][US][0][VALUE];
$forecast[0]['unitsPrecip'] = $tree[WEATHER][0][HEAD][0][UP][0][VALUE];
$forecast[0]['tempPressure'] = $tree[WEATHER][0][HEAD][0][UR][0][VALUE];
$forecast[0]['linkOne'] = $tree[WEATHER][0][LNKS][0][LINK][0][L][0][VALUE];
$forecast[0]['titleOne'] = $tree[WEATHER][0][LNKS][0][LINK][0][T][0][VALUE];
$forecast[0]['linkTwo'] = $tree[WEATHER][0][LNKS][0][LINK][1][L][0][VALUE];
$forecast[0]['titleTwo'] = $tree[WEATHER][0][LNKS][0][LINK][1][T][0][VALUE];
$forecast[0]['linkThree'] = $tree[WEATHER][0][LNKS][0][LINK][2][L][0][VALUE];
$forecast[0]['titleThree'] = $tree[WEATHER][0][LNKS][0][LINK][2][T][0][VALUE];
$forecast[0]['linkFour'] = $tree[WEATHER][0][LNKS][0][LINK][3][L][0][VALUE];
$forecast[0]['titleFour'] = $tree[WEATHER][0][LNKS][0][LINK][3][T][0][VALUE];
/*
With the Current Conditions we have up to 10 days of data that needs to be collected
we do that here by looping though and grabbing the data
*/
for($i=0; $ierror == 1)
{
}
else
{
if($forecast[0]['error']['exists'] != True)
{
?>
echo $this->forecastDays; ?> day forecast for echo $forecast[0]['loc']; ?>
for($i=0; $i<$this->forecastDays; $i++)
{
$tod = "d";
$hi = " High: ".$forecast[$i]['hi']."° ";
$lo =" Low: ".$forecast[$i]['lo']."°";
if(date("H") > 14 and $i == 0)
{
$tod = "n";
$hi = "";
$lo = " Tonights Low: ".$forecast[$i]['lo']."°";
}
?>
echo $hi; ?> echo $lo; ?>
echo $forecast[$i]['part'][$tod]['cond']; ?> - (Precip. echo $forecast[$i]['part'][$tod]['ppcp']; ?>%)
}
?>
Last Updated echo $forecast[0]['lsup']; ?>
}
else
{
$this->errorMsg($cc['error']);
}
}
}
/**
* Displays the Default forecast for the selected date and ZipCode
* @access Public
* @param $forecast Array Data from XML File
* @param $did Integer Day ID needed to build the forecast Details
* @return None
*/
function detailforecast($forecast,$did)
{
/*
Here we needed to know if it was after 1400 hours as that is when the Weather channel no
longer send the data for that morning in the forecast file so we only show the
evening forecast after 1400 hours
*/
$tod = "day";
if($this->error == 1)
{
}
else
{
if($forecast[0]['error']['exists'] != True)
{
$hi = $forecast[$did]['hi'];
$lo = $forecast[$did]['lo'];
if(date("H") > 14 and $did == 0)
{
$tod = "night";
}
?>
Forecast for echo $forecast[$did]['wkday']." ".$forecast[$did]['date']; ?>
if($tod != "night")
{
?>
Day
echo $forecast[$did]['part']['d']['cond']; ?> echo $hi; ?>° echo $forecast[0]['unitsTemp']; ?>
Humidity
echo $forecast[$did]['part']['d']['humid']; ?>%
Wind Speed
echo $forecast[$i]['part']['d']['winddir']; ?> echo $forecast[$did]['part']['d']['windspeed']; ?> echo $forecast[0]['unitsSpeed']; ?>
Wind Gusts
echo $forecast[$i]['part']['d']['winddir']; ?> echo $forecast[$did]['part']['d']['windgust'] == "N/A" ? "N/A" : $forecast[$did]['part']['d']['windgust']." ".$forecast[0]['unitsSpeed']; ?>
Precipitation
echo $forecast[$did]['part']['d']['ppcp']; ?>%
}
?>
Night
echo $forecast[$did]['part']['n']['cond']; ?> echo $hi; ?>° echo $forecast[0]['unitsTemp']; ?>
Humidity
echo $forecast[$did]['part']['n']['humid']; ?>%
Wind Speed
echo $forecast[$i]['part']['n']['winddir']; ?> echo $forecast[$did]['part']['n']['windspeed']; ?> echo $forecast[0]['unitsSpeed']; ?>
Wind Gusts
echo $forecast[$i]['part']['n']['winddir']; ?> echo $forecast[$did]['part']['n']['windgust'] == "N/A" ? "N/A" : $forecast[$did]['part']['n']['windgust']." ".$forecast[0]['unitsSpeed']; ?>
Precipitation
echo $forecast[$did]['part']['n']['ppcp']; ?>%
Last Updated echo $cc['lastUpdate']; ?>
}
else
{
$this->errorMsg($cc['error']);
}
}
}
/**
* Gets the Current Conditions data from the XML file and puts it into and aarry
* @access Public
* @param None
* @return $cc Array Current Conditions Data
*/
function ccData()
{
/*
Grabbing the Current XML data for the Current Condition and the Current Conditions details
*/
if($this->storage == "db")
{
$sql = "select * from ".$this->conditionsTable." where zip = '".$this->zip."'";
$rs = $this->dbQuery($sql,$this->database);
$row = mysql_fetch_object($rs);
$xmi = $row->text;
$this->debug($xmi,"ccData");
}
else
{
$xmi = $this->cc;
}
$tree = $this->GetXMLTree($xmi);
$error = $this->errorCheck($xmi);
$cc['linkOne'] = $tree[WEATHER][0][LNKS][0][LINK][0][L][0][VALUE];
$cc['titleOne'] = $tree[WEATHER][0][LNKS][0][LINK][0][T][0][VALUE];
$cc['linkTwo'] = $tree[WEATHER][0][LNKS][0][LINK][1][L][0][VALUE];
$cc['titleTwo'] = $tree[WEATHER][0][LNKS][0][LINK][1][T][0][VALUE];
$cc['linkThree'] = $tree[WEATHER][0][LNKS][0][LINK][2][L][0][VALUE];
$cc['titleThree'] = $tree[WEATHER][0][LNKS][0][LINK][2][T][0][VALUE];
$cc['linkFour'] = $tree[WEATHER][0][LNKS][0][LINK][3][L][0][VALUE];
$cc['titleFour'] = $tree[WEATHER][0][LNKS][0][LINK][3][T][0][VALUE];
$cc['unitsTemp'] = $tree[WEATHER][0][HEAD][0][UT][0][VALUE];
$cc['unitsDistance'] = $tree[WEATHER][0][HEAD][0][UD][0][VALUE];
$cc['unitsSpeed'] = $tree[WEATHER][0][HEAD][0][US][0][VALUE];
$cc['unitsPrecip'] = $tree[WEATHER][0][HEAD][0][UP][0][VALUE];
$cc['tempPressure'] = $tree[WEATHER][0][HEAD][0][UR][0][VALUE];
$cc['location'] = $tree[WEATHER][0][LOC][0][ATTRIBUTES][ID];
$cc['sunrise'] = $tree[WEATHER][0][LOC][0][SUNR][0][VALUE];
$cc['sunset'] = $tree[WEATHER][0][LOC][0][SUNS][0][VALUE];
$cc['lastUpdate'] = $tree[WEATHER][0][CC][0][LSUP][0][VALUE];
$cc['observStation'] = $tree[WEATHER][0][CC][0][OBST][0][VALUE];
$cc['temp'] = $tree[WEATHER][0][CC][0][TMP][0][VALUE];
$cc['feelsLike'] = $tree[WEATHER][0][CC][0][FLIK][0][VALUE];
$cc['conditons'] = $tree[WEATHER][0][CC][0][T][0][VALUE];
$cc['icon'] = $tree[WEATHER][0][CC][0][ICON][0][VALUE];
$cc['baromoter'] = $tree[WEATHER][0][CC][0][BAR][0][R][0][VALUE];
$cc['baromoterDesc'] = $tree[WEATHER][0][CC][0][BAR][0][D][0][VALUE];
$cc['wind'] = $tree[WEATHER][0][CC][0][WIND][0][S][0][VALUE];
$cc['windGust'] = $tree[WEATHER][0][CC][0][WIND][0][GUST][0][VALUE];
$cc['windDirdeg'] = $tree[WEATHER][0][CC][0][WIND][0][D][0][VALUE];
$cc['windDirname'] = $tree[WEATHER][0][CC][0][WIND][0][T][0][VALUE];
$cc['humidity'] = $tree[WEATHER][0][CC][0][HMID][0][VALUE];
$cc['visibility'] = $tree[WEATHER][0][CC][0][VIS][0][VALUE];
$cc['uv'] = $tree[WEATHER][0][CC][0][UV][0][I][0][VALUE];
$cc['uvDesc'] = $tree[WEATHER][0][CC][0][UV][0][T][0][VALUE];
$cc['dewPoint'] = $tree[WEATHER][0][CC][0][DEWP][0][VALUE];
$cc['error'] = $error;
return $cc;
}
/**
* Displays Current Condtion
* @access Public
* @param $cc Array array containing the Current Conditions Data
* @return None
*/
function currentConditions($cc)
{
if($cc['error']['exists'] != True)
{
?>
| Weather in Bandon Oregon |
![<? echo $cc['conditons']; ?>](/weather/wxicons/128/<? echo $cc['icon']; ?>.png) |
echo $cc['temp']; ?>° echo $cc['conditons']; ?>
|
}
else
{
$this->errorMsg($cc['error']);
}
}
/**
* Displays Current Condition Details
* @access Public
* @param $cc Array array containing the Current Conditions Data
* @return None
*/
function ccDetails($cc)
{
if($this->error == 1)
{
}
else
{
if($cc['error']['exists'] != True)
{
?>
Conditions for echo $cc['observStation']; ?>
![<? echo $cc['conditons']; ?>](/weather/wxicons/128/<? echo $cc['icon']; ?>.png)
echo $cc['conditons']; ?>
echo $cc['temp']; ?>° echo $cc['unitsTemp']; ?>
Feels Like
echo $cc['feelsLike']; ?>° echo $cc['unitsTemp']; ?>
Humidity
echo $cc['humidity']; ?>%
Wind Speed
echo $cc['wind'] == "calm" ? "Calm" : $cc['windDirname']." ".$cc['wind']." ".$cc['unitsSpeed']; ?> echo $cc['windGust'] == "N/A" ? "" : "(gusting to ".$cc['windGust']." ".$cc['unitsSpeed'].")"; ?>
Barometer
echo $cc['baromoter']; ?>" echo $cc['baromoterDesc']; ?>
Dewpoint
echo $cc['dewPoint']; ?>° echo $cc['unitsTemp']; ?>
Visibility
echo $cc['visibility'] == "Unlimited" ? $cc['visibility'] : $cc['visibility']." ".$cc['unitsDistance']; ?>
UV Index
echo $cc['uv'];?> echo $cc['uvDesc']; ?>
Sunrise
echo $cc['sunrise']; ?>
Sunset
echo $cc['sunset']; ?>
Last Updated echo $cc['lastUpdate']; ?>
}
else
{
$this->errorMsg($cc['error']);
}
}
}
/**
* Performs search for an invalid zip code
* @access Public
* @param $loc - location weather its a zip code or city name
* @return $info - array containing zip and city name
*/
function locData($loc)
{
//$stream = "http://xoap.weather.com/search/search?where=".$loc;
$host = "xoap.weather.com";
$path = "/search/search";
$params = "where=".$loc;
if($this->useSocket == false)
{
$stream = "http://".$host.$path."?".$params;
$data = @file($stream);
$xmi=join('',$data);
}
else
{
$data = $this->getXMLSocket($host,'GET',$path,$params,1);
$start = strpos($data,"");
$total = $stop - $start;
$xmi = substr($data,$start,$total+10);
}
$this->debug($xmi,"locData-Stream");
if($xmi != "")
{
$tree = $this->GetXMLTree($xmi);
for($i=0; $idebug($info,"locData-Info");
return $info;
}
/**
* Displays search form
* @access Public
* @param $loc - array array containing zip and city name
* @return None
*/
function locSearch($loc)
{
$total = count($loc);
if($total == 0)
{
?>
City SearchWe were not able to locate any Locations that matched the information you entered. If you entred an actual zip
code please check to see that you entered it correctly. If you entred a City name please check that the name you entered is spelled correctly and try again.
}
else
{
?>
Search ResultsSorry we were unable to locate the city/zip you entered. We did locate several cities/zip
codes that match. Please select the City from the list below to view the Weather for that city.
}
}
/**
* echo out debug information from application
* @access Public
* @param $msg - info to be output
* @param $func - function debug was called from
* @return None
*/
function debug($msg,$func)
{
if($this->debug == true)
{
if(is_array($msg))
{
echo "DEBUG($func)[".$this->dubugCount."]:";
print_r($msg);
echo " ";
}
else
{
echo "DEBUG($func)[".$this->dubugCount."]: $msg ";
}
$this->dubugCount++;
}
}
###########################################################################################################
}//End Class
?>
Fatal error: Class 'xoapWeather' not found in /www/htdocs/chaswaldrop/webfront/bandon-information/index.php on line 99
| |