OSDN Git Service

Enable to hide $non_list files. Added PLUGIN_MAP_SHOW_HIDDEN.
authorhenoheno <henoheno>
Mon, 10 Jan 2005 09:17:11 +0000 (18:17 +0900)
committerhenoheno <henoheno>
Mon, 10 Jan 2005 09:17:11 +0000 (18:17 +0900)
(Started from a patch by teanan)

plugin/map.inc.php

index e24c55b..530d5f5 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: map.inc.php,v 1.13 2005/01/08 11:35:37 henoheno Exp $
+// $Id: map.inc.php,v 1.14 2005/01/10 09:17:11 henoheno Exp $
 //
-// Site-map plugin
+// Site map plugin
 
 /*
  * ¥×¥é¥°¥¤¥ó map: ¥µ¥¤¥È¥Þ¥Ã¥×(¤Î¤è¤¦¤Ê¤â¤Î)¤òɽ¼¨
  *     ¤¢¤ë¥Ú¡¼¥¸¤¬¤É¤³¤«¤é¥ê¥ó¥¯¤µ¤ì¤Æ¤¤¤ë¤«¤ò°ìÍ÷¡£
 */
 
+// Show $non_list files
+define('PLUGIN_MAP_SHOW_HIDDEN', 0); // 0, 1
+
 function plugin_map_action()
 {
-       global $vars, $whatsnew, $defaultpage;
+       global $vars, $whatsnew, $defaultpage, $non_list;
 
        $reverse = isset($vars['reverse']);
        $refer   = isset($vars['refer']) ? $vars['refer'] : '';
@@ -26,24 +29,26 @@ function plugin_map_action()
        $retval['msg']  = $reverse ? 'Relation map (link from)' : 'Relation map, from $1';
        $retval['body'] = '';
 
+       // Get pages
        $pages = array_values(array_diff(get_existpages(), array($whatsnew)));
-
-       $count = count($pages);
-       if ($count == 0) {
-               $retval['body'] = 'no pages.';
+       if (! PLUGIN_MAP_SHOW_HIDDEN)
+               $pages = array_diff($pages, preg_grep('/' . $non_list . '/', $pages));
+       if (empty($pages)) {
+               $retval['body'] = 'No pages.';
                return $retval;
+       } else {
+               $retval['body'] .= '<p>' . "\n" .  'Total: ' . count($pages) .
+                       ' page(s) on this site.' . "\n" . '</p>' . "\n";
        }
 
-       // ¥Ú¡¼¥¸¿ô
-       $retval['body'] .= '<p>' . "\n" .
-               'Total: ' . $count . ' page(s) on this site.' . "\n" .
-               '</p>' . "\n";
-
-       // ¥Ä¥ê¡¼ºîÀ®
+       // Generate a tree
        $nodes = array();
        foreach ($pages as $page)
                $nodes[$page] = & new MapNode($page, $reverse);
 
+       // Node not found: Because of filtererd by $non_list
+       if (! isset($nodes[$refer])) $vars['refer'] = $refer = $defaultpage;
+
        if ($reverse) {
                $keys = array_keys($nodes);
                sort($keys);
@@ -81,6 +86,7 @@ function plugin_map_action()
                }
                $retval['body'] .= '</ul>' . "\n";
        }
+
        // ½ªÎ»
        return $retval;
 }
@@ -94,10 +100,11 @@ class MapNode
        var $rels;
        var $parent_id = 0;
        var $done;
+       var $hide_pattern;
 
        function MapNode($page, $reverse = FALSE)
        {
-               global $script;
+               global $script, $non_list;
 
                static $id = 0;
 
@@ -107,6 +114,7 @@ class MapNode
                $this->done    = ! $this->is_page;
                $this->link    = make_pagelink($page);
                $this->id      = ++$id;
+               $this->hide_pattern = '/' . $non_list . '/';
 
                $this->rels = $reverse ? $this->ref() : $this->rel();
                $mark       = $reverse ? '' : '<sup>+</sup>';
@@ -115,6 +123,13 @@ class MapNode
                        $mark . '</a>';
        }
 
+       function hide(& $pages)
+       {
+               if (! PLUGIN_MAP_SHOW_HIDDEN)
+                       $pages = array_diff($pages, preg_grep($this->hide_pattern, $pages));
+               return $pages;
+       }
+
        function ref()
        {
                $refs = array();
@@ -124,6 +139,7 @@ class MapNode
                                $ref = explode("\t", $line);
                                $refs[] = $ref[0];
                        }
+                       $this->hide($refs);
                        sort($refs);
                }
                return $refs;
@@ -136,6 +152,7 @@ class MapNode
                if (file_exists($file)) {
                        $data = file($file);
                        $rels = explode("\t", trim($data[0]));
+                       $this->hide($rels);
                        sort($rels);
                }
                return $rels;