Exemplo n.º 1
0
 /**
  * Block Plugin Main Function
  */
 function convert()
 {
     sonots::init_myerror();
     do {
         // try
         $args = func_get_args();
         $argline = csv_implode(',', $args);
         $argoptions = PluginSonotsOption::parse_option_line($argline);
         list($options, $unknowns) = PluginSonotsOption::evaluate_options($argoptions, $this->conf_options);
         $options = $this->check_options($options, $unknowns, $this->conf_options);
         if (sonots::mycatch()) {
             break;
         }
         if (isset($options['tag'])) {
             $plugin_tag = new PluginSonotsTag();
             $pages = $plugin_tag->get_taggedpages($options['tag']);
         } elseif (isset($options['prefix'])) {
             $pages = sonots::get_existpages($options['prefix']);
         } else {
             $pages = get_existpages();
         }
         $pagelist = $this->pagelist($pages, $options, $argoptions);
         $navipages = $this->get_navipages($pagelist, $options);
         $html = $this->display_navi($navipages, $options['look'], $options['border'], $this->conf['printcss']);
         return $html;
     } while (false);
     if (sonots::mycatch()) {
         // catch
         return '<p>#' . $this->plugin . '(): ' . sonots::mycatch() . '</p>';
     }
 }
Exemplo n.º 2
0
 /**
  * Block Plugin Main Function
  */
 function convert()
 {
     sonots::init_myerror();
     do {
         // try
         global $vars, $defaultpage;
         $args = func_get_args();
         $line = csv_implode(',', $args);
         $options = PluginSonotsOption::parse_option_line($line);
         list($options, $unknowns) = PluginSonotsOption::evaluate_options($options, $this->conf_options);
         $current = isset($vars['page']) ? $vars['page'] : $defaultpage;
         $page = isset($options['page']) ? $options['page'] : $current;
         $page = PluginContentsx::check_page($page, $current);
         $options = PluginContentsx::check_options($page, $current, $options, $unknowns);
         if (sonots::mycatch()) {
             break;
         }
         $html = PluginContentsx::display_toc($page, $options);
         if ($html != '') {
             $html = '<table border="0" class="toc"><tbody>' . "\n" . '<tr><td class="toctitle">' . "\n" . '<span>' . _('Table of Contents') . "</span>\n" . "</td></tr>\n" . '<tr><td class="toclist">' . "\n" . $html . "</td></tr>\n" . "</tbody></table>\n";
         }
         return $html;
     } while (false);
     if (sonots::mycatch()) {
         // catch
         return '<p>#contentsx(): ' . sonots::mycatch() . '</p>';
     }
 }
Exemplo n.º 3
0
 /**
  * Convert Plugin Main Function
  */
 function convert()
 {
     global $vars, $defaultpage;
     sonots::init_myerror();
     do {
         // try
         $args = func_get_args();
         $inclpage = array_shift($args);
         $current = isset($vars['page']) ? $vars['page'] : $defaultpage;
         $this->visited[$current] = TRUE;
         $inclpage = PluginIncludex::check_page($inclpage, $current, $this->visited);
         if (sonots::mycatch()) {
             break;
         }
         $this->visited[$inclpage] = TRUE;
         $argline = csv_implode(',', $args);
         $argoptions = PluginSonotsOption::parse_option_line($argline);
         list($options, $unknowns) = PluginSonotsOption::evaluate_options($argoptions, $this->conf_options);
         $options = PluginIncludex::check_options($options, $unknowns, $argoptions);
         if (sonots::mycatch()) {
             break;
         }
         $html = PluginIncludex::display_include($inclpage, $options, $this->syntax);
         return $html;
     } while (false);
     if (sonots::mycatch()) {
         // catch
         return '</p>#includex(): ' . sonots::mycatch() . '</p>';
     }
 }
Exemplo n.º 4
0
 /**
  * Action Plugin Main Function
  */
 function action()
 {
     sonots::init_myerror();
     do {
         // try
         global $vars;
         $argoptions = PluginSonotsOption::parse_uri_option_line($vars);
         $argoptions = array_intersect_key($argoptions, $this->conf_options);
         list($options, $unknowns) = PluginSonotsOption::evaluate_options($argoptions, $this->conf_options);
         $options = $this->check_options($options, array(), $this->conf_options);
         if (sonots::mycatch()) {
             break;
         }
         $pages = get_existpages();
         $title = $this->plugin;
         $html = $this->pagelist($pages, $options, $argoptions);
         return array('msg' => $title, 'body' => $html);
     } while (false);
     if (sonots::mycatch()) {
         // catch
         return array('msg' => $this->plugin, 'body' => '<p>' . sonots::mycatch() . '</p>');
     }
 }
Exemplo n.º 5
0
 /**
  * Action Plugin Main Function
  */
 function action()
 {
     sonots::init_myerror();
     do {
         // try
         global $vars;
         $argoptions = PluginSonotsOption::parse_uri_option_line($vars);
         $argoptions = array_intersect_key($argoptions, $this->conf_options);
         list($options, $unknowns) = PluginSonotsOption::evaluate_options($argoptions, $this->conf_options);
         $options = $this->check_options($options, array(), $this->conf_options);
         if (sonots::mycatch()) {
             break;
         }
         if (isset($options['tag'])) {
             $plugin_tag = new PluginSonotsTag();
             $pages = $plugin_tag->get_taggedpages($options['tag']);
             $title = _('List of pages tagged by "') . htmlspecialchars($options['tag']) . '"';
             $html = $this->pagelist($pages, $options, $argoptions);
         } else {
             $plugin_tag = new PluginSonotsTag();
             if (isset($options['related'])) {
                 $tags = $plugin_tag->get_related_tags($options['related']);
                 $title = _('List of tags related to "') . htmlspecialchars($options['related']) . _('" and their tagged pages');
             } else {
                 $tags = $plugin_tag->get_existtags();
                 $title = _('List of all tags and their tagged pages');
             }
             $html = $this->tagpagelist($tags, $options, $argoptions);
         }
         if (empty($html)) {
             $html = '<p>' . _('No page found.') . '</p>';
         }
         return array('msg' => $title, 'body' => $html);
     } while (false);
     if (sonots::mycatch()) {
         // catch
         return array('msg' => $this->plugin, 'body' => '<p>' . sonots::mycatch() . '</p>');
     }
 }
 function test_evaluate_options()
 {
     $conf_options = array('hierarchy' => array('bool', true), 'num' => array('interval', null), 'filter' => array('string', null), 'sort' => array('enum', 'name', array('name', 'reading', 'date')));
     $options = array('Hoge/' => true, 'filter' => 'AAA');
     list($options, $unknowns) = PluginSonotsOption::evaluate_options($options, $conf_options);
     $truth = array('hierarchy' => true, 'num' => null, 'filter' => 'AAA', 'sort' => 'name');
     $this->assertIdentical($options, $truth);
     $truth = array('Hoge/' => true);
     $this->assertIdentical($unknowns, $truth);
     $conf_options = array('hierarchy' => array('bool', true), 'non_list' => array('bool', true), 'reverse' => array('bool', false), 'basename' => array('bool', false), 'sort' => array('enum', 'name', array('name', 'reading', 'date')), 'tree' => array('enum', false, array(false, 'leaf', 'dir')), 'depth' => array('interval', null), 'num' => array('interval', null), 'next' => array('bool', false), 'except' => array('string', null), 'filter' => array('string', null), 'prefix' => array('string', null), 'contents' => array('array', null), 'include' => array('array', null), 'info' => array('enumarray', null, array('date', 'new')), 'date' => array('bool', false), 'new' => array('bool', false), 'tag' => array('string', null), 'linkstr' => array('enum', 'relative', array('relative', 'absolute', 'basename', 'title', 'headline')), 'link' => array('enum', 'page', array('page', 'anchor', 'off')), 'newpage' => array('enum', null, array('on', 'except')), 'popular' => array('enum', null, array('total', 'today', 'yesterday', 'recent')));
     $options = array('prefix' => 'Hoge/', 'num' => '1:5', 'contents' => array('num' => '1', 'firsthead'));
     list($result, $unknowns) = PluginSonotsOption::evaluate_options($options, $conf_options);
     $truth = array('hierarchy' => true, 'non_list' => true, 'reverse' => false, 'basename' => false, 'sort' => 'name', 'tree' => false, 'depth' => null, 'num' => array(0 => 0, 1 => 5), 'next' => false, 'except' => null, 'filter' => null, 'prefix' => 'Hoge/', 'contents' => array('num' => '1', 0 => 'firsthead'), 'include' => null, 'info' => null, 'date' => false, 'new' => false, 'tag' => null, 'linkstr' => 'relative', 'link' => 'page', 'newpage' => null, 'popular' => null);
     $this->assertEqual($result, $truth);
     $options[''] = TRUE;
     $options['cmd'] = 'read';
     list($result, $unknowns) = PluginSonotsOption::evaluate_options($options, $conf_options);
     $this->assertEqual($result, $truth);
     $this->assertIdentical($unknowns, array('' => TRUE, 'cmd' => 'read'));
     $conf_options = array('num' => array('interval', null), 'except' => array('string', null), 'filter' => array('string', null), 'title' => array('enum', 'on', array('on', 'off', 'nolink', 'basename')), 'titlestr' => array('enum', 'title', array('name', 'pagename', 'absolute', 'relname', 'relative', 'basename', 'title', 'headline', 'off')), 'titlelink' => array('bool', true), 'section' => array('array', null), 'permalink' => array('string', null), 'firsthead' => array('bool', true), 'section' => array('options', null, array('num' => array('interval', null), 'depth' => array('interval', null), 'except' => array('string', null), 'filter' => array('string', null), 'inclsub' => array('bool', false))));
     $options = array('num' => '1:5');
     list($result, $unknowns) = PluginSonotsOption::evaluate_options($options, $conf_options);
     $truth = array('num' => array(0 => 0, 1 => 5), 'except' => null, 'filter' => null, 'title' => 'on', 'titlestr' => 'title', 'titlelink' => true, 'section' => null, 'permalink' => null, 'firsthead' => true);
     $this->assertIdentical($result, $truth);
     $options = array('num' => '1:5', 'section' => array('num' => '1'));
     list($result, $unknowns) = PluginSonotsOption::evaluate_options($options, $conf_options);
     $truth['section'] = array('num' => array(0 => 0, 1 => 1), 'depth' => null, 'except' => null, 'filter' => null, 'inclsub' => false);
     $this->assertIdentical($result, $truth);
 }
Exemplo n.º 7
0
 /**
  * Evaluate an option
  *
  * Lists of Supported Types)
  * - bool      : boolean true or false
  * - string    : string
  * - array     : array
  * - enum      : take only one element of possible values
  * - enumarray : take only elements in possible values
  * - number    : number
  * - interval  : interval string. See parse_interval for details
  * - options   : options
  *
  * @access private
  * @static
  * @param mixed $val option value. 
  * @param string $type option type
  * @param mixed $conf config. See evaluate_options. 
  * @return array array(evaluated value, invalid value)
  * @uses parse_interval
  * @uses evaluate_options
  * @version $Id: v 1.7 2008-07-30 11:14:46 sonots $
  * @since   v 1.0
  */
 function evaluate_option($val, $type, $conf = null)
 {
     if (is_null($val)) {
         return array(null, null);
     }
     $retval = $unknown = null;
     switch ($type) {
         case 'bool':
             if ($val === true && is_bool($conf)) {
                 $retval = $conf;
                 break;
             }
             if ($val === false || $val === '0' || $val === 'off' || $val === 'false' || $val === 'FALSE') {
                 $retval = false;
             } elseif ($val === true || $val === '' || $val === '1' || $val === 'on' || $val === 'true' || $val === 'TRUE') {
                 $retval = true;
             } else {
                 $unknown = $val;
             }
             break;
         case 'string':
             if ($val === true) {
                 // no "=value" option is set to true at parse_option_line
                 $retval = is_string($conf) ? $conf : null;
                 break;
             }
             if (is_string($val)) {
                 $retval = $val;
             } else {
                 $unknown = $val;
             }
             break;
         case 'array':
             if ($val === true) {
                 // no "=value" option is set to true at parse_option_line
                 $retval = is_array($conf) ? $conf : null;
                 break;
             }
             $retval = PluginSonotsOption::boolean_to_numeric((array) $val);
             break;
         case 'enum':
             if ($val === true) {
                 $retval = is_array($conf) ? reset($conf) : null;
                 break;
             }
             if (in_array($val, $conf)) {
                 $retval = $val;
             } else {
                 $unknown = $val;
             }
             break;
         case 'enumarray':
             // special array type
             if ($val === true) {
                 $retval = is_array($conf) ? $conf : null;
                 break;
             }
             $retval = array();
             $unknown = array();
             $val = PluginSonotsOption::boolean_to_numeric((array) $val);
             foreach ($val as $elem) {
                 if (in_array($elem, $conf)) {
                     $retval[] = $elem;
                 } else {
                     $unknown[] = $elem;
                 }
             }
             if (empty($retval)) {
                 $retval = null;
             }
             if (empty($unknown)) {
                 $unknown = null;
             }
             break;
         case 'options':
             if ($val === true) {
                 $val = array();
             }
             list($retval, $unknown) = PluginSonotsOption::evaluate_options($val, $conf);
             if (empty($retval)) {
                 $retval = null;
             }
             if (empty($unknown)) {
                 $unknown = null;
             }
             break;
         case 'number':
             if ($val === true) {
                 $retval = is_int($conf) || is_float($conf) ? $conf : null;
                 break;
             }
             if (is_numeric($val)) {
                 $retval = $val;
             } else {
                 $unknown = $val;
             }
             break;
         case 'interval':
             // $conf is default2 or array(default2, start)
             if ($val === true) {
                 $val = is_array($conf) ? $conf[0] : $conf;
             }
             $start = is_array($conf) ? $conf[1] : 1;
             $retval = PluginSonotsOption::parse_interval($val, $start);
             if (is_null($retval)) {
                 $unknown = $val;
             }
             break;
         default:
             $unknown = $val;
             break;
     }
     return array($retval, $unknown);
 }