Esempio n. 1
0
 /**
  * Adds the timezone to the event schedule information.
  *
  * @param string   $schedule_text
  * @param int|null $event_id
  *
  * @return string
  */
 public static function append_timezone($schedule_text, $event_id = null)
 {
     static $hide_for_all_day;
     if (!isset($hide_for_all_day)) {
         $hide_for_all_day = apply_filters('tribe_events_hide_timezone_for_all_day_events', true);
     }
     if (tribe_event_is_all_day($event_id) && $hide_for_all_day) {
         return $schedule_text;
     }
     $timezone = Tribe__Events__Timezones::is_mode('site') ? self::wp_timezone_abbr(tribe_get_start_date($event_id, true, Tribe__Events__Date_Utils::DBDATETIMEFORMAT)) : self::get_event_timezone_abbr($event_id);
     if (!empty($timezone)) {
         $timezone_text = " <span class='timezone'> {$timezone} </span>";
         $schedule_text = $schedule_text . $timezone_text;
     }
     return $schedule_text;
 }
Esempio n. 2
0
 /**
  * @param bool $keep_original_index
  */
 private function sort_sequence($keep_original_index = true)
 {
     if ($this->has_sorted_sequence) {
         return;
     }
     // determine the parent event timezone to use for same day comparison between events
     $timezone = Tribe__Events__Timezones::get_event_timezone_string($this->parent_event_id);
     $this->timezone_string = Tribe__Events__Timezones::generate_timezone_string_from_utc_offset($timezone);
     //add the original key to entry array in the sequence
     if ($keep_original_index) {
         array_walk($this->sequence, array($this, 'set_original_index'));
     }
     // sort the dates to create by starting time
     usort($this->sequence, array($this, 'sort_by_start_date'));
     $this->has_sorted_sequence = true;
 }
Esempio n. 3
0
 /**
  * End Time
  *
  * Returns the event end time
  *
  * @category Events
  * @param int    $event       (optional)
  * @param string $dateFormat  Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  * @param string $timezone    Timezone in which to present the date/time (or default behaviour if not set)
  *
  * @return string|null Time
  */
 function tribe_get_end_time($event = null, $dateFormat = '', $timezone = null)
 {
     if (is_null($event)) {
         global $post;
         $event = $post;
     }
     if (is_numeric($event)) {
         $event = get_post($event);
     }
     if (!is_object($event)) {
         return;
     }
     if (tribe_event_is_all_day($event)) {
         return;
     }
     $end_date = Tribe__Events__Timezones::event_end_timestamp($event->ID, $timezone);
     if ('' == $dateFormat) {
         $dateFormat = tribe_get_time_format();
     }
     return tribe_format_date($end_date, false, $dateFormat);
 }
Esempio n. 4
0
 /**
  * Fetches the JSON-LD data for this type of object
  *
  * @param  int|WP_Post|null $post The post/event
  * @param  array  $args
  * @return array
  */
 public function get_data($posts = null, $args = array())
 {
     $posts = $posts instanceof WP_Post ? array($posts) : (array) $posts;
     $return = array();
     foreach ($posts as $i => $post) {
         $data = parent::get_data($post, $args);
         // If we have an Empty data we just skip
         if (empty($data)) {
             continue;
         }
         // Fetch first key
         $post_id = key($data);
         // Fetch first Value
         $data = reset($data);
         $event_tz_string = get_post_meta($post_id, '_EventTimezone', true);
         $tz_mode = tribe_get_option('tribe_events_timezone_mode', 'event');
         $tz_string = $event_tz_string && $tz_mode === 'event' ? $event_tz_string : Tribe__Events__Timezones::wp_timezone_string();
         $data->startDate = Tribe__Events__Timezones::to_utc(tribe_get_start_date($post_id, true, Tribe__Date_Utils::DBDATETIMEFORMAT), $tz_string, 'c');
         $data->endDate = Tribe__Events__Timezones::to_utc(tribe_get_end_date($post_id, true, Tribe__Date_Utils::DBDATETIMEFORMAT), $tz_string, 'c');
         if (tribe_has_venue($post_id)) {
             $venue_id = tribe_get_venue_id($post_id);
             $venue_data = Tribe__Events__JSON_LD__Venue::instance()->get_data($venue_id);
             $data->location = reset($venue_data);
         }
         if (tribe_has_organizer($post_id)) {
             $organizer_id = tribe_get_organizer_id($post_id);
             $organizer_data = Tribe__Events__JSON_LD__Organizer::instance()->get_data($organizer_id);
             $data->organizer = reset($organizer_data);
         }
         $price = tribe_get_cost($post_id);
         $price = $this->normalize_price($price);
         if ('' !== $price) {
             // Manually Include the Price for non Event Tickets
             $data->offers = (object) array('@type' => 'Offer', 'price' => $price, 'url' => $data->url);
         }
         $return[$post_id] = $data;
     }
     return $return;
 }
Esempio n. 5
0
 /**
  * Run on applied action init
  */
 public function init()
 {
     $this->pluginName = __('The Events Calendar', 'the-events-calendar');
     $this->rewriteSlug = $this->getRewriteSlug();
     $this->rewriteSlugSingular = $this->getRewriteSlugSingular();
     $this->taxRewriteSlug = $this->getTaxRewriteSlug();
     $this->tagRewriteSlug = $this->getTagRewriteSlug();
     $this->monthSlug = sanitize_title(__('month', 'the-events-calendar'));
     $this->listSlug = sanitize_title(__('list', 'the-events-calendar'));
     $this->upcomingSlug = sanitize_title(__('upcoming', 'the-events-calendar'));
     $this->pastSlug = sanitize_title(__('past', 'the-events-calendar'));
     $this->daySlug = sanitize_title(__('day', 'the-events-calendar'));
     $this->todaySlug = sanitize_title(__('today', 'the-events-calendar'));
     $this->singular_venue_label = $this->get_venue_label_singular();
     $this->plural_venue_label = $this->get_venue_label_plural();
     $this->singular_organizer_label = $this->get_organizer_label_singular();
     $this->plural_organizer_label = $this->get_organizer_label_plural();
     $this->singular_event_label = $this->get_event_label_singular();
     $this->plural_event_label = $this->get_event_label_plural();
     $this->postTypeArgs['rewrite']['slug'] = sanitize_title($this->rewriteSlugSingular);
     $this->postVenueTypeArgs['rewrite']['slug'] = sanitize_title($this->singular_venue_label);
     $this->postVenueTypeArgs['show_in_nav_menus'] = class_exists('Tribe__Events__Pro__Main') ? true : false;
     $this->postOrganizerTypeArgs['rewrite']['slug'] = sanitize_title($this->singular_organizer_label);
     $this->postOrganizerTypeArgs['show_in_nav_menus'] = class_exists('Tribe__Events__Pro__Main') ? true : false;
     $this->postVenueTypeArgs['public'] = class_exists('Tribe__Events__Pro__Main') ? true : false;
     $this->postOrganizerTypeArgs['public'] = class_exists('Tribe__Events__Pro__Main') ? true : false;
     $this->currentDay = '';
     $this->errors = '';
     $this->default_values = apply_filters('tribe_events_default_value_strategy', new Tribe__Events__Default_Values());
     Tribe__Events__Query::init();
     Tribe__Events__Backcompat::init();
     Tribe__Events__Credits::init();
     Tribe__Events__Timezones::init();
     $this->registerPostType();
     self::debug(sprintf(__('Initializing Tribe Events on %s', 'the-events-calendar'), date('M, jS \\a\\t h:m:s a')));
     $this->maybeSetTECVersion();
 }
Esempio n. 6
0
 /**
  * @return string instance end_date (converted to UTC) in "Y-m-d H:i:s" format
  */
 private function db_formatted_end_date_utc()
 {
     return class_exists('Tribe__Events__Timezones') && !empty($this->timezone) ? Tribe__Events__Timezones::to_utc($this->db_formatted_end_date(), $this->timezone) : $this->db_formatted_end_date();
 }
Esempio n. 7
0
 /**
  * Returns the GCal export link for a given event id.
  *
  * @param int|WP_Post|null $post The Event Post Object or ID, if left empty will give get the current post.
  *
  * @return string The URL for the GCal export link.
  */
 public function googleCalendarLink($post = null)
 {
     if (is_null($post)) {
         $post = self::postIdHelper($post);
     }
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     if (!$post instanceof WP_Post) {
         return false;
     }
     // After this point we know that we have a safe WP_Post object
     // Fetch if the Event is a Full Day Event
     $is_all_day = Tribe__Date_Utils::is_all_day(get_post_meta($post->ID, '_EventAllDay', true));
     // Fetch the required Date TimeStamps
     $start_date = Tribe__Events__Timezones::event_start_timestamp($post->ID);
     // Google Requires that a Full Day event end day happens on the next Day
     $end_date = Tribe__Events__Timezones::event_end_timestamp($post->ID) + ($is_all_day ? DAY_IN_SECONDS : 0);
     if ($is_all_day) {
         $dates = date('Ymd', $start_date) . '/' . date('Ymd', $end_date);
     } else {
         $dates = date('Ymd', $start_date) . 'T' . date('Hi00', $start_date) . '/' . date('Ymd', $end_date) . 'T' . date('Hi00', $end_date);
     }
     // Fetch the
     $location = trim($this->fullAddressString($post->ID));
     $event_details = apply_filters('the_content', get_the_content($post->ID));
     // Hack: Add space after paragraph
     // Normally Google Cal understands the newline character %0a
     // And that character will automatically replace newlines on urlencode()
     $event_details = str_replace('</p>', '</p> ', $event_details);
     $event_details = strip_tags($event_details);
     //Truncate Event Description and add permalink if greater than 996 characters
     if (strlen($event_details) > 996) {
         $event_url = get_permalink($post->ID);
         $event_details = substr($event_details, 0, 996);
         //Only add the permalink if it's shorter than 900 characters, so we don't exceed the browser's URL limits
         if (strlen($event_url) < 900) {
             $event_details .= sprintf(esc_html__(' (View Full %1$s Description Here: %2$s)', 'the-events-calendar'), $this->singular_event_label, $event_url);
         }
     }
     $params = array('action' => 'TEMPLATE', 'text' => urlencode(strip_tags($post->post_title)), 'dates' => $dates, 'details' => urlencode($event_details), 'location' => urlencode($location), 'trp' => 'false', 'sprop' => 'website:' . home_url());
     $timezone = Tribe__Events__Timezones::get_event_timezone_string($post->ID);
     $timezone = Tribe__Events__Timezones::maybe_get_tz_name($timezone);
     // If we have a good timezone string we setup it; UTC doesn't work on Google
     if (false !== $timezone) {
         $params['ctz'] = urlencode($timezone);
     }
     /**
      * Allow users to Filter our Google Calendar Link params
      * @var array Params used in the add_query_arg
      * @var int   Event ID
      */
     $params = apply_filters('tribe_google_calendar_parameters', $params, $post->ID);
     $base_url = 'http://www.google.com/calendar/event';
     $url = add_query_arg($params, $base_url);
     return $url;
 }
Esempio n. 8
0
					</tr>
					<tr class="event-timezone">
						<td class="label">
							<label for="event-timezone">
								<?php 
esc_html_e('Timezone:', 'the-events-calendar');
?>
							</label>
						</td>
						<td>
							<select tabindex="<?php 
tribe_events_tab_index();
?>
" name="EventTimezone" id="event-timezone" class="chosen">
								<?php 
echo wp_timezone_choice(Tribe__Events__Timezones::get_event_timezone_string());
?>
							</select>
						</td>
					</tr>
					<?php 
/**
 * Fires after the event end date field in The Events Calendar meta box
 * HTML outputted here should be wrapped in a table row (<tr>) that contains 2 cells (<td>s)
 *
 * @param int $event->ID the event currently being edited, will be 0 if creating a new event
 * @param boolean
 */
do_action('tribe_events_date_display', $event->ID, true);
?>
				</table>
 /**
  * Custom SQL conditional for event duration meta field
  *
  * @param string   $where_sql
  * @param wp_query $query
  *
  * @return string
  */
 public static function posts_where($where_sql, $query)
 {
     global $wpdb;
     // if it's a true event query then we to setup where conditions
     if ($query->tribe_is_event || $query->tribe_is_event_category) {
         $postmeta_table = self::postmeta_table($query);
         $start_date = $query->get('start_date');
         $end_date = $query->get('end_date');
         $use_utc = Tribe__Events__Timezones::is_mode('site');
         $site_tz = $use_utc ? Tribe__Events__Timezones::wp_timezone_string() : null;
         // Sitewide timezone mode: convert the start date - if set - to UTC
         if ($use_utc && !empty($start_date)) {
             $start_date = Tribe__Events__Timezones::to_utc($start_date, $site_tz);
         }
         // Sitewide timezone mode: convert the end date - if set - to UTC
         if ($use_utc && !empty($end_date)) {
             $end_date = Tribe__Events__Timezones::to_utc($end_date, $site_tz);
         }
         // we can't store end date directly because it messes up the distinct clause
         $event_end_date = apply_filters('tribe_events_query_end_date_column', 'tribe_event_end_date.meta_value');
         // event start date
         $event_start_date = "{$postmeta_table}.meta_value";
         // build where conditionals for events if date range params are set
         if ($start_date != '' && $end_date != '') {
             $start_clause = $wpdb->prepare("({$event_start_date} >= %s AND {$event_start_date} <= %s)", $start_date, $end_date);
             $end_clause = $wpdb->prepare("({$event_end_date} >= %s AND {$event_start_date} <= %s )", $start_date, $end_date);
             $within_clause = $wpdb->prepare("({$event_start_date} < %s AND {$event_end_date} >= %s )", $start_date, $end_date);
             $where_sql .= " AND ({$start_clause} OR {$end_clause} OR {$within_clause})";
         } else {
             if ($start_date != '') {
                 $start_clause = $wpdb->prepare("{$postmeta_table}.meta_value >= %s", $start_date);
                 $within_clause = $wpdb->prepare("({$postmeta_table}.meta_value <= %s AND {$event_end_date} >= %s )", $start_date, $start_date);
                 $where_sql .= " AND ({$start_clause} OR {$within_clause})";
                 if ($query->is_singular() && $query->get('eventDate')) {
                     $tomorrow = date('Y-m-d', strtotime($query->get('eventDate') . ' +1 day'));
                     $tomorrow_clause = $wpdb->prepare("{$postmeta_table}.meta_value < %s", $tomorrow);
                     $where_sql .= " AND {$tomorrow_clause}";
                 }
             } else {
                 if ($end_date != '') {
                     $where_sql .= ' AND ' . $wpdb->prepare("{$event_end_date} < %s", $end_date);
                 }
             }
         }
     }
     return $where_sql;
 }
Esempio n. 10
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 = Tribe__Events__Main::instance();
     $events = '';
     $blogHome = get_bloginfo('url');
     $blogName = get_bloginfo('name');
     if ($post) {
         $events_posts = is_array($post) ? $post : array($post);
     } else {
         if (tribe_is_month()) {
             $events_posts = self::get_month_view_events();
         } else {
             global $wp_query;
             $events_posts = $wp_query->posts;
         }
     }
     $event_ids = wp_list_pluck($events_posts, 'ID');
     foreach ($events_posts as $event_post) {
         // add fields to iCal output
         $item = array();
         $full_format = 'Ymd\\THis';
         $time = (object) array('start' => tribe_get_start_date($event_post->ID, false, 'U'), 'end' => tribe_get_end_date($event_post->ID, false, 'U'), 'modified' => Tribe__Date_Utils::wp_strtotime($event_post->post_modified), 'created' => Tribe__Date_Utils::wp_strtotime($event_post->post_date));
         if ('yes' == get_post_meta($event_post->ID, '_EventAllDay', true)) {
             $type = 'DATE';
             $format = 'Ymd';
         } else {
             $type = 'DATE-TIME';
             $format = $full_format;
         }
         $tzoned = (object) array('start' => date($format, $time->start), 'end' => date($format, $time->end), 'modified' => date($format, $time->modified), 'created' => date($format, $time->created));
         if ('DATE' === $type) {
             $item[] = "DTSTART;VALUE={$type}:" . $tzoned->start;
             $item[] = "DTEND;VALUE={$type}:" . $tzoned->end;
         } else {
             // Are we using the sitewide timezone or the local event timezone?
             $tz = Tribe__Events__Timezones::EVENT_TIMEZONE === Tribe__Events__Timezones::mode() ? Tribe__Events__Timezones::get_event_timezone_string($event_post->ID) : Tribe__Events__Timezones::wp_timezone_string();
             $item[] = 'DTSTART;TZID=' . $tz . ':' . $tzoned->start;
             $item[] = 'DTEND;TZID=' . $tz . ':' . $tzoned->end;
         }
         $item[] = 'DTSTAMP:' . date($full_format, time());
         $item[] = 'CREATED:' . $tzoned->created;
         $item[] = 'LAST-MODIFIED:' . $tzoned->modified;
         $item[] = 'UID:' . $event_post->ID . '-' . $time->start . '-' . $time->end . '@' . parse_url(home_url('/'), PHP_URL_HOST);
         $item[] = 'SUMMARY:' . str_replace(array(',', "\n", "\r", "\t"), array('\\,', '\\n', '', '\\t'), html_entity_decode(strip_tags($event_post->post_title), ENT_QUOTES));
         $item[] = 'DESCRIPTION:' . str_replace(array(',', "\n", "\r", "\t"), array('\\,', '\\n', '', '\\t'), html_entity_decode(strip_tags($event_post->post_content), ENT_QUOTES));
         $item[] = 'URL:' . get_permalink($event_post->ID);
         // add location if available
         $location = $tec->fullAddressString($event_post->ID);
         if (!empty($location)) {
             $str_location = str_replace(array(',', "\n"), array('\\,', '\\n'), html_entity_decode($location, ENT_QUOTES));
             $item[] = 'LOCATION:' . $str_location;
         }
         // add geo coordinates if available
         if (class_exists('Tribe__Events__Pro__Geo_Loc')) {
             $long = Tribe__Events__Pro__Geo_Loc::instance()->get_lng_for_event($event_post->ID);
             $lat = Tribe__Events__Pro__Geo_Loc::instance()->get_lat_for_event($event_post->ID);
             if (!empty($long) && !empty($lat)) {
                 $item[] = sprintf('GEO:%s;%s', $lat, $long);
                 $str_title = str_replace(array(',', "\n"), array('\\,', '\\n'), html_entity_decode(tribe_get_address($event_post->ID), ENT_QUOTES));
                 if (!empty($str_title) && !empty($str_location)) {
                     $item[] = 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=' . str_replace('\\,', '', trim($str_location)) . ';' . 'X-APPLE-RADIUS=500;' . 'X-TITLE=' . trim($str_title) . ':geo:' . $long . ',' . $lat;
                 }
             }
         }
         // add categories if available
         $event_cats = (array) wp_get_object_terms($event_post->ID, Tribe__Events__Main::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_id = tribe_get_organizer_id($event_post->ID);
             $organizer = get_post($organizer_id);
             if ($organizer_id) {
                 $item[] = sprintf('ORGANIZER;CN="%s":MAILTO:%s', rawurlencode($organizer->post_title), $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";
     }
     $site = sanitize_title(get_bloginfo('name'));
     $hash = substr(md5(implode($event_ids)), 0, 11);
     /**
      * Modifies the filename provided in the Content-Disposition header for iCal feeds.
      *
      * @var string       $ical_feed_filename
      * @var WP_Post|null $post
      */
     $filename = apply_filters('tribe_events_ical_feed_filename', $site . '-' . $hash . '.ics', $post);
     header('Content-type: text/calendar; charset=UTF-8');
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     $content = "BEGIN:VCALENDAR\r\n";
     $content .= "VERSION:2.0\r\n";
     $content .= 'PRODID:-//' . $blogName . ' - ECPv' . Tribe__Events__Main::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";
     $content = apply_filters('tribe_ical_properties', $content);
     $content .= $events;
     $content .= 'END:VCALENDAR';
     echo $content;
     exit;
 }
Esempio n. 11
0
 /**
  * given a set of meta data, prepare date data if it exists
  *
  * @param $data array Associative array of event meta data
  *
  * @return array
  */
 protected static function prepare_event_date_meta($event_id, $data)
 {
     $date_provided = false;
     if (isset($data['EventAllDay'])) {
         if (Tribe__Date_Utils::is_all_day($data['EventAllDay'])) {
             $data['EventAllDay'] = 'yes';
         } else {
             $data['EventAllDay'] = 'no';
         }
     }
     $datepicker_format = Tribe__Date_Utils::datepicker_formats(tribe_get_option('datepickerFormat'));
     if (isset($data['EventStartDate'])) {
         $data['EventStartDate'] = Tribe__Date_Utils::datetime_from_format($datepicker_format, $data['EventStartDate']);
     }
     if (isset($data['EventEndDate'])) {
         $data['EventEndDate'] = Tribe__Date_Utils::datetime_from_format($datepicker_format, $data['EventEndDate']);
     }
     if (isset($data['EventAllDay']) && 'yes' === $data['EventAllDay']) {
         $date_provided = true;
         $data['EventStartDate'] = tribe_beginning_of_day($data['EventStartDate']);
         $data['EventEndDate'] = tribe_end_of_day($data['EventEndDate']);
     } elseif (isset($data['EventStartDate']) && isset($data['EventEndDate'])) {
         $date_provided = true;
         delete_post_meta($event_id, '_EventAllDay');
         $start_date_string = "{$data['EventStartDate']} {$data['EventStartHour']}:{$data['EventStartMinute']}:00";
         $end_date_string = "{$data['EventEndDate']} {$data['EventEndHour']}:{$data['EventEndMinute']}:00";
         if (isset($data['EventStartMeridian'])) {
             $start_date_string .= " {$data['EventStartMeridian']}";
         }
         if (isset($data['EventEndMeridian'])) {
             $end_date_string .= " {$data['EventEndMeridian']}";
         }
         $data['EventStartDate'] = date(Tribe__Date_Utils::DBDATETIMEFORMAT, strtotime($start_date_string));
         $data['EventEndDate'] = date(Tribe__Date_Utils::DBDATETIMEFORMAT, strtotime($end_date_string));
     }
     if (!$date_provided) {
         $data['EventStartDate'] = get_post_meta($event_id, '_EventStartDate', true);
         $data['EventEndDate'] = get_post_meta($event_id, '_EventEndDate', true);
         return $data;
     }
     // If a specific timezone was not specified, default to the sitewide timezone
     if (!isset($data['EventTimezone'])) {
         $data['EventTimezone'] = Tribe__Events__Timezones::wp_timezone_string();
     }
     // Additionally store datetimes in UTC
     if (empty($data['EventStartDateUTC'])) {
         $data['EventStartDateUTC'] = Tribe__Events__Timezones::to_utc($data['EventStartDate'], $data['EventTimezone']);
     }
     if (empty($data['EventEndDateUTC'])) {
         $data['EventEndDateUTC'] = Tribe__Events__Timezones::to_utc($data['EventEndDate'], $data['EventTimezone']);
     }
     if (empty($data['EventTimezoneAbbr'])) {
         $data['EventTimezoneAbbr'] = Tribe__Events__Timezones::abbr($data['EventStartDate'], $data['EventTimezone']);
     }
     // sanity check that start date < end date
     $start_timestamp = strtotime($data['EventStartDate']);
     $end_timestamp = strtotime($data['EventEndDate']);
     if ($start_timestamp > $end_timestamp) {
         $data['EventEndDate'] = $data['EventStartDate'];
     }
     $data['EventDuration'] = strtotime($data['EventEndDate']) - $start_timestamp;
     return $data;
 }
Esempio n. 12
0
 /**
  * End Date
  *
  * Returns the event end date
  *
  * @category Events
  * @param int    $event       (optional)
  * @param bool   $displayTime If true shows date and time, if false only shows date
  * @param string $dateFormat  Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  * @param string $timezone    Timezone in which to present the date/time (or default behaviour if not set)
  *
  * @return string|null Date
  */
 function tribe_get_end_date($event = null, $displayTime = true, $dateFormat = '', $timezone = null)
 {
     if (is_null($event)) {
         global $post;
         $event = $post;
     }
     if (is_numeric($event)) {
         $event = get_post($event);
     }
     if (!is_object($event)) {
         return '';
     }
     if (tribe_event_is_all_day($event)) {
         $displayTime = false;
     }
     $end_date = Tribe__Events__Timezones::event_end_timestamp($event->ID, $timezone);
     return tribe_event_format_date($end_date, $displayTime, $dateFormat);
 }
Esempio n. 13
0
/**
 * Returns the event date, or today's date if the event has started and is not over yet.
 *
 * @return int
 **/
function tribe_events_get_widget_event_post_date()
{
    global $post, $wp_query;
    if (class_exists('Tribe__Events__Timezones')) {
        $startDate = Tribe__Events__Timezones::event_start_timestamp($post->ID, null);
        $endDate = Tribe__Events__Timezones::event_end_timestamp($post->ID, null);
    } else {
        $startDate = strtotime($post->EventStartDate);
        $endDate = strtotime($post->EventEndDate);
    }
    $is_multiday = tribe_event_is_multiday($post->ID);
    $is_all_day = tribe_event_is_all_day($post->ID);
    $today = current_time('timestamp');
    $yesterday = $today - DAY_IN_SECONDS;
    // Gets Yesterday cutoff to check which date we pick
    $yesterday_end = tribe_end_of_day(date(Tribe__Date_Utils::DBDATETIMEFORMAT, $yesterday), 'U') + 1;
    // Check if the yesterday cutoff will get the start date of the event
    if ($yesterday_end >= $startDate && !$is_multiday && !$is_all_day) {
        $postDate = $yesterday;
        // If the event starts way in the past or ends way in the future, let's show today's date
    } elseif ($today > $startDate && $today < $endDate) {
        $postDate = $today;
    } else {
        $postDate = $startDate;
    }
    /* If the user clicked in a particular day, let's show that day as the event date, even if the event spans a few days */
    if (defined('DOING_AJAX') && DOING_AJAX && isset($_POST['action']) && $_POST['action'] == 'tribe-mini-cal-day') {
        $postDate = strtotime($_POST['eventDate']);
    }
    return apply_filters('tribe_events_get_widget_event_post_date', $postDate);
}
Esempio n. 14
0
 /**
  * Updates the next batch of non-timezone ready events.
  *
  * @param int $batch_size (defaults to -1 meaning "update all")
  */
 public function process($batch_size = -1)
 {
     $site_timezone = Tribe__Events__Timezones::wp_timezone_string();
     foreach ($this->get_ids($batch_size) as $event_id) {
         $local_start_time = tribe_get_start_date($event_id, true, Tribe__Events__Date_Utils::DBDATETIMEFORMAT);
         $utc_start_time = Tribe__Events__Timezones::to_utc($local_start_time, $site_timezone);
         $local_end_time = tribe_get_end_date($event_id, true, Tribe__Events__Date_Utils::DBDATETIMEFORMAT);
         $utc_end_time = Tribe__Events__Timezones::to_utc($local_end_time, $site_timezone);
         // The abbreviation needs to be calculated per event as it can vary according to the actual date
         $site_timezone_abbr = Tribe__Events__Timezones::wp_timezone_abbr($local_start_time);
         update_post_meta($event_id, '_EventTimezone', $site_timezone);
         update_post_meta($event_id, '_EventTimezoneAbbr', $site_timezone_abbr);
         update_post_meta($event_id, '_EventStartDateUTC', $utc_start_time);
         update_post_meta($event_id, '_EventEndDateUTC', $utc_end_time);
     }
 }
Esempio n. 15
0
 /**
  * End Date
  *
  * Returns the event end date
  *
  * @category Events
  * @param int    $event       (optional)
  * @param bool   $display_time If true shows date and time, if false only shows date
  * @param string $date_format  Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  * @param string $timezone    Timezone in which to present the date/time (or default behaviour if not set)
  *
  * @return string|null Date
  */
 function tribe_get_end_date($event = null, $display_time = true, $date_format = '', $timezone = null)
 {
     if (is_null($event)) {
         global $post;
         $event = $post;
     }
     if (is_numeric($event)) {
         $event = get_post($event);
     }
     if (!is_object($event)) {
         return '';
     }
     if (Tribe__Date_Utils::is_all_day(get_post_meta($event->ID, '_EventAllDay', true))) {
         $display_time = false;
     }
     // @todo move timezones to Common
     if (class_exists('Tribe__Events__Timezones')) {
         $end_date = Tribe__Events__Timezones::event_end_timestamp($event->ID, $timezone);
     }
     return tribe_format_date($end_date, $display_time, $date_format);
 }