Revisión | 398acb9df44cd8b42a629d0ff75d028ee448a185 (tree) |
---|---|
Tiempo | 2007-04-15 23:37:04 |
Autor | henoheno <henoheno> |
Commiter | henoheno |
Simplify br. Beautify XHTML br. Show total counts at the bottom of the page (this is not the main function).
@@ -1,18 +1,15 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone. |
3 | -// $Id: map.inc.php,v 1.14 2005/01/10 09:17:11 henoheno Exp $ | |
3 | +// $Id: map.inc.php,v 1.15 2007/04/15 14:37:04 henoheno Exp $ | |
4 | +// Copyright (C) 2002-2005, 2007 PukiWiki Developers Team | |
5 | +// License: GPL v2 or (at your option) any later version | |
4 | 6 | // |
5 | -// Site map plugin | |
6 | - | |
7 | -/* | |
8 | - * プラグイン map: サイトマップ(のようなもの)を表示 | |
9 | - * Usage : http://.../pukiwiki.php?plugin=map | |
10 | - * パラメータ | |
11 | - * &refer=ページ名 | |
12 | - * 起点となるページを指定 | |
13 | - * &reverse=true | |
14 | - * あるページがどこからリンクされているかを一覧。 | |
15 | -*/ | |
7 | +// Relation map plugin | |
8 | +// | |
9 | +// Usage : | |
10 | +// ?plugin=map&refer=pagename | |
11 | +// ?plugin=map&refer=pagename&reverse=true | |
12 | + | |
16 | 13 | |
17 | 14 | // Show $non_list files |
18 | 15 | define('PLUGIN_MAP_SHOW_HIDDEN', 0); // 0, 1 |
@@ -23,28 +20,29 @@ function plugin_map_action() | ||
23 | 20 | |
24 | 21 | $reverse = isset($vars['reverse']); |
25 | 22 | $refer = isset($vars['refer']) ? $vars['refer'] : ''; |
26 | - if ($refer == '' || ! is_page($refer)) | |
23 | + if ($refer == '' || ! is_page($refer)) { | |
27 | 24 | $vars['refer'] = $refer = $defaultpage; |
25 | + } | |
28 | 26 | |
29 | 27 | $retval['msg'] = $reverse ? 'Relation map (link from)' : 'Relation map, from $1'; |
30 | - $retval['body'] = ''; | |
31 | 28 | |
32 | 29 | // Get pages |
33 | 30 | $pages = array_values(array_diff(get_existpages(), array($whatsnew))); |
34 | - if (! PLUGIN_MAP_SHOW_HIDDEN) | |
31 | + if (! PLUGIN_MAP_SHOW_HIDDEN) { | |
35 | 32 | $pages = array_diff($pages, preg_grep('/' . $non_list . '/', $pages)); |
33 | + } | |
36 | 34 | if (empty($pages)) { |
37 | - $retval['body'] = 'No pages.'; | |
35 | + $retval['body'] = 'No page.'; | |
38 | 36 | return $retval; |
39 | - } else { | |
40 | - $retval['body'] .= '<p>' . "\n" . 'Total: ' . count($pages) . | |
41 | - ' page(s) on this site.' . "\n" . '</p>' . "\n"; | |
42 | 37 | } |
43 | 38 | |
39 | + $body = array(); | |
40 | + | |
44 | 41 | // Generate a tree |
45 | 42 | $nodes = array(); |
46 | - foreach ($pages as $page) | |
43 | + foreach ($pages as $page) { | |
47 | 44 | $nodes[$page] = & new MapNode($page, $reverse); |
45 | + } | |
48 | 46 | |
49 | 47 | // Node not found: Because of filtererd by $non_list |
50 | 48 | if (! isset($nodes[$refer])) $vars['refer'] = $refer = $defaultpage; |
@@ -53,41 +51,47 @@ function plugin_map_action() | ||
53 | 51 | $keys = array_keys($nodes); |
54 | 52 | sort($keys); |
55 | 53 | $alone = array(); |
56 | - $retval['body'] .= '<ul>' . "\n"; | |
54 | + $body[] = '<ul>'; | |
57 | 55 | foreach ($keys as $page) { |
58 | 56 | if (! empty($nodes[$page]->rels)) { |
59 | - $retval['body'] .= $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id); | |
57 | + $body[] = $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id); | |
60 | 58 | } else { |
61 | 59 | $alone[] = $page; |
62 | 60 | } |
63 | 61 | } |
64 | - $retval['body'] .= '</ul>' . "\n"; | |
62 | + $body[] = '</ul>'; | |
65 | 63 | if (! empty($alone)) { |
66 | - $retval['body'] .= '<hr />' . "\n" . | |
67 | - '<p>No link from anywhere in this site.</p>' . "\n"; | |
68 | - $retval['body'] .= '<ul>' . "\n"; | |
69 | - foreach ($alone as $page) | |
70 | - $retval['body'] .= $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id); | |
71 | - $retval['body'] .= '</ul>' . "\n"; | |
64 | + $body[] = '<hr />'; | |
65 | + $body[] = '<p>No link from anywhere in this site.</p>'; | |
66 | + $body[] = '<ul>'; | |
67 | + foreach ($alone as $page) { | |
68 | + $body[] = $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id); | |
69 | + } | |
70 | + $body[] = '</ul>'; | |
72 | 71 | } |
73 | 72 | } else { |
74 | 73 | $nodes[$refer]->chain($nodes); |
75 | - $retval['body'] .= '<ul>' . "\n" . $nodes[$refer]->toString($nodes) . '</ul>' . "\n"; | |
76 | - $retval['body'] .= '<hr />' . "\n" . | |
77 | - '<p>Not related from ' . htmlspecialchars($refer) . '</p>' . "\n"; | |
74 | + $body[] = '<ul>'; | |
75 | + $body[] = $nodes[$refer]->toString($nodes) . '</ul>'; | |
76 | + $body[] = '<hr />'; | |
77 | + $body[] = '<p>Not related from ' . htmlspecialchars($refer) . '</p>'; | |
78 | 78 | $keys = array_keys($nodes); |
79 | 79 | sort($keys); |
80 | - $retval['body'] .= '<ul>' . "\n"; | |
80 | + $body[] = '<ul>'; | |
81 | 81 | foreach ($keys as $page) { |
82 | 82 | if (! $nodes[$page]->done) { |
83 | 83 | $nodes[$page]->chain($nodes); |
84 | - $retval['body'] .= $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id); | |
84 | + $body[] = $nodes[$page]->toString($nodes, 1, $nodes[$page]->parent_id); | |
85 | 85 | } |
86 | 86 | } |
87 | - $retval['body'] .= '</ul>' . "\n"; | |
87 | + $body[] = '</ul>'; | |
88 | 88 | } |
89 | + | |
90 | + $body[] = '<hr />'; | |
91 | + $body[] = '<p>Total: ' . count($pages) . ' page(s) on this site.</p>'; | |
89 | 92 | |
90 | - // 終了 | |
93 | + | |
94 | + $retval['body'] = implode("\n", $body) . "\n"; | |
91 | 95 | return $retval; |
92 | 96 | } |
93 | 97 |
@@ -104,9 +108,14 @@ class MapNode | ||
104 | 108 | |
105 | 109 | function MapNode($page, $reverse = FALSE) |
106 | 110 | { |
107 | - global $script, $non_list; | |
111 | + global $non_list; | |
112 | + | |
113 | + static $script, $_hide_pattern, $id = 0; | |
108 | 114 | |
109 | - static $id = 0; | |
115 | + if (! isset($script)) { | |
116 | + $script = get_script_uri(); | |
117 | + $_hide_pattern = '/' . $non_list . '/'; | |
118 | + } | |
110 | 119 | |
111 | 120 | $this->page = $page; |
112 | 121 | $this->is_page = is_page($page); |
@@ -114,7 +123,7 @@ class MapNode | ||
114 | 123 | $this->done = ! $this->is_page; |
115 | 124 | $this->link = make_pagelink($page); |
116 | 125 | $this->id = ++$id; |
117 | - $this->hide_pattern = '/' . $non_list . '/'; | |
126 | + $this->hide_pattern = & $_hide_pattern; | |
118 | 127 | |
119 | 128 | $this->rels = $reverse ? $this->ref() : $this->rel(); |
120 | 129 | $mark = $reverse ? '' : '<sup>+</sup>'; |
@@ -125,8 +134,9 @@ class MapNode | ||
125 | 134 | |
126 | 135 | function hide(& $pages) |
127 | 136 | { |
128 | - if (! PLUGIN_MAP_SHOW_HIDDEN) | |
137 | + if (! PLUGIN_MAP_SHOW_HIDDEN) { | |
129 | 138 | $pages = array_diff($pages, preg_grep($this->hide_pattern, $pages)); |
139 | + } | |
130 | 140 | return $pages; |
131 | 141 | } |
132 | 142 |
@@ -170,8 +180,9 @@ class MapNode | ||
170 | 180 | if ($nodes[$page]->parent_id == 0) |
171 | 181 | $nodes[$page]->parent_id = $this->id; |
172 | 182 | } |
173 | - foreach ($this->rels as $page) | |
183 | + foreach ($this->rels as $page) { | |
174 | 184 | $nodes[$page]->chain($nodes); |
185 | + } | |
175 | 186 | } |
176 | 187 | |
177 | 188 | function toString(& $nodes, $level = 1, $parent_id = -1) |
@@ -179,26 +190,33 @@ class MapNode | ||
179 | 190 | $indent = str_repeat(' ', $level); |
180 | 191 | |
181 | 192 | if (! $this->is_page) { |
182 | - return $indent . '<li>' . $this->link . '</li>' . "\n"; | |
193 | + return $indent . '<li>' . $this->link . '</li>'; | |
183 | 194 | } else if ($this->parent_id != $parent_id) { |
184 | 195 | return $indent . '<li>' . $this->link . |
185 | - '<a href="#rel_' . $this->id . '">...</a></li>' . "\n"; | |
196 | + '<a href="#rel_' . $this->id . '">...</a></li>'; | |
197 | + } else if (empty($this->rels)) { | |
198 | + return $indent . '<li>' . $this->mark . $this->link . '</li>'; | |
186 | 199 | } |
187 | - $retval = $indent . '<li>' . $this->mark . $this->link . "\n"; | |
188 | - if (! empty($this->rels)) { | |
189 | - $childs = array(); | |
190 | - $level += 2; | |
191 | - foreach ($this->rels as $page) | |
192 | - if (isset($nodes[$page]) && $this->parent_id != $nodes[$page]->id) | |
193 | - $childs[] = $nodes[$page]->toString($nodes, $level, $this->id); | |
194 | - | |
195 | - if (! empty($childs)) | |
196 | - $retval .= $indent . ' <ul>' . "\n" . | |
197 | - join('', $childs) . $indent . ' </ul>' . "\n"; | |
200 | + | |
201 | + $retval = array(); | |
202 | + $retval[] = $indent . '<li>' . $this->mark . $this->link; | |
203 | + $childs = array(); | |
204 | + $level += 2; | |
205 | + foreach ($this->rels as $page) { | |
206 | + if (isset($nodes[$page]) && $this->parent_id != $nodes[$page]->id) { | |
207 | + $childs[] = $nodes[$page]->toString($nodes, $level, $this->id); | |
208 | + } | |
209 | + } | |
210 | + if (! empty($childs)) { | |
211 | + $retval[] = $indent . ' <ul>'; | |
212 | + foreach(array_keys($childs) as $key){ | |
213 | + $retval[] = & $childs[$key]; | |
214 | + } | |
215 | + $retval[] = $indent . ' </ul>'; | |
198 | 216 | } |
199 | - $retval .= $indent . '</li>' . "\n"; | |
217 | + $retval[] = $indent . '</li>'; | |
200 | 218 | |
201 | - return $retval; | |
219 | + return implode("\n", $retval); | |
202 | 220 | } |
203 | 221 | } |
204 | 222 | ?> |