Completed
Push — master ( d13b22...a2d243 )
by Justin
05:45
created
system/core/datatype/text.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,18 +27,18 @@
 block discarded – undo
27 27
 
28 28
 class DataType_Text extends DataType_Base {
29 29
 
30
-	public function getFormCode(): string {
31
-		return "<textarea name=\"" . $this->getInputName() . "\" rows=\"4\" cols=\"50\">" . $this->getValue() . "</textarea>";
32
-	}
33
-
34
-	public function validate(string $value): bool {
35
-		$val = new Validator_String();
36
-		return $val->isValide($value);
37
-	}
38
-
39
-	protected function saveAsync($value) {
40
-		Settings::setAsync($this->getKey(), (string) $value);
41
-	}
30
+    public function getFormCode(): string {
31
+        return "<textarea name=\"" . $this->getInputName() . "\" rows=\"4\" cols=\"50\">" . $this->getValue() . "</textarea>";
32
+    }
33
+
34
+    public function validate(string $value): bool {
35
+        $val = new Validator_String();
36
+        return $val->isValide($value);
37
+    }
38
+
39
+    protected function saveAsync($value) {
40
+        Settings::setAsync($this->getKey(), (string) $value);
41
+    }
42 42
 
43 43
 }
44 44
 
Please login to merge, or discard this patch.
system/core/datatype/menuselector.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -27,31 +27,31 @@
 block discarded – undo
27 27
 
28 28
 class DataType_MenuSelector extends DataType_Base {
29 29
 
30
-	public function getFormCode(): string {
31
-		$code = "<select name=\"" . $this->getInputName() . "\" class=\"form-control select2\" style=\"width: 100%;\">";
32
-
33
-		foreach (Menu::listMenuNames() as $row) {
34
-			$code .= "<option value=\"" . $row['menuID'] . "\"" . ($row['menuID'] == $this->getValue() ? " selected=\"selected\"" : "") . ">" . $row['title'] . "</option>";
35
-		}
36
-
37
-		$code .= "</select>";
38
-		return $code;
39
-	}
40
-
41
-	public function validate(string $value): bool {
42
-		foreach (Menu::listMenuNames() as $row) {
43
-			if ($row['menuID'] == $value) {
44
-				//menuID exists
45
-				return true;
46
-			}
47
-		}
48
-
49
-		return false;
50
-	}
51
-
52
-	protected function saveAsync($value) {
53
-		Settings::setAsync($this->getKey(), (int) $value);
54
-	}
30
+    public function getFormCode(): string {
31
+        $code = "<select name=\"" . $this->getInputName() . "\" class=\"form-control select2\" style=\"width: 100%;\">";
32
+
33
+        foreach (Menu::listMenuNames() as $row) {
34
+            $code .= "<option value=\"" . $row['menuID'] . "\"" . ($row['menuID'] == $this->getValue() ? " selected=\"selected\"" : "") . ">" . $row['title'] . "</option>";
35
+        }
36
+
37
+        $code .= "</select>";
38
+        return $code;
39
+    }
40
+
41
+    public function validate(string $value): bool {
42
+        foreach (Menu::listMenuNames() as $row) {
43
+            if ($row['menuID'] == $value) {
44
+                //menuID exists
45
+                return true;
46
+            }
47
+        }
48
+
49
+        return false;
50
+    }
51
+
52
+    protected function saveAsync($value) {
53
+        Settings::setAsync($this->getKey(), (int) $value);
54
+    }
55 55
 
56 56
 }
57 57
 
Please login to merge, or discard this patch.
system/core/datatype/sidebarchooser.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -27,36 +27,36 @@
 block discarded – undo
27 27
 
28 28
 class DataType_SidebarChooser extends DataType_Base {
29 29
 
30
-	public function getFormCode(): string {
31
-		$code = "<select name=\"" . $this->getInputName() . "\" class=\"form-control select2\" style=\"width: 100%;\">";
30
+    public function getFormCode(): string {
31
+        $code = "<select name=\"" . $this->getInputName() . "\" class=\"form-control select2\" style=\"width: 100%;\">";
32 32
 
33
-		foreach (Sidebar::listSidebars() as $sidebar) {
34
-			$sidebar = Sidebar::cast($sidebar);
35
-			$code .= "<option value=\"" . $sidebar->getSidebarId() . "\"" . ($sidebar->getSidebarId() == $this->getValue() ? " selected=\"selected\"" : "") . ">" . $sidebar->getTitle() . "</option>";
36
-		}
33
+        foreach (Sidebar::listSidebars() as $sidebar) {
34
+            $sidebar = Sidebar::cast($sidebar);
35
+            $code .= "<option value=\"" . $sidebar->getSidebarId() . "\"" . ($sidebar->getSidebarId() == $this->getValue() ? " selected=\"selected\"" : "") . ">" . $sidebar->getTitle() . "</option>";
36
+        }
37 37
 
38
-		$code .= "</select>";
38
+        $code .= "</select>";
39 39
 
40
-		return $code;
41
-	}
40
+        return $code;
41
+    }
42 42
 
43
-	public function validate(string $value): bool {
44
-		foreach (Sidebar::listSidebars() as $sidebar) {
45
-			$sidebar = Sidebar::cast($sidebar);
46
-			$value = (int) $value;
43
+    public function validate(string $value): bool {
44
+        foreach (Sidebar::listSidebars() as $sidebar) {
45
+            $sidebar = Sidebar::cast($sidebar);
46
+            $value = (int) $value;
47 47
 
48
-			if ($sidebar->getSidebarId() == $value) {
49
-				//sidebar exists
50
-				return true;
51
-			}
52
-		}
48
+            if ($sidebar->getSidebarId() == $value) {
49
+                //sidebar exists
50
+                return true;
51
+            }
52
+        }
53 53
 
54
-		return false;
55
-	}
54
+        return false;
55
+    }
56 56
 
57
-	protected function saveAsync($value) {
58
-		Settings::setAsync($this->getKey(), (int) $value);
59
-	}
57
+    protected function saveAsync($value) {
58
+        Settings::setAsync($this->getKey(), (int) $value);
59
+    }
60 60
 
61 61
 }
62 62
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.settings/classes/settings.php 2 patches
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -25,280 +25,280 @@
 block discarded – undo
25 25
  */
26 26
 class Settings {
27 27
 
28
-	//in-memory cache of settings
29
-	protected static $settings = array();
30
-
31
-	//flag, if global settings was initialized
32
-	protected static $initialized = false;
33
-
34
-	protected static $async_save_list = array();
35
-
36
-	/**
37
-	 * get value of setting
38
-	 *
39
-	 * @package com.jukusoft.cms.settings
40
-	 *
41
-	 * @param key setting
42
-	 *
43
-	 * @throws IllegalStateException of key doesnt exists and no default value is set
44
-	 *
45
-	 * @return mixed or null, if key doesnt exists in database / default value, if set
46
-	 */
47
-	public static function get (string $key, $default_value = null) {
48
-		//load settings if neccessary
49
-		self::loadSettingsIfAbsent();
50
-
51
-		if (!isset(self::$settings[$key])) {
52
-			if ($default_value !== null) {
53
-				return $default_value;
54
-			} else {
55
-				throw new IllegalStateException("Settings key '" . $key . "' doesnt exists.");
56
-			}
57
-		} else {
58
-			return unserialize(self::$settings[$key]);
59
-		}
60
-	}
61
-
62
-	/**
63
-	 * set setting
64
-	 *
65
-	 * @param $key setting
66
-	 * @param $value mixed value to set
67
-	 */
68
-	public static function set (string $key, $value) {
69
-		//serialize data
70
-		$value = serialize($value);
71
-
72
-		//update database
73
-		Database::getInstance()->execute("UPDATE `{praefix}global_settings` SET `value` = :value WHERE `key` = :key;", array(
74
-			'value' => $value,
75
-			'key' => $key
76
-		));
77
-
78
-		//update local in-memory cache
79
-		self::$settings[$key] = $value;
80
-
81
-		//clear cache (area "global_settings")
82
-		Cache::clear("global_settings");
83
-	}
84
-
85
-	public static function setAsync (string $key, $value) {
86
-		//only execute database query, if value was changed
87
-		if (isset(self::$async_save_list[$key]) || self::get($key) != $value) {
88
-			self::$async_save_list[$key] = $value;
89
-		}
90
-
91
-		//update local in-memory cache
92
-		self::$settings[$key] = serialize($value);
93
-	}
94
-
95
-	public static function saveAsync () {
96
-		if (!empty(self::$async_save_list)) {
97
-			foreach (self::$async_save_list as $key=>$value) {
98
-				Settings::set($key, $value);
99
-			}
100
-		}
101
-	}
102
-
103
-	/**
104
-	 * check if settings key exists
105
-	 *
106
-	 * @param $key string settings key
107
-	 *
108
-	 * @return true if setting key exists
109
-	 */
110
-	public static function contains (string $key) : bool {
111
-		//load settings if neccessary
112
-		self::loadSettingsIfAbsent();
113
-
114
-		//escape key
115
-		//$key = Database::getInstance()->escape($key);
116
-
117
-		return isset(self::$settings[$key]);
118
-	}
119
-
120
-	/**
121
-	 * set setting if key is absent
122
-	 *
123
-	 * @param $key setting
124
-	 * @param $value mixed value to set
125
-	 */
126
-	public static function setIfAbsent (string $key, $value) {
127
-		self::loadSettingsIfAbsent();
128
-
129
-		if (!isset(self::$settings[$key])) {
130
-			self::set($key, $value);
131
-		}
132
-	}
133
-
134
-	/**
135
-	 * create setting (so it can be shown on settings page)
136
-	 */
137
-	public static function create (string $key, $value, string $title, string $description, string $owner, string $category = "general", string $datatype = "DataType_String", $datatype_params = "", bool $editable = true, $visible_permissions = "can_see_global_settings", $change_permissions = "can_change_global_settings", int $order = 10, string $icon_path = "none", string $last_update = "0000-00-00 00:00:00") {
138
-		self::loadSettingsIfAbsent();
139
-
140
-		if (strlen($key) > 255) {
141
-			throw new IllegalArgumentException("max key length is 255, your key: " . $key);
142
-		}
143
-
144
-		//check, if setting already exists
145
-		/*if (isset(self::$settings[$key])) {
28
+    //in-memory cache of settings
29
+    protected static $settings = array();
30
+
31
+    //flag, if global settings was initialized
32
+    protected static $initialized = false;
33
+
34
+    protected static $async_save_list = array();
35
+
36
+    /**
37
+     * get value of setting
38
+     *
39
+     * @package com.jukusoft.cms.settings
40
+     *
41
+     * @param key setting
42
+     *
43
+     * @throws IllegalStateException of key doesnt exists and no default value is set
44
+     *
45
+     * @return mixed or null, if key doesnt exists in database / default value, if set
46
+     */
47
+    public static function get (string $key, $default_value = null) {
48
+        //load settings if neccessary
49
+        self::loadSettingsIfAbsent();
50
+
51
+        if (!isset(self::$settings[$key])) {
52
+            if ($default_value !== null) {
53
+                return $default_value;
54
+            } else {
55
+                throw new IllegalStateException("Settings key '" . $key . "' doesnt exists.");
56
+            }
57
+        } else {
58
+            return unserialize(self::$settings[$key]);
59
+        }
60
+    }
61
+
62
+    /**
63
+     * set setting
64
+     *
65
+     * @param $key setting
66
+     * @param $value mixed value to set
67
+     */
68
+    public static function set (string $key, $value) {
69
+        //serialize data
70
+        $value = serialize($value);
71
+
72
+        //update database
73
+        Database::getInstance()->execute("UPDATE `{praefix}global_settings` SET `value` = :value WHERE `key` = :key;", array(
74
+            'value' => $value,
75
+            'key' => $key
76
+        ));
77
+
78
+        //update local in-memory cache
79
+        self::$settings[$key] = $value;
80
+
81
+        //clear cache (area "global_settings")
82
+        Cache::clear("global_settings");
83
+    }
84
+
85
+    public static function setAsync (string $key, $value) {
86
+        //only execute database query, if value was changed
87
+        if (isset(self::$async_save_list[$key]) || self::get($key) != $value) {
88
+            self::$async_save_list[$key] = $value;
89
+        }
90
+
91
+        //update local in-memory cache
92
+        self::$settings[$key] = serialize($value);
93
+    }
94
+
95
+    public static function saveAsync () {
96
+        if (!empty(self::$async_save_list)) {
97
+            foreach (self::$async_save_list as $key=>$value) {
98
+                Settings::set($key, $value);
99
+            }
100
+        }
101
+    }
102
+
103
+    /**
104
+     * check if settings key exists
105
+     *
106
+     * @param $key string settings key
107
+     *
108
+     * @return true if setting key exists
109
+     */
110
+    public static function contains (string $key) : bool {
111
+        //load settings if neccessary
112
+        self::loadSettingsIfAbsent();
113
+
114
+        //escape key
115
+        //$key = Database::getInstance()->escape($key);
116
+
117
+        return isset(self::$settings[$key]);
118
+    }
119
+
120
+    /**
121
+     * set setting if key is absent
122
+     *
123
+     * @param $key setting
124
+     * @param $value mixed value to set
125
+     */
126
+    public static function setIfAbsent (string $key, $value) {
127
+        self::loadSettingsIfAbsent();
128
+
129
+        if (!isset(self::$settings[$key])) {
130
+            self::set($key, $value);
131
+        }
132
+    }
133
+
134
+    /**
135
+     * create setting (so it can be shown on settings page)
136
+     */
137
+    public static function create (string $key, $value, string $title, string $description, string $owner, string $category = "general", string $datatype = "DataType_String", $datatype_params = "", bool $editable = true, $visible_permissions = "can_see_global_settings", $change_permissions = "can_change_global_settings", int $order = 10, string $icon_path = "none", string $last_update = "0000-00-00 00:00:00") {
138
+        self::loadSettingsIfAbsent();
139
+
140
+        if (strlen($key) > 255) {
141
+            throw new IllegalArgumentException("max key length is 255, your key: " . $key);
142
+        }
143
+
144
+        //check, if setting already exists
145
+        /*if (isset(self::$settings[$key])) {
146 146
 			throw new IllegalArgumentException("global setting key '" . $key . "' already exists in database.");
147 147
 		}*/
148 148
 
149
-		//allow more than one possible permission as array
150
-		if (is_array($visible_permissions)) {
151
-			$visible_permissions = implode("|", $visible_permissions);
152
-		}
149
+        //allow more than one possible permission as array
150
+        if (is_array($visible_permissions)) {
151
+            $visible_permissions = implode("|", $visible_permissions);
152
+        }
153 153
 
154
-		//allow more than one possible permission as array
155
-		if (is_array($change_permissions)) {
156
-			$change_permissions = implode("|", $change_permissions);
157
-		}
154
+        //allow more than one possible permission as array
155
+        if (is_array($change_permissions)) {
156
+            $change_permissions = implode("|", $change_permissions);
157
+        }
158 158
 
159
-		//serialize value
160
-		$value = serialize($value);
161
-		$datatype_params = serialize($datatype_params);
159
+        //serialize value
160
+        $value = serialize($value);
161
+        $datatype_params = serialize($datatype_params);
162 162
 
163
-		//insert setting into database
164
-		Database::getInstance()->execute("INSERT INTO `{praefix}global_settings` (
163
+        //insert setting into database
164
+        Database::getInstance()->execute("INSERT INTO `{praefix}global_settings` (
165 165
 			`key`, `value`, `title`, `description`, `visible_permission`, `change_permission`, `owner`, `order`, `icon_path`, `last_update`, `datatype`, `datatype_params`, `editable`, `category`, `activated`
166 166
 		) VALUES (
167 167
 			:key, :value, :title, :description, :visible_permissions, :change_permissions, :owner, :order, :icon_path, '0000-00-00 00:00:00', :datatype, :datatype_params, :editable, :category, :activated
168 168
 		) ON DUPLICATE KEY UPDATE `title` = :title, `description` = :description, `visible_permission` = :visible_permissions, `change_permission` = :change_permissions, `owner` = :owner, `order` = :order, `icon_path` = :icon_path, `last_update` = CURRENT_TIMESTAMP, `datatype` = :datatype, `datatype_params` = :datatype_params, `editable` = :editable, `category` = :category; ", array(
169
-			'key' => $key,
170
-			'value' => $value,
171
-			'title' => $title,
172
-			'description' => $description,
173
-			'visible_permissions' => $visible_permissions,
174
-			'change_permissions' => $change_permissions,
175
-			'owner' => $owner,
176
-			'order' => (int) $order,
177
-			'icon_path' => $icon_path,
178
-			'datatype' => $datatype,
179
-			'datatype_params' => $datatype_params,
180
-			'editable' => ($editable ? 1 : 0),
181
-			'category' => $category,
182
-			'activated' => 1
183
-		));
184
-
185
-		//update value in local in-memory cache
186
-		self::$settings[$key] = $value;
187
-
188
-		//clear cache (area "global_settings")
189
-		Cache::clear("global_settings");
190
-	}
191
-
192
-	/**
193
-	 * delete setting
194
-	 */
195
-	public static function delete (string $key) {
196
-		//remove from in-memory cache
197
-		unset(self::$settings[$key]);
198
-
199
-		//remove key in database
200
-		Database::getInstance()->execute("DELETE FROM `{praefix}global_settings` WHERE `key` = :key; ", array('key' => $key));
201
-
202
-		//clear cache (area "global_settings")
203
-		Cache::clear("global_settings");
204
-	}
205
-
206
-	/**
207
-	 * initialize settings and get global settings
208
-	 */
209
-	protected static function loadCategorySettings (string $category) {
210
-		//$category = Database::getInstance()->escape($category);
211
-
212
-		$category_settings = array();
213
-
214
-		if (Cache::contains("global_settings", "settings-category-" + $category)) {
215
-			$category_settings = Cache::get("global_settings", "settings-category-" + $category);
216
-		} else {
217
-			//load settings from database
218
-			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}global_settings` WHERE `category` = :category AND `activated` = '1' ORDER BY `order`; ", array(
219
-				'category' => array(
220
-					'type' => PDO::PARAM_STR,
221
-					'value' => $category
222
-				)
223
-			));
224
-
225
-			foreach ($rows as $row) {
226
-				$category_settings[$row['key']] = $row['value'];
227
-			}
228
-
229
-			//cache rows
230
-			Cache::put("global_settings", "settings-category-" + $category, $category_settings);
231
-		}
232
-
233
-		//merge arrays
234
-		self::$settings = array_merge(self::$settings, $category_settings);
235
-
236
-		self::$initialized = true;
237
-	}
238
-
239
-	/**
240
-	 * initialize settings and get global settings
241
-	 */
242
-	protected static function loadAllSettings () {
243
-		if (Cache::contains("global_settings", "all-settings")) {
244
-			self::$settings = Cache::get("global_settings", "all-settings");
245
-		} else {
246
-			//load settings from database
247
-			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}global_settings` WHERE `activated` = '1' ORDER BY `order`; ");
169
+            'key' => $key,
170
+            'value' => $value,
171
+            'title' => $title,
172
+            'description' => $description,
173
+            'visible_permissions' => $visible_permissions,
174
+            'change_permissions' => $change_permissions,
175
+            'owner' => $owner,
176
+            'order' => (int) $order,
177
+            'icon_path' => $icon_path,
178
+            'datatype' => $datatype,
179
+            'datatype_params' => $datatype_params,
180
+            'editable' => ($editable ? 1 : 0),
181
+            'category' => $category,
182
+            'activated' => 1
183
+        ));
184
+
185
+        //update value in local in-memory cache
186
+        self::$settings[$key] = $value;
187
+
188
+        //clear cache (area "global_settings")
189
+        Cache::clear("global_settings");
190
+    }
191
+
192
+    /**
193
+     * delete setting
194
+     */
195
+    public static function delete (string $key) {
196
+        //remove from in-memory cache
197
+        unset(self::$settings[$key]);
198
+
199
+        //remove key in database
200
+        Database::getInstance()->execute("DELETE FROM `{praefix}global_settings` WHERE `key` = :key; ", array('key' => $key));
201
+
202
+        //clear cache (area "global_settings")
203
+        Cache::clear("global_settings");
204
+    }
205
+
206
+    /**
207
+     * initialize settings and get global settings
208
+     */
209
+    protected static function loadCategorySettings (string $category) {
210
+        //$category = Database::getInstance()->escape($category);
211
+
212
+        $category_settings = array();
213
+
214
+        if (Cache::contains("global_settings", "settings-category-" + $category)) {
215
+            $category_settings = Cache::get("global_settings", "settings-category-" + $category);
216
+        } else {
217
+            //load settings from database
218
+            $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}global_settings` WHERE `category` = :category AND `activated` = '1' ORDER BY `order`; ", array(
219
+                'category' => array(
220
+                    'type' => PDO::PARAM_STR,
221
+                    'value' => $category
222
+                )
223
+            ));
224
+
225
+            foreach ($rows as $row) {
226
+                $category_settings[$row['key']] = $row['value'];
227
+            }
228
+
229
+            //cache rows
230
+            Cache::put("global_settings", "settings-category-" + $category, $category_settings);
231
+        }
232
+
233
+        //merge arrays
234
+        self::$settings = array_merge(self::$settings, $category_settings);
235
+
236
+        self::$initialized = true;
237
+    }
238
+
239
+    /**
240
+     * initialize settings and get global settings
241
+     */
242
+    protected static function loadAllSettings () {
243
+        if (Cache::contains("global_settings", "all-settings")) {
244
+            self::$settings = Cache::get("global_settings", "all-settings");
245
+        } else {
246
+            //load settings from database
247
+            $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}global_settings` WHERE `activated` = '1' ORDER BY `order`; ");
248 248
 			
249
-			self::$settings = array();
249
+            self::$settings = array();
250 250
 
251
-			foreach ($rows as $row) {
252
-				self::$settings[$row['key']] = $row['value'];
253
-			}
251
+            foreach ($rows as $row) {
252
+                self::$settings[$row['key']] = $row['value'];
253
+            }
254 254
 
255
-			//cache rows
256
-			Cache::put("global_settings", "all-settings", self::$settings);
257
-		}
255
+            //cache rows
256
+            Cache::put("global_settings", "all-settings", self::$settings);
257
+        }
258 258
 
259
-		self::$initialized = true;
260
-	}
259
+        self::$initialized = true;
260
+    }
261 261
 
262
-	public static function listAllSettingsByCategory () {
263
-		//load settings if neccessary
264
-		self::loadSettingsIfAbsent();
262
+    public static function listAllSettingsByCategory () {
263
+        //load settings if neccessary
264
+        self::loadSettingsIfAbsent();
265 265
 
266
-		$rows = array();
266
+        $rows = array();
267 267
 
268
-		if (Cache::contains("global_settings", "all_rows")) {
269
-			$rows = Cache::get("global_settings", "all_rows");
270
-		} else {
271
-			//load settings from database
272
-			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}global_settings` WHERE `activated` = '1' ORDER BY `order`; ");
268
+        if (Cache::contains("global_settings", "all_rows")) {
269
+            $rows = Cache::get("global_settings", "all_rows");
270
+        } else {
271
+            //load settings from database
272
+            $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}global_settings` WHERE `activated` = '1' ORDER BY `order`; ");
273 273
 
274
-			Cache::put("global_settings", "all_rows", $rows);
275
-		}
274
+            Cache::put("global_settings", "all_rows", $rows);
275
+        }
276 276
 
277
-		$list = array();
277
+        $list = array();
278 278
 
279
-		foreach ($rows as $row) {
280
-			$category = $row['category'];
281
-			$key = $row['key'];
279
+        foreach ($rows as $row) {
280
+            $category = $row['category'];
281
+            $key = $row['key'];
282 282
 
283
-			//add array, if key doesnt exists in array
284
-			if (!isset($list[$category])) {
285
-				$list[$category] = array();
286
-			}
283
+            //add array, if key doesnt exists in array
284
+            if (!isset($list[$category])) {
285
+                $list[$category] = array();
286
+            }
287 287
 
288
-			$list[$category][$key] = $row;
289
-		}
288
+            $list[$category][$key] = $row;
289
+        }
290 290
 
291
-		return $list;
292
-	}
291
+        return $list;
292
+    }
293 293
 
294
-	/**
295
-	 * load settings, if class was not initialized yet
296
-	 */
297
-	protected static function loadSettingsIfAbsent () {
298
-		if (!self::$initialized) {
299
-			self::loadAllSettings();
300
-		}
301
-	}
294
+    /**
295
+     * load settings, if class was not initialized yet
296
+     */
297
+    protected static function loadSettingsIfAbsent () {
298
+        if (!self::$initialized) {
299
+            self::loadAllSettings();
300
+        }
301
+    }
302 302
 
303 303
 }
304 304
 
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return mixed or null, if key doesnt exists in database / default value, if set
46 46
 	 */
47
-	public static function get (string $key, $default_value = null) {
47
+	public static function get(string $key, $default_value = null) {
48 48
 		//load settings if neccessary
49 49
 		self::loadSettingsIfAbsent();
50 50
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 * @param $key setting
66 66
 	 * @param $value mixed value to set
67 67
 	 */
68
-	public static function set (string $key, $value) {
68
+	public static function set(string $key, $value) {
69 69
 		//serialize data
70 70
 		$value = serialize($value);
71 71
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		Cache::clear("global_settings");
83 83
 	}
84 84
 
85
-	public static function setAsync (string $key, $value) {
85
+	public static function setAsync(string $key, $value) {
86 86
 		//only execute database query, if value was changed
87 87
 		if (isset(self::$async_save_list[$key]) || self::get($key) != $value) {
88 88
 			self::$async_save_list[$key] = $value;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 		self::$settings[$key] = serialize($value);
93 93
 	}
94 94
 
95
-	public static function saveAsync () {
95
+	public static function saveAsync() {
96 96
 		if (!empty(self::$async_save_list)) {
97 97
 			foreach (self::$async_save_list as $key=>$value) {
98 98
 				Settings::set($key, $value);
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 *
108 108
 	 * @return true if setting key exists
109 109
 	 */
110
-	public static function contains (string $key) : bool {
110
+	public static function contains(string $key) : bool {
111 111
 		//load settings if neccessary
112 112
 		self::loadSettingsIfAbsent();
113 113
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 * @param $key setting
124 124
 	 * @param $value mixed value to set
125 125
 	 */
126
-	public static function setIfAbsent (string $key, $value) {
126
+	public static function setIfAbsent(string $key, $value) {
127 127
 		self::loadSettingsIfAbsent();
128 128
 
129 129
 		if (!isset(self::$settings[$key])) {
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	/**
135 135
 	 * create setting (so it can be shown on settings page)
136 136
 	 */
137
-	public static function create (string $key, $value, string $title, string $description, string $owner, string $category = "general", string $datatype = "DataType_String", $datatype_params = "", bool $editable = true, $visible_permissions = "can_see_global_settings", $change_permissions = "can_change_global_settings", int $order = 10, string $icon_path = "none", string $last_update = "0000-00-00 00:00:00") {
137
+	public static function create(string $key, $value, string $title, string $description, string $owner, string $category = "general", string $datatype = "DataType_String", $datatype_params = "", bool $editable = true, $visible_permissions = "can_see_global_settings", $change_permissions = "can_change_global_settings", int $order = 10, string $icon_path = "none", string $last_update = "0000-00-00 00:00:00") {
138 138
 		self::loadSettingsIfAbsent();
139 139
 
140 140
 		if (strlen($key) > 255) {
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	/**
193 193
 	 * delete setting
194 194
 	 */
195
-	public static function delete (string $key) {
195
+	public static function delete(string $key) {
196 196
 		//remove from in-memory cache
197 197
 		unset(self::$settings[$key]);
198 198
 
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
 	/**
207 207
 	 * initialize settings and get global settings
208 208
 	 */
209
-	protected static function loadCategorySettings (string $category) {
209
+	protected static function loadCategorySettings(string $category) {
210 210
 		//$category = Database::getInstance()->escape($category);
211 211
 
212 212
 		$category_settings = array();
213 213
 
214
-		if (Cache::contains("global_settings", "settings-category-" + $category)) {
215
-			$category_settings = Cache::get("global_settings", "settings-category-" + $category);
214
+		if (Cache::contains("global_settings", "settings-category-" +$category)) {
215
+			$category_settings = Cache::get("global_settings", "settings-category-" +$category);
216 216
 		} else {
217 217
 			//load settings from database
218 218
 			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}global_settings` WHERE `category` = :category AND `activated` = '1' ORDER BY `order`; ", array(
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 			}
228 228
 
229 229
 			//cache rows
230
-			Cache::put("global_settings", "settings-category-" + $category, $category_settings);
230
+			Cache::put("global_settings", "settings-category-" +$category, $category_settings);
231 231
 		}
232 232
 
233 233
 		//merge arrays
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	/**
240 240
 	 * initialize settings and get global settings
241 241
 	 */
242
-	protected static function loadAllSettings () {
242
+	protected static function loadAllSettings() {
243 243
 		if (Cache::contains("global_settings", "all-settings")) {
244 244
 			self::$settings = Cache::get("global_settings", "all-settings");
245 245
 		} else {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		self::$initialized = true;
260 260
 	}
261 261
 
262
-	public static function listAllSettingsByCategory () {
262
+	public static function listAllSettingsByCategory() {
263 263
 		//load settings if neccessary
264 264
 		self::loadSettingsIfAbsent();
265 265
 
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	/**
295 295
 	 * load settings, if class was not initialized yet
296 296
 	 */
297
-	protected static function loadSettingsIfAbsent () {
297
+	protected static function loadSettingsIfAbsent() {
298 298
 		if (!self::$initialized) {
299 299
 			self::loadAllSettings();
300 300
 		}
Please login to merge, or discard this patch.
system/core/datatype/boolean.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -27,26 +27,26 @@
 block discarded – undo
27 27
 
28 28
 class DataType_Boolean extends DataType_Base {
29 29
 
30
-	public function getFormCode(): string {
31
-		//return "<input type=\"checkbox\" name=\"" . $this->getInputName() . "\" value=\"" . $this->getTitle() . "\"" . ($this->getValue() == true ? " checked" : "") . " />";
30
+    public function getFormCode(): string {
31
+        //return "<input type=\"checkbox\" name=\"" . $this->getInputName() . "\" value=\"" . $this->getTitle() . "\"" . ($this->getValue() == true ? " checked" : "") . " />";
32 32
 
33
-		return "	<label>
33
+        return "	<label>
34 34
 						<input type=\"checkbox\" name=\"" . $this->getInputName() . "\" value=\"enabled\" class=\"flat-green\"" . ($this->getValue() == true ? " checked" : "") . " />
35 35
                 	</label>";
36
-	}
36
+    }
37 37
 
38
-	public function val () : bool {
39
-		//if key isn't set this means checkbox isn't checked
40
-		return true;
41
-	}
38
+    public function val () : bool {
39
+        //if key isn't set this means checkbox isn't checked
40
+        return true;
41
+    }
42 42
 
43
-	public function validate(string $value): bool {
44
-		return true;
45
-	}
43
+    public function validate(string $value): bool {
44
+        return true;
45
+    }
46 46
 
47
-	protected function saveAsync($value) {
48
-		Settings::setAsync($this->getKey(), (boolean) (isset($_REQUEST[$this->getInputName()]) ? true : false));
49
-	}
47
+    protected function saveAsync($value) {
48
+        Settings::setAsync($this->getKey(), (boolean) (isset($_REQUEST[$this->getInputName()]) ? true : false));
49
+    }
50 50
 }
51 51
 
52 52
 ?>
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
                 	</label>";
36 36
 	}
37 37
 
38
-	public function val () : bool {
38
+	public function val() : bool {
39 39
 		//if key isn't set this means checkbox isn't checked
40 40
 		return true;
41 41
 	}
Please login to merge, or discard this patch.
system/core/datatype/base.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -27,68 +27,68 @@
 block discarded – undo
27 27
 
28 28
 abstract class DataType_Base {
29 29
 
30
-	protected $row = array();
31
-	protected $datatype_params = null;
30
+    protected $row = array();
31
+    protected $datatype_params = null;
32 32
 
33
-	public function load (array $row, $datatype_params) {
34
-		$this->row = $row;
35
-		$this->datatype_params = $datatype_params;
36
-	}
33
+    public function load (array $row, $datatype_params) {
34
+        $this->row = $row;
35
+        $this->datatype_params = $datatype_params;
36
+    }
37 37
 
38
-	/**
39
-	 * @return array
40
-	 */
41
-	public function getRow (): array {
42
-		return $this->row;
43
-	}
38
+    /**
39
+     * @return array
40
+     */
41
+    public function getRow (): array {
42
+        return $this->row;
43
+    }
44 44
 
45
-	public function getDatatypeParams () {
46
-		return $this->datatype_params;
47
-	}
45
+    public function getDatatypeParams () {
46
+        return $this->datatype_params;
47
+    }
48 48
 
49
-	public function getInputName () {
50
-		return "setting_" . $this->row['key'];
51
-	}
49
+    public function getInputName () {
50
+        return "setting_" . $this->row['key'];
51
+    }
52 52
 
53
-	public function getKey () {
54
-		return $this->row['key'];
55
-	}
53
+    public function getKey () {
54
+        return $this->row['key'];
55
+    }
56 56
 
57
-	public function getTitle () : string {
58
-		if (is_array($this->datatype_params) && isset($this->datatype_params['checkbox_title'])) {
59
-			return $this->datatype_params['checkbox_title'];
60
-		}
57
+    public function getTitle () : string {
58
+        if (is_array($this->datatype_params) && isset($this->datatype_params['checkbox_title'])) {
59
+            return $this->datatype_params['checkbox_title'];
60
+        }
61 61
 
62
-		return $this->row['title'];
63
-	}
62
+        return $this->row['title'];
63
+    }
64 64
 
65
-	public function getDescription () : string {
66
-		return $this->row['description'];
67
-	}
65
+    public function getDescription () : string {
66
+        return $this->row['description'];
67
+    }
68 68
 
69
-	public function getValue () {
70
-		return unserialize($this->row['value']);
71
-	}
69
+    public function getValue () {
70
+        return unserialize($this->row['value']);
71
+    }
72 72
 
73
-	public abstract function getFormCode () : string;
73
+    public abstract function getFormCode () : string;
74 74
 
75
-	public abstract function validate (string $value) : bool;
75
+    public abstract function validate (string $value) : bool;
76 76
 
77
-	public function val () : bool {
78
-		return isset($_REQUEST[$this->getInputName()]) && $this->validate($_REQUEST[$this->getInputName()]);
79
-	}
77
+    public function val () : bool {
78
+        return isset($_REQUEST[$this->getInputName()]) && $this->validate($_REQUEST[$this->getInputName()]);
79
+    }
80 80
 
81
-	public final function save () {
82
-		//get value - because checkboxes doesn't require key is set, we have to check it first
83
-		$value = (isset($_REQUEST[$this->getInputName()]) ? $_REQUEST[$this->getInputName()] : "");
81
+    public final function save () {
82
+        //get value - because checkboxes doesn't require key is set, we have to check it first
83
+        $value = (isset($_REQUEST[$this->getInputName()]) ? $_REQUEST[$this->getInputName()] : "");
84 84
 
85
-		$this->saveAsync($value);
85
+        $this->saveAsync($value);
86 86
 
87
-		//set new value for form
88
-		$this->row['value'] = serialize($value);
89
-	}
87
+        //set new value for form
88
+        $this->row['value'] = serialize($value);
89
+    }
90 90
 
91
-	protected abstract function saveAsync ($value);
91
+    protected abstract function saveAsync ($value);
92 92
 
93 93
 }
94 94
 
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	protected $row = array();
31 31
 	protected $datatype_params = null;
32 32
 
33
-	public function load (array $row, $datatype_params) {
33
+	public function load(array $row, $datatype_params) {
34 34
 		$this->row = $row;
35 35
 		$this->datatype_params = $datatype_params;
36 36
 	}
@@ -38,23 +38,23 @@  discard block
 block discarded – undo
38 38
 	/**
39 39
 	 * @return array
40 40
 	 */
41
-	public function getRow (): array {
41
+	public function getRow(): array {
42 42
 		return $this->row;
43 43
 	}
44 44
 
45
-	public function getDatatypeParams () {
45
+	public function getDatatypeParams() {
46 46
 		return $this->datatype_params;
47 47
 	}
48 48
 
49
-	public function getInputName () {
49
+	public function getInputName() {
50 50
 		return "setting_" . $this->row['key'];
51 51
 	}
52 52
 
53
-	public function getKey () {
53
+	public function getKey() {
54 54
 		return $this->row['key'];
55 55
 	}
56 56
 
57
-	public function getTitle () : string {
57
+	public function getTitle() : string {
58 58
 		if (is_array($this->datatype_params) && isset($this->datatype_params['checkbox_title'])) {
59 59
 			return $this->datatype_params['checkbox_title'];
60 60
 		}
@@ -62,23 +62,23 @@  discard block
 block discarded – undo
62 62
 		return $this->row['title'];
63 63
 	}
64 64
 
65
-	public function getDescription () : string {
65
+	public function getDescription() : string {
66 66
 		return $this->row['description'];
67 67
 	}
68 68
 
69
-	public function getValue () {
69
+	public function getValue() {
70 70
 		return unserialize($this->row['value']);
71 71
 	}
72 72
 
73
-	public abstract function getFormCode () : string;
73
+	public abstract function getFormCode() : string;
74 74
 
75
-	public abstract function validate (string $value) : bool;
75
+	public abstract function validate(string $value) : bool;
76 76
 
77
-	public function val () : bool {
77
+	public function val() : bool {
78 78
 		return isset($_REQUEST[$this->getInputName()]) && $this->validate($_REQUEST[$this->getInputName()]);
79 79
 	}
80 80
 
81
-	public final function save () {
81
+	public final function save() {
82 82
 		//get value - because checkboxes doesn't require key is set, we have to check it first
83 83
 		$value = (isset($_REQUEST[$this->getInputName()]) ? $_REQUEST[$this->getInputName()] : "");
84 84
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 		$this->row['value'] = serialize($value);
89 89
 	}
90 90
 
91
-	protected abstract function saveAsync ($value);
91
+	protected abstract function saveAsync($value);
92 92
 
93 93
 }
94 94
 
Please login to merge, or discard this patch.
system/core/datatype/string.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,18 +27,18 @@
 block discarded – undo
27 27
 
28 28
 class DataType_String extends DataType_Base {
29 29
 
30
-	public function getFormCode(): string {
31
-		return "<input type=\"text\" name=\"" . $this->getInputName() . "\" value=\"" . $this->getValue() . "\" class=\"form-control\" />";
32
-	}
33
-
34
-	public function validate(string $value): bool {
35
-		$val = new Validator_String();
36
-		return $val->isValide($value);
37
-	}
38
-
39
-	protected function saveAsync($value) {
40
-		Settings::setAsync($this->getKey(), (string) $value);
41
-	}
30
+    public function getFormCode(): string {
31
+        return "<input type=\"text\" name=\"" . $this->getInputName() . "\" value=\"" . $this->getValue() . "\" class=\"form-control\" />";
32
+    }
33
+
34
+    public function validate(string $value): bool {
35
+        $val = new Validator_String();
36
+        return $val->isValide($value);
37
+    }
38
+
39
+    protected function saveAsync($value) {
40
+        Settings::setAsync($this->getKey(), (string) $value);
41
+    }
42 42
 
43 43
 }
44 44
 
Please login to merge, or discard this patch.
system/core/datatype/url.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,21 +27,21 @@
 block discarded – undo
27 27
 
28 28
 class DataType_URL extends DataType_Base {
29 29
 
30
-	public function getFormCode(): string {
31
-		return "<input type=\"text\" name=\"" . $this->getInputName() . "\" value=\"" . $this->getValue() . "\" required aria-required=\"true\" pattern=\"https?:\/\/.*|#.*\" placeholder=\"https://example.com\" class=\"form-control\" />";
32
-	}
30
+    public function getFormCode(): string {
31
+        return "<input type=\"text\" name=\"" . $this->getInputName() . "\" value=\"" . $this->getValue() . "\" required aria-required=\"true\" pattern=\"https?:\/\/.*|#.*\" placeholder=\"https://example.com\" class=\"form-control\" />";
32
+    }
33 33
 
34
-	public function validate(string $value): bool {
35
-		if ($value === "#") {
36
-			return true;
37
-		}
34
+    public function validate(string $value): bool {
35
+        if ($value === "#") {
36
+            return true;
37
+        }
38 38
 
39
-		return filter_var($value, FILTER_VALIDATE_URL);
40
-	}
39
+        return filter_var($value, FILTER_VALIDATE_URL);
40
+    }
41 41
 
42
-	protected function saveAsync($value) {
43
-		Settings::setAsync($this->getKey(), (string) $value);
44
-	}
42
+    protected function saveAsync($value) {
43
+        Settings::setAsync($this->getKey(), (string) $value);
44
+    }
45 45
 
46 46
 }
47 47
 
Please login to merge, or discard this patch.
system/core/datatype/username.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -27,20 +27,20 @@
 block discarded – undo
27 27
 
28 28
 class DataType_Username extends DataType_Base {
29 29
 
30
-	public function getFormCode(): string {
31
-		$regex = Settings::get("username_regex");
30
+    public function getFormCode(): string {
31
+        $regex = Settings::get("username_regex");
32 32
 
33
-		return "<input type=\"text\" name=\"" . $this->getInputName() . "\" value=\"" . $this->getValue() . "\" class=\"form-control\" />";
34
-	}
33
+        return "<input type=\"text\" name=\"" . $this->getInputName() . "\" value=\"" . $this->getValue() . "\" class=\"form-control\" />";
34
+    }
35 35
 
36
-	public function validate(string $value): bool {
37
-		$val = new Validator_Username();
38
-		return $val->isValide($value);
39
-	}
36
+    public function validate(string $value): bool {
37
+        $val = new Validator_Username();
38
+        return $val->isValide($value);
39
+    }
40 40
 
41
-	protected function saveAsync($value) {
42
-		Settings::setAsync($this->getKey(), (string) $value);
43
-	}
41
+    protected function saveAsync($value) {
42
+        Settings::setAsync($this->getKey(), (string) $value);
43
+    }
44 44
 
45 45
 }
46 46
 
Please login to merge, or discard this patch.