function test_depth()
 {
     $pagelist = new PluginSonotsPagelist($this->pages);
     $pagelist->gen_metas('depth');
     $depths = $pagelist->get_metas('depth');
     $truth = array(0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 4, 5 => 4);
     $this->assertTrue($depths, $truth);
     // do not use negative interval for depth
     $depth = PluginSonotsOption::parse_interval('2:3');
     list($offset, $length) = $depth;
     list($min, $max) = PluginSonotsOption::conv_interval(array($offset, $length), array(1, PHP_INT_MAX));
     $pagelist->grep_by('depth', 'ge', $min);
     $pagelist->grep_by('depth', 'le', $max);
     $pages = $pagelist->get_metas('page');
     $truth = array(1 => 'test/a', 2 => 'test/a/aa');
     $this->assertTrue($pages, $truth);
     // depth measures relname
     $pagelist = new PluginSonotsPagelist($this->pages);
     $prefix = 'test/a/';
     $pagelist->grep_by('page', 'prefix', $prefix);
     $pagelist->gen_metas('relname', array(sonots::get_dirname($prefix)));
     $pagelist->gen_metas('depth');
     $depths = $pagelist->get_metas('depth');
     $truth = array(2 => 1, 3 => 2, 4 => 2);
     $this->assertTrue($depths, $truth);
 }
Пример #2
0
/**
 * Get TITLE: line or the first headline of a page
 *
 * Usage:
 * - &get_title(page,[option])
 * Option
 * - firsthead Get the first headline instead of title
 *
 * @package    plugin
 * @license    http://www.gnu.org/licenses/gpl.html GPL v2
 * @author     sonots
 * @link       http://lsx.sourceforge.jp/?Plugin%2Fget_title.inc.php
 * @version    $Id: get_title.inc.php,v 2.0 2008-07-30 16:28:39Z sonots $
 */
function plugin_get_title_inline()
{
    $args = func_get_args();
    array_pop($args);
    $page = array_shift($args);
    $conf_options = array('firsthead' => false);
    $options = sonots::parse_options($args, $conf_options);
    if ($options['firsthead']) {
        $str = PluginSonotsMetapage::firsthead($page);
    } else {
        $str = PluginSonotsMetapage::title($page);
    }
    if (is_null($str)) {
        $str = $page;
    }
    $str = strip_htmltag(make_link($str));
    return $str;
}
Пример #3
0
 function convert()
 {
     $args = func_get_args();
     $options = $this->conf_options;
     $options = sonots::parse_options($args, $options);
     // check_options
     if ($options['limit'] === "0") {
         $options['limit'] = NULL;
     }
     if ($options['cloud'] === 'off' || $options['cloud'] === 'false') {
         $options['cloud'] = FALSE;
     }
     //print_r($options);
     $plugin_tag = new PluginSonotsTag();
     if ($options['cloud']) {
         $html = $plugin_tag->display_tagcloud($options['limit'], $options['related']);
     } else {
         $html = $plugin_tag->display_taglist($options['limit'], $options['related']);
     }
     return $html;
 }
Пример #4
0
 /**
  * Clean Table of Contents Cache Files
  */
 function clean_cache()
 {
     set_time_limit(0);
     global $vars;
     $page = isset($vars['page']) ? $vars['page'] : '';
     if ($page != '') {
         $toc = new PluginSonotsToc();
         $file = $toc->syntax['cachefile']($page);
         @unlink($file);
         if (exec_page($page, '/^#contentsx/')) {
             $body = 'Recreated a cache of ';
         } else {
             $body = 'No #contentsx in ';
         }
         $body .= make_pagelink($page);
     } else {
         $toc = new PluginSonotsToc();
         $file = $toc->syntax['cachefile']('hoge');
         $suffix = substr($file, strrpos($file, '.'));
         // remove all files
         $files = sonots::get_existfiles(CACHE_DIR, $suffix);
         foreach ($files as $file) {
             unlink($file);
         }
         // execute all pages
         $exec_pages = sonots::exec_existpages('', '/^#contentsx/');
         $links = array_map('make_pagelink', $exec_pages);
         $body = '<p>Following pages were executed to assure:</p>' . '<p>' . implode("<br />\n", $links) . '</p>';
     }
     return $body;
 }
Пример #5
0
 function r_strnatcmp($a, $b)
 {
     return sonots::r_cmp($a, $b, 'strnatcmp');
 }
Пример #6
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;
 }
 function test_string_to_array()
 {
     $str = 'A,B,indC:C,(D,E),indF:F';
     $parse = sonots::string_to_array($str);
     $truth = array('A', 'B', 'indC' => 'C', array('D', 'E'), 'indF' => 'F');
     $this->assertEqual($parse, $truth);
     $str = '';
     $parse = sonots::string_to_array($str);
     $truth = array();
     $this->assertEqual($parse, $truth);
 }
Пример #8
0
 /**
  * Display navigation
  *
  * @param array $navipages array($home, $up, $prev, $current, $next)
  * @param string $look Show DocBook 'footer' style or DocBook 'header'
  *
  * DocBook header
  * <pre>
  *     Prev          Home          Next
  * </pre>
  * DocBook footer
  * <pre>
  *     Prev          Home          Next
  *     <pagename>     Up     <pagename>
  * </pre>
  *
  * @param string $border 'off' or 'top' or 'bottom'. 
  * - 'off' shows no border.
  * - 'top' shows a border top.
  * - 'bottom' shows a border bottom. 
  * @param bool $printcss print css with html as style="" attributes. 
  * @return string html
  */
 function display_navi($navipages, $look = 'header', $border = 'off', $printcss = false)
 {
     $linkstr = $this->linkstr;
     $css = $this->css;
     $footer = $look == 'footer';
     list($home, $up, $prev, $current, $next) = $navipages;
     // get link
     $link = array();
     $link['prev'] = make_pagelink($prev, $linkstr['prev']);
     $link['home'] = $home == '' ? sonots::make_toplink($linkstr['home']) : make_pagelink($home, $linkstr['home']);
     if ($next) {
         $link['next'] = make_pagelink($next, $linkstr['next']);
     }
     if ($footer) {
         $link['up'] = make_pagelink($up, $linkstr['up']);
         $link['prevfoot'] = strip_tags(make_link(PluginSonotsMetapage::linkstr($prev, $footer, $current, true)));
         if ($next) {
             $link['nextfoot'] = strip_tags(make_link(PluginSonotsMetapage::linkstr($next, $footer, $current, true)));
         }
     }
     // html
     $html = '<div class="wrap_navix" style="margin:0px;padding:0px;">' . "\n";
     if ($border === 'top') {
         $html .= '<hr class="full_hr top"' . ($printcss ? ' style="' . $css['div.wrap_navix hr.top'] . '"' : '') . '/>' . "\n";
     }
     $html .= '<ul class="navix"' . ($printcss ? ' style="' . $css['ul.navix'] . '"' : '') . '>' . "\n";
     $html .= '<li class="left"' . ($printcss ? ' style="' . $css['ul.navix li.left'] . '"' : '') . '>' . $link['prev'] . ($footer ? '<br />' . $link['prevfoot'] : '') . '</li>' . "\n";
     $html .= '<li class="center"' . ($printcss ? ' style="' . $css['ul.navix li.center'] . '"' : '') . '>' . $link['home'] . ($footer ? '<br />' . $link['up'] : '') . '</li>' . "\n";
     $html .= '<li class="right"' . ($printcss ? ' style="' . $css['ul.navix li.right'] . '"' : '') . '>' . ($next ? $link['next'] . ($footer ? '<br />' . $link['nextfoot'] : '') : '&nbsp;') . '</li>' . "\n";
     $html .= '</ul>' . "\n";
     if ($border === 'bottom') {
         $html .= '<hr class="full_hr bottom"' . ($printcss ? ' style="' . $css['div.wrap_navix hr.bottom'] . '"' : '') . '/>' . "\n";
     }
     $html .= '</div>' . "\n";
     return $html;
 }
Пример #9
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 (isset($options['depth']) || $options['tree']) {
         $pagelist->gen_metas('depth');
     }
     if (isset($options['depth'])) {
         // do not use negative interval for depth
         list($min, $max) = PluginSonotsOption::conv_interval($options['depth'], array(1, PHP_INT_MAX));
         $pagelist->grep_by('depth', 'ge', $min);
         $pagelist->grep_by('depth', 'le', $max);
     }
     switch ($options['tree']) {
         case 'leaf':
             $pagelist->gen_metas('leaf');
             $pagelist->grep_by('leaf', 'eq', true);
             break;
         case 'dir':
             $pagelist->gen_metas('leaf');
             $pagelist->grep_by('leaf', 'eq', false);
             break;
         default:
             break;
     }
     if (isset($options['popular'])) {
         $pagelist->gen_metas('popular', array($options['popular']));
     }
     $pagelist->sort_by('popular', $options['reverse']);
     $max = count($pagelist->metapages);
     // for next option
     if (is_array($options['num'])) {
         list($offset, $length) = $options['num'];
         $pagelist->slice($offset, $length);
     }
     //// display
     $pagelist->gen_metas('linkstr', array($options['linkstr']));
     $linkstrs = $pagelist->get_metas('linkstr');
     $pages = $pagelist->get_metas('page');
     $counts = $pagelist->get_metas('popular');
     $links = $this->get_popular_links($pages, $linkstrs, $counts, $GLOBALS['var']['page']);
     if (empty($links)) {
         return '<p>#' . $this->plugin . '(): no counter information is available.</p>';
     }
     $levels = array_map(create_function('', 'return 1;'), $links);
     $html = sonots::display_list($links, $levels, 'popularx');
     //// display navi. $max is needed, $argoptions is need.
     if ($options['next'] && is_array($options['num'])) {
         $argoptions['popular'] = $options['popular'];
         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;
 }
 function test_relname()
 {
     $this->assertEqual(PluginSonotsMetapage::relname('Hoge/A', ''), 'Hoge/A');
     $this->assertEqual(PluginSonotsMetapage::relname('Hoge/A', sonots::get_dirname('Hoge/')), 'A');
 }
Пример #11
0
 /**
  * Get link of a page
  * 
  * @access public
  * @static
  * @param string $page pagename
  * @param string $linkstr linkstr
  * @param string $option option
  * - page   : link to page
  * - anchor : link to anchor
  * - off    : no link
  * @return string
  * @uses sonots::make_pagelink_nopg
  * @uses sonots::make_pageanchor
  */
 function link($page, $linkstr, $option)
 {
     switch ($option) {
         case 'page':
             $link = sonots::make_pagelink_nopg($page, $linkstr);
             break;
         case 'anchor':
             $anchor = sonots::make_pageanchor($page);
             $link = sonots::make_pagelink_nopg('', $linkstr, '#' . $anchor);
             break;
         case 'off':
             $link = $linkstr;
             break;
     }
     return $link;
 }
Пример #12
0
 /**
  * Get <h1> title of a page
  * 
  * @access static
  * @param string $page pagename
  * @param string $titlestr titlestr
  * @param boolean $link link to page or not
  * @param boolean $editlink add edit link icon or not
  * @param string $cssclass
  * @return $string html
  */
 function display_title($page, $titlestr = '', $link = FALSE, $editlink = FALSE, $cssclass = '')
 {
     $aname = ' ' . sonots::make_pageanamelink_icon($page);
     $edit = '';
     if ($titlestr == '') {
         return '<div class="' . $cssclass . '" style="padding:0px;margin:0px;">' . $aname . '</div>';
     }
     if ($editlink) {
         $edit = ' ' . sonots::make_pageeditlink_icon($page);
     }
     if ($link) {
         $titlestr = make_pagelink($page, $titlestr);
     }
     return '<h1 class="' . $cssclass . '">' . $titlestr . $edit . $aname . '</h1>';
 }
Пример #13
0
 /**
  * Recover option line, but into GET argument style such as
  *  opt1=val1&opt2=val2&opt3=(a&b)
  * Note that this is not inverse of parse_uri_option_line exactly
  * because parse_uri_option_line assumes input variables are already
  * rawurldecoded, but this performs rawurlencode.
  *
  * @access public
  * @static
  * @param array $options
  * @return string
  * @see glue_option_line
  * @see parse_uri_option_line
  * @version $Id: v 1.0 2008-07-16 11:14:46 sonots $
  * @since   v 1.8
  */
 function glue_uri_option_line($options)
 {
     $array = PluginSonotsOption::boolean_to_numeric($options);
     $string = sonots::array_to_string($array, '=', '&', '(', ')', true);
     $args = explode('&', $string);
     foreach ($args as $i => $arg) {
         $vars = explode('=', $arg);
         $vars = array_map('rawurlencode', $vars);
         $args[$i] = implode('=', $vars);
     }
     return implode('&', $args);
 }
Пример #14
0
 /**
  * Convert Includeline to Headline
  *
  * @return PluginSonotsHeadline
  */
 function headline($usecache = true)
 {
     $linenum = $this->linenum;
     $depth = 0;
     $options = sonots::parse_options($this->args, array('titlestr' => 'title'));
     $string = PluginSonotsMetapage::linkstr($this->page, $options['titlestr'], $usecache);
     $anchor = sonots::make_pageanchor($this->page);
     return new PluginSonotsHeadline($this->page, $linenum, $depth, $string, $anchor);
 }
Пример #15
0
 /**
  * Get HTML of page list
  *
  * @access public
  * @param string $cssclass css class
  * @return string list html
  * @version $Id: v 1.0 2008-06-07 07:23:17Z sonots $
  */
 function display_pages($cssclass = '')
 {
     $items = $this->get_metas('link');
     $levels = $this->get_metas('depth');
     return sonots::display_list($items, $levels, $cssclass);
 }
Пример #16
0
 /**
  * Clean Tag Caches
  *
  * @return string HTML
  */
 function clean_cache()
 {
     set_time_limit(0);
     global $vars;
     // remove all files
     $pkwk_tag = new PluginSonotsTag();
     $files = $pkwk_tag->get_items_filenames();
     $files = array_merge($files, $pkwk_tag->get_tags_filenames());
     $files[] = $pkwk_tag->get_tagcloud_filename();
     foreach ($files as $file) {
         unlink($file);
     }
     // execute all pages
     $exec_pages = sonots::exec_existpages('', '/&tag\\([^;]*\\);/');
     if (empty($exec_pages)) {
         $html = '';
     } else {
         $links = array_map('make_pagelink', $exec_pages);
         $html = '<p>Following pages were executed to assure:</p>' . '<p>' . implode("<br />\n", $links) . '</p>';
     }
     $html .= $pkwk_tag->display_tagcloud();
     return $html;
 }