private function _map_from_address($address, $args = array(), $content = false)
 {
     $key = md5(serialize($args));
     $map_id = get_option($key, false);
     if (!$map_id) {
         $model = new AgmMapModel();
         $map_id = $model->autocreate_map(false, false, false, $address);
         if (!$map_id) {
             return $content;
         }
         update_option($key, $map_id);
     }
     $args['id'] = $map_id;
     $codec = new AgmMarkerReplacer();
     return $codec->process_tags($args, $content);
 }
 /**
  * Events map shortcode
  * @param  array   $args    Shortcode arguments
  * @param  boolean $content Fallback content
  * @return string           Map string or fallback content
  */
 function process_events_map_shortcode($args = array(), $content = false)
 {
     if (!class_exists('AgmMapModel') || !class_exists('AgmMarkerReplacer')) {
         return $content;
     }
     $map_args = $args;
     $args = $this->_preparse_arguments($args, array('relative_date' => false, 'date' => false, 'lookahead' => false, 'weeks' => false, 'category' => false, 'categories' => false, 'limit' => false, 'order' => false, 'allow_multiple_markers' => false, 'open_only' => true, 'show_date' => true, 'show_excerpt' => false, 'excerpt_length' => 55, 'legacy' => false, 'featured_image' => false, 'class' => false, 'template' => 'get_shortcode_events_map_marker_body_output'));
     $args['featured_image'] = $this->_arg_to_bool($args['featured_image']);
     $args['show_date'] = $this->_arg_to_bool($args['show_date']);
     $args['show_excerpt'] = $this->_arg_to_bool($args['show_excerpt']);
     $args['allow_multiple_markers'] = $this->_arg_to_bool($args['allow_multiple_markers']);
     $class = $args['class'] ? 'class="' . $args['class'] . '"' : '';
     $query = $this->_to_query_args($args);
     $order_method = $args['order'] ? create_function('', 'return "' . $args['order'] . '";') : false;
     if ($order_method) {
         add_filter('eab-collection-date_ordering_direction', $order_method);
     }
     $maps = array();
     if ($this->_arg_to_bool($args['legacy'])) {
         // Lookahead - depending on presence, use regular upcoming query, or poll week count
         if ($args['lookahead']) {
             $method = $args['weeks'] ? create_function('', 'return ' . $args['weeks'] . ';') : false;
             if ($method) {
                 add_filter('eab-collection-upcoming_weeks-week_number', $method);
             }
             $events = Eab_CollectionFactory::get_upcoming_weeks($args['date'], $query);
             if ($method) {
                 remove_filter('eab-collection-upcoming_weeks-week_number', $method);
             }
         } else {
             // No lookahead, get the full month only
             $events = Eab_CollectionFactory::get_upcoming($args['date'], $query);
         }
         if ($order_method) {
             remove_filter('eab-collection-date_ordering_direction', $order_method);
         }
         $model = new AgmMapModel();
         $raw_maps = $model->get_custom_maps($events->query);
         if (empty($raw_maps)) {
             return $content;
         }
         foreach ($raw_maps as $key => $map) {
             if (empty($map['markers']) || count($map['markers']) > 1) {
                 continue;
             }
             $event = !empty($map['post_ids']) && !empty($map['post_ids'][0]) ? new Eab_EventModel(get_post($map['post_ids'][0])) : false;
             if (!$event) {
                 continue;
             }
             $map['markers'][0]['title'] = $event->get_title();
             $map['markers'][0]['body'] = Eab_Template::util_apply_shortcode_template($event, $args);
             if ($args['featured_image']) {
                 $icon = $event->get_featured_image_url();
                 if ($icon) {
                     $map['markers'][0]['icon'] = $icon;
                 }
             }
             $maps[] = $map;
         }
     } else {
         if ($args['lookahead']) {
             $method = $args['weeks'] ? create_function('', 'return ' . $args['weeks'] . ';') : false;
             if ($method) {
                 add_filter('eab-collection-upcoming_weeks-week_number', $method);
             }
             $events = Eab_CollectionFactory::get_upcoming_weeks_events($args['date'], $query);
             if ($method) {
                 remove_filter('eab-collection-upcoming_weeks-week_number', $method);
             }
         } else {
             // No lookahead, get the full month only
             $events = Eab_CollectionFactory::get_upcoming_events($args['date'], $query);
         }
         if ($order_method) {
             remove_filter('eab-collection-date_ordering_direction', $order_method);
         }
         $open_only = $this->_arg_to_bool($args['open_only']);
         foreach ($events as $event) {
             if ($open_only && !$event->is_open()) {
                 continue;
             }
             $map = $event->get_raw_map();
             if (!is_array($map) || empty($map)) {
                 continue;
             }
             if (empty($map['markers'])) {
                 continue;
             }
             if (empty($args['allow_multiple_markers']) && count($map['markers']) > 1) {
                 continue;
             }
             // Even with multiple markers, only deal with the first one
             $marker_body = Eab_Template::util_apply_shortcode_template($event, $args);
             $map['markers'][0]['title'] = $event->get_title();
             $icon = $args['featured_image'] ? $event->get_featured_image_url() : false;
             foreach ($map['markers'] as $idx => $mrk) {
                 $map['markers'][$idx]['body'] = $marker_body;
                 if ($args['featured_image'] && !empty($icon)) {
                     $map['markers'][$idx]['icon'] = $icon;
                 }
             }
             $maps[] = $map;
         }
     }
     if (!$maps) {
         return $content;
     }
     if (!is_array($map_args)) {
         $map_args = array();
     }
     $codec = new AgmMarkerReplacer();
     return "<div {$class}>" . $codec->create_overlay_tag($maps, $map_args) . '</div>';
 }
示例#3
0
 function all_geocoded_posts_map($args = array(), $content = '')
 {
     $_yes = array('yes', 'true', 'on');
     $args = is_array($args) ? $args : array();
     $map = $this->_model->get_map_defaults();
     $map['defaults'] = $this->_model->get_map_defaults();
     $map['id'] = 'geocoded_posts-' . md5(microtime());
     $map['show_map'] = 1;
     $map['markers'] = $this->_data->get_all_geolocated_posts_as_markers(6);
     foreach ($args as $key => $arg) {
         if (in_array($arg, $_yes)) {
             $args[$key] = 1;
         }
     }
     $args['nearby_posts'] = false;
     // ... or the world explodes
     if (!empty($args['show_markers']) && empty($args['nearby_posts_in_list'])) {
         $args['nearby_posts_in_list'] = true;
         // Auto-set if not explicitly requested otherwise
     }
     $codec = new AgmMarkerReplacer();
     return $codec->create_tag($map, $args);
 }
 public function add_joint_my_appointments_map($out, $my_appointments)
 {
     if (empty($my_appointments)) {
         return $out;
     }
     if (!class_exists('AgmMarkerReplacer')) {
         return $out;
     }
     $maps = array();
     foreach ($my_appointments as $app) {
         if (empty($app->location)) {
             continue;
         }
         $location = $this->_locations->find_by('id', $app->location);
         $map = $location->to_map();
         if (!$map) {
             continue;
         }
         $maps[] = $map;
     }
     if (empty($maps)) {
         return $out;
     }
     $codec = new AgmMarkerReplacer();
     $overrides = !empty($this->_data['google_maps']['overrides']) ? $this->_data['google_maps']['overrides'] : array();
     $overrides['show_images'] = !empty($overrides['show_images']) ? $overrides['show_images'] : 0;
     $out .= $codec->create_overlay_tag($maps, $overrides);
     return $out;
 }
 /**
  * Get venue map tag.
  * @param string $venue Venue
  * @param array $args Optional map overrides
  * @return string Map tag
  */
 private function _venue_to_map($venue, $args = array())
 {
     $venue = $venue ? $venue : $this->get_venue();
     if (!class_exists('AgmMarkerReplacer')) {
         return $venue;
     }
     if (!$this->has_venue_map($venue)) {
         return $venue;
     }
     $codec = new AgmMarkerReplacer();
     if (empty($args)) {
         $args = apply_filters('eab-maps-map_defaults', array());
         $args = apply_filters('agm_google_maps-autogen_map-shortcode_attributes', $args);
     }
     return $codec->create_tag($this->_get_venue_map($venue), $args);
 }
 /**
  * Creates a map from a list of markers.
  */
 private function _create_map($markers, $id = false, $overrides = array())
 {
     if (!$markers) {
         return false;
     }
     $id = $id ? $id : md5(time() . rand());
     $map = $this->_model->get_map_defaults();
     $map['defaults'] = $this->_model->get_map_defaults();
     $map['id'] = $id;
     $map['show_map'] = 1;
     $map['show_markers'] = 0;
     $map['markers'] = $markers;
     $codec = new AgmMarkerReplacer();
     return $codec->create_tag($map, $overrides);
 }
 /**
  * Adds needed hooks.
  *
  * @access private
  */
 function add_hooks()
 {
     // Step1a: Add root dependencies
     add_action('wp_print_scripts', array($this, 'js_maps_global'));
     add_action('wp_print_scripts', array($this, 'js_plugin_url'));
     add_action('wp_print_styles', array($this, 'css_load_styles'));
     // Step1b: Add Google Maps dependencies
     add_action('wp_print_scripts', array($this, 'js_google_maps_api'));
     // Step 1c: Additiona styles
     add_action('wp_head', array($this, 'css_additional_styles'));
     // Step2: Register custom fields processing
     $opts = apply_filters('agm_google_maps-options', get_option('agm_google_maps'));
     if (@$opts['use_custom_fields']) {
         add_filter('the_content', array($this, 'process_post_meta'), 1);
         // Note the order
     }
     // Step3: Process map tags
     $rpl = AgmMarkerReplacer::register();
     //add_filter('the_content', array($rpl, 'process_tags'), 99);
 }
 /**
  * Adds needed hooks.
  *
  * @access private
  */
 function add_hooks()
 {
     // Step 1: Additional styles
     add_action('wp_head', array($this, 'css_additional_styles'));
     // Step2: Register custom fields processing
     $opts = apply_filters('agm_google_maps-options', get_option('agm_google_maps'));
     if (@$opts['use_custom_fields']) {
         add_filter('the_content', array($this, 'process_post_meta'), 1);
         // Note the order
     }
     // Step3: Process map tags
     $rpl = AgmMarkerReplacer::register();
 }
 private function _get_group_map_tag($group_id, $overrides = array())
 {
     $map = $this->_get_group_map($group_id);
     if (!$map) {
         return false;
     }
     $codec = new AgmMarkerReplacer();
     return $codec->create_tag($map, $overrides);
 }
 /**
  * Creates a replacer and registers shortcodes.
  *
  * @access public
  * @static
  */
 static function register()
 {
     $me = new AgmMarkerReplacer();
     $me->register_shortcodes();
 }