PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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.4, at classes/models/FrmSettings.php

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