Пример #1
0
/**
 * Build a mini calendar for a specific month
 *
 * @param array The calendar array for the calendar
 * @param int The month of the year
 * @param int The year
 * @param array Optional events cache for this calendar
 * @return string The built mini calendar
 */
function build_mini_calendar($calendar, $month, $year, &$events_cache)
{
    global $events_cache, $mybb, $templates, $theme, $monthnames;
    // Incoming month/year?
    if (!$year || $year > my_date("Y") + 5) {
        $year = my_date("Y");
    }
    // Then the month
    if ($month < 1 || $month > 12) {
        $month = my_date("n");
    }
    $weekdays = fetch_weekday_structure($calendar['startofweek']);
    $calendar_permissions = get_calendar_permissions($calendar['cid']);
    $month_link = get_calendar_link($calendar['cid'], $year, $month);
    $next_month = get_next_month($month, $year);
    $prev_month = get_prev_month($month, $year);
    $month_start_weekday = gmdate("w", gmmktime(0, 0, 0, $month, $calendar['startofweek'] + 1, $year));
    if ($month_start_weekday != $weekdays[0] || $calendar['startofweek'] != 0) {
        $day = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
        $day -= array_search($month_start_weekday, $weekdays);
        $day += $calendar['startofweek'] + 1;
        $calendar_month = $prev_month['month'];
        $calendar_year = $prev_month['year'];
        if ($day > 31 && $calendar['startofweek'] == 1 && $prev_month_days == 30) {
            // We need to fix it for these days
            $day = 25;
        }
    } else {
        $day = $calendar['startofweek'] + 1;
        $calendar_month = $month;
        $calendar_year = $year;
    }
    $prev_month_days = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
    // So now we fetch events for this month
    $start_timestamp = gmmktime(0, 0, 0, $calendar_month, $day, $year);
    $num_days = gmdate("t", gmmktime(0, 0, 0, $month, 1, $year));
    $end_timestamp = gmmktime(23, 59, 59, $month, $num_days, $year);
    if (!$events_cache) {
        $events_cache = get_events($calendar, $start_timestamp, $end_timestamp, $calendar_permissions['canmoderateevents']);
    }
    $today = my_date("dnY");
    // Build weekday headers
    $weekday_headers = '';
    foreach ($weekdays as $weekday) {
        $weekday_name = fetch_weekday_name($weekday, true);
        eval("\$weekday_headers .= \"" . $templates->get("calendar_mini_weekdayheader") . "\";");
    }
    $in_month = 0;
    $day_bits = $calendar_rows = '';
    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;
                } else {
                    if ($day > $num_days && $calendar_month != $prev_month['month']) {
                        $in_month = 0;
                        $calendar_month = $next_month['month'];
                        $calendar_year = $next_month['year'];
                        $day = 1;
                        if ($calendar_month == $month) {
                            $in_month = 1;
                        }
                    }
                }
            }
            if ($weekday_id == 0) {
                $week_stamp = gmmktime(0, 0, 0, $calendar_month, $day, $calendar_year);
                $week_link = get_calendar_week_link($calendar['cid'], $week_stamp);
            }
            if ($weekday_id == 0 && $calendar_month == $next_month['month']) {
                break;
            }
            $link_to_day = false;
            // Any events on this specific day?
            if (@count($events_cache["{$day}-{$calendar_month}-{$calendar_year}"]) > 0) {
                $link_to_day = true;
            }
            // Is the current day
            if ($day . $calendar_month . $year == $today && $month == $calendar_month) {
                $day_class = "trow_sep";
            } else {
                if ($in_month == 0) {
                    $day_class = "trow1";
                } else {
                    $day_class = "trow2";
                }
            }
            if ($link_to_day) {
                $day_link = "<a href=\"" . get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day) . "\">{$day}</a>";
            } else {
                $day_link = $day;
            }
            eval("\$day_bits .= \"" . $templates->get("calendar_mini_weekrow_day") . "\";");
            ++$day;
        }
        if ($day_bits) {
            eval("\$calendar_rows .= \"" . $templates->get("calendar_mini_weekrow") . "\";");
        }
        $day_bits = "";
    }
    eval("\$mini_calendar = \"" . $templates->get("calendar_mini") . "\";");
    return $mini_calendar;
}
Пример #2
0
 // Incoming month/year?
 if ($mybb->input['year'] && $mybb->input['year'] <= my_date("Y") + 5) {
     $year = intval($mybb->input['year']);
 } else {
     $year = my_date("Y");
 }
 // Then the month
 if ($mybb->input['month'] >= 1 && $mybb->input['month'] <= 12) {
     $month = intval($mybb->input['month']);
 } else {
     $month = my_date("n");
 }
 add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid']));
 add_breadcrumb("{$monthnames[$month]} {$year}", get_calendar_link($calendar['cid'], $year, $month));
 $next_month = get_next_month($month, $year);
 $prev_month = get_prev_month($month, $year);
 $prev_link = get_calendar_link($calendar['cid'], $prev_month['year'], $prev_month['month']);
 $next_link = get_calendar_link($calendar['cid'], $next_month['year'], $next_month['month']);
 // Start constructing the calendar
 $weekdays = fetch_weekday_structure($calendar['startofweek']);
 $month_start_weekday = gmdate("w", gmmktime(0, 0, 0, $month, $calendar['startofweek'] + 1, $year));
 $prev_month_days = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
 // This is if we have days in the previous month to show
 if ($month_start_weekday != $weekdays[0] || $calendar['startofweek'] != 0) {
     $prev_days = $day = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
     $day -= array_search($month_start_weekday, $weekdays);
     $day += $calendar['startofweek'] + 1;
     if ($day > $prev_month_days + 1) {
         // Go one week back
         $day -= 7;
     }