|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xoops\Core\Text\Sanitizer; |
|
13
|
|
|
|
|
14
|
|
|
use Xmf\Yaml; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Provide a standard mechanism for a runtime registry for key/value pairs, useful |
|
18
|
|
|
* for attributes and parameters. |
|
19
|
|
|
* |
|
20
|
|
|
* @category Sanitizer |
|
21
|
|
|
* @package Xoops\Core\Text |
|
22
|
|
|
* @author Richard Griffith <[email protected]> |
|
23
|
|
|
* @copyright 2013-2015 XOOPS Project (http://xoops.org) |
|
24
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
25
|
|
|
* @link http://xoops.org |
|
26
|
|
|
*/ |
|
27
|
|
|
class Configuration extends ConfigurationAbstract |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var string config file with sanitizer prefs |
|
31
|
|
|
*/ |
|
32
|
|
|
private $sanitizerPrefsFilename = 'var/configs/system_sanitizer_prefs.yml'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get the sanitizer configuration. |
|
36
|
|
|
*/ |
|
37
|
3 |
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
3 |
|
$sanitizerConfiguration = $this->readSanitizerPreferences(); |
|
40
|
3 |
|
parent::__construct($sanitizerConfiguration); |
|
41
|
3 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* readSanitizerPreferences - read configured sanitizer preferences |
|
45
|
|
|
* |
|
46
|
|
|
* If configuration file does not exist, create it. |
|
47
|
|
|
* |
|
48
|
|
|
* If configurable extensions exist that are not in the configuration |
|
49
|
|
|
* file, add them, and rewrite the configuration file. |
|
50
|
|
|
* |
|
51
|
|
|
* @return array of sanitizer preferences |
|
52
|
|
|
*/ |
|
53
|
3 |
|
protected function readSanitizerPreferences() |
|
54
|
|
|
{ |
|
55
|
3 |
|
$xoops = \Xoops::getInstance(); |
|
56
|
|
|
|
|
57
|
3 |
|
$sanitizerPrefs = array(); |
|
58
|
|
|
|
|
59
|
|
|
try { |
|
60
|
3 |
|
$file = $xoops->path($this->sanitizerPrefsFilename); |
|
61
|
3 |
|
$sanitizerPrefs = Yaml::read($file); |
|
62
|
|
|
} catch (\Exception $e) { |
|
63
|
|
|
$xoops->events()->triggerEvent('core.exception', $e); |
|
64
|
|
|
} |
|
65
|
3 |
|
if (!is_array($sanitizerPrefs)) { |
|
66
|
|
|
$sanitizerPrefs = array(); |
|
67
|
|
|
} |
|
68
|
3 |
|
$changed = false; |
|
69
|
3 |
|
$defaultPrefs = new DefaultConfiguration(); |
|
70
|
3 |
|
foreach ($defaultPrefs as $name => $value) { |
|
71
|
3 |
|
if (!array_key_exists($name, $sanitizerPrefs)) { |
|
72
|
|
|
$sanitizerPrefs[$name] = $defaultPrefs[$name]; |
|
73
|
|
|
$changed = true; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
3 |
|
if ($changed) { |
|
77
|
|
|
$this->saveSanitizerPrefrences($sanitizerPrefs); |
|
78
|
|
|
} |
|
79
|
3 |
|
return $sanitizerPrefs; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* saveSanitizerPreferences - record array of sanitizer preferences in config file |
|
84
|
|
|
* |
|
85
|
|
|
* @param array $sanitizerPrefs array of sanitizer preferences to save |
|
86
|
|
|
* |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function saveSanitizerPrefrences($sanitizerPrefs) |
|
90
|
|
|
{ |
|
91
|
|
|
if (is_array($sanitizerPrefs)) { |
|
92
|
|
|
$xoops = \Xoops::getInstance(); |
|
93
|
|
|
try { |
|
94
|
|
|
Yaml::save($sanitizerPrefs, $xoops->path($this->sanitizerPrefsFilename)); |
|
95
|
|
|
} catch (\Exception $e) { |
|
96
|
|
|
$xoops->events()->triggerEvent('core.exception', $e); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|