PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.6
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.6
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmSettings.php

FrmSettings.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.5.6, at classes/models/FrmSettings.php

331 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmSettings {
7 public $option_name = 'frm_options';
8 public $menu;
9 public $mu_menu;
10 public $use_html;
11 public $jquery_css;
12 public $accordion_js;
13 public $fade_form;
14 public $old_css;
15 public $admin_bar;
16
17 public $success_msg;
18 public $blank_msg;
19 public $unique_msg;
20 public $invalid_msg;
21 public $failed_msg;
22 public $submit_value;
23 public $login_msg;
24 public $admin_permission;
25
26 public $email_to;
27 public $load_style;
28 public $custom_style;
29
30 public $active_captcha;
31 public $hcaptcha_pubkey;
32 public $hcaptcha_privkey;
33 public $pubkey;
34 public $privkey;
35 public $re_lang;
36 public $re_type;
37 public $re_msg;
38 public $re_multi;
39
40 public $no_ips;
41 public $current_form = 0;
42 public $tracking;
43
44 public function __construct( $args = array() ) {
45 if ( ! defined( 'ABSPATH' ) ) {
46 die( 'You are not allowed to call this page directly.' );
47 }
48
49 $settings = get_transient( $this->option_name );
50
51 if ( ! is_object( $settings ) ) {
52 $settings = $this->translate_settings( $settings );
53 }
54
55 foreach ( $settings as $setting_name => $setting ) {
56 $this->{$setting_name} = $setting;
57 unset( $setting_name, $setting );
58 }
59
60 $this->set_default_options();
61
62 $this->maybe_filter_for_form( $args );
63 }
64
65 private function translate_settings( $settings ) {
66 if ( $settings ) { //workaround for W3 total cache conflict
67 return unserialize( serialize( $settings ) );
68 }
69
70 $settings = get_option( $this->option_name );
71 if ( is_object( $settings ) ) {
72 set_transient( $this->option_name, $settings );
73
74 return $settings;
75 }
76
77 // If unserializing didn't work
78 if ( $settings ) { //workaround for W3 total cache conflict
79 $settings = unserialize( serialize( $settings ) );
80 } else {
81 $settings = $this;
82 }
83
84 update_option( $this->option_name, $settings );
85 set_transient( $this->option_name, $settings );
86
87 return $settings;
88 }
89
90 /**
91 * @return array
92 */
93 public function default_options() {
94 return array(
95 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
96 'mu_menu' => 0,
97 'use_html' => true,
98 'jquery_css' => false,
99 'accordion_js' => false,
100 'fade_form' => false,
101 'old_css' => false,
102 'admin_bar' => false,
103
104 're_multi' => 1,
105
106 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
107 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
108 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
109 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
110 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
111 'submit_value' => __( 'Submit', 'formidable' ),
112 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
113 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
114
115 'email_to' => '[admin_email]',
116 'no_ips' => 0,
117 'tracking' => FrmAppHelper::pro_is_installed(),
118 );
119 }
120
121 private function set_default_options() {
122 $this->fill_captcha_settings();
123
124 if ( ! isset( $this->load_style ) ) {
125 if ( ! isset( $this->custom_style ) ) {
126 $this->custom_style = true;
127 }
128
129 $this->load_style = 'all';
130 }
131
132 $this->fill_with_defaults();
133
134 if ( is_multisite() && is_admin() ) {
135 $mu_menu = get_site_option( 'frm_admin_menu_name' );
136 if ( $mu_menu && ! empty( $mu_menu ) ) {
137 $this->menu = $mu_menu;
138 $this->mu_menu = 1;
139 }
140 }
141
142 $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
143 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
144 if ( ! isset( $this->$frm_role ) ) {
145 $this->$frm_role = 'administrator';
146 }
147 }
148 }
149
150 /**
151 * @param array $params
152 */
153 public function fill_with_defaults( $params = array() ) {
154 $settings = $this->default_options();
155 $filter_html = ! FrmAppHelper::allow_unfiltered_html();
156
157 if ( $filter_html ) {
158 $filter_keys = array( 'failed_msg', 'blank_msg', 'invalid_msg', 'admin_permission', 'unique_msg', 'success_msg', 'submit_value', 'login_msg', 'menu' );
159 if ( ! empty( $params['additional_filter_keys'] ) ) {
160 $filter_keys = array_merge( $filter_keys, $params['additional_filter_keys'] );
161 }
162 } else {
163 $filter_keys = array();
164 }
165
166 foreach ( $settings as $setting => $default ) {
167 if ( isset( $params[ 'frm_' . $setting ] ) ) {
168 $this->{$setting} = $params[ 'frm_' . $setting ];
169 } elseif ( ! isset( $this->{$setting} ) ) {
170 $this->{$setting} = $default;
171 }
172
173 if ( $setting === 'menu' && empty( $this->{$setting} ) ) {
174 $this->{$setting} = $default;
175 }
176
177 if ( $filter_html && in_array( $setting, $filter_keys, true ) ) {
178 $this->{$setting} = FrmAppHelper::kses( $this->{$setting}, 'all' );
179 }
180
181 unset( $setting, $default );
182 }
183 }
184
185 private function fill_captcha_settings() {
186 if ( ! isset( $this->active_captcha ) ) {
187 $this->active_captcha = 'recaptcha';
188 }
189
190 $privkey = '';
191 $re_lang = '';
192
193 if ( ! isset( $this->hcaptcha_privkey ) ) {
194 $this->hcaptcha_privkey = '';
195 }
196
197 if ( ! isset( $this->pubkey ) ) {
198 // get the options from the database
199 $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
200 $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
201 $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
202 $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
203 }
204
205 if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
206 $this->re_msg = __( 'The CAPTCHA was not entered correctly', 'formidable' );
207 }
208
209 if ( ! isset( $this->privkey ) ) {
210 $this->privkey = $privkey;
211 }
212
213 if ( ! isset( $this->re_lang ) ) {
214 $this->re_lang = $re_lang;
215 }
216
217 if ( ! isset( $this->re_type ) ) {
218 $this->re_type = '';
219 }
220
221 if ( ! isset( $this->re_threshold ) ) {
222 $this->re_threshold = .5;
223 }
224 }
225
226 /**
227 * Get values that may be shown on the front-end without an override in the form settings.
228 *
229 * @since 3.06.01
230 */
231 public function translatable_strings() {
232 return array(
233 'invalid_msg',
234 'admin_permission',
235 'failed_msg',
236 'login_msg',
237 );
238 }
239
240 /**
241 * Allow strings to be filtered when a specific form may be displaying them.
242 *
243 * @since 3.06.01
244 */
245 public function maybe_filter_for_form( $args ) {
246 if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
247 $this->current_form = $args['current_form'];
248 foreach ( $this->translatable_strings() as $string ) {
249 $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this );
250 $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this );
251 }
252 }
253 }
254
255 public function validate( $params, $errors ) {
256 return apply_filters( 'frm_validate_settings', $errors, $params );
257 }
258
259 public function update( $params ) {
260 $this->fill_with_defaults( $params );
261 $this->update_settings( $params );
262
263 if ( $this->mu_menu ) {
264 update_site_option( 'frm_admin_menu_name', $this->menu );
265 } elseif ( current_user_can( 'administrator' ) ) {
266 update_site_option( 'frm_admin_menu_name', false );
267 }
268
269 $this->update_roles( $params );
270
271 do_action( 'frm_update_settings', $params );
272
273 if ( function_exists( 'get_filesystem_method' ) ) {
274 // save styling settings in case fallback setting changes
275 $frm_style = new FrmStyle();
276 $frm_style->update( 'default' );
277 }
278 }
279
280 private function update_settings( $params ) {
281 $this->active_captcha = $params['frm_active_captcha'];
282 $this->hcaptcha_pubkey = trim( $params['frm_hcaptcha_pubkey'] );
283 $this->hcaptcha_privkey = $params['frm_hcaptcha_privkey'];
284 $this->pubkey = trim( $params['frm_pubkey'] );
285 $this->privkey = $params['frm_privkey'];
286 $this->re_type = $params['frm_re_type'];
287 $this->re_lang = $params['frm_re_lang'];
288 $this->re_threshold = floatval( $params['frm_re_threshold'] );
289 $this->load_style = $params['frm_load_style'];
290
291 $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'tracking', 'admin_bar' );
292 foreach ( $checkboxes as $set ) {
293 $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
294 }
295 }
296
297 private function update_roles( $params ) {
298 global $wp_roles;
299
300 $frm_roles = FrmAppHelper::frm_capabilities();
301 $roles = get_editable_roles();
302 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
303 $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
304
305 // Make sure administrators always have permissions
306 if ( ! in_array( 'administrator', $this->$frm_role ) ) {
307 array_push( $this->$frm_role, 'administrator' );
308 }
309
310 foreach ( $roles as $role => $details ) {
311 if ( in_array( $role, $this->$frm_role ) ) {
312 $wp_roles->add_cap( $role, $frm_role );
313 } else {
314 $wp_roles->remove_cap( $role, $frm_role );
315 }
316 }
317 }
318 }
319
320 public function store() {
321 // Save the posted value in the database
322
323 update_option( 'frm_options', $this );
324
325 delete_transient( 'frm_options' );
326 set_transient( 'frm_options', $this );
327
328 do_action( 'frm_store_settings' );
329 }
330 }
331