OSDN Git Service

BugTrack/2484 AutoTicketLink for JIRA: Support underscore key XX_X
[pukiwiki/pukiwiki.git] / plugin / topicpath.inc.php
index d7cb2a0..1bb064d 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone
 // topicpath.inc.php
 // Copyright
-//   2004-2017 PukiWiki Development Team
+//   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)
@@ -30,40 +30,49 @@ function plugin_topicpath_convert()
        return '<div>' . plugin_topicpath_inline() . '</div>';
 }
 
+function plugin_topicpath_parent_links($page)
+{
+       $parts = explode('/', $page);
+       $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 '';
-
-       $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 = plugin_topicpath_parent_links($page);
        $topic_path = array();
-       while (! empty($parts)) {
-               $_landing = join('/', $parts);
-               $element  = htmlsc(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="' . get_page_uri($_landing) . '">' .
-                               $element . '</a>';
+                       $topic_path[] = '<a href="' . $p['uri'] . '">' .
+                               $p['leaf'] . '</a>';
+               }
+       }
+       // 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, array_reverse($topic_path));
+       $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) .