Advertisement
Guest User

Untitled

a guest
Dec 6th, 2010
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Google Group Map
  4. Plugin URI:
  5. Description: This plugin will embed a google map for buddypress groups.
  6. Author: Charl Kruger
  7. Author URI:
  8. Version: 1.0
  9.  
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25.  
  26.  
  27.  
  28.  
  29.  
  30. //add css
  31. function ggmap_header() {
  32. echo '<link rel="stylesheet" type="text/css" href="'.WP_PLUGIN_URL.'/google-group-map/google-group-map.css" media="screen" />'."\n";
  33. }
  34. add_action('wp_head', 'ggmap_header');
  35.  
  36. /*
  37. ===============================================================================
  38.  
  39. group stuff
  40.  
  41. ===============================================================================
  42. */
  43.  
  44. /* - HERE BEGINS THE CODE - */
  45.  
  46. // create the form to add the field for the map
  47. function ggmap_add_map_form() {
  48. ?>
  49. <label for="group-map"><?php _e( 'Group map co-ordinates', 'ggmap' ) ?></label>
  50. <input type="text" name="group-map" id="group-map" value="<?php echo ggmap_get_group_map() ?>" />
  51. <br /><em>Must be in decimal format seperated by a comma eg: -12.34567,12.34567</em>
  52. <br />Need <a title="gps helper" href="http://stevemorse.org/jcal/latlon.php" target="_blank">help</a> finding your co-ordinates?
  53.  
  54. <?php
  55.  
  56. }
  57. add_action( 'groups_custom_group_fields_editable', 'ggmap_add_map_form' );
  58.  
  59. // Save the map lat and long in the group meta
  60. function ggmap_save_map( $group_id ) {
  61. global $bp;
  62.  
  63. if($bp->groups->new_group_id)
  64. $id = $bp->groups->new_group_id;
  65. else
  66. $id = $group_id;
  67.  
  68. if ( $_POST['group-map'] )
  69. groups_update_groupmeta( $id, 'ggmap_group_map', $_POST['group-map'] );
  70. }
  71.  
  72. // Get or return the map lat and long
  73. function ggmap_group_map() {
  74. echo ggmap_get_group_map();
  75. }
  76. function ggmap_get_group_map( $group = false ) {
  77. global $groups_template;
  78. if ( !$group )
  79. $group =& $groups_template->group;
  80. $group_map = groups_get_groupmeta( $group->id, 'ggmap_group_map' );
  81. $group_map = stripcslashes( $group_map );
  82. return apply_filters( 'ggmap_get_group_map', $group_map );
  83. }
  84.  
  85. // show map in group header
  86. function ggmap_show_map_in_header( $description ) {
  87. global $ggmap_show_map_in_header;
  88. if ( ggmap_get_group_map() && $ggmap_show_map_in_header ) {
  89. $description .= '<div class="ggmap-header">'. __('map', 'ggmap').': '. ggmap_make_map_for_group().'</div>';
  90. }
  91. return $description;
  92. }
  93.  
  94. // show map for an individual group
  95. function ggmap_make_map_for_group() {
  96. global $bp, $wpdb, $ggmap_args;
  97.  
  98. $group_map = "
  99. <script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false'></script>
  100. <script type='text/javascript'>
  101. function makeMap() {
  102. var latlng = new google.maps.LatLng(".ggmap_get_group_map().")
  103.  
  104. var myOptions = {
  105. zoom: 15,
  106. center: latlng,
  107. streetViewControl: true,
  108. mapTypeControl: true,
  109. mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
  110. navigationControl: true,
  111. navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
  112. mapTypeId: google.maps.MapTypeId.ROADMAP
  113.  
  114. };
  115. var map = new google.maps.Map(document.getElementById('GGM'), myOptions);
  116.  
  117. var contentString = '<div class=\"infoWindow\">HI :D</div>';
  118. var infowindow = new google.maps.InfoWindow({
  119. content: contentString
  120. });
  121.  
  122. var marker = new google.maps.Marker({
  123. position: latlng,
  124. map: map,
  125. title: ''
  126. });
  127.  
  128. google.maps.event.addListener(marker, 'click', function() {
  129. infowindow.open(map,marker);
  130. });
  131. }
  132. window.onload = makeMap;
  133. </script>
  134.  
  135. <div id='GGM'></div>
  136.  
  137. ";
  138.  
  139. return $group_map;
  140. }
  141. // add directions for an individual group
  142. function ggmap_make_directions_for_group() {
  143. global $bp, $wpdb, $ggmap_args;
  144.  
  145. $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>
  146. <em>*enter your current location</em>";
  147.  
  148. return $directionsto;
  149. }
  150.  
  151.  
  152. add_action( 'groups_create_group_step_save_group-details', 'ggmap_save_map' );
  153. add_action( 'groups_details_updated', 'ggmap_save_map' );
  154.  
  155.  
  156.  
  157.  
  158. /*
  159. ===============================================================================
  160.  
  161. Google Group Extension API - Map tab
  162.  
  163. ===============================================================================
  164. */
  165.  
  166.  
  167. class Google_Group_Extension extends BP_Group_Extension {
  168.  
  169. var $enable_create_step = false;
  170. var $enable_edit_item = false;
  171.  
  172.  
  173. function google_group_extension() {
  174. $this->name = 'Map';
  175. $this->slug = 'map';
  176.  
  177. $this->create_step_position = 21;
  178. $this->nav_item_position = 31;
  179. }
  180.  
  181. function display() {
  182. global $bp;
  183. echo '<div class="ggmap-map">'. __('', 'ggmap').' '. ggmap_make_map_for_group().'</div>';
  184. echo '<div class="ggmap-directions">'. __('', 'ggmap').' '. ggmap_make_directions_for_group().'</div>';
  185. }
  186.  
  187. }
  188. bp_register_group_extension( 'Google_Group_Extension' );
  189.  
  190.  
  191.  
  192.  
  193. /*
  194. ===============================================================================
  195.  
  196. insert styles into <head>
  197.  
  198. ===============================================================================
  199. */
  200.  
  201.  
  202.  
  203.  
  204.  
  205. add_action ('wp_head', 'printStyles');
  206.  
  207. function printStyles() {
  208. print "<!-- styles for Simple Google Map -->\n<style type='text/css'>\n";
  209. print "#GGM {width:100%; height:300px;}
  210. #GGM .infoWindow {line-height:13px; font-size:10px;}
  211. #GGM input {margin:4px 4px 0 0; font-size:10px;}
  212. #GGM input.text {border:solid 1px #ccc; background-color:#fff; padding:2px;}";
  213. print "\n</style>\n<!-- end styles for Simple Google Map -->\n";
  214. }
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement