Completed
Push — master ( 31086c...3e76a9 )
by Stephanie
03:30
created
classes/models/FrmSettings.php 1 patch
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -1,260 +1,260 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 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;
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 10
 	public $fade_form;
11 11
 	public $old_css;
12 12
 
13
-    public $success_msg;
14
-    public $blank_msg;
15
-    public $unique_msg;
16
-    public $invalid_msg;
17
-    public $failed_msg;
18
-    public $submit_value;
19
-    public $login_msg;
20
-    public $admin_permission;
21
-
22
-    public $email_to;
23
-    public $load_style;
24
-    public $custom_style;
25
-
26
-    public $pubkey;
27
-    public $privkey;
28
-    public $re_lang;
13
+	public $success_msg;
14
+	public $blank_msg;
15
+	public $unique_msg;
16
+	public $invalid_msg;
17
+	public $failed_msg;
18
+	public $submit_value;
19
+	public $login_msg;
20
+	public $admin_permission;
21
+
22
+	public $email_to;
23
+	public $load_style;
24
+	public $custom_style;
25
+
26
+	public $pubkey;
27
+	public $privkey;
28
+	public $re_lang;
29 29
 	public $re_type;
30
-    public $re_msg;
30
+	public $re_msg;
31 31
 	public $re_multi;
32 32
 
33 33
 	public $no_ips;
34 34
 
35
-    public function __construct() {
36
-        if ( ! defined('ABSPATH') ) {
37
-            die('You are not allowed to call this page directly.');
38
-        }
35
+	public function __construct() {
36
+		if ( ! defined('ABSPATH') ) {
37
+			die('You are not allowed to call this page directly.');
38
+		}
39 39
 
40
-        $settings = get_transient($this->option_name);
40
+		$settings = get_transient($this->option_name);
41 41
 
42
-        if ( ! is_object($settings) ) {
43
-            $settings = $this->translate_settings($settings);
44
-        }
42
+		if ( ! is_object($settings) ) {
43
+			$settings = $this->translate_settings($settings);
44
+		}
45 45
 
46
-        foreach ( $settings as $setting_name => $setting ) {
47
-            $this->{$setting_name} = $setting;
48
-            unset($setting_name, $setting);
49
-        }
46
+		foreach ( $settings as $setting_name => $setting ) {
47
+			$this->{$setting_name} = $setting;
48
+			unset($setting_name, $setting);
49
+		}
50 50
 
51
-        $this->set_default_options();
52
-    }
51
+		$this->set_default_options();
52
+	}
53 53
 
54 54
 	private function translate_settings( $settings ) {
55
-        if ( $settings ) { //workaround for W3 total cache conflict
56
-            return unserialize(serialize($settings));
57
-        }
58
-
59
-        $settings = get_option($this->option_name);
60
-        if ( is_object($settings) ) {
61
-            set_transient($this->option_name, $settings);
62
-            return $settings;
63
-        }
64
-
65
-        // If unserializing didn't work
66
-        if ( $settings ) { //workaround for W3 total cache conflict
67
-            $settings = unserialize(serialize($settings));
68
-        } else {
69
-            $settings = $this;
70
-        }
71
-
72
-        update_option($this->option_name, $settings);
73
-        set_transient($this->option_name, $settings);
74
-
75
-        return $settings;
76
-    }
77
-
78
-    /**
79
-     * @return array
80
-     */
55
+		if ( $settings ) { //workaround for W3 total cache conflict
56
+			return unserialize(serialize($settings));
57
+		}
58
+
59
+		$settings = get_option($this->option_name);
60
+		if ( is_object($settings) ) {
61
+			set_transient($this->option_name, $settings);
62
+			return $settings;
63
+		}
64
+
65
+		// If unserializing didn't work
66
+		if ( $settings ) { //workaround for W3 total cache conflict
67
+			$settings = unserialize(serialize($settings));
68
+		} else {
69
+			$settings = $this;
70
+		}
71
+
72
+		update_option($this->option_name, $settings);
73
+		set_transient($this->option_name, $settings);
74
+
75
+		return $settings;
76
+	}
77
+
78
+	/**
79
+	 * @return array
80
+	 */
81 81
 	public function default_options() {
82
-        return array(
83
-            'menu'      => apply_filters( 'frm_default_menu', 'Formidable' ),
84
-            'mu_menu'   => 0,
85
-            'use_html'  => true,
86
-            'jquery_css' => false,
87
-            'accordion_js' => false,
82
+		return array(
83
+			'menu'      => apply_filters( 'frm_default_menu', 'Formidable' ),
84
+			'mu_menu'   => 0,
85
+			'use_html'  => true,
86
+			'jquery_css' => false,
87
+			'accordion_js' => false,
88 88
 			'fade_form' => false,
89 89
 			'old_css'   => true,
90 90
 
91 91
 			're_multi'  => 0,
92 92
 
93
-            'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
94
-            'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
95
-            'unique_msg' => __( 'This value must be unique.', 'formidable' ),
96
-            'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
97
-            'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
98
-            'submit_value' => __( 'Submit', 'formidable' ),
99
-            'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
100
-            'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
93
+			'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
94
+			'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
95
+			'unique_msg' => __( 'This value must be unique.', 'formidable' ),
96
+			'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
97
+			'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
98
+			'submit_value' => __( 'Submit', 'formidable' ),
99
+			'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
100
+			'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
101 101
 
102
-            'email_to' => '[admin_email]',
102
+			'email_to' => '[admin_email]',
103 103
 			'no_ips'   => 0,
104
-        );
105
-    }
104
+		);
105
+	}
106 106
 
107 107
 	private function set_default_options() {
108
-        $this->fill_recaptcha_settings();
109
-
110
-        if ( ! isset($this->load_style) ) {
111
-            if ( ! isset($this->custom_style) ) {
112
-                $this->custom_style = true;
113
-            }
114
-
115
-            $this->load_style = 'all';
116
-        }
117
-
118
-        $this->fill_with_defaults();
119
-
120
-        if ( is_multisite() && is_admin() ) {
121
-            $mu_menu = get_site_option('frm_admin_menu_name');
122
-            if ( $mu_menu && ! empty($mu_menu) ) {
123
-                $this->menu = $mu_menu;
124
-                $this->mu_menu = 1;
125
-            }
126
-        }
127
-
128
-        $frm_roles = FrmAppHelper::frm_capabilities('pro');
129
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
130
-            if ( ! isset($this->$frm_role) ) {
131
-                $this->$frm_role = 'administrator';
132
-            }
133
-        }
134
-    }
108
+		$this->fill_recaptcha_settings();
109
+
110
+		if ( ! isset($this->load_style) ) {
111
+			if ( ! isset($this->custom_style) ) {
112
+				$this->custom_style = true;
113
+			}
114
+
115
+			$this->load_style = 'all';
116
+		}
117
+
118
+		$this->fill_with_defaults();
119
+
120
+		if ( is_multisite() && is_admin() ) {
121
+			$mu_menu = get_site_option('frm_admin_menu_name');
122
+			if ( $mu_menu && ! empty($mu_menu) ) {
123
+				$this->menu = $mu_menu;
124
+				$this->mu_menu = 1;
125
+			}
126
+		}
127
+
128
+		$frm_roles = FrmAppHelper::frm_capabilities('pro');
129
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
130
+			if ( ! isset($this->$frm_role) ) {
131
+				$this->$frm_role = 'administrator';
132
+			}
133
+		}
134
+	}
135 135
 
136 136
 	public function fill_with_defaults( $params = array() ) {
137
-        $settings = $this->default_options();
137
+		$settings = $this->default_options();
138 138
 
139
-        foreach ( $settings as $setting => $default ) {
139
+		foreach ( $settings as $setting => $default ) {
140 140
 			if ( isset( $params[ 'frm_' . $setting ] ) ) {
141 141
 				$this->{$setting} = $params[ 'frm_' . $setting ];
142
-            } else if ( ! isset($this->{$setting}) ) {
143
-                $this->{$setting} = $default;
144
-            }
142
+			} else if ( ! isset($this->{$setting}) ) {
143
+				$this->{$setting} = $default;
144
+			}
145 145
 
146 146
 			if ( $setting == 'menu' && empty( $this->{$setting} ) ) {
147 147
 				$this->{$setting} = $default;
148 148
 			}
149 149
 
150
-            unset($setting, $default);
151
-        }
152
-    }
150
+			unset($setting, $default);
151
+		}
152
+	}
153 153
 
154
-    private function fill_recaptcha_settings() {
155
-        $privkey = '';
154
+	private function fill_recaptcha_settings() {
155
+		$privkey = '';
156 156
 		$re_lang = '';
157 157
 
158
-        if ( ! isset($this->pubkey) ) {
159
-            // get the options from the database
160
-            $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha');
161
-            $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
162
-            $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey;
163
-            $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang;
164
-        }
158
+		if ( ! isset($this->pubkey) ) {
159
+			// get the options from the database
160
+			$recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha');
161
+			$this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
162
+			$privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey;
163
+			$re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang;
164
+		}
165 165
 
166
-        if ( ! isset($this->re_msg) || empty($this->re_msg) ) {
167
-            $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
168
-        }
166
+		if ( ! isset($this->re_msg) || empty($this->re_msg) ) {
167
+			$this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
168
+		}
169 169
 
170
-        if ( ! isset($this->privkey) ) {
171
-            $this->privkey = $privkey;
172
-        }
170
+		if ( ! isset($this->privkey) ) {
171
+			$this->privkey = $privkey;
172
+		}
173 173
 
174
-        if ( ! isset($this->re_lang) ) {
175
-            $this->re_lang = $re_lang;
176
-        }
174
+		if ( ! isset($this->re_lang) ) {
175
+			$this->re_lang = $re_lang;
176
+		}
177 177
 
178 178
 		if ( ! isset( $this->re_type ) ) {
179 179
 			$this->re_type = '';
180 180
 		}
181
-    }
181
+	}
182 182
 
183
-    public function validate( $params, $errors ) {
184
-        return apply_filters( 'frm_validate_settings', $errors, $params );
185
-    }
183
+	public function validate( $params, $errors ) {
184
+		return apply_filters( 'frm_validate_settings', $errors, $params );
185
+	}
186 186
 
187 187
 	public function update( $params ) {
188
-        $this->fill_with_defaults($params);
189
-        $this->update_settings($params);
188
+		$this->fill_with_defaults($params);
189
+		$this->update_settings($params);
190 190
 
191
-        if ( $this->mu_menu ) {
192
-            update_site_option('frm_admin_menu_name', $this->menu);
193
-        } else if ( current_user_can('administrator') ) {
194
-            update_site_option('frm_admin_menu_name', false);
195
-        }
191
+		if ( $this->mu_menu ) {
192
+			update_site_option('frm_admin_menu_name', $this->menu);
193
+		} else if ( current_user_can('administrator') ) {
194
+			update_site_option('frm_admin_menu_name', false);
195
+		}
196 196
 
197
-        $this->update_roles($params);
197
+		$this->update_roles($params);
198 198
 
199
-        do_action( 'frm_update_settings', $params );
199
+		do_action( 'frm_update_settings', $params );
200 200
 
201 201
 		if ( function_exists( 'get_filesystem_method' ) ) {
202 202
 			// save styling settings in case fallback setting changes
203 203
 			$frm_style = new FrmStyle();
204 204
 			$frm_style->update( 'default' );
205 205
 		}
206
-    }
206
+	}
207 207
 
208 208
 	private function update_settings( $params ) {
209
-        $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
209
+		$this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
210 210
 
211
-        $this->pubkey = trim($params['frm_pubkey']);
212
-        $this->privkey = $params['frm_privkey'];
211
+		$this->pubkey = trim($params['frm_pubkey']);
212
+		$this->privkey = $params['frm_privkey'];
213 213
 		$this->re_type = $params['frm_re_type'];
214
-        $this->re_lang = $params['frm_re_lang'];
214
+		$this->re_lang = $params['frm_re_lang'];
215 215
 		$this->re_multi = isset( $params['frm_re_multi'] ) ? $params['frm_re_multi'] : 0;
216 216
 
217
-        $this->load_style = $params['frm_load_style'];
217
+		$this->load_style = $params['frm_load_style'];
218 218
 
219
-        $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
219
+		$this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
220 220
 		$this->jquery_css = isset( $params['frm_jquery_css'] ) ? absint( $params['frm_jquery_css'] ) : 0;
221 221
 		$this->accordion_js = isset( $params['frm_accordion_js'] ) ? absint( $params['frm_accordion_js'] ) : 0;
222 222
 		$this->fade_form = isset( $params['frm_fade_form'] ) ? absint( $params['frm_fade_form'] ) : 0;
223 223
 		$this->old_css   = isset( $params['frm_old_css'] ) ? absint( $params['frm_old_css'] ) : 0;
224 224
 		$this->no_ips = isset( $params['frm_no_ips'] ) ? absint( $params['frm_no_ips'] ) : 0;
225
-    }
225
+	}
226 226
 
227 227
 	private function update_roles( $params ) {
228
-        global $wp_roles;
228
+		global $wp_roles;
229 229
 
230
-        $frm_roles = FrmAppHelper::frm_capabilities();
231
-        $roles = get_editable_roles();
232
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
233
-            $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
230
+		$frm_roles = FrmAppHelper::frm_capabilities();
231
+		$roles = get_editable_roles();
232
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
233
+			$this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
234 234
 
235
-            // Make sure administrators always have permissions
236
-            if ( ! in_array( 'administrator', $this->$frm_role ) ) {
235
+			// Make sure administrators always have permissions
236
+			if ( ! in_array( 'administrator', $this->$frm_role ) ) {
237 237
 				array_push( $this->$frm_role, 'administrator' );
238
-            }
239
-
240
-            foreach ( $roles as $role => $details ) {
241
-                if ( in_array($role, $this->$frm_role) ) {
242
-    			    $wp_roles->add_cap( $role, $frm_role );
243
-    			} else {
244
-    			    $wp_roles->remove_cap( $role, $frm_role );
245
-    			}
246
-    		}
238
+			}
239
+
240
+			foreach ( $roles as $role => $details ) {
241
+				if ( in_array($role, $this->$frm_role) ) {
242
+					$wp_roles->add_cap( $role, $frm_role );
243
+				} else {
244
+					$wp_roles->remove_cap( $role, $frm_role );
245
+				}
246
+			}
247 247
 		}
248
-    }
248
+	}
249 249
 
250 250
 	public function store() {
251
-        // Save the posted value in the database
251
+		// Save the posted value in the database
252 252
 
253
-        update_option('frm_options', $this);
253
+		update_option('frm_options', $this);
254 254
 
255
-        delete_transient('frm_options');
256
-        set_transient('frm_options', $this);
255
+		delete_transient('frm_options');
256
+		set_transient('frm_options', $this);
257 257
 
258
-        do_action( 'frm_store_settings' );
259
-    }
258
+		do_action( 'frm_store_settings' );
259
+	}
260 260
 }
Please login to merge, or discard this patch.