function configuration()
{
- $system = false;
- $user = false;
+ $this->system = false;
+ $this->user = false;
}
function xmlFindTag($node, $tag)
function read($app_name)
{
+ $this->system = false;
$filename = "/etc/" . $app_name . ".conf";
if (!is_readable($filename))
{
}
}
}
- else
+
+ $this->user = false;
+ if (isset($_ENV['HOME']) && $_ENV['HOME'] != '/')
{
- print("Configuration error: Configuration file for $app_name not found.<br>");
+ // 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.<br>");
+ $this->user = false;
+ }
+ }
+ }
+
+ }
+
+ if ($this->system == false && $this->user == false)
+ {
+ print("Configuration error: Configuration file for $app_name not found.<br>\n");
}
+
+ return $this->system != false || $this->user != false;
}
function find_parameter($section, $parameter)
}
}
+ // 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;
}
}