+ /** Writes an ini file separated in categories
+ * @param filename the name of the file to write (overwrite existing)
+ * @param categories an array of categories (array of keys and values)
+ */
+ private static function write_ini_file($filename, &$categories)
+ {
+ // [category]
+ // key = value
+ $f = fopen($filename, 'w');
+ foreach ($categories as $cat => $conf) {
+ fwrite($f, '; {{{ '.$cat."\n\n");
+ fwrite($f, '['.$cat.']'."\n\n");
+ foreach ($conf as $k => $v) {
+ fwrite($f, $k.' = "'.str_replace('"','\\"',$v).'"'."\n");
+ }
+ fwrite($f, "\n".'; }}}'."\n");
+ }
+ fwrite($f, '; vim:set syntax=dosini foldmethod=marker:'."\n");
+ fclose($f);
+ }
+
+ /** Change dynamic config file
+ * @param conf array of keys and values to add or replace
+ * @param category name of category to change
+ *
+ * Opens the dynamic conf file and set values from conf in specified
+ * category. Updates config vars too.
+ */
+ public function change_dynamic_config($conf, $category = 'Core')
+ {
+ $dynamicfile = $this->spoolroot.'/spool/conf/platal.dynamic.conf';
+ if (file_exists($dynamicfile)) {
+ $array = parse_ini_file($dynamicfile, true);
+ } else {
+ $array = null;
+ }
+ if (!is_array($array)) {
+ // dynamic conf is empty
+ $array = array($category => $conf);
+ } else {
+ // looks for a category that looks the same (case insensitive)
+ $same = false;
+ foreach ($array as $m => &$c) {
+ if (strtolower($m) == strtolower($category)) {
+ $same = $m;
+ break;