/** * produce monthly views for provided items * * @parameter array of $url => ($prefix, $label, $suffix, $type, $icon, $date) * @parameter boolean if TRUE, add links to yearly and monthly views * @parameter boolean if FALSE, do no display month caption * @parameter boolean if FALSE, do not label days in week * @parameter boolean if TRUE, display day content below the calendar * @parameter int forced year, in case no dates are provided * @parameter int forced month, in case no dates are provided * @return a string to be put in the web page */ public static function &build_months($dates, $with_zoom = FALSE, $with_caption = TRUE, $with_headers = TRUE, $compact = FALSE, $forced_year = NULL, $forced_month = NULL, $style = "month calendar") { global $context; // we return some text $text = ''; // nothing done yet $current_year = $current_month = $current_day = NULL; $day_content = array(); // day details static $day_panel_index; if (!isset($day_panel_index)) { $day_panel_index = 1; } $day_panel_id = 'day_panel_' . $day_panel_index++; // process all dates foreach ($dates as $date_link => $date_attributes) { // look at this date list($prefix, $label, $suffix, $type, $icon, $date) = $date_attributes; $year = intval(substr($date, 0, 4)); $month = intval(substr($date, 5, 2)); $day = intval(substr($date, 8, 2)); // flush previous day, if any if ($day_content && ($day != $current_day || $month != $current_month || $year != $current_year)) { $text .= '<td class="spot">' . Dates::build_day($current_day, $day_content, $day_panel_id, $compact) . '</td>'; $current_day++; if (++$day_in_week >= W_END_DAY) { $day_in_week = W_START_DAY; $text .= '</tr><tr>'; } $day_content = array(); } // use the image as a link to the target page if ($icon) { // fix relative path if (!preg_match('/^(\\/|http:|https:|ftp:)/', $icon)) { $icon = $context['url_to_root'] . $icon; } // build the complete HTML element $icon = Skin::build_link($date_link, '<img src="' . $icon . '" alt="" title="' . encode_field($label) . '" />', 'overlaid') . BR; } // content for this date $day_content[] = $icon . $prefix . Skin::build_link($date_link, $label, 'overlaid') . $suffix; // close current month if ($current_month && $month != $current_month) { $text .= Dates::build_month_suffix($current_year, $current_month, $current_day); } // move to month for this date while (!$current_year && !$current_month && !$current_day || $month != $current_month) { if (!$current_month) { $current_year = $year; $current_month = $month; } else { if (++$current_month > 12) { $current_year++; $current_month = 1; } } // add a caption $title = ''; if ($with_caption) { // month title $title = ucfirst(Dates::get_month_label($current_month)) . ' ' . $current_year; // zoom to the monthly view if ($with_zoom) { $title = Skin::build_link(Dates::get_url($current_year . '/' . $current_month, 'month'), $title, 'month'); } } // first day of this month $first_of_month = gmmktime(0, 0, 0, $month, 1, $year); // day in week for the first day of the month //$day_in_week = (int)gmstrftime(STRFTIME_FORMAT, $first_of_month); $day_in_week = gmstrftime(STRFTIME_FORMAT, $first_of_month); $day_in_week = Dates::day2num($day_in_week); // start a new month $current_day = 1; $text .= Dates::build_month_prefix($current_year, $current_month, $day_in_week, $style, $title, $with_headers); // not yet at the target month, close an empty month if ($month != $current_month) { $text .= Dates::build_month_suffix($current_year, $current_month, $current_day); } } // fill in gaps while ($current_day < $day) { $text .= '<td>' . $current_day++ . '</td>'; // start a new week on next row if (++$day_in_week >= W_END_DAY) { $day_in_week = W_START_DAY; $text .= '</tr><tr>'; } } } // flush previous day if ($day_content) { $text .= '<td class="spot">' . Dates::build_day($current_day++, $day_content, $day_panel_id, $compact) . '</td>'; } // close last month, if any if ($current_month) { $text .= Dates::build_month_suffix($current_year, $current_month, $current_day); } // draw an empty calendar, if required if (!$text && $forced_year) { // one single month if ($forced_month > 0) { // add a caption $title = ''; if ($with_caption) { // month title $title = ucfirst(Dates::get_month_label($forced_month)) . ' ' . $forced_year; // zoom to the monthly view if ($with_zoom) { $title = Skin::build_link(Dates::get_url($forced_year . '/' . $forced_month, 'month'), $title, 'month'); } } $text .= Dates::build_month_prefix($forced_year, $forced_month, -1, $style, $title, $with_headers) . Dates::build_month_suffix($forced_year, $forced_month, 1); } } // empty rows are not allowed $text = str_replace('<tr></tr>', '', $text); // an area to display date details $text .= '<div id="' . $day_panel_id . '" class="day_panel" ></div>'; // done return $text; }