<?php
// PukiWiki - Yet another WikiWikiWeb clone
-// $Id: topicpath.inc.php,v 1.6 2005/01/29 14:31:04 henoheno Exp $
+// topicpath.inc.php
+// Copyright
+// 2004-2018 PukiWiki Development Team
+// 2003 reimy (Some bug fix)
+// 2003 t.m (Migrate to 1.3)
+// 2003 Nibun-no-ni (Originally written for PukiWiki 1.4.x)
+// License: GPL v2 or (at your option) any later version
//
-// 'topicpath' plugin for PukiWiki, available under GPL
+// 'topicpath' plugin for PukiWiki
// Show a link to $defaultpage or not
define('PLUGIN_TOPICPATH_TOP_DISPLAY', 1);
define('PLUGIN_TOPICPATH_TOP_LABEL', 'Top');
// Separetor / of / topic / path
-define('PLUGIN_TOPICPATH_TOP_SEPARATOR', ' / ');
+define('PLUGIN_TOPICPATH_TOP_SEPARATOR', '<span class="topicpath-slash">/</span>');
// Show the page itself or not
define('PLUGIN_TOPICPATH_THIS_PAGE_DISPLAY', 1);
return '<div>' . plugin_topicpath_inline() . '</div>';
}
-function plugin_topicpath_inline()
+function plugin_topicpath_parent_links($page)
{
- global $script, $vars, $defaultpage;
-
- $page = isset($vars['page']) ? $vars['page'] : '';
- if ($page == '' || $page == $defaultpage) return '';
-
$parts = explode('/', $page);
-
- $b_link = TRUE;
- if (PLUGIN_TOPICPATH_THIS_PAGE_DISPLAY) {
- $b_link = PLUGIN_TOPICPATH_THIS_PAGE_LINK;
- } else {
- array_pop($parts); // Remove the page itself
+ $parents = array();
+ for ($i = 0, $pos = 0; $pos = strpos($page, '/', $i); $i = $pos + 1) {
+ $p = substr($page, 0, $pos);
+ $parents[] = array(
+ 'page' => $p,
+ 'leaf' => substr($p, $i),
+ 'uri' => get_page_uri($p),
+ );
}
+ return $parents;
+}
+function plugin_topicpath_inline()
+{
+ global $vars, $defaultpage;
+ $page = isset($vars['page']) ? $vars['page'] : '';
+ if ($page == '' || $page == $defaultpage) return '';
+ $parents = plugin_topicpath_parent_links($page);
$topic_path = array();
- while (! empty($parts)) {
- $_landing = join('/', $parts);
- $landing = rawurlencode($_landing);
- $element = htmlspecialchars(array_pop($parts));
- if (! $b_link) {
- // This page ($_landing == $page)
- $b_link = TRUE;
- $topic_path[] = $element;
- } else if (PKWK_READONLY && ! is_page($_landing)) {
+ foreach ($parents as $p) {
+ if (PKWK_READONLY && !is_page($p['page'])) {
// Page not exists
- $topic_path[] = $element;
+ $topic_path[] = htmlsc($p['leaf']);
} else {
// Page exists or not exists
- $topic_path[] = '<a href="' . $script . '?' . $landing . '">' .
- $element . '</a>';
+ $topic_path[] = '<a href="' . $p['uri'] . '">' .
+ $p['leaf'] . '</a>';
}
}
-
- if (PLUGIN_TOPICPATH_TOP_DISPLAY)
- $topic_path[] = make_pagelink($defaultpage, PLUGIN_TOPICPATH_TOP_LABEL);
-
- return join(PLUGIN_TOPICPATH_TOP_SEPARATOR, array_reverse($topic_path));
+ // This page
+ if (PLUGIN_TOPICPATH_THIS_PAGE_DISPLAY) {
+ $leaf_name = preg_replace('#^.*/#', '', $page);
+ if (PLUGIN_TOPICPATH_THIS_PAGE_LINK) {
+ $topic_path[] = '<a href="' . get_page_uri($page) . '">' .
+ $leaf_name . '</a>';
+ } else {
+ $topic_path[] = htmlsc($leaf_name);
+ }
+ }
+ $s = join(PLUGIN_TOPICPATH_TOP_SEPARATOR, $topic_path);
+ if (PLUGIN_TOPICPATH_TOP_DISPLAY) {
+ $s = '<span class="topicpath-top">' .
+ make_pagelink($defaultpage, PLUGIN_TOPICPATH_TOP_LABEL) .
+ PLUGIN_TOPICPATH_TOP_SEPARATOR . '</span>' . $s;
+ }
+ return $s;
}
-?>