Пример #1
0
 /**
  * Include page
  *
  * @access tatic
  * @param string $page
  * @param array $options
  * @param array $syntax
  * @return string html
  */
 function display_include($page, $options, $syntax)
 {
     global $vars;
     $lines = get_source($page);
     if (is_array($options['section'])) {
         $lines = PluginIncludex::get_sections($lines, $page, $options['section']);
     }
     if (isset($options['readmore'])) {
         $toc = new PluginSonotsToc($page, $options['section']['cache']);
         $readmore = $toc->get_readmore();
         if (isset($readmore)) {
             $last = key(array_keys($lines));
             switch ($options['readmore']) {
                 case 'until':
                     for ($i = $readmore; $i <= $last; ++$i) {
                         if (isset($lines[$i])) {
                             unset($lines[$i]);
                         }
                     }
                     break;
                 case 'from':
                     for ($i = 0; $i <= $readmore; ++$i) {
                         if (isset($lines[$i])) {
                             unset($lines[$i]);
                         }
                     }
                     break;
             }
         }
     }
     if (isset($options['filter'])) {
         $lines = sonots::grep_array('/' . str_replace('/', '\\/', $options['filter']) . '/', $lines, 'preg', TRUE);
     }
     if (isset($options['except'])) {
         $lines = sonots::grep_array('/' . str_replace('/', '\\/', $options['except']) . '/', $lines, 'preg', TRUE, TRUE);
         // inverse
     }
     if (is_array($options['num'])) {
         list($offset, $length) = $options['num'];
         $lines = sonots::array_slice($lines, $offset, $length, true);
     }
     if (!$options['firsthead']) {
         // cut the headline on the first line
         $firstline = reset($lines);
         if (preg_match($syntax['headline'], $firstline)) {
             array_shift($lines);
         }
     }
     // html
     $html = sonots::get_convert_html($page, $lines);
     //if (trim($html) === '') return '';
     $titlestr = '';
     if ($options['titlestr'] !== 'off') {
         $titlestr = PluginSonotsMetapage::linkstr($page, $options['titlestr'], $vars['page'], true);
     }
     $title = PluginIncludex::display_title($page, $titlestr, $options['title'], $GLOBALS['fixed_heading_edited'], 'includex');
     $footer = '';
     if (is_string($options['permalink'])) {
         $linkstr = sonots::make_inline($options['permalink']);
         $footer = '<p class="permalink">' . make_pagelink($page, $linkstr) . '</p>';
     }
     return $title . "\n" . $html . $footer;
 }
Пример #2
0
 /**
  * Grep out array of objects by speific members
  *
  * @access public
  * @static
  * @param array $objs
  * @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
  */
 function grep_by(&$objs, $meta, $func, $pattern, $inverse = FALSE)
 {
     $metas = sonots::get_members($objs, $meta);
     $metas = sonots::grep_array($pattern, $metas, $func);
     if (!$inverse) {
         $objs = array_intersect_key($objs, $metas);
     } else {
         $objs = array_diff_key($objs, $metas);
     }
 }
Пример #3
0
 /**
  * Reverse expand_includes
  *
  * @access public
  * @return void
  * @see expand_includes
  */
 function shrink_includes()
 {
     $pages = sonots::get_members($this->headlines, 'page');
     $keys = sonots::grep_array($this->page, $pages, 'eq');
     $this->headlines = array_intersect_key($this->headlines, $keys);
 }