• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión398acb9df44cd8b42a629d0ff75d028ee448a185 (tree)
Tiempo2007-04-15 23:37:04
Autorhenoheno <henoheno>
Commiterhenoheno

Log Message

Simplify br. Beautify XHTML br. Show total counts at the bottom of the page (this is not the main function).

Cambiar Resumen

Diferencia incremental

--- a/plugin/map.inc.php
+++ b/plugin/map.inc.php
@@ -1,18 +1,15 @@
11 <?php
22 // 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
46 //
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+
1613
1714 // Show $non_list files
1815 define('PLUGIN_MAP_SHOW_HIDDEN', 0); // 0, 1
@@ -23,28 +20,29 @@ function plugin_map_action()
2320
2421 $reverse = isset($vars['reverse']);
2522 $refer = isset($vars['refer']) ? $vars['refer'] : '';
26- if ($refer == '' || ! is_page($refer))
23+ if ($refer == '' || ! is_page($refer)) {
2724 $vars['refer'] = $refer = $defaultpage;
25+ }
2826
2927 $retval['msg'] = $reverse ? 'Relation map (link from)' : 'Relation map, from $1';
30- $retval['body'] = '';
3128
3229 // Get pages
3330 $pages = array_values(array_diff(get_existpages(), array($whatsnew)));
34- if (! PLUGIN_MAP_SHOW_HIDDEN)
31+ if (! PLUGIN_MAP_SHOW_HIDDEN) {
3532 $pages = array_diff($pages, preg_grep('/' . $non_list . '/', $pages));
33+ }
3634 if (empty($pages)) {
37- $retval['body'] = 'No pages.';
35+ $retval['body'] = 'No page.';
3836 return $retval;
39- } else {
40- $retval['body'] .= '<p>' . "\n" . 'Total: ' . count($pages) .
41- ' page(s) on this site.' . "\n" . '</p>' . "\n";
4237 }
4338
39+ $body = array();
40+
4441 // Generate a tree
4542 $nodes = array();
46- foreach ($pages as $page)
43+ foreach ($pages as $page) {
4744 $nodes[$page] = & new MapNode($page, $reverse);
45+ }
4846
4947 // Node not found: Because of filtererd by $non_list
5048 if (! isset($nodes[$refer])) $vars['refer'] = $refer = $defaultpage;
@@ -53,41 +51,47 @@ function plugin_map_action()
5351 $keys = array_keys($nodes);
5452 sort($keys);
5553 $alone = array();
56- $retval['body'] .= '<ul>' . "\n";
54+ $body[] = '<ul>';
5755 foreach ($keys as $page) {
5856 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);
6058 } else {
6159 $alone[] = $page;
6260 }
6361 }
64- $retval['body'] .= '</ul>' . "\n";
62+ $body[] = '</ul>';
6563 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>';
7271 }
7372 } else {
7473 $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>';
7878 $keys = array_keys($nodes);
7979 sort($keys);
80- $retval['body'] .= '<ul>' . "\n";
80+ $body[] = '<ul>';
8181 foreach ($keys as $page) {
8282 if (! $nodes[$page]->done) {
8383 $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);
8585 }
8686 }
87- $retval['body'] .= '</ul>' . "\n";
87+ $body[] = '</ul>';
8888 }
89+
90+ $body[] = '<hr />';
91+ $body[] = '<p>Total: ' . count($pages) . ' page(s) on this site.</p>';
8992
90- // 終了
93+
94+ $retval['body'] = implode("\n", $body) . "\n";
9195 return $retval;
9296 }
9397
@@ -104,9 +108,14 @@ class MapNode
104108
105109 function MapNode($page, $reverse = FALSE)
106110 {
107- global $script, $non_list;
111+ global $non_list;
112+
113+ static $script, $_hide_pattern, $id = 0;
108114
109- static $id = 0;
115+ if (! isset($script)) {
116+ $script = get_script_uri();
117+ $_hide_pattern = '/' . $non_list . '/';
118+ }
110119
111120 $this->page = $page;
112121 $this->is_page = is_page($page);
@@ -114,7 +123,7 @@ class MapNode
114123 $this->done = ! $this->is_page;
115124 $this->link = make_pagelink($page);
116125 $this->id = ++$id;
117- $this->hide_pattern = '/' . $non_list . '/';
126+ $this->hide_pattern = & $_hide_pattern;
118127
119128 $this->rels = $reverse ? $this->ref() : $this->rel();
120129 $mark = $reverse ? '' : '<sup>+</sup>';
@@ -125,8 +134,9 @@ class MapNode
125134
126135 function hide(& $pages)
127136 {
128- if (! PLUGIN_MAP_SHOW_HIDDEN)
137+ if (! PLUGIN_MAP_SHOW_HIDDEN) {
129138 $pages = array_diff($pages, preg_grep($this->hide_pattern, $pages));
139+ }
130140 return $pages;
131141 }
132142
@@ -170,8 +180,9 @@ class MapNode
170180 if ($nodes[$page]->parent_id == 0)
171181 $nodes[$page]->parent_id = $this->id;
172182 }
173- foreach ($this->rels as $page)
183+ foreach ($this->rels as $page) {
174184 $nodes[$page]->chain($nodes);
185+ }
175186 }
176187
177188 function toString(& $nodes, $level = 1, $parent_id = -1)
@@ -179,26 +190,33 @@ class MapNode
179190 $indent = str_repeat(' ', $level);
180191
181192 if (! $this->is_page) {
182- return $indent . '<li>' . $this->link . '</li>' . "\n";
193+ return $indent . '<li>' . $this->link . '</li>';
183194 } else if ($this->parent_id != $parent_id) {
184195 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>';
186199 }
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>';
198216 }
199- $retval .= $indent . '</li>' . "\n";
217+ $retval[] = $indent . '</li>';
200218
201- return $retval;
219+ return implode("\n", $retval);
202220 }
203221 }
204222 ?>