1: <?php
2:
3: 4: 5: 6: 7: 8:
9: function updateConfigItem($item, $value, $zp_cfg, $quote = true) {
10: if ($quote) {
11: $value = '"' . $value . '"';
12: }
13: $i = strpos($zp_cfg, $item);
14: if ($i === false) {
15: $parts = preg_split('~\/\*.*Do not edit below this line.*\*\/~', $zp_cfg);
16: if (isset($parts[1])) {
17: $zp_cfg = $parts[0] . "\$conf['" . $item . "'] = " . $value . ";\n/** Do not edit below this line. **/" . $parts[1];
18: } else {
19: zp_error(gettext('The Zenphoto configuration file is corrupt. You will need to restore it from a backup.'));
20: }
21: } else {
22: $i = strpos($zp_cfg, '=', $i);
23: $j = strpos($zp_cfg, "\n", $i);
24: $zp_cfg = substr($zp_cfg, 0, $i) . '= ' . $value . ';' . substr($zp_cfg, $j);
25: }
26: return $zp_cfg;
27: }
28:
29: 30: 31: 32: 33:
34: function storeConfig($zp_cfg) {
35: debugLogBacktrace(gettext('Updating the configuration file'));
36: $mod = fileperms(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE) & 0777;
37: @rename(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE, $backkup = SERVERPATH . '/' . DATA_FOLDER . '/' . stripSuffix(CONFIGFILE) . '.bak.php');
38: @chmod($backup, $mod);
39: file_put_contents(SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE, $zp_cfg);
40: @chmod($backup, SERVERPATH . '/' . DATA_FOLDER . '/' . CONFIGFILE, $mod);
41: }
42:
43: ?>