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

311 lines 8.5 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', '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
211 /**
212 * Get values that may be shown on the front-end without an override in the form settings.
213 *
214 * @since 3.06.01
215 */
216 public function translatable_strings() {
217 return array(
218 'invalid_msg',
219 'failed_msg',
220 'login_msg',
221 );
222 }
223
224 /**
225 * Allow strings to be filtered when a specific form may be displaying them.
226 *
227 * @since 3.06.01
228 */
229 public function maybe_filter_for_form( $args ) {
230 if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
231 $this->current_form = $args['current_form'];
232 foreach ( $this->translatable_strings() as $string ) {
233 $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this );
234 $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this );
235 }
236 }
237 }
238
239 public function validate( $params, $errors ) {
240 return apply_filters( 'frm_validate_settings', $errors, $params );
241 }
242
243 public function update( $params ) {
244 $this->fill_with_defaults( $params );
245 $this->update_settings( $params );
246
247 if ( $this->mu_menu ) {
248 update_site_option( 'frm_admin_menu_name', $this->menu );
249 } elseif ( current_user_can( 'administrator' ) ) {
250 update_site_option( 'frm_admin_menu_name', false );
251 }
252
253 $this->update_roles( $params );
254
255 do_action( 'frm_update_settings', $params );
256
257 if ( function_exists( 'get_filesystem_method' ) ) {
258 // save styling settings in case fallback setting changes
259 $frm_style = new FrmStyle();
260 $frm_style->update( 'default' );
261 }
262 }
263
264 private function update_settings( $params ) {
265 $this->pubkey = trim( $params['frm_pubkey'] );
266 $this->privkey = $params['frm_privkey'];
267 $this->re_type = $params['frm_re_type'];
268 $this->re_lang = $params['frm_re_lang'];
269 $this->load_style = $params['frm_load_style'];
270
271 $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'tracking', 'admin_bar' );
272 foreach ( $checkboxes as $set ) {
273 $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
274 }
275 }
276
277 private function update_roles( $params ) {
278 global $wp_roles;
279
280 $frm_roles = FrmAppHelper::frm_capabilities();
281 $roles = get_editable_roles();
282 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
283 $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
284
285 // Make sure administrators always have permissions
286 if ( ! in_array( 'administrator', $this->$frm_role ) ) {
287 array_push( $this->$frm_role, 'administrator' );
288 }
289
290 foreach ( $roles as $role => $details ) {
291 if ( in_array( $role, $this->$frm_role ) ) {
292 $wp_roles->add_cap( $role, $frm_role );
293 } else {
294 $wp_roles->remove_cap( $role, $frm_role );
295 }
296 }
297 }
298 }
299
300 public function store() {
301 // Save the posted value in the database
302
303 update_option( 'frm_options', $this );
304
305 delete_transient( 'frm_options' );
306 set_transient( 'frm_options', $this );
307
308 do_action( 'frm_store_settings' );
309 }
310 }
311