/** * render a calendar * * The provided anchor can reference: * - a section 'section:123' * - nothing * * @param string the anchor (e.g. 'section:123') * @return string the rendered text **/ public function render($matches) { global $context; $anchor = count($matches) ? $matches[0] : ''; // a list of dates include_once $context['path_to_root'] . 'dates/dates.php'; // get records if ($anchor && strpos($anchor, 'section:') === 0) { $items = Dates::list_for_prefix(NULL, 'compact', trim($anchor)); } else { $items = Dates::list_for_prefix(NULL, 'compact', NULL); } // build calendar for current month $text = Dates::build_months($items, FALSE, TRUE, FALSE, TRUE, gmstrftime('%Y'), gmstrftime('%m'), 'compact calendar'); // job done return $text; }
/** * list dates at some anchor * * @param string type of replaced items (e.g., 'articles') * @param string the anchor to consider (e.g., 'section:123') * @param int page index * @return string to be inserted in resulting web page, or NULL */ function render($type, $anchor, $page = 1) { global $context; // instead of articles if ($type != 'articles') { return NULL; } // get the containing page $container = Anchors::get($anchor); // handle dates include_once $context['path_to_root'] . 'dates/dates.php'; // the maximum number of articles per page if (!defined('DATES_PER_PAGE')) { define('DATES_PER_PAGE', 50); } // where we are $offset = ($page - 1) * DATES_PER_PAGE; // should we display all dates, or not? $with_past_dates = FALSE; if (preg_match('/\\bwith_past_dates\\b/i', $this->attributes['overlay_parameters'])) { $with_past_dates = TRUE; } // menu to be displayed at the top $menu = array(); // empowered users can contribute if (Articles::allow_creation(NULL, $container)) { Skin::define_img('ARTICLES_ADD_IMG', 'articles/add.gif'); $menu[] = '<div style="display: inline">' . Skin::build_link('articles/edit.php?anchor=' . urlencode($anchor), ARTICLES_ADD_IMG . i18n::s('Add an event'), 'span') . '</div>'; } // ensure access to past dates if (!$with_past_dates && ($items = Dates::list_past_for_anchor($anchor, $offset, DATES_PER_PAGE, 'compact'))) { // turn an array to a string if (is_array($items)) { $items =& Skin::build_list($items, 'compact'); } // navigation bar $bar = array(); // count the number of dates in this section $stats = Dates::stat_past_for_anchor($anchor); if ($stats['count'] > DATES_PER_PAGE) { $bar = array_merge($bar, array('_count' => sprintf(i18n::ns('%d date', '%d dates', $stats['count']), $stats['count']))); } // navigation commands for dates if ($section = Sections::get(str_replace('section:', '', $anchor))) { $home = Sections::get_permalink($section); $prefix = Sections::get_url($section['id'], 'navigate', 'articles'); $bar = array_merge($bar, Skin::navigate($home, $prefix, $stats['count'], DATES_PER_PAGE, $page)); } // display the bar if (is_array($bar)) { $items = Skin::build_list($bar, 'menu_bar') . $items; } // in a separate box $menu[] = Skin::build_sliding_box(i18n::s('Past dates'), $items, 'past_dates', TRUE); } // menu displayed towards the top of the page $text = Skin::finalize_list($menu, 'menu_bar'); // build a list of events if (preg_match('/\\blayout_as_list\\b/i', $this->attributes['overlay_parameters'])) { // list all dates if ($with_past_dates) { // navigation bar $bar = array(); // count the number of dates in this section $stats = Dates::stat_for_anchor($anchor); if ($stats['count'] > DATES_PER_PAGE) { $bar = array_merge($bar, array('_count' => sprintf(i18n::ns('%d date', '%d dates', $stats['count']), $stats['count']))); } // navigation commands for dates $section = Sections::get($anchor); $home = Sections::get_permalink($section); $prefix = Sections::get_url($section['id'], 'navigate', 'articles'); $bar = array_merge($bar, Skin::navigate($home, $prefix, $stats['count'], DATES_PER_PAGE, $page)); // display the bar if (count($bar)) { $text .= Skin::build_list($bar, 'menu_bar'); } // list one page of dates if ($items = Dates::list_for_anchor($anchor, $offset, DATES_PER_PAGE, 'family')) { $text .= $items; } // display only future dates to regular surfers } else { // show future dates on first page if ($page == 1 && ($items = Dates::list_future_for_anchor($anchor, 0, 500, 'family', TRUE))) { $text .= $items; } } // deliver a calendar view for current month, plus months around } else { // show past dates as well if ($with_past_dates) { $items = Dates::list_for_anchor($anchor, 0, 500, 'links'); } else { $items = Dates::list_future_for_anchor($anchor, 0, 500, 'links', TRUE); } // layout all these dates if ($items) { $text .= Dates::build_months($items); } } // integrate this into the page return $text; }
include_once 'dates.php'; // load the skin load_skin('dates'); // the title of the page $context['page_title'] = i18n::s('Dates'); // count dates in the database $stats = Dates::stat(); if ($stats['count']) { $context['page_menu'] += array('_count' => sprintf(i18n::ns('%d date', '%d dates', $stats['count']), $stats['count'])); } // page main content $cache_id = 'dates/index.php#text'; if (!($text = Cache::get($cache_id))) { // get and draw upcoming events with links to global calendars if ($items =& Dates::list_future(0, 200, 'links')) { $text = Dates::build_months($items, TRUE); } else { $text = i18n::s('No event has been planned so far'); } // cache, whatever changes, for 1 minute Cache::put($cache_id, $text, 'stable', 60); } $context['text'] .= $text; // page tools if (Surfer::is_associate()) { $context['page_tools'][] = Skin::build_link('dates/check.php', i18n::s('Maintenance'), 'basic'); } // subscribe to this calendar if (!isset($context['skins_general_without_feed']) || $context['skins_general_without_feed'] != 'Y') { $lines = array(); $lines[] = Skin::build_link($context['url_to_home'] . $context['url_to_root'] . 'dates/fetch_ics.php', i18n::s('Get calendar'), 'basic');
if (!Surfer::is_crawler()) { // previous year $previous = $year - 1; // next year $next = $year + 1; // neighbours $neighbours = array(Dates::get_url($previous, 'year'), $previous, Dates::get_url($next, 'year'), $next, NULL, NULL); // links to display previous and next years $text .= Skin::neighbours($neighbours, 'slideshow'); } // one calendar per month for ($index = 1; $index <= 12; $index++) { // items for this month $items =& Dates::list_for_month($year, $index, 'links'); // draw all months - force empty months $text .= Dates::build_months($items, TRUE, TRUE, TRUE, FALSE, $year, $index); } // cache, whatever change, for 5 minutes Cache::put($cache_id, $text, 'stable', 300); } $context['text'] .= $text; } // page extra content $cache_id = 'dates/year.php#extra'; if (!($text = Cache::get($cache_id))) { // side bar with the list of most recent pages 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'); } Cache::put($cache_id, $text, 'articles'); }
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'; if (!($text = Cache::get($cache_id))) { // side bar with the list of most recent pages 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'); } Cache::put($cache_id, $text, 'articles'); }