public static function frontend_scripts()
 {
     wp_enqueue_script('locations-search-google-maps-api', '//maps.googleapis.com/maps/api/js?key=' . LocationsSearchSettings::get('google_api_key'));
     wp_enqueue_script('locations-search-clusterer', LocationsSearch::get_url() . '/vendor/marker-clusterer/markerclusterer.js', array(), LOCATIONSSEARCHVERSION);
     wp_enqueue_script('locations-search', LocationsSearch::get_url() . '/js/locations-search.js', array('locations-search-google-maps-api', 'locations-search-clusterer', 'jquery'), LOCATIONSSEARCHVERSION);
     wp_localize_script('locations-search', 'locations_search', array('ajax_url' => admin_url('admin-ajax.php'), 'ajax_action' => 'lsajax_search_results', 'map_styles' => apply_filters('locations_search_map_styles', LocationsSearchSettings::get('map_styles')), 'focus_country' => LocationsSearchSettings::get('focus_country'), 'focus_country_strict' => LocationsSearchSettings::get('focus_country_strict'), 'text_did_you_mean' => 'Did you mean:', 'text_0_results' => 'No results found', 'text_1_result' => '1 result found', 'text_more_results' => '# results found', 'text_please_enter_address' => 'Please enter an address', 'error_invalid_request' => 'Invalid request, please verify that the requested address is correct', 'error_query_limit' => 'You have exceeded the maximum number of allowed queries, please wait for some time before trying again', 'error_no_results' => 'No results found, please try a different address', 'error_unknown' => 'There was an unknown error', 'initial_lat' => -33.865, 'initial_lng' => 151.2094, 'text_current_location' => '(current location)', 'map_marker_active' => apply_filters('locations_search_map_marker_active', LocationsSearchModel::get_marker_data(LocationsSearchSettings::get('map_marker_active'))), 'map_cluster' => apply_filters('locations_search_map_cluster', array('imagePath' => LocationsSearch::get_url() . '/vendor/marker-clusterer/m', 'maxZoom' => 13, 'styles' => LocationsSearchModel::get_cluster_data()))));
     wp_enqueue_style('locations-search', LocationsSearch::get_url() . '/css/locations-search.css', array(), LOCATIONSSEARCHVERSION);
 }
 public static function get($field_key)
 {
     // Load field value
     if (is_null(self::$option)) {
         self::$option = get_option(self::$option_name);
     }
     $field_value = isset(self::$option[$field_key]) ? self::$option[$field_key] : '';
     // Fallback values
     if ($field_key == 'permalinks_base' && empty($field_value)) {
         $field_value = 'locations';
     }
     if ($field_key == 'permalinks_category' && empty($field_value)) {
         $field_value = 'locations-category';
     }
     // $bias_bounds;
     // $restrict_state;
     // $restrict_postcode;
     // $restrict_suburb;
     // $restrict_street;
     // $language
     // Return
     return $field_value;
 }
 public static function get_cluster_data($attachment_id = false)
 {
     // Check attachment_id
     if ($attachment_id === false) {
         $attachment_id = LocationsSearchSettings::get('map_cluster');
     }
     $attachment_id = absint($attachment_id);
     // Get data
     $attachment_data = wp_get_attachment_image_src($attachment_id, 'medium');
     if (empty($attachment_data)) {
         return false;
     }
     // Prepare data
     $url = $attachment_data[0];
     $width = $scaledWidth = $attachment_data[1];
     $height = $scaledHeight = $attachment_data[2];
     if ($scaledWidth > 40) {
         $ratio = 40 / $scaledWidth;
         $scaledWidth = 40;
         $scaledHeight = round($scaledHeight * $ratio);
     }
     if ($scaledHeight > 40) {
         $ratio = 40 / $scaledHeight;
         $scaledHeight = 40;
         $scaledWidth = round($scaledWidth * $ratio);
     }
     // Return data
     $cluster = array(array('url' => $url, 'width' => $scaledWidth, 'height' => $scaledHeight, 'backgroundPosition' => 'center center; background-size: contain'));
     return $cluster;
 }
Ejemplo n.º 4
0
 public function load_assets($hook)
 {
     // Only on post edit screen
     if (!in_array($hook, array('post.php', 'post-new.php')) || get_post_type() != $this->post_type) {
         return;
     }
     // Load assets
     wp_enqueue_script('location-edit-google-maps-api', '//maps.googleapis.com/maps/api/js?key=' . LocationsSearchSettings::get('google_api_key'));
     wp_enqueue_script('location-edit-screen', LocationsSearch::get_url() . '/js/location-edit.js', array('location-edit-google-maps-api', 'jquery'), LOCATIONSSEARCHVERSION);
     wp_enqueue_style('location-edit-screen', LocationsSearch::get_url() . '/css/location-edit.css', array(), LOCATIONSSEARCHVERSION);
 }
 public static function get_formatted_address($post)
 {
     $meta_keys = array('address', 'address2', 'suburb', 'state', 'postcode', 'country');
     foreach ($meta_keys as $meta_key) {
         ${$meta_key} = trim(esc_html(get_post_meta($post->ID, $meta_key, true)));
     }
     $focus_country = LocationsSearchGeneric::get_country_name(LocationsSearchSettings::get('focus_country'));
     if ($country == $focus_country) {
         $country = '';
     }
     $address_line_1 = $address;
     $address_line_2 = $address2;
     $address_line_3 = implode(', ', array_filter(array($suburb, $state, $postcode, $country)));
     $formatted_address = implode('<br>', array_filter(array($address_line_1, $address_line_2, $address_line_3)));
     return $formatted_address;
 }