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