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

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