Пример #1
0
<?php

/**
 * The template for event google map
 * 
 * Override this template by copying it to yourtheme/single-event/excerpt.php
 *
 * @author 	Digital Factory
 * @package Events Maker/Templates
 * @since 	1.2.0
 */
if (!defined('ABSPATH')) {
    exit;
}
// exit if accessed directly
global $post;
// display options
$display_options = get_post_meta($post->ID, '_event_display_options', true);
// tickets enabled?
if (!$display_options['google_map']) {
    return;
}
// event locations
$locations = em_get_locations_for($post->ID);
// locations available?
if (!isset($locations) || empty($locations)) {
    return;
}
$args = apply_filters('em_single_event_google_map_args', array('width' => '100%', 'height' => '300px', 'zoom' => 15, 'maptype' => 'roadmap', 'maptypecontrol' => true, 'zoomcontrol' => true, 'streetviewcontrol' => true, 'overviewmapcontrol' => false, 'pancontrol' => false, 'rotatecontrol' => false, 'scalecontrol' => false, 'draggable' => true, 'keyboardshortcuts' => true, 'scrollzoom' => true));
em_display_google_map($args, $locations);
Пример #2
0
 /**
  * Google map shortcode.
  */
 public function google_map_shortcode($args)
 {
     $markers = array();
     $map_types = array('hybrid', 'roadmap', 'satellite', 'terrain');
     $booleans = array('on', 'off');
     $defaults = array('width' => '100%', 'height' => '300px', 'zoom' => 15, 'maptype' => 'roadmap', 'locations' => '', 'maptypecontrol' => 'on', 'zoomcontrol' => 'on', 'streetviewcontrol' => 'on', 'overviewmapcontrol' => 'off', 'pancontrol' => 'off', 'rotatecontrol' => 'off', 'scalecontrol' => 'off', 'draggable' => 'on', 'keyboardshortcuts' => 'on', 'scrollzoom' => 'on');
     $args = shortcode_atts($defaults, $args);
     $args['zoom'] = (int) $args['zoom'];
     if (!in_array(strtolower($args['maptype']), $map_types, TRUE)) {
         $args['maptype'] = $defaults['maptype'];
     }
     $args['maptype'] = strtoupper($args['maptype']);
     $args['maptypecontrol'] = $this->get_proper_arg($args['maptypecontrol'], $defaults['maptypecontrol'], $booleans);
     $args['zoomcontrol'] = $this->get_proper_arg($args['zoomcontrol'], $defaults['zoomcontrol'], $booleans);
     $args['streetviewcontrol'] = $this->get_proper_arg($args['streetviewcontrol'], $defaults['streetviewcontrol'], $booleans);
     $args['overviewmapcontrol'] = $this->get_proper_arg($args['overviewmapcontrol'], $defaults['overviewmapcontrol'], $booleans);
     $args['pancontrol'] = $this->get_proper_arg($args['pancontrol'], $defaults['pancontrol'], $booleans);
     $args['rotatecontrol'] = $this->get_proper_arg($args['rotatecontrol'], $defaults['rotatecontrol'], $booleans);
     $args['scalecontrol'] = $this->get_proper_arg($args['scalecontrol'], $defaults['scalecontrol'], $booleans);
     $args['draggable'] = $this->get_proper_arg($args['draggable'], $defaults['draggable'], $booleans);
     $args['keyboardshortcuts'] = $this->get_proper_arg($args['keyboardshortcuts'], $defaults['keyboardshortcuts'], $booleans);
     $args['scrollzoom'] = $this->get_proper_arg($args['scrollzoom'], $defaults['scrollzoom'], $booleans);
     // location ids
     $locations = $args['locations'] !== '' ? explode(',', $args['locations']) : '';
     if (is_array($locations) && !empty($locations)) {
         $locations_tmp = array();
         foreach ($locations as $location) {
             $locations_tmp[] = (int) $location;
         }
         foreach (array_unique($locations_tmp) as $location_id) {
             $location = em_get_location($location_id);
             if (!empty($location->location_meta['google_map']) && is_array($location->location_meta['google_map'])) {
                 $location->location_meta['name'] = $location->name;
                 $location->location_meta['latitude'] = $location->location_meta['google_map']['latitude'];
                 $location->location_meta['longitude'] = $location->location_meta['google_map']['longitude'];
                 $markers[] = $location->location_meta;
             } elseif (!empty($location->location_meta['latitude']) && !empty($location->location_meta['longitude'])) {
                 $location->location_meta['name'] = $location->name;
                 $markers[] = $location->location_meta;
             }
         }
     } elseif (is_tax('event-location') || in_array(get_post_type(), apply_filters('em_event_post_type', array('event'))) && is_single()) {
         $object = get_queried_object();
         // taxonomy page
         if (isset($object->term_id)) {
             $location = em_get_location($object->term_id);
             if (!empty($location->location_meta['google_map']) && is_array($location->location_meta['google_map'])) {
                 $location->location_meta['name'] = $location->name;
                 $location->location_meta['latitude'] = $location->location_meta['google_map']['latitude'];
                 $location->location_meta['longitude'] = $location->location_meta['google_map']['longitude'];
                 $markers[] = $location->location_meta;
             } elseif (!empty($location->location_meta['latitude']) && !empty($location->location_meta['longitude'])) {
                 $location->location_meta['name'] = $location->name;
                 $markers[] = $location->location_meta;
             }
         } elseif (isset($object->ID)) {
             $locations = em_get_locations_for($object->ID);
             if (is_array($locations) && !empty($locations)) {
                 foreach ($locations as $location) {
                     if (!empty($location->location_meta['google_map']) && is_array($location->location_meta['google_map'])) {
                         $location->location_meta['name'] = $location->name;
                         $location->location_meta['latitude'] = $location->location_meta['google_map']['latitude'];
                         $location->location_meta['longitude'] = $location->location_meta['google_map']['longitude'];
                         $markers[] = $location->location_meta;
                     } elseif (!empty($location->location_meta['latitude']) && !empty($location->location_meta['longitude'])) {
                         $location->location_meta['name'] = $location->name;
                         $markers[] = $location->location_meta;
                     }
                 }
             }
         }
     }
     wp_register_script('events-maker-google-maps', 'https://maps.googleapis.com/maps/api/js?sensor=false&language=' . substr(get_locale(), 0, 2));
     wp_register_script('events-maker-front-locations', EVENTS_MAKER_URL . '/js/front-locations.js', array('jquery', 'events-maker-google-maps'));
     wp_enqueue_script('events-maker-front-locations');
     wp_localize_script('events-maker-front-locations', 'emMapArgs', array('markers' => $markers, 'zoom' => $args['zoom'], 'mapTypeId' => $args['maptype'], 'mapTypeControl' => $args['maptypecontrol'], 'zoomControl' => $args['zoomcontrol'], 'streetViewControl' => $args['streetviewcontrol'], 'overviewMapControl' => $args['overviewmapcontrol'], 'panControl' => $args['pancontrol'], 'rotateControl' => $args['rotatecontrol'], 'scaleControl' => $args['scalecontrol'], 'draggable' => $args['draggable'], 'keyboardShortcuts' => $args['keyboardshortcuts'], 'scrollwheel' => $args['scrollzoom']));
     $html = '<div id="event-google-map" style="width: ' . $args['width'] . '; height: ' . $args['height'] . ';"></div>';
     return apply_filters('em_shortcode_google_map', $html);
 }
Пример #3
0
 /**
  * Generate iCal file content.
  */
 public function generate_ical_feed($query, $item)
 {
     $events = array();
     $output = '';
     switch ($query) {
         case 'single':
             $args = array('posts_per_page' => 1, 'no_found_rows' => true, 'name' => $item);
             $feedname = 'single-event-' . $item;
             break;
         case 'post_type':
             $args = array('posts_per_page' => -1);
             $feedname = 'events';
             break;
         case 'event-category':
         case 'event-tag':
         case 'event-location':
         case 'event-organizer':
             $args = array('posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => $query, 'field' => 'slug', 'terms' => $item)));
             $feedname = $query . '-' . $item;
             break;
     }
     $args = apply_filters('em_icl_feed_query_args', array_merge($args, array('post_type' => 'event', 'suppress_filters' => false, 'event_show_past_events' => false, 'event_show_occurrences' => false, 'orderby' => 'event_start_date', 'order' => 'asc')));
     // get events data
     $events = get_posts($args);
     // events query
     if (!empty($events)) {
         foreach ($events as $event) {
             // get the event date
             $start_date = get_post_meta($event->ID, '_event_start_date', true);
             $end_date = get_post_meta($event->ID, '_event_end_date', true);
             // convert to gmt, all day
             if (em_is_all_day($event->ID)) {
                 $event_start = date('Ymd', strtotime(get_gmt_from_date(date('Y-m-d H:i:s', strtotime($start_date)))));
                 $event_end = date('Ymd', strtotime(get_gmt_from_date(date('Y-m-d H:i:s', strtotime($end_date)))));
             } else {
                 $event_start = date('Ymd\\THis\\Z', strtotime(get_gmt_from_date(date('Y-m-d H:i:s', strtotime($start_date)))));
                 $event_end = date('Ymd\\THis\\Z', strtotime(get_gmt_from_date(date('Y-m-d H:i:s', strtotime($end_date)))));
             }
             // get categories, if available
             if ($categories = wp_get_post_terms($event->ID, 'event-category', array('fields' => 'names'))) {
                 if (!empty($categories) && is_array($categories) && !is_wp_error($categories)) {
                     $categories_output = "CATEGORIES:" . $this->escape_string(implode(',', (array) $categories)) . "\r\n";
                 }
             }
             // get location, if available
             if ($location = em_get_locations_for($event->ID)) {
                 $location_output = "LOCATION:" . $location[0]->name . " ";
                 $location_meta = array();
                 if (!empty($location[0]->location_meta)) {
                     foreach ($location[0]->location_meta as $key => $value) {
                         if (in_array($key, array('address', 'city', 'state', 'zip', 'country')) && !empty($value)) {
                             $location_meta[] = $this->escape_string(esc_attr($value));
                         }
                     }
                     $location_output .= implode(', ', $location_meta);
                 }
                 $location_output .= "\r\n";
             }
             // get organizer, if available
             if ($organizer = em_get_organizers_for($event->ID)) {
                 $organizer_meta = array();
                 if (!empty($organizer[0]->organizer_meta)) {
                     $organizer_output = "ORGANIZER;";
                     // contact name
                     if (isset($organizer[0]->organizer_meta['contact_name']) && !empty($organizer[0]->organizer_meta['contact_name'])) {
                         $organizer_output .= "CN=" . $this->escape_string($organizer[0]->organizer_meta['contact_name']);
                         // email
                         if (isset($organizer[0]->organizer_meta['email']) && !empty($organizer[0]->organizer_meta['email'])) {
                             $organizer_output .= ":MAILTO:" . $this->escape_string(esc_url($organizer[0]->organizer_meta['email']));
                         } else {
                             $organizer_output .= ";";
                         }
                     }
                     $organizer_output .= "\r\n";
                 }
             }
             // single event output
             $output .= "BEGIN:VEVENT\r\n";
             $output .= "DTEND:" . $event_end . "\r\n";
             $output .= "UID:" . uniqid() . "\r\n";
             $output .= "DTSTAMP:" . date('Ymd\\THis\\Z', time()) . "\r\n";
             $output .= !empty($categories_output) ? $categories_output : '';
             $output .= !empty($location_output) ? $location_output : '';
             $output .= !empty($organizer_output) ? $organizer_output : '';
             $output .= "DESCRIPTION:" . $this->escape_string(str_replace(array("\r", "\n"), " ", wp_strip_all_tags($event->post_content))) . "\r\n";
             $output .= "URL;VALUE=URI:" . $this->escape_string(esc_url(get_permalink($event->ID))) . "\r\n";
             $output .= "SUMMARY:" . $this->escape_string(esc_attr($event->post_title)) . "\r\n";
             $output .= "DTSTART:" . $event_start . "\r\n";
             // event recurrences data
             if (em_is_recurring($event->ID)) {
                 $recurrence_data = get_post_meta($event->ID, '_event_recurrence');
                 // fix for recurrence settings saved as array
                 if (is_array($recurrence_data)) {
                     $recurrence_data = $recurrence_data[0];
                 }
                 // recurrence type
                 switch ($recurrence_data['type']) {
                     case 'daily':
                         $ocurrences = em_get_occurrences($event->ID);
                         $output .= "RRULE:FREQ=" . strtoupper($recurrence_data['type']) . ";INTERVAL=1;COUNT=" . count($ocurrences) . ";\r\n";
                         break;
                     case 'weekly':
                         $days = array('MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU');
                         foreach ($recurrence_data['weekly_days'] as $key => $day) {
                             $byday[$key] = $days[$day - 1];
                         }
                         $output .= "RRULE:FREQ=" . strtoupper($recurrence_data['type']) . ";INTERVAL=" . $recurrence_data['repeat'] . ";BYDAY=" . implode(',', $byday) . ";UNTIL=" . date('Ymd\\THis\\Z', strtotime($recurrence_data['until'])) . ";\r\n";
                         break;
                     case 'monthly':
                         if ((int) $recurrence_data['monthly_day_type'] == 2) {
                             $days = array('MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU');
                             $current_week = ceil((date('d', strtotime($event_date['start'])) - date('w', strtotime($event_date['start'])) - 1) / 7) + 1;
                             $monthly_output = 'BYDAY=' . $current_week . $days[date('N', strtotime($event_date['start']))] . ';';
                         } else {
                             $monthly_output = '';
                         }
                         $output .= "RRULE:FREQ=" . strtoupper($recurrence_data['type']) . ";INTERVAL=" . $recurrence_data['repeat'] . ";UNTIL=" . date('Ymd\\THis\\Z', strtotime($recurrence_data['until'])) . ";" . $monthly_output . "\r\n";
                         break;
                     case 'yearly':
                         $output .= "RRULE:FREQ=" . strtoupper($recurrence_data['type']) . ";INTERVAL=" . $recurrence_data['repeat'] . ";UNTIL=" . date('Ymd\\THis\\Z', strtotime($recurrence_data['until'])) . ";\r\n";
                         break;
                     case 'custom':
                         $ocurrences = em_get_occurrences($event->ID);
                         if (!empty($ocurrences)) {
                             foreach ($ocurrences as $id => $occurence) {
                                 if (!empty($recurrence_data['separate_end_date'][(int) $id - 1])) {
                                     /* @TODO: separate_end_date not accepting end date parameter
                                     										  $seconds = strtotime($occurence['start']) - strtotime($occurence['end']);
                                     										  $days    = floor($seconds / 86400);
                                     										  $hours   = floor(($seconds - ($days * 86400)) / 3600);
                                     										  $minutes = floor(($seconds - ($days * 86400) - ($hours * 3600))/60);
                                     
                                     										  $output .= "RDATE;VALUE=PERIOD:".date('Ymd\THis\Z', strtotime($occurence['start']))."/".date('Ymd\THis\Z', strtotime($occurence['end'])).",".date('Ymd\THis\Z', strtotime($occurence['start']))."/PT".(!empty($days) && (int)$days > 0 ? $days."D" : '').(!empty($hours) ? $hours."H" : '').(!empty($minutes) ? $minutes."M" : '').";\r\n";
                                     										 */
                                     $output .= "RDATE:" . date('Ymd\\THis\\Z', strtotime($occurence['start'])) . ";\r\n";
                                 } else {
                                     $output .= "RDATE:" . date('Ymd\\THis\\Z', strtotime($occurence['start'])) . ";\r\n";
                                 }
                             }
                         }
                         break;
                 }
             }
             // single event end
             $output .= "END:VEVENT\r\n";
         }
         // set the correct headers for this file
         header('Content-type: text/calendar; charset=utf-8');
         header('Content-Disposition: attachment; filename=' . apply_filters('em_icl_feed_filename', 'em-' . date('Ymd', time()) . '-' . $feedname, $query, $item) . '.ical');
         echo "BEGIN:VCALENDAR\r\n";
         echo "VERSION:2.0\r\n";
         echo "PRODID:-//DIGITAL FACTORY//EVENTS MAKER V" . get_option('events_maker_version') . "//EN\r\n";
         echo "CALSCALE:GREGORIAN\r\n";
         // all events data
         echo $output;
         echo "END:VCALENDAR\r\n";
     }
     exit;
 }
    function em_display_event_locations($post_id = 0)
    {
        $post_id = (int) (empty($post_id) ? get_the_ID() : $post_id);
        if (empty($post_id)) {
            return false;
        }
        $locations = em_get_locations_for($post_id);
        if (empty($locations) || is_wp_error($locations)) {
            return false;
        }
        ?>
		
		<?php 
        $output = get_the_term_list($post_id, 'event-location', __('<strong>Location: </strong>', 'events-maker'), ', ', '');
        ?>
		
		<div class="entry-meta">
			
			<span class="term-list event-location cat-links">

			<?php 
        if (is_single()) {
            ?>
				
				<?php 
            $event_display_options = get_post_meta($post_id, '_event_display_options', TRUE);
            // event display options
            ?>
				
				<?php 
            if (!empty($event_display_options) && $event_display_options['display_location_details'] === 1) {
                ?>
					
					<?php 
                $output = __('<strong>Location: </strong>', 'events-maker');
                foreach ($locations as $term) {
                    $output .= '<span class="single-location term-' . $term->term_id . '">';
                    $term_link = get_term_link($term->slug, 'event-location');
                    if (is_wp_error($term_link)) {
                        continue;
                    }
                    $output .= '<a href="' . $term_link . '" class="location">' . $term->name . '</a>';
                    // Location details
                    $location_details = $term->location_meta;
                    if ($location_details) {
                        $output .= ' ';
                        $output .= !empty($location_details['address']) ? $location_details['address'] . ' ' : '';
                        $output .= !empty($location_details['zip']) ? $location_details['zip'] . ' ' : '';
                        $output .= !empty($location_details['city']) ? $location_details['city'] . ' ' : '';
                        $output .= !empty($location_details['state']) ? $location_details['state'] . ' ' : '';
                        $output .= !empty($location_details['country']) ? $location_details['country'] . ' ' : '';
                        $output .= ' ';
                    }
                    $output .= '</span>';
                }
                ?>
					
				<?php 
            }
            // display location details
            ?>

			<?php 
        }
        // single
        ?>
			
			<?php 
        echo $output;
        ?>
		
			</span>
			
		</div>

    <?php 
    }
Пример #5
0
    function em_display_event_locations($post_id = 0)
    {
        $post_id = (int) (empty($post_id) ? get_the_ID() : $post_id);
        if (empty($post_id)) {
            return false;
        }
        $locations = em_get_locations_for($post_id);
        if (empty($locations) || is_wp_error($locations)) {
            return false;
        }
        ?>

		<?php 
        $output = get_the_term_list($post_id, 'event-location', __('<strong>Location: </strong>', 'events-maker'), ', ', '');
        ?>

		<div class="entry-meta">

			<span class="term-list event-location cat-links">

			<?php 
        if (is_single()) {
            ?>

				<?php 
            $event_display_options = get_post_meta($post_id, '_event_display_options', true);
            // event display options
            ?>

				<?php 
            if (isset($event_display_options['display_location_details']) && $event_display_options['display_location_details'] == true) {
                ?>

					<?php 
                $output = __('<strong>Location: </strong>', 'events-maker');
                foreach ($locations as $term) {
                    $output .= '<span class="single-location term-' . $term->term_id . '">';
                    $term_link = get_term_link($term->slug, 'event-location');
                    if (is_wp_error($term_link)) {
                        continue;
                    }
                    $output .= '<a href="' . $term_link . '" class="location">' . $term->name . '</a> ';
                    // Location details
                    $location_fields = em_get_event_location_fields();
                    $location_details = $term->location_meta;
                    if ($location_details) {
                        // backward compatibility
                        if (isset($location_details['latitude'])) {
                            unset($location_details['latitude']);
                        }
                        if (isset($location_details['longitude'])) {
                            unset($location_details['longitude']);
                        }
                        // filter data
                        foreach ($location_fields as $key => $field) {
                            if (!in_array($field['type'], array('text', 'url', 'email', 'select')) || empty($location_details[$key])) {
                                unset($location_details[$key]);
                            }
                        }
                    }
                    if ($location_details) {
                        $output .= '<span class="location-details">(' . implode(' ', $location_details) . ')</span>';
                    }
                    $output .= '</span>';
                }
                ?>

				<?php 
            }
            ?>

			<?php 
        }
        ?>

			<?php 
        echo $output;
        ?>

			</span>

		</div>

		<?php 
    }