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