* @license http://www.gnu.org/licenses/gpl.html GPL * @link http://lsx.sourceforge.jp/?Plugin%2Flsx.inc.php * @version $Id: lsx.inc.php,v 1.17 2007-06-16 11:14:46 sonots $ * @package plugin */ // v1.18 PHP8.0対応 2021-12-15 byはいふん class PluginLsx { function __construct() { // Configure external plugins static $conf = array( 'plugin_contents' => 'contentsx', 'plugin_include' => 'includex', 'plugin_new' => 'new', 'plugin_tag' => 'tag', ); // Modify here for default option values static $default_options = array( 'hierarchy' => array('bool', true), 'non_list' => array('bool', true), 'reverse' => array('bool', false), 'basename' => array('bool', false), // obsolete 'sort' => array('enum', 'name', array('name', 'reading', 'date')), 'tree' => array('enum', false, array(false, 'leaf', 'dir')), 'depth' => array('number', ''), 'num' => array('number', ''), 'next' => array('bool', false), 'except' => array('string', ''), 'filter' => array('string', ''), 'prefix' => array('string', ''), 'contents' => array('array', ''), 'include' => array('array', ''), 'info' => array('enumarray', array(), array('date', 'new')), 'date' => array('bool', false), // will be obsolete 'new' => array('bool', false), 'tag' => array('string', ''), 'linkstr' => array('enum', 'relative', array('relative', 'absolute', 'basename', 'title', 'headline')), 'link' => array('enum', 'page', array('page', 'anchor', 'off')), 'newpage' => array('enum', false, array('on', 'except')), 'popular' => array('enum', false, array('total', 'today', 'yesterday', 'recent')), // alpha ); $this->conf = &$conf; $this->default_options = &$default_options; // init $this->options = $this->default_options; if (function_exists('mb_ereg')) { // extension_loaded('mbstring') mb_regex_encoding(SOURCE_ENCODING); $this->ereg = 'mb_ereg'; } else { $this->ereg = 'ereg'; } } function PluginLsx() { $this->__construct(); } // static var $conf; var $default_options; // var var $options; var $error = ""; var $plugin = "lsx"; var $metapages; function convert() { $args = func_get_args(); $body = $this->body($args); if ($this->error != "") { $body = "

$this->plugin(): $this->error

"; } return $body; } function action() { global $vars; $args = $vars; $body = $this->body($args); if ($this->error != "") { $body = "

$this->plugin(): $this->error

"; } if (! isset($body)) $body = '

no result.

'; if ($this->options['tag'][1] != '') { $msg = htmlsc($this->options['tag'][1]); } elseif ($this->options['prefix'][1] != '') { $msg = htmlsc($this->options['prefix'][1]); } else { $msg = $this->plugin; } return array('msg'=>$msg, 'body'=>$body); } function body($args) { $parser = new PluginLsxOptionParser(); $this->options = $parser->parse_options($args, $this->options); if ($parser->error != "") { $this->error = $parser->error; return; } $this->validate_options(); if ($this->error !== "") { return $this->error; } $this->init_metapages(); if ($this->error !== "") { return $this->error; } $this->prefix_filter_metapages(); if ($this->error !== "") { return $this->error; } $this->nonlist_filter_metapages(); if ($this->error !== "") { return $this->error; } $this->relative_metapages(); // before filter, except if ($this->error !== "") { return $this->error; } $this->filter_filter_metapages(); if ($this->error !== "") { return $this->error; } $this->except_filter_metapages(); if ($this->error !== "") { return $this->error; } $this->newpage_filter_metapages(); if ($this->error !== "") { return $this->error; } $parser = new PluginLsxOptionParser(); $this->maxdepth = $this->depth_metapages(); $this->options['depth'][1] = $parser->parse_numoption($this->options['depth'][1], 1, $this->maxdepth); if ($parser->error != "") { $this->error = $parser->error; return; } $this->depth_filter_metapages(); if ($this->error !== "") { return $this->error; } $this->tree_filter_metapages(); if ($this->error !== "") { return $this->error; } $this->popular_metapages(); // before sort if ($this->error !== "") { return $this->error; } $this->timestamp_metapages(); // before sort if ($this->error !== "") { return $this->error; } $this->sort_metapages(); // before num_filter if ($this->error !== "") { return $this->error; } $this->maxnum = sizeof($this->metapages); // after all filters $this->options['num'][1] = $parser->parse_numoption($this->options['num'][1], 1, $this->maxnum); if ($parser->error != "") { $this->error = $parser->error; return; } $this->num_filter_metapages(); if ($this->error !== "") { return $this->error; } $this->hierarchy_metapages(); if ($this->error !== "") { return $this->error; } $this->info_metapages(); if ($this->error !== "") { return $this->error; } $this->linkstr_metapages(); if ($this->error !== "") { return $this->error; } $this->link_metapages(); if ($this->error !== "") { return $this->error; } $body = $this->list_pages(); $body .= $this->next_pages(); return $body; } function validate_options() { global $vars; if ($this->options['tag'][1] != '') { if(! exist_plugin($this->conf['plugin_tag'])) { $this->error .= "The option, tag, requires #{$this->conf['plugin_tag']} plugin, but it does not exist. "; return; } $this->options['hierarchy'][1] = false; // best is to turn off the default only so that 'hierarchy' can be configured by option. } else { if ($this->options['prefix'][1] == '') { $this->options['prefix'][1] = $vars['page'] != '' ? $vars['page'] . '/' : ''; } } if ($this->options['prefix'][1] == '/') { $this->options['prefix'][1] = ''; } elseif ($this->options['prefix'][1] != '') { $this->options['prefix'][1] = $this->get_fullname($this->options['prefix'][1], $vars['page']); } $this->options['prefix'][4] = $this->options['prefix'][1]; if ($this->options['sort'][1] == 'date') { $this->options['hierarchy'][1] = false; } // alpha func if ($this->options['popular'][1] != false) { $this->options['sort'][1] = 'popular'; $this->options['hierarchy'][1] = false; // Future Work: info_popular. hmmm } // Another Idea // sort=popular>today,popular>total,popular>yesterday,popular>recent // if (strpos($this->options['sort'][1], 'popular>') !== false) { // list($this->optiions['sort'][1], $this->options['popular'][1]) = explode('>', $this->options['sort'][1]); // $this->options['hierarchy'][1] = false; // } if ($this->options['contents'][1] != '') { if(! exist_plugin_convert($this->conf['plugin_contents'])) { $this->error .= "The option, contents, requires {$this->conf['plugin_contents']} plugin, but it does not exist. "; return; } } if ($this->options['include'][1] != '') { if(! exist_plugin_convert($this->conf['plugin_include'])) { $this->error .= "The option, include, requires {$this->conf['plugin_include']} plugin, but it does not exist. "; return; } $this->options['hierarchy'][1] = false; // hierarchy + include => XHTML invalid $this->options['date'][1] = false; // include does not use definitely $this->options['new'][1] = false; // include does not use definitely $this->options['contents'][1] = ''; // include does not use definitely } if ($this->options['linkstr'][1] === 'title' || $this->options['linkstr'][1] === 'headline') { if(! exist_plugin_convert($this->conf['plugin_contents'])) { $this->error .= "The option, linkstr, requires {$this->conf['plugin_contents']} plugin, but it does not exist. "; return; } } // to support lower versions // basename -> linkstr if ($this->options['basename'][1] === true) { $this->options['linkstr'][1] = 'basename'; } // new,date -> info foreach ($this->options['info'][2] as $key) { if ($this->options[$key][1]) { array_push($this->options['info'][1], $key); } } $this->options['info'][1] = array_unique($this->options['info'][1]); // to save time (to avoid in_array everytime) foreach ($this->options['info'][1] as $key) { $this->options[$key][1] = true; } if ($this->options['new'][1] && ! exist_plugin_inline($this->conf['plugin_new'])) { $this->error .= "The option, new, requires {$this->conf['plugin_new']} plugin, but it does not exist. "; return; } } function next_pages() { if (! $this->options['next'][1] || $this->options['num'][1] == '') return; $options = $this->options; unset($options['num']); $href = get_script_uri() . '?' . 'cmd=lsx'; foreach ($options as $key => $val) { if (isset($val[4])) { $href .= '&' . htmlsc($key) . '=' . htmlsc(rawurlencode($val[4])); } } $count = count($this->options['num'][1]); $min = reset($this->options['num'][1]); $max = end($this->options['num'][1]); $maxnum = $this->maxnum; $prevmin = max($min - $count, 0); $prevmax = min($min - 1, $maxnum); $prevlink = ''; if ($prevmax > 0) { $prevhref = $href . '&num=' . $prevmin . ':' . $prevmax; $prevlink = '' . _('Prev ') . $count . ''; } $nextmin = max($max + 1, 0); $nextmax = min($max + $count, $maxnum); $nextlink = ''; if ($nextmin < $maxnum) { $nexthref = $href . '&num=' . $nextmin . ':' . $nextmax; $nextlink = '' . _('Next ') . $count . ''; } $ret = ''; $ret .= '
' . $prevlink . $nextlink . '
'; return $ret; } function list_pages() { global $script; if (sizeof($this->metapages) == 0) { return; } /* HTML validate (without