1 | <?php |
||
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() |
|
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) |
||
100 | } |
||
101 |