/** * __construct function. * * @access public * @return void */ public function __construct() { //check if we are in new/edit post page if (in_array(basename($_SERVER['PHP_SELF']), array('post-new.php', 'post.php', 'page.php', 'page-new'))) { include_once GMW_PT_PATH . 'includes/admin/gmw-pt-metaboxes.php'; } //add "address" column to manage posts page foreach (gmw_get_option('post_types_settings', 'post_types', array()) as $post_type) { if ($post_type == 'job_listing' || $post_type == 'resume') { continue; } add_filter("manage_{$post_type}_posts_columns", array($this, 'add_address_column')); add_action("manage_{$post_type}_posts_custom_column", array($this, 'address_column_content'), 10, 2); } add_filter('gmw_admin_settings', array($this, 'settings_init'), 1); add_filter('gmw_admin_new_form_button', array($this, 'new_form_button'), 1, 1); add_filter('gmw_posts_form_settings', array($this, 'form_settings_init'), 1, 1); add_filter('gmw_admin_shortcodes_page', array($this, 'shortcodes_page'), 1, 10); //main settings page add_action('gmw_main_settings_post_types', array($this, 'main_settings_post_types'), 1, 4); //form settings add_action('gmw_posts_form_settings_post_types', array($this, 'form_settings_post_types'), 1, 4); add_action('gmw_posts_form_settings_featured_image', array($this, 'featured_image'), 1, 4); add_action('gmw_posts_form_settings_show_excerpt', array($this, 'show_excerpt'), 1, 4); add_action('gmw_posts_form_settings_form_taxonomies', array($this, 'form_taxonomies'), 1, 4); }
/** * gmw_shortcode * * GEO my WP's main shortcode * @param unknown_type $atts */ function gmw_shortcode($atts) { //abort if no attributes found if (empty($atts)) { return; } //get the first attribute of the shortcode. //the first attribute must be the element ( form, search_form, map or search_results ). $element = key($atts); //get the form ID $formId = $atts[$element]; //make sure the element is lagit if (empty($formId) || !in_array($element, array('search_form', 'map', 'search_results', 'form'))) { return; } /** * GEO my WP URL parameteres prefix * * This is the prefix used for the URL paramaters that GEO my WP * uses with submitted form. IT can modified if needed * * @var string */ $gmw_prefix = gmw_get_option('general_settings', 'url_px', 'gmw_'); //modify the URL parameters $_GET = apply_filters('gmw_modify_get_args', $_GET); //if this is results page we get the formId from URL if ($formId == 'results') { if (empty($_GET['action']) || $_GET['action'] != $gmw_prefix . 'post' || empty($_GET[$gmw_prefix . 'form'])) { return; } $formId = absint($_GET[$gmw_prefix . 'form']); $element = 'results_page'; } else { $formId = absint($atts[$element]); } //get the forms from database $forms = get_option('gmw_forms'); //look for the form based on the form ID. Abort if no form was found if (empty($forms[$formId])) { return; } //get the current form $form = $forms[$formId]; //make sure the add-on of the form is activated if (!GEO_my_WP::gmw_check_addon($form['addon'])) { return; } $form['element_triggered'] = $element; $form['params'] = $atts; $form['url_px'] = $gmw_prefix; $form_output = new GMW_Form_Init($form); ob_start(); $form_output->display(); $output_string = ob_get_contents(); ob_end_clean(); return $output_string; }
/** * Display meta boxes */ function display_meta_box() { global $post, $wpdb; $post_info = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "places_locator WHERE post_id = %d", array($post->ID))); if (empty($post_info)) { $post_info = (object) array('post_id' => '', 'feature' => '', 'post_status' => '', 'post_type' => '', 'post_title' => '', 'lat' => '', 'long' => '', 'street_number' => '', 'street_name' => '', 'street' => '', 'apt' => '', 'city' => '', 'state' => '', 'state_long' => '', 'zipcode' => '', 'country' => '', 'country_long' => '', 'address' => '', 'formatted_address' => '', 'phone' => '', 'fax' => '', 'email' => '', 'website' => '', 'map_icon' => ''); } if (isset($this->settings['general_settings']['mandatory_address'])) { wp_localize_script('wppl-address-picker', 'addressMandatory', $this->settings['general_settings']['mandatory_address']); } ?> <?php do_action('gmw_admin_location_section_start', $post); ?> <!-- <input type="text" name="gmw_post_level" id="gmw-post-level"> --> <input type="hidden" name="this->meta_boxes_nonce" value="<?php echo wp_create_nonce(basename(__FILE__)); ?> " /> <div class="gmw-location-section map"> <h3> <?php _e('Use the map to drag and drop the marker to the desired location.', 'GMW'); ?> </h3> <div id="map"></div> </div> <div class="gmw-location-section current-location"> <h3> <?php _e('Get your current location', 'GMW'); ?> </h3> <div class="current-location-inner"> <input type="button" id="gmw-admin-locator-btn" class="button-primary" value="<?php _e('Locate Me', 'GMW'); ?> " /> </div> </div> <div class="gmw-location-section autocomplete"> <h3> <?php _e('Type an address to autocomplete', 'GMW'); ?> </h3> <div class="autocomplete-location-inner"> <input type="text" id="wppl-addresspicker" value="<?php echo $post_info->address; ?> " /> </div> </div> <div class="clear"></div> <div class="gmw-location-section gmw-location-manually-wrapper"> <h3><?php _e('Enter Location Manually', 'GMW'); ?> </h3> <div class="gmw-location-section-inner"> <div class="address"> <h3><?php _e('Address', 'GMW'); ?> </h3> <div class="gmw-location-section-description"> <p><?php _e('Fill out the address fields and click "Get Lat/Long" to retrive the latitude and longitude of the location.', 'GMW'); ?> </p> </div> <table class="gmw-admin-location-table"> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][0]['id']; ?> "><?php echo $this->meta_boxes['fields'][0]['name']; ?> </label></th> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][0]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][0]['id']; ?> " value="<?php echo $post_info->street; ?> " /><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][1]['id']; ?> "><?php echo $this->meta_boxes['fields'][1]['name']; ?> </label></th> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][1]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][1]['id']; ?> " value="<?php echo $post_info->apt; ?> " /><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][2]['id']; ?> "><?php echo $this->meta_boxes['fields'][2]['name']; ?> </label></th> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][2]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][2]['id']; ?> " value="<?php echo $post_info->city; ?> " /><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][3]['id']; ?> "><?php echo $this->meta_boxes['fields'][3]['name']; ?> </label></th> <td><input type="text" id="<?php echo $this->meta_boxes['fields'][3]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][3]['id']; ?> " value="<?php echo $post_info->state; ?> "/><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][4]['id']; ?> "><?php echo $this->meta_boxes['fields'][4]['name']; ?> </label></th> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][4]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][4]['id']; ?> " value="<?php echo $post_info->zipcode; ?> " /><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][5]['id']; ?> "><?php echo $this->meta_boxes['fields'][5]['name']; ?> </label></th> <td><input type="text" id="<?php echo $this->meta_boxes['fields'][5]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][5]['id']; ?> " value="<?php echo $post_info->country; ?> "/><br /></td> </tr> <tr> <th></th> <td><input type="button"id="gmw-admin-getlatlong-btn" class="button-primary" value="Get Lat/Long" style="margin: 10px 0px;"></td> </tr> </table> <table style="display:none;"> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][19]['id']; ?> "><?php echo $this->meta_boxes['fields'][19]['name']; ?> </label></th> </tr> <tr> <td><input type="text" id="<?php echo $this->meta_boxes['fields'][19]['id']; ?> " name="<?php echo $this->meta_boxes['fields'][19]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][19]['id']; ?> " value="<?php echo $post_info->street_number; ?> " /><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][20]['id']; ?> "><?php echo $this->meta_boxes['fields'][20]['name']; ?> </label></th> </tr> <tr> <td><input type="text" id="<?php echo $this->meta_boxes['fields'][20]['id']; ?> " name="<?php echo $this->meta_boxes['fields'][20]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][20]['id']; ?> " value="<?php echo $post_info->street_name; ?> " /><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][3]['id']; ?> "><?php echo $this->meta_boxes['fields'][3]['name']; ?> </label></th> </tr> <tr> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][3]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][3]['id']; ?> " value="<?php echo $post_info->state; ?> " /><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][16]['id']; ?> "><?php echo $this->meta_boxes['fields'][16]['name']; ?> </label></th> </tr> <tr> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][16]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][16]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][16]['id']; ?> " value="<?php echo $post_info->state_long; ?> " style="width: 100%;"/><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][5]['id']; ?> "><?php echo $this->meta_boxes['fields'][5]['name']; ?> </label></th> </tr> <tr> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][5]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][5]['id']; ?> " value="<?php echo $post_info->country; ?> " /><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][17]['id']; ?> "><?php echo $this->meta_boxes['fields'][17]['name']; ?> </label></th> </tr> <tr> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][17]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][17]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][17]['id']; ?> " value="<?php echo $post_info->country_long; ?> " style="width: 100%;" /><br /></td> </tr <tr> <th><label for="<?php echo $this->meta_boxes['fields'][14]['id']; ?> "><?php echo $this->meta_boxes['fields'][14]['name']; ?> </label></th> </tr> <tr> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][14]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][14]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][14]['id']; ?> " value="<?php echo $post_info->address; ?> " style="width: 100%;"/><br /></td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][18]['id']; ?> "><?php echo $this->meta_boxes['fields'][18]['name']; ?> </label></th> </tr> <tr> <td><input type="text" name="<?php echo $this->meta_boxes['fields'][18]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][18]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][18]['id']; ?> " value="<?php echo $post_info->formatted_address; ?> " style="width: 100%;" /><br /></td> </tr> </table> </div> <div class="right-side"> <div class="coords"> <h3><?php _e('Latitude / Longitude', 'GMW'); ?> </h3> <div class="gmw-location-section-description"> <p><?php _e('Fill out the Latitude and Longitude fields and click on "Get Address" to retrive the address of the location.', 'GMW'); ?> </p> </div> <table class="gmw-admin-location-table"> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][12]['id']; ?> "><?php echo $this->meta_boxes['fields'][12]['name']; ?> </label></th> <td> <input type="text" name="<?php echo $this->meta_boxes['fields'][12]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][12]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][12]['id']; ?> " value="<?php echo $post_info->lat; ?> " /> <input type="hidden" name="gmw_check_lat" id="gmw_check_lat" value""> </td> </tr> <tr> <th><label for="<?php echo $this->meta_boxes['fields'][13]['id']; ?> "><?php echo $this->meta_boxes['fields'][13]['name']; ?> </label></th> <td> <input type="text" name="<?php echo $this->meta_boxes['fields'][13]['id']; ?> " id="<?php echo $this->meta_boxes['fields'][13]['id']; ?> " class="<?php echo $this->meta_boxes['fields'][13]['id']; ?> " value="<?php echo $post_info->long; ?> " /> <input type="hidden" name="gmw_check_long" id="gmw_check_long" value""> </td> </tr> <tr> <th></th> <td><input style="margin: 10px 0px;" type="button" id="gmw-admin-getaddress-btn" class="button-primary" value="Get Address" /></td> </tr> </table> </div> <div class="delete-location-wrapper"> <h3><?php _e('Delete Location', 'GMW'); ?> </h3> <div class="delete-locaiton-inner"> <input type="button" style="float:none;" id="gmw-admin-delete-btn" class="button-primary" value="<?php _e('Delete address', 'GMW'); ?> " /> </div> </div> <div id="gmw-getting-info" class="location-status-wrapper"> <h3 ><?php _e('Location status', 'GMW'); ?> </h3> <div class="location-status-inner"> <div id="gmw-location-loader" style="display:none;background:none; border:0px;height: 23px;"><img style="width:15px;margin-right: 5px"src="<?php echo GMW_IMAGES; ?> /gmw-loader.gif" id="ajax-loader-image" alt="" "><?php _e('Loading...', 'GMW'); ?> </div> <div id="gmw-good-location-message" class="" style="display:none;height: 23px;"><p><?php _e('Location is ready', 'GMW'); ?> </p></div> <div id="gmw-bad-location-message" class="gmw-location-message" style="height: 23px;"><p style="color:red"><?php _e('A valid address, latitude and longitude are required to save the Location', 'GMW'); ?> </p></div> </div> </div> <div class="clear"></div> </div> </div> </div> <?php do_action('gmw_admin_location_section_end', $post); ?> <div class="clear"></div> <?php wp_enqueue_style('gmw-pt-admin-style'); wp_enqueue_script('google-maps'); wp_enqueue_script('jquery-ui-autocomplete'); wp_enqueue_script('gmw-admin-address-picker'); //make sure address_mandatory is not undefined $this->settings['post_types_settings']['mandatory_address'] = gmw_get_option('post_types_settings', 'mandatory_address', false); wp_localize_script('gmw-admin-address-picker', 'gmwOptions', $this->settings); }
/** * frontend_scripts function. * * @access public * @return void */ public function register_scripts() { global $gmw_options; $protocol = is_ssl() ? 'https' : 'http'; //register google maps api if (!wp_script_is('google-maps', 'registered') && apply_filters('gmw_google_maps_api', true)) { //Build Google API url. elements can be modified via filters $google_url = apply_filters('gmw_google_maps_api_url', array('protocol' => $protocol, 'url_base' => '://maps.googleapis.com/maps/api/js?', 'url_data' => http_build_query(apply_filters('gmw_google_maps_api_args', array('libraries' => 'places', 'key' => gmw_get_option('general_settings', 'google_api', ''), 'region' => $gmw_options['general_settings']['country_code'], 'language' => $gmw_options['general_settings']['language_code'], 'sansor' => 'false')), '', '&')), $gmw_options); wp_register_script('google-maps', implode('', $google_url), array('jquery'), GMW_VERSION, false); } //register font-awesome if (!wp_style_is('font-awesome', 'enqueued')) { wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css', array(), GMW_VERSION); } //register chosen if (!wp_script_is('chosen', 'registered')) { wp_register_script('chosen', GMW_URL . '/assets/js/chosen.jquery.min.js', array('jquery'), GMW_VERSION, true); } if (!wp_style_is('chosen', 'registered')) { wp_register_style('chosen', GMW_URL . '/assets/css/chosen.min.css', array(), GMW_VERSION); } //register in front-end only if (!is_admin()) { //enqueue google maps api if (!wp_script_is('google-maps', 'enqueued')) { wp_enqueue_script('google-maps'); } //include dashicons. Will be removed in the future replaced by fontawsome wp_enqueue_style('dashicons'); //include GMW main stylesheet wp_register_style('gmw-style', GMW_URL . '/assets/css/style.css', array(), GMW_VERSION); wp_enqueue_style('gmw-style'); //temporary until this feature will be removed. It is being replaced by the new Current Location core add-on if (!class_exists('GMW_Current_Location')) { wp_register_style('gmw-cl-style-dep', GMW_URL . '/assets/css/gmw-cl-style-dep.css', array(), GMW_VERSION); wp_enqueue_style('gmw-cl-style-dep'); wp_register_script('gmw-cl-map', GMW_URL . '/assets/js/gmw-cl.min.js', array('jquery', 'google-maps'), GMW_VERSION, true); } //register gmw script wp_register_script('gmw-js', GMW_URL . '/assets/js/gmw.min.js', array('jquery'), GMW_VERSION, true); //localize gmw options wp_localize_script('gmw-js', 'gmwSettings', $gmw_options); //register gmw map script wp_register_script('gmw-map', GMW_URL . '/assets/js/map.min.js', array('jquery'), GMW_VERSION, true); //register gmw autocomplete script wp_register_script('gmw-google-autocomplete', GMW_URL . '/assets/js/googleAddressAutocomplete.js', array('jquery'), GMW_VERSION, true); //register some Jquery ui components wp_register_style('ui-comp', GMW_URL . '/assets/css/ui-comp.min.css'); //Google Maps Infobox - only register, to be used with premium features if (!wp_script_is('gmw-infobox', 'registered')) { //infobox library wp_register_script('gmw-infobox', GMW_URL . '/assets/js/infobox.min.js', array('jquery'), GMW_VERSION, true); $infobox_close_btn = $protocol . '://www.google.com/intl/en_us/mapfiles/close.gif'; wp_localize_script('gmw-infobox', 'closeButton', $infobox_close_btn); } //Marker clusterer library - only register, to be used with premium features if (!wp_script_is('gmw-marker-clusterer', 'registered')) { wp_register_script('gmw-marker-clusterer', GMW_URL . '/assets/js/marker-clusterer.min.js', array('jquery'), GMW_VERSION, true); } $cluster_image = apply_filters('gmw_clusters_folder', $protocol . '://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/images/m'); wp_localize_script('gmw-marker-clusterer', 'clusterImage', $cluster_image); //Marker spiderfire library - only register, to be used with premium features if (!wp_script_is('gmw-marker-spiderfier', 'registered')) { wp_register_script('gmw-marker-spiderfier', GMW_URL . '/assets/js/marker-spiderfier.min.js', array('jquery'), GMW_VERSION, true); } $form_styles = apply_filters('gmw_load_form_styles_early', array()); //run enqueue forms loader function if array is not empty if (!empty($form_styles)) { gmw_enqueue_form_styles($form_styles); } } }
/** * GMW function - Geocode address * @since 1.0 * @author Eyal Fitoussi * @author This function inspired by a script written by Pippin Williamson - Thank you */ function gmw_geocoder($raw_address, $force_refresh = false) { $invalid_chars = array(" " => "+", "," => "", "?" => "", "&" => "", "=" => "", "#" => ""); $raw_address = trim(strtolower(str_replace(array_keys($invalid_chars), array_values($invalid_chars), $raw_address))); if (empty($raw_address)) { return false; } $address_hash = md5($raw_address); $location = get_transient('gmw_geocoded_' . $address_hash); if ($force_refresh == true || $location === false) { global $gmw_options; //Build Google API url. elements can be modified via filters $url = apply_filters('gmw_google_maps_api_geocoder_url', array('protocol' => is_ssl() ? 'https' : 'http', 'url_base' => '://maps.googleapis.com/maps/api/geocode/json?', 'url_data' => http_build_query(apply_filters('gmw_google_maps_api_geocoder_args', array('address' => $raw_address, 'key' => gmw_get_option('general_settings', 'google_api', ''), 'region' => $gmw_options['general_settings']['country_code'], 'language' => $gmw_options['general_settings']['language_code'], 'sansor' => 'false')), '', '&')), $gmw_options); $response = wp_remote_get(implode('', $url)); if (is_wp_error($response)) { return; } $data = wp_remote_retrieve_body($response); if (is_wp_error($data)) { return; } if ($response['response']['code'] == 200) { $data = json_decode($data); if (!empty($data) && $data->status === 'OK') { $location['geocoded'] = true; $location['street_number'] = false; $location['street_name'] = false; $location['street'] = false; $location['apt'] = false; $location['city'] = false; $location['state_short'] = false; $location['state_long'] = false; $location['zipcode'] = false; $location['country_short'] = false; $location['country_long'] = false; $location['lat'] = sanitize_text_field($data->results[0]->geometry->location->lat); $location['lng'] = sanitize_text_field($data->results[0]->geometry->location->lng); $location['formatted_address'] = sanitize_text_field($data->results[0]->formatted_address); $address_componenets = $data->results[0]->address_components; foreach ($address_componenets as $data) { switch ($data->types[0]) { case 'street_number': $location['street_number'] = $location['street'] = sanitize_text_field($data->long_name); break; case 'route': $location['street_name'] = sanitize_text_field($data->long_name); if (!empty($location['street_number'])) { $location['street'] = $location['street_number'] . ' ' . $location['street_name']; } else { $location['street'] = $location['street_name']; } break; case 'subpremise': $location['apt'] = sanitize_text_field($data->long_name); break; case 'sublocality_level_1': case 'locality': case 'postal_town': $location['city'] = sanitize_text_field($data->long_name); break; case 'administrative_area_level_1': case 'administrative_area_level_2': $location['state_short'] = sanitize_text_field($data->short_name); $location['state_long'] = sanitize_text_field($data->long_name); break; case 'postal_code': $location['zipcode'] = sanitize_text_field($data->long_name); break; case 'country': $location['country_short'] = sanitize_text_field($data->short_name); $location['country_long'] = sanitize_text_field($data->long_name); break; } } do_action('gmw_geocoded_location', $location); // cache coordinates for 3 months set_transient('gmw_geocoded_' . $address_hash, $location, 3600 * 24 * 30 * 3); } elseif ($data->status === 'ZERO_RESULTS') { return array('geocoded' => false, 'error' => __('The address entered could not be geocoded.', 'GMW')); } elseif ($data->status === 'INVALID_REQUEST') { return array('geocoded' => false, 'error' => __('Invalid request. Did you enter an address?', 'GMW')); } elseif ($data->status === 'OVER_QUERY_LIMIT') { return array('geocoded' => false, 'error' => __('Something went wrong while retrieving your location.', 'GMW') . '<span style="display:none">OVER_QUERY_LIMIT</span>'); } else { return array('geocoded' => false, 'error' => __('Something went wrong while retrieving your location.', 'GMW')); } } else { return array('geocoded' => false, 'error' => __('Unable to contact Google API service.', 'GMW')); } } return $location; }