/** * 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>'; } }
function section_lines() { if (empty($this->options['section'][1])) { return; } $parser = new PluginIncludexOptionParser(); $this->section_options = $parser->parse_options($this->options['section'][1], $this->section_options); if ($parser->error != "") { $this->error = $parser->error; return; } // what a public class! hehehe $contentsx = new PluginContentsx(); $contentsx->options['include'][1] = false; $contentsx->options['fromhere'][1] = false; $contentsx->options['page'][1] = $contentsx->check_page($this->inclpage); $this->headlines = $contentsx->get_metalines($this->inclpage); if ($contentsx->error != "") { $this->error = $contentsx->error; return; } foreach ($this->section_options as $key => $val) { $contentsx->options[$key] = $val; } $contentsx->narrow_metalines(); if ($contentsx->error != "") { $this->error = $contentsx->error; return; } $this->narrowed_headlines = $contentsx->metalines; $size = sizeof($this->headlines); $this->section_options['num'][1] = $parser->parse_numoption($this->section_options['num'][1], 0, $size); $lines = array(); if (in_array(0, $this->section_options['num'][1])) { $linenum = $this->headlines[0]['linenum']; $lines = array_merge($lines, array_splice($this->lines, 0, $linenum)); } // FutureWork: Do no rely on contentsx's cache as much as possible. $i = 0; $size = sizeof($this->headlines); foreach ($this->narrowed_headlines as $narrowed_headline) { $linenum = $narrowed_headline['linenum']; for (; $i < $size; $i++) { $current = $i; if ($linenum != $this->headlines[$current]['linenum']) { continue; } $next = $i + 1; if ($next < $size) { $len = $this->headlines[$next]['linenum'] - $linenum; $lines = array_merge($lines, array_slice($this->lines, $linenum, $len)); } else { $lines = array_merge($lines, array_slice($this->lines, $linenum)); } break; } } $this->lines = $lines; }