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

255 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 $preview_page_id;
8 public $use_html;
9 public $jquery_css;
10 public $accordion_js;
11 public $fade_form;
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;
29 public $re_type;
30 public $re_msg;
31 public $re_multi;
32
33 public $no_ips;
34
35 public function __construct() {
36 if ( ! defined('ABSPATH') ) {
37 die('You are not allowed to call this page directly.');
38 }
39
40 $settings = get_transient($this->option_name);
41
42 if ( ! is_object($settings) ) {
43 $settings = $this->translate_settings($settings);
44 }
45
46 foreach ( $settings as $setting_name => $setting ) {
47 $this->{$setting_name} = $setting;
48 unset($setting_name, $setting);
49 }
50
51 $this->set_default_options();
52 }
53
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 */
81 public function default_options() {
82 return array(
83 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
84 'mu_menu' => 0,
85 'preview_page_id' => 0,
86 'use_html' => true,
87 'jquery_css' => false,
88 'accordion_js' => false,
89 'fade_form' => false,
90
91 're_multi' => 0,
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' ),
101
102 'email_to' => '[admin_email]',
103 'no_ips' => 0,
104 );
105 }
106
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 }
135
136 public function fill_with_defaults( $params = array() ) {
137 $settings = $this->default_options();
138
139 foreach ( $settings as $setting => $default ) {
140 if ( isset( $params[ 'frm_' . $setting ] ) ) {
141 $this->{$setting} = $params[ 'frm_' . $setting ];
142 } else if ( ! isset($this->{$setting}) ) {
143 $this->{$setting} = $default;
144 }
145
146 if ( $setting == 'menu' && empty( $this->{$setting} ) ) {
147 $this->{$setting} = $default;
148 }
149
150 unset($setting, $default);
151 }
152 }
153
154 private function fill_recaptcha_settings() {
155 $privkey = '';
156 $re_lang = '';
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 }
165
166 if ( ! isset($this->re_msg) || empty($this->re_msg) ) {
167 $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
168 }
169
170 if ( ! isset($this->privkey) ) {
171 $this->privkey = $privkey;
172 }
173
174 if ( ! isset($this->re_lang) ) {
175 $this->re_lang = $re_lang;
176 }
177
178 if ( ! isset( $this->re_type ) ) {
179 $this->re_type = '';
180 }
181 }
182
183 public function validate( $params, $errors ) {
184 return apply_filters( 'frm_validate_settings', $errors, $params );
185 }
186
187 public function update( $params ) {
188 $this->fill_with_defaults($params);
189 $this->update_settings($params);
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 }
196
197 $this->update_roles($params);
198
199 do_action( 'frm_update_settings', $params );
200 }
201
202 private function update_settings( $params ) {
203 $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
204
205 $this->pubkey = trim($params['frm_pubkey']);
206 $this->privkey = $params['frm_privkey'];
207 $this->re_type = $params['frm_re_type'];
208 $this->re_lang = $params['frm_re_lang'];
209 $this->re_multi = isset( $params['frm_re_multi'] ) ? $params['frm_re_multi'] : 0;
210
211 $this->load_style = $params['frm_load_style'];
212 $this->preview_page_id = (int) $params['frm-preview-page-id'];
213
214 $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
215 $this->jquery_css = isset( $params['frm_jquery_css'] ) ? absint( $params['frm_jquery_css'] ) : 0;
216 $this->accordion_js = isset( $params['frm_accordion_js'] ) ? absint( $params['frm_accordion_js'] ) : 0;
217 $this->fade_form = isset( $params['frm_fade_form'] ) ? absint( $params['frm_fade_form'] ) : 0;
218 $this->no_ips = isset( $params['frm_no_ips'] ) ? absint( $params['frm_no_ips'] ) : 0;
219 }
220
221 private function update_roles( $params ) {
222 global $wp_roles;
223
224 $frm_roles = FrmAppHelper::frm_capabilities();
225 $roles = get_editable_roles();
226 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
227 $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
228
229 // Make sure administrators always have permissions
230 if ( ! in_array( 'administrator', $this->$frm_role ) ) {
231 array_push( $this->$frm_role, 'administrator' );
232 }
233
234 foreach ( $roles as $role => $details ) {
235 if ( in_array($role, $this->$frm_role) ) {
236 $wp_roles->add_cap( $role, $frm_role );
237 } else {
238 $wp_roles->remove_cap( $role, $frm_role );
239 }
240 }
241 }
242 }
243
244 public function store() {
245 // Save the posted value in the database
246
247 update_option('frm_options', $this);
248
249 delete_transient('frm_options');
250 set_transient('frm_options', $this);
251
252 do_action( 'frm_store_settings' );
253 }
254 }
255