예제 #1
0
 /**
  * Display Table of Contents
  *
  * @access static
  * @param string $page
  * @param array $options
  * @return string html
  */
 function display_toc($page, $options)
 {
     $toc = new PluginSonotsToc($page, $options['cache']);
     if ($options['include']) {
         $toc->expand_includes();
     }
     $headlines = $toc->get_headlines();
     if ($options['fromhere']) {
         $fromhere = $toc->get_fromhere();
         $offset = 0;
         $headline = reset($headlines);
         while (!($headline->page === $page && $headline->linenum > $fromhere)) {
             ++$offset;
             if (($headline = next($headlines)) === false) {
                 break;
             }
         }
         $headlines = sonots::array_slice($headlines, $offset, null, true);
     }
     if (isset($options['filter'])) {
         sonots::grep_by($headlines, 'string', 'preg', '/' . str_replace('/', '\\/', $options['filter']) . '/');
     }
     if (isset($options['except'])) {
         sonots::grep_by($headlines, 'string', 'preg', '/' . str_replace('/', '\\/', $options['except']) . '/', true);
         // inverse
     }
     if (is_array($options['depth'])) {
         // Do not use negative offsets
         list($min, $max) = PluginSonotsOption::conv_interval($options['depth'], array(1, PHP_INT_MAX));
         sonots::grep_by($headlines, 'depth', 'ge', $min);
         sonots::grep_by($headlines, 'depth', 'le', $max);
     }
     if (is_array($options['num'])) {
         list($offset, $length) = $options['num'];
         $headlines = sonots::array_slice($headlines, $offset, $length, true);
     }
     if ($options['hierarchy']) {
         if ($options['include'] && count($toc->get_includes()) >= 1) {
             // depth of included page is 0, shift up
             sonots::map_members($headlines, 'depth', create_function('$x', 'return $x+1;'));
         }
         if ($options['compact']) {
             PluginSonotsToc::compact_depth($headlines);
         }
     } else {
         sonots::init_members($headlines, 'depth', 1);
         // flatten (to all 1)
     }
     $html = PluginSonotsToc::display_toc($headlines, 'contentsx', $options['link']);
     return $html;
 }