PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / GlobalSettings / GlobalSettingsService.php

GlobalSettingsService.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.14, at app/Services/GlobalSettings/GlobalSettingsService.php

140 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\GlobalSettings;
4
5 use FluentForm\Framework\Support\Arr;
6
7 class GlobalSettingsService
8 {
9 // Keying material and the gateway secrets it encrypts. Together they let a settings
10 // manager decrypt every stored API key offline, so neither is readable here.
11 const DENIED_OPTION_KEYS = ['_fluentform_encryption_key'];
12 const DENIED_OPTION_PREFIXES = ['fluentform_payment_settings_'];
13
14 private function isAllowedOptionKey($key)
15 {
16 $deniedKeys = (array) apply_filters('fluentform/global_settings_denied_option_keys', self::DENIED_OPTION_KEYS);
17 $deniedPrefixes = (array) apply_filters('fluentform/global_settings_denied_option_prefixes', self::DENIED_OPTION_PREFIXES);
18
19 // wp_options.option_name also collates accent-insensitively: an accented, fullwidth or zero-width
20 // spelling misses the deny list yet resolves the denied row, so only the plain alphabet is looked up
21 $isPlainOptionKey = (bool) preg_match('/^[A-Za-z0-9_-]+$/', $key);
22 if (!$isPlainOptionKey) {
23 return false;
24 }
25
26 $comparableKey = strtolower($key);
27
28 if (in_array($comparableKey, array_map('strtolower', $deniedKeys), true)) {
29 return false;
30 }
31 foreach ($deniedPrefixes as $prefix) {
32 if ('' !== $prefix && strpos($comparableKey, strtolower($prefix)) === 0) {
33 return false;
34 }
35 }
36
37 $allowedPrefixes = [
38 'fluentform_',
39 '_fluentform_',
40 'fluentform-',
41 '_fluentform-',
42 ];
43 foreach ($allowedPrefixes as $prefix) {
44 if (strpos($comparableKey, $prefix) === 0) {
45 return true;
46 }
47 }
48 return false;
49 }
50
51 public function get($attributes = [])
52 {
53 $values = [];
54 $key = Arr::get($attributes, 'key');
55
56 if (is_array($key)) {
57 foreach ($key as $key_item) {
58 $sanitizedKey = sanitize_text_field($key_item);
59 if (!$this->isAllowedOptionKey($sanitizedKey)) {
60 continue;
61 }
62 $values[$key_item] = get_option($sanitizedKey);
63 }
64 } else {
65 $sanitizedKey = sanitize_text_field($key);
66 if (!$this->isAllowedOptionKey($sanitizedKey)) {
67 return $values;
68 }
69 $values[$key] = get_option($sanitizedKey);
70 }
71
72 $values = apply_filters_deprecated(
73 'fluentform_get_global_settings_values',
74 [
75 $values,
76 $key,
77 ],
78 FLUENTFORM_FRAMEWORK_UPGRADE,
79 'fluentform/get_global_settings_values',
80 'Use fluentform/get_global_settings_values instead of fluentform_get_global_settings_values.'
81 );
82
83 return apply_filters('fluentform/get_global_settings_values', $values, $key);
84 }
85
86 public function store($attributes = [])
87 {
88 $key = Arr::get($attributes, 'key');
89 if (is_array($key)) {
90 $key = array_map('sanitize_text_field', $key);
91 } else {
92 $key = sanitize_text_field($key);
93 }
94
95 $globalSettingsHelper = new GlobalSettingsHelper();
96
97 $allowedMethods = [
98 'storeReCaptcha',
99 'storeHCaptcha',
100 'storeTurnstile',
101 'storeCleantalk',
102 'storeSaveGlobalLayoutSettings',
103 'storeMailChimpSettings',
104 'storeEmailSummarySettings',
105 'storeAutosaveSettings',
106 'storeDefaultStyleTemplate',
107 ];
108
109 $method = '';
110 $container = [];
111 if (is_array($key)) {
112 foreach ($key as $item) {
113 $method = 'store' . ucwords($item);
114 if (in_array($method, $allowedMethods)) {
115 $container[] = $globalSettingsHelper->{$method}($attributes);
116 }
117 }
118 return $container;
119 } else {
120 $method = 'store' . ucwords($key);
121 }
122
123 do_action_deprecated(
124 'fluentform_saving_global_settings_with_key_method',
125 [
126 $attributes,
127 ],
128 FLUENTFORM_FRAMEWORK_UPGRADE,
129 'fluentform/saving_global_settings_with_key_method',
130 'Use fluentform/saving_global_settings_with_key_method instead of fluentform_saving_global_settings_with_key_method.'
131 );
132
133 do_action('fluentform/saving_global_settings_with_key_method', $attributes);
134
135 if (in_array($method, $allowedMethods)) {
136 return $globalSettingsHelper->{$method}($attributes);
137 }
138 }
139 }
140