// We calling this directly, if so, your evil... if (!defined('SMF')) die('Hacking attempt...'); function Map() { global $db_prefix, $context; // Are we allowed to view the map? Keep in mind here we should be a guest unless user is in IE! isAllowedTo('googleMap_view'); //Lets try this to make it work on first click... //loadUserSettings(); writeLog(); //Map using the internal XML File? Or the JS file? if (isset($_GET['sa']) && $_GET['sa'] == '.xml') return MapsXML(); if (isset($_GET['sa']) && $_GET['sa'] == '.js') return MapsJS(); // Get the template ready.... not really much else to do. //loadLanguage('MemberMap'); loadTemplate('GoogleMap'); $context['sub_template'] = 'map'; $context['page_title'] = "Member Map"; } function MapsJS() { global $db_prefix, $context, $scripturl, $txt, $modSettings, $user_info; // Lets dump everything in the buffer and start clean and new and fresh ob_end_clean(); if (!empty($modSettings['enableCompressedOutput'])) @ob_start('ob_gzhandler'); else ob_start(); echo ' onerror=handleErr var txt="" function handleErr(msg,url,l) { txt="There was an error on this page.\n\n" txt+="Error: " + msg + "\n" txt+="URL: " + url + "\n" txt+="Line: " + l + "\n\n" txt+="Click OK to continue.\n\n" //alert(txt) return true } // Globals. //Icon(s), and if gender is enabled, php will allow those to be defined. var icon = new GIcon(); icon.image = "http://labs.google.com/ridefinder/images/mm_20_green.png"; icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; icon.iconSize = new GSize(12, 20); icon.shadowSize = new GSize(22, 20); icon.iconAnchor = new GPoint(6, 20); icon.infoWindowAnchor = new GPoint(5, 1); // For that lovly clustering thing! var clusterIcon = new GIcon(); clusterIcon.image = "http://labs.google.com/ridefinder/images/mm_20_purple.png"; clusterIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; clusterIcon.iconSize = new GSize(12, 20); clusterIcon.shadowSize = new GSize(22, 20); clusterIcon.iconAnchor = new GPoint(6, 20); clusterIcon.infoWindowAnchor = new GPoint(5, 1);'; if ($modSettings['googleMapsPinGender']) echo ' var iconm = new GIcon(); iconm.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png"; iconm.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; iconm.iconSize = new GSize(12, 20); iconm.shadowSize = new GSize(22, 20); iconm.iconAnchor = new GPoint(6, 20); iconm.infoWindowAnchor = new GPoint(5, 1); var iconf = new GIcon(); iconf.image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; iconf.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; iconf.iconSize = new GSize(12, 20); iconf.shadowSize = new GSize(22, 20); iconf.iconAnchor = new GPoint(6, 20); iconf.infoWindowAnchor = new GPoint(5, 1);'; echo ' if (GBrowserIsCompatible()) { // this variable will collect the html which will eventually be placed in the sidebar var sidebar_html = ""; // arrays to hold copies of the markers and html used by the sidebar // because the function closure trick doesnt work there var gmarkers = []; var htmls = []; // A function to create the marker and set up the event window function createMarker(marker_num, point, icon, name, html) { var marker = new GMarker(point, icon); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); // save the info we need to use later for the sidebar gmarkers[marker_num] = marker; htmls[marker_num] = html; // add a line to the sidebar html'; if ($modSettings['googleSidebar'] == 1) echo ' sidebar_html += \'\' + name + \'
\';'; if ($modSettings['googleSidebar'] == 2) echo ' sidebar_html += \'\' + name + \', \';'; echo ' //Now that we cached it lets return the marker.... return marker; } // This function picks up the click and opens the corresponding info window function myclick(i) { gmarkers[i].openInfoWindowHtml(htmls[i]); } // create the map var map = new GMap(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.addControl(new GScaleControl()); // Sets the map type based on admin prefrence map.setMapType(' . $modSettings['googleMapsType'] . '); // Lets load up the default long/lat/zoom for the map for those that like wine. map.centerAndZoom(new GPoint(' . $modSettings['googleMapsDefaultLong'] . ', ' . $modSettings['googleMapsDefaultLat'] . '), ' . $modSettings['googleMapsDefaultZoom'] . '); // This is so we can try to cluster some of those pins together so the map does not get over loaded? var clusterer = new Clusterer( map ); clusterer.icon = clusterIcon; clusterer.minMarkersPerClusterer = ' . $modSettings['googleMapsMinMarkerCluster'] . '; clusterer.maxVisibleMarkers = ' . $modSettings['googleMapsMaxVisMarker'] . '; clusterer.GridSize = ' . $modSettings['googleMapsMaxNumClusters'] . '; clusterer.MaxLinesPerInfoBox = ' . $modSettings['googleMapsMaxLinesCluster'] . '; // Read the data var request = GXmlHttp.create(); request.open("GET", "'. $scripturl . '?action=googlemap;sa=.xml", true); request.onreadystatechange = function() { if (request.readyState == 4) { var xmlDoc = request.responseXML; // obtain the array of markers and loop through it var markers = xmlDoc.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { // obtain the attribues of each marker var lng = parseFloat(markers[i].getAttribute("lng")); var lat = parseFloat(markers[i].getAttribute("lat")); var point = new GPoint(lng, lat); var html = markers[i].getAttribute("html"); var label = markers[i].getAttribute("label"); // create the marker'; if ($modSettings['googleMapsPinGender']) echo ' if (parseFloat(markers[i].getAttribute("gender")) == 0) var marker = createMarker(i, point, icon, label, html); if (parseFloat(markers[i].getAttribute("gender")) == 1) var marker = createMarker(i, point, iconm, label, html); if (parseFloat(markers[i].getAttribute("gender")) == 2) var marker = createMarker(i, point, iconf, label, html);'; else echo ' var marker = createMarker(i, point, icon, label, html);'; if ($modSettings['googleMapsEnableClusterer']) echo ' clusterer.AddMarker(marker, label);'; else echo ' map.addOverlay(marker);'; echo ' } }'; if($modSettings['googleMasSideBar']) echo' // put the assembled sidebar_html contents into the sidebar div document.getElementById("sidebar").innerHTML = sidebar_html;'; echo ' }; request.send(null); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } '; obExit(false); } function MapsXML() { global $db_prefix, $context, $scripturl, $txt, $modSettings, $user_info, $themeUser, $memberContext; // Lets dump everything in the buffer and start clean and new and fresh ob_end_clean(); if (!empty($modSettings['enableCompressedOutput'])) @ob_start('ob_gzhandler'); else ob_start(); // XML Header, and should these not be UTF-8? //header("Content-Type: plain/text; charset=ISO-8859-1"); header("Content-Type: application/xml; charset=UTF-8"); // Lets find number of members that set there map $request = db_query(" SELECT COUNT(*) as TOTALFOUND FROM {$db_prefix}members WHERE latitude IS NOT NULL AND longitude IS NOT NULL ", __FILE__, __LINE__); // Pull the answer and store it... $totalSet = mysql_fetch_row($request); // If the total people set there lat/long is greater than googleMapsPinNumber, // We check for if we have any bounds that got passed from the JS, // If no bounds we just pick the number of googleMapsPinNumber to show... // If we are under the max allowed, just show them all! if ($totalSet[0] >= $modSettings['googleMapsPinNumber']) { // Lets set this to nothing, just to be safe if we dont have variables... $sql_addon = ""; // Check to see if we have any ranges before we add to the SQL statment... // This could stand to have a bit better security on it but its gonna be let by the side for now if ((isset($_GET['minX'])) && (isset($_GET['maxX'])) && (isset($_GET['minY'])) && (isset($_GET['maxY']))) { $sql_addon = " AND latitude > " . $_GET['minX'] . " AND latitude < " . $_GET['maxX'] . " AND longitude > " . $_GET['minY'] . " AND longitude < " . $_GET['maxY']; } // Lets just make this simple for the query... $maxPins = $modSettings['googleMapsPinNumber']; // Load the data up at random to the ping count! $query = "SELECT * FROM {$db_prefix}members WHERE latitude IS NOT NULL AND longitude IS NOT NULL $sql_addon ORDER BY RAND() LIMIT 0, $maxPins"; } else { // Looks like we passed under the max, Load everyone... $query = "SELECT * FROM {$db_prefix}members WHERE latitude IS NOT NULL AND longitude IS NOT NULL ORDER BY `realName` ASC "; } $request = db_query($query, __FILE__, __LINE__); //Ok this is block of code takes care of the entire load all member data into $themeUser/$memberContext on per # basis $temp = array(); while ($row = mysql_fetch_array($request, MYSQL_ASSOC)) $temp[] = $row['ID_MEMBER']; loadMemberData($temp); foreach ($temp as $v) loadMemberContext($v); // Seeing how SMF 1.0 uses $themeUser and SMF 1.1 uses $memberContext, lets just make our own now? if (isset($memberContext)) $data = $memberContext; elseif (isset($themeUser)) $data = $themeUser; // Lets accualy start making XML Mr. PHP, and should this not be UTF-8? echo ' '; if (isset($data)) { // Assuming we have data to work with... foreach ($data as $marker) { $datablurb = '
' . $marker['online']['text'] .' ' . $marker['name'] . ' ' . $marker['avatar']['image'] . '
' . $marker['title'] . '
'; if (($marker['website']['url'] != '') && ($marker['website']['title'] != '')) $datablurb = $datablurb . '' . $marker['website']['title'] . ''; $datablurb = $datablurb . '
' . $marker['blurb'] . '
'; // This is to help against those funky chars... and protect against those " errors in XML! $datablurb = htmlspecialchars($datablurb); // Lets bring it all together... $markers = ''; echo $markers; } } echo '
'; // Ok we should be done with output, dump it to user... obExit(false); } function ShowKML () { global $db_prefix, $context, $scripturl, $txt, $modSettings, $user_info, $mbname, $themeUser, $memberContext; // Are we allowed to view the map? Keep in mind here we should be a guest unless user is in IE! isAllowedTo('googleMap_view'); // If it's not enabled, die. if (empty($modSettings['xmlnews_enable'])) obExit(false); // This is an kml file, its like an XML file... ob_end_clean(); if (!empty($modSettings['enableCompressedOutput'])) @ob_start('ob_gzhandler'); else ob_start(); // Lets make sure its sent as KML header('Content-type: application/keyhole;'); // It will be called ourforumname.kml header('Content-Disposition: attachment; filename="' . $mbname . '.kml"'); // Load the data up, and seeing how its google earth, lets just send everything. // If we get complaints about this, then we shall have to figure out how to limit it. $request = db_query(" SELECT * FROM {$db_prefix}members WHERE latitude IS NOT NULL AND longitude IS NOT NULL ", __FILE__, __LINE__); //Ok this is block of code takes care of the entire load all member data into $memberContext on per # basis $temp = array(); while ($row = mysql_fetch_array($request, MYSQL_ASSOC)) $temp[] = $row['ID_MEMBER']; loadMemberData($temp); foreach ($temp as $v) loadMemberContext($v); // Seeing how SMF 1.0 uses $themeUser and SMF 1.1 uses $memberContext, lets just make our own now? if (isset($memberContext)) $data = $memberContext; elseif (isset($themeUser)) $data = $themeUser; echo ' ' . $mbname . ' 0'; if (isset($data)) { // Assuming we have data to work with... foreach ($data as $marker) { echo ' ' . $marker['online']['text'] .' ' . $marker['name'] . ' ' . $marker['avatar']['image'] . ' ' . $marker['title'] . ' ' . $marker['icq']['link'] . ' ' . $marker['aim']['link'] . ' ' . $marker['yim']['link'] . ' ' . $marker['msn']['link'] . ' '; if (($marker['website']['url'] != '') && ($marker['website']['title'] != '')) echo '' . $marker['website']['title'] . ''; echo ' ' . $marker['blurb'] . ' '; echo ' ]]> ' . $marker['name'] . ' ' . $marker['googleMap']['longitude'] . ' ' . $marker['googleMap']['latitude'] . ' 15000 root://styles#default+icon=0x304'; /* This does not appeal to me right now... if ($modSettings['googleMapsPinGender']) { echo ' '; } */ echo ' 1 absolute ' . $marker['googleMap']['longitude'] . ',' . $marker['googleMap']['latitude'] . ',8000 '; } } echo ' '; // Ok done, should send everything now.. obExit(false); } ?>