/** * Get the HTML for a map. * * @param array $atts Optional. Array of attributes and content for the map <div>. * @return string HTML. */ function get_map_html($atts = null) { $atts = wp_parse_args($atts, array('classes' => array(), 'styles' => array(), 'content' => '')); // Classes if (!is_array($atts['classes'])) { $atts['classes'] = array($atts['classes']); } $atts['classes'][] = 'wpgeo_map'; $atts['classes'][] = 'wp_geo_map'; // For legacy compatibility $atts['classes'] = array_unique($atts['classes']); // Styles $atts['styles'] = wp_parse_args($atts['styles'], array('width' => $this->width, 'height' => $this->height)); $styles = ''; foreach ($atts['styles'] as $style => $value) { if (in_array($style, array('width', 'height'))) { $value = wpgeo_css_dimension($value); } $styles .= $style . ':' . $value . ';'; } return sprintf('<div id="%s" class="%s" style="%s">%s</div>', esc_attr($this->get_dom_id()), esc_attr(implode(' ', $atts['classes'])), esc_attr($styles), $atts['content']); }
/** * Get WP Geo Map * * @param array $query Query args. * @param array $options Options array. * @return string Output. */ function get_wpgeo_map($query, $options = null) { global $wpgeo, $wpgeo_map_id; $wpgeo_map_id++; $id = 'wpgeo_map_id_' . $wpgeo_map_id; $wp_geo_options = get_option('wp_geo_options'); $defaults = apply_filters('wpgeo_map_default_query_args', array('width' => $wp_geo_options['default_map_width'], 'height' => $wp_geo_options['default_map_height'], 'type' => $wp_geo_options['google_map_type'], 'polylines' => $wp_geo_options['show_polylines'], 'polyline_colour' => $wp_geo_options['polyline_colour'], 'zoom' => $wp_geo_options['default_map_zoom'], 'align' => 'none', 'numberposts' => -1, 'posts_per_page' => -1, 'post_type' => 'post', 'post_status' => 'publish', 'orderby' => 'post_date', 'order' => 'DESC', 'markers' => 'large', 'offset' => 0, 'category' => null, 'include' => null, 'exclude' => null, 'meta_key' => null, 'meta_value' => null, 'post_ids' => '', 'post_mime_type' => null, 'post_parent' => null)); // Validate Args $r = wp_parse_args($query, $defaults); $r['width'] = wpgeo_css_dimension($r['width']); $r['height'] = wpgeo_css_dimension($r['height']); if ($r['posts_per_page'] < $r['numberposts']) { $r['posts_per_page'] = $r['numberposts']; } // Set 'post__in' if 'post_ids' set, but don't overwrite. if (!empty($r['post_ids']) && empty($r['post__in'])) { if (is_array($r['post_ids'])) { $r['post__in'] = $r['post_ids']; } else { $r['post__in'] = explode(',', $r['post_ids']); } } $posts = get_posts($r); // Map $map = new WPGeo_Map('id_' . $wpgeo_map_id); $map->set_size($r['width'], $r['height']); $map->set_map_centre(new WPGeo_Coord($wp_geo_options['default_map_latitude'], $wp_geo_options['default_map_longitude'])); $map->set_map_zoom($r['zoom']); $map->set_map_type($r['type']); // Points if ($posts) { foreach ($posts as $post) { $coord = get_wpgeo_post_coord($post->ID); if ($coord->is_valid_coord()) { $marker = get_post_meta($post->ID, WPGEO_MARKER_META, true); if (empty($marker)) { $marker = $r['markers']; } $map->add_point($coord, array('icon' => apply_filters('wpgeo_marker_icon', $marker, $post, 'template'), 'title' => get_wpgeo_title($post->ID), 'link' => apply_filters('wpgeo_marker_link', get_permalink($post), $post), 'post' => $post)); } } } // Polylines if (count($map->points) > 0) { if ($r['polylines'] == 'Y') { $polyline = new WPGeo_Polyline(array('color' => $r['polyline_colour'])); foreach ($map->points as $point) { $polyline->add_coord($point->get_coord()); } $map->add_polyline($polyline); } } $center_coord = $map->get_map_centre(); $wpgeo->maps->add_map($map); return $map->get_map_html(array('styles' => array('float' => $r['align']))); }
/** * @method Options Page * @description Outputs the options page. */ function options_page() { global $wpgeo; $wp_geo_options = get_option('wp_geo_options'); // Process option updates if (isset($_POST['action']) && $_POST['action'] == 'update') { $wp_geo_options['google_api_key'] = $_POST['google_api_key']; $wp_geo_options['google_map_type'] = $_POST['google_map_type']; $wp_geo_options['show_post_map'] = $_POST['show_post_map']; $wp_geo_options['default_map_latitude'] = empty($_POST['default_map_latitude']) ? $wpgeo->default_map_latitude : $_POST['default_map_latitude']; $wp_geo_options['default_map_longitude'] = empty($_POST['default_map_longitude']) ? $wpgeo->default_map_longitude : $_POST['default_map_longitude']; $wp_geo_options['default_map_width'] = wpgeo_css_dimension($_POST['default_map_width']); $wp_geo_options['default_map_height'] = wpgeo_css_dimension($_POST['default_map_height']); $wp_geo_options['default_map_zoom'] = $_POST['default_map_zoom']; $wp_geo_options['default_map_control'] = $_POST['default_map_control']; $wp_geo_options['show_map_type_normal'] = isset($_POST['show_map_type_normal']) && $_POST['show_map_type_normal'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_map_type_satellite'] = isset($_POST['show_map_type_satellite']) && $_POST['show_map_type_satellite'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_map_type_hybrid'] = isset($_POST['show_map_type_hybrid']) && $_POST['show_map_type_hybrid'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_map_type_physical'] = isset($_POST['show_map_type_physical']) && $_POST['show_map_type_physical'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_map_scale'] = isset($_POST['show_map_scale']) && $_POST['show_map_scale'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_map_overview'] = isset($_POST['show_map_overview']) && $_POST['show_map_overview'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['save_post_zoom'] = isset($_POST['save_post_zoom']) && $_POST['save_post_zoom'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['save_post_map_type'] = isset($_POST['save_post_map_type']) && $_POST['save_post_map_type'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['save_post_centre_point'] = isset($_POST['save_post_centre_point']) && $_POST['save_post_centre_point'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_polylines'] = isset($_POST['show_polylines']) && $_POST['show_polylines'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['polyline_colour'] = $_POST['polyline_colour']; $wp_geo_options['show_maps_on_home'] = isset($_POST['show_maps_on_home']) && $_POST['show_maps_on_home'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_on_pages'] = isset($_POST['show_maps_on_pages']) && $_POST['show_maps_on_pages'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_on_posts'] = isset($_POST['show_maps_on_posts']) && $_POST['show_maps_on_posts'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_in_datearchives'] = isset($_POST['show_maps_in_datearchives']) && $_POST['show_maps_in_datearchives'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_in_categoryarchives'] = isset($_POST['show_maps_in_categoryarchives']) && $_POST['show_maps_in_categoryarchives'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_in_tagarchives'] = isset($_POST['show_maps_in_tagarchives']) && $_POST['show_maps_in_tagarchives'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_in_taxarchives'] = isset($_POST['show_maps_in_taxarchives']) && $_POST['show_maps_in_taxarchives'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_in_authorarchives'] = isset($_POST['show_maps_in_authorarchives']) && $_POST['show_maps_in_authorarchives'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_in_searchresults'] = isset($_POST['show_maps_in_searchresults']) && $_POST['show_maps_in_searchresults'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_on_excerpts'] = isset($_POST['show_maps_on_excerpts']) && $_POST['show_maps_on_excerpts'] == 'Y' ? 'Y' : 'N'; $wp_geo_options['show_maps_on_customposttypes'] = array(); if (isset($_POST['show_maps_on_customposttypes']) && is_array($_POST['show_maps_on_customposttypes'])) { foreach ($_POST['show_maps_on_customposttypes'] as $key => $val) { $wp_geo_options['show_maps_on_customposttypes'][$key] = $val == 'Y' ? 'Y' : 'N'; } } $wp_geo_options['add_geo_information_to_rss'] = $_POST['add_geo_information_to_rss'] == 'Y' ? 'Y' : 'N'; update_option('wp_geo_options', $wp_geo_options); echo '<div class="updated"><p>' . __('WP Geo settings updated', 'wp-geo') . '</p></div>'; } // Markers $markers = array(); $markers['large'] = $this->markers->get_marker_by_id('large'); $markers['small'] = $this->markers->get_marker_by_id('small'); $markers['dot'] = $this->markers->get_marker_by_id('dot'); // Write the form echo ' <div class="wrap"> <h2>' . __('WP Geo Settings', 'wp-geo') . '</h2> <form method="post"> <img style="float:right; padding:0 20px 0 0; margin:0 0 20px 20px;" src="' . WPGEO_URL . 'img/logo/wp-geo.png" />'; include WPGEO_DIR . 'admin/donate-links.php'; echo '<h3>' . __('General Settings', 'wp-geo') . '</h3> <p>' . sprintf(__("For more information and documentation about this plugin please visit the <a %s>WP Geo Plugin</a> home page.", 'wp-geo'), 'href="http://www.benhuson.co.uk/wordpress-plugins/wp-geo/"') . '<br />' . sprintf(__("If you experience any problems/bugs with the plugin, please <a %s>log it here</a>.", 'wp-geo'), 'href="http://code.google.com/p/wp-geo/issues/list"') . '</p>'; if (!$wpgeo->markers->marker_folder_exists()) { echo '<div class="error"><p>' . sprintf(__("Unable to create the markers folder %s.<br />Please create it and copy the marker images to it from %s</p>", 'wp-geo'), str_replace(ABSPATH, '', $wpgeo->markers->upload_dir) . '/wp-geo/markers/', str_replace(ABSPATH, '', WP_PLUGIN_DIR) . WPGEO_SUBDIR . 'img/markers') . '</div>'; } if (!$this->checkGoogleAPIKey()) { echo '<div class="error"><p>Before you can use Wp Geo you must acquire a <a href="http://code.google.com/apis/maps/documentation/javascript/v2/introduction.html#Obtaining_Key">Google API Key</a> for your blog - the plugin will not function without it!</p></div>'; } echo '<table class="form-table"> <tr valign="top"> <th scope="row">' . __('Google API Key', 'wp-geo') . '</th> <td><input name="google_api_key" type="text" id="google_api_key" value="' . $wp_geo_options['google_api_key'] . '" size="50" /></td> </tr> <tr valign="top"> <th scope="row">' . __('Map Type', 'wp-geo') . '</th> <td>' . $wpgeo->google_map_types('menu', $wp_geo_options['google_map_type']) . '</td> </tr> <tr valign="top"> <th scope="row">' . __('Show Post Map', 'wp-geo') . '</th> <td>' . $wpgeo->post_map_menu('menu', $wp_geo_options['show_post_map']) . '<br /> ' . $wpgeo->options_checkbox('show_maps_on_excerpts', 'Y', $wp_geo_options['show_maps_on_excerpts']) . ' ' . __('Show on excerpts', 'wp-geo') . ' </td> </tr> <tr valign="top"> <th scope="row">' . __('Default Map Location', 'wp-geo') . '</th> <td> <label for="default_map_latitude" style="width:70px; display:inline-block;">Latitude</label> <input name="default_map_latitude" type="text" id="default_map_latitude" value="' . $wp_geo_options['default_map_latitude'] . '" size="25" /><br /> <label for="default_map_longitude" style="width:70px; display:inline-block;">Longitude</label> <input name="default_map_longitude" type="text" id="default_map_longitude" value="' . $wp_geo_options['default_map_longitude'] . '" size="25" /> </td> </tr> <tr valign="top"> <th scope="row">' . __('Default Map Width', 'wp-geo') . '</th> <td><input name="default_map_width" type="text" id="default_map_width" value="' . $wp_geo_options['default_map_width'] . '" size="10" /></td> </tr> <tr valign="top"> <th scope="row">' . __('Default Map Height', 'wp-geo') . '</th> <td><input name="default_map_height" type="text" id="default_map_height" value="' . $wp_geo_options['default_map_height'] . '" size="10" /></td> </tr> <tr valign="top"> <th scope="row">' . __('Default Map Zoom', 'wp-geo') . '</th> <td>' . $wpgeo->selectMapZoom('menu', $wp_geo_options['default_map_zoom']) . '</td> </tr> <tr valign="top"> <th scope="row">' . __('Default Map Controls', 'wp-geo') . '</th> <td> ' . $wpgeo->selectMapControl('menu', $wp_geo_options['default_map_control']) . '<br /> <p style="margin:1em 0 0 0;"><strong>' . __('Map Type Controls', 'wp-geo') . '</strong></p> <p style="margin:0;">' . __('You must select at least 2 map types for the control to show.', 'wp-geo') . '</p> ' . $wpgeo->options_checkbox('show_map_type_normal', 'Y', $wp_geo_options['show_map_type_normal']) . ' ' . __('Normal map', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_map_type_satellite', 'Y', $wp_geo_options['show_map_type_satellite']) . ' ' . __('Satellite (photographic map)', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_map_type_hybrid', 'Y', $wp_geo_options['show_map_type_hybrid']) . ' ' . __('Hybrid (photographic map with normal features)', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_map_type_physical', 'Y', $wp_geo_options['show_map_type_physical']) . ' ' . __('Physical (terrain map)', 'wp-geo') . '<br /> <p style="margin:1em 0 0 0;"><strong>' . __('Other Controls', 'wp-geo') . '</strong></p> ' . $wpgeo->options_checkbox('show_map_scale', 'Y', $wp_geo_options['show_map_scale']) . ' ' . __('Show map scale', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_map_overview', 'Y', $wp_geo_options['show_map_overview']) . ' ' . __('Show collapsible overview map (in the corner of the map)', 'wp-geo') . ' </td> </tr> <tr valign="top"> <th scope="row">' . __('Default Post Options', 'wp-geo') . '</th> <td> <p style="margin:0;"> ' . $wpgeo->options_checkbox('save_post_zoom', 'Y', $wp_geo_options['save_post_zoom']) . ' ' . __('Save custom map zoom for this post', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('save_post_map_type', 'Y', $wp_geo_options['save_post_map_type']) . ' ' . __('Save custom map type for this post', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('save_post_centre_point', 'Y', $wp_geo_options['save_post_centre_point']) . ' ' . __('Save map centre point for this post', 'wp-geo') . ' </p> </td> </tr> <tr valign="top"> <th scope="row">' . __('Polylines', 'wp-geo') . '</th> <td>' . $wpgeo->options_checkbox('show_polylines', 'Y', $wp_geo_options['show_polylines']) . ' ' . __('Show polylines (to connect multiple points on a single map)', 'wp-geo') . '</td> </tr> <tr valign="top"> <th scope="row">' . __('Polyline Colour', 'wp-geo') . '</th> <td><input name="polyline_colour" type="text" id="polyline_colour" value="' . $wp_geo_options['polyline_colour'] . '" size="7" /></td> </tr> <tr valign="top"> <th scope="row">' . __('Show Maps On', 'wp-geo') . '</th> <td> ' . $wpgeo->options_checkbox('show_maps_on_pages', 'Y', $wp_geo_options['show_maps_on_pages']) . ' ' . __('Pages', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_maps_on_posts', 'Y', $wp_geo_options['show_maps_on_posts']) . ' ' . __('Posts (single posts)', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_maps_on_home', 'Y', $wp_geo_options['show_maps_on_home']) . ' ' . __('Posts home page', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_maps_in_datearchives', 'Y', $wp_geo_options['show_maps_in_datearchives']) . ' ' . __('Posts in date archives', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_maps_in_categoryarchives', 'Y', $wp_geo_options['show_maps_in_categoryarchives']) . ' ' . __('Posts in category archives', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_maps_in_tagarchives', 'Y', $wp_geo_options['show_maps_in_tagarchives']) . ' ' . __('Posts in tag archives', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_maps_in_taxarchives', 'Y', $wp_geo_options['show_maps_in_taxarchives']) . ' ' . __('Posts in taxonomy archives', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_maps_in_authorarchives', 'Y', $wp_geo_options['show_maps_in_authorarchives']) . ' ' . __('Posts in author archives', 'wp-geo') . '<br /> ' . $wpgeo->options_checkbox('show_maps_in_searchresults', 'Y', $wp_geo_options['show_maps_in_searchresults']) . ' ' . __('Search Results', 'wp-geo') . '<br />'; if (function_exists('get_post_types') && function_exists('post_type_supports')) { $custom_post_type_checkboxes = ''; $post_types = get_post_types(array(), 'objects'); foreach ($post_types as $post_type) { if ($post_type->name == 'post' || $post_type->name == 'page') { continue; } if ($post_type->show_ui) { $custom_post_type_checkbox_value = isset($wp_geo_options['show_maps_on_customposttypes'][$post_type->query_var]) ? $wp_geo_options['show_maps_on_customposttypes'][$post_type->query_var] : ''; $custom_post_type_disabled = false; if (post_type_supports($post_type->query_var, 'wpgeo')) { $custom_post_type_checkbox_value = 'Y'; $custom_post_type_disabled = true; } $custom_post_type_checkboxes .= $wpgeo->options_checkbox('show_maps_on_customposttypes[' . $post_type->query_var . ']', 'Y', $custom_post_type_checkbox_value, $custom_post_type_disabled) . ' ' . __($post_type->label, 'wp-geo') . '<br />'; } elseif (post_type_supports($post_type->query_var, 'wpgeo')) { $custom_post_type_checkboxes .= $wpgeo->options_checkbox('show_maps_on_customposttypes[' . $post_type->query_var . ']', 'Y', 'Y', true) . ' ' . __($post_type->label, 'wp-geo') . '<br />'; } } if (!empty($custom_post_type_checkboxes)) { $custom_post_type_checkboxes = '<strong>Custom Post Types</strong><br />' . $custom_post_type_checkboxes; } echo $custom_post_type_checkboxes; } echo ' </td> </tr> <tr valign="top"> <th scope="row">' . __('Feeds', 'wp-geo') . '</th> <td>' . $wpgeo->options_checkbox('add_geo_information_to_rss', 'Y', $wp_geo_options['add_geo_information_to_rss']) . ' ' . __('Add geographic information', 'wp-geo') . '</td> </tr> </table> <p class="submit"> <input type="submit" name="Submit" value="' . __('Save Changes', 'wp-geo') . '" /> <input type="hidden" name="action" value="update" /> <input type="hidden" name="option_fields" value="google_api_key,google_map_type,show_post_map" /> </p> <h2 style="margin-top:30px;">' . __('Marker Settings', 'wp-geo') . '</h2>' . __('<p>Custom marker images are automatically created in your WordPress uploads folder and used by WP Geo.<br />A copy of these images will remain in the WP Geo folder in case you need to revert to them at any time.<br />You may edit these marker icons if you wish - they must be PNG files. Each marker consist of a marker image and a shadow image. If you do not wish to show a marker shadow you should use a transparent PNG for the shadow file.</p><p>Currently you must update these images manually and the anchor point must be the same - looking to provide more control in future versions.</p>', 'wp-geo') . ' ' . $wpgeo->markers->get_admin_display(); if (function_exists('register_setting') && function_exists('settings_fields')) { settings_fields('wp-geo-options'); } echo '</form> <h2 style="margin-top:30px;">' . __('Documentation', 'wp-geo') . '</h2>' . __('<p>If you set the Show Post Map setting to "Manual", you can use the Shortcode <code>[wp_geo_map]</code> in a post to display a map (if a location has been set for the post). You can only include the Shortcode once within a post. If you select another Show Post Map option then the Shortcode will be ignored and the map will be positioned automatically.</p>', 'wp-geo') . '<h2 style="margin-top:30px;">' . __('Feedback', 'wp-geo') . '</h2>' . sprintf(__("<p>If you experience any problems or bugs with the plugin, or want to suggest an improvement, please visit the <a %s>WP Geo Google Code page</a> to log your issue. If you would like to feedback or comment on the plugin please visit the <a %s>WP Geo plugin</a> page.</p>", 'wp-geo'), 'href="http://code.google.com/p/wp-geo/issues/list"', 'href="http://www.benhuson.co.uk/wordpress-plugins/wp-geo/"') . sprintf(__("<p>If you like WP Geo and would like to make a donation, please do so on the <a %s>WP Geo website</a>. Your contributions help to ensure that I can dedicate more time to the support and development of the plugin.</p>", 'wp-geo'), 'href="http://www.wpgeo.com/" target="_blank"') . ' </div>'; }