_('Table of Contents'), ); // Modify here for default option values static $default_options = array( 'page' => array('string', ''), 'fromhere' => array('bool', true), 'hierarchy' => array('bool', true), 'compact' => array('bool', true), 'num' => array('number', ''), 'depth' => array('number', ''), 'except' => array('string', ''), 'filter' => array('string', ''), 'include' => array('bool', true), 'cache' => array('enum', 'on', array('on', 'off', 'reset')), 'link' => array('enum', 'on', array('on', 'off', 'anchor', 'page')), ); // Definitions static $conf = array( 'def_headline' => '/^(\*{1,3})/', 'max_depth' => 3, 'def_include' => '/^#include.*\((.+)\)/', 'def_title' => '/^TITLE:(.+)/', 'use_session' => TRUE, // action 'through_if_admin' => TRUE, // action ); $this->msg = &$msg; $this->default_options = &$default_options; $this->conf = &$conf; // init $this->options = $this->default_options; } function PluginContentsx() { $this->__construct(); } // static var $msg; var $default_options; var $conf; // var var $args; var $options; var $error = ""; var $plugin = "contentsx"; var $metalines; var $visited = array(); // page => title(alias) function action() // clean cache { global $vars; if (is_admin($vars['pass'], $this->conf['use_session'], $this->conf['through_if_admin']) && $vars['pcmd'] == 'clean') { $body = $this->clean_cache(); } else { $body = $this->display_password_form(); } return array('msg'=>'Clean Contentsx Caches', 'body'=>$body); } function clean_cache() { set_time_limit(0); global $vars; $page = isset($vars['page']) ? $vars['page'] : ''; if ($page != '') { $file = $this->get_cache_filename($page); @unlink($file); if (exec_page($page, '/^#contentsx/')) { $body = 'Recreated a cache of '; } else { $body = 'No #contentsx in '; } $body .= make_pagelink($page); } else { // remove all files $files = $this->get_cache_filenames(); foreach ($files as $file) { unlink($file); } // execute all pages $exec_pages = exec_existpages('/^#contentsx/'); if (empty($exec_pages)) { $body = ''; } else { $links = array_map('make_pagelink', $exec_pages); $body = '

Following pages were executed to assure:

' . '

' . implode("
\n", $links) . '

'; } } return $body; } /** * Display a password form * * @param $msg error message or some messages * @return string form html */ function display_password_form($message = "") { $cmd = $this->plugin; $pcmd = 'clean'; $form = array(); $form[] = '
'; $form[] = '
'; $form[] = ' '; $form[] = ' ' . _('A Page (Blank if All)') . '
'; if (! is_admin(null, $this->conf['use_session'], $this->conf['through_if_admin'])) { $form[] = ' ' . _('Admin Password') . '
'; } else { $form[] = ' ' . _('Admin Password') . '
'; } $form[] = '
'; $form[] = '
'; $form[] = '
'; $form = implode("\n", $form); if ($message != '') { $message = '

' . htmlsc($message) . '

'; } return $message . $form; } function convert() { $args = func_get_args(); if ($GLOBALS['vars']['cmd'] != 'read') { return ''; } $body = $this->body($args); if ($body != '') { $body = '' . "\n" . '\n" . '\n" . "
' . "\n" . '' . $this->msg['toctitle'] . "\n" . "
' . "\n" . $body . "
\n"; } if ($this->error != "" ) { return "

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

"; } return $body; } function body($args) { global $vars; $parser = new PluginContentsxOptionParser(); $this->options = $parser->parse_options($args, $this->options); if ($parser->error != "") { $this->error = $parser->error; return; } $this->options['page'][1] = $this->check_page($this->options['page'][1]); if ($this->error !== "") { return; } $this->init_metalines($this->options['page'][1]); if ($this->error !== "") { return; } $this->narrow_metalines(); if ($this->error !== "") { return; } $body = $this->frontend(); if ($this->error !== "") { return; } return $body; } function get_title($page) { $page = $this->check_page($page); $this->init_metalines($page); $title = $this->visited[$page]; // FYI: $title = strip_htmltag(make_link($title)); // $link = make_pagelink($page, $title); return $title; } function get_visited($page) { $page = $this->check_page($page); $this->init_metalines($page); return array_keys($this->visited); } function get_metalines($page) { $page = $this->check_page($page); $this->init_metalines($page); return $this->metalines; } function narrow_metalines() { $this->fromhere_metalines(); $this->include_metalines(); $this->filter_metalines(); $this->except_metalines(); $parser = new PluginContentsxOptionParser(); $this->options['depth'][1] = $parser->parse_numoption($this->options['depth'][1], 0, $this->conf['max_depth']); if ($parser->error != "") { $this->error = $parser->error; return; } $this->depth_filter_metalines(); $num = sizeof($this->metalines); $this->options['num'][1] = $parser->parse_numoption($this->options['num'][1], 1, $num); if ($parser->error != "") { $this->error = $parser->error; return; } $this->num_filter_metalines(); } function frontend() { $this->hierarchy_metalines(); $this->compact_metalines(); $this->makelink_metalines(); return $this->list_metalines(); } function list_metalines() { if (sizeof($this->metalines) == 0) { return; } /* HTML validate (without