/** * Render an GEO microformat for the specified latitude and longitude * * @param float $latitude * @param float $longitude */ public static function render($arguments = array()) { // Arguments $defaults = array('echo' => true); $arguments = wp_parse_args($arguments, $defaults); // Options $options = Pronamic_Google_Maps_Maps::getOptions(); $pgm = Pronamic_Google_Maps_Maps::getMetaData(); $activeTypes = $options['active']; global $post; $active = isset($activeTypes[$post->post_type]) && $activeTypes[$post->post_type]; // Active if ($active && $pgm->active) { $content = sprintf(' <div class="geo"> <abbr class="latitude" title="%.6f">%s</abbr> <abbr class="longitude" title="%.6f">%s</abbr> </div>', $pgm->latitude, Pronamic_Google_Maps_LatLng::convertToDegMinSec($pgm->latitude, Pronamic_Google_Maps_LatLng::DIRECTION_LATITUDE), $pgm->longitude, Pronamic_Google_Maps_LatLng::convertToDegMinSec($pgm->longitude, Pronamic_Google_Maps_LatLng::DIRECTION_LONGITUDE)); if ($arguments['echo']) { echo $content; } else { return $content; } } }
/** * Render the widget * * @param array $arguments * @param array $instance */ public function widget($arguments, $instance) { extract($arguments); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $info = new Pronamic_Google_Maps_Info(); $info->title = $instance['title']; $info->description = $instance['description']; $info->width = $instance['width']; $info->height = $instance['height']; $info->latitude = (double) $instance['latitude']; $info->longitude = (double) $instance['longitude']; $info->static = $instance['static']; $info->mapOptions->mapTypeId = $instance['map-type']; $info->mapOptions->zoom = (int) $instance['zoom']; if ($info->isDynamic()) { Pronamic_Google_Maps_Site::requireSiteScript(); } echo Pronamic_Google_Maps_Maps::getMapHtml($info); echo $after_widget; }
function pronamic_google_maps($arguments = array()) { return Pronamic_Google_Maps_Maps::render($arguments); }
/** * Render an Google Maps for the current global post * * @param mixed $arguments */ public static function render($arguments = array()) { $defaults = array('width' => self::$defaultWidth, 'height' => self::$defaultHeight, 'static' => false, 'label' => null, 'color' => null, 'echo' => true, 'marker_options' => array(), 'map_options' => array()); $arguments = wp_parse_args($arguments, $defaults); $options = Pronamic_Google_Maps_Maps::getOptions(); $pgm = Pronamic_Google_Maps_Maps::getMetaData(); $activeTypes = $options['active']; global $post; $active = isset($activeTypes[$post->post_type]) && $activeTypes[$post->post_type]; if ($active && $pgm->active) { $info = new Pronamic_Google_Maps_Info(); $info->title = $pgm->title; $info->description = $pgm->description; $info->latitude = $pgm->latitude; $info->longitude = $pgm->longitude; $info->width = $arguments['width']; $info->height = $arguments['height']; $info->static = filter_var($arguments['static'], FILTER_VALIDATE_BOOLEAN); $info->label = $arguments['label']; $info->color = $arguments['color']; // Marker options $marker_options = $arguments['marker_options']; $marker_options = apply_filters('pronamic_google_maps_marker_options', $marker_options); foreach ($marker_options as $key => $value) { $value = apply_filters('pronamic_google_maps_marker_options_' . $key, $value); $info->markerOptions->{$key} = $value; } // Map options $info->mapOptions->mapTypeId = $pgm->mapType; $info->mapOptions->zoom = $pgm->zoom; foreach ($arguments['map_options'] as $key => $value) { $value = apply_filters('pronamic_google_maps_map_options_' . $key, $value); $info->mapOptions->{$key} = $value; } $html = self::getMapHtml($info); if ($info->isDynamic()) { Pronamic_Google_Maps_Site::requireSiteScript(); } if ($arguments['echo']) { echo $html; } else { return $html; } } }
/** * Add the meta box */ public static function addMetaBox() { $options = Pronamic_Google_Maps_Maps::getOptions(); if (isset($options['active'])) { $types = $options['active']; if (is_array($types)) { foreach ($types as $name => $active) { Pronamic_Google_Maps_MetaBox::register($name); } } } }
public static function render($q = array(), $arguments = array()) { Pronamic_Google_Maps_Site::requireSiteScript(); $defaults = array('width' => Pronamic_Google_Maps_Maps::$defaultWidth, 'height' => Pronamic_Google_Maps_Maps::$defaultHeight, 'latitude' => 0, 'longitude' => 0, 'zoom' => Pronamic_Google_Maps_Maps::MAP_ZOOM_DEFAULT, 'map_type_id' => Pronamic_Google_Maps_Maps::MAP_TYPE_DEFAULT, 'hide_list' => true, 'fit_bounds' => true, 'center_client_location' => false, 'marker_options' => array(), 'map_options' => array(), 'marker_cluster_options' => array(), 'echo' => true); $arguments = wp_parse_args($arguments, $defaults); if ($q instanceof WP_Query) { $query = $q; } else { $query = new WP_Query($q); } $options = new stdClass(); $options->width = $arguments['width']; if (is_numeric($options->width)) { $options->width = '' . $options->width . 'px'; } $options->height = $arguments['height']; if (is_numeric($options->height)) { $options->height = '' . $options->height . 'px'; } $options->center = new stdClass(); $options->center->latitude = $arguments['latitude']; $options->center->longitude = $arguments['longitude']; $options->hideList = $arguments['hide_list']; $options->fitBounds = filter_var($arguments['fit_bounds'], FILTER_VALIDATE_BOOLEAN); $options->centerClientLocation = $arguments['center_client_location']; // Map options $options->mapOptions = new stdClass(); $options->mapOptions->mapTypeId = $arguments['map_type_id']; $options->mapOptions->zoom = $arguments['zoom']; foreach ($arguments['map_options'] as $key => $value) { $value = apply_filters('pronamic_google_maps_map_options_' . $key, $value); $options->mapOptions->{$key} = $value; } // Marker cluster options if (!empty($arguments['marker_clusterer_options'])) { wp_enqueue_script('google-maps-markerclustererplus'); $options->markerClustererOptions = new stdClass(); foreach ($arguments['marker_clusterer_options'] as $key => $value) { $value = apply_filters('pronamic_google_maps_marker_clusterer_options_' . $key, $value); $options->markerClustererOptions->{$key} = $value; } } $options->markers = array(); // HTML $items = ''; while ($query->have_posts()) { $query->the_post(); $pgm = Pronamic_Google_Maps_Maps::getMetaData(); if ($pgm->active) { $description = sprintf('<a href="%s" title="%s" rel="bookmark">%s</a>', get_permalink(), sprintf(esc_attr__('Permalink to %s', 'pronamic_google_maps'), the_title_attribute('echo=0')), get_the_title()); $description = apply_filters(Pronamic_Google_Maps_Filters::FILTER_MASHUP_ITEM, $description); $info = new Pronamic_Google_Maps_Info(); $info->title = $pgm->title; $info->description = $pgm->description; $info->latitude = $pgm->latitude; $info->longitude = $pgm->longitude; $info->markerOptions = new stdClass(); // Marker options $marker_options = $arguments['marker_options']; $marker_options = apply_filters('pronamic_google_maps_marker_options', $marker_options); foreach ($marker_options as $key => $value) { $value = apply_filters('pronamic_google_maps_marker_options_' . $key, $value); $info->markerOptions->{$key} = $value; } $marker = new stdClass(); $marker->options = $info->markerOptions; $marker->lat = $pgm->latitude; $marker->lng = $pgm->longitude; $marker->title = $pgm->title; $marker->description = $description; $marker->post_id = get_the_ID(); $options->markers[] = $marker; $items .= '<li>'; $items .= sprintf('<input type="hidden" name="pgm-info" value="%s" />', esc_attr(json_encode($info))); $item = sprintf('<a href="%s" title="%s" rel="bookmark">%s</a>', get_permalink(), sprintf(esc_attr__('Permalink to %s', 'pronamic_google_maps'), the_title_attribute('echo=0')), get_the_title()); $items .= apply_filters(Pronamic_Google_Maps_Filters::FILTER_MASHUP_ITEM, $item); $items .= '</li>'; } } wp_reset_postdata(); $content = '<div class="pgmm">'; $content .= sprintf('<input type="hidden" name="pgmm-info" value="%s" />', esc_attr(json_encode($options))); $content .= sprintf('<div class="canvas" style="width: %s; height: %s;">', $options->width, $options->height); $content .= sprintf('</div>'); if (!empty($items)) { $content .= '<noscript>'; $content .= '<ul>'; $content .= $items; $content .= '</ul>'; $content .= '</noscript>'; } $content .= '</div>'; if ($arguments['echo']) { echo $content; } else { return $content; } }
/** * Shortcode map */ public static function shortcode_map($atts) { $atts = self::parse_map_options($atts); $atts['echo'] = false; return Pronamic_Google_Maps_Maps::render($atts); }
/* Plugin Name: Pronamic Google Maps Plugin URI: http://www.happywp.com/plugins/pronamic-google-maps/ Description: This plugin makes it simple to add Google Maps to your WordPress post, pages or other custom post types. Version: 2.2.9 Requires at least: 3.0 Author: Pronamic Author URI: http://www.pronamic.eu/ Text Domain: pronamic_google_maps Domain Path: /languages/ License: GPL */ if (function_exists('spl_autoload_register')) { function pronamic_google_maps_autoload($name) { $name = str_replace('\\', DIRECTORY_SEPARATOR, $name); $name = str_replace('_', DIRECTORY_SEPARATOR, $name); $file = plugin_dir_path(__FILE__) . 'classes' . DIRECTORY_SEPARATOR . $name . '.php'; if (is_file($file)) { require_once $file; } } spl_autoload_register('pronamic_google_maps_autoload'); require_once 'includes/functions.php'; Pronamic_Google_Maps_Maps::bootstrap(__FILE__); }