コード例 #1
0
ファイル: event.php プロジェクト: rair/yacs
 /**
  * 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;
 }
コード例 #2
0
ファイル: anchors.php プロジェクト: rair/yacs
 /**
  * count related items
  *
  * This function draws a nice table to show how many items are related to
  * the anchor that has the focus.
  *
  * @param string the target reference
  * @param string the label to use, if any
  * @return string some XHTML snippet to send to the browser
  */
 public static function stat_related_to($anchor, $label = NULL)
 {
     global $context;
     // describe related content
     $related = '';
     $lines = 2;
     // stats for related categories, but only within categories
     if (strpos($anchor, 'category:') === 0) {
         if (($stats = Categories::stat_for_anchor($anchor)) && $stats['count']) {
             $cells = array();
             $cells[] = i18n::s('Categories');
             $cells[] = 'center=' . $stats['count'];
             $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
             $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
             $related .= Skin::table_row($cells, $lines++);
         }
     }
     // stats for related sections, but only within sections
     if (strpos($anchor, 'section:') === 0) {
         if (($stats = Sections::stat_for_anchor($anchor)) && $stats['count']) {
             $cells = array();
             $cells[] = i18n::s('Sections');
             $cells[] = 'center=' . $stats['count'];
             $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
             $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
             $related .= Skin::table_row($cells, $lines++);
         }
     }
     // stats for related articles, but only within sections
     if (strpos($anchor, 'section:') === 0) {
         if (($stats = Articles::stat_for_anchor($anchor)) && $stats['count']) {
             $cells = array();
             $cells[] = i18n::s('Pages');
             $cells[] = 'center=' . $stats['count'];
             $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
             $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
             $related .= Skin::table_row($cells, $lines++);
         }
     }
     // stats for related images
     include_once $context['path_to_root'] . 'images/images.php';
     if (($stats = Images::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Images');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related locations
     include_once $context['path_to_root'] . 'locations/locations.php';
     if (($stats = Locations::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Locations');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related tables
     include_once $context['path_to_root'] . 'tables/tables.php';
     if (($stats = Tables::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Tables');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related files
     if (($stats = Files::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Files');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related dates
     include_once $context['path_to_root'] . 'dates/dates.php';
     if (($stats = Dates::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Dates');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related comments
     include_once $context['path_to_root'] . 'comments/comments.php';
     if (($stats = Comments::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Comments');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related links
     include_once $context['path_to_root'] . 'links/links.php';
     if (($stats = Links::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Links');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related versions
     include_once $context['path_to_root'] . 'versions/versions.php';
     if (($stats = Versions::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Versions');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // ensure we have a label
     if (!$label) {
         $label = i18n::s('Following items are attached to this record and will be impacted as well.');
     }
     // stats for related items in a neat table
     if ($related) {
         // make a nice table
         $related = '<p>' . $label . "</p>\n" . Skin::table_prefix('') . Skin::table_row(array(i18n::s('Table'), i18n::s('Records'), i18n::s('Creation date'), i18n::s('Last edition')), 'header') . $related . Skin::table_suffix();
         // put it in a box
         $related = Skin::build_box(i18n::s('Related items'), $related);
     }
     // job done
     return $related;
 }