Пример #1
0
 function get_sections($lines, $page, $options)
 {
     $toc = new PluginSonotsToc($page, $options['cache']);
     $headlines = $toc->get_headlines();
     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);
     }
     $outlines = array();
     if (is_array($options['num'])) {
         array_unshift($headlines, new PluginSonotsHeadline($page, 0, 0, '', ''));
         list($offset, $length) = $options['num'];
         $headlines = sonots::array_slice($headlines, $offset, $length, true);
     }
     $linenums = sonots::get_members($headlines, 'linenum');
     // extract from current head till next head - 1
     $allheadlines = $toc->get_headlines();
     $alllinenums = sonots::get_members($allheadlines, 'linenum');
     if (!isset($alllinenums[0])) {
         array_unshift($alllinenums, 0);
     }
     // virtual head at the file head
     array_push($alllinenums, end(array_keys($lines)) + 1);
     // virtual head at the file tail
     $outlines = array();
     $current = 0;
     foreach ($alllinenums as $next) {
         if (in_array($current, $linenums)) {
             if ($next == $current) {
                 continue;
             }
             $outlines += sonots::array_slice($lines, $current, $next - $current, true);
         }
         $current = $next;
     }
     return $outlines;
 }
Пример #2
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;
 }
 /**
  * Grep out metapages by speific fields
  *
  * @access public
  * @param string $meta name of meta information to be greped
  * @param string $func func name
  *  - preg     : grep by preg
  *  - ereg     : grep by ereg
  *  - mb_ereg  : grep by mb_ereg
  *  - prefix   : remains if prefix matches (strpos)
  *  - mb_prefix: (mb_strpos)
  *  - eq       : remains if equality holds
  *  - ge       : remains if greater or equal to
  *  - le       : remains if less or equal to
  * @param mixed $pattern
  * @param boolean $inverse grep -v
  * @return void
  * @version $Id: v 1.0 2008-06-07 07:23:17Z sonots $
  */
 function grep_by($meta, $func, $pattern, $inverse = FALSE)
 {
     sonots::grep_by($this->metapages, $meta, $func, $pattern, $inverse);
 }