/** * 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; }
/** * List pages * * @param array $pages * @param array $options * @param array $argoptions * @return string html */ function pagelist($pages, $options, $argoptions) { $pagelist = new PluginSonotsPagelist($pages); 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 (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 { $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); } if ($options['next'] && is_array($options['num'])) { $argoptions['tag'] = $options['tag']; 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; }
function linkstr_metapages() { switch ($this->options['linkstr'][1]) { case 'absolute': foreach ($this->metapages as $i => $metapage) { $this->metapages[$i]['linkstr'] = htmlspecialchars($metapage['page']); } break; case 'basename': foreach ($this->metapages as $i => $metapage) { $this->metapages[$i]['linkstr'] = htmlspecialchars($this->my_basename($metapage['page'])); } break; case 'title': $contentsx = new PluginContentsx(); foreach ($this->metapages as $i => $metapage) { $title = $contentsx->get_title($metapage['page']); $title = strip_htmltag(make_link($title)); $this->metapages[$i]['linkstr'] = $title; } break; case 'headline': $contentsx = new PluginContentsx(); foreach ($this->metapages as $i => $metapage) { $metalines = $contentsx->get_metalines($metapage['page']); $title = $metalines[0]['headline']; $title = strip_htmltag(make_link($title)); $this->metapages[$i]['linkstr'] = $title; } break; } // default: relative if ($this->options['hierarchy'][1] === true) { foreach ($this->metapages as $i => $metapage) { if (!isset($metapage['linkstr']) || $metapage['linkstr'] === '') { $this->metapages[$i]['linkstr'] = htmlspecialchars($this->my_basename($metapage['page'])); } } } else { foreach ($this->metapages as $i => $metapage) { if (!isset($metapage['linkstr']) || $metapage['linkstr'] === '') { $this->metapages[$i]['linkstr'] = htmlspecialchars($metapage['relative']); } } } }