Example #1
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);
 }
Example #2
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;
 }
/**
 * 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);
}
Example #4
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);
 }
Example #5
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);
 }