7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2008 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: navi.inc.php 1088 2008-10-19 07:42:08Z fishbone $
14 * @link http://www.magic3.org
18 * #navi(contents-page-name) <for ALL child pages>
19 * #navi([contents-page-name][,reverse]) <for contents page>
22 * contents-page-name - Page name of home of the navigation (default:itself)
23 * reverse - Show contents revese
25 * Behaviour at contents page:
26 * Always show child-page list like 'ls' plugin
28 * Behaviour at child pages:
30 * The first plugin call - Show a navigation bar like a DocBook header
32 * Prev <contents-page-name> Next
33 * --------------------------------
35 * The second call - Show a navigation bar like a DocBook footer
37 * --------------------------------
39 * <pagename> Up <pagename>
41 * Page-construction example:
42 * foobar - Contents page, includes '#navi' or '#navi(foobar)'
43 * foobar/1 - One of child pages, includes one or two '#navi(foobar)'
44 * foobar/2 - One of child pages, includes one or two '#navi(foobar)'
47 // Exclusive regex pattern of child pages
48 define('PLUGIN_NAVI_EXCLUSIVE_REGEX', '');
49 //define('PLUGIN_NAVI_EXCLUSIVE_REGEX', '#/_#'); // Ignore 'foobar/_memo' etc.
51 // Insert <link rel=... /> tags into XHTML <head></head>
52 define('PLUGIN_NAVI_LINK_TAGS', FALSE); // FALSE, TRUE
56 function plugin_navi_convert()
58 //global $vars, $script, $head_tags;
59 global $script, $head_tags;
60 global $_navi_prev, $_navi_next, $_navi_up, $_navi_home;
61 static $navi = array();
63 //$current = $vars['page'];
64 $current = WikiParam::getPage();
66 if (func_num_args()) {
67 list($home, $reverse) = array_pad(func_get_args(), 2, '');
68 // strip_bracket() is not necessary but compatible
69 $home = get_fullname(strip_bracket($home), $current);
70 $is_home = ($home == $current);
71 if (! is_page($home)) {
72 return '#navi(contents-page-name): No such page: ' .
73 htmlspecialchars($home) . '<br />';
74 } else if (! $is_home &&
75 ! preg_match('/^' . preg_quote($home, '/') . '/', $current)) {
76 return '#navi(' . htmlspecialchars($home) .
77 '): Not a child page like: ' .
78 htmlspecialchars($home . '/' . basename($current)) .
81 $reverse = (strtolower($reverse) == 'reverse');
83 //$home = $vars['page'];
84 $home = WikiParam::getPage();
85 $is_home = TRUE; // $home == $current
89 $footer = isset($navi[$home]); // The first time: FALSE, the second: TRUE
101 $pages = preg_grep('/^' . preg_quote($home, '/') .
102 '($|\/)/', get_existpages());
103 if (PLUGIN_NAVI_EXCLUSIVE_REGEX != '') {
104 // If old PHP could use preg_grep(,,PREG_GREP_INVERT)...
105 $pages = array_diff($pages,
106 preg_grep(PLUGIN_NAVI_EXCLUSIVE_REGEX, $pages));
108 $pages[] = $current; // Sentinel :)
109 $pages = array_unique($pages);
111 if ($reverse) $pages = array_reverse($pages);
114 foreach ($pages as $page) {
115 if ($page == $current) break;
118 $next = current($pages);
120 $pos = strrpos($current, '/');
123 $up = substr($current, 0, $pos);
124 $navi[$home]['up'] = make_pagelink($up, $_navi_up);
127 $navi[$home]['prev'] = make_pagelink($prev);
128 $navi[$home]['prev1'] = make_pagelink($prev, $_navi_prev);
131 $navi[$home]['next'] = make_pagelink($next);
132 $navi[$home]['next1'] = make_pagelink($next, $_navi_next);
134 $navi[$home]['home'] = make_pagelink($home);
135 $navi[$home]['home1'] = make_pagelink($home, $_navi_home);
137 // Generate <link> tag: start next prev(previous) parent(up)
138 // Not implemented: contents(toc) search first(begin) last(end)
139 if (PLUGIN_NAVI_LINK_TAGS) {
140 foreach (array('start'=>$home, 'next'=>$next,
141 'prev'=>$prev, 'up'=>$up) as $rel=>$_page) {
143 $s_page = htmlspecialchars($_page);
144 $r_page = rawurlencode($_page);
145 $head_tags[] = ' <link rel="' .
146 $rel . '" href="' . $script .
147 '?' . $r_page . '" title="' .
158 $count = count($pages);
160 return '#navi(contents-page-name): You already view the result<br />';
161 } else if ($count == 1) {
162 // Sentinel only: Show usage and warning
163 $home = htmlspecialchars($home);
164 $ret .= '#navi(' . $home . '): No child page like: ' .
168 foreach ($pages as $page)
170 $ret .= ' <li>' . make_pagelink($page) . '</li>';
174 } else if (! $footer) {
178 <li class="navi_left">{$navi[$home]['prev1']}</li>
179 <li class="navi_right">{$navi[$home]['next1']}</li>
180 <li class="navi_none">{$navi[$home]['home']}</li>
182 <hr class="full_hr" />
188 <hr class="full_hr" />
190 <li class="navi_left">{$navi[$home]['prev1']}<br />{$navi[$home]['prev']}</li>
191 <li class="navi_right">{$navi[$home]['next1']}<br />{$navi[$home]['next']}</li>
192 <li class="navi_none">{$navi[$home]['home1']}<br />{$navi[$home]['up']}</li>