/** * cascade to children * * @param string referencing of the changed anchor * @param string rights to be cascaded (e.g., 'Y', 'R' or 'N') */ public static function cascade($reference, $active) { global $context; // only sections may have sub-sections if (strpos($reference, 'section:') === 0) { // cascade to sub-sections if ($items = Sections::list_for_anchor($reference, 'raw')) { // cascade to each section individually foreach ($items as $id => $item) { // limit actual rights $item['active'] = Anchors::ceil_rights($active, $item['active_set']); $query = "UPDATE " . SQL::table_name('sections') . " SET active='" . SQL::escape($item['active']) . "' WHERE id = " . SQL::escape($id); SQL::query($query); // cascade to children Anchors::cascade('section:' . $item['id'], $item['active']); } } } // only categories may have sub-categories if (strpos($reference, 'category:') === 0) { // cascade to sub-categories if ($items = Categories::list_for_anchor($reference, 'raw')) { // cascade to each section individually foreach ($items as $id => $item) { // limit actual rights $item['active'] = Anchors::ceil_rights($active, $item['active_set']); $query = "UPDATE " . SQL::table_name('categories') . " SET active='" . SQL::escape($item['active']) . "' WHERE id = " . SQL::escape($id); SQL::query($query); // cascade to children Anchors::cascade('category:' . $item['id'], $item['active']); } } } // only sections may have articles if (strpos($reference, 'section:') === 0) { // cascade to articles --up to 3000 if ($items =& Articles::list_for_anchor_by('edition', $reference, 0, 3000, 'raw')) { // cascade to each section individually foreach ($items as $id => $item) { // limit actual rights $item['active'] = Anchors::ceil_rights($active, $item['active_set']); $query = "UPDATE " . SQL::table_name('articles') . " SET active='" . SQL::escape($item['active']) . "' WHERE id = " . SQL::escape($id); SQL::query($query); // cascade to children Anchors::cascade('article:' . $item['id'], $item['active']); } } } // cascade to files --up to 3000 if ($items = Files::list_by_date_for_anchor($reference, 0, 3000, 'raw')) { // cascade to each section individually foreach ($items as $id => $item) { // limit actual rights $item['active'] = Anchors::ceil_rights($active, $item['active_set']); $query = "UPDATE " . SQL::table_name('files') . " SET active='" . SQL::escape($item['active']) . "' WHERE id = " . SQL::escape($id); SQL::query($query); } } }
/** * list childs of this anchor, with or without type filters * * @param string set of desired childs (articles, sections...) separted by comma, or "all" keyword * @param int offset to start listing * @param int the maximum of items returned per type * @param mixed string or object the layout to use * @return an array of array with raw items sorted by type */ function get_childs($filter = 'all', $offset = 0, $max = 50, $layout = 'raw') { // we return a array $childs = array(); // sub sections if ($filter == 'all' || preg_match('/\\bsections?\\b/i', $filter)) { $childs['section'] = Sections::list_by_title_for_anchor($this->get_reference(), $offset, $max, $layout); } // sub articles if ($filter == 'all' || preg_match('/\\barticles?\\b/i', $filter)) { $childs['article'] = Articles::list_for_anchor_by('title', $this->get_reference(), $offset, $max, $layout); } // files if ($filter == 'all' || preg_match('/\\bfiles?\\b/i', $filter)) { $childs['file'] = Files::list_by_title_for_anchor($this->get_reference(), $offset, $max, $layout); } return $childs; }
} } // save in cache, whatever change, for 5 minutes Cache::put($cache_id, $text, 'stable', 300); } // news $context['components']['news'] = $text; // list extra boxes $text = ''; if ($anchor = Sections::lookup('extra_boxes')) { // the maximum number of boxes is a global parameter if (!isset($context['site_extra_maximum']) || !$context['site_extra_maximum']) { $context['site_extra_maximum'] = 7; } // articles to be displayed as extra boxes if ($items =& Articles::list_for_anchor_by('publication', $anchor, 0, $context['site_extra_maximum'], 'boxes')) { foreach ($items as $title => $attributes) { $text .= Skin::build_box($title, $attributes['content'], 'boxes', $attributes['id']) . "\n"; } } } // boxes $context['components']['boxes'] = $text; // referrals, if any if (Surfer::is_associate() || isset($context['with_referrals']) && $context['with_referrals'] == 'Y') { $context['components']['referrals'] =& Skin::build_referrals('index.php'); } // // compute navigation information -- $context['navigation'] // // a meta link to a feeding page
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License */ // common definitions and initial processing include_once '../shared/global.php'; // load the skin load_skin('articles'); // the path to this page $context['path_bar'] = array('articles/' => i18n::s('All pages')); // the title of the page $context['page_title'] = i18n::s('Review queue'); // the menu bar for this page $context['page_menu'] = array('articles/' => i18n::s('All pages')); // list queries if (Surfer::is_associate()) { $anchor = Sections::lookup('queries'); if ($anchor && ($rows =& Articles::list_for_anchor_by('publication', $anchor, 0, 5))) { if (is_array($rows)) { $rows = Skin::build_list($rows, 'decorated'); } $context['text'] .= Skin::build_box(i18n::s('Submitted queries'), $rows, 'header1', 'queries'); } } // list draft articles if ($rows =& Articles::list_by('draft')) { // set a title to the section only if we have other sections if (Surfer::is_associate()) { $context['text'] .= Skin::build_block(i18n::s('Submitted articles'), 'title', 'submitted'); } if (is_array($rows)) { $context['text'] .= Skin::build_list($rows, 'decorated'); } else {
$layout->set_focus('section:' . $item['id']); } // the maximum number of articles per page if (is_object($layout)) { $items_per_page = $layout->items_per_page(); } else { $items_per_page = ARTICLES_PER_PAGE; } // list articles by date (default) or by title (option 'articles_by_title') $offset = ($zoom_index - 1) * $items_per_page; if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } $items =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], $offset, $items_per_page, $layout); // actually render the html for the box $content = ''; if (is_array($items)) { $content = Skin::build_list($items, 'compact'); } else { $content = $items; } // make a complete box if ($content) { $text .= Skin::build_box(i18n::s('Hidden pages'), $content, 'header1', 'articles'); } } // title label $title_label = ''; if (is_object($overlay)) {
/** * 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; } // maximum number of items if (isset($this->layout_variant) && $this->layout_variant > 3) { $maximum_items = $this->layout_variant; } elseif (defined('YAHOO_LIST_SIZE')) { $maximum_items = YAHOO_LIST_SIZE; } else { $maximum_items = 7; } // clear flows $text .= '<br style="clear: left" />'; // process all items in the list $family = ''; while ($item = SQL::fetch($result)) { // change the family if ($item['family'] != $family) { $family = $item['family']; $text .= '<h2><span>' . $family . ' </span></h2>' . "\n"; } // get the anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Sections::get_permalink($item); // initialize variables $prefix = $label = $suffix = $icon = $hover = ''; // signal restricted and private sections if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // flag sections that are draft, dead, or created or updated very recently if ($item['activation_date'] >= $context['now']) { $prefix .= DRAFT_FLAG; } elseif ($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; } // display introduction field on hovering if ($item['introduction']) { $hover .= strip_tags(Codes::beautify_introduction($item['introduction'])); } // details and content $details = array(); $content = array(); // count related sub-elements $related_count = 0; // info on related articles if ($count = Articles::count_for_anchor('section:' . $item['id'])) { if ($count > $maximum_items) { $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count); } elseif (Surfer::is_empowered()) { $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count); } $related_count += $count; // get the overlay for content of this section, if any $content_overlay = NULL; if (isset($item['content_overlay'])) { $content_overlay = Overlay::bind($item['content_overlay']); } // no room to list articles if (count($content) >= $maximum_items) { } elseif (is_object($content_overlay) && is_callable(array($content_overlay, 'render_list_for_anchor'))) { if ($related = $content_overlay->render_list_for_anchor('section:' . $item['id'], $maximum_items - count($content))) { 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]; } $content[] = $sub_prefix . $label . $sub_suffix; } } // regular rendering of related articles } else { if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } if ($related =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, $maximum_items - count($content), '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]; } $content[] = $sub_prefix . $label . $sub_suffix; } } } } // info on related files if ($count = Files::count_for_anchor('section:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); $related_count += $count; // add related files if necessary if (count($content) < $maximum_items && ($related = Files::list_by_date_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), '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]; } $content[] = $sub_prefix . $label . $sub_suffix; } } } // info on related links if ($count = Links::count_for_anchor('section:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); $related_count += $count; // add related links if necessary if (count($content) < $maximum_items && ($related = Links::list_by_date_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), '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]; } $content[] = $sub_prefix . $label . $sub_suffix; } } } // info on related comments if ($count = Comments::count_for_anchor('section:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); $related_count += $count; } // info on related sections if ($count = Sections::count_for_anchor('section:' . $item['id'])) { if ($count > $maximum_items) { $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count); } elseif (Surfer::is_empowered()) { $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count); } $related_count += $count; // add sub-sections if ($related =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), '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]; } $content[] = $sub_prefix . $label . $sub_suffix; } } } // give me more if (count($content) && $related_count > $maximum_items) { $content[] = '...' . MORE_IMG; } // layout details if (count($content)) { $hover .= '<ul><li>' . implode('</li><li>', $content) . '</li></ul>'; } // add a link to the main page if (!$hover) { $hover = i18n::s('View the section'); } // use the title to label the link $title = Skin::strip($item['title'], 50); // new or updated flag if ($suffix) { $details[] = $suffix; } // append details if (count($details)) { $title .= BR . '<span class="details">' . implode(', ', $details) . '</span>'; } // look for an image $icon = ''; if (isset($item['thumbnail_url']) && $item['thumbnail_url']) { $icon = $item['thumbnail_url']; } elseif (is_callable(array($anchor, 'get_bullet_url'))) { $icon = $anchor->get_bullet_url(); } // use the thumbnail for this section if ($icon) { // fix relative path if (!preg_match('/^(\\/|http:|https:|ftp:)/', $icon)) { $icon = $context['url_to_root'] . $icon; } // use parameter of the control panel for this one $options = ''; if (isset($context['classes_for_thumbnail_images'])) { $options = 'class="' . $context['classes_for_thumbnail_images'] . '" '; } // build the complete HTML element $icon = '<img src="' . $icon . '" alt="" title="" ' . $options . ' />'; // use default icon if nothing to display } else { $icon = MAP_IMG; } // use tipsy on hover $content = '<a href="' . $url . '" id="titles_' . $item['id'] . '">' . $icon . BR . $prefix . $title . '</a>'; Page::insert_script('$(function() {' . "\n" . ' $("a#titles_' . $item['id'] . '").each(function() {' . "\n" . ' $(this).tipsy({fallback: \'<div style="text-align: left;">' . str_replace(array("'", "\n"), array('"', '<br />'), $hover) . '</div>\',' . "\n" . ' html: true,' . "\n" . ' gravity: $.fn.tipsy.autoWE,' . "\n" . ' fade: true,' . "\n" . ' offset: 8,' . "\n" . ' opacity: 1.0});' . "\n" . ' });' . "\n" . '});' . "\n"); // add a floating box $text .= Skin::build_box(NULL, $content, 'floating'); } // clear flows $text .= '<br style="clear: left" />'; // end of processing SQL::free($result); return $text; }
/** * list articles attached to one anchor * * The ordering method is provided by layout. * * Only articles matching following criteria are returned: * - article is visible (active='Y') * - article is restricted (active='R'), but the surfer is an authenticated member, * or YACS is allowed to show restricted teasers * - article is protected (active='N'), but surfer is an associate, and we are not feeding someone * - surfer is anonymous, and article has been officially published * - logged surfers are restricted to their own articles, plus published articles * - an expiry date has not been defined, or is not yet passed * * @param mixed, either a string the target anchor, or an array of anchors * @param int the offset from the start of the list; usually, 0 or 1 * @param int the number of items to display * @param string the list variant, if any * @param boolean FALSE to include sticky pages, TRUE otherwise * @return NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon) */ public static function &list_for_anchor($anchor, $offset = 0, $count = 10, $layout = 'no_anchor', $without_sticky = FALSE) { global $context; // define items order if (is_callable(array($layout, 'items_order'))) { $order = $layout->items_order(); } if (!isset($order) || !$order) { $order = 'edition'; } // ask for ordered items $output =& Articles::list_for_anchor_by($order, $anchor, $offset, $count, $layout, $without_sticky); return $output; }
/** * render a compact list of recent modifications * * The provided anchor can reference: * - a section 'section:123' * - a category 'category:456' * - a user 'user:789' * - 'self' * - nothing * * @param string the anchor (e.g. 'section:123') * @param string layout to use * @return string the rendered text **/ public static function render_updated($layout = 'simple', $anchor = '') { global $context; // we return some text; $text = ''; // number of items to display $count = COMPACT_LIST_SIZE; if (($position = strpos($anchor, ',')) !== FALSE) { $count = (int) trim(substr($anchor, $position + 1)); if (!$count) { $count = COMPACT_LIST_SIZE; } $anchor = trim(substr($anchor, 0, $position)); } // scope is limited to current surfer if ($anchor == 'self' && Surfer::get_id()) { $anchor = 'user:'******'section:') === 0) { // look at this branch of the content tree $anchors = Sections::get_branch_at_anchor($anchor); // query the database and layout that stuff $text = Articles::list_for_anchor_by('edition', $anchors, 0, $count, $layout); // scope is limited to one category } elseif (strpos($anchor, 'category:') === 0) { // first level of depth $anchors = array(); // get sections linked to this category if ($topics = Members::list_sections_by_title_for_anchor($anchor, 0, 50, 'raw')) { foreach ($topics as $id => $not_used) { $anchors = array_merge($anchors, array('section:' . $id)); } } // second level of depth if (count($topics) && count($anchors) < 2000) { $topics = Sections::get_children_of_anchor($anchors); $anchors = array_merge($anchors, $topics); } // third level of depth if (count($topics) && count($anchors) < 2000) { $topics = Sections::get_children_of_anchor($anchors); $anchors = array_merge($anchors, $topics); } // fourth level of depth if (count($topics) && count($anchors) < 2000) { $topics = Sections::get_children_of_anchor($anchors); $anchors = array_merge($anchors, $topics); } // fifth level of depth if (count($topics) && count($anchors) < 2000) { $topics = Sections::get_children_of_anchor($anchors); $anchors = array_merge($anchors, $topics); } // the category itself is an anchor $anchors[] = $anchor; // ensure anchors are referenced only once $anchors = array_unique($anchors); // query the database and layout that stuff $text = Members::list_articles_by_date_for_anchor($anchors, 0, $count, $layout); // scope is limited to pages of one surfer } elseif (strpos($anchor, 'user:'******'edition', substr($anchor, 5), 0, $count, $layout); } else { $text = Articles::list_by('edition', 0, $count, $layout); } // we have an array to format if (is_array($text)) { $text = Skin::build_list($text, $layout); } // job done return $text; }
/** * list sections * * @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 some text $text = ''; // maximum number of items if (isset($this->layout_variant) && $this->layout_variant > 3) { $maximum_items = $this->layout_variant; } elseif (defined('YAHOO_LIST_SIZE')) { $maximum_items = YAHOO_LIST_SIZE; } else { $maximum_items = 7; } // stack of items $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'; $family = ''; while ($item = SQL::fetch($result)) { // change the family if ($item['family'] != $family) { // flush current stack, if any if (count($items)) { $text .= Skin::build_list($items, '2-columns'); } $items = array(); // show the family $family = $item['family']; $text .= '<h2><span>' . $family . ' </span></h2>' . "\n"; } // the url to view this item $url = Sections::get_permalink($item); // initialize variables $prefix = $label = $suffix = $icon = ''; // signal restricted and private sections if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // flag sections that are draft, dead, or created or updated very recently if ($item['activation_date'] >= $context['now']) { $prefix .= DRAFT_FLAG; } elseif ($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; } // details and content $details = array(); $content = array(); // count related sub-elements $related_count = 0; // info on related articles if ($count = Articles::count_for_anchor('section:' . $item['id'])) { if ($count > $maximum_items) { $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count); } elseif (Surfer::is_empowered()) { $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count); } $related_count += $count; // get the overlay for content of this section, if any $content_overlay = NULL; if (isset($item['content_overlay'])) { $content_overlay = Overlay::bind($item['content_overlay']); } // no room to list articles if (count($content) >= $maximum_items) { } elseif (is_object($content_overlay) && is_callable(array($content_overlay, 'render_list_for_anchor'))) { if ($related = $content_overlay->render_list_for_anchor('section:' . $item['id'], $maximum_items - count($content))) { 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]; } $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'basic', $sub_hover) . $sub_suffix; } } // regular rendering of related articles } else { if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } if ($related =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, $maximum_items - count($content), '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]; } $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'article', $sub_hover) . $sub_suffix; } } } } // info on related files if ($count = Files::count_for_anchor('section:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); $related_count += $count; // add related files if necessary if (count($content) < $maximum_items && ($related = Files::list_by_date_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), '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]; } $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'file', $sub_hover) . $sub_suffix; } } } // info on related links if ($count = Links::count_for_anchor('section:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); $related_count += $count; // add related links if necessary if (count($content) < $maximum_items && ($related = Links::list_by_date_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), '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]; } $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'link', $sub_hover) . $sub_suffix; } } } // info on related comments if ($count = Comments::count_for_anchor('section:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); $related_count += $count; } // info on related sections if ($count = Sections::count_for_anchor('section:' . $item['id'])) { if ($count > $maximum_items) { $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count); } elseif (Surfer::is_empowered()) { $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count); } $related_count += $count; // add sub-sections if ($related =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, $maximum_items, '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]; } $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'section', $sub_hover) . $sub_suffix; } } } // introduction if ($item['introduction']) { $suffix .= ' ' . Codes::beautify_introduction($item['introduction']); } // append details to the suffix if (count($details)) { $suffix .= ' <span class="details">(' . implode(', ', $details) . ')</span>'; } // give me more if (count($content) && $related_count > $maximum_items) { $content[] = Skin::build_link(Sections::get_permalink($item), i18n::s('More') . MORE_IMG, 'more', i18n::s('View the section')); } // layout details if (count($content)) { foreach ($content as $line) { $suffix .= '<div>' . YAHOO_ITEM_PREFIX . $line . YAHOO_ITEM_SUFFIX . '</div>'; } } // use the title to label the link $label = Skin::strip($item['title'], 50); // put the actual icon in the left column if (isset($item['thumbnail_url'])) { $icon = $item['thumbnail_url']; } // some hovering title for this section $hover = i18n::s('View the section'); // list all components for this item --use basic link style to avoid prefix or suffix images, if any $items[$url] = array($prefix, $label, $suffix, 'basic', $icon, $hover); } // flush the stack if (count($items)) { $text .= Skin::build_list($items, '2-columns'); } // end of processing SQL::free($result); return $text; }
/** * list sections * * @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; } // the maximum number of items per section if (!defined('MAXIMUM_ITEMS_PER_SECTION')) { define('MAXIMUM_ITEMS_PER_SECTION', 100); } // we return plain text $text = ''; // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; $family = ''; while ($item = SQL::fetch($result)) { // change the family if ($item['family'] != $family) { $family = $item['family']; // show the family $text .= '<h2><span>' . $family . ' </span></h2>' . "\n"; } // get the related overlay, if any $overlay = Overlay::load($item, 'section:' . $item['id']); // get the main anchor $anchor = Anchors::get($item['anchor']); // one box per section $box = array('title' => '', 'text' => ''); // box content $elements = array(); // use the title to label the link if (is_object($overlay)) { $box['title'] .= Codes::beautify_title($overlay->get_text('title', $item)); } else { $box['title'] .= Codes::beautify_title($item['title']); } $details = array(); // info on related articles if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } $items =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact'); if (@count($items)) { // mention the number of items in folded title $details[] = sprintf(i18n::ns('%d page', '%d pages', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'article') . $suffix; } } // info on related files if (Sections::has_option('files_by', $anchor, $item) == 'title') { $items = Files::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact'); } else { $items = Files::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact'); } if ($items) { // mention the number of sections in folded title $details[] = sprintf(i18n::ns('%d file', '%d files', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'file') . $suffix; } } // info on related comments if ($items = Comments::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact', TRUE)) { // mention the number of sections in folded title $details[] = sprintf(i18n::ns('%d comment', '%d comments', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'comment') . $suffix; } } // info on related links if (Sections::has_option('links_by_title', $anchor, $item)) { $items = Links::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact'); } else { $items = Links::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact'); } if ($items) { // mention the number of sections in folded title $details[] = sprintf(i18n::ns('%d link', '%d links', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label) . $suffix; } } // list related sections, if any if ($items =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact')) { // mention the number of sections in folded title $details[] = sprintf(i18n::ns('%d section', '%d sections', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'section') . $suffix; } } // signal continuing sections if (count($elements) > MAXIMUM_ITEMS_PER_SECTION) { $elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('More pages') . MORE_IMG, 'basic'); } else { $elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'shortcut'); } // complement title if (count($details)) { $box['title'] .= ' <span class="details">(' . join(', ', $details) . ')</span>'; } // insert introduction, if any if ($item['introduction']) { $box['text'] .= Codes::beautify_introduction($item['introduction']); } // make a full list if (count($elements)) { $box['text'] .= '<ul><li>' . implode('</li>' . "\n" . '<li>', $elements) . '</li></ul>' . "\n"; } // if we have an icon for this section, use it if (isset($item['thumbnail_url']) && $item['thumbnail_url']) { // adjust the class $class = ''; if (isset($context['classes_for_thumbnail_images'])) { $class = 'class="' . $context['classes_for_thumbnail_images'] . '" '; } // build the complete HTML element $icon = '<img src="' . $item['thumbnail_url'] . '" alt="" title="' . encode_field(Codes::beautify_title($item['title'])) . '" ' . $class . '/>'; // make it clickable $link = Skin::build_link(Sections::get_permalink($item), $icon, 'basic'); // put this aside $box['text'] = '<table class="decorated"><tr>' . '<td class="image">' . $link . '</td>' . '<td class="content">' . $box['text'] . '</td>' . '</tr></table>'; } // always make a box $text .= Skin::build_box($box['title'], $box['text'], 'folded'); } // end of processing SQL::free($result); return $text; }
/** * list pages * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // allow for multiple calls static $accordion_id; if (!isset($accordion_id)) { $accordion_id = 1; } else { $accordion_id++; } // empty list if (!SQL::count($result)) { $output = array(); return $output; } // the maximum number of items per article if (!defined('MAXIMUM_ITEMS_PER_ACCORDION')) { define('MAXIMUM_ITEMS_PER_ACCORDION', 100); } // we return plain text $text = ''; // type of listed object $items_type = $this->listed_type; // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; $family = ''; while ($item = SQL::fetch($result)) { // get the object interface, this may load parent and overlay $entity = new $items_type($item); // change the family (layout of sections) if (isset($item['family']) && $item['family'] != $family) { $family = $item['family']; // show the family $text .= '<h2><span>' . $family . ' </span></h2>' . "\n"; } // one box per page $box = array('title' => '', 'text' => ''); // signal entity to be published if (isset($item['publish_date']) && ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S'))) { $box['title'] .= DRAFT_FLAG; } // signal entity to be activated if (isset($item['activation_date']) && $item['activation_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $box['title'] .= DRAFT_FLAG; } // signal restricted and private entity if ($item['active'] == 'N') { $box['title'] .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $box['title'] .= RESTRICTED_FLAG; } // use the title to label the link if (is_object($entity->overlay)) { $box['title'] .= Codes::beautify_title($entity->overlay->get_text('title', $item)); } else { $box['title'] .= Codes::beautify_title($item['title']); } // box content $elements = array(); // complement the title with interesting details $details = array(); // info on related article, only for sections if ($items_type == 'section') { if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } $items =& Articles::list_for_anchor_by($order, $entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact'); if (@count($items)) { // mention the number of items in folded title $details[] = sprintf(i18n::ns('%d page', '%d pages', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'article') . $suffix; } } } // info on related files if ($entity->has_option('files_by') == 'title') { $items = Files::list_by_title_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact'); } else { $items = Files::list_by_date_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact'); } if ($items) { // mention the number of items in folded title $details[] = sprintf(i18n::ns('%d file', '%d files', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'file') . $suffix; } } // info on related comments if ($items = Comments::list_by_date_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact', TRUE)) { // mention the number of items in folded title $details[] = sprintf(i18n::ns('%d comment', '%d comments', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = rtrim(Codes::strip(' ' . $label[2]), '- '); $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'comment') . $suffix; } } // info on related links if ($entity->has_option('links_by_title')) { $items = Links::list_by_title_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact'); } else { $items = Links::list_by_date_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact'); } if ($items) { // mention the number of items in folded title $details[] = sprintf(i18n::ns('%d link', '%d links', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label) . $suffix; } } // list related sub-sections, if any if ($items_type == 'section') { if ($items =& Sections::list_by_title_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact')) { // mention the number of sections in folded title $details[] = sprintf(i18n::ns('%d section', '%d sections', count($items)), count($items)); // add one link per item foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'section') . $suffix; } } } // a link to the page $permalink = $entity->get_permalink($item); $elements[] = Skin::build_link($permalink, sprintf(i18n::s('View the %s'), $items_type) . MORE_IMG, 'shortcut'); // complement title if (count($details)) { $box['title'] .= ' <span class="details">(' . join(', ', $details) . ')</span>'; } // insert introduction, if any if (is_object($entity->overlay)) { $box['text'] .= Skin::build_block($entity->overlay->get_text('introduction', $item), 'introduction'); } elseif (trim($item['introduction'])) { $box['text'] .= Skin::build_block($item['introduction'], 'introduction'); } else { // insert overlay data, if any if (is_object($entity->overlay)) { $box['text'] .= $entity->overlay->get_text('box', $item); } // the content of this box $box['text'] .= Codes::beautify($item['description'], $item['options']); } // make a full list if (count($elements)) { $box['text'] .= Skin::finalize_list($elements, 'compact'); } // display all tags if ($item['tags']) { $box['text'] .= ' <p class="tags" style="margin-bottom: 0">' . Skin::build_tags($item['tags'], $entity->get_reference()) . '</p>'; } // if we have an icon for this page, use it if (isset($item['thumbnail_url']) && $item['thumbnail_url']) { // adjust the class $class = ''; if (isset($context['classes_for_thumbnail_images'])) { $class = 'class="' . $context['classes_for_thumbnail_images'] . '" '; } // build the complete HTML element $icon = '<img src="' . $item['thumbnail_url'] . '" alt="" title="' . encode_field(Codes::beautify_title($item['title'])) . '" ' . $class . '/>'; // make it clickable $link = Skin::build_link($permalink, $icon, 'basic'); // put this aside $box['text'] = '<table class="decorated"><tr>' . '<td class="image">' . $link . '</td>' . '<td class="content">' . $box['text'] . '</td>' . '</tr></table>'; } // always make a box $text .= $this->build_accordion_box($box['title'], $box['text'], 'accordion_' . $accordion_id); } // we have bounded styles and scripts $this->load_scripts_n_styles(); // end of processing SQL::free($result); return $text; }
/** * list sections * * Accept following variants: * - 'full' - include anchor information -- also the default value * * @param resource the SQL result * @return array of resulting items, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($url => $attributes) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // sanity check if (!isset($this->layout_variant)) { $this->layout_variant = 'decorated'; } // 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)) { // 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); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag sections that are draft, dead, or created or updated very recently if ($item['activation_date'] >= $context['now']) { $prefix .= DRAFT_FLAG; } elseif ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } if ($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 .= ' - ' . Codes::beautify_introduction($item['introduction']); } // details and content $details = array(); $content = array(); // count related sub-elements $related_count = 0; // info on related articles if ($count = Articles::count_for_anchor('section:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count); $related_count += $count; // add related articles if necessary if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } if (count($details) < YAHOO_LIST_SIZE && ($related =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, YAHOO_LIST_SIZE - count($details), 'compact'))) { foreach ($related as $link => $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]; } $content[$link] = array($sub_prefix, $label, $sub_suffix, 'basic', '', $sub_hover); } } } // info on related files if ($count = Files::count_for_anchor('section:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); $related_count += $count; // add related files if necessary if (count($details) < YAHOO_LIST_SIZE && ($related = Files::list_by_date_for_anchor('section:' . $item['id'], 0, YAHOO_LIST_SIZE - count($details), 'compact'))) { foreach ($related as $link => $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]; } $content[$link] = array($sub_prefix, $label, $sub_suffix, 'basic', '', $sub_hover); } } } // info on related links if ($count = Links::count_for_anchor('section:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); $related_count += $count; // add related links if necessary if (count($details) < YAHOO_LIST_SIZE && ($related = Links::list_by_date_for_anchor('section:' . $item['id'], 0, YAHOO_LIST_SIZE - count($details), 'compact'))) { foreach ($related as $link => $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]; } $content[$link] = array($sub_prefix, $label, $sub_suffix, 'basic', '', $sub_hover); } } } // info on related comments if ($count = Comments::count_for_anchor('section:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); } // info on related sections if ($count = Sections::count_for_anchor('section:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count); $related_count += $count; // add sub-sections if ($related =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, YAHOO_LIST_SIZE, 'compact')) { foreach ($related as $link => $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]; } $content[$link] = array($sub_prefix, $label, $sub_suffix, 'basic', '', $sub_hover); } } } // give me more if (count($details) && $related_count > YAHOO_LIST_SIZE) { $content[Sections::get_permalink($item)] = array('', i18n::s('More') . MORE_IMG, '', 'more', '', i18n::s('View the section')); } // append details to the suffix if (count($details)) { $suffix .= ' <span class="details">(' . implode(', ', $details) . ')</span>'; } // the main anchor link if (is_object($anchor) && (!isset($this->focus) || $item['anchor'] != $this->focus)) { $suffix .= ' <span class="details">' . sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'section')) . "</span>\n"; } // not if decorated if ($this->layout_variant != 'decorated' && $this->layout_variant != 'references') { // one line per related item if (count($content)) { $suffix .= '<div class="details">' . Skin::build_list($content, 'compact') . "</div>\n"; } } // the icon to put in the left column if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } // some hovering title for this section $hover = i18n::s('View the section'); // list all components for this item $items[$url] = array($prefix, $title, $suffix, 'section', $icon, $hover); } // end of processing SQL::free($result); return $items; }
$box['text'] = ''; if (is_array($items)) { $box['text'] .= Skin::build_list($items, 'decorated'); } elseif (is_string($items)) { $box['text'] .= $items; } if ($box['text']) { $context['text'] .= Skin::build_box('', $box['text']); } // newest articles posted in this branch of the content tree if ($anchors = Sections::get_branch_at_anchor('section:' . $item['id'])) { // build a complete box $box['bar'] = array(); $box['text'] = ''; // list articles by publication date $items =& Articles::list_for_anchor_by('edition', $anchors, 0, 50, 'full'); // actually render the html for the section if (is_array($items)) { $box['text'] .= Skin::build_list($items, 'decorated'); } elseif (is_string($items)) { $box['text'] .= $items; } if ($box['text']) { $context['text'] .= Skin::build_box(i18n::s('What is new?'), $box['text']); } } // // attached files // // list files by date (default) or by title (option :files_by_title:) if (preg_match('/\\bfiles_by_title\\b/i', $item['options'])) {
// loads feeding parameters Safe::load('parameters/feeds.include.php'); // set channel information $values = array(); $values['channel'] = array(); $values['channel']['title'] = $item['title']; $values['channel']['link'] = Sections::get_permalink($item); $values['channel']['description'] = $item['introduction']; // the image for this channel if (isset($context['powered_by_image']) && $context['powered_by_image']) { $values['channel']['image'] = $context['url_to_home'] . $context['url_to_root'] . $context['powered_by_image']; } // all anchors to consider $anchors = Sections::get_branch_at_anchor('section:' . $item['id']); // the list of newest pages $values['items'] =& Articles::list_for_anchor_by('edition', $anchors, 0, 20, 'feed'); // make a text include_once '../services/codec.php'; include_once '../services/rss_codec.php'; $result = rss_Codec::encode($values); $text = @$result[1]; // save in cache for the next request Cache::put($cache_id, $text, 'articles'); } // // transfer to the user agent // // handle the output correctly render_raw('text/xml; charset=' . $context['charset']); // suggest a name on download if (!headers_sent()) {
/** * list sections * * @param resource the SQL result * @return a string to be displayed * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // no hovering label $href_title = ''; // we build an array for the skin::build_tabs() function $panels = array(); // process all items in the list while ($item = SQL::fetch($result)) { // get the main anchor $anchor = Anchors::get($item['anchor']); // get the related overlay, if any $overlay = Overlay::load($item, 'section:' . $item['id']); // get the overlay for content of this section, if any $content_overlay = NULL; if (isset($item['content_overlay'])) { $content_overlay = Overlay::bind($item['content_overlay']); } // panel content $text = ''; // insert anchor prefix if (is_object($anchor)) { $text .= $anchor->get_prefix(); } // the introduction text, if any if (is_object($overlay)) { $text .= Skin::build_block($overlay->get_text('introduction', $item), 'introduction'); } elseif (isset($item['introduction']) && trim($item['introduction'])) { $text .= Skin::build_block($item['introduction'], 'introduction'); } // get text related to the overlay, if any if (is_object($overlay)) { $text .= $overlay->get_text('view', $item); } // filter description, if necessary if (is_object($overlay)) { $description = $overlay->get_text('description', $item); } else { $description = $item['description']; } // the beautified description, which is the actual page body if ($description) { // use adequate label if (is_object($overlay) && ($label = $overlay->get_label('description'))) { $text .= Skin::build_block($label, 'title'); } // beautify the target page $text .= Skin::build_block($description, 'description', '', $item['options']); } // delegate rendering to the overlay, where applicable if (is_object($content_overlay) && ($overlaid = $content_overlay->render('articles', 'section:' . $item['id'], 1))) { $text .= $overlaid; // regular rendering } elseif (!isset($item['articles_layout']) || $item['articles_layout'] != 'none') { // select a layout if (!isset($item['articles_layout']) || !$item['articles_layout']) { include_once '../articles/layout_articles.php'; $layout = new Layout_articles(); } else { $layout = Layouts::new_($item['articles_layout'], 'article'); } // avoid links to this page if (is_object($layout) && is_callable(array($layout, 'set_variant'))) { $layout->set_focus('section:' . $item['id']); } // the maximum number of articles per page if (is_object($layout)) { $items_per_page = $layout->items_per_page(); } else { $items_per_page = ARTICLES_PER_PAGE; } // sort and list articles $offset = 0; if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } elseif (is_callable(array($layout, 'items_order'))) { $order = $layout->items_order(); } else { $order = 'edition'; } // create a box $box = array('top_bar' => array(), 'text' => '', 'bottom_bar' => array()); // the command to post a new page //if(Articles::allow_creation($item, $anchor)) { if ($anchor->allows('creation', 'article')) { Skin::define_img('ARTICLES_ADD_IMG', 'articles/add.gif'); $url = 'articles/edit.php?anchor=' . urlencode('section:' . $item['id']); if (is_object($content_overlay) && ($label = $content_overlay->get_label('new_command', 'articles'))) { } else { $label = ARTICLES_ADD_IMG . i18n::s('Add a page'); } $box['top_bar'] += array($url => $label); } // list pages under preparation $this_section = new section(); $this_section->load_by_content($item, $anchor); if ($this_section->is_assigned()) { if ($order == 'publication' && ($items =& Articles::list_for_anchor_by('draft', 'section:' . $item['id'], 0, 20, 'compact'))) { if (is_array($items)) { $items = Skin::build_list($items, 'compact'); } $box['top_bar'] += array('_draft' => Skin::build_sliding_box(i18n::s('Draft pages'), $items)); } } // top menu if ($box['top_bar']) { $box['text'] .= Skin::build_list($box['top_bar'], 'menu_bar'); } // get pages $items =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], $offset, $items_per_page, $layout); // items in the middle if (is_array($items) && isset($item['articles_layout']) && $item['articles_layout'] == 'compact') { $box['text'] .= Skin::build_list($items, 'compact'); } elseif (is_array($items)) { $box['text'] .= Skin::build_list($items, 'decorated'); } elseif (is_string($items)) { $box['text'] .= $items; } // no navigation bar with alistapart if (!isset($item['articles_layout']) || $item['articles_layout'] != 'alistapart') { // count the number of articles in this section if ($count = Articles::count_for_anchor('section:' . $item['id'])) { if ($count > 20) { $box['bottom_bar'] += array('_count' => sprintf(i18n::ns('%d page', '%d pages', $count), $count)); } // navigation commands for articles $home = Sections::get_permalink($item); $prefix = Sections::get_url($item['id'], 'navigate', 'articles'); $box['bottom_bar'] += Skin::navigate($home, $prefix, $count, $items_per_page, 1); } } // bottom menu if ($box['bottom_bar']) { $box['text'] .= Skin::build_list($box['bottom_bar'], 'menu_bar'); } // there is some box content if ($box['text']) { $text .= $box['text']; } } // layout sub-sections if (!isset($item['sections_layout']) || $item['sections_layout'] != 'none') { // select a layout if (!isset($item['sections_layout']) || !$item['sections_layout']) { include_once 'layout_sections.php'; $layout = new Layout_sections(); } else { $layout = Layouts::new_($item['sections_layout'], 'section'); } // the maximum number of sections per page if (is_object($layout)) { $items_per_page = $layout->items_per_page(); } else { $items_per_page = SECTIONS_PER_PAGE; } // build a complete box $box = array('top_bar' => array(), 'text' => '', 'bottom_bar' => array()); // the command to add a new section //if(Sections::allow_creation($item, $anchor)) { if ($anchor->allows('creation', 'section')) { Skin::define_img('SECTIONS_ADD_IMG', 'sections/add.gif'); $box['top_bar'] += array('sections/edit.php?anchor=' . urlencode('section:' . $item['id']) => SECTIONS_ADD_IMG . i18n::s('Add a section')); } // top menu if ($box['top_bar']) { $box['text'] .= Skin::build_list($box['top_bar'], 'menu_bar'); } // list items by family then title $offset = 0 * $items_per_page; $items = Sections::list_by_title_for_anchor('section:' . $item['id'], $offset, $items_per_page, $layout, TRUE); // actually render the html for the section if (is_array($items) && is_string($item['sections_layout']) && $item['sections_layout'] == 'compact') { $box['text'] .= Skin::build_list($items, 'compact'); } elseif (is_array($items)) { $box['text'] .= Skin::build_list($items, 'decorated'); } elseif (is_string($items)) { $box['text'] .= $items; } // count the number of subsections if ($count = Sections::count_for_anchor('section:' . $item['id'])) { if ($count > 20) { $box['bottom_bar'] = array('_count' => sprintf(i18n::ns('%d section', '%d sections', $count), $count)); } // navigation commands for sections $home = Sections::get_permalink($item); $prefix = Sections::get_url($item['id'], 'navigate', 'sections'); $box['bottom_bar'] += Skin::navigate($home, $prefix, $count, $items_per_page, 1); } // bottom menu if ($box['bottom_bar']) { $box['text'] .= Skin::build_list($box['bottom_bar'], 'menu_bar'); } // there is some box content if ($box['text']) { $text .= $box['text']; } } // ensure that the surfer can change content if (Sections::allow_modification($item, $anchor)) { // view or modify this section $menu = array(); $menu[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the sub-section'), 'span'); if (!is_object($overlay) || !($label = $overlay->get_label('edit_command', 'sections'))) { $label = i18n::s('Edit this sub-section'); } $menu[] = Skin::build_link(Sections::get_url($item['id'], 'edit'), $label, 'span'); $text .= Skin::finalize_list($menu, 'menu_bar'); } // assemble the full panel $panels[] = array('stt' . $item['id'], ucfirst(Skin::strip($item['title'], 30)), 'stc' . $item['id'], $text); } // format tabs if ($this->has_variant('as_array')) { $text = $panels; } else { $text = Skin::build_tabs($panels); } // end of processing SQL::free($result); return $text; }
/** * list sections as topics in a forum * * @param resource the SQL result * @return string the rendered text **/ function layout($result) { global $context; // empty list if (!SQL::count($result)) { $output = array(); return $output; } // layout in a table $text = Skin::table_prefix('wide'); // 'even' is used for title rows, 'odd' for detail rows $class_title = 'odd'; $class_detail = 'even'; // build a list of sections $family = ''; include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // change the family if ($item['family'] != $family) { $family = $item['family']; // show the family $text .= Skin::table_suffix() . '<h2><span>' . $family . ' </span></h2>' . "\n" . Skin::table_prefix('wide'); } // get the related overlay, if any $overlay = Overlay::load($item, 'section:' . $item['id']); // get the main anchor $anchor = Anchors::get($item['anchor']); // reset everything $prefix = $label = $suffix = $icon = ''; // signal restricted and private sections if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // indicate the id in the hovering popup $hover = i18n::s('View the section'); if (Surfer::is_member()) { $hover .= ' [section=' . $item['id'] . ']'; } // the url to view this item $url = Sections::get_permalink($item); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // use the title as a link to the page $title =& Skin::build_link($url, $title, 'basic', $hover); // flag sections updated recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $suffix = EXPIRED_FLAG . ' '; } elseif ($item['create_date'] >= $context['fresh']) { $suffix = NEW_FLAG . ' '; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix = UPDATED_FLAG . ' '; } // this is another row of the output $text .= '<tr class="' . $class_title . '"><th>' . $prefix . $title . $suffix . '</th><th>' . i18n::s('Poster') . '</th><th>' . i18n::s('Messages') . '</th><th>' . i18n::s('Last active') . '</th></tr>' . "\n"; $count = 1; // get last posts for this board --avoid sticky pages if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } if ($articles =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, 5, 'raw', TRUE)) { foreach ($articles as $id => $article) { // get the related overlay, if any $article_overlay = Overlay::load($article, 'article:' . $id); // flag articles updated recently if ($article['expiry_date'] > NULL_DATE && $article['expiry_date'] <= $context['now']) { $flag = EXPIRED_FLAG . ' '; } elseif ($article['create_date'] >= $context['fresh']) { $flag = NEW_FLAG . ' '; } elseif ($article['edit_date'] >= $context['fresh']) { $flag = UPDATED_FLAG . ' '; } else { $flag = ''; } // use the title to label the link if (is_object($article_overlay)) { $title = Codes::beautify_title($article_overlay->get_text('title', $article)); } else { $title = Codes::beautify_title($article['title']); } // title $title = Skin::build_link(Articles::get_permalink($article), $title, 'article'); // poster $poster = Users::get_link($article['create_name'], $article['create_address'], $article['create_id']); // comments $comments = Comments::count_for_anchor('article:' . $article['id']); // last editor $action = ''; if ($article['edit_date']) { // label the action if (isset($article['edit_action'])) { $action = Anchors::get_action_label($article['edit_action']); } else { $action = i18n::s('edited'); } $action = '<span class="details">' . $action . ' ' . Skin::build_date($article['edit_date']) . '</span>'; } // this is another row of the output $text .= '<tr class="' . $class_detail . '"><td>' . $title . $flag . '</td><td>' . $poster . '</td><td style="text-align: center;">' . $comments . '</td><td>' . $action . '</td></tr>' . "\n"; } } // more details $details = array(); // board introduction if ($item['introduction']) { $details[] = Codes::beautify_introduction($item['introduction']); } // indicate the total number of threads here if (($count = Articles::count_for_anchor('section:' . $item['id'])) && $count >= 5) { $details[] = sprintf(i18n::s('%d threads'), $count) . ' »'; } // link to the section index page if ($details) { $details = Skin::build_link(Sections::get_permalink($item), join(' - ', $details), 'basic'); } else { $details = ''; } // add a command for new post $poster = ''; if (Surfer::is_empowered()) { $poster = Skin::build_link('articles/edit.php?anchor=' . urlencode('section:' . $item['id']), i18n::s('Add a page') . ' »', 'basic'); } // insert details in a separate row if ($details || $poster) { $text .= '<tr class="' . $class_detail . '"><td colspan="3">' . $details . '</td><td>' . $poster . '</td></tr>' . "\n"; } // more details $more = array(); // board moderators if ($moderators = Sections::list_editors_by_name($item, 0, 7, 'comma5')) { $more[] = sprintf(i18n::ns('Moderator: %s', 'Moderators: %s', count($moderators)), $moderators); } // children boards if ($children =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, COMPACT_LIST_SIZE, 'compact')) { $more[] = sprintf(i18n::ns('Child board: %s', 'Child boards: %s', count($children)), Skin::build_list($children, 'comma')); } // as a compact list if (count($more)) { $content = '<ul class="compact">'; foreach ($more as $list_item) { $content .= '<li>' . $list_item . '</li>' . "\n"; } $content .= '</ul>' . "\n"; // insert details in a separate row $text .= '<tr class="' . $class_detail . '"><td colspan="4">' . $content . '</td></tr>' . "\n"; } } // end of processing SQL::free($result); $text .= Skin::table_suffix(); return $text; }
/** * render a compact list of voted pages * * @param string the anchor (e.g. 'section:123') * @param string layout to use * @return string the rendered text **/ public static function render_voted($anchor = '', $layout = 'simple') { global $context; // we return some text; $text = ''; // number of items to display $count = COMPACT_LIST_SIZE; if (($position = strpos($anchor, ',')) !== FALSE) { $count = (int) trim(substr($anchor, $position + 1)); if (!$count) { $count = COMPACT_LIST_SIZE; } $anchor = trim(substr($anchor, 0, $position)); } // scope is limited to current surfer if ($anchor == 'self' && Surfer::get_id()) { $anchor = 'user:'******'section:') === 0) { // look at this branch of the content tree $anchors = Sections::get_branch_at_anchor($anchor); // query the database and layout that stuff $text =& Articles::list_for_anchor_by('rating', $anchors, 0, $count, $layout); // scope is limited to pages of one surfer } elseif (strpos($anchor, 'user:'******'rating', substr($anchor, 5), 0, $count, $layout); } else { $text =& Articles::list_by('rating', 0, $count, $layout); } // we have an array to format if (is_array($text)) { $text =& Skin::build_list($text, $layout); } // job done return $text; }
/** * list sections * * @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; } // the maximum number of items per section if (!defined('MAXIMUM_ITEMS_PER_SECTION')) { define('MAXIMUM_ITEMS_PER_SECTION', 50); } // we return plain text $text = ''; // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; while ($item = SQL::fetch($result)) { // 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); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag sections that are draft, dead, or created or updated very recently if ($item['activation_date'] >= $context['now']) { $prefix .= DRAFT_FLAG; } elseif ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } if ($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; } // one box per section $box = array('title' => '', 'text' => ''); // add a direct link to the section $box['title'] = $prefix . Skin::build_link($url, $title, 'basic') . $suffix; // box content $elements = array(); // info on related articles if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } $items =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact'); if (@count($items)) { foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'article') . $suffix; } } // info on related files if (Sections::has_option('files_by', $anchor, $item) == 'title') { $items = Files::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact'); } else { $items = Files::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact'); } if ($items) { foreach ($items as $url => $label) { if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'file') . $suffix; } } // info on related comments if ($items = Comments::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact', TRUE)) { foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'comment') . $suffix; } } // list related sections, if any if ($items =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact')) { foreach ($items as $url => $label) { $prefix = $suffix = ''; if (is_array($label)) { $prefix = $label[0]; $suffix = $label[2]; $label = $label[1]; } $elements[] = $prefix . Skin::build_link($url, $label, 'section') . $suffix; } } // signal continuing sections if (count($elements) > MAXIMUM_ITEMS_PER_SECTION) { $elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('More pages') . MORE_IMG, 'basic'); } elseif (!count($elements) && Surfer::is_associate()) { $elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'shortcut'); } // make a full list if (count($elements)) { $box['text'] = '<ul><li>' . implode('</li>' . "\n" . '<li>', $elements) . '</li></ul>' . "\n"; } // always make a box $text .= Skin::build_box($box['title'], $box['text']); } // end of processing SQL::free($result); return $text; }