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 pages used for Navi
  *
  * @access global
  * @param object $pagelist PluginSonotsPagelist object
  * @param array $options
  * @return array $navipages array($home, $up, $prev, $current, $next)
  */
 function get_navipages($pagelist, $options)
 {
     global $vars, $defaultpage;
     $current = $vars['page'];
     $home = $options['home'];
     $up = sonots::get_dirname($current);
     $pages = $pagelist->get_metas('page');
     $prev = $home;
     foreach ($pages as $page) {
         if ($page == $current) {
             break;
         }
         $prev = $page;
     }
     $next = current($pages);
     return array($home, $up, $prev, $current, $next);
 }
 function test_relname()
 {
     $this->assertEqual(PluginSonotsMetapage::relname('Hoge/A', ''), 'Hoge/A');
     $this->assertEqual(PluginSonotsMetapage::relname('Hoge/A', sonots::get_dirname('Hoge/')), 'A');
 }
Пример #4
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 (isset($options['prefix']) && $options['prefix'] !== '') {
         $pagelist->gen_metas('relname', array(sonots::get_dirname($options['prefix'])));
     }
     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['hierarchy'] || $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 (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 {
         if ($options['hierarchy']) {
             if ($pagelist->pad_dirnodes($options['prefix'])) {
                 $pagelist->sort_by($options['sort'], $options['reverse']);
             }
         } 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);
     }
     //// display navi. $max is needed, $argoptions is need.
     if ($options['next'] && is_array($options['num'])) {
         $argoptions['prefix'] = $options['prefix'];
         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) ? '' : '&' . htmlspecialchars($argline);
         $current = PluginSonotsOption::conv_interval($options['num']);
         $html .= $pagelist->display_navi($current, array(1, $max), $basehref, $this->plugin);
     }
     return $html;
 }
 /**
  * Pad non existing dir nodes to construct hierarchical tree
  *
  * Example)
  *  A       A
  *  A/A =>  A/A
  *  B/B     B(non exist)
  *          B/B
  *
  * @access public
  * @param string $prefix current path (need to create relname)
  * @return boolean some intances were added or not
  * @version $Id: v 1.1 2008-06-07 07:23:17Z sonots $
  */
 function pad_dirnodes($prefix)
 {
     $origsize = count($this->metapages);
     $prefix = sonots::get_dirname($prefix);
     $prefix = empty($prefix) ? '' : $prefix . '/';
     $paths = $this->get_metas('relname');
     foreach ($paths as $i => $path) {
         $currpath = $path;
         while (TRUE) {
             if ($currpath == '') {
                 break;
             }
             // if parent dir does not exist, pad
             if (($j = array_search($currpath, $paths)) === FALSE) {
                 $abspath = $prefix . $currpath;
                 $new = new PluginSonotsMetapage($abspath);
                 $new->reading = $abspath;
                 $new->relname = $currpath;
                 $new->depth = substr_count($currpath, '/') + 1;
                 $new->timestamp = 1;
                 $new->date = '';
                 $new->leaf = FALSE;
                 $new->exist = FALSE;
                 $this->metapages[] = $new;
                 $paths[] = $currpath;
             }
             $currpath = sonots::get_dirname($currpath);
         }
     }
     return count($this->metapages) > $origsize;
 }