OSDN Git Service

PukiWiki version is "1.5.4" / Year 2021
[pukiwiki/pukiwiki.git] / lib / config.php
index 0ec1dfa..ec6dc7c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: config.php,v 1.5 2005/04/29 09:10:11 henoheno Exp $
-// Copywrite (C) 2003-2005 PukiWiki Developers Team
+// config.php
+// Copyright 2003-2021 PukiWiki Development Team
 // License: GPL v2 or (at your option) any later version
 //
 // Parse a PukiWiki page as a configuration page
@@ -29,6 +29,10 @@ class Config
 
        function Config($name)
        {
+               $this->__construct($name);
+       }
+       function __construct($name)
+       {
                $this->name = $name;
                $this->page = PKWK_CONFIG_PREFIX . $name;
        }
@@ -39,13 +43,13 @@ class Config
                if (! is_page($this->page)) return FALSE;
 
                $this->objs = array();
-               $obj        = new ConfigTable('');
+               $obj        = new ConfigTable('');
                $matches = array();
 
                foreach (get_source($this->page) as $line) {
                        if ($line == '') continue;
 
-                       $head  = $line{0};      // The first letter
+                       $head  = $line[0];      // The first letter
                        $level = strspn($line, $head);
 
                        if ($level > 3) {
@@ -57,22 +61,22 @@ class Config
 
                                if ($level == 1) {
                                        $this->objs[$obj->title] = $obj;
-                                       $obj = new ConfigTable($line);
+                                       $obj = new ConfigTable($line);
                                } else {
                                        if (! is_a($obj, 'ConfigTable_Direct'))
-                                               $obj = new ConfigTable_Direct('', $obj);
+                                               $obj = new ConfigTable_Direct('', $obj);
                                        $obj->set_key($line);
                                }
                                
                        } else if ($head == '-' && $level > 1) {
                                if (! is_a($obj, 'ConfigTable_Direct'))
-                                       $obj = new ConfigTable_Direct('', $obj);
+                                       $obj = new ConfigTable_Direct('', $obj);
                                $obj->add_value($line);
 
                        } else if ($head == '|' && preg_match('/^\|(.+)\|\s*$/', $line, $matches)) {
                                // Table row
                                if (! is_a($obj, 'ConfigTable_Sequential'))
-                                       $obj = new ConfigTable_Sequential('', $obj);
+                                       $obj = new ConfigTable_Sequential('', $obj);
                                // Trim() each table cell
                                $obj->add_value(array_map('trim', explode('|', $matches[1])));
                        } else {
@@ -109,7 +113,7 @@ class Config
        function & get_object($title)
        {
                if (! isset($this->objs[$title]))
-                       $this->objs[$title] = new ConfigTable('*' . trim($title) . "\n");
+                       $this->objs[$title] = new ConfigTable('*' . trim($title) . "\n");
                return $this->objs[$title];
        }
 
@@ -137,6 +141,10 @@ class ConfigTable
 
        function ConfigTable($title, $obj = NULL)
        {
+               $this->__construct($title, $obj);
+       }
+       function __construct($title, $obj = NULL)
+       {
                if ($obj !== NULL) {
                        $this->title  = $obj->title;
                        $this->before = array_merge($obj->before, $obj->after);
@@ -221,4 +229,3 @@ class ConfigTable_Direct extends ConfigTable
                return $retval;
        }
 }
-?>