Example #1
0
 /**
  * list sections
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // the script used to check all pages at once
     Page::insert_script('function cascade_selection_to_all_section_rows(handle) {' . "\n" . '	$("div#sections_panel input[type=\'checkbox\'].row_selector").each(' . "\n" . '		function() { $(this).attr("checked", $(handle).is(":checked"));}' . "\n" . '	);' . "\n" . '}' . "\n");
     // table prefix
     $text .= Skin::table_prefix('yc-grid');
     // table headers
     $main = '<input type="checkbox" class="row_selector" onclick="cascade_selection_to_all_section_rows(this);" />';
     $cells = array($main, i18n::s('Section'), i18n::s('Rank'));
     $text .= Skin::table_row($cells, 'header');
     // process all items in the list
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     $count = 0;
     while ($item = SQL::fetch($result)) {
         $cells = array();
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'section:' . $item['id']);
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Sections::get_permalink($item);
         // column to select the row
         $cells[] = '<input type="checkbox" name="selected_sections[]" id="section_selector_' . $count . '" class="row_selector" value="' . $item['id'] . '" />';
         // use the title to label the link
         if (is_object($overlay)) {
             $title = Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $title = Codes::beautify($item['title']);
         }
         // initialize variables
         $prefix = $suffix = $icon = '';
         // flag sticky pages
         if ($item['rank'] < 10000) {
             $prefix .= STICKY_FLAG;
         }
         // signal locked sections
         if (isset($item['locked']) && $item['locked'] == 'Y') {
             $suffix .= ' ' . LOCKED_FLAG;
         }
         // flag sections 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 sections
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // the introductory text
         if ($item['introduction']) {
             $suffix .= BR . Codes::beautify_introduction($item['introduction']);
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $suffix .= $overlay->get_text('list', $item);
         }
         // append details to the suffix
         $suffix .= BR . '<span class="details">';
         // details
         $details = array();
         // info on related pages
         $stats = Articles::stat_for_anchor('section:' . $item['id']);
         if ($stats['count']) {
             $details[] = sprintf(i18n::ns('%d page', '%d pages', $stats['count']), $stats['count']);
         }
         // info on related files
         $stats = Files::stat_for_anchor('section:' . $item['id']);
         if ($stats['count']) {
             $details[] = sprintf(i18n::ns('%d file', '%d files', $stats['count']), $stats['count']);
         }
         // info on related links
         $stats = Links::stat_for_anchor('section:' . $item['id']);
         if ($stats['count']) {
             $details[] = sprintf(i18n::ns('%d link', '%d links', $stats['count']), $stats['count']);
         }
         // info on related comments
         $stats = Comments::stat_for_anchor('section:' . $item['id']);
         if ($stats['count']) {
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', $stats['count']), $stats['count']);
         }
         // info on related sections
         $stats = Sections::stat_for_anchor('section:' . $item['id']);
         if ($stats['count']) {
             $details[] = sprintf(i18n::ns('%d section', '%d sections', $stats['count']), $stats['count']);
         }
         // combine in-line details
         if (count($details)) {
             $suffix .= ucfirst(trim(implode(', ', $details))) . BR;
         }
         // list up to three categories by title, if any
         $anchors = array();
         if ($members =& Members::list_categories_by_title_for_member('section:' . $item['id'], 0, 7, 'raw')) {
             foreach ($members as $id => $attributes) {
                 // add background color to distinguish this category against others
                 if (isset($attributes['background_color']) && $attributes['background_color']) {
                     $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>';
                 }
                 $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic');
             }
         }
         if (count($anchors)) {
             $suffix .= sprintf(i18n::s('In %s'), implode(' | ', $anchors)) . BR;
         }
         // details
         $details = array();
         // the author
         if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
             if ($item['create_name'] != $item['edit_name']) {
                 $details[] = sprintf(i18n::s('by %s, %s'), $item['create_name'], $item['edit_name']);
             } else {
                 $details[] = sprintf(i18n::s('by %s'), $item['create_name']);
             }
         }
         // the last action
         $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']);
         // the number of hits
         if (Surfer::is_logged() && $item['hits'] > 1) {
             $details[] = Skin::build_number($item['hits'], i18n::s('hits'));
         }
         // combine in-line details
         if (count($details)) {
             $suffix .= ucfirst(trim(implode(', ', $details)));
         }
         // end of details
         $suffix .= '</span>';
         // strip empty details
         $suffix = str_replace(BR . '<span class="details"></span>', '', $suffix);
         $suffix = str_replace('<span class="details"></span>', '', $suffix);
         // the icon to put in the left column
         if ($item['thumbnail_url']) {
             $icon = $item['thumbnail_url'];
         }
         // commands
         $commands = array(Skin::build_link(Sections::get_url($item['id'], 'edit'), i18n::s('edit'), 'basic'), Skin::build_link(Sections::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic'));
         // link to this page
         $cells[] = $prefix . Skin::build_link($url, $title, 'section') . ' - ' . Skin::finalize_list($commands, 'menu') . $suffix;
         // ranking
         $cells[] = '<input type="text" size="5" name="section_rank_' . $item['id'] . '" value="' . $item['rank'] . '" onfocus="$(\'#section_selector_' . $count . '\').attr(\'checked\', \'checked\');" onchange="$(\'#act_on_sections\').prop(\'selectedIndex\', 6);" />';
         // append the row
         $text .= Skin::table_row($cells, $count++);
     }
     // select all rows
     $cells = array('<input type="checkbox" class="row_selector" onclick="cascade_selection_to_all_section_rows(this);" />', i18n::s('Select all/none'), '');
     $text .= Skin::table_row($cells, $count++);
     // table suffix
     $text .= Skin::table_suffix();
     // end of processing
     SQL::free($result);
     return $text;
 }
Example #2
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;
 }