protected function match_existing_post(array $record)
 {
     $start_date = $this->get_event_start_date($record);
     $end_date = $this->get_event_end_date($record);
     $all_day = $this->get_boolean_value_by_key($record, 'event_all_day');
     // Base query - only the meta query will be different
     $query_args = array('post_type' => Tribe__Events__Main::POSTTYPE, 'post_title' => $this->get_value_by_key($record, 'event_name'), 'fields' => 'ids', 'posts_per_page' => 1);
     // When trying to find matches for all day events, the comparison should only be against the date
     // component only since a) the time is irrelevant and b) the time may have been adjusted to match
     // the eod cutoff setting
     if (Tribe__Date_Utils::is_all_day($all_day)) {
         $meta_query = array(array('key' => '_EventStartDate', 'value' => $this->get_event_start_date($record, true), 'compare' => 'LIKE'), array('key' => '_EventAllDay', 'value' => 'yes'));
         // For regular, non-all day events, use the full date *and* time in the start date comparison
     } else {
         $meta_query = array(array('key' => '_EventStartDate', 'value' => $start_date));
     }
     // Optionally use the end date/time for matching, where available
     if (!empty($end_date) && !$all_day) {
         $meta_query[] = array('key' => '_EventEndDate', 'value' => $end_date);
     }
     $query_args['meta_query'] = $meta_query;
     add_filter('posts_search', array($this, 'filter_query_for_title_search'), 10, 2);
     $matches = get_posts($query_args);
     remove_filter('posts_search', array($this, 'filter_query_for_title_search'), 10, 2);
     if (empty($matches)) {
         return 0;
     }
     return reset($matches);
 }
 /**
  * Assess if this is an all day event.
  */
 protected function set_all_day()
 {
     $this->vars['isEventAllDay'] = Tribe__Date_Utils::is_all_day($this->vars['_EventAllDay']) || !Tribe__Date_Utils::date_only($this->vars['_EventStartDate']) ? 'checked="checked"' : '';
 }
Exemplo n.º 3
0
 /**
  * All Day Event Test
  *
  * Returns true if the event is an all day event
  *
  * @category Events
  * @param int $postId (optional)
  *
  * @return bool
  */
 function tribe_event_is_all_day($postId = null)
 {
     $output = Tribe__Date_Utils::is_all_day(tribe_get_event_meta($postId, '_EventAllDay', true));
     return apply_filters('tribe_event_is_all_day', $output, $postId);
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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);
 }