/** * 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; }