Ejemplo n.º 1
0
 function get_title($inclpage, $titlestr, $option = true)
 {
     global $fixed_heading_edited;
     $anchorlink = ' ' . PluginIncludex::get_page_anchorlink($inclpage);
     $editlink = $fixed_heading_edited ? ' ' . PluginIncludex::get_page_editlink($inclpage) : '';
     if ($titlestr == '') {
         //return $ret = '<div class="' .$this->plugin . '">' . $anchorlink . '</div>';
         return '';
     }
     switch ($option) {
         case false:
             $ret = '<h1 class="includex">' . $titlestr . $editlink . $anchorlink . '</h1>';
             break;
         case true:
         default:
             $link = make_pagelink($inclpage, $titlestr);
             $ret = '<h1 class="includex">' . $link . $editlink . $anchorlink . '</h1>';
             break;
     }
     return $ret;
 }
Ejemplo n.º 2
0
 function r_metalines($page, $detected = false)
 {
     if (array_key_exists($page, $this->visited)) {
         return array();
     }
     if (!is_page($page)) {
         return array();
     }
     $this->visited[$page] = '';
     $lines = $this->get_source($page);
     $multiline = 0;
     $metalines = array();
     foreach ($lines as $i => $line) {
         // multiline plugin. refer lib/convert_html
         if (defined('PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK') && PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK === 0) {
             $matches = array();
             if ($multiline < 2) {
                 if (preg_match('/^#([^\\(\\{]+)(?:\\(([^\\r]*)\\))?(\\{*)/', $line, $matches)) {
                     $multiline = strlen($matches[3]);
                 }
             } else {
                 if (preg_match('/^\\}{' . $multiline . '}$/', $line, $matches)) {
                     $multiline = 0;
                 }
                 continue;
             }
         }
         // fromhere
         if ($this->options['page'][1] == $page && !$detected) {
             if (preg_match('/^#' . $this->plugin . '/', $line, $matches)) {
                 $detected = true;
                 continue;
             }
         }
         if (preg_match($this->conf['def_headline'], $line, $matches)) {
             $depth = strlen($matches[1]);
             $anchor = '#' . $this->make_heading($line);
             // *** [id] is removed from $line
             $headline = trim($line);
             $metalines[] = array(page => $page, headline => $headline, anchor => $anchor, depth => $depth, linenum => $i, fromhere => $detected);
             continue;
         }
         if (preg_match($this->conf['def_include'], $line, $matches)) {
             $args = csv_explode(',', $matches[1]);
             $inclpage = array_shift($args);
             $options = array();
             foreach ($args as $arg) {
                 list($key, $val) = array_pad(explode('=', $arg, 2), 2, true);
                 $options[$key] = $val;
             }
             $inclpage = get_fullname($inclpage, $page);
             if (!$this->is_page($inclpage)) {
                 continue;
             }
             // $anchor = PluginIncludex::get_page_anchor($inclpage)
             $anchor = 'z' . md5($inclpage);
             $anchor = '#' . htmlspecialchars($anchor);
             if (exist_plugin('includex') & is_callable(array('PluginIncludex', 'get_titlestr'))) {
                 $titlestr = PluginIncludex::get_titlestr($inclpage, $options['titlestr']);
             } else {
                 $titlestr = $inclpage;
             }
             $metalines[] = array(page => $inclpage, headline => $titlestr, anchor => $anchor, depth => 0, linenum => $i, fromhere => $detected);
             $metalines = array_merge($metalines, $this->r_metalines($inclpage, $detected));
             continue;
         }
         if (preg_match($this->conf['def_title'], $line, $matches)) {
             $title = $matches[1];
             $this->visited[$page] = $title;
             continue;
         }
     }
     return $metalines;
 }
Ejemplo n.º 3
0
 /**
  * List pages
  *
  * @param array $pages
  * @param array $options
  * @param array $argoptions
  * @return string html
  */
 function pagelist($pages, $options, $argoptions)
 {
     $pagelist = new PluginSonotsPagelist($pages);
     if ($options['non_list']) {
         $pattern = '/' . $GLOBALS['non_list'] . '/';
         $pagelist->grep_by('page', 'preg', $pattern, true);
         // inverse
     }
     if (isset($options['filter']) && $options['filter'] !== '') {
         $pagelist->grep_by('relname', 'preg', '/' . str_replace('/', '\\/', $options['filter']) . '/');
     }
     if (isset($options['except'])) {
         $pagelist->grep_by('relname', 'preg', '/' . str_replace('/', '\\/', $options['except']) . '/', true);
         // inverse
     }
     if (isset($options['newpage'])) {
         switch ($options['newpage']) {
             case 'on':
                 $pagelist->gen_metas('newpage');
                 $pagelist->grep_by('newpage', 'eq', true);
                 break;
             case 'except':
             case 'off':
                 $pagelist->gen_metas('newpage');
                 $pagelist->grep_by('newpage', 'eq', false);
                 break;
             default:
                 break;
         }
     }
     if (is_array($options['info']) || $options['sort'] === 'date') {
         $pagelist->gen_metas('timestamp');
     }
     if ($options['sort'] === 'popular') {
         $pagelist->gen_metas('popular', array($options['popular']));
     }
     if ($options['sort'] === 'reading') {
         $pagelist->gen_metas('reading');
     }
     if ($options['sort'] === 'title') {
         $pagelist->gen_metas('title');
     }
     $pagelist->sort_by($options['sort'], $options['reverse']);
     $max = count($pagelist->metapages);
     // for next option
     if (is_array($options['num'])) {
         list($offset, $length) = $options['num'];
         $pagelist->slice($offset, $length);
     }
     //// display
     if (isset($options['include'])) {
         $pages = $pagelist->get_metas('page');
         $include = new PluginIncludex();
         // just want static var
         $includes = array();
         foreach ($pages as $i => $page) {
             $includes[$i] = PluginIncludex::display_include($page, $options['include'], $include->syntax);
         }
         $html = implode("\n", $includes);
     } else {
         $pagelist->init_metas('depth', 1);
         $pagelist->gen_metas('link', array($options['linkstr'], $options['link']));
         $links = $pagelist->get_metas('link');
         $infos = array();
         if (is_array($options['info'])) {
             $pagelist->gen_metas('info', array($options['info']));
             $infos = $pagelist->get_metas('info');
         }
         $tocs = array();
         if (isset($options['contents'])) {
             $pages = $pagelist->get_metas('page');
             foreach ($pages as $i => $page) {
                 $toc_options = PluginContentsx::check_options($page, '', $options['contents']);
                 $tocs[$i] = PluginContentsx::display_toc($page, $toc_options);
             }
         }
         $items = array();
         foreach ($links as $i => $link) {
             $items[$i] = $links[$i];
             if (isset($infos[$i])) {
                 $items[$i] .= ' ' . $infos[$i];
             }
             if (isset($tocs[$i])) {
                 $items[$i] .= $tocs[$i];
             }
         }
         $levels = $pagelist->get_metas('depth');
         $html = sonots::display_list($items, $levels, $this->plugin);
     }
     if ($options['next'] && is_array($options['num'])) {
         $argoptions['tag'] = $options['tag'];
         unset($argoptions['num']);
         $argoptions = array_intersect_key($argoptions, $options);
         $argline = PluginSonotsOption::glue_uri_option_line($argoptions);
         $basehref = get_script_uri() . '?cmd=' . $this->plugin;
         $basehref .= empty($argline) ? '' : '&amp;' . htmlspecialchars($argline);
         $current = PluginSonotsOption::conv_interval($options['num']);
         $html .= $pagelist->display_navi($current, array(1, $max), $basehref, $this->plugin);
     }
     return $html;
 }
Ejemplo n.º 4
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;
 }