/** * 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>'; }