/**
 * Fetch a friendly repetition value for a specific event (Repeats every x months etc)
 *
 * @param array The array of the event
 * @return string The friendly repetition string
 */
function fetch_friendly_repetition($event)
{
    global $lang;
    $monthnames = array("offset", $lang->month_1, $lang->month_2, $lang->month_3, $lang->month_4, $lang->month_5, $lang->month_6, $lang->month_7, $lang->month_8, $lang->month_9, $lang->month_10, $lang->month_11, $lang->month_12);
    if (!is_array($event['repeats'])) {
        $event['repeats'] = my_unserialize($event['repeats']);
        if (!is_array($event['repeats'])) {
            return false;
        }
    }
    $repeats = $event['repeats'];
    switch ($repeats) {
        case 1:
            if ($repeats['days'] <= 1) {
                return $lang->repeats_every_day;
            }
            return $lang->sprintf($lang->repeats_every_x_days, $event['repeats']['days']);
            break;
        case 2:
            return $lang->repeats_on_weekdays;
            break;
        case 3:
            if ($event['repeats']['days'] || count($event['repeats']['days']) == 7) {
                $weekdays = null;
                foreach ($event['repeats']['days'] as $id => $weekday) {
                    $weekday_name = fetch_weekday_name($weekday);
                    if ($event['repeats']['days'][$id + 1] && $weekday) {
                        $weekdays .= $lang->comma;
                    } else {
                        if (!$event['repeats']['days'][$id + 1] && $weekday) {
                            $weekdays .= " {$lang->and} ";
                        }
                    }
                    $weekdays .= $weekday_name;
                }
            }
            if ($event['repeats']['weeks'] == 1) {
                if ($weekdays) {
                    return $lang->sprintf($lang->every_week_on_days, $weekdays);
                } else {
                    return $lang->sprintf($lang->every_week);
                }
            } else {
                if ($weekdays) {
                    return $lang->sprintf($lang->every_x_weeks_on_days, $event['repeats']['weeks'], $weekdays);
                } else {
                    return $lang->sprintf($lang->every_x_weeks, $event['repeats']['weeks']);
                }
            }
            break;
        case 4:
            if ($event['repeats']['day']) {
                if ($event['repeats']['months'] == 1) {
                    return $lang->sprintf($lang->every_month_on_day, $event['repeats']['day']);
                } else {
                    return $lang->sprintf($lang->every_x_months_on_day, $event['repeats']['day'], $event['repeats']['months']);
                }
            } else {
                $weekday_name = fetch_weekday_name($event['repeats']['weekday']);
                $occurance = "weekday_occurance_" . $event['repeats']['occurance'];
                $occurance = $lang->{$occurance};
                if ($event['repeats']['months'] == 1) {
                    return $lang->sprintf($lang->every_month_on_weekday, $occurance, $weekday_name);
                } else {
                    return $lang->sprintf($lang->every_x_months_on_weekday, $occurance, $weekday_name, $event['repeats']['months']);
                }
            }
            break;
        case 5:
            $month = $monthnames[$event['repeats']['month']];
            if ($event['repeats']['day']) {
                if ($event['repeats']['years'] == 1) {
                    return $lang->sprintf($lang->every_year_on_day, $event['repeats']['day'], $month);
                } else {
                    return $lang->sprintf($lang->every_x_years_on_day, $event['repeats']['day'], $month, $event['repeats']['years']);
                }
            } else {
                $weekday_name = fetch_weekday_name($event['repeats']['weekday']);
                $occurance = "weekday_occurance_" . $event['repeats']['occurance'];
                $occurance = $lang->{$occurance};
                if ($event['repeats']['years'] == 1) {
                    return $lang->sprintf($lang->every_year_on_weekday, $occurance, $weekday_name, $month);
                } else {
                    return $lang->sprintf($lang->every_x_year_on_weekday, $occurance, $weekday_name, $month, $event['repeats']['years']);
                }
            }
            break;
    }
}
Beispiel #2
0
 if ($next_days > 0) {
     $end_timestamp = gmmktime(23, 59, 59, $next_month['month'], $next_days, $next_month['year']);
 } else {
     // We don't need days from the next month
     $end_timestamp = gmmktime(23, 59, 59, $month, $num_days, $year);
 }
 $events_cache = get_events($calendar, $start_timestamp, $end_timestamp, $calendar_permissions['canmoderateevents']);
 // Fetch birthdays
 if ($calendar['showbirthdays']) {
     $bday_months = array($month, $prev_month['month'], $next_month['month']);
     $birthdays = get_birthdays($bday_months);
 }
 $today = my_date("dnY");
 // Build weekday headers
 foreach ($weekdays as $weekday) {
     $weekday_name = fetch_weekday_name($weekday);
     eval("\$weekday_headers .= \"" . $templates->get("calendar_weekdayheader") . "\";");
 }
 for ($row = 0; $row < 6; ++$row) {
     foreach ($weekdays as $weekday_id => $weekday) {
         // Current month always starts on 1st row
         if ($row == 0 && $day == $calendar['startofweek'] + 1) {
             $in_month = 1;
             $calendar_month = $month;
             $calendar_year = $year;
         } else {
             if ($calendar_month == $prev_month['month'] && $day > $prev_month_days) {
                 $day = 1;
                 $in_month = 1;
                 $calendar_month = $month;
                 $calendar_year = $year;