*
* Copyright 2009, Roland Mas
*
- * This file is part of FusionForge.
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
*
- * FusionForge is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * FusionForge is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// See docs in http://fusionforge.org/plugins/mediawiki/wiki/fusionforge/index.php/Configuration
/**
- *
+ *
* Singleton FusionForge configuration database manager TODO : Enter better description here ...
*
*/
static protected $instance = NULL ;
private $settings ;
private $bools = array () ;
-
+
/**
* Singleton accessor to the configuration database
* @return FusionForgeConfig instance
}
return self::$instance ;
}
-
+
// TODO: add a constructor that initializes self::$instance to self ?
-
+
public function get_sections () {
return array_keys ($this->settings) ;
}
foreach ($matches[0] as $m) {
$c = explode ('/', substr($m,1)) ;
-
+
if (isset ($this->settings[$c[0]][$c[1]])) {
$tmp = str_replace ($m, $this->get_value($c[0],$c[1]), $tmp) ;
}
}
}
+ public function reset_value ($section, $var, $value) {
+ if (!isset ($this->settings[$section])) {
+ $this->settings[$section] = array () ;
+ }
+
+ $this->settings[$section][$var] = $value ;
+ }
+
function read_config_file ($filename) {
+ if (getenv ('FUSIONFORGE_USE_PRE_51_CONFIG') == 'true') {
+ $fallback_only = true;
+ } else {
+ $fallback_only = false;
+ }
+
if (file_exists($filename) && is_readable($filename)) {
$sections = parse_ini_file ($filename, true) ;
if (is_array($sections)) {
foreach ($sections as $section => $options) {
+ if (!is_array($options)) {
+ continue;
+ }
foreach ($options as $var => $value) {
- $this->settings[$section][$var] = $value ;
+ if ($fallback_only) {
+ $this->set_value($section,$var,$value);
+ } else {
+ $this->reset_value($section,$var,$value);
+ }
}
}
}
case '1':
return true ;
}
-
+
return false ;
}
- }
+}
if (!isset ($fusionforge_config)) {
- $fusionforge_config = new FusionForgeConfig () ;
+ $fusionforge_config = new FusionForgeConfig();
}
/**
return $c->mark_as_bool ($section, $var) ;
}
+/**
+ * Define a new boolean configuration item with given name/section and default value
+ * @param string $var name
+ * @param string $section
+ * @param any $default
+ */
+function forge_define_config_item_bool ($var, $section, $default) {
+ forge_define_config_item ($var, $section, $default);
+ forge_set_config_item_bool ($var, $section);
+}
+
/**
* Read a *.ini file and inject its contents into the configuration database
* @param string $file
*/
function forge_read_config_dir ($path) {
$c = FusionForgeConfig::get_instance () ;
-
+
$files = array () ;
-
+
if (is_dir($path)){
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
- if ($file != "."
+ if ($file != "."
&& $file != ".."
// Avoid .bak, .old, .dpkg-old and so on, but keep .ini
&& preg_match ('/^[0-9a-zA-Z_-]+(.ini)?$/', $file)) {
}
}
+function forge_reset_config_item ($var, $section, $default) {
+ $c = FusionForgeConfig::get_instance () ;
+
+ return $c->reset_value ($section, $var, $default) ;
+}
+
// Local Variables:
// mode: php
// c-file-style: "bsd"