Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Google Group Map
- Plugin URI:
- Description: This plugin will embed a google map for buddypress 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
- */
- //add css
- function ggmap_header() {
- echo '<link rel="stylesheet" type="text/css" href="'.WP_PLUGIN_URL.'/google-group-map/google-group-map.css" media="screen" />'."\n";
- }
- add_action('wp_head', 'ggmap_header');
- /*
- ===============================================================================
- group stuff
- ===============================================================================
- */
- /* - 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( 'Group map co-ordinates', 'ggmap' ) ?></label>
- <input type="text" name="group-map" id="group-map" value="<?php echo ggmap_get_group_map() ?>" />
- <br /><em>Must be in decimal format seperated by a comma eg: -12.34567,12.34567</em>
- <br />Need <a title="gps helper" href="http://stevemorse.org/jcal/latlon.php" target="_blank">help</a> finding your co-ordinates?
- <?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: 15,
- center: latlng,
- streetViewControl: true,
- 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('GGM'), 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='GGM'></div>
- ";
- return $group_map;
- }
- // add directions for an individual group
- function ggmap_make_directions_for_group() {
- global $bp, $wpdb, $ggmap_args;
- $directionsto = "<form method=\"get\" action=\"http://maps.google.com/maps\"target="._blank."><input type=\"hidden\" name=\"daddr\" value=\"".ggmap_get_group_map()."\" /><input type=\"text\" class=\"text\" name=\"saddr\" /><input type=\"submit\" class=\"submit\" value=\"Get directions\" /></form>
- <em>*enter your current location</em>";
- return $directionsto;
- }
- 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 {
- var $enable_create_step = false;
- var $enable_edit_item = false;
- 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-map">'. __('', 'ggmap').' '. ggmap_make_map_for_group().'</div>';
- echo '<div class="ggmap-directions">'. __('', 'ggmap').' '. ggmap_make_directions_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 "#GGM {width:100%; height:300px;}
- #GGM .infoWindow {line-height:13px; font-size:10px;}
- #GGM input {margin:4px 4px 0 0; font-size:10px;}
- #GGM input.text {border:solid 1px #ccc; background-color:#fff; padding:2px;}";
- print "\n</style>\n<!-- end styles for Simple Google Map -->\n";
- }
- ?>
Add Comment
Please, Sign In to add comment