2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: navi.inc.php,v 1.22 2005/04/02 06:33:39 henoheno Exp $
5 // Navi plugin: Show DocBook-like navigation bar and contents
9 * #navi(contents-page-name) <for ALL child pages>
10 * #navi([contents-page-name][,reverse]) <for contents page>
13 * contents-page-name - Page name of home of the navigation (default:itself)
14 * reverse - Show contents revese
16 * Behaviour at contents page:
17 * Always show child-page list like 'ls' plugin
19 * Behaviour at child pages:
21 * The first plugin call - Show a navigation bar like a DocBook header
23 * Prev <contents-page-name> Next
24 * --------------------------------
26 * The second call - Show a navigation bar like a DocBook footer
28 * --------------------------------
30 * <pagename> Up <pagename>
32 * Page-construction example:
33 * foobar - Contents page, includes '#navi' or '#navi(foobar)'
34 * foobar/1 - One of child pages, includes one or two '#navi(foobar)'
35 * foobar/2 - One of child pages, includes one or two '#navi(foobar)'
38 // Exclusive regex pattern of child pages
39 define('PLUGIN_NAVI_EXCLUSIVE_REGEX', '');
40 //define('PLUGIN_NAVI_EXCLUSIVE_REGEX', '#/_#'); // Ignore 'foobar/_memo' etc.
42 // Insert <link rel=... /> tags into XHTML <head></head>
43 define('PLUGIN_NAVI_LINK_TAGS', FALSE); // FALSE, TRUE
47 function plugin_navi_convert()
49 global $vars, $script, $head_tags;
50 global $_navi_prev, $_navi_next, $_navi_up, $_navi_home;
51 static $navi = array();
53 $current = $vars['page'];
55 if (func_num_args()) {
56 list($home, $reverse) = array_pad(func_get_args(), 2, '');
57 // strip_bracket() is not necessary but compatible
58 $home = get_fullname(strip_bracket($home), $current);
59 $is_home = ($home == $current);
60 if (! is_page($home)) {
61 return '#navi(contents-page-name): No such page: ' .
62 htmlspecialchars($home) . '<br />';
63 } else if (! $is_home &&
64 ! preg_match('/^' . preg_quote($home, '/') . '/', $current)) {
65 return '#navi(' . htmlspecialchars($home) .
66 '): Not a child page like: ' .
67 htmlspecialchars($home . '/' . basename($current)) .
70 $reverse = (strtolower($reverse) == 'reverse');
72 $home = $vars['page'];
73 $is_home = TRUE; // $home == $current
77 $footer = isset($navi[$home]); // The first time: FALSE, the second: TRUE
89 $pages = preg_grep('/^' . preg_quote($home, '/') .
90 '($|\/)/', get_existpages());
91 if (PLUGIN_NAVI_EXCLUSIVE_REGEX != '') {
92 // If old PHP could use preg_grep(,,PREG_GREP_INVERT)...
93 $pages = array_diff($pages,
94 preg_grep(PLUGIN_NAVI_EXCLUSIVE_REGEX, $pages));
96 $pages[] = $current; // Sentinel :)
97 $pages = array_unique($pages);
99 if ($reverse) $pages = array_reverse($pages);
102 foreach ($pages as $page) {
103 if ($page == $current) break;
106 $next = current($pages);
108 $pos = strrpos($current, '/');
111 $up = substr($current, 0, $pos);
112 $navi[$home]['up'] = make_pagelink($up, $_navi_up);
115 $navi[$home]['prev'] = make_pagelink($prev);
116 $navi[$home]['prev1'] = make_pagelink($prev, $_navi_prev);
119 $navi[$home]['next'] = make_pagelink($next);
120 $navi[$home]['next1'] = make_pagelink($next, $_navi_next);
122 $navi[$home]['home'] = make_pagelink($home);
123 $navi[$home]['home1'] = make_pagelink($home, $_navi_home);
125 // Generate <link> tag: start next prev(previous) parent(up)
126 // Not implemented: contents(toc) search first(begin) last(end)
127 if (PLUGIN_NAVI_LINK_TAGS) {
128 foreach (array('start'=>$home, 'next'=>$next,
129 'prev'=>$prev, 'up'=>$up) as $rel=>$_page) {
131 $s_page = htmlspecialchars($_page);
132 $r_page = rawurlencode($_page);
133 $head_tags[] = ' <link rel="' .
134 $rel . '" href="' . $script .
135 '?' . $r_page . '" title="' .
146 $count = count($pages);
148 return '#navi(contents-page-name): You already view the result<br />';
149 } else if ($count == 1) {
150 // Sentinel only: Show usage and warning
151 $home = htmlspecialchars($home);
152 $ret .= '#navi(' . $home . '): No child page like: ' .
156 foreach ($pages as $page)
158 $ret .= ' <li>' . make_pagelink($page) . '</li>';
162 } else if (! $footer) {
166 <li class="navi_left">{$navi[$home]['prev1']}</li>
167 <li class="navi_right">{$navi[$home]['next1']}</li>
168 <li class="navi_none">{$navi[$home]['home']}</li>
170 <hr class="full_hr" />
176 <hr class="full_hr" />
178 <li class="navi_left">{$navi[$home]['prev1']}<br />{$navi[$home]['prev']}</li>
179 <li class="navi_right">{$navi[$home]['next1']}<br />{$navi[$home]['next']}</li>
180 <li class="navi_none">{$navi[$home]['home1']}<br />{$navi[$home]['up']}</li>