aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--lib/plugins/config/core/Setting/Setting.php29
-rw-r--r--lib/plugins/config/core/Setting/SettingArray.php13
-rw-r--r--lib/plugins/config/core/Setting/SettingNumeric.php12
-rw-r--r--lib/plugins/config/core/Writer.php4
4 files changed, 27 insertions, 31 deletions
diff --git a/lib/plugins/config/core/Setting/Setting.php b/lib/plugins/config/core/Setting/Setting.php
index ab7d81144..52d00c59f 100644
--- a/lib/plugins/config/core/Setting/Setting.php
+++ b/lib/plugins/config/core/Setting/Setting.php
@@ -183,24 +183,31 @@ class Setting {
}
/**
- * Generate string to save setting value to file according to $fmt
+ * Should the current local value be saved?
*
+ * @see out() to run when this returns true
+ * @return bool
+ */
+ public function shouldBeSaved() {
+ if($this->isProtected()) return false;
+ if($this->local === null) return false;
+ if($this->default == $this->local) return false;
+ return true;
+ }
+
+ /**
+ * Generate string to save local setting value to file according to $fmt
+ *
+ * @see shouldBeSaved() to check if this should be called
* @param string $var name of variable
* @param string $fmt save format
* @return string
*/
public function out($var, $fmt = 'php') {
+ if($fmt != 'php') return '';
- if($this->isProtected()) return '';
- if(is_null($this->local) || ($this->default == $this->local)) return '';
-
- $out = '';
-
- if($fmt == 'php') {
- $tr = array("\\" => '\\\\', "'" => '\\\'');
-
- $out = '$' . $var . "['" . $this->getArrayKey() . "'] = '" . strtr(cleanText($this->local), $tr) . "';\n";
- }
+ $tr = array("\\" => '\\\\', "'" => '\\\''); // escape the value
+ $out = '$' . $var . "['" . $this->getArrayKey() . "'] = '" . strtr(cleanText($this->local), $tr) . "';\n";
return $out;
}
diff --git a/lib/plugins/config/core/Setting/SettingArray.php b/lib/plugins/config/core/Setting/SettingArray.php
index 2f9172d18..c48dc760b 100644
--- a/lib/plugins/config/core/Setting/SettingArray.php
+++ b/lib/plugins/config/core/Setting/SettingArray.php
@@ -72,17 +72,10 @@ class SettingArray extends Setting {
/** @inheritdoc */
public function out($var, $fmt = 'php') {
+ if($fmt != 'php') return '';
- if($this->isProtected()) return '';
- if(is_null($this->local) || ($this->default == $this->local)) return '';
-
- $out = '';
-
- if($fmt == 'php') {
- $vals = array_map(array($this, 'escape'), $this->local);
- $out = '$' . $var . "['" . $this->getArrayKey() . "'] = array(" . join(', ', $vals) . ");\n";
- }
-
+ $vals = array_map(array($this, 'escape'), $this->local);
+ $out = '$' . $var . "['" . $this->getArrayKey() . "'] = array(" . join(', ', $vals) . ");\n";
return $out;
}
diff --git a/lib/plugins/config/core/Setting/SettingNumeric.php b/lib/plugins/config/core/Setting/SettingNumeric.php
index 8570838d2..8a6b17956 100644
--- a/lib/plugins/config/core/Setting/SettingNumeric.php
+++ b/lib/plugins/config/core/Setting/SettingNumeric.php
@@ -32,16 +32,10 @@ class SettingNumeric extends SettingString {
/** @inheritdoc */
public function out($var, $fmt = 'php') {
+ if($fmt != 'php') return '';
- if($this->isProtected()) return '';
- if(is_null($this->local) || ($this->default == $this->local)) return '';
-
- $out = '';
-
- if($fmt == 'php') {
- $local = $this->local === '' ? "''" : $this->local;
- $out .= '$' . $var . "['" . $this->getArrayKey() . "'] = " . $local . ";\n";
- }
+ $local = $this->local === '' ? "''" : $this->local;
+ $out = '$' . $var . "['" . $this->getArrayKey() . "'] = " . $local . ";\n";
return $out;
}
diff --git a/lib/plugins/config/core/Writer.php b/lib/plugins/config/core/Writer.php
index 39e5e9782..6dee223ac 100644
--- a/lib/plugins/config/core/Writer.php
+++ b/lib/plugins/config/core/Writer.php
@@ -44,7 +44,9 @@ class Writer {
$out = $this->getHeader();
foreach($settings as $setting) {
- $out .= $setting->out('conf', 'php');
+ if($setting->shouldBeSaved()) {
+ $out .= $setting->out('conf', 'php');
+ }
}
fwrite($fh, $out);