01-12-2010, 10:49 AM
|
#10 (permalink)
|
|
The Wanderer
Join Date: Jan 2010
Posts: 7
Thanks: 0
|
Out of nothing to do, I have created two classes for you that you can use. Hope you can use php5 as I noticed that you are doing everything in php4.
Can't help you with anything else. Learn from what I've given you and let me know if something is not clear.
Here's the code:
PHP Code:
<?php
class Swellnet_Locations
{
// states
const STATE_QUEENSLAND = 1;
const STATE_NEW_SOUTH_WALES = 2;
const STATE_VICTORIA = 3;
const STATE_SOUTH_AUSTRALIA = 4;
const STATE_WESTERN_AUSTRALIA = 5;
const STATE_TASMANIA = 6;
// Queensland
const REGION_GOLD_COAST = 17;
const REGION_SUNSHINE_COAST = 18;
const REGION_AGNES_WATER = 1;
const REGION_BALLINA = 3;
const REGION_YAMBA = 16;
// New South Wales
const REGION_COFFS_HARBOUR = 7;
const REGION_PT_MACQUARIE = 11;
const REGION_NEWCASTLE = 10;
const REGION_CENTRAL_COAST = 6;
const REGION_NARRABEEN = 13;
const REGION_CURL_CURL = 12;
const REGION_BONDI = 4;
const REGION_MAROUBRA = 9;
const REGION_CRONULLA = 8;
const REGION_WOLLONGONG = 15;
// Victoria
const REGION_WARRNAMBOOL = 34;
const REGION_TORQUAY = 28;
const REGION_13TH_BEACH = 27;
const REGION_MORNINGTON_PEN = 31;
const REGION_WESTERN_PORT = 32;
const REGION_PHILLIP_ISLAND = 35;
const REGION_WOOLAMAI = 33;
// South Australia
const REGION_MID_COAST = 19;
const REGION_VICTOR_HARBOR = 22;
// Tasmania
const REGION_NORTH_EAST = 25;
const REGION_HOBART = 26;
// Western Australia
const REGION_MARGARET_RIVER = 38;
const REGION_PERTH = 39;
const REGION_GERALDTON = 37;
}
class Swellnet_Graph
{
// swellnet url mask
const URL_MASK = 'http://swellnet.com.au/loc_report.php?state_id=%d®ion_id=%d';
// class variables
private $_html = null;
private $_url = null;
private $_params = null;
/**
* Class constructor
*
* @param integer $state State id
* @param integer $region Region id
* @return SwellGraph
*/
public function __construct($state, $region)
{
// generate the url
$this->_url = sprintf(self::URL_MASK, $state, $region);
// get html of the target url
$this->_html = file_get_contents($this->_url);
// fail if couldn't open the url
if ($this->_html === false) {
throw new Exception('Could not fetch contents of ' . $this->_url);
}
// attempt to extract the graph source url
preg_match('/value=\"(\/graph-mod\.swf\?.*?)\"/si', $this->_html, $matches);
// fail if the number of matches is incorrect
if (count($matches) != 2) {
throw new Exception('Error extracting the graph source');
}
// extract url parameters
$url = $matches[1];
$parse = parse_url($url);
parse_str($parse['query'], $this->_params);
}
/**
* Return request url
*
* @return string
*/
public function getUrl()
{
return $this->_url;
}
/**
* Return request html
*
* @return string
*/
public function getHtml()
{
return $this->_html;
}
/**
* Return resulting parameters
*
* @return array
*/
public function getParams()
{
return $this->_params;
}
}
// fetch parameters of the graph
$sg = new Swellnet_Graph(Swellnet_Locations::STATE_QUEENSLAND, Swellnet_Locations::REGION_GOLD_COAST);
var_dump($sg->getUrl());
var_dump($sg->getParams());
Hope that helps.
|
|
|
|