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__Events__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); }
/** * Handler for the date column * * @param $item * * @return string */ public function column_date($item) { return Tribe__Events__Date_Utils::reformat($item['completed_at'], Tribe__Events__Date_Utils::DATEONLYFORMAT); }
protected function set_end_date_time() { $this->vars['endMinuteOptions'] = Tribe__Events__View_Helpers::getMinuteOptions($this->vars['_EventEndDate']); $this->vars['endHourOptions'] = Tribe__Events__View_Helpers::getHourOptions($this->vars['_EventAllDay'] == 'yes' ? null : $this->vars['_EventEndDate']); $this->vars['endMeridianOptions'] = Tribe__Events__View_Helpers::getMeridianOptions($this->vars['_EventEndDate']); $datepicker_format = Tribe__Events__Date_Utils::datepicker_formats(tribe_get_option('datepickerFormat')); if ($this->vars['_EventEndDate']) { $end = Tribe__Events__Date_Utils::date_only($this->vars['_EventEndDate'], false, $datepicker_format); } // If we don't have a valid end date, assume today's date $this->vars['EventEndDate'] = isset($end) && $end ? $end : date($datepicker_format); }
/** * Gets the first day of the week in a month (ie the first Tuesday). * * @param int $curdate A timestamp. * @param int $day_of_week The index of the day of the week. * * @return int The timestamp of the date that fits the qualifications. */ public static function getFirstDayOfWeekInMonth($curdate, $day_of_week) { $nextdate = mktime(0, 0, 0, date('n', $curdate), 1, date('Y', $curdate)); while (!($day_of_week > 0 && date('N', $nextdate) == $day_of_week) && !($day_of_week == -1 && Tribe__Events__Date_Utils::isWeekday($nextdate)) && !($day_of_week == -2 && Tribe__Events__Date_Utils::isWeekend($nextdate))) { $nextdate = strtotime(date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, $nextdate) . " + 1 day"); } return $nextdate; }
/** * 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__, esc_html__('The function needs to be passed an $event or used in the loop.', 'the-events-calendar')); return 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'); } /* 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_is_on_date = Tribe__Events__Date_Utils::range_coincides($start_of_day, $end_of_day, $event_start, $event_end); return apply_filters('tribe_event_is_on_date', $event_is_on_date, $date, $event); }
/** * Get the timestamp of the Nth day of month. * * @param int $curdate The current occurrence's timestamp. * @param int $day_of_week The index of the day-of-week. * @param int $week_of_month The index of the week of the month. * @param int $next_month_of_year The index of the next month of the year. * * @return int The timestamp of the next occurrence on the nth day of the month. */ private function getNthDayOfMonth($curdate, $day_of_week, $week_of_month, $next_month_of_year) { $nextdate = $this->advanceDate($curdate, $next_month_of_year, 1); // advance to correct month $nextdate = Tribe__Events__Date_Utils::get_first_day_of_week_in_month($nextdate, $day_of_week); if ($week_of_month == -1) { // LAST WEEK $nextdate = Tribe__Events__Date_Utils::get_last_day_of_week_in_month($nextdate, $day_of_week); return $nextdate; } else { $maybe_date = strtotime(date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, $nextdate) . ' + ' . ($week_of_month - 1) . ' weeks'); // if this doesn't exist, then try next month while (date('n', $maybe_date) != date('n', $nextdate)) { // advance again $next_month_of_year = $this->getNextMonthOfYear(date('n', $nextdate)); $nextdate = $this->advanceDate($nextdate, $next_month_of_year); $nextdate = Tribe__Events__Date_Utils::get_first_day_of_week_in_month($curdate, $day_of_week); $maybe_date = strtotime(date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, $nextdate) . ' + ' . ($week_of_month - 1) . ' weeks'); } return $maybe_date; } }
/** * Return the date of the first day in the month view grid. * * This is not necessarily the last day of the specified month, rather it is the date of * the final grid cell which could be anything upto 6 days into the next month. * * @param string $month * @param int $start_of_week * * @return bool|string (Y-m-d) */ protected function calculate_final_cell_date($month, $start_of_week = null) { if (null === $start_of_week) { $start_of_week = (int) get_option('start_of_week', 0); } $last_day = Tribe__Events__Date_Utils::last_day_in_month($month); $end_of_week = Tribe__Events__Date_Utils::week_ends_on($start_of_week); if ($end_of_week < $last_day) { $end_of_week += 7; } $diff = $end_of_week - $last_day; if ($diff >= 0) { $diff = "+{$diff}"; } try { $date = new DateTime($month); $date = new DateTime($date->format('Y-m-t')); $date->modify("{$diff} days"); return $date->format(Tribe__Events__Date_Utils::DBDATEFORMAT); } catch (Exception $e) { return false; } }
/** * Returns the earliest known event start date, which can be expected to be a string * in MySQL datetime format (unless some other specific format is provided). * * If this is impossible to determine it will return boolean false. * * @category Events * * @param string $format * * @return mixed bool|string */ function tribe_events_earliest_date($format = Tribe__Events__Date_Utils::DBDATETIMEFORMAT) { // Check if the earliest start date is already known $earliest = tribe_get_option('earliest_date', false); if (false !== $earliest) { return Tribe__Events__Date_Utils::reformat($earliest, $format); } // If not, try to determine now Tribe__Events__Main::instance()->rebuild_known_range(); $earliest = tribe_get_option('earliest_date', false); if (false !== $earliest) { return Tribe__Events__Date_Utils::reformat($earliest, $format); } return false; }
/** * Convert the event recurrence meta into a human readable string * * @param array $postId The recurring event * * @return The human readable string */ public static function recurrenceToText($recurrence_rules = array(), $start_date) { $text = ''; $custom_text = ''; $occurrence_text = ''; $recType = ''; $recEndType = ''; $recEndCount = ''; $recCustomType = ''; $recCustomInterval = null; $recCustomMonthNumber = null; $recCustomYearMonthNumber = null; $recCustomYearFilter = ''; $recCustomYearMonth = ''; $recCustomYearMonthDay = ''; extract($recurrence_rules); if ($recType == 'Every Day') { $text = __('Every day', 'tribe-events-calendar-pro'); $occurrence_text = sprintf(_n(' for %d day', ' for %d days', $recEndCount, 'tribe-events-calendar-pro'), $recEndCount); $custom_text = ''; } elseif ($recType == 'Every Week') { $text = __('Every week', 'tribe-events-calendar-pro'); $occurrence_text = sprintf(_n(' for %d week', ' for %d weeks', $recEndCount, 'tribe-events-calendar-pro'), $recEndCount); } elseif ($recType == 'Every Month') { $text = __('Every month', 'tribe-events-calendar-pro'); $occurrence_text = sprintf(_n(' for %d month', ' for %d months', $recEndCount, 'tribe-events-calendar-pro'), $recEndCount); } elseif ($recType == 'Every Year') { $text = __('Every year', 'tribe-events-calendar-pro'); $occurrence_text = sprintf(_n(' for %d year', ' for %d years', $recEndCount, 'tribe-events-calendar-pro'), $recEndCount); } elseif ($recType == 'Custom') { if ($recCustomType == 'Daily') { $text = $recCustomInterval == 1 ? __('Every day', 'tribe-events-calendar-pro') : sprintf(__('Every %d days', 'tribe-events-calendar-pro'), $recCustomInterval); $occurrence_text = sprintf(_n(', recurring %d time', ', recurring %d times', $recEndCount, 'tribe-events-calendar-pro'), $recEndCount); } elseif ($recCustomType == 'Weekly') { $text = $recCustomInterval == 1 ? __('Every week', 'tribe-events-calendar-pro') : sprintf(__('Every %d weeks', 'tribe-events-calendar-pro'), $recCustomInterval); $custom_text = sprintf(__(' on %s', 'tribe-events-calendar-pro'), self::daysToText($recCustomWeekDay)); $occurrence_text = sprintf(_n(', recurring %d time', ', recurring %d times', $recEndCount, 'tribe-events-calendar-pro'), $recEndCount); } elseif ('Monthly' == $recCustomType) { $text = $recCustomInterval == 1 ? __('Every month', 'tribe-events-calendar-pro') : sprintf(__('Every %d months', 'tribe-events-calendar-pro'), $recCustomInterval); $number_display = is_numeric($recCustomMonthNumber) ? Tribe__Events__Date_Utils::number_to_ordinal($recCustomMonthNumber) : strtolower(esc_attr__($recCustomMonthNumber, 'tribe-events-calendar-pro')); $custom_text = sprintf(__(' on the %s %s', 'tribe-events-calendar-pro'), $number_display, is_numeric($recCustomMonthNumber) ? __('day', 'tribe-events-calendar-pro') : self::daysToText($recCustomMonthDay)); $occurrence_text = sprintf(_n(', recurring %d time', ', recurring %d times', $recEndCount, 'tribe-events-calendar-pro'), $recEndCount); } elseif ($recCustomType == 'Yearly') { $text = $recCustomInterval == 1 ? __('Every year', 'tribe-events-calendar-pro') : sprintf(__('Every %d years', 'tribe-events-calendar-pro'), $recCustomInterval); $customYearNumber = $recCustomYearMonthNumber != -1 ? Tribe__Events__Date_Utils::number_to_ordinal($recCustomYearMonthNumber) : __('last', 'tribe-events-calendar-pro'); $day = $recCustomYearFilter ? $customYearNumber : Tribe__Events__Date_Utils::number_to_ordinal(date('j', strtotime($start_date))); $of_week = $recCustomYearFilter ? self::daysToText($recCustomYearMonthDay) : ''; $months = self::monthsToText($recCustomYearMonth); $custom_text = sprintf(__(' on the %s %s of %s', 'tribe-events-calendar-pro'), $day, $of_week, $months); $occurrence_text = sprintf(_n(', recurring %d time', ', recurring %d times', $recEndCount, 'tribe-events-calendar-pro'), $recEndCount); } } // end text if ($recEndType == 'On') { $endText = ' ' . sprintf(__(' until %s', 'tribe-events-calendar-pro'), date_i18n(get_option('date_format'), strtotime($recEnd))); } elseif ($recEndType == 'Never') { $endText = ''; } else { $endText = $occurrence_text; } return sprintf(__('%s%s%s', 'tribe-events-calendar-pro'), $text, $custom_text, $endText); }
/** * 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; }
/** * Gets a given occurence on a given day-of-week. * * @param int $curdate The current timestamp of an occurence. * @param int $day_of_week The index of a given day-of-week. * @param int $week_of_month The index of a given week-of-month. * * @return int The timestamp of the requested occurrence. */ private function getNthDayOfWeek($curdate, $day_of_week, $week_of_month) { if ($week_of_month == -1) { // LAST WEEK $nextdate = Tribe__Events__Date_Utils::get_last_day_of_week_in_month($curdate, $day_of_week); // If the date returned above is the same as the date we're starting from // move on to the next month by interval to consider. if ($curdate == $nextdate) { $curdate = mktime(0, 0, 0, date('n', $curdate) + $this->months_between, 1, date('Y', $curdate)); $nextdate = Tribe__Events__Date_Utils::get_last_day_of_week_in_month($curdate, $day_of_week); } return $nextdate; } else { // get the first occurrence of the requested day of the week from the requested $curdate's month $first_occurring_day_of_week = Tribe__Events__Date_Utils::get_first_day_of_week_in_month($curdate, $day_of_week); // get that day of the week in the requested nth week $maybe_date = strtotime(date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, $first_occurring_day_of_week) . ' + ' . ($week_of_month - 1) . ' weeks'); // if $maybe_date equals or is before the $curdate, then try next month // (this should only be true if $week_of_month is 1) if (date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_ONLY_FORMAT, $maybe_date) <= date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_ONLY_FORMAT, $curdate)) { // get the first day of the next month according to $this->months_between $next_month = mktime(0, 0, 0, date('n', $curdate) + $this->months_between, 1, date('Y', $curdate)); // Get the first occurrence of the requested day of the week from $next_month's month $first_occurring_day_of_week = Tribe__Events__Date_Utils::get_first_day_of_week_in_month($next_month, $day_of_week); // Get that day of the week in the requested nth week $maybe_date = strtotime(date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, $first_occurring_day_of_week) . ' + ' . ($week_of_month - 1) . ' weeks'); } // if $maybe_date doesn't have the same month as $first_occurring_day_of_week, keep incrementing by $this->months_between // until they do, but don't infinitely loop past the 'recurrenceMaxMonthsAfter' setting $i = 0; while (date('n', $maybe_date) != date('n', $first_occurring_day_of_week) && $i <= tribe_get_option('recurrenceMaxMonthsAfter', 24)) { $next_month = mktime(0, 0, 0, date('n', $first_occurring_day_of_week) + $this->months_between, 1, date('Y', $first_occurring_day_of_week)); $first_occurring_day_of_week = Tribe__Events__Date_Utils::get_first_day_of_week_in_month($next_month, $day_of_week); $maybe_date = strtotime(date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, $first_occurring_day_of_week) . ' + ' . ($week_of_month - 1) . ' weeks'); $i += $this->months_between; } return $maybe_date; } }
</option> <option value="Yearly" data-plural="<?php esc_attr_e('Year(s) on:', 'tribe-events-calendar-pro'); ?> " data-rule-segment=".custom-recurrence-years"><?php esc_html_e('Yearly', 'tribe-events-calendar-pro'); ?> </option> {{/tribe_recurrence_select}} </select> <span class="recurrence-end"> <?php esc_html_e('will not occur on', 'tribe-events-calendar-pro'); ?> <input autocomplete="off" placeholder="<?php echo esc_attr(Tribe__Events__Date_Utils::date_only(date(Tribe__Events__Date_Utils::DBDATEFORMAT))); ?> " type="text" class="tribe-datepicker custom-date" name="recurrence[exclusions][][custom][date][date]" data-field="custom-date" value="{{custom.date.date}}"/> </span> <span class="recurrence-row custom-recurrence-frequency"> <?php esc_html_e('will not occur every', 'tribe-events-calendar-pro'); ?> <input type="text" name="recurrence[exclusions][][custom][interval]" data-field="custom-interval" value="{{#if custom.interval}}{{custom.interval}}{{else}}1{{/if}}" /> <span class="recurrence-interval-type"></span> <input type="hidden" name="recurrence[exclusions][][custom][type-text]" data-field="custom-type-text" value="{{custom.[type-text]}}" /> <input type="hidden" name="recurrence[exclusions][][occurrence-count-text]" data-field="occurrence-count-text" value="<?php esc_attr_e(_x('events', 'occurence count text', 'tribe-events-calendar-pro')); ?> " /> <span class="rec-error rec-days-error"><?php
/** * Generates and returns a set of classes for the current day. * * @return string */ public static function day_classes() { $current_day = self::get_current_day(); $calendar_day = Tribe__Events__Date_Utils::date_only($current_day['date']); $today = date_i18n(Tribe__Events__Date_Utils::DBDATEFORMAT); // Start by determining which month we're looking at if ($current_day['month'] == self::CURRENT_MONTH) { $classes = 'tribe-events-thismonth'; } else { $classes = 'tribe-events-othermonth'; } // Check if the calendar day is in the past, present, or future if ($calendar_day < $today) { $classes .= ' tribe-events-past'; } elseif ($calendar_day === $today) { $classes .= ' tribe-events-present'; } elseif ($calendar_day > $today) { $classes .= ' tribe-events-future'; } // The day has some events if ($current_day['total_events'] > 0) { $classes .= ' tribe-events-has-events'; } // Needed for mobile js $day_num = str_pad($current_day['daynum'], 2, '0', STR_PAD_LEFT); $classes .= ' mobile-trigger tribe-event-day-' . date_i18n('d', $day_num); // Determine which column of the grid the day is in $column = self::$current_day - self::$current_week * 7; if ($column > 0 && ($column % 4 == 0 || $column % 5 == 0 || $column % 6 == 0)) { $classes .= ' tribe-events-right'; } return $classes; }
protected function set_end_date_time() { $this->vars['endMinuteOptions'] = Tribe__Events__View_Helpers::getMinuteOptions($this->vars['_EventEndDate']); $this->vars['endHourOptions'] = Tribe__Events__View_Helpers::getHourOptions($this->vars['_EventAllDay'] == 'yes' ? null : $this->vars['_EventEndDate']); $this->vars['endMeridianOptions'] = Tribe__Events__View_Helpers::getMeridianOptions($this->vars['_EventEndDate']); if ($this->vars['_EventEndDate']) { $end = Tribe__Events__Date_Utils::dateOnly($this->vars['_EventEndDate']); } // If we don't have a valid end date, assume today's date $this->vars['EventEndDate'] = isset($end) && $end ? $end : date('Y-m-d'); }
/** * Bump the :30 min EOD cutoff option to the next full hour * * @return void */ public function remove_30_min_eod_cutoffs() { $eod_cutoff = tribe_event_end_of_day(); if (Tribe__Events__Date_Utils::minutes_only($eod_cutoff) == '29') { $eod_cutoff = date_create('@' . (strtotime($eod_cutoff) + 1)); $eod_cutoff->modify('+30 minutes'); tribe_update_option('multiDayCutoff', $eod_cutoff->format('h:i')); } }
/** * Formatted Date * * Returns formatted date * * @category Events * @param string $date * @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) * * @return string */ function tribe_event_format_date($date, $displayTime = true, $dateFormat = '') { if (!Tribe__Events__Date_Utils::is_timestamp($date)) { $date = strtotime($date); } if ($dateFormat) { $format = $dateFormat; } else { $date_year = date('Y', $date); $cur_year = date('Y', current_time('timestamp')); // only show the year in the date if it's not in the current year $with_year = $date_year == $cur_year ? false : true; if ($displayTime) { $format = tribe_get_datetime_format($with_year); } else { $format = tribe_get_date_format($with_year); } } $date = date_i18n($format, $date); return apply_filters('tribe_event_formatted_date', $date, $displayTime, $dateFormat); }
/** * 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; }
/** * Get the timestamp of the next upcoming Nth day of month. * * @param int $curdate The current occurrence's timestamp * @param int|array $days_of_week Index(-es) of the possible day(s)-of-week the next instance may land on * @param int|array $weeks_of_month Index(-es) of the possible week(s) of the month the next instance may land on * @param int|array $months_of_year Index(-es) of the possible month(s) of the year the next instance may land on * * @return int|false The timestamp of the next occurrence on the nth day of the month or false */ private function getNthDayOfMonth($curdate, $days_of_week, $weeks_of_month, $months_of_year) { // Cast to arrays for consistency $days_of_week = (array) $days_of_week; $weeks_of_month = (array) $weeks_of_month; $months_of_year = (array) $months_of_year; // Obtain the hour, minute and second of $curdate for later comparison $cur_hour = (int) date('G', $curdate); $cur_minute = (int) date('i', $curdate); $cur_second = (int) date('s', $curdate); // Sort and rotate the arrays to give us a sensible starting point $this->sort_and_rotate_int_array($days_of_week, (int) date('N', $curdate)); $this->sort_and_rotate_int_array($months_of_year, (int) date('n', $curdate)); sort($weeks_of_month); $weeks_of_month = array_map('intval', $weeks_of_month); // The next occurence must take place this year or the next applicable year $year = (int) date('Y', $curdate); $years = array($year, $year + $this->years_between); // Examine each possible year and month foreach ($years as $year) { foreach ($months_of_year as $month) { // If we are behind $curdate's month and year then keep advancing if ($year <= date('Y', $curdate) && $month < date('n', $curdate)) { continue; } foreach ($weeks_of_month as $nth_week) { foreach ($days_of_week as $day) { // Determine the date of the first of these days (ie, the date of the first Tuesday this month) $start_of_month = mktime(0, 0, 0, $month, 1, $year); $first_date = Tribe__Events__Date_Utils::get_first_day_of_week_in_month($start_of_month, $day); $day_of_month = (int) date('j', $first_date); // Add the relevant number of weeks $day_of_month += $nth_week * 7 - 7; // Form a timestamp representing this day of the week in the appropriate week of the month $timestamp = mktime($cur_hour, $cur_minute, $cur_second, $month, $day_of_month, $year); // If we got a valid timestamp that is ahead of $curdate, we have a winner if ($timestamp && $timestamp > $curdate) { return $timestamp; } } } } } // No match? return false; }
/** * Update event recurrence when a recurring event is saved * * @param integer $event_id id of the event to update * @param array $data data defining the recurrence of this event * * @return void */ public static function updateRecurrenceMeta($event_id, $data) { if (!isset($data['recurrence'])) { return; } $recurrence_meta = array('rules' => array(), 'exclusions' => array()); $datepicker_format = Tribe__Events__Date_Utils::datepicker_formats(tribe_get_option('datepickerFormat')); if (!empty($data['recurrence'])) { if (isset($data['recurrence']['recurrence-description'])) { unset($data['recurrence']['recurrence-description']); } foreach (array('rules', 'exclusions') as $rule_type) { if (!isset($data['recurrence'][$rule_type])) { continue; } //end if foreach ($data['recurrence'][$rule_type] as $key => &$recurrence) { if (!$recurrence) { continue; } // Ignore the rule if the type isn't set OR the type is set to 'None' // (we're not interested in exclusions here) if ((empty($recurrence['type']) || 'None' === $recurrence['type']) && $rule_type !== 'exclusions') { continue; } if (empty($recurrence['type']) && empty($recurrence['custom']['type']) || 'None' === $recurrence['custom']['type']) { unset($data['recurrence'][$rule_type][$key]); continue; } unset($recurrence['occurrence-count-text'], $recurrence['custom']['type-text']); if (!empty($recurrence['end'])) { $recurrence['end'] = Tribe__Events__Date_Utils::datetime_from_format($datepicker_format, $recurrence['end']); } // if this isn't an exclusion and it isn't a Custom rule, then we don't need the custom array index if ('rules' === $rule_type && 'Custom' !== $recurrence['type']) { unset($recurrence['custom']); } else { $custom_types = array('date', 'day', 'week', 'month', 'year'); $custom_type_key = self::custom_type_to_key($recurrence['custom']['type']); // clean up extraneous array elements foreach ($custom_types as $type) { if ($type === $custom_type_key) { continue; } if (!isset($recurrence['custom'][$type])) { continue; } unset($recurrence['custom'][$type]); } } //end else $recurrence['EventStartDate'] = $data['EventStartDate']; $recurrence['EventEndDate'] = $data['EventEndDate']; if (self::isRecurrenceValid($event_id, $recurrence)) { $recurrence_meta[$rule_type][] = $recurrence; } } } } //end if $updated = update_post_meta($event_id, '_EventRecurrence', $recurrence_meta); self::saveEvents($event_id, $updated); }
public function setup_list($template_file) { if (basename(dirname($template_file)) . '/' . basename($template_file) == 'mini-calendar/list.php') { if ($this->args['count'] == 0) { return; } // make sure the widget taxonomy filter setting is respected add_action('pre_get_posts', array($this, 'set_count'), 1000); global $wp_query; $post_status = array('publish'); if (is_user_logged_in()) { $post_status[] = 'private'; } // hijack the main query to load the events via provided $args if (!is_null($this->args)) { $query_args = array('posts_per_page' => $this->args['count'], 'tax_query' => $this->args['tax_query'], 'eventDisplay' => 'custom', 'start_date' => $this->get_month(), 'post_status' => $post_status, 'is_tribe_widget' => true); // set end date if initial load, or ajax month switch if (!defined('DOING_AJAX') || defined('DOING_AJAX') && $_POST['action'] == 'tribe-mini-cal') { $query_args['end_date'] = substr_replace($this->get_month(Tribe__Events__Date_Utils::DBDATEFORMAT), Tribe__Events__Date_Utils::get_last_day_of_month(strtotime($this->get_month())), -2); // @todo use tribe_events_end_of_day() ? $query_args['end_date'] = tribe_event_end_of_day($query_args['end_date']); } $wp_query = Tribe__Events__Query::getEvents($query_args, true); } } }
/** * 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) { $tec = Tribe__Events__Main::instance(); if (isset($data['EventAllDay'])) { if (Tribe__Events__Date_Utils::is_all_day($data['EventAllDay'])) { $data['EventAllDay'] = 'yes'; } else { $data['EventAllDay'] = 'no'; } } //end if if (isset($data['EventAllDay']) && ('yes' === $data['EventAllDay'] || !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(Tribe__Events__Date_Utils::DBDATETIMEFORMAT, strtotime($data['EventStartDate'] . " " . $data['EventStartHour'] . ":" . $data['EventStartMinute'] . ":00 " . $data['EventStartMeridian'])); $data['EventEndDate'] = date(Tribe__Events__Date_Utils::DBDATETIMEFORMAT, strtotime($data['EventEndDate'] . " " . $data['EventEndHour'] . ":" . $data['EventEndMinute'] . ":00 " . $data['EventEndMeridian'])); } else { $data['EventStartDate'] = date(Tribe__Events__Date_Utils::DBDATETIMEFORMAT, strtotime($data['EventStartDate'] . " " . $data['EventStartHour'] . ":" . $data['EventStartMinute'] . ":00")); $data['EventEndDate'] = date(Tribe__Events__Date_Utils::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'] = Tribe__Events__API::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'] = Tribe__Events__API::saveEventVenue($data["Venue"], $event, $venue_post_status); } // Ordinarily there is a single cost value for each event, but addons (ie, ticketing plugins) may need // to record a number of different pricepoints for the same event $event_cost = isset($data['EventCost']) ? (array) $data['EventCost'] : array(); $data['EventCost'] = (array) apply_filters('tribe_events_event_costs', $event_cost, $event_id); do_action('tribe_events_event_save', $event_id); //update meta fields foreach ($tec->metaTags as $tag) { $htmlElement = ltrim($tag, '_'); if (isset($data[$htmlElement]) && $tag != Tribe__Events__Main::EVENTSERROROPT) { if (is_string($data[$htmlElement])) { $data[$htmlElement] = filter_var($data[$htmlElement], FILTER_SANITIZE_STRING); } // Fields with multiple values per key if (is_array($data[$htmlElement])) { delete_post_meta($event_id, $tag); foreach ($data[$htmlElement] as $value) { add_post_meta($event_id, $tag, $value); } } else { 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); }