Exemple #1
0
 /**
  * Resolve and queue map scripts.
  * 
  * @since 1.5
  * @global object $geo_mashup_options
  * @global object $geo_mashup_custom
  * 
  * @param array $map_data Map data for the current query.
  */
 private static function enqueue_scripts($map_data)
 {
     global $geo_mashup_options, $geo_mashup_custom;
     // Queue scripts
     $mashup_dependencies = array('jquery');
     $language_code = GeoMashup::get_language_code();
     $load_markerclusterer = false;
     if ('google' == $map_data['map_api']) {
         // Google v2 base
         $google_2_url = 'http://maps.google.com/maps?file=api&v=2&sensor=false&key=' . $geo_mashup_options->get('overall', 'google_key');
         if (!empty($language_code)) {
             $google_2_url .= '&hl=' . substr($language_code, 0, 2);
         }
         wp_register_script('google-maps-2', $google_2_url, '', '', true);
         $mashup_dependencies[] = 'google-maps-2';
         $mashup_script = 'geo-mashup-google';
         if (!empty($map_data['cluster_max_zoom'])) {
             // Queue clustering scripts
             GeoMashup::register_script('mapiconmaker', 'js/mapiconmaker.js', array('google-maps-2'), '1.1', true);
             GeoMashup::register_script('clustermarker', 'js/ClusterMarker.js', array('mapiconmaker'), '1.3.2', true);
             $mashup_dependencies[] = 'clustermarker';
         }
     } else {
         // Mapstraction base
         $mashup_script = 'geo-mashup-mxn';
         GeoMashup::register_script('mxn', 'js/mxn/mxn.js', null, GEO_MASHUP_VERSION, true);
         GeoMashup::register_script('mxn-core', 'js/mxn/mxn.core.js', array('mxn'), GEO_MASHUP_VERSION, true);
     }
     // Mapstraction providers
     if ('openlayers' == $map_data['map_api']) {
         wp_register_script('openlayers', 'http://openlayers.org/api/OpenLayers.js', null, 'latest', true);
         wp_register_script('openstreetmap', 'http://www.openstreetmap.org/openlayers/OpenStreetMap.js', array('openlayers'), 'latest', true);
         GeoMashup::register_script('mxn-openlayers', 'js/mxn/mxn.openlayers.core.js', array('mxn-core', 'openstreetmap'), GEO_MASHUP_VERSION, true);
         GeoMashup::register_script('mxn-openlayers-gm', 'js/mxn/mxn.openlayers.geo-mashup.js', array('mxn-openlayers'), GEO_MASHUP_VERSION, true);
         $mashup_dependencies[] = 'mxn-openlayers-gm';
     } else {
         if ('googlev3' == $map_data['map_api']) {
             $google_3_url = 'http://maps.google.com/maps/api/js?sensor=false';
             $googlev3_key = $geo_mashup_options->get('overall', 'googlev3_key');
             if (!empty($googlev3_key)) {
                 $google_3_url .= '&key=' . $googlev3_key;
             }
             if (!empty($language_code)) {
                 $google_3_url .= '&language=' . substr($language_code, 0, 2);
             }
             $load_markerclusterer = (bool) ('single' != $map_data['map_content'] and !empty($map_data['cluster_max_zoom']));
             wp_register_script('google-maps-3', $google_3_url, '', '', true);
             if ($load_markerclusterer) {
                 // Queue clustering scripts
                 GeoMashup::register_script('markerclusterer', 'js/markerclusterer.js', array('google-maps-3'), '2.0.3', true);
                 GeoMashup::register_script('geo-mashup-modernizr', 'js/modernizr.js', array(), '2.6.2', true);
                 GeoMashup::register_script('geo-mashup-markerclusterer', 'js/geo-mashup-markerclusterer.js', array('geo-mashup-mxn', 'geo-mashup-modernizr'), GEO_MASHUP_VERSION, true);
                 $mashup_dependencies[] = 'markerclusterer';
             }
             GeoMashup::register_script('mxn-googlev3', 'js/mxn/mxn.googlev3.core.js', array('mxn-core', 'google-maps-3'), GEO_MASHUP_VERSION, true);
             GeoMashup::register_script('mxn-googlev3-gm', 'js/mxn/mxn.googlev3.geo-mashup.js', array('mxn-googlev3'), GEO_MASHUP_VERSION, true);
             $mashup_dependencies[] = 'mxn-googlev3-gm';
         }
     }
     // Geo Mashup scripts
     GeoMashup::register_script('geo-mashup', 'js/geo-mashup.js', $mashup_dependencies, GEO_MASHUP_VERSION, true);
     $feature_dependencies = array('geo-mashup');
     if (!empty($map_data['include_taxonomies'])) {
         GeoMashup::register_script('geo-mashup-taxonomy', 'js/taxonomy.js', array('geo-mashup'), GEO_MASHUP_VERSION, true);
         $feature_dependencies[] = 'geo-mashup-taxonomy';
     }
     GeoMashup::register_script($mashup_script, 'js/' . $mashup_script . '.js', $feature_dependencies, GEO_MASHUP_VERSION, true);
     wp_enqueue_script($mashup_script);
     self::enqueue_script($mashup_script);
     if ($load_markerclusterer) {
         self::enqueue_script('geo-mashup-markerclusterer');
     }
     // Custom javascript
     $custom_js_url_path = '';
     if (isset($geo_mashup_custom)) {
         $custom_js_url_path = $geo_mashup_custom->file_url('custom-' . $map_data['map_api'] . '.js');
         if (!$custom_js_url_path and 'google' != $map_data['map_api']) {
             $custom_js_url_path = $geo_mashup_custom->file_url('custom-mxn.js');
         }
         if (!$custom_js_url_path) {
             $custom_js_url_path = $geo_mashup_custom->file_url('custom.js');
         }
     } else {
         if (is_readable('custom.js')) {
             $custom_js_url_path = path_join(GEO_MASHUP_URL_PATH, 'custom.js');
         }
     }
     if (!empty($custom_js_url_path)) {
         wp_enqueue_script('geo-mashup-custom', $custom_js_url_path, array($mashup_script));
         self::enqueue_script('geo-mashup-custom');
     }
     // A general hook for rendering customizations
     do_action('geo_mashup_render_map', $mashup_script);
 }
 function widget($args, $instance)
 {
     // Arrange footer scripts
     GeoMashup::register_script('geo-mashup-search-form', 'js/search-form.js', array(), GEO_MASHUP_VERSION, true);
     wp_enqueue_script('geo-mashup-search-form');
     if (!empty($instance['find_me_button'])) {
         GeoMashup::register_script('geo-mashup-search-find-me', 'js/find-me.js', array('jquery'), GEO_MASHUP_VERSION, true);
         wp_localize_script('geo-mashup-search-find-me', 'geo_mashup_search_find_me_env', array('client_ip' => $_SERVER['REMOTE_ADDR'], 'fail_message' => __('Couldn\'t find you...', 'GeoMashup'), 'my_location_message' => __('My Location', 'GeoMashup')));
         wp_enqueue_script('geo-mashup-search-find-me');
     }
     /** @var $before_widget */
     /** @var $after_widget */
     /** @var $before_title */
     /** @var $after_title */
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     echo $before_widget . $before_title . $title . $after_title;
     $results_page_id = intval($instance['results_page_id']);
     if (!$results_page_id) {
         echo '<p class="error">';
         _e('No Geo Mashup Search result page found - check widget settings.', 'GeoMashup');
         echo '</p>';
         return;
     }
     // Set up template variables
     $widget =& $this;
     $action_url = get_permalink($results_page_id);
     $object_name = $instance['object_name'];
     $categories = array();
     if (!empty($instance['categories'])) {
         $category_args = '';
         if ('all' != $instance['categories']) {
             $category_args = 'include=' . $instance['categories'];
         }
         $categories = get_categories($category_args);
     }
     $radii = empty($instance['radius_list']) ? array() : wp_parse_id_list($instance['radius_list']);
     // Load the template
     $template = GeoMashup::locate_template('search-form');
     require $template;
     echo $after_widget;
 }
 /**
  * Print the form script in the footer if it's needed.
  *
  * @since 1.4
  */
 public function wp_footer()
 {
     global $geo_mashup_options;
     if ($this->add_form_script) {
         GeoMashup::register_script('geo-mashup-comment-form', 'js/comment-form.js', array('jquery'), GEO_MASHUP_VERSION, true);
         wp_localize_script('geo-mashup-comment-form', 'geo_mashup_comment_form_settings', array('geonames_username' => $geo_mashup_options->get('overall', 'geonames_username')));
         wp_print_scripts('geo-mashup-comment-form');
     }
 }
 /**
  * Render the requested map.
  *
  * @since 1.4
  */
 public static function render_map()
 {
     global $geo_mashup_options, $geo_mashup_custom;
     // Include theme stylesheet if requested
     if ($geo_mashup_options->get('overall', 'theme_stylesheet_with_maps') == 'true') {
         wp_enqueue_style('theme-style', get_stylesheet_uri());
         self::enqueue_style('theme-style');
     }
     // Resolve map style
     $style_file_path = path_join(get_stylesheet_directory(), 'map-style.css');
     $style_url_path = '';
     if (is_readable($style_file_path)) {
         $style_url_path = path_join(get_stylesheet_directory_uri(), 'map-style.css');
     } else {
         if (isset($geo_mashup_custom)) {
             $style_url_path = $geo_mashup_custom->file_url('map-style.css');
         }
     }
     if (empty($style_url_path)) {
         GeoMashup::register_style('geo-mashup-map-style', 'css/map-style-default.css');
     } else {
         wp_register_style('geo-mashup-map-style', $style_url_path);
     }
     wp_enqueue_style('geo-mashup-map-style');
     self::enqueue_style('geo-mashup-map-style');
     if (isset($_GET['map_data_key'])) {
         // Map data is cached in a transient
         $map_data = get_transient('gmm' . $_GET['map_data_key']);
         if (!$map_data) {
             $map_parameters = get_transient('gmp' . $_GET['map_data_key']);
             if ($map_parameters) {
                 $map_data = GeoMashup::build_map_data($map_parameters);
             } else {
                 $map_data = GeoMashup::build_map_data('');
             }
         }
     } else {
         // Try building map data from the query string
         $map_data = GeoMashup::build_map_data($_GET);
     }
     // Queue scripts
     $mashup_dependencies = array('jquery');
     $language_code = GeoMashup::get_language_code();
     if ('google' == $map_data['map_api']) {
         // Google v2 base
         $google_2_url = 'http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=' . $geo_mashup_options->get('overall', 'google_key');
         if (!empty($language_code)) {
             $google_2_url .= '&amp;hl=' . $language_code;
         }
         wp_register_script('google-maps-2', $google_2_url, '', '', true);
         $mashup_dependencies[] = 'google-maps-2';
         $mashup_script = 'geo-mashup-google';
         if (!empty($map_data['cluster_max_zoom'])) {
             // Queue clustering scripts
             if ('clustermarker' == $map_data['cluster_lib']) {
                 GeoMashup::register_script('mapiconmaker', 'js/mapiconmaker.js', array('google-maps-2'), '1.1', true);
                 GeoMashup::register_script('clustermarker', 'js/ClusterMarker.js', array('mapiconmaker'), '1.3.2', true);
                 $mashup_dependencies[] = 'clustermarker';
             } else {
                 $map_data['cluster_lib'] = 'markerclusterer';
                 GeoMashup::register_script('markerclusterer', 'js/markerclusterer.js', array('google-maps-2', 'geo-mashup-google'), '1.0', true);
                 wp_enqueue_script('markerclusterer');
                 self::enqueue_script('markerclusterer');
             }
         }
     } else {
         // Mapstraction base
         $mashup_script = 'geo-mashup-mxn';
         GeoMashup::register_script('mxn', 'js/mxn/mxn.js', null, GEO_MASHUP_VERSION, true);
         GeoMashup::register_script('mxn-core', 'js/mxn/mxn.core.js', array('mxn'), GEO_MASHUP_VERSION, true);
     }
     // Mapstraction providers
     if ('openlayers' == $map_data['map_api']) {
         wp_register_script('openlayers', 'http://openlayers.org/api/OpenLayers.js', null, 'latest', true);
         wp_register_script('openstreetmap', 'http://www.openstreetmap.org/openlayers/OpenStreetMap.js', array('openlayers'), 'latest', true);
         GeoMashup::register_script('mxn-openlayers', 'js/mxn/mxn.openlayers.core.js', array('mxn-core', 'openstreetmap'), GEO_MASHUP_VERSION, true);
         GeoMashup::register_script('mxn-openlayers-gm', 'js/mxn/mxn.openlayers.geo-mashup.js', array('mxn-openlayers'), GEO_MASHUP_VERSION, true);
         $mashup_dependencies[] = 'mxn-openlayers-gm';
     } else {
         if ('googlev3' == $map_data['map_api']) {
             $google_3_url = 'http://maps.google.com/maps/api/js?sensor=false';
             if (!empty($language_code)) {
                 $google_3_url .= '&amp;language=' . $language_code;
             }
             wp_register_script('google-maps-3', $google_3_url, '', '', true);
             GeoMashup::register_script('mxn-googlev3', 'js/mxn/mxn.googlev3.core.js', array('mxn-core', 'google-maps-3'), GEO_MASHUP_VERSION, true);
             $mashup_dependencies[] = 'mxn-googlev3';
         }
     }
     // Geo Mashup scripts
     GeoMashup::register_script('geo-mashup', 'js/geo-mashup.js', $mashup_dependencies, GEO_MASHUP_VERSION, true);
     GeoMashup::register_script($mashup_script, 'js/' . $mashup_script . '.js', array('geo-mashup'), GEO_MASHUP_VERSION, true);
     wp_enqueue_script($mashup_script);
     self::enqueue_script($mashup_script);
     // Custom javascript
     $custom_js_url_path = '';
     if (isset($geo_mashup_custom)) {
         $custom_js_url_path = $geo_mashup_custom->file_url('custom-' . $map_data['map_api'] . '.js');
         if (!$custom_js_url_path and 'google' != $map_data['map_api']) {
             $custom_js_url_path = $geo_mashup_custom->file_url('custom-mxn.js');
         }
         if (!$custom_js_url_path) {
             $custom_js_url_path = $geo_mashup_custom->file_url('custom.js');
         }
     } else {
         if (is_readable('custom.js')) {
             $custom_js_url_path = path_join(GEO_MASHUP_URL_PATH, 'custom.js');
         }
     }
     if (!empty($custom_js_url_path)) {
         wp_enqueue_script('geo-mashup-custom', $custom_js_url_path, array($mashup_script));
         self::enqueue_script('geo-mashup-custom');
     }
     // Set height and width properties for the template
     $width = $map_data['width'];
     if (substr($width, -1) != '%') {
         $width .= 'px';
     }
     unset($map_data['width']);
     self::map_property('width', $width);
     $height = $map_data['height'];
     if (substr($height, -1) != '%') {
         $height .= 'px';
     }
     unset($map_data['height']);
     self::map_property('height', $height);
     if (isset($map_data['object_data']) and is_array($map_data['object_data'])) {
         $map_data['object_data'] = json_encode($map_data['object_data']);
     }
     array_walk($map_data, array('GeoMashupRenderMap', 'add_double_quotes'));
     if ('single' == $map_data['map_content']) {
         $category_opts = '{}';
     } else {
         $categories = get_categories(array('hide_empty' => false));
         $category_opts = '{';
         if (is_array($categories)) {
             $cat_comma = '';
             $category_color = $geo_mashup_options->get('global_map', 'category_color');
             $category_line_zoom = $geo_mashup_options->get('global_map', 'category_line_zoom');
             foreach ($categories as $category) {
                 $category_opts .= $cat_comma . '"' . $category->term_id . '":{"name":"' . esc_js($category->name) . '"';
                 $parent_id = '';
                 if (!empty($category->parent)) {
                     $parent_id = $category->parent;
                 }
                 $category_opts .= ',"parent_id":"' . $parent_id . '"';
                 if (!empty($category_color[$category->slug])) {
                     $category_opts .= ',"color_name":"' . $category_color[$category->slug] . '"';
                 }
                 if (!empty($category_line_zoom[$category->slug])) {
                     $category_opts .= ',"max_line_zoom":"' . $category_line_zoom[$category->slug] . '"';
                 }
                 $category_opts .= '}';
                 $cat_comma = ',';
             }
         }
         $category_opts .= '}';
     }
     $map_data['category_opts'] = $category_opts;
     // Store the properties for use by the template tag GeoMashupRenderMap::map_script
     self::$map_data = $map_data;
     // Load the template
     status_header(200);
     load_template(GeoMashup::locate_template('map-frame'));
 }