Go to the documentation of this file.00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 {
00004 header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005 echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006 echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007 exit(1);
00008 }
00018 class googlemaps
00019 {
00020 var $latlong="-34.397, 150.644";
00021 var $zoom="14";
00022 var $maptype="ROADMAP";
00023 var $divid="map_canvas";
00024 var $divwidth="300px";
00025 var $divheight="300px";
00026 var $counter="0";
00027 var $includejs="<script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=false\"></script>";
00028 var $mainjs = "";
00029 function render($text)
00030 {
00031 global $sourceFolder;
00032 global $uploadFolder;
00033 global $urlRequestRoot, $cmsFolder;
00034 global $STARTSCRIPTS;
00035 preg_match_all("/\[googlemaps\](.*?)\[\/googlemaps\]/si", $text, $matches);
00036
00037 if(count($matches[0])==0)
00038 return $text;
00039
00040
00041 $address = array();
00042
00043 for ($i = 0; $i < count($matches[0]); $i++) {
00044 $position = strpos($text, $matches[0][$i]);
00045 $address[] = $matches[1][$i];
00046 $div=$this->get_div($i);
00047 $text = substr_replace($text, $div, $position, strlen($matches[0][$i]));
00048 }
00049 $mainjs=$this->generate_js($i,$address);
00050 $STARTSCRIPTS.="googlemaps_initialize();";
00051 return $this->includejs.$mainjs.$text;
00052
00053
00054 }
00055 function get_div($id)
00056 {
00057
00058 $div = " <div id=\"{$this->divid}{$id}\" style=\"width: {$this->divwidth}; height: {$this->divheight};\"></div>";
00059 return $div;
00060 }
00061 function generate_js($count,$address)
00062 {
00063 $varmaps= array();
00064 $varaddr= array();
00065 $varobj= array();
00066 for($i=0;$i<$count;$i++)
00067 {
00068 $varmaps[]="maps$i";
00069 $varaddr[]=<<<ADDR
00070 var address$i = "{$address[$i]}";
00071 geocoder.geocode( { 'address': address$i}, function(results, status) {
00072 if (status == google.maps.GeocoderStatus.OK) {
00073 map$i.setCenter(results[0].geometry.location);
00074 var marker = new google.maps.Marker({
00075 map: map$i,
00076 position: results[0].geometry.location
00077 });
00078 } else {
00079 alert("Geocode was not successful for the following reason: " + status);
00080 }
00081 });
00082 ADDR;
00083 $varobj[]="map$i = new google.maps.Map(document.getElementById(\"{$this->divid}{$i}\"), myOptions);";
00084 }
00085
00086 $varmapsj=implode(",",$varmaps);
00087 $varaddrj=implode("\n",$varaddr);
00088 $varobjj=implode("\n",$varobj);
00089 $mainjs=<<<JS
00090 <script>
00091 var geocode;
00092 var $varmapsj;
00093 function codeAddress() {
00094 $varaddrj
00095 }
00096 function googlemaps_initialize() {
00097 geocoder = new google.maps.Geocoder();
00098 var latlng = new google.maps.LatLng({$this->latlong});
00099 var myOptions = {
00100 zoom: {$this->zoom},
00101 center: latlng,
00102 mapTypeId: google.maps.MapTypeId.{$this->maptype}
00103 }
00104 $varobjj
00105 codeAddress();
00106 }
00107
00108 </script>
00109 JS;
00110 return $mainjs;
00111
00112 }
00113
00114 }