Пример #1
0
 /**
  * AJAX handler for the Map view
  */
 function ajax_response()
 {
     $tribe_paged = !empty($_POST['tribe_paged']) ? $_POST['tribe_paged'] : 1;
     TribeEventsQuery::init();
     $defaults = array('post_type' => TribeEvents::POSTTYPE, 'posts_per_page' => tribe_get_option('postsPerPage', 10), 'paged' => $tribe_paged, 'post_status' => array('publish'), 'eventDisplay' => 'map');
     $view_state = 'map';
     /* if past view */
     if (!empty($_POST['tribe_event_display']) && $_POST['tribe_event_display'] == 'past') {
         $view_state = 'past';
         $defaults['eventDisplay'] = 'past';
     }
     if (isset($_POST['tribe_event_category'])) {
         $defaults[TribeEvents::TAXONOMY] = $_POST['tribe_event_category'];
     }
     $query = TribeEventsQuery::getEvents($defaults, true);
     $have_events = 0 < $query->found_posts;
     if ($have_events && TribeEventsGeoLoc::instance()->is_geoloc_query()) {
         $lat = isset($_POST['tribe-bar-geoloc-lat']) ? $_POST['tribe-bar-geoloc-lat'] : 0;
         $lng = isset($_POST['tribe-bar-geoloc-lng']) ? $_POST['tribe-bar-geoloc-lng'] : 0;
         TribeEventsGeoLoc::instance()->assign_distance_to_posts($query->posts, $lat, $lng);
     } elseif (!$have_events && isset($_POST['tribe-bar-geoloc'])) {
         TribeEvents::setNotice('event-search-no-results', sprintf(__('No results were found for events in or near <strong>"%s"</strong>.', 'tribe-events-calendar-pro'), esc_html($_POST['tribe-bar-geoloc'])));
     } elseif (!$have_events && isset($_POST['tribe_event_category'])) {
         TribeEvents::setNotice('events-not-found', sprintf(__('No matching events listed under %s. Please try viewing the full calendar for a complete list of events.', 'tribe-events-calendar'), esc_html($_POST['tribe_event_category'])));
     } elseif (!$have_events) {
         TribeEvents::setNotice('event-search-no-results', __('There were no results found.', 'tribe-events-calendar-pro'));
     }
     $response = array('html' => '', 'markers' => array(), 'success' => true, 'tribe_paged' => $tribe_paged, 'max_pages' => $query->max_num_pages, 'total_count' => $query->found_posts, 'view' => $view_state);
     // @TODO: clean this up / refactor the following conditional
     if ($have_events) {
         global $wp_query, $post;
         $data = $query->posts;
         $post = $query->posts[0];
         $wp_query = $query;
         TribeEvents::instance()->displaying = 'map';
         ob_start();
         tribe_get_view('pro/map/content');
         $response['html'] .= ob_get_clean();
         $response['markers'] = TribeEventsGeoLoc::instance()->generate_markers($data);
     } else {
         global $wp_query;
         $wp_query = $query;
         TribeEvents::instance()->setDisplay();
         ob_start();
         tribe_get_view('pro/map/content');
         $response['html'] .= ob_get_clean();
     }
     $response = apply_filters('tribe_events_ajax_response', $response);
     header('Content-type: application/json');
     echo json_encode($response);
     exit;
 }
 /**
  * The asset loading function.
  *
  * @param string $name The name of the package reqested.
  * @param array $deps An array of dependencies (this should be the registered name that is registered to the wp_enqueue functions).
  * @return void
  * @author Timothy Wood
  * @since 3.0
  */
 public static function asset_package($name, $deps = array())
 {
     $tec_pro = TribeEventsPro::instance();
     $prefix = 'tribe-events-pro';
     // setup plugin resources & 3rd party vendor urls
     $resources_url = trailingslashit($tec_pro->pluginUrl) . 'resources/';
     $vendor_url = trailingslashit($tec_pro->pluginUrl) . 'vendor/';
     switch ($name) {
         case 'ajax-weekview':
             $ajax_data = array("ajaxurl" => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'post_type' => TribeEvents::POSTTYPE);
             $path1 = Tribe_Template_Factory::getMinFile($vendor_url . 'jquery-slimscroll/jquery.slimscroll.js', true);
             $path2 = Tribe_Template_Factory::getMinFile($resources_url . 'tribe-events-week.js', true);
             wp_enqueue_script('tribe-events-pro-slimscroll', $path1, array('tribe-events-pro', 'jquery-ui-draggable'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_enqueue_script('tribe-events-pro-week', $path2, array('tribe-events-pro-slimscroll'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_localize_script('tribe-events-pro-week', 'TribeWeek', $ajax_data);
             break;
         case 'ajax-photoview':
             $tribe_paged = !empty($_REQUEST['tribe_paged']) ? $_REQUEST['tribe_paged'] : 0;
             $ajax_data = array("ajaxurl" => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'tribe_paged' => $tribe_paged);
             $path1 = Tribe_Template_Factory::getMinFile($vendor_url . 'isotope/jquery.isotope.js', true);
             $path2 = Tribe_Template_Factory::getMinFile($resources_url . 'tribe-events-photo-view.js', true);
             wp_enqueue_script('tribe-events-pro-isotope', $path1, array('tribe-events-pro'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_enqueue_script('tribe-events-pro-photo', $path2, array('tribe-events-pro-isotope'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_localize_script('tribe-events-pro-photo', 'TribePhoto', $ajax_data);
             break;
         case 'ajax-dayview':
             $ajax_data = array("ajaxurl" => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'post_type' => TribeEvents::POSTTYPE);
             $path = Tribe_Template_Factory::getMinFile($resources_url . 'tribe-events-ajax-day.js', true);
             wp_enqueue_script('tribe-events-pro-ajax-day', $path, array('tribe-events-pro'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_localize_script('tribe-events-pro-ajax-day', 'TribeCalendar', $ajax_data);
             break;
         case 'ajax-maps':
             $http = is_ssl() ? 'https' : 'http';
             wp_register_script('gmaps', $http . '://maps.google.com/maps/api/js?sensor=false', array('tribe-events-pro'));
             $path = Tribe_Template_Factory::getMinFile($resources_url . 'tribe-events-ajax-maps.js', true);
             wp_register_script('tribe-events-pro-geoloc', $path, array('gmaps', parent::get_placeholder_handle()), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION));
             wp_enqueue_script('tribe-events-pro-geoloc');
             $geoloc = TribeEventsGeoLoc::instance();
             $data = array('ajaxurl' => admin_url('admin-ajax.php', $http), 'nonce' => wp_create_nonce('tribe_geosearch'), 'map_view' => TribeEvents::instance()->displaying == 'map' ? true : false);
             wp_localize_script('tribe-events-pro-geoloc', 'GeoLoc', $data);
             break;
     }
     parent::asset_package($name, $deps);
 }
 /**
  * filter TribeEvents::getLink for pro views
  * @param  string $eventUrl
  * @param  string $type
  * @param  string $secondary
  * @param  string $term
  * @return string
  * @author tim@imaginesimplicity.com
  * @since 3.0.2
  */
 public function get_link($eventUrl, $type, $secondary, $term)
 {
     switch ($type) {
         case 'week':
             $eventUrl = trailingslashit(esc_url($eventUrl . $this->weekSlug));
             if (!empty($secondary)) {
                 $eventUrl = esc_url(trailingslashit($eventUrl) . $secondary);
             }
             break;
         case 'photo':
             $eventUrl = trailingslashit(esc_url($eventUrl . $this->photoSlug));
             if (!empty($secondary)) {
                 $eventUrl = esc_url(trailingslashit($eventUrl) . $secondary);
             }
             break;
         case 'map':
             $eventUrl = trailingslashit(esc_url($eventUrl . TribeEventsGeoLoc::instance()->rewrite_slug));
             if (!empty($secondary)) {
                 $eventUrl = esc_url(trailingslashit($eventUrl) . $secondary);
             }
             break;
         default:
             break;
     }
     return apply_filters('tribe_events_pro_get_link', $eventUrl, $type, $secondary, $term);
 }
 /**
  * filter TribeEvents::getLink for pro views
  * @param  string $eventUrl
  * @param  string $type
  * @param  string $secondary
  * @param  string $term
  * @return string
  * @author tim@imaginesimplicity.com
  * @since 3.0.2
  */
 public function get_link($eventUrl, $type, $secondary, $term)
 {
     switch ($type) {
         case 'week':
             $eventUrl = trailingslashit(esc_url_raw($eventUrl . $this->weekSlug));
             if (!empty($secondary)) {
                 $eventUrl = esc_url_raw(trailingslashit($eventUrl) . $secondary);
             }
             break;
         case 'photo':
             $eventUrl = trailingslashit(esc_url_raw($eventUrl . $this->photoSlug));
             if (!empty($secondary)) {
                 $eventUrl = esc_url_raw(trailingslashit($eventUrl) . $secondary);
             }
             break;
         case 'map':
             $eventUrl = trailingslashit(esc_url_raw($eventUrl . TribeEventsGeoLoc::instance()->rewrite_slug));
             if (!empty($secondary)) {
                 $eventUrl = esc_url_raw(trailingslashit($eventUrl) . $secondary);
             }
             break;
         case 'all':
             remove_filter('post_type_link', array($this->permalink_editor, 'filter_recurring_event_permalinks'), 10, 4);
             $post_id = $secondary ? $secondary : get_the_ID();
             $post_id = wp_get_post_parent_id($post_id);
             $eventUrl = trailingslashit(get_permalink($post_id));
             $eventUrl = trailingslashit(esc_url_raw($eventUrl . 'all'));
             add_filter('post_type_link', array($this->permalink_editor, 'filter_recurring_event_permalinks'), 10, 4);
             break;
         default:
             break;
     }
     return apply_filters('tribe_events_pro_get_link', $eventUrl, $type, $secondary, $term);
 }
 /**
  * Static Singleton Factory Method
  * @return TribeEventsGeoLoc
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         $className = __CLASS__;
         self::$instance = new $className();
     }
     return self::$instance;
 }
 /**
  * The asset loading function.
  *
  * @param string $name The name of the package reqested.
  * @param array  $deps An array of dependencies (this should be the registered name that is registered to the wp_enqueue functions).
  *
  * @return void
  */
 public static function asset_package($name, $deps = array())
 {
     $tec_pro = TribeEventsPro::instance();
     $prefix = 'tribe-events-pro';
     // setup plugin resources & 3rd party vendor urls
     $resources_url = trailingslashit($tec_pro->pluginUrl) . 'resources/';
     $vendor_url = trailingslashit($tec_pro->pluginUrl) . 'vendor/';
     switch ($name) {
         case 'ajax-weekview':
             $ajax_data = array("ajaxurl" => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'post_type' => TribeEvents::POSTTYPE);
             $path1 = Tribe_Template_Factory::getMinFile($vendor_url . 'jquery-slimscroll/jquery.slimscroll.js', true);
             $path2 = Tribe_Template_Factory::getMinFile($resources_url . 'tribe-events-week.js', true);
             wp_enqueue_script('tribe-events-pro-slimscroll', $path1, array('tribe-events-pro', 'jquery-ui-draggable'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_enqueue_script('tribe-events-pro-week', $path2, array('tribe-events-pro-slimscroll'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_localize_script('tribe-events-pro-week', 'TribeWeek', $ajax_data);
             break;
         case 'ajax-photoview':
             $tribe_paged = !empty($_REQUEST['tribe_paged']) ? $_REQUEST['tribe_paged'] : 0;
             $ajax_data = array("ajaxurl" => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'tribe_paged' => $tribe_paged);
             $path1 = Tribe_Template_Factory::getMinFile($vendor_url . 'isotope/jquery.isotope.js', true);
             $path2 = Tribe_Template_Factory::getMinFile($resources_url . 'tribe-events-photo-view.js', true);
             wp_enqueue_script('tribe-events-pro-isotope', $path1, array('tribe-events-pro'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_enqueue_script('tribe-events-pro-photo', $path2, array('tribe-events-pro-isotope'), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION), true);
             wp_localize_script('tribe-events-pro-photo', 'TribePhoto', $ajax_data);
             break;
         case 'ajax-maps':
             $http = is_ssl() ? 'https' : 'http';
             $url = apply_filters('tribe_events_pro_google_maps_api', $http . '://maps.google.com/maps/api/js?sensor=false');
             wp_register_script('tribe-gmaps', $url, array('tribe-events-pro'));
             $path = Tribe_Template_Factory::getMinFile($resources_url . 'tribe-events-ajax-maps.js', true);
             wp_register_script('tribe-events-pro-geoloc', $path, array('tribe-gmaps', parent::get_placeholder_handle()), apply_filters('tribe_events_pro_js_version', TribeEventsPro::VERSION));
             wp_enqueue_script('tribe-events-pro-geoloc');
             $geoloc = TribeEventsGeoLoc::instance();
             $data = array('ajaxurl' => admin_url('admin-ajax.php', $http), 'nonce' => wp_create_nonce('tribe_geosearch'), 'map_view' => TribeEvents::instance()->displaying == 'map' ? true : false);
             wp_localize_script('tribe-events-pro-geoloc', 'GeoLoc', $data);
             break;
         case 'events-pro-css':
             $stylesheets = array();
             $mobile_break = tribe_get_mobile_breakpoint();
             // Get the selected style option
             $style_option = tribe_get_option('stylesheetOption', 'tribe');
             // Determine the stylesheet files for the selected option
             switch ($style_option) {
                 case 'skeleton':
                     $stylesheets['tribe-events-calendar-pro-style'] = 'tribe-events-pro-skeleton.css';
                     break;
                 case 'full':
                     $stylesheets['tribe-events-calendar-pro-style'] = 'tribe-events-pro-full.css';
                     if ($mobile_break > 0) {
                         $stylesheets['tribe-events-calendar-pro-mobile-style'] = 'tribe-events-pro-full-mobile.css';
                     }
                     break;
                 default:
                     // tribe styles
                     $stylesheets['tribe-events-full-pro-calendar-style'] = 'tribe-events-pro-full.css';
                     $stylesheets['tribe-events-calendar-pro-style'] = 'tribe-events-pro-theme.css';
                     if ($mobile_break > 0) {
                         $stylesheets['tribe-events-calendar-full-pro-mobile-style'] = 'tribe-events-pro-full-mobile.css';
                         $stylesheets['tribe-events-calendar-pro-mobile-style'] = 'tribe-events-pro-theme-mobile.css';
                     }
                     break;
             }
             // put override css at the end of the array
             $stylesheets['tribe-events-calendar-pro-override-style'] = 'tribe-events/pro/tribe-events-pro.css';
             // do the enqueues
             foreach ($stylesheets as $name => $css_file) {
                 if ($name == 'tribe-events-calendar-pro-override-style') {
                     $user_stylesheet_url = TribeEventsTemplates::locate_stylesheet($css_file);
                     if ($user_stylesheet_url) {
                         wp_enqueue_style($name, $user_stylesheet_url);
                     }
                 } else {
                     // get full URL
                     $url = tribe_events_pro_resource_url($css_file);
                     // get the minified file
                     $url = self::getMinFile($url, true);
                     // apply filters
                     $url = apply_filters('tribe_events_pro_stylesheet_url', $url, $name);
                     // set the $media attribute
                     if ($name == 'tribe-events-calendar-pro-mobile-style' || $name == 'tribe-events-calendar-full-pro-mobile-style') {
                         $media = "only screen and (max-width: {$mobile_break}px)";
                         wp_enqueue_style($name, $url, array('tribe-events-calendar-pro-style'), TribeEventsPro::VERSION, $media);
                     } else {
                         wp_register_style($name, $url, array(), TribeEventsPro::VERSION);
                         wp_enqueue_style($name);
                     }
                 }
             }
             break;
     }
     parent::asset_package($name, $deps);
 }
 /**
  * Generates the iCal file
  *
  * @static
  *
  * @param int|null $post If you want the ical file for a single event
  */
 public static function generate_ical_feed($post = null)
 {
     $tec = TribeEvents::instance();
     $wp_timezone = get_option('timezone_string');
     $events = '';
     $blogHome = get_bloginfo('url');
     $blogName = get_bloginfo('name');
     if ($post) {
         $events_posts = array();
         $events_posts[] = $post;
     } else {
         if (tribe_is_month()) {
             $events_posts = self::get_month_view_events();
         } else {
             global $wp_query;
             $events_posts = $wp_query->posts;
         }
     }
     foreach ($events_posts as $event_post) {
         $startDate = $event_post->EventStartDate;
         $endDate = $event_post->EventEndDate;
         // convert 2010-04-08 00:00:00 to 20100408T000000 or YYYYMMDDTHHMMSS
         $startDate = str_replace(array('-', ' ', ':'), array('', 'T', ''), $startDate);
         $endDate = str_replace(array('-', ' ', ':'), array('', 'T', ''), $endDate);
         if (get_post_meta($event_post->ID, '_EventAllDay', true) == 'yes') {
             $startDate = substr($startDate, 0, 8);
             $endDate = substr($endDate, 0, 8);
             // endDate bumped ahead one day to counter iCal's off-by-one error
             $endDateStamp = strtotime($endDate);
             $endDate = date('Ymd', $endDateStamp + 86400);
             $type = 'DATE';
         } else {
             $type = 'DATE-TIME';
         }
         $description = preg_replace("/[\n\t\r]/", ' ', strip_tags($event_post->post_content));
         // add fields to iCal output
         $item = array();
         $item[] = "DTSTART;VALUE={$type}:" . $startDate;
         $item[] = "DTEND;VALUE={$type}:" . $endDate;
         $item[] = 'DTSTAMP:' . date('Ymd\\THis', time());
         $item[] = 'CREATED:' . str_replace(array('-', ' ', ':'), array('', 'T', ''), $event_post->post_date);
         $item[] = 'LAST-MODIFIED:' . str_replace(array('-', ' ', ':'), array('', 'T', ''), $event_post->post_modified);
         $item[] = 'UID:' . $event_post->ID . '-' . strtotime($startDate) . '-' . strtotime($endDate) . '@' . $blogHome;
         $item[] = 'SUMMARY:' . $event_post->post_title;
         $item[] = 'DESCRIPTION:' . str_replace(',', '\\,', $description);
         $item[] = 'URL:' . get_permalink($event_post->ID);
         // add location if available
         $location = $tec->fullAddressString($event_post->ID);
         if (!empty($location)) {
             $item[] = 'LOCATION:' . html_entity_decode($location, ENT_QUOTES);
         }
         // add geo coordinates if available
         if (class_exists('TribeEventsGeoLoc')) {
             $long = TribeEventsGeoLoc::instance()->get_lng_for_event($event_post->ID);
             $lat = TribeEventsGeoLoc::instance()->get_lat_for_event($event_post->ID);
             if (!empty($long) && !empty($lat)) {
                 $item[] = sprintf('GEO:%s;%s', $long, $lat);
             }
         }
         // add categories if available
         $event_cats = (array) wp_get_object_terms($event_post->ID, TribeEvents::TAXONOMY, array('fields' => 'names'));
         if (!empty($event_cats)) {
             $item[] = 'CATEGORIES:' . html_entity_decode(join(',', $event_cats), ENT_QUOTES);
         }
         // add featured image if available
         if (has_post_thumbnail($event_post->ID)) {
             $thumbnail_id = get_post_thumbnail_id($event_post->ID);
             $thumbnail_url = wp_get_attachment_url($thumbnail_id);
             $thumbnail_mime_type = get_post_mime_type($thumbnail_id);
             $item[] = apply_filters('tribe_ical_feed_item_thumbnail', sprintf('ATTACH;FMTTYPE=%s:%s', $thumbnail_mime_type, $thumbnail_url), $event_post->ID);
         }
         // add organizer if available
         $organizer_email = tribe_get_organizer_email($event_post->ID);
         if ($organizer_email) {
             $organizer_name = tribe_get_organizer($event_post->ID);
             if ($organizer_name) {
                 $item[] = sprintf('ORGANIZER;CN=%s:MAILTO:%s', $organizer_name, $organizer_email);
             } else {
                 $item[] = sprintf('ORGANIZER:MAILTO:%s', $organizer_email);
             }
         }
         $item = apply_filters('tribe_ical_feed_item', $item, $event_post);
         $events .= "BEGIN:VEVENT\r\n" . implode("\r\n", $item) . "\r\nEND:VEVENT\r\n";
     }
     header('Content-type: text/calendar; charset=UTF-8');
     header('Content-Disposition: attachment; filename="iCal-TribeEvents.ics"');
     $content = "BEGIN:VCALENDAR\r\n";
     $content .= "VERSION:2.0\r\n";
     $content .= 'PRODID:-//' . $blogName . ' - ECPv' . TribeEvents::VERSION . "//NONSGML v1.0//EN\r\n";
     $content .= "CALSCALE:GREGORIAN\r\n";
     $content .= "METHOD:PUBLISH\r\n";
     $content .= 'X-WR-CALNAME:' . apply_filters('tribe_ical_feed_calname', $blogName) . "\r\n";
     $content .= 'X-ORIGINAL-URL:' . $blogHome . "\r\n";
     $content .= 'X-WR-CALDESC:Events for ' . $blogName . "\r\n";
     if ($wp_timezone) {
         $content .= 'X-WR-TIMEZONE:' . $wp_timezone . "\r\n";
     }
     $content = apply_filters('tribe_ical_properties', $content);
     $content .= $events;
     $content .= 'END:VCALENDAR';
     echo $content;
     exit;
 }