本文整理汇总了PHP中tribe_event_beginning_of_day函数的典型用法代码示例。如果您正苦于以下问题:PHP tribe_event_beginning_of_day函数的具体用法?PHP tribe_event_beginning_of_day怎么用?PHP tribe_event_beginning_of_day使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tribe_event_beginning_of_day函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: where
public function where($where, $wp_query)
{
global $ecp_apm, $wpdb;
// run once
remove_filter('posts_where', array($this, 'where'), 10, 2);
foreach ($this->active as $key => $active) {
$field = '';
if ($key === 'ecp_start_date') {
$field = 'eventStart.meta_value';
}
if ($key === 'ecp_end_date') {
$field = 'eventEnd.meta_value';
}
if (empty($field)) {
continue;
}
$value = $active['value'];
switch ($active['is']) {
case 'is':
$where .= $wpdb->prepare(" AND {$field} BETWEEN %s AND %s ", tribe_event_beginning_of_day($value), tribe_event_end_of_day($value));
break;
case 'not':
$where .= $wpdb->prepare(" AND {$field} NOT BETWEEN %s AND %s ", tribe_event_beginning_of_day($value), tribe_event_end_of_day($value));
break;
case 'gte':
$where .= $wpdb->prepare(" AND {$field} >= %s ", tribe_event_beginning_of_day($value));
break;
case 'lte':
$where .= $wpdb->prepare(" AND {$field} <= %s ", tribe_event_end_of_day($value));
break;
}
}
return $where;
}
示例2: pre_get_posts
/**
* Add custom query modification to the pre_get_posts hook as necessary for PRO.
*
* @param WP_Query $query The current query object.
* @return WP_Query The modified query object.
* @author Timothy Wood
* @since 3.0
*/
public function pre_get_posts($query)
{
$pro_query = false;
$query->tribe_is_week = false;
$query->tribe_is_day = false;
$query->tribe_is_photo = false;
$query->tribe_is_map = false;
if (!empty($query->query_vars['eventDisplay'])) {
$pro_query = true;
switch ($query->query_vars['eventDisplay']) {
case 'week':
$week = tribe_get_first_week_day($query->get('eventDate'));
$query->set('start_date', $week);
$query->set('eventDate', $week);
$query->set('end_date', tribe_get_last_week_day($week));
$query->set('orderby', 'event_date');
$query->set('order', 'ASC');
$query->set('posts_per_page', -1);
// show ALL week posts
$query->set('hide_upcoming', false);
$query->tribe_is_week = true;
break;
case 'day':
// a little hack to prevent 404 from happening on day view
add_filter('tribe_events_templates_is_404', '__return_false');
$event_date = $query->get('eventDate') != '' ? $query->get('eventDate') : Date('Y-m-d');
$query->set('start_date', tribe_event_beginning_of_day($event_date));
$query->set('end_date', tribe_event_end_of_day($event_date));
$query->set('eventDate', $event_date);
$query->set('orderby', 'event_date');
$query->set('order', 'ASC');
$query->set('posts_per_page', -1);
// show ALL day posts
$query->set('hide_upcoming', false);
$query->tribe_is_day = true;
break;
case 'photo':
$tribe_event_display = !empty($_REQUEST['tribe_event_display']) ? $_REQUEST['tribe_event_display'] : '';
$tribe_paged = !empty($_REQUEST['tribe_paged']) ? $_REQUEST['tribe_paged'] : 0;
$event_date = $query->get('eventDate') != '' ? $query->get('eventDate') : Date('Y-m-d');
$query->set('start_date', tribe_event_beginning_of_day($event_date));
$query->set('eventDate', $event_date);
$query->set('orderby', 'event_date');
$query->set('order', 'ASC');
$query->set('hide_upcoming', false);
$query->set('paged', $tribe_paged);
$query->tribe_is_photo = true;
if ($tribe_event_display === 'past') {
add_filter('tribe_events_pre_get_posts', array($this, 'set_past_events_query'), 20);
}
break;
case 'map':
/*
* Query setup for the map view is located in
* TribeEventsGeoLoc->setup_geoloc_in_query()
*/
$query->tribe_is_map = true;
}
}
$query->tribe_is_event_pro_query = $pro_query;
return $query->tribe_is_event_pro_query ? apply_filters('tribe_events_pro_pre_get_posts', $query) : $query;
}
示例3: get_rounded_beginning_of_day
/**
* Account for :30 EOD cutoffs, which break week view
*
* @param $date
* @param string $format
*
* @return bool|string
*/
protected static function get_rounded_beginning_of_day($date, $format = 'U')
{
$beginning_of_day = tribe_event_beginning_of_day($date, 'U');
reset(self::$hour_range);
$date = max($beginning_of_day, strtotime($date . ' ' . tribe_events_week_get_hours('first-hour')));
$date = date('Y-m-d H:00:00', $date);
$date = date($format, strtotime($date));
return $date;
}
示例4: saveEventMeta
/**
* Used by createEvent and updateEvent - saves all the various event meta
*
* @param int $event_id The event ID we are modifying meta for.
* @param array $data The meta fields we want saved.
* @param WP_Post The event itself.
*
* @return void
*/
public static function saveEventMeta($event_id, $data, $event = null)
{
if (isset($data['EventAllDay']) && ($data['EventAllDay'] == 'yes' || $data['EventAllDay'] == true || !isset($data['EventStartDate']))) {
$data['EventStartDate'] = tribe_event_beginning_of_day($data['EventStartDate']);
$data['EventEndDate'] = tribe_event_end_of_day($data['EventEndDate']);
} else {
delete_post_meta($event_id, '_EventAllDay');
if (isset($data['EventStartMeridian'])) {
$data['EventStartDate'] = date(TribeDateUtils::DBDATETIMEFORMAT, strtotime($data['EventStartDate'] . " " . $data['EventStartHour'] . ":" . $data['EventStartMinute'] . ":00 " . $data['EventStartMeridian']));
$data['EventEndDate'] = date(TribeDateUtils::DBDATETIMEFORMAT, strtotime($data['EventEndDate'] . " " . $data['EventEndHour'] . ":" . $data['EventEndMinute'] . ":00 " . $data['EventEndMeridian']));
} else {
$data['EventStartDate'] = date(TribeDateUtils::DBDATETIMEFORMAT, strtotime($data['EventStartDate'] . " " . $data['EventStartHour'] . ":" . $data['EventStartMinute'] . ":00"));
$data['EventEndDate'] = date(TribeDateUtils::DBDATETIMEFORMAT, strtotime($data['EventEndDate'] . " " . $data['EventEndHour'] . ":" . $data['EventEndMinute'] . ":00"));
}
}
if (empty($data['EventHideFromUpcoming'])) {
delete_post_meta($event_id, '_EventHideFromUpcoming');
}
// sanity check that start date < end date
$startTimestamp = strtotime($data['EventStartDate']);
$endTimestamp = strtotime($data['EventEndDate']);
if ($startTimestamp > $endTimestamp) {
$data['EventEndDate'] = $data['EventStartDate'];
}
$data['EventDuration'] = strtotime($data['EventEndDate']) - $startTimestamp;
update_post_meta($event_id, '_EventShowMapLink', isset($data['venue']['EventShowMapLink']));
update_post_meta($event_id, '_EventShowMap', isset($data['venue']['EventShowMap']));
if (isset($data['post_status'])) {
$post_status = $data['post_status'];
} else {
$post_status = get_post_status($event_id);
}
if (isset($data["Organizer"])) {
if (!empty($data["Organizer"]["OrganizerID"])) {
$organizer_post_status = get_post($data["Organizer"]['OrganizerID'])->post_status;
} else {
$organizer_post_status = $post_status;
}
$data['EventOrganizerID'] = TribeEventsAPI::saveEventOrganizer($data["Organizer"], $event, $organizer_post_status);
}
if (isset($data["Venue"])) {
if (!empty($data['Venue']["VenueID"])) {
$venue_post_status = get_post($data['Venue']['VenueID'])->post_status;
} else {
$venue_post_status = $post_status;
}
$data['EventVenueID'] = TribeEventsAPI::saveEventVenue($data["Venue"], $event, $venue_post_status);
}
$cost = isset($data['EventCost']) ? $data['EventCost'] : '';
$data['EventCost'] = $cost;
do_action('tribe_events_event_save', $event_id);
$cost = isset($data['EventCost']) ? $data['EventCost'] : '';
$data['EventCost'] = $cost;
//update meta fields
foreach (TribeEvents::instance()->metaTags as $tag) {
$htmlElement = ltrim($tag, '_');
if (isset($data[$htmlElement]) && $tag != TribeEvents::EVENTSERROROPT) {
if (is_string($data[$htmlElement])) {
$data[$htmlElement] = filter_var($data[$htmlElement], FILTER_SANITIZE_STRING);
}
update_post_meta($event_id, $tag, $data[$htmlElement]);
}
}
// Set sticky state for calendar view.
if (isset($data['EventShowInCalendar']) && $data['EventShowInCalendar'] == 'yes' && $event->menu_order != '-1') {
$update_event = array('ID' => $event_id, 'menu_order' => '-1');
wp_update_post($update_event);
} elseif ((!isset($data['EventShowInCalendar']) || $data['EventShowInCalendar'] != 'yes') && $event->menu_order == '-1') {
$update_event = array('ID' => $event_id, 'menu_order' => '0');
wp_update_post($update_event);
}
do_action('tribe_events_update_meta', $event_id, $data);
}
示例5: pre_get_posts
/**
* Add custom query modification to the pre_get_posts hook as necessary for PRO.
*
* @param WP_Query $query The current query object.
* @return WP_Query The modified query object.
* @author Timothy Wood
* @since 3.0
*/
public function pre_get_posts($query)
{
if (!empty($query->tribe_is_event_pro_query)) {
switch ($query->query_vars['eventDisplay']) {
case 'week':
$week = tribe_get_first_week_day($query->get('eventDate'));
$query->set('eventDate', $week);
$query->set('start_date', $week);
$query->set('end_date', tribe_get_last_week_day($week));
$query->set('posts_per_page', -1);
// show ALL week posts
$query->set('hide_upcoming', false);
break;
case 'day':
$event_date = $query->get('eventDate') != '' ? $query->get('eventDate') : Date('Y-m-d', current_time('timestamp'));
$query->set('eventDate', $event_date);
$query->set('start_date', tribe_event_beginning_of_day($event_date));
$query->set('end_date', tribe_event_end_of_day($event_date));
$query->set('posts_per_page', -1);
// show ALL day posts
$query->set('hide_upcoming', false);
break;
case 'photo':
$query->set('hide_upcoming', false);
break;
}
apply_filters('tribe_events_pro_pre_get_posts', $query);
}
}
示例6: getEventCounts
/**
* Gets the event counts for individual days.
*
* @param array $args
*
* @return array The counts array.
*/
public static function getEventCounts($args = array())
{
_deprecated_function(__METHOD__, '3.10.1');
global $wpdb;
$date = date('Y-m-d');
$defaults = array('post_type' => Tribe__Events__Main::POSTTYPE, 'start_date' => tribe_event_beginning_of_day($date), 'end_date' => tribe_event_end_of_day($date), 'display_type' => 'daily', 'hide_upcoming_ids' => null);
$args = wp_parse_args($args, $defaults);
$args['posts_per_page'] = -1;
$args['fields'] = 'ids';
// remove empty args and sort by key, this increases chance of a cache hit
$args = array_filter($args, array(__CLASS__, 'filter_args'));
ksort($args);
$cache = new Tribe__Events__Cache();
$cache_key = 'daily_counts_and_ids_' . serialize($args);
$found = $cache->get($cache_key, 'save_post');
if ($found) {
return $found;
}
$cache_key = 'month_post_ids_' . serialize($args);
$found = $cache->get($cache_key, 'save_post');
if ($found && is_array($found)) {
$post_ids = $found;
} else {
$post_id_query = new WP_Query();
$post_ids = $post_id_query->query($args);
$cache->set($cache_key, $post_ids, Tribe__Events__Cache::NON_PERSISTENT, 'save_post');
}
$counts = array();
$event_ids = array();
if (!empty($post_ids)) {
switch ($args['display_type']) {
case 'daily':
default:
global $wp_query;
$output_date_format = '%Y-%m-%d %H:%i:%s';
$raw_counts = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT \ttribe_event_start.post_id as ID,\n\t\t\t\t\t\t\t\t\ttribe_event_start.meta_value as EventStartDate,\n\t\t\t\t\t\t\t\t\tDATE_FORMAT( tribe_event_end_date.meta_value, '%1\$s') as EventEndDate,\n\t\t\t\t\t\t\t\t\t{$wpdb->posts}.menu_order as menu_order\n\t\t\t\t\t\t\tFROM {$wpdb->postmeta} AS tribe_event_start\n\t\t\t\t\t\t\t\t\tLEFT JOIN {$wpdb->posts} ON (tribe_event_start.post_id = {$wpdb->posts}.ID)\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} as tribe_event_end_date ON ( tribe_event_start.post_id = tribe_event_end_date.post_id AND tribe_event_end_date.meta_key = '_EventEndDate' )\n\t\t\t\t\t\t\tWHERE tribe_event_start.meta_key = '_EventStartDate'\n\t\t\t\t\t\t\tAND tribe_event_start.post_id IN ( %5\$s )\n\t\t\t\t\t\t\tAND ( (tribe_event_start.meta_value >= '%3\$s' AND tribe_event_start.meta_value <= '%4\$s')\n\t\t\t\t\t\t\t\tOR (tribe_event_start.meta_value <= '%3\$s' AND tribe_event_end_date.meta_value >= '%3\$s')\n\t\t\t\t\t\t\t\tOR ( tribe_event_start.meta_value >= '%3\$s' AND tribe_event_start.meta_value <= '%4\$s')\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tORDER BY menu_order ASC, DATE(tribe_event_start.meta_value) ASC, TIME(tribe_event_start.meta_value) ASC;", $output_date_format, $output_date_format, $post_id_query->query_vars['start_date'], $post_id_query->query_vars['end_date'], implode(',', array_map('intval', $post_ids))));
$start_date = new DateTime($post_id_query->query_vars['start_date']);
$end_date = new DateTime($post_id_query->query_vars['end_date']);
$days = Tribe__Events__Date_Utils::date_diff($start_date->format('Y-m-d'), $end_date->format('Y-m-d'));
$term_id = isset($wp_query->query_vars[Tribe__Events__Main::TAXONOMY]) ? $wp_query->query_vars[Tribe__Events__Main::TAXONOMY] : null;
$terms = array();
if (is_int($term_id)) {
$terms[0] = $term_id;
} elseif (is_string($term_id)) {
$term = get_term_by('slug', $term_id, Tribe__Events__Main::TAXONOMY);
if ($term) {
$terms[0] = $term->term_id;
}
}
if (!empty($terms) && is_tax(Tribe__Events__Main::TAXONOMY)) {
$terms = array_merge($terms, get_term_children($terms[0], Tribe__Events__Main::TAXONOMY));
}
for ($i = 0, $date = $start_date; $i <= $days; $i++, $date->modify('+1 day')) {
$formatted_date = $date->format('Y-m-d');
$count = 0;
$_day_event_ids = array();
foreach ($raw_counts as $record) {
$event = new stdClass();
$event->EventStartDate = $record->EventStartDate;
$event->EventEndDate = $record->EventEndDate;
$per_day_limit = apply_filters('tribe_events_month_day_limit', tribe_get_option('monthEventAmount', '3'));
if (tribe_event_is_on_date($formatted_date, $event)) {
if (!empty($terms)) {
if (!has_term($terms, Tribe__Events__Main::TAXONOMY, $record->ID)) {
continue;
}
}
if (count($_day_event_ids) < $per_day_limit) {
$_day_event_ids[] = $record->ID;
}
$count++;
}
}
$event_ids[$formatted_date] = $_day_event_ids;
$counts[$formatted_date] = $count;
}
break;
}
// get a unique list of the event IDs that will be displayed, and update all their postmeta and term caches at once
$final_event_ids = call_user_func_array('array_merge', $event_ids);
$final_event_ids = array_unique($final_event_ids);
update_object_term_cache($final_event_ids, Tribe__Events__Main::POSTTYPE);
update_postmeta_cache($final_event_ids);
}
// return IDs per day and total counts per day
$return = array('counts' => $counts, 'event_ids' => $event_ids);
$cache = new Tribe__Events__Cache();
$cache_key = 'daily_counts_and_ids_' . serialize($args);
$cache->set($cache_key, $return, Tribe__Events__Cache::NON_PERSISTENT, 'save_post');
return $return;
}
示例7: getEventCounts
/**
* Gets the event counts for individual days.
*
* @param array $args
*
* @return array The counts array.
*/
public static function getEventCounts($args = array())
{
global $wpdb;
do_action('log', 'getEventCounts() $args', 'tribe-events-query', $args);
$date = date('Y-m-d');
$defaults = array('post_type' => TribeEvents::POSTTYPE, 'start_date' => tribe_event_beginning_of_day($date), 'end_date' => tribe_event_end_of_day($date), 'display_type' => 'daily', 'hide_upcoming_ids' => null);
$args = wp_parse_args($args, $defaults);
$args['posts_per_page'] = -1;
$args['fields'] = 'ids';
// remove empty args and sort by key, this increases chance of a cache hit
$args = array_filter($args, array(__CLASS__, 'filter_args'));
ksort($args);
$cache = new TribeEventsCache();
$cache_key = 'daily_counts_and_ids_' . serialize($args);
$found = $cache->get($cache_key, 'save_post');
if ($found) {
do_action('log', 'cache hit ' . __LINE__, 'tribe-events-cache', $args);
return $found;
}
do_action('log', 'no cache hit ' . __LINE__, 'tribe-events-cache', $args);
$cache_key = 'month_post_ids_' . serialize($args);
$found = $cache->get($cache_key, 'save_post');
if ($found && is_array($found)) {
do_action('log', 'cache hit ' . __LINE__, 'tribe-events-cache', $args);
$post_ids = $found;
} else {
do_action('log', 'no cache hit ' . __LINE__, 'tribe-events-cache', $args);
$post_id_query = new WP_Query();
$post_ids = $post_id_query->query($args);
do_action('log', 'final args for month view post ids', 'tribe-events-query', $post_id_query->query_vars);
do_action('log', 'Month view getEventCounts SQL', 'tribe-events-query', $post_id_query->request);
$cache->set($cache_key, $post_ids, TribeEventsCache::NON_PERSISTENT, 'save_post');
}
do_action('log', 'Month view post ids found', 'tribe-events-query', $post_ids);
$counts = array();
$event_ids = array();
if (!empty($post_ids)) {
switch ($args['display_type']) {
case 'daily':
default:
global $wp_query;
$output_date_format = '%Y-%m-%d %H:%i:%s';
do_action('log', 'raw counts args', 'tribe-events-query', $args);
$raw_counts = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT \ttribe_event_start.post_id as ID, \n\t\t\t\t\t\t\t\t\ttribe_event_start.meta_value as EventStartDate, \n\t\t\t\t\t\t\t\t\tDATE_FORMAT( tribe_event_end_date.meta_value, '%1\$s') as EventEndDate,\n\t\t\t\t\t\t\t\t\t{$wpdb->posts}.menu_order as menu_order\n\t\t\t\t\t\t\tFROM {$wpdb->postmeta} AS tribe_event_start\n\t\t\t\t\t\t\t\t\tLEFT JOIN {$wpdb->posts} ON (tribe_event_start.post_id = {$wpdb->posts}.ID)\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} as tribe_event_end_date ON ( tribe_event_start.post_id = tribe_event_end_date.post_id AND tribe_event_end_date.meta_key = '_EventEndDate' )\n\t\t\t\t\t\t\tWHERE tribe_event_start.meta_key = '_EventStartDate'\n\t\t\t\t\t\t\tAND tribe_event_start.post_id IN ( %5\$s )\n\t\t\t\t\t\t\tAND ( (tribe_event_start.meta_value >= '%3\$s' AND tribe_event_start.meta_value <= '%4\$s')\n\t\t\t\t\t\t\t\tOR (tribe_event_start.meta_value <= '%3\$s' AND tribe_event_end_date.meta_value >= '%3\$s')\n\t\t\t\t\t\t\t\tOR ( tribe_event_start.meta_value >= '%3\$s' AND tribe_event_start.meta_value <= '%4\$s')\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tORDER BY menu_order ASC, DATE(tribe_event_start.meta_value) ASC, TIME(tribe_event_start.meta_value) ASC;", $output_date_format, $output_date_format, $post_id_query->query_vars['start_date'], $post_id_query->query_vars['end_date'], implode(',', array_map('intval', $post_ids))));
do_action('log', 'raw counts query', 'tribe-events-query', $wpdb->last_query);
$start_date = new DateTime($post_id_query->query_vars['start_date']);
$end_date = new DateTime($post_id_query->query_vars['end_date']);
$days = TribeDateUtils::dateDiff($start_date->format('Y-m-d'), $end_date->format('Y-m-d'));
$term_id = isset($wp_query->query_vars[TribeEvents::TAXONOMY]) ? $wp_query->query_vars[TribeEvents::TAXONOMY] : null;
if (is_int($term_id)) {
$term = get_term_by('id', $term_id, TribeEvents::TAXONOMY);
} elseif (is_string($term_id)) {
$term = get_term_by('slug', $term_id, TribeEvents::TAXONOMY);
}
for ($i = 0, $date = $start_date; $i <= $days; $i++, $date->modify('+1 day')) {
$formatted_date = $date->format('Y-m-d');
$start_of_day = strtotime(tribe_event_beginning_of_day($formatted_date));
$end_of_day = strtotime(tribe_event_end_of_day($formatted_date)) + 1;
$count = 0;
$_day_event_ids = array();
foreach ($raw_counts as $record) {
$record_start = strtotime($record->EventStartDate);
$record_end = strtotime($record->EventEndDate);
/**
* conditions:
* event starts on this day (event start time is between start and end of day)
* event ends on this day (event end time is between start and end of day)
* event starts before start of day and ends after end of day (spans across this day)
* note:
* events that start exactly on the EOD cutoff will count on the following day
* events that end exactly on the EOD cutoff will count on the previous day
*/
$event_starts_today = $record_start >= $start_of_day && $record_start < $end_of_day;
$event_ends_today = $record_end > $start_of_day && $record_end <= $end_of_day;
$event_spans_across_today = $record_start < $start_of_day && $record_end > $end_of_day;
if ($event_starts_today || $event_ends_today || $event_spans_across_today) {
if (isset($term->term_id)) {
if (!has_term($term, TribeEvents::TAXONOMY, $record->ID)) {
continue;
}
}
if (count($_day_event_ids) < apply_filters('tribe_events_month_day_limit', tribe_get_option('monthEventAmount', '3'))) {
$_day_event_ids[] = $record->ID;
}
$count++;
}
}
$event_ids[$formatted_date] = $_day_event_ids;
$counts[$formatted_date] = $count;
}
break;
}
// get a unique list of the event IDs that will be displayed, and update all their postmeta and term caches at once
//.........这里部分代码省略.........
示例8: ajax_select_day_set_date
public function ajax_select_day_set_date($query)
{
if (isset($_POST['eventDate']) && $_POST['eventDate']) {
$query->set('eventDate', $_POST['eventDate']);
$query->set('eventDisplay', 'day');
$query->set('start_date', tribe_event_beginning_of_day($_POST['eventDate']));
$query->set('end_date', tribe_event_end_of_day($_POST['eventDate']));
$query->set('hide_upcoming', false);
}
return $query;
}
示例9: get_rounded_beginning_of_day
protected static function get_rounded_beginning_of_day($date, $format = 'U')
{
$date = tribe_event_beginning_of_day($date, 'Y-m-d H:00:00');
return date($format, strtotime($date));
}
示例10: get_cutoff_details
/**
* Retrieves beginning/end times for a given date
*
* @param string $date Y-m-d date string
* @param string $key Key of cached data to retrieve
*
* return string|int
*/
private function get_cutoff_details($date, $key)
{
static $beginnings_and_ends = array();
if (empty($beginnings_and_ends[$date])) {
$beginnings_and_ends[$date] = array('beginning' => tribe_event_beginning_of_day($date), 'end' => tribe_event_end_of_day($date));
$beginnings_and_ends[$date]['beginning_timestamp'] = strtotime($beginnings_and_ends[$date]['beginning']);
$beginnings_and_ends[$date]['end_timestamp'] = strtotime($beginnings_and_ends[$date]['end']);
}
return $beginnings_and_ends[$date][$key];
}
示例11: pre_get_posts
/**
* Add custom query modification to the pre_get_posts hook as necessary for PRO.
*
* @param WP_Query $query The current query object.
* @return WP_Query The modified query object.
* @author Timothy Wood
* @since 3.0
*/
public function pre_get_posts($query)
{
if ($query->is_single() && $query->get('eventDate')) {
$this->set_post_id_for_recurring_event_query($query);
}
if (!empty($query->tribe_is_event_pro_query)) {
switch ($query->query_vars['eventDisplay']) {
case 'week':
$week = tribe_get_first_week_day($query->get('eventDate'));
$query->set('eventDate', $week);
$query->set('start_date', $week);
$query->set('end_date', tribe_get_last_week_day($week));
$query->set('posts_per_page', -1);
// show ALL week posts
$query->set('hide_upcoming', false);
break;
case 'day':
$event_date = $query->get('eventDate') != '' ? $query->get('eventDate') : Date('Y-m-d', current_time('timestamp'));
$query->set('eventDate', $event_date);
$query->set('start_date', tribe_event_beginning_of_day($event_date));
$query->set('end_date', tribe_event_end_of_day($event_date));
$query->set('posts_per_page', -1);
// show ALL day posts
$query->set('hide_upcoming', false);
break;
case 'photo':
$query->set('hide_upcoming', false);
break;
case 'all':
$slug = $query->get('name');
if (empty($slug)) {
break;
// we shouldn't be here
}
unset($query->query_vars['name']);
unset($query->query_vars['tribe_events']);
$all_ids = TribeEventsRecurrenceMeta::get_events_by_slug($slug);
if (empty($all_ids)) {
$query->set('p', -1);
} else {
$query->set('post__in', $all_ids);
}
break;
}
apply_filters('tribe_events_pro_pre_get_posts', $query);
}
}
示例12: prepare_event_date_meta
/**
* 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__Events__Date_Utils::is_all_day($data['EventAllDay'])) {
$data['EventAllDay'] = 'yes';
} else {
$data['EventAllDay'] = 'no';
}
}
$datepicker_format = Tribe__Events__Date_Utils::datepicker_formats(tribe_get_option('datepickerFormat'));
if (isset($data['EventStartDate'])) {
$data['EventStartDate'] = Tribe__Events__Date_Utils::datetime_from_format($datepicker_format, $data['EventStartDate']);
}
if (isset($data['EventEndDate'])) {
$data['EventEndDate'] = Tribe__Events__Date_Utils::datetime_from_format($datepicker_format, $data['EventEndDate']);
}
if (isset($data['EventAllDay']) && 'yes' === $data['EventAllDay']) {
$date_provided = true;
$data['EventStartDate'] = tribe_event_beginning_of_day($data['EventStartDate']);
$data['EventEndDate'] = tribe_event_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__Events__Date_Utils::DBDATETIMEFORMAT, strtotime($start_date_string));
$data['EventEndDate'] = date(Tribe__Events__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
$data['EventStartDateUTC'] = Tribe__Events__Timezones::to_utc($data['EventStartDate'], $data['EventTimezone']);
$data['EventEndDateUTC'] = Tribe__Events__Timezones::to_utc($data['EventEndDate'], $data['EventTimezone']);
$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;
}
示例13: tribe_event_is_on_date
/**
* Given a date and an event, returns true or false if the event is happening on that date
* This function properly adjusts for the EOD cutoff and multi-day events
*
* @param null $date
* @param null $event
*
* @return mixed|void
*/
function tribe_event_is_on_date($date = null, $event = null)
{
if (null === $date) {
$date = current_time('mysql');
}
if (null === $event) {
global $post;
$event = $post;
if (empty($event)) {
_doing_it_wrong(__FUNCTION__, __('The function needs to be passed an $event or used in the loop.', 'tribe-events-calendar'));
return false;
}
}
$event_is_on_date = false;
$start_of_day = tribe_event_beginning_of_day($date, 'U');
$end_of_day = tribe_event_end_of_day($date, 'U');
$event_start = tribe_get_start_date($event, null, 'U');
$event_end = tribe_get_end_date($event, null, 'U');
// kludge
if (!empty($event->_end_date_fixed)) {
// @todo remove this once we can have all day events without a start / end time
$event_end = date_create(date(Tribe__Events__Date_Utils::DBDATETIMEFORMAT, $event_end));
$event_end->modify('+1 day');
$event_end = $event_end->format('U');
}
/**
* conditions:
* event starts on this day (event start time is between start and end of day)
* event ends on this day (event end time is between start and end of day)
* event starts before start of day and ends after end of day (spans across this day)
* note:
* events that start exactly on the EOD cutoff will count on the following day
* events that end exactly on the EOD cutoff will count on the previous day
*/
$event_starts_today = $event_start >= $start_of_day && $event_start < $end_of_day;
$event_ends_today = $event_end > $start_of_day && $event_end <= $end_of_day;
$event_spans_across_today = $event_start < $start_of_day && $event_end > $end_of_day;
if ($event_starts_today || $event_ends_today || $event_spans_across_today) {
$event_is_on_date = true;
}
return apply_filters('tribe_event_is_on_date', $event_is_on_date, $date, $event);
}
示例14: get_daily_events
/**
* Get the events for a single day
*
* @param string $date
*
* @return WP_Query
*/
private function get_daily_events($date)
{
$args = wp_parse_args(array('start_date' => tribe_event_beginning_of_day($date), 'end_date' => tribe_event_end_of_day($date), 'posts_per_page' => $this->events_per_day, 'post__in' => $this->events_in_month, 'orderby' => 'menu_order'), self::$args);
$result = tribe_get_events($args, true);
return $result;
}
示例15: beginningOfDay
/**
* Returns the beginning of a given day.
*
* @deprecated since 3.10
* @todo remove in 4.1
*
* @param int|string $date The date (timestamp or string).
* @param bool $isTimestamp Is $date in timestamp format?
*
* @return string The date and time of the beginning of a given day.
*/
public static function beginningOfDay($date, $isTimestamp = false)
{
_deprecated_function(__METHOD__, '3.10', 'tribe_event_beginning_of_day');
if ($isTimestamp) {
$date = date(self::DBDATEFORMAT, $date);
}
return tribe_event_beginning_of_day($date, self::DBDATETIMEFORMAT);
}