OSDN Git Service

1.4.5_1
[pukiwiki/pukiwiki.git] / plugin / topicpath.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: topicpath.inc.php,v 1.6 2005/01/29 14:31:04 henoheno Exp $
4 //
5 // 'topicpath' plugin for PukiWiki, available under GPL
6
7 // Show a link to $defaultpage or not
8 define('PLUGIN_TOPICPATH_TOP_DISPLAY', 1);
9
10 // Label for $defaultpage
11 define('PLUGIN_TOPICPATH_TOP_LABEL', 'Top');
12
13 // Separetor / of / topic / path
14 define('PLUGIN_TOPICPATH_TOP_SEPARATOR', ' / ');
15
16 // Show the page itself or not
17 define('PLUGIN_TOPICPATH_THIS_PAGE_DISPLAY', 1);
18
19 // If PLUGIN_TOPICPATH_THIS_PAGE_DISPLAY, add a link to itself
20 define('PLUGIN_TOPICPATH_THIS_PAGE_LINK', 0);
21
22 function plugin_topicpath_convert()
23 {
24         return '<div>' . plugin_topicpath_inline() . '</div>';
25 }
26
27 function plugin_topicpath_inline()
28 {
29         global $script, $vars, $defaultpage;
30
31         $page = isset($vars['page']) ? $vars['page'] : '';
32         if ($page == '' || $page == $defaultpage) return '';
33
34         $parts = explode('/', $page);
35
36         $b_link = TRUE;
37         if (PLUGIN_TOPICPATH_THIS_PAGE_DISPLAY) {
38                 $b_link = PLUGIN_TOPICPATH_THIS_PAGE_LINK;
39         } else {
40                 array_pop($parts); // Remove the page itself
41         }
42
43         $topic_path = array();
44         while (! empty($parts)) {
45                 $_landing = join('/', $parts);
46                 $landing  = rawurlencode($_landing);
47                 $element = htmlspecialchars(array_pop($parts));
48                 if (! $b_link)  {
49                         // This page ($_landing == $page)
50                         $b_link = TRUE;
51                         $topic_path[] = $element;
52                 } else if (PKWK_READONLY && ! is_page($_landing)) {
53                         // Page not exists
54                         $topic_path[] = $element;
55                 } else {
56                         // Page exists or not exists
57                         $topic_path[] = '<a href="' . $script . '?' . $landing . '">' .
58                                 $element . '</a>';
59                 }
60         }
61
62         if (PLUGIN_TOPICPATH_TOP_DISPLAY)
63                 $topic_path[] = make_pagelink($defaultpage, PLUGIN_TOPICPATH_TOP_LABEL);
64
65         return join(PLUGIN_TOPICPATH_TOP_SEPARATOR, array_reverse($topic_path));
66 }
67 ?>