Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // display the index
} else {
    // insert anchor prefix
    if (is_object($anchor)) {
        $context['text'] .= $anchor->get_prefix();
    }
    // cache the section
    $cache_id = 'versions/list.php?id=' . $anchor->get_reference() . '#' . $page;
    if (!($text = Cache::get($cache_id))) {
        // section title
        $box['title'] = '';
        $box['bar'] = array();
        $box['text'] = '';
        // count versions in the database
        $stats = Versions::stat_for_anchor($anchor->get_reference());
        $stats['count'] += 1;
        if ($stats['count'] > VERSIONS_PER_PAGE) {
            // total count of versions
            $box['bar'] += array('_count' => sprintf(i18n::ns('%d version', '%d versions', $stats['count']), $stats['count']));
            // navigation commands
            $home = 'versions/list.php';
            if ($context['with_friendly_urls'] == 'Y') {
                $prefix = $home . '/' . str_replace(':', '/', $anchor->get_reference());
            } elseif ($context['with_friendly_urls'] == 'R') {
                $prefix = $home . '/' . str_replace(':', '/', $anchor->get_reference());
            } else {
                $prefix = $home . '?id=' . $anchor->get_reference() . '&page=';
            }
            $box['bar'] += Skin::navigate($home, $prefix, $stats['count'], VERSIONS_PER_PAGE, $page);
        }