Completed
Push — master ( 32d825...51fdfc )
by Stephanie
03:49
created
classes/models/FrmSettings.php 1 patch
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -1,246 +1,246 @@
 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'      => __( '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'      => __( '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
-            }
136
-            unset($setting, $default);
137
-        }
138
-    }
139
-
140
-    private function fill_recaptcha_settings() {
141
-        $privkey = '';
142
-        $re_lang = 'en';
143
-
144
-        if ( ! isset($this->pubkey) ) {
145
-            // get the options from the database
146
-            $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha');
147
-            $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
148
-            $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey;
149
-            $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang;
150
-        }
151
-
152
-        if ( ! isset($this->re_msg) || empty($this->re_msg) ) {
153
-            $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
154
-        }
155
-
156
-        if ( ! isset($this->privkey) ) {
157
-            $this->privkey = $privkey;
158
-        }
159
-
160
-        if ( ! isset($this->re_lang) ) {
161
-            $this->re_lang = $re_lang;
162
-        }
163
-    }
164
-
165
-    public function validate( $params, $errors ) {
166
-        $errors = apply_filters( 'frm_validate_settings', $errors, $params );
167
-        return $errors;
168
-    }
133
+			} else if ( ! isset($this->{$setting}) ) {
134
+				$this->{$setting} = $default;
135
+			}
136
+			unset($setting, $default);
137
+		}
138
+	}
139
+
140
+	private function fill_recaptcha_settings() {
141
+		$privkey = '';
142
+		$re_lang = 'en';
143
+
144
+		if ( ! isset($this->pubkey) ) {
145
+			// get the options from the database
146
+			$recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha');
147
+			$this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
148
+			$privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey;
149
+			$re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang;
150
+		}
151
+
152
+		if ( ! isset($this->re_msg) || empty($this->re_msg) ) {
153
+			$this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
154
+		}
155
+
156
+		if ( ! isset($this->privkey) ) {
157
+			$this->privkey = $privkey;
158
+		}
159
+
160
+		if ( ! isset($this->re_lang) ) {
161
+			$this->re_lang = $re_lang;
162
+		}
163
+	}
164
+
165
+	public function validate( $params, $errors ) {
166
+		$errors = apply_filters( 'frm_validate_settings', $errors, $params );
167
+		return $errors;
168
+	}
169 169
 
170 170
 	public function update( $params ) {
171
-        $this->fill_with_defaults($params);
172
-        $this->update_settings($params);
171
+		$this->fill_with_defaults($params);
172
+		$this->update_settings($params);
173 173
 
174
-        if ( $this->mu_menu ) {
175
-            update_site_option('frm_admin_menu_name', $this->menu);
176
-        } else if ( current_user_can('administrator') ) {
177
-            update_site_option('frm_admin_menu_name', false);
178
-        }
174
+		if ( $this->mu_menu ) {
175
+			update_site_option('frm_admin_menu_name', $this->menu);
176
+		} else if ( current_user_can('administrator') ) {
177
+			update_site_option('frm_admin_menu_name', false);
178
+		}
179 179
 
180
-        $this->update_roles($params);
180
+		$this->update_roles($params);
181 181
 
182
-        do_action( 'frm_update_settings', $params );
183
-    }
182
+		do_action( 'frm_update_settings', $params );
183
+	}
184 184
 
185 185
 	private function update_settings( $params ) {
186
-        $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
186
+		$this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
187 187
 
188
-        $this->pubkey = trim($params['frm_pubkey']);
189
-        $this->privkey = $params['frm_privkey'];
190
-        $this->re_lang = $params['frm_re_lang'];
188
+		$this->pubkey = trim($params['frm_pubkey']);
189
+		$this->privkey = $params['frm_privkey'];
190
+		$this->re_lang = $params['frm_re_lang'];
191 191
 
192
-        $this->load_style = $params['frm_load_style'];
193
-        $this->preview_page_id = (int) $params['frm-preview-page-id'];
192
+		$this->load_style = $params['frm_load_style'];
193
+		$this->preview_page_id = (int) $params['frm-preview-page-id'];
194 194
 
195
-        $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
196
-        //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0;
195
+		$this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
196
+		//$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0;
197 197
 		$this->jquery_css = isset( $params['frm_jquery_css'] ) ? absint( $params['frm_jquery_css'] ) : 0;
198 198
 		$this->accordion_js = isset( $params['frm_accordion_js'] ) ? absint( $params['frm_accordion_js'] ) : 0;
199
-    }
199
+	}
200 200
 
201 201
 	private function update_roles( $params ) {
202
-        //update roles
203
-        global $wp_roles;
204
-
205
-        $frm_roles = FrmAppHelper::frm_capabilities();
206
-        $roles = get_editable_roles();
207
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
208
-            $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
209
-
210
-            if ( count($this->$frm_role) === 1 ) {
211
-                $set_role = reset($this->$frm_role);
212
-                switch ( $set_role ) {
213
-                    case 'subscriber':
214
-                        array_push($this->$frm_role, 'contributor');
215
-                    case 'contributor':
216
-                        array_push($this->$frm_role, 'author');
217
-                    case 'author':
218
-                        array_push($this->$frm_role, 'editor');
219
-                    case 'editor':
220
-                        array_push($this->$frm_role, 'administrator');
221
-                }
222
-                unset($set_role);
223
-            }
224
-
225
-            foreach ( $roles as $role => $details ) {
226
-                if ( in_array($role, $this->$frm_role) ) {
227
-    			    $wp_roles->add_cap( $role, $frm_role );
228
-    			} else {
229
-    			    $wp_roles->remove_cap( $role, $frm_role );
230
-    			}
231
-    			unset($role, $details);
232
-    		}
233
-		}
234
-    }
202
+		//update roles
203
+		global $wp_roles;
204
+
205
+		$frm_roles = FrmAppHelper::frm_capabilities();
206
+		$roles = get_editable_roles();
207
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
208
+			$this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
209
+
210
+			if ( count($this->$frm_role) === 1 ) {
211
+				$set_role = reset($this->$frm_role);
212
+				switch ( $set_role ) {
213
+					case 'subscriber':
214
+						array_push($this->$frm_role, 'contributor');
215
+					case 'contributor':
216
+						array_push($this->$frm_role, 'author');
217
+					case 'author':
218
+						array_push($this->$frm_role, 'editor');
219
+					case 'editor':
220
+						array_push($this->$frm_role, 'administrator');
221
+				}
222
+				unset($set_role);
223
+			}
224
+
225
+			foreach ( $roles as $role => $details ) {
226
+				if ( in_array($role, $this->$frm_role) ) {
227
+					$wp_roles->add_cap( $role, $frm_role );
228
+				} else {
229
+					$wp_roles->remove_cap( $role, $frm_role );
230
+				}
231
+				unset($role, $details);
232
+			}
233
+		}
234
+	}
235 235
 
236 236
 	public function store() {
237
-        // Save the posted value in the database
237
+		// Save the posted value in the database
238 238
 
239
-        update_option('frm_options', $this);
239
+		update_option('frm_options', $this);
240 240
 
241
-        delete_transient('frm_options');
242
-        set_transient('frm_options', $this);
241
+		delete_transient('frm_options');
242
+		set_transient('frm_options', $this);
243 243
 
244
-        do_action( 'frm_store_settings' );
245
-    }
244
+		do_action( 'frm_store_settings' );
245
+	}
246 246
 }
Please login to merge, or discard this patch.