Class for fetching data from www.yr.no.
<?php
class yrFetch {
// If database buffering is on: Handle to open MySQL connection. NULL if database buffering is off.
private $sqlHandle;
// If file buffering is on: Directory of buffer files. NULL if file buffering is off.
private $bufferDir;
// Language
private $language;
// Name of buffer table
const tableName='yr_buffer';
// Debug information
private $debugStr;
private $debugOn;
public function __construct($debug=false, $language=LANG_YR_NORWEGIAN)
/*
Constructor
$language (string): Language. Must be either:
LANG_YR_NORWEGIAN
LANG_YR_NEWNORWEGIAN
LANG_YR_ENGLISH
$debug (string): Turn debug mode on/off. Use function getDebug() to get debug string.
*/
public function sqlBuffering($sqlHandle)
/*
Turns on buffering in MySQL database.
$sqlHandle: Handle to open MySQL connection.
NOTE: If file buffering is on, it will be turned off.
Returns: Nothing.
*/
public function fileBuffering($directory)
/*
Turns on file buffering.
$directory (string): Directory where buffer files are stored. Make sure the script
has read and write access to this directory.
NOTE: If database buffering is on, it will be turned off.
Returns: Nothing.
*/
public function getXml($county, $commune, $place)
/*
Returns XML weather data from a specific location in Norway.
$county (string): County (fylke)
$commune (string): Commune (kommune)
$place (string): Place (sted)
IMPORTANT: All names are case sensitive!!
Returns (string): Weather data from this location as XML. Null on any error.
NOTE: Errors can be caused by:
1. No connection to yr.no
2. $county, $commune or $place is incorrect.
3. You've specified an incorrect language in the constructor.
*/
public function getYrData($county, $commune, $place)
/*
Returns weather data from a specific location in Norway as a yrData object.
$county (string): County (fylke)
$commune (string): Commune (kommune)
$place (string): Place (sted)
IMPORTANT: All names are case sensitive!!
Returns (object): yrData object. Null on any error.
NOTE: Errors can be caused by:
1. No connection to yr.no
2. $county, $commune or $place is incorrect.
3. You've specified an incorrect language in the constructor.
*/
public function createTable()
/*
Creates table for information buffering.
IMPORTANT: The constructor must have been called with a MySQL handle before calling this
function.
Returns (bool): True on success, false on any error.
*/
public function getDebug($newline="<br/>")
/*
Returns debug string.
$newline (string): Newline character. For instance, user '<br/>' if displayed in HTML
context.
*/
private function setDebug($s)
/*
Inserts $s in the debug string if debug is on.
Returns nothing.
*/
private function fetch($county, $commune, $place, $location_md5)
/*
- Downloads weather data and returns as XML and yrData object.
- Stores downloaded values in database.
$county (string): County (fylke)
$commune (string): Commune (kommune)
$place (string): Place (sted)
$location_md5 (string): MD5 hash of location.
Returns (array of mixed):
[xml]: As XML
[yrdata]: As yrData object
*/
}
?>