<?php
/*
Plugin Name: Google Group Map
Plugin URI:
Description: This plugin will embed a google map for groups.
Author: Charl Kruger
Author URI:
Version: 1.0
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
===============================================================================
group stuff
===============================================================================
*/
/* Show group map in group header */
$ggmap_show_map_in_header = true ;
/* - HERE BEGINS THE CODE - */
// create the form to add the field for the map
function ggmap_add_map_form() {
?>
<label for="group-map"><?php _e( 'map', 'ggmap' ) ?></label>
<input type="text" name="group-map" id="group-map" value="" />
<?php
}
add_action( 'groups_custom_group_fields_editable', 'ggmap_add_map_form' );
// Save the map lat and long in the group meta
function ggmap_save_map( $group_id ) {
global $bp;
if($bp->groups->new_group_id)
$id = $bp->groups->new_group_id;
else
$id = $group_id;
if ( $_POST['group-map'] )
groups_update_groupmeta( $id, 'ggmap_group_map', $_POST['group-map'] );
}
// Get or return the map lat and long
function ggmap_group_map() {
echo ggmap_get_group_map();
}
function ggmap_get_group_map( $group = false ) {
global $groups_template;
if ( !$group )
$group =& $groups_template->group;
$group_map = groups_get_groupmeta( $group->id, 'ggmap_group_map' );
$group_map = stripcslashes( $group_map );
return apply_filters( 'ggmap_get_group_map', $group_map );
}
// show map in group header
function ggmap_show_map_in_header( $description ) {
global $ggmap_show_map_in_header;
if ( ggmap_get_group_map() && $ggmap_show_map_in_header ) {
$description .= '<div class="ggmap-header">'. __('map', 'ggmap').': '. ggmap_make_map_for_group().'</div>';
}
return $description;
}
// show map for an individual group
function ggmap_make_map_for_group() {
global $bp, $wpdb, $ggmap_args;
$group_map = "
<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false'></script>
<script type='text/javascript'>
function makeMap() {
var latlng = new google.maps.LatLng(".ggmap_get_group_map().")
var myOptions = {
zoom: 14,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('SGM'), myOptions);
var contentString = '<div class=\"infoWindow\">HI :D</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: ''
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
window.onload = makeMap;
</script>
<div id='SGM'></div>
";
return $group_map;
}
add_action( 'groups_create_group_step_save_group-details', 'ggmap_save_map' );
add_action( 'groups_details_updated', 'ggmap_save_map' );
/*
===============================================================================
Google Group Extension API - Map tab
===============================================================================
*/
class Google_Group_Extension extends BP_Group_Extension {
function google_group_extension() {
$this->name = 'Map';
$this->slug = 'map';
$this->create_step_position = 21;
$this->nav_item_position = 31;
}
function display() {
global $bp;
echo '<div class="ggmap-header">'. __('map', 'ggmap').': '. ggmap_make_map_for_group().'</div>';
}
}
bp_register_group_extension( 'Google_Group_Extension' );
/*
===============================================================================
insert styles into <head>
===============================================================================
*/
add_action ('wp_head', 'printStyles');
function printStyles() {
print "<!-- styles for Simple Google Map -->\n<style type='text/css'>\n";
print "#SGM {width:50%; height:300px;}
#SGM .infoWindow {line-height:13px; font-size:10px;}
#SGM input {margin:4px 4px 0 0; font-size:10px;}
#SGM input.text {border:solid 1px #ccc; background-color:#fff; padding:2px;}";
print "\n</style>\n<!-- end styles for Simple Google Map -->\n";
}
?>