Пример #1
0
function _backend_load_event_of_date()
{
    if (isset($_POST['event_date']) && $_POST['event_date']) {
        TribeEventsQuery::init();
        $states[] = 'publish';
        if (0 < get_current_user_id()) {
            $states[] = 'private';
        }
        $args = array('post_status' => $states, 'eventDate' => $_POST["event_date"], 'eventDisplay' => 'day');
        TribeEvents::instance()->displaying = 'day';
        $query = TribeEventsQuery::getEvents($args, true);
        global $wp_query, $post;
        $wp_query = $query;
        add_filter('tribe_is_day', '__return_true');
        $html = '';
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                $html .= '<option value="' . get_the_ID() . '"> ' . get_the_title() . '</option>';
            }
            wp_reset_postdata();
        }
        $response = array('html' => $html, 'success' => true, 'total_count' => $query->found_posts, 'view' => 'day');
        header('Content-type: application/json');
        echo json_encode($response);
        die;
    }
}
Пример #2
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;
 }
Пример #3
0
 /**
  * List view ajax handler
  *
  * @return void
  */
 function ajax_response()
 {
     TribeEventsQuery::init();
     $tribe_paged = !empty($_POST['tribe_paged']) ? intval($_POST['tribe_paged']) : 1;
     $args = array('eventDisplay' => 'list', 'post_type' => TribeEvents::POSTTYPE, 'post_status' => 'publish', 'paged' => $tribe_paged);
     // check & set past display
     if (isset($_POST['tribe_event_display']) && $_POST['tribe_event_display'] == 'past') {
         $args['eventDisplay'] = 'past';
     }
     // check & set event category
     if (isset($_POST['tribe_event_category'])) {
         $args[TribeEvents::TAXONOMY] = $_POST['tribe_event_category'];
     }
     $query = tribe_get_events($args, true);
     // $hash is used to detect whether the primary arguments in the query have changed (i.e. due to a filter bar request)
     // if they have, we want to go back to page 1
     $hash = $query->query_vars;
     $hash['paged'] = null;
     $hash['start_date'] = null;
     $hash['end_date'] = null;
     $hash_str = md5(maybe_serialize($hash));
     if (!empty($_POST['hash']) && $hash_str !== $_POST['hash']) {
         $tribe_paged = 1;
         $args['paged'] = 1;
         $query = TribeEventsQuery::getEvents($args, true);
     }
     $response = array('html' => '', 'success' => true, 'max_pages' => $query->max_num_pages, 'hash' => $hash_str, 'tribe_paged' => $tribe_paged, 'total_count' => $query->found_posts, 'view' => 'list');
     global $wp_query, $post, $paged;
     $wp_query = $query;
     if (!empty($query->posts)) {
         $post = $query->posts[0];
     }
     $paged = $tribe_paged;
     TribeEvents::instance()->displaying = 'list';
     if (!empty($_POST['tribe_event_display']) && $_POST['tribe_event_display'] == 'past') {
         $response['view'] = 'past';
     }
     ob_start();
     tribe_get_view('list/content');
     $response['html'] .= ob_get_clean();
     apply_filters('tribe_events_ajax_response', $response);
     header('Content-type: application/json');
     echo json_encode($response);
     die;
 }
Пример #4
0
 /**
  * AJAX handler for Photo view
  *
  * @return void
  */
 function ajax_response()
 {
     $tec = TribeEvents::instance();
     TribeEventsQuery::init();
     $tribe_paged = !empty($_POST['tribe_paged']) ? intval($_POST['tribe_paged']) : 1;
     $args = array('eventDisplay' => 'list', 'post_type' => TribeEvents::POSTTYPE, 'post_status' => 'publish', 'paged' => $tribe_paged);
     $view_state = 'photo';
     if (isset($_POST['tribe_event_category'])) {
         $args[TribeEvents::TAXONOMY] = $_POST['tribe_event_category'];
     }
     /* if past view */
     if (!empty($_POST['tribe_event_display']) && $_POST['tribe_event_display'] == 'past') {
         $view_state = 'past';
         $args['eventDisplay'] = 'past';
     }
     $query = TribeEventsQuery::getEvents($args, true);
     $hash = $query->query_vars;
     $hash['paged'] = null;
     $hash['start_date'] = null;
     $hash_str = md5(maybe_serialize($hash));
     if (!empty($_POST['hash']) && $hash_str !== $_POST['hash']) {
         $tribe_paged = 1;
         $args['paged'] = 1;
         $query = TribeEventsQuery::getEvents($args, true);
     }
     $response = array('html' => '', 'success' => true, 'max_pages' => $query->max_num_pages, 'hash' => $hash_str, 'tribe_paged' => $tribe_paged, 'view' => $view_state);
     global $wp_query, $post;
     $wp_query = $query;
     if (!empty($query->posts)) {
         $post = $query->posts[0];
     }
     add_filter('tribe_events_list_pagination', array('TribeEvents', 'clear_module_pagination'), 10);
     $tec->displaying = 'photo';
     ob_start();
     tribe_get_view('pro/photo/content');
     $response['html'] .= ob_get_clean();
     apply_filters('tribe_events_ajax_response', $response);
     header('Content-type: application/json');
     echo json_encode($response);
     die;
 }
Пример #5
0
 /**
  * AJAX handler for tribe_event_day (dayview navigation)
  * This loads up the day view shard with all the appropriate events for the day
  *
  * @return void
  */
 function ajax_response()
 {
     if (isset($_POST['eventDate']) && $_POST['eventDate']) {
         TribeEventsQuery::init();
         $states[] = 'publish';
         if (0 < get_current_user_id()) {
             $states[] = 'private';
         }
         $args = array('post_status' => $states, 'eventDate' => $_POST["eventDate"], 'eventDisplay' => 'day');
         TribeEvents::instance()->displaying = 'day';
         if (isset($_POST['tribe_event_category'])) {
             $args[TribeEvents::TAXONOMY] = $_POST['tribe_event_category'];
         }
         $query = TribeEventsQuery::getEvents($args, true);
         global $wp_query, $post;
         $wp_query = $query;
         add_filter('tribe_is_day', '__return_true');
         // simplest way to declare that this is a day view
         ob_start();
         tribe_get_view('day/content');
         $response = array('html' => ob_get_clean(), 'success' => true, 'total_count' => $query->found_posts, 'view' => 'day');
         apply_filters('tribe_events_ajax_response', $response);
         header('Content-type: application/json');
         echo json_encode($response);
         die;
     }
 }
Пример #6
0
 /**
  * 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');
     $event_display = !empty($_REQUEST['tribe_display']) ? $_REQUEST['tribe_display'] : 'upcoming';
     if ($event_display == 'list') {
         $event_display = 'upcoming';
     }
     if ($post) {
         $events_posts = array();
         $events_posts[] = $post;
     } else {
         TribeEventsQuery::init();
         $events_query = TribeEventsQuery::getEvents(array('posts_per_page' => -1, 'eventDisplay' => $event_display), true);
         $events_posts = $events_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[] = 'LOCATION:' . html_entity_decode($tec->fullAddressString($event_post->ID), ENT_QUOTES);
         $item[] = 'URL:' . get_permalink($event_post->ID);
         $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;
 }
 public function setup_list($template_file)
 {
     if (basename(dirname($template_file)) . '/' . basename($template_file) == 'mini-calendar/list.php') {
         if ($this->args['count'] == 0) {
             return;
         }
         // make sure the widget taxonomy filter setting is respected
         add_action('pre_get_posts', array($this, 'set_count'), 1000);
         global $wp_query;
         // hijack the main query to load the events via provided $args
         if (!is_null($this->args)) {
             $query_args = array('posts_per_page' => $this->args['count'], 'tax_query' => $this->args['tax_query'], 'eventDisplay' => 'custom', 'start_date' => $this->get_month(), 'post_status' => array('publish'), 'is_tribe_mini_calendar' => true, 'tribeHideRecurrence' => false);
             // set end date if initial load, or ajax month switch
             if (!defined('DOING_AJAX') || defined('DOING_AJAX') && $_POST['action'] == 'tribe-mini-cal') {
                 $query_args['end_date'] = substr_replace($this->get_month(TribeDateUtils::DBDATEFORMAT), TribeDateUtils::getLastDayOfMonth(strtotime($this->get_month())), -2);
                 // @todo use tribe_events_end_of_day() ?
                 $query_args['end_date'] = TribeDateUtils::endOfDay($query_args['end_date']);
             }
             $wp_query = TribeEventsQuery::getEvents($query_args, true);
         }
     }
 }
 /**
  * AJAX handler for tribe_event_day (dayview navigation)
  * This loads up the day view shard with all the appropriate events for the day
  *
  * @return void
  * @author Timothy Wood
  * @since 3.0
  */
 function wp_ajax_tribe_event_day()
 {
     if (isset($_POST["eventDate"]) && $_POST["eventDate"]) {
         if (class_exists('TribeEventsFilterView')) {
             TribeEventsFilterView::instance()->createFilters(null, true);
         }
         TribeEventsQuery::init();
         add_filter('tribe_events_pre_get_posts', array($this, 'pre_get_posts'));
         $args = array('post_status' => array('publish', 'private', 'future'), 'eventDate' => $_POST["eventDate"], 'eventDisplay' => 'day');
         if (isset($_POST['tribe_event_category'])) {
             $args[TribeEvents::TAXONOMY] = $_POST['tribe_event_category'];
         }
         $query = TribeEventsQuery::getEvents($args, true);
         global $wp_query, $post;
         $wp_query = $query;
         if (have_posts()) {
             the_post();
             // TODO: why is this here?
             rewind_posts();
             // so we don't skip the first post when rendering
         }
         add_filter('tribe_is_day', '__return_true');
         // simplest way to declare that this is a day view
         TribeEventsTemplates::getTemplateHierarchy('day', '', 'pro', $this->pluginPath);
         ob_start();
         tribe_get_view('day/content');
         $response = array('html' => ob_get_clean(), 'success' => true, 'total_count' => $query->found_posts, 'view' => 'day');
         apply_filters('tribe_events_ajax_response', $response);
         header('Content-type: application/json');
         echo json_encode($response);
         die;
     }
 }
 public function getEvents($args = '')
 {
     $tribe_ecp = TribeEvents::instance();
     $defaults = array('posts_per_page' => tribe_get_option('postsPerPage', 10), 'post_type' => TribeEvents::POSTTYPE, 'orderby' => 'event_date', 'order' => 'ASC');
     $args = wp_parse_args($args, $defaults);
     return TribeEventsQuery::getEvents($args);
 }
Пример #10
0
 /**
  * The List View AJAX handler.
  *
  * @return void
  * @since 3.0
  */
 function list_ajax_call()
 {
     TribeEventsQuery::init();
     $tribe_paged = !empty($_POST['tribe_paged']) ? intval($_POST['tribe_paged']) : 1;
     $args = array('eventDisplay' => 'upcoming', 'post_type' => TribeEvents::POSTTYPE, 'post_status' => 'publish', 'paged' => $tribe_paged);
     // check & set past display
     if (isset($_POST['tribe_event_display']) && $_POST['tribe_event_display'] == 'past') {
         $args['eventDisplay'] = 'past';
     }
     // check & set event category
     if (isset($_POST['tribe_event_category'])) {
         $args[TribeEvents::TAXONOMY] = $_POST['tribe_event_category'];
     }
     $query = TribeEventsQuery::getEvents($args, true);
     $hash = $query->query_vars;
     $hash['paged'] = null;
     $hash['start_date'] = null;
     $hash_str = md5(maybe_serialize($hash));
     if (!empty($_POST['hash']) && $hash_str !== $_POST['hash']) {
         $tribe_paged = 1;
         $args['paged'] = 1;
         $query = TribeEventsQuery::getEvents($args, true);
     }
     $response = array('html' => '', 'success' => true, 'max_pages' => $query->max_num_pages, 'hash' => $hash_str, 'tribe_paged' => $tribe_paged, 'total_count' => $query->found_posts, 'view' => 'list');
     global $wp_query, $post, $paged;
     $wp_query = $query;
     if (!empty($query->posts)) {
         $post = $query->posts[0];
     }
     $paged = $tribe_paged;
     add_filter('tribe_events_list_pagination', array(__CLASS__, 'clear_module_pagination'), 10);
     if ($query->query_vars['eventDisplay'] == 'list') {
         $this->displaying = 'upcoming';
     } elseif ($query->query_vars['eventDisplay'] == 'past') {
         $this->displaying = 'past';
         $response['view'] = 'past';
     }
     $old_request = $_SERVER;
     if (tribe_is_past()) {
         $_SERVER['REQUEST_URI'] = $this->rewriteSlug . '/' . 'past/';
     } else {
         $_SERVER['REQUEST_URI'] = $this->rewriteSlug . '/' . 'upcoming/';
     }
     ob_start();
     tribe_get_view('list/content');
     $response['html'] .= ob_get_clean();
     $_SERVER = $old_request;
     apply_filters('tribe_events_ajax_response', $response);
     header('Content-type: application/json');
     echo json_encode($response);
     die;
 }
 function fetch_upcoming()
 {
     $query = array('paged' => false, 'posts_per_page' => 1, 'eventDisplay' => 'list');
     $upcoming = TribeEventsQuery::getEvents($query, true);
     return $upcoming;
 }
 /**
  * AJAX handler for the Map view
  */
 function ajax_tribe_geosearch()
 {
     if (class_exists('TribeEventsFilterView')) {
         TribeEventsFilterView::instance()->createFilters(null, true);
         $this->setup_geoloc_filter_in_filters();
     }
     $tribe_paged = !empty($_POST["tribe_paged"]) ? $_POST["tribe_paged"] : 1;
     TribeEventsQuery::init();
     $defaults = array('post_type' => TribeEvents::POSTTYPE, 'orderby' => 'event_date', 'order' => 'ASC', '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';
         add_filter('tribe_events_pre_get_posts', array($this, 'set_past_events_query'));
     }
     $query = TribeEventsQuery::getEvents($defaults, true);
     if ($this->is_geoloc_query() && $query->found_posts > 0) {
         $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;
         $this->order_posts_by_distance($query->posts, $lat, $lng);
     }
     $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);
     if ($query->found_posts > 0) {
         global $wp_query, $post;
         $data = $query->posts;
         $post = $query->posts[0];
         $wp_query = $query;
         TribeEvents::instance()->setDisplay();
         ob_start();
         tribe_get_view('map/content');
         $response['html'] .= ob_get_clean();
         $response['markers'] = $this->generate_markers($data);
     } else {
         global $wp_query;
         $wp_query = $query;
         TribeEvents::instance()->setDisplay();
         ob_start();
         tribe_get_view('map/content');
         $response['html'] .= ob_get_clean();
     }
     apply_filters('tribe_events_ajax_response', $response);
     header('Content-type: application/json');
     echo json_encode($response);
     exit;
 }
Пример #13
0
 /**
  * @param string $date
  * @return WP_Query
  */
 private function get_daily_events($date)
 {
     global $wp_query;
     $tribe_ecp = TribeEvents::instance();
     $post_status = is_user_logged_in() ? array('publish', 'private') : 'publish';
     $args = wp_parse_args(array('eventDate' => $date, 'start_date' => tribe_event_beginning_of_day($date), 'end_date' => tribe_event_end_of_day($date), 'post__not_in' => self::$hide_upcoming_ids, 'hide_upcoming' => false, 'posts_per_page' => self::$posts_per_page_limit, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_status' => $post_status, 'eventDisplay' => 'custom', 'no_found_rows' => true), self::$args);
     if (is_tax($tribe_ecp->get_event_taxonomy())) {
         $cat = get_term_by('slug', get_query_var('term'), $tribe_ecp->get_event_taxonomy());
         $args['eventCat'] = (int) $cat->term_id;
     }
     $cache = new TribeEventsCache();
     $cache_key = 'daily_events_' . serialize($args);
     $found = $cache->get($cache_key, 'save_post');
     if ($found && is_a($found, 'WP_Query')) {
         // return $found;
     }
     $result = TribeEventsQuery::getEvents($args, true);
     $cache->set($cache_key, $result, self::$cache_expiration, 'save_post');
     return $result;
 }
Пример #14
0
 /**
  * Template tag to get related posts for the current post.
  *
  * @since 1.1
  * @author Paul Hughes
  * @param int $count number of related posts to return.
  * @param int|obj $post the post to get related posts to, defaults to current global $post
  * @return array the related posts.
  */
 function tribe_get_related_posts($count = 3, $post = false)
 {
     $post_id = TribeEvents::postIdHelper($post);
     $tags = wp_get_post_tags($post_id, array('fields' => 'ids'));
     $categories = wp_get_object_terms($post_id, TribeEvents::TAXONOMY, array('fields' => 'ids'));
     if (!$tags && !$categories) {
         return;
     }
     $args = array('posts_per_page' => $count, 'post__not_in' => array($post_id), 'eventDisplay' => 'upcoming', 'tax_query' => array('relation' => 'OR'), 'orderby' => 'rand');
     if ($tags) {
         $args['tax_query'][] = array('taxonomy' => 'post_tag', 'field' => 'id', 'terms' => $tags);
     }
     if ($categories) {
         $args['tax_query'][] = array('taxonomy' => TribeEvents::TAXONOMY, 'field' => 'id', 'terms' => $categories);
     }
     $args = apply_filters('tribe_related_posts_args', $args);
     if ($args) {
         $posts = TribeEventsQuery::getEvents($args);
     } else {
         $posts = array();
     }
     return apply_filters('tribe_get_related_posts', $posts);
 }
 /**
  * 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');
     $event_display = !empty($_REQUEST['tribe_display']) ? $_REQUEST['tribe_display'] : 'upcoming';
     if ($event_display == 'list') {
         $event_display = 'upcoming';
     }
     if ($post) {
         $events_posts = array();
         $events_posts[] = $post;
     } else {
         TribeEventsQuery::init();
         $events_query = TribeEventsQuery::getEvents(array('posts_per_page' => -1, 'eventDisplay' => $event_display), true);
         $events_posts = $events_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;
 }
Пример #16
0
 /**
  * @param string $date
  * @return WP_Query
  */
 private function get_daily_events($date)
 {
     global $wp_query;
     $tribe_ecp = TribeEvents::instance();
     $post_status = is_user_logged_in() ? array('publish', 'private') : 'publish';
     $args = wp_parse_args(array('post__in' => self::$event_daily_ids[$date], 'post_type' => TribeEvents::POSTTYPE, 'start_date' => tribe_event_beginning_of_day($date), 'end_date' => tribe_event_end_of_day($date), 'eventDisplay' => 'custom', 'no_found_rows' => true, 'posts_per_page' => self::$posts_per_page_limit), self::$args);
     $result = TribeEventsQuery::getEvents($args, true);
     return $result;
 }
Пример #17
0
 * @version    $Id$
 * @package    wpbase
 * @author     WPOpal  Team <wpopal@gmail.com, support@wpopal.com>
 * @copyright  Copyright (C) 2015 wpopal.com. All Rights Reserved.
 * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * @website  http://www.wpopal.com
 * @support  http://www.wpopal.com/support/forum.html
 */
$atts = vc_map_get_attributes($this->getShortcode(), $atts);
extract($atts);
TribeEventsQuery::init();
$states[] = 'publish';
$args = array('post_status' => $states, 'eventDate' => $event_date, 'eventDisplay' => 'day', 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'tribe_events', 'post__in' => wp_parse_id_list($event_ids));
TribeEvents::instance()->displaying = 'day';
$query = TribeEventsQuery::getEvents($args, true);
$_id = training_wpo_makeid();
?>
<div class="widget wpo-event-of-date <?php 
echo esc_attr($el_class);
?>
">
   <?php 
if ($title) {
    ?>
      <h3 class="widget-title visual-title <?php 
    echo esc_attr($size) . ' ' . $alignment;
    ?>
">
      </h3>
   <?php 
Пример #18
0
 /**
  * Accepts an array of query arguments, retrieves them, and returns the html for those events in list view
  *
  * Optional inline example:
  * < code >
  * <?php
  * echo myfunction();
  * ?>
  * </ code >
  *
  * @param array $args       Args to be passed to TribeEventsQuery::getEvents()
  * @param bool  $initialize Whether the list view template class needs to be included and initialized
  *
  * @return string
  **/
 function tribe_include_view_list($args = null, $initialize = true)
 {
     global $wp_query;
     // hijack the main query to load the events via provided $args
     if (!is_null($args) || !($wp_query->tribe_is_event || $wp_query->tribe_is_event_category)) {
         $reset_q = $wp_query;
         $wp_query = TribeEventsQuery::getEvents($args, true);
     }
     // single-event notices are jumping in on this init when loading as a module
     TribeEvents::removeNotice('event-past');
     // get the list view template
     ob_start();
     if ($initialize) {
         tribe_initialize_view('Tribe_Events_List_Template');
     }
     tribe_get_view('list/content');
     $list_view_html = ob_get_clean();
     // fix the error of our ways
     if (!empty($reset_q)) {
         $wp_query = $reset_q;
     }
     // return the parsed template
     return $list_view_html;
 }