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