Advertisement
Guest User

Untitled

a guest
Oct 6th, 2010
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 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 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.  
  31.  
  32. /*
  33. ===============================================================================
  34.  
  35. group stuff
  36.  
  37. ===============================================================================
  38. */
  39.  
  40. /* Show group map in group header */
  41. $ggmap_show_map_in_header = true ;
  42.  
  43. /* - HERE BEGINS THE CODE - */
  44.  
  45. // create the form to add the field for the map
  46. function ggmap_add_map_form() {
  47. ?>
  48. <label for="group-map"><?php _e( 'map', 'ggmap' ) ?></label>
  49. <input type="text" name="group-map" id="group-map" value="" />
  50.  
  51. <?php
  52.  
  53. }
  54. add_action( 'groups_custom_group_fields_editable', 'ggmap_add_map_form' );
  55.  
  56. // Save the map lat and long in the group meta
  57. function ggmap_save_map( $group_id ) {
  58. global $bp;
  59.  
  60. if($bp->groups->new_group_id)
  61. $id = $bp->groups->new_group_id;
  62. else
  63. $id = $group_id;
  64.  
  65. if ( $_POST['group-map'] )
  66. groups_update_groupmeta( $id, 'ggmap_group_map', $_POST['group-map'] );
  67. }
  68.  
  69. // Get or return the map lat and long
  70. function ggmap_group_map() {
  71. echo ggmap_get_group_map();
  72. }
  73. function ggmap_get_group_map( $group = false ) {
  74. global $groups_template;
  75. if ( !$group )
  76. $group =& $groups_template->group;
  77. $group_map = groups_get_groupmeta( $group->id, 'ggmap_group_map' );
  78. $group_map = stripcslashes( $group_map );
  79. return apply_filters( 'ggmap_get_group_map', $group_map );
  80. }
  81.  
  82. // show map in group header
  83. function ggmap_show_map_in_header( $description ) {
  84. global $ggmap_show_map_in_header;
  85. if ( ggmap_get_group_map() && $ggmap_show_map_in_header ) {
  86. $description .= '<div class="ggmap-header">'. __('map', 'ggmap').': '. ggmap_make_map_for_group().'</div>';
  87. }
  88. return $description;
  89. }
  90.  
  91. // show map for an individual group
  92. function ggmap_make_map_for_group() {
  93. global $bp, $wpdb, $ggmap_args;
  94.  
  95.  
  96. $group_map = "
  97. <script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false'></script>
  98. <script type='text/javascript'>
  99. function makeMap() {
  100. var latlng = new google.maps.LatLng(".ggmap_get_group_map().")
  101.  
  102. var myOptions = {
  103. zoom: 14,
  104. center: latlng,
  105. mapTypeControl: true,
  106. mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
  107. navigationControl: true,
  108. navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
  109. mapTypeId: google.maps.MapTypeId.ROADMAP
  110. };
  111. var map = new google.maps.Map(document.getElementById('SGM'), myOptions);
  112.  
  113. var contentString = '<div class=\"infoWindow\">HI :D</div>';
  114. var infowindow = new google.maps.InfoWindow({
  115. content: contentString
  116. });
  117.  
  118. var marker = new google.maps.Marker({
  119. position: latlng,
  120. map: map,
  121. title: ''
  122. });
  123.  
  124. google.maps.event.addListener(marker, 'click', function() {
  125. infowindow.open(map,marker);
  126. });
  127. }
  128. window.onload = makeMap;
  129. </script>
  130.  
  131. <div id='SGM'></div>
  132.  
  133. ";
  134.  
  135. return $group_map;
  136. }
  137.  
  138. add_action( 'groups_create_group_step_save_group-details', 'ggmap_save_map' );
  139. add_action( 'groups_details_updated', 'ggmap_save_map' );
  140.  
  141.  
  142.  
  143.  
  144. /*
  145. ===============================================================================
  146.  
  147. Google Group Extension API - Map tab
  148.  
  149. ===============================================================================
  150. */
  151.  
  152.  
  153. class Google_Group_Extension extends BP_Group_Extension {
  154.  
  155. function google_group_extension() {
  156. $this->name = 'Map';
  157. $this->slug = 'map';
  158.  
  159. $this->create_step_position = 21;
  160. $this->nav_item_position = 31;
  161. }
  162.  
  163. function display() {
  164. global $bp;
  165. echo '<div class="ggmap-header">'. __('map', 'ggmap').': '. ggmap_make_map_for_group().'</div>';
  166. }
  167.  
  168.  
  169. }
  170. bp_register_group_extension( 'Google_Group_Extension' );
  171.  
  172.  
  173.  
  174.  
  175. /*
  176. ===============================================================================
  177.  
  178. insert styles into <head>
  179.  
  180. ===============================================================================
  181. */
  182.  
  183.  
  184.  
  185.  
  186.  
  187. add_action ('wp_head', 'printStyles');
  188.  
  189. function printStyles() {
  190. print "<!-- styles for Simple Google Map -->\n<style type='text/css'>\n";
  191. print "#SGM {width:50%; height:300px;}
  192. #SGM .infoWindow {line-height:13px; font-size:10px;}
  193. #SGM input {margin:4px 4px 0 0; font-size:10px;}
  194. #SGM input.text {border:solid 1px #ccc; background-color:#fff; padding:2px;}";
  195. print "\n</style>\n<!-- end styles for Simple Google Map -->\n";
  196. }
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement