/** * Responsible for displaying a user's custom recurrence pattern description. * * @deprecated since 3.6 * @param string $meta_id The meta group this is in. * @return string The custom description. * @author Timothy Wood * @since 3.0 */ public static function custom_recurrence_description($meta_id) { global $_tribe_meta_factory; $post_id = get_the_ID(); $recurrence_meta = TribeEventsRecurrenceMeta::getRecurrenceMeta($post_id); $recurrence_description = !empty($recurrence_meta['recCustomRecurrenceDescription']) ? $recurrence_meta['recCustomRecurrenceDescription'] : tribe_get_recurrence_text($post_id); $html = tribe_is_recurring_event($post_id) ? Tribe_Meta_Factory::template($_tribe_meta_factory->meta[$meta_id]['label'], $recurrence_description, $meta_id) : ''; return apply_filters('tribe_event_pro_meta_custom_recurrence_description', $html); }
/** * 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($postId = null) { $text = ""; $custom_text = ""; $occurrence_text = ""; if ($postId == null) { global $post; $postId = $post->ID; } extract(TribeEventsRecurrenceMeta::getRecurrenceMeta($postId)); 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 = ""; } else { if ($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); } else { if ($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); } else { if ($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); } else { if ($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); } else { if ($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); } else { if ($recCustomType == "Monthly") { $text = $recCustomInterval == 1 ? __("Every month", 'tribe-events-calendar-pro') : sprintf(__("Every %d months", 'tribe-events-calendar-pro'), $recCustomInterval); $number_display = is_numeric($recCustomMonthNumber) ? TribeDateUtils::numberToOrdinal($recCustomMonthNumber) : strtolower($recCustomMonthNumber); $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); } else { if ($recCustomType == "Yearly") { $text = $recCustomInterval == 1 ? __("Every year", 'tribe-events-calendar-pro') : sprintf(__("Every %d years", 'tribe-events-calendar-pro'), $recCustomInterval); $customYearNumber = $recCustomYearMonthNumber != -1 ? TribeDateUtils::numberToOrdinal($recCustomYearMonthNumber) : __("last", 'tribe-events-calendar-pro'); $day = $recCustomYearFilter ? $customYearNumber : TribeDateUtils::numberToOrdinal(date('j', strtotime(TribeEvents::getRealStartDate($postId)))); $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))); } else { $endText = $occurrence_text; } return sprintf(__('%s%s%s', 'tribe-events-calendar-pro'), $text, $custom_text, $endText); }
* Override this template in your own theme by creating a file at * [your-theme]/tribe-events/community/modules/recurrence.php * * @package TribeCommunityEvents * @since 2.1 * @author Modern Tribe Inc. * */ if (!defined('ABSPATH')) { die('-1'); } global $post; $post_id = isset($post->ID) ? $post->ID : null; if ($post_id) { // convert array to variables that can be used in the view extract(TribeEventsRecurrenceMeta::getRecurrenceMeta($post_id)); } else { // create variables that can be used in the view $recType = 'None'; $recEndType = ''; $recEnd = ''; $recEndCount = ''; $recCustomType = ''; $recCustomInterval = ''; $recCustomTypeText = ''; $recOccurrenceCountText = ''; $recCustomWeekDay = array(); //array $recCustomMonthNumber = ''; $recCustomMonthDay = 1; $recCustomYearFilter = '';
/** * Get the recurrence pattern in text format by post id. * * @param int $postId The post id. * * @return sting The human readable string. */ public static function recurrenceToTextByPost($postId = null) { if ($postId == null) { global $post; $postId = $post->ID; } $recurrence_rules = TribeEventsRecurrenceMeta::getRecurrenceMeta($postId); $start_date = TribeEvents::get_series_start_date($postId); $output_text = empty($recurrence_rules['recCustomRecurrenceDescription']) ? self::recurrenceToText($recurrence_rules, $start_date) : $recurrence_rules['recCustomRecurrenceDescription']; return $output_text; }
/** * Checks the recurrence amount and adds a filter to display an errir if it is not correct. * * @since 3.0 * @author Paul Hughes * * @param int $post_id The post id. * @return void */ public function checkRecurrenceAmount($post_id) { $is_success = true; if (get_post_type($post_id) == TribeEvents::POSTTYPE && get_post_meta($post_id, '_EventRecurrence')) { extract(TribeEventsRecurrenceMeta::getRecurrenceMeta($post_id)); $rules = TribeEventsRecurrenceMeta::getSeriesRules($post_id); // use the recurrence start meta if necessary because we can't guarantee which order the start date will come back in $recStart = strtotime(get_post_meta($post_id, '_EventStartDate', true)); $eventEnd = strtotime(get_post_meta($post_id, '_EventEndDate', true)); $duration = $eventEnd - $recStart; $recEnd = $recEndType == "On" ? strtotime(TribeDateUtils::endOfDay($recEnd)) : $recEndCount - 1; // subtract one because event is first occurrence $old_start_dates = get_post_meta($post_id, '_EventStartDate'); if ($recType != "None") { $recurrence = new TribeRecurrence($recStart, $recEnd, $rules, $recEndType == "After", get_post($post_id)); $dates = (array) $recurrence->getDates(true, $old_start_dates); $max_recurrences = apply_filters('tribe_events_max_recurrences', 199); if (count($dates) > $max_recurrences) { add_filter('redirect_post_location', array(__CLASS__, 'tooManyRecurrencesError')); $is_success = false; } } } return $is_success; }