/**
  * 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);
 }
 public function addDateToRecurringEvents($permalink, $post)
 {
     if (function_exists('tribe_is_recurring_event') && $post->post_type == self::POSTTYPE && tribe_is_recurring_event($post->ID) && !is_search()) {
         if (is_admin() && (!isset($post->EventStartDate) || !$post->EventStartDate)) {
             if (isset($_REQUEST['eventDate'])) {
                 $post->EventStartDate = $_REQUEST['eventDate'];
             } else {
                 $post->EventStartDate = TribeEvents::getRealStartDate($post->ID);
             }
         }
         // prevent any call from outside the tribe from appending bad date on the end of recurring permalinks (looking at Yoast WP SEO)
         if (!isset($post->EventStartDate) || !$post->EventStartDate) {
             return $permalink;
         }
         if ('' == get_option('permalink_structure')) {
             return add_query_arg('eventDate', TribeDateUtils::dateOnly($post->EventStartDate), $permalink);
         } else {
             return trailingslashit($permalink) . TribeDateUtils::dateOnly(isset($post->EventStartDate) ? $post->EventStartDate : null);
         }
     }
     return $permalink;
 }
 /**
  * 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::getRealStartDate($postId);
     $output_text = empty($recurrence_rules['recCustomRecurrenceDescription']) ? self::recurrenceToText($recurrence_rules, $start_date) : $recurrence_rules['recCustomRecurrenceDescription'];
     return $output_text;
 }