コード例 #1
0
ファイル: dates.php プロジェクト: rair/yacs
 /**
  * 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;
 }
コード例 #2
0
ファイル: day.php プロジェクト: rair/yacs
        $cache_id = 'dates/day.php#text#' . $target;
        if (!($text = Cache::get($cache_id))) {
            // draw one day
            if ($items = Dates::list_for_day($year, $month, $day, 'decorated')) {
                $text .= Skin::build_list($items, 'decorated');
            } else {
                $text .= '<p>' . i18n::s('Nothing has been recorded for this date.') . '</p>';
            }
            // robots cannot navigate
            if (!Surfer::is_crawler()) {
                // previous day
                $previous = gmstrftime('%Y/%m/%d', gmmktime(0, 0, 0, $month, $day - 1, $year));
                // next day
                $next = gmstrftime('%Y/%m/%d', gmmktime(0, 0, 0, $month, $day + 1, $year));
                // neighbours
                $neighbours = array(Dates::get_url($previous, 'day'), Skin::build_date($previous, 'standalone'), Dates::get_url($next, 'day'), Skin::build_date($next, 'standalone'), Dates::get_url($year . '/' . $month, 'month'), Dates::get_month_label($year . '/' . $month));
                // links to display previous and next days
                $text .= Skin::neighbours($neighbours, 'slideshow');
            }
            // cache, whatever change, for 1 minute
            Cache::put($cache_id, $text, 'stable', 60);
        }
        // in the main panel
        $context['text'] .= $text;
    }
}
// side bar with the list of most recent pages
$cache_id = 'dates/day.php#extra';
if (!($text = Cache::get($cache_id))) {
    if ($items =& Articles::list_by('publication', 0, COMPACT_LIST_SIZE, 'compact')) {
        $text =& Skin::build_box(i18n::s('Recent pages'), Skin::build_list($items, 'compact'), 'boxes');
コード例 #3
0
ファイル: month.php プロジェクト: rair/yacs
    // no more than two years difference with now
    if (abs(mktime(0, 0, 0, $month, 1, $year) - time()) > 31536000 * 2) {
        Safe::header('Status: 401 Unauthorized', TRUE, 401);
        Logger::error(i18n::s('You are not allowed to perform this operation.'));
    } else {
        // page main content
        $cache_id = 'dates/month.php#text#' . $target;
        if (!($text = Cache::get($cache_id))) {
            // robots cannot navigate
            if (!Surfer::is_crawler()) {
                // previous month
                $previous = gmstrftime('%Y/%m', gmmktime(0, 0, 0, $month - 1, 1, $year));
                // next month
                $next = gmstrftime('%Y/%m', gmmktime(0, 0, 0, $month + 1, 1, $year));
                // neighbours
                $neighbours = array(Dates::get_url($previous, 'month'), Dates::get_month_label($previous), Dates::get_url($next, 'month'), Dates::get_month_label($next), Dates::get_url($year, 'year'), $year);
                // links to display previous and next months
                $text .= Skin::neighbours($neighbours, 'slideshow');
            }
            // get items for this month
            $items =& Dates::list_for_month($year, $month, 'links');
            // draw one month - force an empty month
            $text .= Dates::build_months($items, FALSE, FALSE, TRUE, FALSE, $year, $month);
            // cache, whatever change, for 5 minutes
            Cache::put($cache_id, $text, 'stable', 300);
        }
        $context['text'] .= $text;
    }
}
// page extra content
$cache_id = 'dates/month.php#extra';