Ejemplo n.º 1
0
 /**
  * build a contextual menu for this page
  *
  * You can overload this function in your own skin to change this behaviour.
  *
  * @param array path of anchors to the current page
  * @return string to be inserted in the returned web page
  *
  * @see articles/view.php
  * @see sections/view.php
  */
 public static function &build_contextual_menu($anchors)
 {
     global $context;
     // build the contextual tree
     $tree = array();
     // list underneath level
     if ($children = Sections::get_children_of_anchor($anchors[count($anchors) - 1])) {
         // place children
         foreach ($children as $child) {
             if ($anchor = Anchors::get($child)) {
                 $tree[] = array($anchor->get_url(), NULL, $anchor->get_title(), NULL, 'below', NULL, $anchor->get_teaser('hover'));
             }
         }
     }
     // ensure minimum depth
     if (count($anchors) < 2) {
         $text = Skin::build_tree($tree);
         return $text;
     }
     // current level
     if ($anchor = Anchors::get($anchors[count($anchors) - 1])) {
         $tree = array(array_merge(array($anchor->get_url(), NULL, $anchor->get_title(), NULL, 'current', NULL, $anchor->get_teaser('hover')), array($tree)));
     }
     // upper levels
     for ($index = count($anchors) - 2; $index >= 0; $index--) {
         // get nibbles
         if ($nibbles = Sections::get_children_of_anchor($anchors[$index])) {
             // list nibbles
             $insert = TRUE;
             $prefix = array();
             foreach ($nibbles as $nibble) {
                 // match the item that has the focus
                 if ($nibble == $anchors[$index + 1]) {
                     $insert = FALSE;
                     continue;
                 }
                 // list nibble before or after the one that has he focus
                 if ($anchor = Anchors::get($nibble)) {
                     if ($insert) {
                         $prefix[] = array($anchor->get_url(), NULL, $anchor->get_title(), NULL, 'close', NULL, $anchor->get_teaser('hover'));
                     } else {
                         $tree[] = array($anchor->get_url(), NULL, $anchor->get_title(), NULL, 'close', NULL, $anchor->get_teaser('hover'));
                     }
                 }
             }
             // preserve ordering
             $tree = array_merge($prefix, $tree);
         }
         // move up the contextual path
         if ($index > 0 && ($anchor = Anchors::get($anchors[$index]))) {
             $tree = array(array_merge(array($anchor->get_url(), NULL, $anchor->get_title(), NULL, 'open', NULL, $anchor->get_teaser('hover')), array($tree)));
         }
     }
     // transform this structure to XHTML
     $text =& Skin::build_tree($tree, 0, 'contextual_menu_focus');
     return $text;
 }
Ejemplo n.º 2
0
 /**
  * get containers of one branch of the content tree
  *
  * This function provides references to the target section, and also of sub-sections.
  * It looks iteratively into up to 5 levels of sub-sections.
  *
  * @param string the reference of the target section (e.g., 'section:123')
  * @return an array of references (e.g., array('section:123', 'section:456', 'section:789'))
  */
 public static function get_branch_at_anchor($anchor = NULL, $with_top = true)
 {
     global $context;
     // look for children
     $anchors = array();
     // first level of depth
     $children = Sections::get_children_of_anchor($anchor);
     $anchors = array_merge($anchors, $children);
     // second level of depth
     if (count($children) && count($anchors) < 2000) {
         $children = Sections::get_children_of_anchor($children);
         $anchors = array_merge($anchors, $children);
     }
     // third level of depth
     if (count($children) && count($anchors) < 2000) {
         $children = Sections::get_children_of_anchor($children);
         $anchors = array_merge($anchors, $children);
     }
     // fourth level of depth
     if (count($children) && count($anchors) < 2000) {
         $children = Sections::get_children_of_anchor($children);
         $anchors = array_merge($anchors, $children);
     }
     // fifth level of depth
     if (count($children) && count($anchors) < 2000) {
         $children = Sections::get_children_of_anchor($children);
         $anchors = array_merge($anchors, $children);
     }
     // also include the top level, of course
     if ($with_top) {
         $anchors[] = $anchor;
     }
     // all children included, from several levels
     return $anchors;
 }
Ejemplo n.º 3
0
Archivo: codes.php Proyecto: rair/yacs
 /**
  * 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;
 }