X-Git-Url: http://www.andromeda.nl/gitweb/?p=gnucomo.git;a=blobdiff_plain;f=src%2Fphpclasses%2Fconfiguration.class.php;h=1aaaa66b48b6aa9dcccab76ab93e76022a4e9447;hp=30a14466166af438310a5dbc60e396faf9e36eb5;hb=cacf62f70a6af511fc5573210e309bc47f8eb1a8;hpb=90c1513c3549903aca8860c1eea70e3208f99497
diff --git a/src/phpclasses/configuration.class.php b/src/phpclasses/configuration.class.php
index 30a1446..1aaaa66 100644
--- a/src/phpclasses/configuration.class.php
+++ b/src/phpclasses/configuration.class.php
@@ -37,8 +37,8 @@ class configuration
function configuration()
{
- $system = false;
- $user = false;
+ $this->system = false;
+ $this->user = false;
}
function xmlFindTag($node, $tag)
@@ -60,6 +60,7 @@ class configuration
function read($app_name)
{
+ $this->system = false;
$filename = "/etc/" . $app_name . ".conf";
if (!is_readable($filename))
{
@@ -81,10 +82,38 @@ class configuration
}
}
}
- else
+
+ $this->user = false;
+ if (isset($_ENV['HOME']) && $_ENV['HOME'] != '/')
{
- print("Configuration error: Configuration file for $app_name not found.
");
+ // Read configurations from the user's homedir.
+
+ $filename = $_ENV['HOME'] . "/." . $app_name . ".conf";
+ if (is_readable($filename))
+ {
+
+ $this->user = xmldocfile($filename);
+
+ if ($this->user)
+ {
+ $root = $this->user->root();
+
+ if ($root->tagname != $app_name)
+ {
+ print("Configuration error: Wrong configuration file.
");
+ $this->user = false;
+ }
+ }
+ }
+
+ }
+
+ if ($this->system == false && $this->user == false)
+ {
+ print("Configuration error: Configuration file for $app_name not found.
\n");
}
+
+ return $this->system != false || $this->user != false;
}
function find_parameter($section, $parameter)
@@ -109,6 +138,27 @@ class configuration
}
}
+ // If the parameter is also defined in the user config, it will override
+ // the system-wide value.
+
+ if ($this->user)
+ {
+ $root_node = $this->user->root();
+ $section_node = $this->xmlFindTag($root_node->children(), $section);
+ if ($section_node)
+ {
+ $param_node = $this->xmlFindTag($section_node->children(), $parameter);
+ if ($param_node)
+ {
+ $param_node = $param_node->children();
+ }
+ if ($param_node && $param_node[0]->type == XML_TEXT_NODE)
+ {
+ $param_value = $param_node[0]->content;
+ }
+ }
+ }
+
return $param_value;
}
}