* @copyright 2005 system7designs */ class PhoogleHelper extends Helper{ /** * validPoints : array * Holds addresses and HTML Messages for points that are valid (ie: have longitude and latitutde) */ var $validPoints = array(); /** * invalidPoints : array * Holds addresses and HTML Messages for points that are invalid (ie: don't have longitude and latitutde) */ var $invalidPoints = array(); /** * mapWidth * width of the Google Map, in pixels */ var $mapWidth = 300; /** * mapHeight * height of the Google Map, in pixels */ var $mapHeight = 300; /** * apiKey * Google API Key */ var $apiKey = ""; /** * showControl * True/False whether to show map controls or not */ var $showControl = true; /** * showType * True/False whether to show map type controls or not */ var $showType = true; /** * showPanoramio * True/False whether to show Panoramio imagen on map or not */ var $showPanoramio = false; /** * controlType * string: can be 'small' or 'large' * display's either the large or the small controls on the map, small by default */ var $controlType = 'small'; /** * zoomLevel * int: 0-17 * set's the initial zoom level of the map */ var $zoomLevel = 4; /** * @function addGeoPoint * @description Add's an address to be displayed on the Google Map using latitude/longitude * early version of this function, considered experimental */ function addGeoPoint($lat,$long,$infoHTML){ $pointer = count($this->validPoints); $this->validPoints[$pointer]['lat'] = $lat; $this->validPoints[$pointer]['long'] = $long; $this->validPoints[$pointer]['htmlMessage'] = $infoHTML; } /** * @function centerMap * @description center's Google Map on a specific point * (thus eliminating the need for two different show methods from version 1.0) */ function centerMap($lat,$long){ $this->centerMap = "map.centerAndZoom(new GPoint(".$long.",".$lat."), ".$this->zoomLevel.");\n"; } /** * @function addAddress * @param $address:string * @returns Boolean True:False (True if address has long/lat, false if it doesn't) * @description Add's an address to be displayed on the Google Map * (thus eliminating the need for two different show methods from version 1.0) */ function addAddress($address,$htmlMessage=null){ if (!is_string($address)){ die("All Addresses must be passed as a string"); } $apiURL = "http://maps.google.com/maps/geo?&output=xml&key=".$this->apiKey."&q="; $addressData = file_get_contents($apiURL.urlencode($address)); $results = $this->xml2array(utf8_encode($addressData)); if (empty($results['kml']['Response']['Placemark']['Point']['coordinates'])){ $pointer = count($this->invalidPoints); $this->invalidPoints[$pointer]['lat']= $results['kml']['Response']['Placemark']['Point']['coordinates'][0]; $this->invalidPoints[$pointer]['long']= $results['kml']['Response']['Placemark']['Point']['coordinates'][1]; $this->invalidPoints[$pointer]['passedAddress'] = $address; $this->invalidPoints[$pointer]['htmlMessage'] = $htmlMessage; }else{ $pointer = count($this->validPoints); $this->validPoints[$pointer]['lat']= $results['kml']['Response']['Placemark']['Point']['coordinates']; $this->validPoints[$pointer]['long']= $results['kml']['Response']['Placemark']['Point']['coordinates']; $this->validPoints[$pointer]['passedAddress'] = $address; $this->validPoints[$pointer]['htmlMessage'] = $htmlMessage; } } /** * @function showValidPoints * @param $displayType:string * @param $css_id:string * @returns nothing * @description Displays either a table or a list of the address points that are valid. * Mainly used for debugging but could be useful for showing a list of addresses * on the map */ function showValidPoints($displayType,$css_id){ $total = count($this->validPoints); if ($displayType == "table"){ echo "\n\n\t\n\n"; for ($t=0; $t<$total; $t++){ echo"\n\t\n\n"; } echo "
Address
".$this->validPoints[$t]['passedAddress']."
\n"; } if ($displayType == "list"){ echo "\n"; } } /** * @function showInvalidPoints * @param $displayType:string * @param $css_id:string * @returns nothing * @description Displays either a table or a list of the address points that are invalid. * Mainly used for debugging shows only the points that are NOT on the map */ function showInvalidPoints($displayType,$css_id){ $total = count($this->invalidPoints); if ($displayType == "table"){ echo "\n\n\t\n\n"; for ($t=0; $t<$total; $t++){ echo"\n\t\n\n"; } echo "
Address
".$this->invalidPoints[$t]['passedAddress']."
\n"; } if ($displayType == "list"){ echo "\n"; } } /** * @function setWidth * @param $width:int * @returns nothing * @description Sets the width of the map to be displayed */ function setWidth($width){ $this->mapWidth = $width; } /** * @function setHeight * @param $height:int * @returns nothing * @description Sets the height of the map to be displayed */ function setHeight($height){ $this->mapHeight = $height; } /** * @function setAPIkey * @param $key:string * @returns nothing * @description Stores the API Key acquired from Google */ function setAPIkey($key){ $this->apiKey = $key; } /** * @function printGoogleJS * @returns nothing * @description Adds the necessary Javascript for the Google Map to function * should be called in between the html tags */ function printGoogleJS(){ echo "\n\n"; } /** * @function showMap * @description Displays the Google Map on the page */ function showMap(){ echo "\n
mapWidth."px; height: ".$this->mapHeight."px\">\n
\n"; echo " \n"; } ///////////THIS BLOCK OF CODE IS FROM Roger Veciana's CLASS (assoc_array2xml) OBTAINED FROM PHPCLASSES.ORG////////////// function xml2array($xml){ $this->depth=-1; $this->xml_parser = xml_parser_create(); xml_set_object($this->xml_parser, $this); xml_parser_set_option ($this->xml_parser,XML_OPTION_CASE_FOLDING,0);//Don't put tags uppercase //xml_parser_set_option ($this->xml_parser,XML_OPTION_SKIP_WHITE,1);//Sigh xml_set_element_handler($this->xml_parser, "startElement", "endElement"); xml_set_character_data_handler($this->xml_parser,"characterData"); xml_parse($this->xml_parser,$xml,true); xml_parser_free($this->xml_parser); return $this->arrays[0]; } function startElement($parser, $name, $attrs){ $this->keys[]=$name; $this->node_flag=1; $this->depth++; //$this->log("startElement(\$parser, $name, $attrs): " . var_export($this->arrays, true), LOG_DEBUG); } function characterData($parser,$data){ if(!trim($data)) return; // strips all whitespace strings $key=end($this->keys); $this->arrays[$this->depth][$key]=$data; $this->node_flag=0; //$this->log("characterData(\$parser, $data): " . var_export($this->arrays, true), LOG_DEBUG); } function endElement($parser, $name) { $key=array_pop($this->keys); if($this->node_flag==1){ $this->arrays[$this->depth][$key]=$this->arrays[$this->depth+1]; unset($this->arrays[$this->depth+1]); } $this->node_flag=1; $this->depth--; //$this->log("endElement(\$parser, $name): " . var_export($this->arrays, true), LOG_DEBUG); } //////////////////END CODE FROM Roger Veciana's CLASS (assoc_array2xml) ///////////////////////////////// }//End Of Class ?>