function test_link() { $parse = PluginSonotsMetapage::link('Hoge/A', 'A', 'page'); $assert = '<span class="noexists">A<a href="?cmd=edit&page=Hoge%2FA">?</a></span>'; $this->assertEqual($parse, $assert); $parse = PluginSonotsMetapage::link('Hoge/A', 'A', 'anchor'); $assert = '<a href="#z758465a6084944c5973bedbbfaf08be9">A</a>'; $this->assertEqual($parse, $assert); $parse = PluginSonotsMetapage::link('Hoge/A', 'A', 'off'); $assert = 'A'; $this->assertEqual($parse, $assert); }
/** * Get TITLE: line or the first headline of a page * * Usage: * - &get_title(page,[option]) * Option * - firsthead Get the first headline instead of title * * @package plugin * @license http://www.gnu.org/licenses/gpl.html GPL v2 * @author sonots * @link http://lsx.sourceforge.jp/?Plugin%2Fget_title.inc.php * @version $Id: get_title.inc.php,v 2.0 2008-07-30 16:28:39Z sonots $ */ function plugin_get_title_inline() { $args = func_get_args(); array_pop($args); $page = array_shift($args); $conf_options = array('firsthead' => false); $options = sonots::parse_options($args, $conf_options); if ($options['firsthead']) { $str = PluginSonotsMetapage::firsthead($page); } else { $str = PluginSonotsMetapage::title($page); } if (is_null($str)) { $str = $page; } $str = strip_htmltag(make_link($str)); return $str; }
/** * Display navigation * * @param array $navipages array($home, $up, $prev, $current, $next) * @param string $look Show DocBook 'footer' style or DocBook 'header' * * DocBook header * <pre> * Prev Home Next * </pre> * DocBook footer * <pre> * Prev Home Next * <pagename> Up <pagename> * </pre> * * @param string $border 'off' or 'top' or 'bottom'. * - 'off' shows no border. * - 'top' shows a border top. * - 'bottom' shows a border bottom. * @param bool $printcss print css with html as style="" attributes. * @return string html */ function display_navi($navipages, $look = 'header', $border = 'off', $printcss = false) { $linkstr = $this->linkstr; $css = $this->css; $footer = $look == 'footer'; list($home, $up, $prev, $current, $next) = $navipages; // get link $link = array(); $link['prev'] = make_pagelink($prev, $linkstr['prev']); $link['home'] = $home == '' ? sonots::make_toplink($linkstr['home']) : make_pagelink($home, $linkstr['home']); if ($next) { $link['next'] = make_pagelink($next, $linkstr['next']); } if ($footer) { $link['up'] = make_pagelink($up, $linkstr['up']); $link['prevfoot'] = strip_tags(make_link(PluginSonotsMetapage::linkstr($prev, $footer, $current, true))); if ($next) { $link['nextfoot'] = strip_tags(make_link(PluginSonotsMetapage::linkstr($next, $footer, $current, true))); } } // html $html = '<div class="wrap_navix" style="margin:0px;padding:0px;">' . "\n"; if ($border === 'top') { $html .= '<hr class="full_hr top"' . ($printcss ? ' style="' . $css['div.wrap_navix hr.top'] . '"' : '') . '/>' . "\n"; } $html .= '<ul class="navix"' . ($printcss ? ' style="' . $css['ul.navix'] . '"' : '') . '>' . "\n"; $html .= '<li class="left"' . ($printcss ? ' style="' . $css['ul.navix li.left'] . '"' : '') . '>' . $link['prev'] . ($footer ? '<br />' . $link['prevfoot'] : '') . '</li>' . "\n"; $html .= '<li class="center"' . ($printcss ? ' style="' . $css['ul.navix li.center'] . '"' : '') . '>' . $link['home'] . ($footer ? '<br />' . $link['up'] : '') . '</li>' . "\n"; $html .= '<li class="right"' . ($printcss ? ' style="' . $css['ul.navix li.right'] . '"' : '') . '>' . ($next ? $link['next'] . ($footer ? '<br />' . $link['nextfoot'] : '') : ' ') . '</li>' . "\n"; $html .= '</ul>' . "\n"; if ($border === 'bottom') { $html .= '<hr class="full_hr bottom"' . ($printcss ? ' style="' . $css['div.wrap_navix hr.bottom'] . '"' : '') . '/>' . "\n"; } $html .= '</div>' . "\n"; return $html; }
/** * Get string used in html link * * @access public * @static * @param string $page pagename * @param string $option option * - name|page|pagename|absolute: pagename (absolute path) * - base|basename : page basename * - title : TITLE: of page * - headline|firsthead : The first headline of a page * - relative|relname : relative pagename from currdir * @param string $currdir current dir name($currdir is required for relative) * @param boolean $usecache use cache of Toc or not (used for title and headline) * @return string * @uses sonots::get_basename * @uses title * @uses firsthead * @uses relname */ function linkstr($page, $option = 'relative', $currdir = '', $usecache = true) { switch ($option) { case 'name': case 'page': case 'pagename': case 'absolute': default: $linkstr = htmlspecialchars($page); break; case 'base': case 'basename': $linkstr = htmlspecialchars(sonots::get_basename($page)); break; case 'title': $title = PluginSonotsMetapage::title($page, $usecache); if (is_null($title)) { $linkstr = htmlspecialchars($page); } else { $linkstr = strip_htmltag(make_link($title)); } break; case 'firsthead': case 'headline': $firsthead = PluginSonotsMetapage::firsthead($page, $usecache); if (is_null($firsthead)) { $linkstr = htmlspecialchars($page); } else { $linkstr = strip_htmltag(make_link($firsthead)); } break; case 'relname': case 'relative': $linkstr = htmlspecialchars(PluginSonotsMetapage::relname($page, $currdir)); break; } return $linkstr; }
/** * Include page * * @access tatic * @param string $page * @param array $options * @param array $syntax * @return string html */ function display_include($page, $options, $syntax) { global $vars; $lines = get_source($page); if (is_array($options['section'])) { $lines = PluginIncludex::get_sections($lines, $page, $options['section']); } if (isset($options['readmore'])) { $toc = new PluginSonotsToc($page, $options['section']['cache']); $readmore = $toc->get_readmore(); if (isset($readmore)) { $last = key(array_keys($lines)); switch ($options['readmore']) { case 'until': for ($i = $readmore; $i <= $last; ++$i) { if (isset($lines[$i])) { unset($lines[$i]); } } break; case 'from': for ($i = 0; $i <= $readmore; ++$i) { if (isset($lines[$i])) { unset($lines[$i]); } } break; } } } if (isset($options['filter'])) { $lines = sonots::grep_array('/' . str_replace('/', '\\/', $options['filter']) . '/', $lines, 'preg', TRUE); } if (isset($options['except'])) { $lines = sonots::grep_array('/' . str_replace('/', '\\/', $options['except']) . '/', $lines, 'preg', TRUE, TRUE); // inverse } if (is_array($options['num'])) { list($offset, $length) = $options['num']; $lines = sonots::array_slice($lines, $offset, $length, true); } if (!$options['firsthead']) { // cut the headline on the first line $firstline = reset($lines); if (preg_match($syntax['headline'], $firstline)) { array_shift($lines); } } // html $html = sonots::get_convert_html($page, $lines); //if (trim($html) === '') return ''; $titlestr = ''; if ($options['titlestr'] !== 'off') { $titlestr = PluginSonotsMetapage::linkstr($page, $options['titlestr'], $vars['page'], true); } $title = PluginIncludex::display_title($page, $titlestr, $options['title'], $GLOBALS['fixed_heading_edited'], 'includex'); $footer = ''; if (is_string($options['permalink'])) { $linkstr = sonots::make_inline($options['permalink']); $footer = '<p class="permalink">' . make_pagelink($page, $linkstr) . '</p>'; } return $title . "\n" . $html . $footer; }
/** * Convert Includeline to Headline * * @return PluginSonotsHeadline */ function headline($usecache = true) { $linenum = $this->linenum; $depth = 0; $options = sonots::parse_options($this->args, array('titlestr' => 'title')); $string = PluginSonotsMetapage::linkstr($this->page, $options['titlestr'], $usecache); $anchor = sonots::make_pageanchor($this->page); return new PluginSonotsHeadline($this->page, $linenum, $depth, $string, $anchor); }