2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: navi.inc.php,v 1.20 2004/12/30 13:26:43 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]) <for contents page>
13 * contents-page-name - Page name of home of the navigation (default:itself)
15 * Behaviour at contents page:
16 * Always show child-page list like 'ls' plugin
18 * Behaviour at child pages:
20 * The first plugin call - Show a navigation bar like a DocBook header
22 * Prev <contents-page-name> Next
23 * --------------------------------
25 * The second call - Show a navigation bar like a DocBook footer
27 * --------------------------------
29 * <pagename> Up <pagename>
31 * Page-construction example:
32 * foobar - Contents page, includes '#navi' or '#navi(foobar)'
33 * foobar/1 - One of child pages, includes one or two '#navi(foobar)'
34 * foobar/2 - One of child pages, includes one or two '#navi(foobar)'
37 // Exclusive regex pattern of child pages
38 define('PLUGIN_NAVI_EXCLUSIVE_REGEX', '');
39 //define('PLUGIN_NAVI_EXCLUSIVE_REGEX', '#/_#'); // Ignore 'foobar/_memo' etc.
41 // Insert <link rel=... /> tags into XHTML <head></head>
42 define('PLUGIN_NAVI_LINK_TAGS', FALSE); // FALSE, TRUE
46 function plugin_navi_convert()
48 global $vars, $script, $head_tags;
49 global $_navi_prev, $_navi_next, $_navi_up, $_navi_home;
50 static $navi = array();
52 $current = $vars['page'];
53 if (func_num_args()) {
54 list($home) = func_get_args();
55 // strip_bracket() is not necessary but compatible
56 $home = get_fullname(strip_bracket($home), $current);
57 $is_home = ($home == $current);
58 if (! is_page($home)) {
59 return '#navi(contents-page-name): No such page: ' .
60 htmlspecialchars($home) . '<br/>';
61 } else if (! $is_home &&
62 ! preg_match('|^' . preg_quote($home, '|') . '|', $current)) {
63 return '#navi(' . htmlspecialchars($home) .
64 '): Not a child page like: ' .
65 htmlspecialchars($home . '/' . basename($current)) .
69 $home = $vars['page'];
70 $is_home = TRUE; // $home == $current
74 $footer = isset($navi[$home]); // The first time: FALSE, the second: TRUE
86 $pages = preg_grep('/^' . preg_quote($home, '/') .
87 '($|\/)/', get_existpages());
88 if (PLUGIN_NAVI_EXCLUSIVE_REGEX != '') {
89 // If old PHP could use preg_grep(,,PREG_GREP_INVERT)...
90 $pages = array_diff($pages,
91 preg_grep(PLUGIN_NAVI_EXCLUSIVE_REGEX, $pages));
93 $pages[] = $current; // Sentinel :)
94 $pages = array_unique($pages);
97 foreach ($pages as $page) {
98 if ($page == $current) break;
101 $next = current($pages);
103 $pos = strrpos($current, '/');
106 $up = substr($current, 0, $pos);
107 $navi[$home]['up'] = make_pagelink($up, $_navi_up);
110 $navi[$home]['prev'] = make_pagelink($prev);
111 $navi[$home]['prev1'] = make_pagelink($prev, $_navi_prev);
114 $navi[$home]['next'] = make_pagelink($next);
115 $navi[$home]['next1'] = make_pagelink($next, $_navi_next);
117 $navi[$home]['home'] = make_pagelink($home);
118 $navi[$home]['home1'] = make_pagelink($home, $_navi_home);
120 // Generate <link> tag: start next prev(previous) parent(up)
121 // Not implemented: contents(toc) search first(begin) last(end)
122 if (PLUGIN_NAVI_LINK_TAGS) {
123 foreach (array('start'=>$home, 'next'=>$next,
124 'prev'=>$prev, 'up'=>$up) as $rel=>$_page) {
126 $s_page = htmlspecialchars($_page);
127 $r_page = rawurlencode($_page);
128 $head_tags[] = ' <link rel="' .
129 $rel . '" href="' . $script .
130 '?' . $r_page . '" title="' .
141 $count = count($pages);
143 return '#navi(contents-page-name): You already view the result<br/>';
144 } else if ($count == 1) {
145 // Sentinel only: Show usage and warning
146 $home = htmlspecialchars($home);
147 $ret .= '#navi(' . $home . '): No child page like: ' .
151 foreach ($pages as $page)
153 $ret .= ' <li>' . make_pagelink($page) . '</li>';
157 } else if (! $footer) {
161 <li class="navi_left">{$navi[$home]['prev1']}</li>
162 <li class="navi_right">{$navi[$home]['next1']}</li>
163 <li class="navi_none">{$navi[$home]['home']}</li>
165 <hr class="full_hr" />
171 <hr class="full_hr" />
173 <li class="navi_left">{$navi[$home]['prev1']}<br />{$navi[$home]['prev']}</li>
174 <li class="navi_right">{$navi[$home]['next1']}<br />{$navi[$home]['next']}</li>
175 <li class="navi_none">{$navi[$home]['home1']}<br />{$navi[$home]['up']}</li>