/**
  * list categories
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // empty list
     if (!SQL::count($result)) {
         $output = array();
         return $output;
     }
     // we return an array of ($url => $attributes)
     $items = array();
     // process all items in the list
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     while ($item = SQL::fetch($result)) {
         // url to read the full category
         $url = Categories::get_permalink($item);
         // initialize variables
         $prefix = $suffix = $icon = '';
         // flag categories that are dead, or created or updated very recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $prefix .= EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix .= NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= UPDATED_FLAG;
         }
         // signal restricted and private categories
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // introduction
         if ($item['introduction']) {
             $suffix .= ' ' . Codes::beautify(trim($item['introduction']));
         }
         // details
         $details = array();
         // count related sub-elements
         $related_count = 0;
         // info on related categories
         $stats = Categories::stat_for_anchor('category:' . $item['id']);
         if ($stats['count']) {
             $details[] = sprintf(i18n::ns('%d category', '%d categories', $stats['count']), $stats['count']);
         }
         $related_count += $stats['count'];
         // info on related sections
         if ($count = Members::count_sections_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count);
             $related_count += $count;
         }
         // info on related articles
         if ($count = Members::count_articles_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
             $related_count += $count;
         }
         // info on related files
         if ($count = Files::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
             $related_count += $count;
         }
         // info on related links
         if ($count = Links::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
             $related_count += $count;
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
             $related_count += $stats['count'];
         }
         // info on related users
         if ($count = Members::count_users_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d user', '%d users', $count), $count);
         }
         // append details to the suffix
         if (count($details)) {
             $suffix .= "\n" . '<span class="details">(' . implode(', ', $details) . ')</span>';
         }
         // add a head list of related links
         $details = array();
         // add sub-categories on index pages
         if ($related = Categories::list_by_date_for_anchor('category:' . $item['id'], 0, YAHOO_LIST_SIZE, 'compact')) {
             foreach ($related as $sub_url => $label) {
                 $sub_prefix = $sub_suffix = $sub_hover = '';
                 if (is_array($label)) {
                     $sub_prefix = $label[0];
                     $sub_suffix = $label[2];
                     if (@$label[5]) {
                         $sub_hover = $label[5];
                     }
                     $label = $label[1];
                 }
                 $details[] = $sub_prefix . Skin::build_link($sub_url, $label, 'basic', $sub_hover) . $sub_suffix;
             }
         }
         // add related sections if necessary
         if (count($details) < YAHOO_LIST_SIZE && ($related =& Members::list_sections_by_title_for_anchor('category:' . $item['id'], 0, YAHOO_LIST_SIZE - count($details), 'compact'))) {
             foreach ($related as $sub_url => $label) {
                 $sub_prefix = $sub_suffix = $sub_hover = '';
                 if (is_array($label)) {
                     $sub_prefix = $label[0];
                     $sub_suffix = $label[2];
                     if (@$label[5]) {
                         $sub_hover = $label[5];
                     }
                     $label = $label[1];
                 }
                 $details[] = $sub_prefix . Skin::build_link($sub_url, $label, 'basic', $sub_hover) . $sub_suffix;
             }
         }
         // add related articles if necessary
         if (count($details) < YAHOO_LIST_SIZE && ($related =& Members::list_articles_by_date_for_anchor('category:' . $item['id'], 0, YAHOO_LIST_SIZE - count($details), 'compact'))) {
             foreach ($related as $sub_url => $label) {
                 $sub_prefix = $sub_suffix = $sub_hover = '';
                 if (is_array($label)) {
                     $sub_prefix = $label[0];
                     $sub_suffix = $label[2];
                     if (@$label[5]) {
                         $sub_hover = $label[5];
                     }
                     $label = $label[1];
                 }
                 $details[] = $sub_prefix . Skin::build_link($sub_url, $label, 'basic', $sub_hover) . $sub_suffix;
             }
         }
         // give me more
         if (count($details) && $related_count > YAHOO_LIST_SIZE) {
             $details[] = Skin::build_link(Categories::get_permalink($item), i18n::s('More') . MORE_IMG, 'more', i18n::s('View the category'));
         }
         // layout details
         if (count($details)) {
             $suffix .= BR . "\n&raquo;&nbsp;" . '<span class="details">' . implode(', ', $details) . "</span>\n";
         }
         // put the actual icon in the left column
         if (isset($item['thumbnail_url'])) {
             $icon = $item['thumbnail_url'];
         }
         // use the title to label the link
         $label = Skin::strip($item['title'], 50);
         // some hovering title for this category
         $hover = i18n::s('View the category');
         // list all components for this item
         $items[$url] = array($prefix, $label, $suffix, 'category', $icon, $hover);
     }
     // end of processing
     SQL::free($result);
     $output = Skin::build_list($items, '2-columns');
     return $output;
 }
Exemple #2
0
include_once 'categories.php';
// which page should be displayed
if (isset($_REQUEST['page'])) {
    $page = $_REQUEST['page'];
} elseif (isset($context['arguments'][0])) {
    $page = $context['arguments'][0];
} else {
    $page = 1;
}
$page = max(1, intval($page));
// load the skin
load_skin('site_taxonomy');
// the title of the page
$context['page_title'] = i18n::s('Categories');
// count categories in the database
$stats = Categories::stat_for_anchor(NULL);
// stop hackers
if ($page > 1 && ($page - 1) * CATEGORIES_PER_PAGE > $stats['count']) {
    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 = 'categories/index.php#text#' . $page;
    if (!($text = Cache::get($cache_id))) {
        // do it the Yahoo! style
        $layout = Layouts::new_('yahoo', 'category');
        // the list of active categories
        $offset = ($page - 1) * CATEGORIES_PER_PAGE;
        if (!($text = Categories::list_by_title_for_anchor(NULL, $offset, CATEGORIES_PER_PAGE, $layout))) {
            $text = '<p>' . i18n::s('No category has been created yet.') . '</p>';
        }
Exemple #3
0
 /**
  * list categories
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // empty list
     if (!SQL::count($result)) {
         $output = array();
         return $output;
     }
     // we return an array of ($url => $attributes)
     $items = array();
     // process all items in the list
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     while ($item = SQL::fetch($result)) {
         // url to read the full category
         $url = Categories::get_permalink($item);
         // initialize variables
         $prefix = $suffix = $icon = '';
         // flag categories that are dead, or created or updated very recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $prefix .= EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix .= NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= UPDATED_FLAG;
         }
         // signal restricted and private categories
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // use the title to label the link
         $label = Skin::strip($item['title'], 10);
         // details
         $details = array();
         // info on related categories
         $stats = Categories::stat_for_anchor('category:' . $item['id']);
         if ($stats['count']) {
             $details[] = sprintf(i18n::ns('%d category', '%d categories', $stats['count']), $stats['count']);
         }
         // info on related sections
         if ($count = Members::count_sections_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count);
         }
         // info on related articles
         if ($count = Members::count_articles_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
         }
         // info on related files
         if ($count = Files::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
         }
         // info on related links
         if ($count = Links::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
         }
         // info on related users
         if ($count = Members::count_users_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d user', '%d users', $count), $count);
         }
         // append details to the suffix
         if (count($details)) {
             $suffix .= "\n" . '<span class="details">(' . implode(', ', $details) . ')</span>';
         }
         // introduction
         if ($item['introduction']) {
             $suffix .= ' ' . Codes::beautify(trim($item['introduction']));
         }
         // put the actual icon in the left column
         if (isset($item['thumbnail_url']) && $this->layout_variant != 'sidebar') {
             $icon = $item['thumbnail_url'];
         }
         // list all components for this item
         $items[$url] = array($prefix, $label, $suffix, 'category', $icon);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
Exemple #4
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;
 }
 /**
  * list categories for search requests
  *
  * @param resource the SQL result
  * @return array of resulting items ($score, $summary), or NULL
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return an array of array($score, $summary)
     $items = array();
     // empty list
     if (!SQL::count($result)) {
         return $items;
     }
     // process all items in the list
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     while ($item = SQL::fetch($result)) {
         // one box at a time
         $box = '';
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // url to read the full category
         $url = Categories::get_permalink($item);
         // initialize variables
         $prefix = $suffix = $icon = '';
         // flag categories that are dead, or created or updated very recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $prefix .= EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix .= NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= UPDATED_FLAG;
         }
         // signal restricted and private categories
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // use the title to label the link
         $title = Skin::strip($item['title'], 10);
         // details
         $details = array();
         // info on related categories
         $stats = Categories::stat_for_anchor('category:' . $item['id']);
         if ($stats['count']) {
             $details[] = sprintf(i18n::ns('%d category', '%d categories', $stats['count']), $stats['count']);
         }
         // info on related sections
         if ($count = Members::count_sections_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count);
         }
         // info on related articles
         if ($count = Members::count_articles_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
         }
         // info on related files
         if ($count = Files::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
         }
         // info on related links
         if ($count = Links::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('category:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
         }
         // info on related users
         if ($count = Members::count_users_for_anchor('category:' . $item['id'])) {
             $details[] = sprintf(i18n::ns('%d user', '%d users', $count), $count);
         }
         // the main anchor link
         if (is_object($anchor)) {
             $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'category'));
         }
         // append details to the suffix
         if (count($details)) {
             $suffix .= "\n" . '<span class="details">(' . implode(', ', $details) . ')</span>';
         }
         // introduction
         if ($item['introduction']) {
             $suffix .= ' ' . Codes::beautify(trim($item['introduction']));
         }
         // item summary
         $box .= $prefix . Skin::build_link($url, $title, 'category') . $suffix;
         // put the actual icon in the left column
         if (isset($item['thumbnail_url']) && $this->layout_variant != 'sidebar') {
             $icon = $item['thumbnail_url'];
         }
         // layout this item
         if ($icon) {
             // build the complete HTML element
             $icon = '<img src="' . $icon . '" alt="" title="' . encode_field(strip_tags($title)) . '" />';
             // make it a clickable link
             $icon = Skin::build_link($url, $icon, 'basic');
             $list = array(array($box, $icon));
             $items[] = array($item['score'], Skin::finalize_list($list, 'decorated'));
             // put the item in a division
         } else {
             $items[] = array($item['score'], '<div style="margin: 0 0 1em 0">' . $box . '</div>');
         }
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
Exemple #6
0
 $box = array('bar' => array(), 'text' => '');
 // select a layout
 if (!isset($item['categories_layout']) || !$item['categories_layout']) {
     include_once 'layout_categories.php';
     $layout = new Layout_categories();
 } else {
     $layout = Layouts::new_($item['categories_layout'], 'category');
 }
 // the maximum number of categories per page
 if (is_object($layout)) {
     $items_per_page = $layout->items_per_page();
 } else {
     $items_per_page = CATEGORIES_PER_PAGE;
 }
 // count the number of subcategories
 $stats = Categories::stat_for_anchor('category:' . $item['id']);
 // 		if($stats['count'])
 // 			$box['bar'] += array('_count' => sprintf(i18n::ns('%d category', '%d categories', $stats['count']), $stats['count']));
 // list items by date (default) or by title (option 'categories_by_title')
 $offset = ($zoom_index - 1) * $items_per_page;
 if (preg_match('/\\bcategories_by_title\\b/i', $item['options'])) {
     $items = Categories::list_by_title_for_anchor('category:' . $item['id'], $offset, $items_per_page, $layout);
 } else {
     $items = Categories::list_by_date_for_anchor('category:' . $item['id'], $offset, $items_per_page, $layout);
 }
 // navigation commands for categories
 $home = Categories::get_permalink($item);
 $prefix = Categories::get_url($item['id'], 'navigate', 'categories');
 $box['bar'] = array_merge($box['bar'], Skin::navigate($home, $prefix, $stats['count'], $items_per_page, $zoom_index));
 // the command to post a new category
 if ($stats['count'] && $this_cat->allow_creation()) {