Esempio n. 1
0
 /**
  * check if a section can be modified
  *
  * This function returns TRUE if the section can be modified,
  * and FALSE otherwise.
  *
  * @param array a set of item attributes, aka, the target section
  * @param object an instance of the Anchor interface
  * @return TRUE or FALSE
  */
 public static function allow_modification($item, $anchor = NULL)
 {
     global $context;
     // sanity check
     if (!isset($item['id']) && !$anchor) {
         return FALSE;
     }
     // surfer is an associate
     if (Surfer::is_associate()) {
         return TRUE;
     }
     // submissions have been disallowed
     if (isset($context['users_without_submission']) && $context['users_without_submission'] == 'Y') {
         return FALSE;
     }
     // surfer owns the container or the section
     if (Sections::is_owned($item, $anchor, TRUE)) {
         return TRUE;
     }
     // allow editor of parent section, if not subscriber, to manage content, except on private sections
     if (Surfer::is_member() && is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned()) {
         return TRUE;
     }
     // section has been locked
     if (isset($item['locked']) && $item['locked'] == 'Y') {
         return FALSE;
     }
     // maybe this anonymous surfer is allowed to handle this item
     if (isset($item['handle']) && Surfer::may_handle($item['handle'])) {
         return TRUE;
     }
     // community wiki
     if (Surfer::is_logged() && Sections::has_option('members_edit', $anchor, $item)) {
         return TRUE;
     }
     // public wiki
     if (Sections::has_option('anonymous_edit', $anchor, $item)) {
         return TRUE;
     }
     // default case
     return FALSE;
 }
Esempio n. 2
0
 /**
  * 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 . '&nbsp;</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;
 }
Esempio n. 3
0
File: view.php Progetto: rair/yacs
     $context['page_menu'] = $behaviors->add_commands('sections/view.php', 'section:' . $item['id'], $context['page_menu']);
 }
 // remember surfer visit
 Surfer::is_visiting(Sections::get_permalink($item), Codes::beautify_title($item['title']), 'section:' . $item['id'], $item['active']);
 // increment silently the hits counter if not robot, nor associate, nor owner, nor at follow-up page
 if (Surfer::is_crawler() || Surfer::is_associate()) {
 } elseif (isset($item['owner_id']) && Surfer::is($item['owner_id'])) {
 } elseif (!$zoom_type) {
     $item['hits'] = isset($item['hits']) ? $item['hits'] + 1 : 1;
     Sections::increment_hits($item['id']);
 }
 // initialize the rendering engine
 Codes::initialize($cur_section->get_permalink());
 // neighbours information
 $neighbours = NULL;
 if (Sections::has_option('with_neighbours', $anchor, $item) && is_object($anchor)) {
     $neighbours = $anchor->get_neighbours('section', $item);
 }
 //
 // set page image -- $context['page_image']
 //
 // the section or the anchor icon, if any
 if (isset($item['icon_url']) && $item['icon_url']) {
     $context['page_image'] = $item['icon_url'];
 } elseif (is_object($anchor)) {
     $context['page_image'] = $anchor->get_icon_url();
 }
 //
 // set page meta_information -- $context['page_header'], etc.
 //
 // add meta information, if any
Esempio n. 4
0
 /**
  * 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;
 }