@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | public $action_options; // Option array passed to wp_register_sidebar_widget() |
9 | 9 | public $control_options; // Option array passed to wp_register_widget_control() |
10 | 10 | |
11 | - public $form_id; // The ID of the form to evaluate |
|
11 | + public $form_id; // The ID of the form to evaluate |
|
12 | 12 | public $number = false; // Unique ID number of the current instance. |
13 | 13 | public $id = ''; // Unique ID string of the current instance (id_base-number) |
14 | 14 | public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | - * Echo the settings update form |
|
32 | + * Echo the settings update form |
|
33 | 33 | * |
34 | 34 | * @param array $instance Current settings |
35 | 35 | */ |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @return array of the default options |
43 | 43 | */ |
44 | 44 | public function get_defaults() { |
45 | - return array(); |
|
45 | + return array(); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | public function get_switch_fields() { |
49 | - return array(); |
|
49 | + return array(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function migrate_values( $action, $form ) { |
53 | - return $action; |
|
53 | + return $action; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | // Functions you'll need to call. |
@@ -69,24 +69,24 @@ discard block |
||
69 | 69 | * - height: currently not used but may be needed in the future |
70 | 70 | */ |
71 | 71 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
72 | - if ( ! defined('ABSPATH') ) { |
|
73 | - die('You are not allowed to call this page directly.'); |
|
74 | - } |
|
72 | + if ( ! defined('ABSPATH') ) { |
|
73 | + die('You are not allowed to call this page directly.'); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | $this->id_base = strtolower($id_base); |
77 | 77 | $this->name = $name; |
78 | 78 | $this->option_name = 'frm_' . $this->id_base . '_action'; |
79 | 79 | |
80 | - $default_options = array( |
|
81 | - 'classes' => '', |
|
82 | - 'active' => true, |
|
80 | + $default_options = array( |
|
81 | + 'classes' => '', |
|
82 | + 'active' => true, |
|
83 | 83 | 'event' => array( 'create' ), |
84 | - 'limit' => 1, |
|
85 | - 'force_event' => false, |
|
86 | - 'priority' => 20, |
|
87 | - 'ajax_load' => true, |
|
88 | - 'tooltip' => $name, |
|
89 | - ); |
|
84 | + 'limit' => 1, |
|
85 | + 'force_event' => false, |
|
86 | + 'priority' => 20, |
|
87 | + 'ajax_load' => true, |
|
88 | + 'tooltip' => $name, |
|
89 | + ); |
|
90 | 90 | |
91 | 91 | $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options ); |
92 | 92 | $this->action_options = wp_parse_args( $action_options, $default_options ); |
@@ -135,132 +135,132 @@ discard block |
||
135 | 135 | } |
136 | 136 | |
137 | 137 | public function prepare_new( $form_id = false ) { |
138 | - if ( $form_id ) { |
|
139 | - $this->form_id = $form_id; |
|
140 | - } |
|
141 | - |
|
142 | - $post_content = array(); |
|
143 | - $default_values = $this->get_global_defaults(); |
|
144 | - |
|
145 | - // fill default values |
|
146 | - $post_content = wp_parse_args( $post_content, $default_values); |
|
147 | - |
|
148 | - if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
149 | - $post_content['event'] = array( reset($this->action_options['event']) ); |
|
150 | - } |
|
151 | - |
|
152 | - $form_action = array( |
|
153 | - 'post_title' => $this->name, |
|
154 | - 'post_content' => $post_content, |
|
155 | - 'post_excerpt' => $this->id_base, |
|
156 | - 'ID' => '', |
|
157 | - 'post_status' => 'publish', |
|
158 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
138 | + if ( $form_id ) { |
|
139 | + $this->form_id = $form_id; |
|
140 | + } |
|
141 | + |
|
142 | + $post_content = array(); |
|
143 | + $default_values = $this->get_global_defaults(); |
|
144 | + |
|
145 | + // fill default values |
|
146 | + $post_content = wp_parse_args( $post_content, $default_values); |
|
147 | + |
|
148 | + if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
149 | + $post_content['event'] = array( reset($this->action_options['event']) ); |
|
150 | + } |
|
151 | + |
|
152 | + $form_action = array( |
|
153 | + 'post_title' => $this->name, |
|
154 | + 'post_content' => $post_content, |
|
155 | + 'post_excerpt' => $this->id_base, |
|
156 | + 'ID' => '', |
|
157 | + 'post_status' => 'publish', |
|
158 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
159 | 159 | 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
160 | - 'menu_order' => $this->form_id, |
|
161 | - ); |
|
162 | - unset($post_content); |
|
160 | + 'menu_order' => $this->form_id, |
|
161 | + ); |
|
162 | + unset($post_content); |
|
163 | 163 | |
164 | - return (object) $form_action; |
|
165 | - } |
|
164 | + return (object) $form_action; |
|
165 | + } |
|
166 | 166 | |
167 | 167 | public function create( $form_id ) { |
168 | - $this->form_id = $form_id; |
|
168 | + $this->form_id = $form_id; |
|
169 | 169 | |
170 | - $action = $this->prepare_new(); |
|
170 | + $action = $this->prepare_new(); |
|
171 | 171 | |
172 | - return $this->save_settings($action); |
|
173 | - } |
|
172 | + return $this->save_settings($action); |
|
173 | + } |
|
174 | 174 | |
175 | 175 | public function duplicate_form_actions( $form_id, $old_id ) { |
176 | - if ( $form_id == $old_id ) { |
|
177 | - // don't duplicate the actions if this is a template getting updated |
|
178 | - return; |
|
179 | - } |
|
180 | - |
|
181 | - $this->form_id = $old_id; |
|
182 | - $actions = $this->get_all( $old_id ); |
|
183 | - |
|
184 | - $this->form_id = $form_id; |
|
185 | - foreach ( $actions as $action ) { |
|
186 | - $this->duplicate_one($action, $form_id); |
|
187 | - unset($action); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - /* Check if imported action should be created or updated |
|
176 | + if ( $form_id == $old_id ) { |
|
177 | + // don't duplicate the actions if this is a template getting updated |
|
178 | + return; |
|
179 | + } |
|
180 | + |
|
181 | + $this->form_id = $old_id; |
|
182 | + $actions = $this->get_all( $old_id ); |
|
183 | + |
|
184 | + $this->form_id = $form_id; |
|
185 | + foreach ( $actions as $action ) { |
|
186 | + $this->duplicate_one($action, $form_id); |
|
187 | + unset($action); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + /* Check if imported action should be created or updated |
|
192 | 192 | * |
193 | 193 | * Since 2.0 |
194 | 194 | * |
195 | 195 | * @param array $action |
196 | 196 | * @return integer $post_id |
197 | 197 | */ |
198 | - public function maybe_create_action( $action, $forms ) { |
|
198 | + public function maybe_create_action( $action, $forms ) { |
|
199 | 199 | if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
200 | - // Update action only |
|
201 | - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
202 | - $post_id = $this->save_settings( $action ); |
|
203 | - } else { |
|
204 | - // Create action |
|
205 | - $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
206 | - $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
207 | - } |
|
208 | - return $post_id; |
|
209 | - } |
|
200 | + // Update action only |
|
201 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
202 | + $post_id = $this->save_settings( $action ); |
|
203 | + } else { |
|
204 | + // Create action |
|
205 | + $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
206 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
207 | + } |
|
208 | + return $post_id; |
|
209 | + } |
|
210 | 210 | |
211 | 211 | public function duplicate_one( $action, $form_id ) { |
212 | - global $frm_duplicate_ids; |
|
212 | + global $frm_duplicate_ids; |
|
213 | 213 | |
214 | - $action->menu_order = $form_id; |
|
215 | - $switch = $this->get_global_switch_fields(); |
|
216 | - foreach ( (array) $action->post_content as $key => $val ) { |
|
214 | + $action->menu_order = $form_id; |
|
215 | + $switch = $this->get_global_switch_fields(); |
|
216 | + foreach ( (array) $action->post_content as $key => $val ) { |
|
217 | 217 | if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
218 | 218 | $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
219 | - } else if ( ! is_array( $val ) ) { |
|
219 | + } else if ( ! is_array( $val ) ) { |
|
220 | 220 | $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
221 | 221 | } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
222 | - // loop through each value if empty |
|
222 | + // loop through each value if empty |
|
223 | 223 | if ( empty( $switch[ $key ] ) ) { |
224 | 224 | $switch[ $key ] = array_keys( $val ); |
225 | 225 | } |
226 | 226 | |
227 | 227 | foreach ( $switch[ $key ] as $subkey ) { |
228 | 228 | $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
229 | - } |
|
230 | - } |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | - unset($key, $val); |
|
233 | - } |
|
234 | - unset($action->ID); |
|
232 | + unset($key, $val); |
|
233 | + } |
|
234 | + unset($action->ID); |
|
235 | 235 | |
236 | - return $this->save_settings($action); |
|
237 | - } |
|
236 | + return $this->save_settings($action); |
|
237 | + } |
|
238 | 238 | |
239 | 239 | private function duplicate_array_walk( $action, $subkey, $val ) { |
240 | - global $frm_duplicate_ids; |
|
240 | + global $frm_duplicate_ids; |
|
241 | 241 | |
242 | - if ( is_array($subkey) ) { |
|
243 | - foreach ( $subkey as $subkey2 ) { |
|
244 | - foreach ( (array) $val as $ck => $cv ) { |
|
245 | - if ( is_array($cv) ) { |
|
242 | + if ( is_array($subkey) ) { |
|
243 | + foreach ( $subkey as $subkey2 ) { |
|
244 | + foreach ( (array) $val as $ck => $cv ) { |
|
245 | + if ( is_array($cv) ) { |
|
246 | 246 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
247 | 247 | } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
248 | 248 | $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
249 | - } |
|
250 | - } |
|
251 | - } |
|
252 | - } else { |
|
253 | - foreach ( (array) $val as $ck => $cv ) { |
|
254 | - if ( is_array($cv) ) { |
|
249 | + } |
|
250 | + } |
|
251 | + } |
|
252 | + } else { |
|
253 | + foreach ( (array) $val as $ck => $cv ) { |
|
254 | + if ( is_array($cv) ) { |
|
255 | 255 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
256 | 256 | } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
257 | 257 | $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
258 | - } |
|
259 | - } |
|
260 | - } |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - return $action; |
|
263 | - } |
|
262 | + return $action; |
|
263 | + } |
|
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Deal with changed settings. |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * |
270 | 270 | */ |
271 | 271 | public function update_callback( $form_id ) { |
272 | - $this->form_id = $form_id; |
|
272 | + $this->form_id = $form_id; |
|
273 | 273 | |
274 | 274 | $all_instances = $this->get_settings(); |
275 | 275 | |
@@ -284,25 +284,25 @@ discard block |
||
284 | 284 | return; |
285 | 285 | } |
286 | 286 | |
287 | - $action_ids = array(); |
|
287 | + $action_ids = array(); |
|
288 | 288 | |
289 | 289 | foreach ( $settings as $number => $new_instance ) { |
290 | 290 | $this->_set($number); |
291 | 291 | |
292 | 292 | if ( ! isset($new_instance['post_title']) ) { |
293 | - // settings were never opened, so don't update |
|
294 | - $action_ids[] = $new_instance['ID']; |
|
295 | - $this->updated = true; |
|
296 | - continue; |
|
293 | + // settings were never opened, so don't update |
|
294 | + $action_ids[] = $new_instance['ID']; |
|
295 | + $this->updated = true; |
|
296 | + continue; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
300 | 300 | |
301 | 301 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
302 | 302 | $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
303 | - $new_instance['menu_order'] = $this->form_id; |
|
304 | - $new_instance['post_status'] = 'publish'; |
|
305 | - $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
|
303 | + $new_instance['menu_order'] = $this->form_id; |
|
304 | + $new_instance['post_status'] = 'publish'; |
|
305 | + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
|
306 | 306 | |
307 | 307 | $instance = $this->update( $new_instance, $old_instance ); |
308 | 308 | |
@@ -328,9 +328,9 @@ discard block |
||
328 | 328 | $all_instances[ $number ] = $instance; |
329 | 329 | } |
330 | 330 | |
331 | - $action_ids[] = $this->save_settings($instance); |
|
331 | + $action_ids[] = $this->save_settings($instance); |
|
332 | 332 | |
333 | - $this->updated = true; |
|
333 | + $this->updated = true; |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | return $action_ids; |
@@ -342,59 +342,59 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | public function get_single_action( $id ) { |
345 | - $action = get_post($id); |
|
345 | + $action = get_post($id); |
|
346 | 346 | if ( $action ) { |
347 | 347 | $action = $this->prepare_action( $action ); |
348 | 348 | $this->_set( $id ); |
349 | 349 | } |
350 | - return $action; |
|
350 | + return $action; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | public function get_one( $form_id ) { |
354 | - return $this->get_all($form_id, 1); |
|
354 | + return $this->get_all($form_id, 1); |
|
355 | 355 | } |
356 | 356 | |
357 | - public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
|
358 | - $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
359 | - if ( empty($action_controls) ) { |
|
360 | - // don't continue if there are no available actions |
|
361 | - return array(); |
|
362 | - } |
|
357 | + public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
|
358 | + $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
359 | + if ( empty($action_controls) ) { |
|
360 | + // don't continue if there are no available actions |
|
361 | + return array(); |
|
362 | + } |
|
363 | 363 | |
364 | - if ( 'all' != $type ) { |
|
365 | - return $action_controls->get_all( $form_id, $limit ); |
|
366 | - } |
|
364 | + if ( 'all' != $type ) { |
|
365 | + return $action_controls->get_all( $form_id, $limit ); |
|
366 | + } |
|
367 | 367 | |
368 | 368 | $args = self::action_args( $form_id, $limit ); |
369 | 369 | $actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' ); |
370 | 370 | |
371 | - if ( ! $actions ) { |
|
372 | - return array(); |
|
373 | - } |
|
371 | + if ( ! $actions ) { |
|
372 | + return array(); |
|
373 | + } |
|
374 | 374 | |
375 | - $settings = array(); |
|
376 | - foreach ( $actions as $action ) { |
|
375 | + $settings = array(); |
|
376 | + foreach ( $actions as $action ) { |
|
377 | 377 | // some plugins/themes are formatting the post_excerpt |
378 | 378 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
379 | 379 | |
380 | 380 | if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
381 | - continue; |
|
382 | - } |
|
381 | + continue; |
|
382 | + } |
|
383 | 383 | |
384 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
384 | + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
385 | 385 | $settings[ $action->ID ] = $action; |
386 | 386 | |
387 | 387 | if ( count( $settings ) >= $limit ) { |
388 | 388 | break; |
389 | 389 | } |
390 | - } |
|
390 | + } |
|
391 | 391 | |
392 | - if ( 1 === $limit ) { |
|
393 | - $settings = reset($settings); |
|
394 | - } |
|
392 | + if ( 1 === $limit ) { |
|
393 | + $settings = reset($settings); |
|
394 | + } |
|
395 | 395 | |
396 | - return $settings; |
|
397 | - } |
|
396 | + return $settings; |
|
397 | + } |
|
398 | 398 | |
399 | 399 | /** |
400 | 400 | * @param int $action_id |
@@ -414,45 +414,45 @@ discard block |
||
414 | 414 | } |
415 | 415 | |
416 | 416 | public function get_all( $form_id = false, $limit = 99 ) { |
417 | - if ( $form_id ) { |
|
418 | - $this->form_id = $form_id; |
|
419 | - } |
|
417 | + if ( $form_id ) { |
|
418 | + $this->form_id = $form_id; |
|
419 | + } |
|
420 | 420 | |
421 | - $type = $this->id_base; |
|
421 | + $type = $this->id_base; |
|
422 | 422 | |
423 | - global $frm_vars; |
|
424 | - $frm_vars['action_type'] = $type; |
|
423 | + global $frm_vars; |
|
424 | + $frm_vars['action_type'] = $type; |
|
425 | 425 | |
426 | - add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
426 | + add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
427 | 427 | $query = self::action_args( $form_id, $limit ); |
428 | - $query['post_status'] = 'any'; |
|
429 | - $query['suppress_filters'] = false; |
|
428 | + $query['post_status'] = 'any'; |
|
429 | + $query['suppress_filters'] = false; |
|
430 | 430 | |
431 | 431 | $actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
432 | - unset($query); |
|
432 | + unset($query); |
|
433 | 433 | |
434 | - remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
434 | + remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
435 | 435 | |
436 | - if ( empty($actions) ) { |
|
437 | - return array(); |
|
438 | - } |
|
436 | + if ( empty($actions) ) { |
|
437 | + return array(); |
|
438 | + } |
|
439 | 439 | |
440 | - $settings = array(); |
|
441 | - foreach ( $actions as $action ) { |
|
442 | - if ( count($settings) >= $limit ) { |
|
443 | - continue; |
|
444 | - } |
|
440 | + $settings = array(); |
|
441 | + foreach ( $actions as $action ) { |
|
442 | + if ( count($settings) >= $limit ) { |
|
443 | + continue; |
|
444 | + } |
|
445 | 445 | |
446 | - $action = $this->prepare_action($action); |
|
446 | + $action = $this->prepare_action($action); |
|
447 | 447 | |
448 | 448 | $settings[ $action->ID ] = $action; |
449 | - } |
|
449 | + } |
|
450 | 450 | |
451 | - if ( 1 === $limit ) { |
|
452 | - $settings = reset($settings); |
|
453 | - } |
|
451 | + if ( 1 === $limit ) { |
|
452 | + $settings = reset($settings); |
|
453 | + } |
|
454 | 454 | |
455 | - return $settings; |
|
455 | + return $settings; |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | public static function action_args( $form_id = 0, $limit = 99 ) { |
@@ -475,45 +475,45 @@ discard block |
||
475 | 475 | $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
476 | 476 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
477 | 477 | |
478 | - $default_values = $this->get_global_defaults(); |
|
478 | + $default_values = $this->get_global_defaults(); |
|
479 | 479 | |
480 | - // fill default values |
|
481 | - $action->post_content += $default_values; |
|
480 | + // fill default values |
|
481 | + $action->post_content += $default_values; |
|
482 | 482 | |
483 | - foreach ( $default_values as $k => $vals ) { |
|
484 | - if ( is_array($vals) && ! empty($vals) ) { |
|
483 | + foreach ( $default_values as $k => $vals ) { |
|
484 | + if ( is_array($vals) && ! empty($vals) ) { |
|
485 | 485 | if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
486 | - continue; |
|
487 | - } |
|
486 | + continue; |
|
487 | + } |
|
488 | 488 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
489 | - } |
|
490 | - } |
|
489 | + } |
|
490 | + } |
|
491 | 491 | |
492 | - if ( ! is_array($action->post_content['event']) ) { |
|
493 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
494 | - } |
|
492 | + if ( ! is_array($action->post_content['event']) ) { |
|
493 | + $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
494 | + } |
|
495 | 495 | |
496 | - return $action; |
|
496 | + return $action; |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | public function destroy( $form_id = false, $type = 'default' ) { |
500 | - global $wpdb; |
|
500 | + global $wpdb; |
|
501 | 501 | |
502 | - $this->form_id = $form_id; |
|
502 | + $this->form_id = $form_id; |
|
503 | 503 | |
504 | - $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
505 | - if ( $form_id ) { |
|
506 | - $query['menu_order'] = $form_id; |
|
507 | - } |
|
508 | - if ( 'all' != $type ) { |
|
509 | - $query['post_excerpt'] = $this->id_base; |
|
510 | - } |
|
504 | + $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
505 | + if ( $form_id ) { |
|
506 | + $query['menu_order'] = $form_id; |
|
507 | + } |
|
508 | + if ( 'all' != $type ) { |
|
509 | + $query['post_excerpt'] = $this->id_base; |
|
510 | + } |
|
511 | 511 | |
512 | - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
512 | + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
513 | 513 | |
514 | - foreach ( $post_ids as $id ) { |
|
515 | - wp_delete_post($id); |
|
516 | - } |
|
514 | + foreach ( $post_ids as $id ) { |
|
515 | + wp_delete_post($id); |
|
516 | + } |
|
517 | 517 | self::clear_cache(); |
518 | 518 | } |
519 | 519 | |
@@ -531,69 +531,69 @@ discard block |
||
531 | 531 | } |
532 | 532 | |
533 | 533 | public function get_global_defaults() { |
534 | - $defaults = $this->get_defaults(); |
|
534 | + $defaults = $this->get_defaults(); |
|
535 | 535 | |
536 | - if ( ! isset($defaults['event']) ) { |
|
536 | + if ( ! isset($defaults['event']) ) { |
|
537 | 537 | $defaults['event'] = array( 'create' ); |
538 | - } |
|
538 | + } |
|
539 | 539 | |
540 | - if ( ! isset($defaults['conditions']) ) { |
|
541 | - $defaults['conditions'] = array( |
|
542 | - 'send_stop' => '', |
|
543 | - 'any_all' => '', |
|
544 | - ); |
|
545 | - } |
|
540 | + if ( ! isset($defaults['conditions']) ) { |
|
541 | + $defaults['conditions'] = array( |
|
542 | + 'send_stop' => '', |
|
543 | + 'any_all' => '', |
|
544 | + ); |
|
545 | + } |
|
546 | 546 | |
547 | - return $defaults; |
|
547 | + return $defaults; |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | public function get_global_switch_fields() { |
551 | - $switch = $this->get_switch_fields(); |
|
551 | + $switch = $this->get_switch_fields(); |
|
552 | 552 | $switch['conditions'] = array( 'hide_field' ); |
553 | - return $switch; |
|
553 | + return $switch; |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
557 | 557 | * Migrate settings from form->options into new action. |
558 | 558 | */ |
559 | 559 | public function migrate_to_2( $form, $update = 'update' ) { |
560 | - $action = $this->prepare_new($form->id); |
|
561 | - $form->options = maybe_unserialize($form->options); |
|
560 | + $action = $this->prepare_new($form->id); |
|
561 | + $form->options = maybe_unserialize($form->options); |
|
562 | 562 | |
563 | - // fill with existing options |
|
564 | - foreach ( $action->post_content as $name => $val ) { |
|
563 | + // fill with existing options |
|
564 | + foreach ( $action->post_content as $name => $val ) { |
|
565 | 565 | if ( isset( $form->options[ $name ] ) ) { |
566 | 566 | $action->post_content[ $name ] = $form->options[ $name ]; |
567 | 567 | unset( $form->options[ $name ] ); |
568 | - } |
|
569 | - } |
|
568 | + } |
|
569 | + } |
|
570 | 570 | |
571 | - $action = $this->migrate_values($action, $form); |
|
571 | + $action = $this->migrate_values($action, $form); |
|
572 | 572 | |
573 | - // check if action already exists |
|
574 | - $post_id = get_posts( array( |
|
575 | - 'name' => $action->post_name, |
|
576 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
577 | - 'post_status' => $action->post_status, |
|
578 | - 'numberposts' => 1, |
|
579 | - ) ); |
|
573 | + // check if action already exists |
|
574 | + $post_id = get_posts( array( |
|
575 | + 'name' => $action->post_name, |
|
576 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
577 | + 'post_status' => $action->post_status, |
|
578 | + 'numberposts' => 1, |
|
579 | + ) ); |
|
580 | 580 | |
581 | - if ( empty($post_id) ) { |
|
582 | - // create action now |
|
583 | - $post_id = $this->save_settings($action); |
|
584 | - } |
|
581 | + if ( empty($post_id) ) { |
|
582 | + // create action now |
|
583 | + $post_id = $this->save_settings($action); |
|
584 | + } |
|
585 | 585 | |
586 | - if ( $post_id && 'update' == $update ) { |
|
587 | - global $wpdb; |
|
588 | - $form->options = maybe_serialize($form->options); |
|
586 | + if ( $post_id && 'update' == $update ) { |
|
587 | + global $wpdb; |
|
588 | + $form->options = maybe_serialize($form->options); |
|
589 | 589 | |
590 | - // update form options |
|
590 | + // update form options |
|
591 | 591 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
592 | - FrmForm::clear_form_cache(); |
|
593 | - } |
|
592 | + FrmForm::clear_form_cache(); |
|
593 | + } |
|
594 | 594 | |
595 | - return $post_id; |
|
596 | - } |
|
595 | + return $post_id; |
|
596 | + } |
|
597 | 597 | |
598 | 598 | public static function action_conditions_met( $action, $entry ) { |
599 | 599 | $notification = $action->post_content; |
@@ -2,16 +2,16 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmFormAction { |
4 | 4 | |
5 | - public $id_base; // Root id for all actions of this type. |
|
6 | - public $name; // Name for this action type. |
|
5 | + public $id_base; // Root id for all actions of this type. |
|
6 | + public $name; // Name for this action type. |
|
7 | 7 | public $option_name; |
8 | - public $action_options; // Option array passed to wp_register_sidebar_widget() |
|
9 | - public $control_options; // Option array passed to wp_register_widget_control() |
|
8 | + public $action_options; // Option array passed to wp_register_sidebar_widget() |
|
9 | + public $control_options; // Option array passed to wp_register_widget_control() |
|
10 | 10 | |
11 | - public $form_id; // The ID of the form to evaluate |
|
12 | - public $number = false; // Unique ID number of the current instance. |
|
13 | - public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
14 | - public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
|
11 | + public $form_id; // The ID of the form to evaluate |
|
12 | + public $number = false; // Unique ID number of the current instance. |
|
13 | + public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
14 | + public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
|
15 | 15 | |
16 | 16 | // Member functions that you must over-ride. |
17 | 17 | |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | * - height: currently not used but may be needed in the future |
70 | 70 | */ |
71 | 71 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
72 | - if ( ! defined('ABSPATH') ) { |
|
73 | - die('You are not allowed to call this page directly.'); |
|
72 | + if ( ! defined( 'ABSPATH' ) ) { |
|
73 | + die( 'You are not allowed to call this page directly.' ); |
|
74 | 74 | } |
75 | 75 | |
76 | - $this->id_base = strtolower($id_base); |
|
76 | + $this->id_base = strtolower( $id_base ); |
|
77 | 77 | $this->name = $name; |
78 | 78 | $this->option_name = 'frm_' . $this->id_base . '_action'; |
79 | 79 | |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | $default_values = $this->get_global_defaults(); |
144 | 144 | |
145 | 145 | // fill default values |
146 | - $post_content = wp_parse_args( $post_content, $default_values); |
|
146 | + $post_content = wp_parse_args( $post_content, $default_values ); |
|
147 | 147 | |
148 | - if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
149 | - $post_content['event'] = array( reset($this->action_options['event']) ); |
|
148 | + if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) { |
|
149 | + $post_content['event'] = array( reset( $this->action_options['event'] ) ); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $form_action = array( |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
160 | 160 | 'menu_order' => $this->form_id, |
161 | 161 | ); |
162 | - unset($post_content); |
|
162 | + unset( $post_content ); |
|
163 | 163 | |
164 | 164 | return (object) $form_action; |
165 | 165 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | $action = $this->prepare_new(); |
171 | 171 | |
172 | - return $this->save_settings($action); |
|
172 | + return $this->save_settings( $action ); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | public function duplicate_form_actions( $form_id, $old_id ) { |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | |
184 | 184 | $this->form_id = $form_id; |
185 | 185 | foreach ( $actions as $action ) { |
186 | - $this->duplicate_one($action, $form_id); |
|
187 | - unset($action); |
|
186 | + $this->duplicate_one( $action, $form_id ); |
|
187 | + unset( $action ); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | * @return integer $post_id |
197 | 197 | */ |
198 | 198 | public function maybe_create_action( $action, $forms ) { |
199 | - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
|
199 | + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) { |
|
200 | 200 | // Update action only |
201 | 201 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
202 | 202 | $post_id = $this->save_settings( $action ); |
203 | 203 | } else { |
204 | 204 | // Create action |
205 | - $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
206 | - $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
205 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
206 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] ); |
|
207 | 207 | } |
208 | 208 | return $post_id; |
209 | 209 | } |
@@ -214,47 +214,47 @@ discard block |
||
214 | 214 | $action->menu_order = $form_id; |
215 | 215 | $switch = $this->get_global_switch_fields(); |
216 | 216 | foreach ( (array) $action->post_content as $key => $val ) { |
217 | - if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
|
218 | - $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
|
217 | + if ( is_numeric( $val ) && isset( $frm_duplicate_ids[$val] ) ) { |
|
218 | + $action->post_content[$key] = $frm_duplicate_ids[$val]; |
|
219 | 219 | } else if ( ! is_array( $val ) ) { |
220 | - $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
|
221 | - } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
|
220 | + $action->post_content[$key] = FrmFieldsHelper::switch_field_ids( $val ); |
|
221 | + } else if ( isset( $switch[$key] ) && is_array( $switch[$key] ) ) { |
|
222 | 222 | // loop through each value if empty |
223 | - if ( empty( $switch[ $key ] ) ) { |
|
224 | - $switch[ $key ] = array_keys( $val ); |
|
223 | + if ( empty( $switch[$key] ) ) { |
|
224 | + $switch[$key] = array_keys( $val ); |
|
225 | 225 | } |
226 | 226 | |
227 | - foreach ( $switch[ $key ] as $subkey ) { |
|
228 | - $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
|
227 | + foreach ( $switch[$key] as $subkey ) { |
|
228 | + $action->post_content[$key] = $this->duplicate_array_walk( $action->post_content[$key], $subkey, $val ); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - unset($key, $val); |
|
232 | + unset( $key, $val ); |
|
233 | 233 | } |
234 | - unset($action->ID); |
|
234 | + unset( $action->ID ); |
|
235 | 235 | |
236 | - return $this->save_settings($action); |
|
236 | + return $this->save_settings( $action ); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | private function duplicate_array_walk( $action, $subkey, $val ) { |
240 | 240 | global $frm_duplicate_ids; |
241 | 241 | |
242 | - if ( is_array($subkey) ) { |
|
242 | + if ( is_array( $subkey ) ) { |
|
243 | 243 | foreach ( $subkey as $subkey2 ) { |
244 | 244 | foreach ( (array) $val as $ck => $cv ) { |
245 | - if ( is_array($cv) ) { |
|
246 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
|
247 | - } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
|
248 | - $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
|
245 | + if ( is_array( $cv ) ) { |
|
246 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey2, $cv ); |
|
247 | + } else if ( isset( $cv[$subkey] ) && is_numeric( $cv[$subkey] ) && isset( $frm_duplicate_ids[$cv[$subkey]] ) ) { |
|
248 | + $action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]]; |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | } |
252 | 252 | } else { |
253 | 253 | foreach ( (array) $val as $ck => $cv ) { |
254 | - if ( is_array($cv) ) { |
|
255 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
|
256 | - } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
|
257 | - $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
|
254 | + if ( is_array( $cv ) ) { |
|
255 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey, $cv ); |
|
256 | + } else if ( $ck == $subkey && isset( $frm_duplicate_ids[$cv] ) ) { |
|
257 | + $action[$ck] = $frm_duplicate_ids[$cv]; |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | } |
@@ -278,8 +278,8 @@ discard block |
||
278 | 278 | return; |
279 | 279 | } |
280 | 280 | |
281 | - if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) { |
|
282 | - $settings = $_POST[ $this->option_name ]; |
|
281 | + if ( isset( $_POST[$this->option_name] ) && is_array( $_POST[$this->option_name] ) ) { |
|
282 | + $settings = $_POST[$this->option_name]; |
|
283 | 283 | } else { |
284 | 284 | return; |
285 | 285 | } |
@@ -287,19 +287,19 @@ discard block |
||
287 | 287 | $action_ids = array(); |
288 | 288 | |
289 | 289 | foreach ( $settings as $number => $new_instance ) { |
290 | - $this->_set($number); |
|
290 | + $this->_set( $number ); |
|
291 | 291 | |
292 | - if ( ! isset($new_instance['post_title']) ) { |
|
292 | + if ( ! isset( $new_instance['post_title'] ) ) { |
|
293 | 293 | // settings were never opened, so don't update |
294 | 294 | $action_ids[] = $new_instance['ID']; |
295 | 295 | $this->updated = true; |
296 | 296 | continue; |
297 | 297 | } |
298 | 298 | |
299 | - $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
|
299 | + $old_instance = isset( $all_instances[$number] ) ? $all_instances[$number] : array(); |
|
300 | 300 | |
301 | - $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
|
302 | - $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
|
301 | + $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
|
302 | + $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
|
303 | 303 | $new_instance['menu_order'] = $this->form_id; |
304 | 304 | $new_instance['post_status'] = 'publish'; |
305 | 305 | $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
@@ -321,14 +321,14 @@ discard block |
||
321 | 321 | */ |
322 | 322 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
323 | 323 | |
324 | - $instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this); |
|
324 | + $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
|
325 | 325 | $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
326 | 326 | |
327 | 327 | if ( false !== $instance ) { |
328 | - $all_instances[ $number ] = $instance; |
|
328 | + $all_instances[$number] = $instance; |
|
329 | 329 | } |
330 | 330 | |
331 | - $action_ids[] = $this->save_settings($instance); |
|
331 | + $action_ids[] = $this->save_settings( $instance ); |
|
332 | 332 | |
333 | 333 | $this->updated = true; |
334 | 334 | } |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | public function get_single_action( $id ) { |
345 | - $action = get_post($id); |
|
345 | + $action = get_post( $id ); |
|
346 | 346 | if ( $action ) { |
347 | 347 | $action = $this->prepare_action( $action ); |
348 | 348 | $this->_set( $id ); |
@@ -351,12 +351,12 @@ discard block |
||
351 | 351 | } |
352 | 352 | |
353 | 353 | public function get_one( $form_id ) { |
354 | - return $this->get_all($form_id, 1); |
|
354 | + return $this->get_all( $form_id, 1 ); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
358 | 358 | $action_controls = FrmFormActionsController::get_form_actions( $type ); |
359 | - if ( empty($action_controls) ) { |
|
359 | + if ( empty( $action_controls ) ) { |
|
360 | 360 | // don't continue if there are no available actions |
361 | 361 | return array(); |
362 | 362 | } |
@@ -377,12 +377,12 @@ discard block |
||
377 | 377 | // some plugins/themes are formatting the post_excerpt |
378 | 378 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
379 | 379 | |
380 | - if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
|
380 | + if ( ! isset( $action_controls[$action->post_excerpt] ) ) { |
|
381 | 381 | continue; |
382 | 382 | } |
383 | 383 | |
384 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
385 | - $settings[ $action->ID ] = $action; |
|
384 | + $action = $action_controls[$action->post_excerpt]->prepare_action( $action ); |
|
385 | + $settings[$action->ID] = $action; |
|
386 | 386 | |
387 | 387 | if ( count( $settings ) >= $limit ) { |
388 | 388 | break; |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | if ( 1 === $limit ) { |
393 | - $settings = reset($settings); |
|
393 | + $settings = reset( $settings ); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return $settings; |
@@ -423,33 +423,33 @@ discard block |
||
423 | 423 | global $frm_vars; |
424 | 424 | $frm_vars['action_type'] = $type; |
425 | 425 | |
426 | - add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
426 | + add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
|
427 | 427 | $query = self::action_args( $form_id, $limit ); |
428 | 428 | $query['post_status'] = 'any'; |
429 | 429 | $query['suppress_filters'] = false; |
430 | 430 | |
431 | 431 | $actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
432 | - unset($query); |
|
432 | + unset( $query ); |
|
433 | 433 | |
434 | - remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
434 | + remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
|
435 | 435 | |
436 | - if ( empty($actions) ) { |
|
436 | + if ( empty( $actions ) ) { |
|
437 | 437 | return array(); |
438 | 438 | } |
439 | 439 | |
440 | 440 | $settings = array(); |
441 | 441 | foreach ( $actions as $action ) { |
442 | - if ( count($settings) >= $limit ) { |
|
442 | + if ( count( $settings ) >= $limit ) { |
|
443 | 443 | continue; |
444 | 444 | } |
445 | 445 | |
446 | - $action = $this->prepare_action($action); |
|
446 | + $action = $this->prepare_action( $action ); |
|
447 | 447 | |
448 | - $settings[ $action->ID ] = $action; |
|
448 | + $settings[$action->ID] = $action; |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | if ( 1 === $limit ) { |
452 | - $settings = reset($settings); |
|
452 | + $settings = reset( $settings ); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | return $settings; |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | } |
473 | 473 | |
474 | 474 | public function prepare_action( $action ) { |
475 | - $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
|
475 | + $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
|
476 | 476 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
477 | 477 | |
478 | 478 | $default_values = $this->get_global_defaults(); |
@@ -481,16 +481,16 @@ discard block |
||
481 | 481 | $action->post_content += $default_values; |
482 | 482 | |
483 | 483 | foreach ( $default_values as $k => $vals ) { |
484 | - if ( is_array($vals) && ! empty($vals) ) { |
|
485 | - if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
|
484 | + if ( is_array( $vals ) && ! empty( $vals ) ) { |
|
485 | + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[$k] ) ) { |
|
486 | 486 | continue; |
487 | 487 | } |
488 | - $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
|
488 | + $action->post_content[$k] = wp_parse_args( $action->post_content[$k], $vals ); |
|
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | - if ( ! is_array($action->post_content['event']) ) { |
|
493 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
492 | + if ( ! is_array( $action->post_content['event'] ) ) { |
|
493 | + $action->post_content['event'] = explode( ',', $action->post_content['event'] ); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | return $action; |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
513 | 513 | |
514 | 514 | foreach ( $post_ids as $id ) { |
515 | - wp_delete_post($id); |
|
515 | + wp_delete_post( $id ); |
|
516 | 516 | } |
517 | 517 | self::clear_cache(); |
518 | 518 | } |
@@ -533,11 +533,11 @@ discard block |
||
533 | 533 | public function get_global_defaults() { |
534 | 534 | $defaults = $this->get_defaults(); |
535 | 535 | |
536 | - if ( ! isset($defaults['event']) ) { |
|
536 | + if ( ! isset( $defaults['event'] ) ) { |
|
537 | 537 | $defaults['event'] = array( 'create' ); |
538 | 538 | } |
539 | 539 | |
540 | - if ( ! isset($defaults['conditions']) ) { |
|
540 | + if ( ! isset( $defaults['conditions'] ) ) { |
|
541 | 541 | $defaults['conditions'] = array( |
542 | 542 | 'send_stop' => '', |
543 | 543 | 'any_all' => '', |
@@ -557,18 +557,18 @@ discard block |
||
557 | 557 | * Migrate settings from form->options into new action. |
558 | 558 | */ |
559 | 559 | public function migrate_to_2( $form, $update = 'update' ) { |
560 | - $action = $this->prepare_new($form->id); |
|
561 | - $form->options = maybe_unserialize($form->options); |
|
560 | + $action = $this->prepare_new( $form->id ); |
|
561 | + $form->options = maybe_unserialize( $form->options ); |
|
562 | 562 | |
563 | 563 | // fill with existing options |
564 | 564 | foreach ( $action->post_content as $name => $val ) { |
565 | - if ( isset( $form->options[ $name ] ) ) { |
|
566 | - $action->post_content[ $name ] = $form->options[ $name ]; |
|
567 | - unset( $form->options[ $name ] ); |
|
565 | + if ( isset( $form->options[$name] ) ) { |
|
566 | + $action->post_content[$name] = $form->options[$name]; |
|
567 | + unset( $form->options[$name] ); |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
571 | - $action = $this->migrate_values($action, $form); |
|
571 | + $action = $this->migrate_values( $action, $form ); |
|
572 | 572 | |
573 | 573 | // check if action already exists |
574 | 574 | $post_id = get_posts( array( |
@@ -578,14 +578,14 @@ discard block |
||
578 | 578 | 'numberposts' => 1, |
579 | 579 | ) ); |
580 | 580 | |
581 | - if ( empty($post_id) ) { |
|
581 | + if ( empty( $post_id ) ) { |
|
582 | 582 | // create action now |
583 | - $post_id = $this->save_settings($action); |
|
583 | + $post_id = $this->save_settings( $action ); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | if ( $post_id && 'update' == $update ) { |
587 | 587 | global $wpdb; |
588 | - $form->options = maybe_serialize($form->options); |
|
588 | + $form->options = maybe_serialize( $form->options ); |
|
589 | 589 | |
590 | 590 | // update form options |
591 | 591 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
@@ -617,18 +617,18 @@ discard block |
||
617 | 617 | |
618 | 618 | $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] ); |
619 | 619 | |
620 | - $stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']); |
|
620 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); |
|
621 | 621 | |
622 | 622 | if ( $notification['conditions']['send_stop'] == 'send' ) { |
623 | 623 | $stop = $stop ? false : true; |
624 | 624 | } |
625 | 625 | |
626 | - $met[ $stop ] = $stop; |
|
626 | + $met[$stop] = $stop; |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { |
630 | - $stop = ($notification['conditions']['send_stop'] == 'send'); |
|
631 | - } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) { |
|
630 | + $stop = ( $notification['conditions']['send_stop'] == 'send' ); |
|
631 | + } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) { |
|
632 | 632 | $stop = false; |
633 | 633 | } |
634 | 634 | |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | private static function get_value_from_entry( $entry, $field_id ) { |
664 | 664 | $observed_value = ''; |
665 | 665 | |
666 | - if ( isset( $entry->metas[ $field_id ] ) ) { |
|
667 | - $observed_value = $entry->metas[ $field_id ]; |
|
666 | + if ( isset( $entry->metas[$field_id] ) ) { |
|
667 | + $observed_value = $entry->metas[$field_id]; |
|
668 | 668 | } else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) { |
669 | 669 | $field = FrmField::getOne( $field_id ); |
670 | 670 | $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value( $entry, $field, array( 'links' => false, 'truncate' => false ) ); |
@@ -23,30 +23,30 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | public static function import_xml( $file ) { |
26 | - $defaults = array( |
|
27 | - 'forms' => 0, 'fields' => 0, 'terms' => 0, |
|
28 | - 'posts' => 0, 'views' => 0, 'actions' => 0, |
|
29 | - 'styles' => 0, |
|
30 | - ); |
|
31 | - |
|
32 | - $imported = array( |
|
33 | - 'imported' => $defaults, |
|
26 | + $defaults = array( |
|
27 | + 'forms' => 0, 'fields' => 0, 'terms' => 0, |
|
28 | + 'posts' => 0, 'views' => 0, 'actions' => 0, |
|
29 | + 'styles' => 0, |
|
30 | + ); |
|
31 | + |
|
32 | + $imported = array( |
|
33 | + 'imported' => $defaults, |
|
34 | 34 | 'updated' => $defaults, |
35 | 35 | 'forms' => array(), |
36 | 36 | 'terms' => array(), |
37 | - ); |
|
37 | + ); |
|
38 | 38 | |
39 | - unset($defaults); |
|
39 | + unset($defaults); |
|
40 | 40 | |
41 | 41 | if ( ! defined( 'WP_IMPORTING' ) ) { |
42 | - define('WP_IMPORTING', true); |
|
43 | - } |
|
42 | + define('WP_IMPORTING', true); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | if ( ! class_exists( 'DOMDocument' ) ) { |
46 | - return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() ); |
|
47 | - } |
|
46 | + return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() ); |
|
47 | + } |
|
48 | 48 | |
49 | - $dom = new DOMDocument; |
|
49 | + $dom = new DOMDocument; |
|
50 | 50 | $success = $dom->loadXML( file_get_contents( $file ) ); |
51 | 51 | if ( ! $success ) { |
52 | 52 | return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() ); |
@@ -64,45 +64,45 @@ discard block |
||
64 | 64 | return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() ); |
65 | 65 | } |
66 | 66 | |
67 | - // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order |
|
67 | + // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order |
|
68 | 68 | foreach ( array( 'term', 'form', 'view' ) as $item_type ) { |
69 | - // grab cats, tags, and terms, or forms or posts |
|
70 | - if ( isset($xml->{$item_type} ) ) { |
|
69 | + // grab cats, tags, and terms, or forms or posts |
|
70 | + if ( isset($xml->{$item_type} ) ) { |
|
71 | 71 | $function_name = 'import_xml_' . $item_type . 's'; |
72 | 72 | $imported = self::$function_name( $xml->{$item_type}, $imported ); |
73 | 73 | unset( $function_name, $xml->{$item_type} ); |
74 | - } |
|
75 | - } |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - $return = apply_filters('frm_importing_xml', $imported, $xml ); |
|
77 | + $return = apply_filters('frm_importing_xml', $imported, $xml ); |
|
78 | 78 | |
79 | - return $return; |
|
80 | - } |
|
79 | + return $return; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | public static function import_xml_terms( $terms, $imported ) { |
83 | - foreach ( $terms as $t ) { |
|
83 | + foreach ( $terms as $t ) { |
|
84 | 84 | if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) { |
85 | - continue; |
|
85 | + continue; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $parent = self::get_term_parent_id( $t ); |
89 | 89 | |
90 | 90 | $term = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array( |
91 | - 'slug' => (string) $t->term_slug, |
|
92 | - 'description' => (string) $t->term_description, |
|
91 | + 'slug' => (string) $t->term_slug, |
|
92 | + 'description' => (string) $t->term_description, |
|
93 | 93 | 'parent' => empty( $parent ) ? 0 : $parent, |
94 | - )); |
|
94 | + )); |
|
95 | 95 | |
96 | 96 | if ( $term && is_array( $term ) ) { |
97 | - $imported['imported']['terms']++; |
|
97 | + $imported['imported']['terms']++; |
|
98 | 98 | $imported['terms'][ (int) $t->term_id ] = $term['term_id']; |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | unset( $term, $t ); |
102 | 102 | } |
103 | 103 | |
104 | 104 | return $imported; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @since 2.0.8 |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | self::put_child_forms_first( $forms ); |
128 | 128 | |
129 | 129 | foreach ( $forms as $item ) { |
130 | - $form = self::fill_form( $item ); |
|
130 | + $form = self::fill_form( $item ); |
|
131 | 131 | |
132 | 132 | self::update_custom_style_setting_on_import( $form ); |
133 | 133 | |
134 | - $this_form = self::maybe_get_form( $form ); |
|
134 | + $this_form = self::maybe_get_form( $form ); |
|
135 | 135 | |
136 | 136 | $old_id = $form_fields = false; |
137 | 137 | if ( ! empty( $this_form ) ) { |
@@ -141,35 +141,35 @@ discard block |
||
141 | 141 | $form_fields = self::get_form_fields( $form_id ); |
142 | 142 | } else { |
143 | 143 | $form_id = FrmForm::create( $form ); |
144 | - if ( $form_id ) { |
|
145 | - $imported['imported']['forms']++; |
|
146 | - // Keep track of whether this specific form was updated or not |
|
144 | + if ( $form_id ) { |
|
145 | + $imported['imported']['forms']++; |
|
146 | + // Keep track of whether this specific form was updated or not |
|
147 | 147 | $imported['form_status'][ $form_id ] = 'imported'; |
148 | 148 | self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms ); |
149 | - } |
|
149 | + } |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported ); |
153 | 153 | |
154 | 154 | self::delete_removed_fields( $form_fields ); |
155 | 155 | |
156 | - // Update field ids/keys to new ones |
|
156 | + // Update field ids/keys to new ones |
|
157 | 157 | do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) ); |
158 | 158 | |
159 | 159 | $imported['forms'][ (int) $item->id ] = $form_id; |
160 | 160 | |
161 | - // Send pre 2.0 form options through function that creates actions |
|
162 | - self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
|
161 | + // Send pre 2.0 form options through function that creates actions |
|
162 | + self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
|
163 | 163 | |
164 | 164 | do_action( 'frm_after_import_form', $form_id, $form ); |
165 | 165 | |
166 | - unset($form, $item); |
|
166 | + unset($form, $item); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms ); |
170 | 170 | |
171 | 171 | return $imported; |
172 | - } |
|
172 | + } |
|
173 | 173 | |
174 | 174 | private static function fill_form( $item ) { |
175 | 175 | $form = array( |
@@ -237,11 +237,11 @@ discard block |
||
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
240 | - * Put child forms first so they will be imported before parents |
|
241 | - * |
|
242 | - * @since 2.0.16 |
|
243 | - * @param array $forms |
|
244 | - */ |
|
240 | + * Put child forms first so they will be imported before parents |
|
241 | + * |
|
242 | + * @since 2.0.16 |
|
243 | + * @param array $forms |
|
244 | + */ |
|
245 | 245 | private static function put_child_forms_first( &$forms ) { |
246 | 246 | $child_forms = array(); |
247 | 247 | $regular_forms = array(); |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | - * Keep track of all imported child forms |
|
264 | - * |
|
265 | - * @since 2.0.16 |
|
266 | - * @param int $form_id |
|
267 | - * @param int $parent_form_id |
|
268 | - * @param array $child_forms |
|
269 | - */ |
|
263 | + * Keep track of all imported child forms |
|
264 | + * |
|
265 | + * @since 2.0.16 |
|
266 | + * @param int $form_id |
|
267 | + * @param int $parent_form_id |
|
268 | + * @param array $child_forms |
|
269 | + */ |
|
270 | 270 | private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) { |
271 | 271 | if ( $parent_form_id ) { |
272 | 272 | $child_forms[ $form_id ] = $parent_form_id; |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
277 | - * Update the parent_form_id on imported child forms |
|
278 | - * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported |
|
279 | - * |
|
280 | - * @since 2.0.6 |
|
281 | - * @param array $imported_forms |
|
282 | - * @param array $child_forms |
|
283 | - */ |
|
277 | + * Update the parent_form_id on imported child forms |
|
278 | + * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported |
|
279 | + * |
|
280 | + * @since 2.0.6 |
|
281 | + * @param array $imported_forms |
|
282 | + * @param array $child_forms |
|
283 | + */ |
|
284 | 284 | private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) { |
285 | 285 | foreach ( $child_forms as $child_form_id => $old_parent_form_id ) { |
286 | 286 | |
@@ -294,28 +294,28 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Import all fields for a form |
|
298 | - * @since 2.0.13 |
|
299 | - * |
|
300 | - * TODO: Cut down on params |
|
301 | - */ |
|
297 | + * Import all fields for a form |
|
298 | + * @since 2.0.13 |
|
299 | + * |
|
300 | + * TODO: Cut down on params |
|
301 | + */ |
|
302 | 302 | private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) { |
303 | 303 | $in_section = 0; |
304 | 304 | |
305 | 305 | foreach ( $xml_fields as $field ) { |
306 | 306 | $f = self::fill_field( $field, $form_id ); |
307 | 307 | |
308 | - if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
309 | - 'text', 'email', 'url', 'textarea', |
|
310 | - 'number','phone', 'date', 'time', |
|
311 | - 'hidden', 'password', 'tag', 'image', |
|
312 | - )) ) { |
|
313 | - if ( count($f['default_value']) === 1 ) { |
|
308 | + if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
309 | + 'text', 'email', 'url', 'textarea', |
|
310 | + 'number','phone', 'date', 'time', |
|
311 | + 'hidden', 'password', 'tag', 'image', |
|
312 | + )) ) { |
|
313 | + if ( count($f['default_value']) === 1 ) { |
|
314 | 314 | $f['default_value'] = '[' . reset( $f['default_value'] ) . ']'; |
315 | - } else { |
|
316 | - $f['default_value'] = reset($f['default_value']); |
|
317 | - } |
|
318 | - } |
|
315 | + } else { |
|
316 | + $f['default_value'] = reset($f['default_value']); |
|
317 | + } |
|
318 | + } |
|
319 | 319 | |
320 | 320 | self::maybe_update_in_section_variable( $in_section, $f ); |
321 | 321 | self::maybe_update_form_select( $f, $imported ); |
@@ -394,12 +394,12 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
397 | - * Switch the form_select on a repeating field or embedded form if it needs to be switched |
|
398 | - * |
|
399 | - * @since 2.0.16 |
|
400 | - * @param array $f |
|
401 | - * @param array $imported |
|
402 | - */ |
|
397 | + * Switch the form_select on a repeating field or embedded form if it needs to be switched |
|
398 | + * |
|
399 | + * @since 2.0.16 |
|
400 | + * @param array $f |
|
401 | + * @param array $imported |
|
402 | + */ |
|
403 | 403 | private static function maybe_update_form_select( &$f, $imported ) { |
404 | 404 | if ( ! isset( $imported['forms'] ) ) { |
405 | 405 | return; |
@@ -451,13 +451,13 @@ discard block |
||
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
454 | - * Updates the custom style setting on import |
|
455 | - * Convert the post slug to an ID |
|
456 | - * |
|
457 | - * @since 2.0.19 |
|
458 | - * @param array $form |
|
459 | - * |
|
460 | - */ |
|
454 | + * Updates the custom style setting on import |
|
455 | + * Convert the post slug to an ID |
|
456 | + * |
|
457 | + * @since 2.0.19 |
|
458 | + * @param array $form |
|
459 | + * |
|
460 | + */ |
|
461 | 461 | private static function update_custom_style_setting_on_import( &$form ) { |
462 | 462 | if ( ! isset( $form['options']['custom_style'] ) ) { |
463 | 463 | return; |
@@ -511,16 +511,16 @@ discard block |
||
511 | 511 | } |
512 | 512 | |
513 | 513 | public static function import_xml_views( $views, $imported ) { |
514 | - $imported['posts'] = array(); |
|
515 | - $form_action_type = FrmFormActionsController::$action_post_type; |
|
514 | + $imported['posts'] = array(); |
|
515 | + $form_action_type = FrmFormActionsController::$action_post_type; |
|
516 | 516 | |
517 | - $post_types = array( |
|
518 | - 'frm_display' => 'views', |
|
519 | - $form_action_type => 'actions', |
|
520 | - 'frm_styles' => 'styles', |
|
521 | - ); |
|
517 | + $post_types = array( |
|
518 | + 'frm_display' => 'views', |
|
519 | + $form_action_type => 'actions', |
|
520 | + 'frm_styles' => 'styles', |
|
521 | + ); |
|
522 | 522 | |
523 | - foreach ( $views as $item ) { |
|
523 | + foreach ( $views as $item ) { |
|
524 | 524 | $post = array( |
525 | 525 | 'post_title' => (string) $item->title, |
526 | 526 | 'post_name' => (string) $item->post_name, |
@@ -539,52 +539,52 @@ discard block |
||
539 | 539 | 'post_date' => (string) $item->post_date, |
540 | 540 | 'post_date_gmt' => (string) $item->post_date_gmt, |
541 | 541 | 'ping_status' => (string) $item->ping_status, |
542 | - 'postmeta' => array(), |
|
543 | - 'tax_input' => array(), |
|
542 | + 'postmeta' => array(), |
|
543 | + 'tax_input' => array(), |
|
544 | 544 | ); |
545 | 545 | |
546 | - $old_id = $post['post_id']; |
|
547 | - self::populate_post($post, $item, $imported); |
|
546 | + $old_id = $post['post_id']; |
|
547 | + self::populate_post($post, $item, $imported); |
|
548 | 548 | |
549 | 549 | unset($item); |
550 | 550 | |
551 | 551 | $post_id = false; |
552 | - if ( $post['post_type'] == $form_action_type ) { |
|
553 | - $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] ); |
|
552 | + if ( $post['post_type'] == $form_action_type ) { |
|
553 | + $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] ); |
|
554 | 554 | if ( $action_control && is_object( $action_control ) ) { |
555 | 555 | $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] ); |
556 | 556 | } |
557 | - unset($action_control); |
|
558 | - } else if ( $post['post_type'] == 'frm_styles' ) { |
|
559 | - // Properly encode post content before inserting the post |
|
560 | - $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
|
561 | - $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
|
562 | - |
|
563 | - // Create/update post now |
|
564 | - $post_id = wp_insert_post( $post ); |
|
565 | - } else { |
|
566 | - // Create/update post now |
|
567 | - $post_id = wp_insert_post( $post ); |
|
568 | - } |
|
569 | - |
|
570 | - if ( ! is_numeric($post_id) ) { |
|
571 | - continue; |
|
572 | - } |
|
573 | - |
|
574 | - self::update_postmeta($post, $post_id); |
|
575 | - |
|
576 | - $this_type = 'posts'; |
|
557 | + unset($action_control); |
|
558 | + } else if ( $post['post_type'] == 'frm_styles' ) { |
|
559 | + // Properly encode post content before inserting the post |
|
560 | + $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
|
561 | + $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
|
562 | + |
|
563 | + // Create/update post now |
|
564 | + $post_id = wp_insert_post( $post ); |
|
565 | + } else { |
|
566 | + // Create/update post now |
|
567 | + $post_id = wp_insert_post( $post ); |
|
568 | + } |
|
569 | + |
|
570 | + if ( ! is_numeric($post_id) ) { |
|
571 | + continue; |
|
572 | + } |
|
573 | + |
|
574 | + self::update_postmeta($post, $post_id); |
|
575 | + |
|
576 | + $this_type = 'posts'; |
|
577 | 577 | if ( isset( $post_types[ $post['post_type'] ] ) ) { |
578 | 578 | $this_type = $post_types[ $post['post_type'] ]; |
579 | - } |
|
579 | + } |
|
580 | 580 | |
581 | - if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
582 | - $imported['updated'][ $this_type ]++; |
|
583 | - } else { |
|
584 | - $imported['imported'][ $this_type ]++; |
|
585 | - } |
|
581 | + if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
582 | + $imported['updated'][ $this_type ]++; |
|
583 | + } else { |
|
584 | + $imported['imported'][ $this_type ]++; |
|
585 | + } |
|
586 | 586 | |
587 | - unset($post); |
|
587 | + unset($post); |
|
588 | 588 | |
589 | 589 | $imported['posts'][ (int) $old_id ] = $post_id; |
590 | 590 | } |
@@ -592,16 +592,16 @@ discard block |
||
592 | 592 | self::maybe_update_stylesheet( $imported ); |
593 | 593 | |
594 | 594 | return $imported; |
595 | - } |
|
595 | + } |
|
596 | 596 | |
597 | - private static function populate_post( &$post, $item, $imported ) { |
|
597 | + private static function populate_post( &$post, $item, $imported ) { |
|
598 | 598 | if ( isset($item->attachment_url) ) { |
599 | 599 | $post['attachment_url'] = (string) $item->attachment_url; |
600 | 600 | } |
601 | 601 | |
602 | 602 | if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) { |
603 | - // update to new form id |
|
604 | - $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
603 | + // update to new form id |
|
604 | + $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // Don't allow default styles to take over a site's default style |
@@ -610,144 +610,144 @@ discard block |
||
610 | 610 | } |
611 | 611 | |
612 | 612 | foreach ( $item->postmeta as $meta ) { |
613 | - self::populate_postmeta($post, $meta, $imported); |
|
613 | + self::populate_postmeta($post, $meta, $imported); |
|
614 | 614 | unset($meta); |
615 | 615 | } |
616 | 616 | |
617 | - self::populate_taxonomies($post, $item); |
|
617 | + self::populate_taxonomies($post, $item); |
|
618 | 618 | |
619 | - self::maybe_editing_post($post); |
|
620 | - } |
|
619 | + self::maybe_editing_post($post); |
|
620 | + } |
|
621 | 621 | |
622 | - private static function populate_postmeta( &$post, $meta, $imported ) { |
|
623 | - global $frm_duplicate_ids; |
|
622 | + private static function populate_postmeta( &$post, $meta, $imported ) { |
|
623 | + global $frm_duplicate_ids; |
|
624 | 624 | |
625 | - $m = array( |
|
625 | + $m = array( |
|
626 | 626 | 'key' => (string) $meta->meta_key, |
627 | 627 | 'value' => (string) $meta->meta_value, |
628 | 628 | ); |
629 | 629 | |
630 | 630 | //switch old form and field ids to new ones |
631 | 631 | if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) { |
632 | - $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
632 | + $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
633 | 633 | } else { |
634 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
634 | + $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
635 | 635 | |
636 | - if ( ! empty($frm_duplicate_ids) ) { |
|
636 | + if ( ! empty($frm_duplicate_ids) ) { |
|
637 | 637 | |
638 | - if ( $m['key'] == 'frm_dyncontent' ) { |
|
639 | - $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
640 | - } else if ( $m['key'] == 'frm_options' ) { |
|
638 | + if ( $m['key'] == 'frm_dyncontent' ) { |
|
639 | + $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
640 | + } else if ( $m['key'] == 'frm_options' ) { |
|
641 | 641 | |
642 | 642 | foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) { |
643 | 643 | if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) { |
644 | 644 | $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
645 | - } |
|
646 | - } |
|
647 | - |
|
648 | - $check_dup_array = array(); |
|
649 | - if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
|
650 | - if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
651 | - $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
652 | - } else if ( is_array( $m['value']['order_by'] ) ) { |
|
653 | - $check_dup_array[] = 'order_by'; |
|
654 | - } |
|
655 | - } |
|
656 | - |
|
657 | - if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { |
|
658 | - $check_dup_array[] = 'where'; |
|
659 | - } |
|
660 | - |
|
661 | - foreach ( $check_dup_array as $check_k ) { |
|
645 | + } |
|
646 | + } |
|
647 | + |
|
648 | + $check_dup_array = array(); |
|
649 | + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
|
650 | + if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
651 | + $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
652 | + } else if ( is_array( $m['value']['order_by'] ) ) { |
|
653 | + $check_dup_array[] = 'order_by'; |
|
654 | + } |
|
655 | + } |
|
656 | + |
|
657 | + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { |
|
658 | + $check_dup_array[] = 'where'; |
|
659 | + } |
|
660 | + |
|
661 | + foreach ( $check_dup_array as $check_k ) { |
|
662 | 662 | foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) { |
663 | 663 | if ( isset( $frm_duplicate_ids[ $mv ] ) ) { |
664 | 664 | $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ]; |
665 | - } |
|
666 | - unset($mk, $mv); |
|
667 | - } |
|
668 | - } |
|
669 | - } |
|
670 | - } |
|
665 | + } |
|
666 | + unset($mk, $mv); |
|
667 | + } |
|
668 | + } |
|
669 | + } |
|
670 | + } |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | if ( ! is_array($m['value']) ) { |
674 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
674 | + $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | $post['postmeta'][ (string) $meta->meta_key ] = $m['value']; |
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Add terms to post |
|
682 | - * @param array $post by reference |
|
683 | - * @param object $item The XML object data |
|
684 | - */ |
|
685 | - private static function populate_taxonomies( &$post, $item ) { |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Add terms to post |
|
682 | + * @param array $post by reference |
|
683 | + * @param object $item The XML object data |
|
684 | + */ |
|
685 | + private static function populate_taxonomies( &$post, $item ) { |
|
686 | 686 | foreach ( $item->category as $c ) { |
687 | 687 | $att = $c->attributes(); |
688 | 688 | if ( ! isset( $att['nicename'] ) ) { |
689 | - continue; |
|
690 | - } |
|
691 | - |
|
692 | - $taxonomy = (string) $att['domain']; |
|
693 | - if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
694 | - $name = (string) $att['nicename']; |
|
695 | - $h_term = get_term_by('slug', $name, $taxonomy); |
|
696 | - if ( $h_term ) { |
|
697 | - $name = $h_term->term_id; |
|
698 | - } |
|
699 | - unset($h_term); |
|
700 | - } else { |
|
701 | - $name = (string) $c; |
|
702 | - } |
|
689 | + continue; |
|
690 | + } |
|
691 | + |
|
692 | + $taxonomy = (string) $att['domain']; |
|
693 | + if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
694 | + $name = (string) $att['nicename']; |
|
695 | + $h_term = get_term_by('slug', $name, $taxonomy); |
|
696 | + if ( $h_term ) { |
|
697 | + $name = $h_term->term_id; |
|
698 | + } |
|
699 | + unset($h_term); |
|
700 | + } else { |
|
701 | + $name = (string) $c; |
|
702 | + } |
|
703 | 703 | |
704 | 704 | if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) { |
705 | 705 | $post['tax_input'][ $taxonomy ] = array(); |
706 | 706 | } |
707 | 707 | |
708 | 708 | $post['tax_input'][ $taxonomy ][] = $name; |
709 | - unset($name); |
|
709 | + unset($name); |
|
710 | 710 | } |
711 | - } |
|
711 | + } |
|
712 | 712 | |
713 | - /** |
|
714 | - * Edit post if the key and created time match |
|
715 | - */ |
|
716 | - private static function maybe_editing_post( &$post ) { |
|
713 | + /** |
|
714 | + * Edit post if the key and created time match |
|
715 | + */ |
|
716 | + private static function maybe_editing_post( &$post ) { |
|
717 | 717 | $match_by = array( |
718 | - 'post_type' => $post['post_type'], |
|
719 | - 'name' => $post['post_name'], |
|
720 | - 'post_status' => $post['post_status'], |
|
721 | - 'posts_per_page' => 1, |
|
718 | + 'post_type' => $post['post_type'], |
|
719 | + 'name' => $post['post_name'], |
|
720 | + 'post_status' => $post['post_status'], |
|
721 | + 'posts_per_page' => 1, |
|
722 | 722 | ); |
723 | 723 | |
724 | 724 | if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) { |
725 | - $match_by['include'] = $post['post_id']; |
|
726 | - unset($match_by['name']); |
|
725 | + $match_by['include'] = $post['post_id']; |
|
726 | + unset($match_by['name']); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | $editing = get_posts($match_by); |
730 | 730 | |
731 | - if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
732 | - // set the id of the post to edit |
|
733 | - $post['ID'] = current($editing)->ID; |
|
734 | - } |
|
735 | - } |
|
731 | + if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
732 | + // set the id of the post to edit |
|
733 | + $post['ID'] = current($editing)->ID; |
|
734 | + } |
|
735 | + } |
|
736 | 736 | |
737 | - private static function update_postmeta( &$post, $post_id ) { |
|
738 | - foreach ( $post['postmeta'] as $k => $v ) { |
|
739 | - if ( '_edit_last' == $k ) { |
|
740 | - $v = FrmAppHelper::get_user_id_param($v); |
|
741 | - } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
|
742 | - //change the attachment ID |
|
743 | - $v = FrmProXMLHelper::get_file_id($v); |
|
744 | - } |
|
737 | + private static function update_postmeta( &$post, $post_id ) { |
|
738 | + foreach ( $post['postmeta'] as $k => $v ) { |
|
739 | + if ( '_edit_last' == $k ) { |
|
740 | + $v = FrmAppHelper::get_user_id_param($v); |
|
741 | + } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
|
742 | + //change the attachment ID |
|
743 | + $v = FrmProXMLHelper::get_file_id($v); |
|
744 | + } |
|
745 | 745 | |
746 | - update_post_meta($post_id, $k, $v); |
|
746 | + update_post_meta($post_id, $k, $v); |
|
747 | 747 | |
748 | - unset($k, $v); |
|
749 | - } |
|
750 | - } |
|
748 | + unset($k, $v); |
|
749 | + } |
|
750 | + } |
|
751 | 751 | |
752 | 752 | private static function maybe_update_stylesheet( $imported ) { |
753 | 753 | $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] ); |
@@ -763,72 +763,72 @@ discard block |
||
763 | 763 | } |
764 | 764 | } |
765 | 765 | |
766 | - /** |
|
767 | - * @param string $message |
|
768 | - */ |
|
766 | + /** |
|
767 | + * @param string $message |
|
768 | + */ |
|
769 | 769 | public static function parse_message( $result, &$message, &$errors ) { |
770 | - if ( is_wp_error($result) ) { |
|
771 | - $errors[] = $result->get_error_message(); |
|
772 | - } else if ( ! $result ) { |
|
773 | - return; |
|
774 | - } |
|
775 | - |
|
776 | - if ( ! is_array($result) ) { |
|
777 | - $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
|
778 | - return; |
|
779 | - } |
|
780 | - |
|
781 | - $t_strings = array( |
|
782 | - 'imported' => __( 'Imported', 'formidable' ), |
|
783 | - 'updated' => __( 'Updated', 'formidable' ), |
|
784 | - ); |
|
785 | - |
|
786 | - $message = '<ul>'; |
|
787 | - foreach ( $result as $type => $results ) { |
|
770 | + if ( is_wp_error($result) ) { |
|
771 | + $errors[] = $result->get_error_message(); |
|
772 | + } else if ( ! $result ) { |
|
773 | + return; |
|
774 | + } |
|
775 | + |
|
776 | + if ( ! is_array($result) ) { |
|
777 | + $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
|
778 | + return; |
|
779 | + } |
|
780 | + |
|
781 | + $t_strings = array( |
|
782 | + 'imported' => __( 'Imported', 'formidable' ), |
|
783 | + 'updated' => __( 'Updated', 'formidable' ), |
|
784 | + ); |
|
785 | + |
|
786 | + $message = '<ul>'; |
|
787 | + foreach ( $result as $type => $results ) { |
|
788 | 788 | if ( ! isset( $t_strings[ $type ] ) ) { |
789 | - // only print imported and updated |
|
790 | - continue; |
|
791 | - } |
|
789 | + // only print imported and updated |
|
790 | + continue; |
|
791 | + } |
|
792 | 792 | |
793 | - $s_message = array(); |
|
794 | - foreach ( $results as $k => $m ) { |
|
795 | - self::item_count_message($m, $k, $s_message); |
|
796 | - unset($k, $m); |
|
797 | - } |
|
793 | + $s_message = array(); |
|
794 | + foreach ( $results as $k => $m ) { |
|
795 | + self::item_count_message($m, $k, $s_message); |
|
796 | + unset($k, $m); |
|
797 | + } |
|
798 | 798 | |
799 | - if ( ! empty($s_message) ) { |
|
799 | + if ( ! empty($s_message) ) { |
|
800 | 800 | $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> '; |
801 | - $message .= implode(', ', $s_message); |
|
802 | - $message .= '</li>'; |
|
803 | - } |
|
804 | - } |
|
805 | - |
|
806 | - if ( $message == '<ul>' ) { |
|
807 | - $message = ''; |
|
808 | - $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
|
809 | - } else { |
|
810 | - $message .= '</ul>'; |
|
811 | - } |
|
812 | - } |
|
801 | + $message .= implode(', ', $s_message); |
|
802 | + $message .= '</li>'; |
|
803 | + } |
|
804 | + } |
|
805 | + |
|
806 | + if ( $message == '<ul>' ) { |
|
807 | + $message = ''; |
|
808 | + $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
|
809 | + } else { |
|
810 | + $message .= '</ul>'; |
|
811 | + } |
|
812 | + } |
|
813 | 813 | |
814 | 814 | public static function item_count_message( $m, $type, &$s_message ) { |
815 | - if ( ! $m ) { |
|
816 | - return; |
|
817 | - } |
|
818 | - |
|
819 | - $strings = array( |
|
820 | - 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ), |
|
821 | - 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ), |
|
822 | - 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ), |
|
823 | - 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ), |
|
824 | - 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ), |
|
825 | - 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ), |
|
826 | - 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ), |
|
827 | - 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
|
828 | - ); |
|
815 | + if ( ! $m ) { |
|
816 | + return; |
|
817 | + } |
|
818 | + |
|
819 | + $strings = array( |
|
820 | + 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ), |
|
821 | + 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ), |
|
822 | + 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ), |
|
823 | + 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ), |
|
824 | + 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ), |
|
825 | + 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ), |
|
826 | + 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ), |
|
827 | + 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
|
828 | + ); |
|
829 | 829 | |
830 | 830 | $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type ); |
831 | - } |
|
831 | + } |
|
832 | 832 | |
833 | 833 | /** |
834 | 834 | * Prepare the form options for export |
@@ -859,16 +859,16 @@ discard block |
||
859 | 859 | } |
860 | 860 | |
861 | 861 | public static function cdata( $str ) { |
862 | - $str = maybe_unserialize($str); |
|
863 | - if ( is_array($str) ) { |
|
864 | - $str = json_encode($str); |
|
862 | + $str = maybe_unserialize($str); |
|
863 | + if ( is_array($str) ) { |
|
864 | + $str = json_encode($str); |
|
865 | 865 | } else if ( seems_utf8( $str ) == false ) { |
866 | 866 | $str = utf8_encode( $str ); |
867 | 867 | } |
868 | 868 | |
869 | - if ( is_numeric($str) ) { |
|
870 | - return $str; |
|
871 | - } |
|
869 | + if ( is_numeric($str) ) { |
|
870 | + return $str; |
|
871 | + } |
|
872 | 872 | |
873 | 873 | self::remove_invalid_characters_from_xml( $str ); |
874 | 874 | |
@@ -889,58 +889,58 @@ discard block |
||
889 | 889 | $str = str_replace( '\x1F', '', $str ); |
890 | 890 | } |
891 | 891 | |
892 | - public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) { |
|
893 | - // Get post type |
|
894 | - $post_type = FrmFormActionsController::$action_post_type; |
|
895 | - |
|
896 | - // Set up imported index, if not set up yet |
|
897 | - if ( ! isset( $imported['imported']['actions'] ) ) { |
|
898 | - $imported['imported']['actions'] = 0; |
|
899 | - } |
|
900 | - |
|
901 | - // Migrate post settings to action |
|
902 | - self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
903 | - |
|
904 | - // Migrate email settings to action |
|
905 | - self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * Migrate post settings to form action |
|
910 | - * |
|
911 | - * @param string $post_type |
|
912 | - */ |
|
913 | - private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
914 | - if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
915 | - return; |
|
916 | - } |
|
917 | - |
|
918 | - $new_action = array( |
|
919 | - 'post_type' => $post_type, |
|
920 | - 'post_excerpt' => 'wppost', |
|
892 | + public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) { |
|
893 | + // Get post type |
|
894 | + $post_type = FrmFormActionsController::$action_post_type; |
|
895 | + |
|
896 | + // Set up imported index, if not set up yet |
|
897 | + if ( ! isset( $imported['imported']['actions'] ) ) { |
|
898 | + $imported['imported']['actions'] = 0; |
|
899 | + } |
|
900 | + |
|
901 | + // Migrate post settings to action |
|
902 | + self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
903 | + |
|
904 | + // Migrate email settings to action |
|
905 | + self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * Migrate post settings to form action |
|
910 | + * |
|
911 | + * @param string $post_type |
|
912 | + */ |
|
913 | + private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
914 | + if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
915 | + return; |
|
916 | + } |
|
917 | + |
|
918 | + $new_action = array( |
|
919 | + 'post_type' => $post_type, |
|
920 | + 'post_excerpt' => 'wppost', |
|
921 | 921 | 'post_title' => __( 'Create Posts', 'formidable' ), |
922 | - 'menu_order' => $form_id, |
|
923 | - 'post_status' => 'publish', |
|
924 | - 'post_content' => array(), |
|
922 | + 'menu_order' => $form_id, |
|
923 | + 'post_status' => 'publish', |
|
924 | + 'post_content' => array(), |
|
925 | 925 | 'post_name' => $form_id . '_wppost_1', |
926 | - ); |
|
926 | + ); |
|
927 | 927 | |
928 | - $post_settings = array( |
|
929 | - 'post_type', 'post_category', 'post_content', |
|
930 | - 'post_excerpt', 'post_title', 'post_name', 'post_date', |
|
928 | + $post_settings = array( |
|
929 | + 'post_type', 'post_category', 'post_content', |
|
930 | + 'post_excerpt', 'post_title', 'post_name', 'post_date', |
|
931 | 931 | 'post_status', 'post_custom_fields', 'post_password', |
932 | - ); |
|
932 | + ); |
|
933 | 933 | |
934 | - foreach ( $post_settings as $post_setting ) { |
|
934 | + foreach ( $post_settings as $post_setting ) { |
|
935 | 935 | if ( isset( $form_options[ $post_setting ] ) ) { |
936 | 936 | $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ]; |
937 | - } |
|
938 | - unset($post_setting); |
|
939 | - } |
|
937 | + } |
|
938 | + unset($post_setting); |
|
939 | + } |
|
940 | 940 | |
941 | 941 | $new_action['event'] = array( 'create', 'update' ); |
942 | 942 | |
943 | - if ( $switch ) { |
|
943 | + if ( $switch ) { |
|
944 | 944 | // Fields with string or int saved |
945 | 945 | $basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' ); |
946 | 946 | |
@@ -948,22 +948,22 @@ discard block |
||
948 | 948 | $array_fields = array( 'post_category', 'post_custom_fields' ); |
949 | 949 | |
950 | 950 | $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields ); |
951 | - } |
|
952 | - $new_action['post_content'] = json_encode($new_action['post_content']); |
|
951 | + } |
|
952 | + $new_action['post_content'] = json_encode($new_action['post_content']); |
|
953 | 953 | |
954 | - $exists = get_posts( array( |
|
955 | - 'name' => $new_action['post_name'], |
|
956 | - 'post_type' => $new_action['post_type'], |
|
957 | - 'post_status' => $new_action['post_status'], |
|
958 | - 'numberposts' => 1, |
|
959 | - ) ); |
|
954 | + $exists = get_posts( array( |
|
955 | + 'name' => $new_action['post_name'], |
|
956 | + 'post_type' => $new_action['post_type'], |
|
957 | + 'post_status' => $new_action['post_status'], |
|
958 | + 'numberposts' => 1, |
|
959 | + ) ); |
|
960 | 960 | |
961 | - if ( ! $exists ) { |
|
961 | + if ( ! $exists ) { |
|
962 | 962 | // this isn't an email, but we need to use a class that will always be included |
963 | 963 | FrmAppHelper::save_json_post( $new_action ); |
964 | - $imported['imported']['actions']++; |
|
965 | - } |
|
966 | - } |
|
964 | + $imported['imported']['actions']++; |
|
965 | + } |
|
966 | + } |
|
967 | 967 | |
968 | 968 | /** |
969 | 969 | * Switch old field IDs for new field IDs in emails and post |
@@ -976,211 +976,211 @@ discard block |
||
976 | 976 | * @return string $post_content - new field IDs |
977 | 977 | */ |
978 | 978 | private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) { |
979 | - global $frm_duplicate_ids; |
|
979 | + global $frm_duplicate_ids; |
|
980 | 980 | |
981 | - // If there aren't IDs that were switched, end now |
|
982 | - if ( ! $frm_duplicate_ids ) { |
|
983 | - return; |
|
984 | - } |
|
981 | + // If there aren't IDs that were switched, end now |
|
982 | + if ( ! $frm_duplicate_ids ) { |
|
983 | + return; |
|
984 | + } |
|
985 | 985 | |
986 | - // Get old IDs |
|
987 | - $old = array_keys( $frm_duplicate_ids ); |
|
986 | + // Get old IDs |
|
987 | + $old = array_keys( $frm_duplicate_ids ); |
|
988 | 988 | |
989 | - // Get new IDs |
|
990 | - $new = array_values( $frm_duplicate_ids ); |
|
989 | + // Get new IDs |
|
990 | + $new = array_values( $frm_duplicate_ids ); |
|
991 | 991 | |
992 | - // Do a str_replace with each item to set the new IDs |
|
993 | - foreach ( $post_content as $key => $setting ) { |
|
994 | - if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
|
995 | - // Replace old IDs with new IDs |
|
992 | + // Do a str_replace with each item to set the new IDs |
|
993 | + foreach ( $post_content as $key => $setting ) { |
|
994 | + if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
|
995 | + // Replace old IDs with new IDs |
|
996 | 996 | $post_content[ $key ] = str_replace( $old, $new, $setting ); |
997 | - } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
|
998 | - foreach ( $setting as $k => $val ) { |
|
999 | - // Replace old IDs with new IDs |
|
997 | + } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
|
998 | + foreach ( $setting as $k => $val ) { |
|
999 | + // Replace old IDs with new IDs |
|
1000 | 1000 | $post_content[ $key ][ $k ] = str_replace( $old, $new, $val ); |
1001 | - } |
|
1002 | - } |
|
1003 | - unset( $key, $setting ); |
|
1004 | - } |
|
1005 | - return $post_content; |
|
1006 | - } |
|
1007 | - |
|
1008 | - private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
1009 | - // No old notifications or autoresponders to carry over |
|
1001 | + } |
|
1002 | + } |
|
1003 | + unset( $key, $setting ); |
|
1004 | + } |
|
1005 | + return $post_content; |
|
1006 | + } |
|
1007 | + |
|
1008 | + private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
1009 | + // No old notifications or autoresponders to carry over |
|
1010 | 1010 | if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) { |
1011 | - return; |
|
1012 | - } |
|
1011 | + return; |
|
1012 | + } |
|
1013 | 1013 | |
1014 | - // Initialize notifications array |
|
1015 | - $notifications = array(); |
|
1014 | + // Initialize notifications array |
|
1015 | + $notifications = array(); |
|
1016 | 1016 | |
1017 | - // Migrate regular notifications |
|
1018 | - self::migrate_notifications_to_action( $form_options, $form_id, $notifications ); |
|
1017 | + // Migrate regular notifications |
|
1018 | + self::migrate_notifications_to_action( $form_options, $form_id, $notifications ); |
|
1019 | 1019 | |
1020 | - // Migrate autoresponders |
|
1021 | - self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
|
1020 | + // Migrate autoresponders |
|
1021 | + self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
|
1022 | 1022 | |
1023 | - if ( empty( $notifications ) ) { |
|
1024 | - return; |
|
1025 | - } |
|
1023 | + if ( empty( $notifications ) ) { |
|
1024 | + return; |
|
1025 | + } |
|
1026 | 1026 | |
1027 | - foreach ( $notifications as $new_notification ) { |
|
1028 | - $new_notification['post_type'] = $post_type; |
|
1029 | - $new_notification['post_excerpt'] = 'email'; |
|
1027 | + foreach ( $notifications as $new_notification ) { |
|
1028 | + $new_notification['post_type'] = $post_type; |
|
1029 | + $new_notification['post_excerpt'] = 'email'; |
|
1030 | 1030 | $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
1031 | - $new_notification['menu_order'] = $form_id; |
|
1032 | - $new_notification['post_status'] = 'publish'; |
|
1031 | + $new_notification['menu_order'] = $form_id; |
|
1032 | + $new_notification['post_status'] = 'publish'; |
|
1033 | 1033 | |
1034 | - // Switch field IDs and keys, if needed |
|
1035 | - if ( $switch ) { |
|
1034 | + // Switch field IDs and keys, if needed |
|
1035 | + if ( $switch ) { |
|
1036 | 1036 | |
1037 | 1037 | // Switch field IDs in email conditional logic |
1038 | 1038 | self::switch_email_contition_field_ids( $new_notification['post_content'] ); |
1039 | 1039 | |
1040 | 1040 | // Switch all other field IDs in email |
1041 | - $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
|
1042 | - } |
|
1043 | - $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
1044 | - |
|
1045 | - $exists = get_posts( array( |
|
1046 | - 'name' => $new_notification['post_name'], |
|
1047 | - 'post_type' => $new_notification['post_type'], |
|
1048 | - 'post_status' => $new_notification['post_status'], |
|
1049 | - 'numberposts' => 1, |
|
1050 | - ) ); |
|
1051 | - |
|
1052 | - if ( empty($exists) ) { |
|
1041 | + $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
|
1042 | + } |
|
1043 | + $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
1044 | + |
|
1045 | + $exists = get_posts( array( |
|
1046 | + 'name' => $new_notification['post_name'], |
|
1047 | + 'post_type' => $new_notification['post_type'], |
|
1048 | + 'post_status' => $new_notification['post_status'], |
|
1049 | + 'numberposts' => 1, |
|
1050 | + ) ); |
|
1051 | + |
|
1052 | + if ( empty($exists) ) { |
|
1053 | 1053 | FrmAppHelper::save_json_post( $new_notification ); |
1054 | - $imported['imported']['actions']++; |
|
1055 | - } |
|
1056 | - unset($new_notification); |
|
1057 | - } |
|
1058 | - } |
|
1059 | - |
|
1060 | - private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
|
1061 | - if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { |
|
1062 | - // add old settings into notification array |
|
1054 | + $imported['imported']['actions']++; |
|
1055 | + } |
|
1056 | + unset($new_notification); |
|
1057 | + } |
|
1058 | + } |
|
1059 | + |
|
1060 | + private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
|
1061 | + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { |
|
1062 | + // add old settings into notification array |
|
1063 | 1063 | $form_options['notification'] = array( 0 => $form_options ); |
1064 | - } else if ( isset( $form_options['notification']['email_to'] ) ) { |
|
1065 | - // make sure it's in the correct format |
|
1064 | + } else if ( isset( $form_options['notification']['email_to'] ) ) { |
|
1065 | + // make sure it's in the correct format |
|
1066 | 1066 | $form_options['notification'] = array( 0 => $form_options['notification'] ); |
1067 | - } |
|
1067 | + } |
|
1068 | 1068 | |
1069 | - if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
1070 | - foreach ( $form_options['notification'] as $email_key => $notification ) { |
|
1069 | + if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
1070 | + foreach ( $form_options['notification'] as $email_key => $notification ) { |
|
1071 | 1071 | |
1072 | - $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
|
1072 | + $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
|
1073 | 1073 | |
1074 | - // Format the email data |
|
1075 | - self::format_email_data( $atts, $notification ); |
|
1074 | + // Format the email data |
|
1075 | + self::format_email_data( $atts, $notification ); |
|
1076 | 1076 | |
1077 | 1077 | if ( isset( $notification['twilio'] ) && $notification['twilio'] ) { |
1078 | 1078 | do_action( 'frm_create_twilio_action', $atts, $notification ); |
1079 | 1079 | } |
1080 | 1080 | |
1081 | - // Setup the new notification |
|
1082 | - $new_notification = array(); |
|
1083 | - self::setup_new_notification( $new_notification, $notification, $atts ); |
|
1081 | + // Setup the new notification |
|
1082 | + $new_notification = array(); |
|
1083 | + self::setup_new_notification( $new_notification, $notification, $atts ); |
|
1084 | 1084 | |
1085 | - $notifications[] = $new_notification; |
|
1086 | - } |
|
1087 | - } |
|
1088 | - } |
|
1085 | + $notifications[] = $new_notification; |
|
1086 | + } |
|
1087 | + } |
|
1088 | + } |
|
1089 | 1089 | |
1090 | - private static function format_email_data( &$atts, $notification ) { |
|
1091 | - // Format email_to |
|
1092 | - self::format_email_to_data( $atts, $notification ); |
|
1090 | + private static function format_email_data( &$atts, $notification ) { |
|
1091 | + // Format email_to |
|
1092 | + self::format_email_to_data( $atts, $notification ); |
|
1093 | 1093 | |
1094 | - // Format the reply to email and name |
|
1095 | - $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
|
1096 | - foreach ( $reply_fields as $f => $val ) { |
|
1094 | + // Format the reply to email and name |
|
1095 | + $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
|
1096 | + foreach ( $reply_fields as $f => $val ) { |
|
1097 | 1097 | if ( isset( $notification[ $f ] ) ) { |
1098 | 1098 | $atts[ $f ] = $notification[ $f ]; |
1099 | 1099 | if ( 'custom' == $notification[ $f ] ) { |
1100 | 1100 | $atts[ $f ] = $notification[ 'cust_' . $f ]; |
1101 | 1101 | } else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) { |
1102 | 1102 | $atts[ $f ] = '[' . $atts[ $f ] . ']'; |
1103 | - } |
|
1104 | - } |
|
1105 | - unset( $f, $val ); |
|
1106 | - } |
|
1103 | + } |
|
1104 | + } |
|
1105 | + unset( $f, $val ); |
|
1106 | + } |
|
1107 | 1107 | |
1108 | - // Format event |
|
1108 | + // Format event |
|
1109 | 1109 | $atts['event'] = array( 'create' ); |
1110 | - if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
|
1111 | - $atts['event'][] = 'update'; |
|
1112 | - } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
1110 | + if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
|
1111 | + $atts['event'][] = 'update'; |
|
1112 | + } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
1113 | 1113 | $atts['event'] = array( 'update' ); |
1114 | - } |
|
1115 | - } |
|
1114 | + } |
|
1115 | + } |
|
1116 | 1116 | |
1117 | - private static function format_email_to_data( &$atts, $notification ) { |
|
1118 | - if ( isset( $notification['email_to'] ) ) { |
|
1117 | + private static function format_email_to_data( &$atts, $notification ) { |
|
1118 | + if ( isset( $notification['email_to'] ) ) { |
|
1119 | 1119 | $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] ); |
1120 | - } else { |
|
1121 | - $atts['email_to'] = array(); |
|
1122 | - } |
|
1120 | + } else { |
|
1121 | + $atts['email_to'] = array(); |
|
1122 | + } |
|
1123 | 1123 | |
1124 | - if ( isset( $notification['also_email_to'] ) ) { |
|
1125 | - $email_fields = (array) $notification['also_email_to']; |
|
1126 | - $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] ); |
|
1127 | - unset( $email_fields ); |
|
1128 | - } |
|
1124 | + if ( isset( $notification['also_email_to'] ) ) { |
|
1125 | + $email_fields = (array) $notification['also_email_to']; |
|
1126 | + $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] ); |
|
1127 | + unset( $email_fields ); |
|
1128 | + } |
|
1129 | 1129 | |
1130 | - foreach ( $atts['email_to'] as $key => $email_field ) { |
|
1130 | + foreach ( $atts['email_to'] as $key => $email_field ) { |
|
1131 | 1131 | |
1132 | - if ( is_numeric( $email_field ) ) { |
|
1132 | + if ( is_numeric( $email_field ) ) { |
|
1133 | 1133 | $atts['email_to'][ $key ] = '[' . $email_field . ']'; |
1134 | - } |
|
1134 | + } |
|
1135 | 1135 | |
1136 | - if ( strpos( $email_field, '|') ) { |
|
1137 | - $email_opt = explode( '|', $email_field ); |
|
1138 | - if ( isset( $email_opt[0] ) ) { |
|
1136 | + if ( strpos( $email_field, '|') ) { |
|
1137 | + $email_opt = explode( '|', $email_field ); |
|
1138 | + if ( isset( $email_opt[0] ) ) { |
|
1139 | 1139 | $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
1140 | - } |
|
1141 | - unset( $email_opt ); |
|
1142 | - } |
|
1143 | - } |
|
1144 | - $atts['email_to'] = implode(', ', $atts['email_to']); |
|
1145 | - } |
|
1146 | - |
|
1147 | - private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
|
1148 | - // Set up new notification |
|
1149 | - $new_notification = array( |
|
1150 | - 'post_content' => array( |
|
1151 | - 'email_to' => $atts['email_to'], |
|
1152 | - 'event' => $atts['event'], |
|
1153 | - ), |
|
1140 | + } |
|
1141 | + unset( $email_opt ); |
|
1142 | + } |
|
1143 | + } |
|
1144 | + $atts['email_to'] = implode(', ', $atts['email_to']); |
|
1145 | + } |
|
1146 | + |
|
1147 | + private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
|
1148 | + // Set up new notification |
|
1149 | + $new_notification = array( |
|
1150 | + 'post_content' => array( |
|
1151 | + 'email_to' => $atts['email_to'], |
|
1152 | + 'event' => $atts['event'], |
|
1153 | + ), |
|
1154 | 1154 | 'post_name' => $atts['form_id'] . '_email_' . $atts['email_key'], |
1155 | - ); |
|
1155 | + ); |
|
1156 | 1156 | |
1157 | - // Add more fields to the new notification |
|
1158 | - $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
|
1159 | - foreach ( $add_fields as $add_field ) { |
|
1157 | + // Add more fields to the new notification |
|
1158 | + $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
|
1159 | + foreach ( $add_fields as $add_field ) { |
|
1160 | 1160 | if ( isset( $notification[ $add_field ] ) ) { |
1161 | 1161 | $new_notification['post_content'][ $add_field ] = $notification[ $add_field ]; |
1162 | - } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
|
1162 | + } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
|
1163 | 1163 | $new_notification['post_content'][ $add_field ] = 0; |
1164 | - } else { |
|
1164 | + } else { |
|
1165 | 1165 | $new_notification['post_content'][ $add_field ] = ''; |
1166 | - } |
|
1167 | - unset( $add_field ); |
|
1168 | - } |
|
1166 | + } |
|
1167 | + unset( $add_field ); |
|
1168 | + } |
|
1169 | 1169 | |
1170 | 1170 | // Set reply to |
1171 | 1171 | $new_notification['post_content']['reply_to'] = $atts['reply_to']; |
1172 | 1172 | |
1173 | - // Set from |
|
1173 | + // Set from |
|
1174 | 1174 | if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) { |
1175 | 1175 | $new_notification['post_content']['from'] = ( empty( $atts['reply_to_name'] ) ? '[sitename]' : $atts['reply_to_name'] ) . ' <' . ( empty( $atts['reply_to'] ) ? '[admin_email]' : $atts['reply_to'] ) . '>'; |
1176 | - } |
|
1177 | - } |
|
1176 | + } |
|
1177 | + } |
|
1178 | 1178 | |
1179 | 1179 | /** |
1180 | - * Switch field IDs in pre-2.0 email conditional logic |
|
1181 | - * |
|
1182 | - * @param $post_content array, pass by reference |
|
1183 | - */ |
|
1180 | + * Switch field IDs in pre-2.0 email conditional logic |
|
1181 | + * |
|
1182 | + * @param $post_content array, pass by reference |
|
1183 | + */ |
|
1184 | 1184 | private static function switch_email_contition_field_ids( &$post_content ) { |
1185 | 1185 | // Switch field IDs in conditional logic |
1186 | 1186 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
@@ -1193,36 +1193,36 @@ discard block |
||
1193 | 1193 | } |
1194 | 1194 | } |
1195 | 1195 | |
1196 | - private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
|
1197 | - if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
1198 | - // migrate autoresponder |
|
1199 | - |
|
1200 | - $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
1201 | - if ( strpos($email_field, '|') ) { |
|
1202 | - // data from entries field |
|
1203 | - $email_field = explode('|', $email_field); |
|
1204 | - if ( isset($email_field[1]) ) { |
|
1205 | - $email_field = $email_field[1]; |
|
1206 | - } |
|
1207 | - } |
|
1208 | - if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
1196 | + private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
|
1197 | + if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
1198 | + // migrate autoresponder |
|
1199 | + |
|
1200 | + $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
1201 | + if ( strpos($email_field, '|') ) { |
|
1202 | + // data from entries field |
|
1203 | + $email_field = explode('|', $email_field); |
|
1204 | + if ( isset($email_field[1]) ) { |
|
1205 | + $email_field = $email_field[1]; |
|
1206 | + } |
|
1207 | + } |
|
1208 | + if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
1209 | 1209 | $email_field = '[' . $email_field . ']'; |
1210 | - } |
|
1211 | - |
|
1212 | - $notification = $form_options; |
|
1213 | - $new_notification2 = array( |
|
1214 | - 'post_content' => array( |
|
1215 | - 'email_message' => $notification['ar_email_message'], |
|
1216 | - 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
1217 | - 'email_to' => $email_field, |
|
1218 | - 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
1219 | - 'inc_user_info' => 0, |
|
1220 | - ), |
|
1210 | + } |
|
1211 | + |
|
1212 | + $notification = $form_options; |
|
1213 | + $new_notification2 = array( |
|
1214 | + 'post_content' => array( |
|
1215 | + 'email_message' => $notification['ar_email_message'], |
|
1216 | + 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
1217 | + 'email_to' => $email_field, |
|
1218 | + 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
1219 | + 'inc_user_info' => 0, |
|
1220 | + ), |
|
1221 | 1221 | 'post_name' => $form_id . '_email_' . count( $notifications ), |
1222 | - ); |
|
1222 | + ); |
|
1223 | 1223 | |
1224 | - $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
1225 | - $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
1224 | + $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
1225 | + $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
1226 | 1226 | |
1227 | 1227 | if ( ! empty( $reply_to ) ) { |
1228 | 1228 | $new_notification2['post_content']['reply_to'] = $reply_to; |
@@ -1232,9 +1232,9 @@ discard block |
||
1232 | 1232 | $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>'; |
1233 | 1233 | } |
1234 | 1234 | |
1235 | - $notifications[] = $new_notification2; |
|
1236 | - unset( $new_notification2 ); |
|
1237 | - } |
|
1238 | - } |
|
1235 | + $notifications[] = $new_notification2; |
|
1236 | + unset( $new_notification2 ); |
|
1237 | + } |
|
1238 | + } |
|
1239 | 1239 | } |
1240 | 1240 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | 'terms' => array(), |
37 | 37 | ); |
38 | 38 | |
39 | - unset($defaults); |
|
39 | + unset( $defaults ); |
|
40 | 40 | |
41 | 41 | if ( ! defined( 'WP_IMPORTING' ) ) { |
42 | - define('WP_IMPORTING', true); |
|
42 | + define( 'WP_IMPORTING', true ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | if ( ! class_exists( 'DOMDocument' ) ) { |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() ); |
53 | 53 | } |
54 | 54 | |
55 | - if ( ! function_exists('simplexml_import_dom') ) { |
|
55 | + if ( ! function_exists( 'simplexml_import_dom' ) ) { |
|
56 | 56 | return new WP_Error( 'SimpleXML_parse_error', __( 'Your server is missing the simplexml_import_dom function', 'formidable' ), libxml_get_errors() ); |
57 | 57 | } |
58 | 58 | |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order |
68 | 68 | foreach ( array( 'term', 'form', 'view' ) as $item_type ) { |
69 | 69 | // grab cats, tags, and terms, or forms or posts |
70 | - if ( isset($xml->{$item_type} ) ) { |
|
70 | + if ( isset( $xml->{$item_type} ) ) { |
|
71 | 71 | $function_name = 'import_xml_' . $item_type . 's'; |
72 | 72 | $imported = self::$function_name( $xml->{$item_type}, $imported ); |
73 | 73 | unset( $function_name, $xml->{$item_type} ); |
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - $return = apply_filters('frm_importing_xml', $imported, $xml ); |
|
77 | + $return = apply_filters( 'frm_importing_xml', $imported, $xml ); |
|
78 | 78 | |
79 | 79 | return $return; |
80 | 80 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | 'slug' => (string) $t->term_slug, |
92 | 92 | 'description' => (string) $t->term_description, |
93 | 93 | 'parent' => empty( $parent ) ? 0 : $parent, |
94 | - )); |
|
94 | + ) ); |
|
95 | 95 | |
96 | 96 | if ( $term && is_array( $term ) ) { |
97 | - $imported['imported']['terms']++; |
|
98 | - $imported['terms'][ (int) $t->term_id ] = $term['term_id']; |
|
97 | + $imported['imported']['terms'] ++; |
|
98 | + $imported['terms'][(int) $t->term_id] = $term['term_id']; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | unset( $term, $t ); |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | } else { |
143 | 143 | $form_id = FrmForm::create( $form ); |
144 | 144 | if ( $form_id ) { |
145 | - $imported['imported']['forms']++; |
|
145 | + $imported['imported']['forms'] ++; |
|
146 | 146 | // Keep track of whether this specific form was updated or not |
147 | - $imported['form_status'][ $form_id ] = 'imported'; |
|
147 | + $imported['form_status'][$form_id] = 'imported'; |
|
148 | 148 | self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms ); |
149 | 149 | } |
150 | 150 | } |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | // Update field ids/keys to new ones |
157 | 157 | do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) ); |
158 | 158 | |
159 | - $imported['forms'][ (int) $item->id ] = $form_id; |
|
159 | + $imported['forms'][(int) $item->id] = $form_id; |
|
160 | 160 | |
161 | 161 | // Send pre 2.0 form options through function that creates actions |
162 | 162 | self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
163 | 163 | |
164 | 164 | do_action( 'frm_after_import_form', $form_id, $form ); |
165 | 165 | |
166 | - unset($form, $item); |
|
166 | + unset( $form, $item ); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms ); |
@@ -205,18 +205,18 @@ discard block |
||
205 | 205 | private static function update_form( $this_form, $form, &$imported ) { |
206 | 206 | $form_id = $this_form->id; |
207 | 207 | FrmForm::update( $form_id, $form ); |
208 | - $imported['updated']['forms']++; |
|
208 | + $imported['updated']['forms'] ++; |
|
209 | 209 | // Keep track of whether this specific form was updated or not |
210 | - $imported['form_status'][ $form_id ] = 'updated'; |
|
210 | + $imported['form_status'][$form_id] = 'updated'; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | private static function get_form_fields( $form_id ) { |
214 | 214 | $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' ); |
215 | 215 | $old_fields = array(); |
216 | 216 | foreach ( $form_fields as $f ) { |
217 | - $old_fields[ $f->id ] = $f; |
|
218 | - $old_fields[ $f->field_key ] = $f->id; |
|
219 | - unset($f); |
|
217 | + $old_fields[$f->id] = $f; |
|
218 | + $old_fields[$f->field_key] = $f->id; |
|
219 | + unset( $f ); |
|
220 | 220 | } |
221 | 221 | $form_fields = $old_fields; |
222 | 222 | return $form_fields; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $regular_forms = array(); |
248 | 248 | |
249 | 249 | foreach ( $forms as $form ) { |
250 | - $parent_form_id = isset( $form->parent_form_id) ? (int) $form->parent_form_id : 0; |
|
250 | + $parent_form_id = isset( $form->parent_form_id ) ? (int) $form->parent_form_id : 0; |
|
251 | 251 | |
252 | 252 | if ( $parent_form_id ) { |
253 | 253 | $child_forms[] = $form; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | */ |
270 | 270 | private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) { |
271 | 271 | if ( $parent_form_id ) { |
272 | - $child_forms[ $form_id ] = $parent_form_id; |
|
272 | + $child_forms[$form_id] = $parent_form_id; |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) { |
285 | 285 | foreach ( $child_forms as $child_form_id => $old_parent_form_id ) { |
286 | 286 | |
287 | - if ( isset( $imported_forms[ $old_parent_form_id ] ) && $imported_forms[ $old_parent_form_id ] != $old_parent_form_id ) { |
|
287 | + if ( isset( $imported_forms[$old_parent_form_id] ) && $imported_forms[$old_parent_form_id] != $old_parent_form_id ) { |
|
288 | 288 | // Update all children with this old parent_form_id |
289 | - $new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ]; |
|
289 | + $new_parent_form_id = (int) $imported_forms[$old_parent_form_id]; |
|
290 | 290 | |
291 | 291 | FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) ); |
292 | 292 | } |
@@ -305,15 +305,15 @@ discard block |
||
305 | 305 | foreach ( $xml_fields as $field ) { |
306 | 306 | $f = self::fill_field( $field, $form_id ); |
307 | 307 | |
308 | - if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
308 | + if ( is_array( $f['default_value'] ) && in_array( $f['type'], array( |
|
309 | 309 | 'text', 'email', 'url', 'textarea', |
310 | - 'number','phone', 'date', 'time', |
|
310 | + 'number', 'phone', 'date', 'time', |
|
311 | 311 | 'hidden', 'password', 'tag', 'image', |
312 | - )) ) { |
|
313 | - if ( count($f['default_value']) === 1 ) { |
|
312 | + ) ) ) { |
|
313 | + if ( count( $f['default_value'] ) === 1 ) { |
|
314 | 314 | $f['default_value'] = '[' . reset( $f['default_value'] ) . ']'; |
315 | 315 | } else { |
316 | - $f['default_value'] = reset($f['default_value']); |
|
316 | + $f['default_value'] = reset( $f['default_value'] ); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
@@ -321,27 +321,27 @@ discard block |
||
321 | 321 | self::maybe_update_form_select( $f, $imported ); |
322 | 322 | self::maybe_update_get_values_form_setting( $imported, $f ); |
323 | 323 | |
324 | - if ( ! empty($this_form) ) { |
|
324 | + if ( ! empty( $this_form ) ) { |
|
325 | 325 | // check for field to edit by field id |
326 | - if ( isset( $form_fields[ $f['id'] ] ) ) { |
|
326 | + if ( isset( $form_fields[$f['id']] ) ) { |
|
327 | 327 | FrmField::update( $f['id'], $f ); |
328 | - $imported['updated']['fields']++; |
|
328 | + $imported['updated']['fields'] ++; |
|
329 | 329 | |
330 | - unset( $form_fields[ $f['id'] ] ); |
|
330 | + unset( $form_fields[$f['id']] ); |
|
331 | 331 | |
332 | 332 | //unset old field key |
333 | - if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
|
334 | - unset( $form_fields[ $f['field_key'] ] ); |
|
333 | + if ( isset( $form_fields[$f['field_key']] ) ) { |
|
334 | + unset( $form_fields[$f['field_key']] ); |
|
335 | 335 | } |
336 | - } else if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
|
336 | + } else if ( isset( $form_fields[$f['field_key']] ) ) { |
|
337 | 337 | // check for field to edit by field key |
338 | - unset($f['id']); |
|
338 | + unset( $f['id'] ); |
|
339 | 339 | |
340 | - FrmField::update( $form_fields[ $f['field_key'] ], $f ); |
|
341 | - $imported['updated']['fields']++; |
|
340 | + FrmField::update( $form_fields[$f['field_key']], $f ); |
|
341 | + $imported['updated']['fields'] ++; |
|
342 | 342 | |
343 | - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id |
|
344 | - unset( $form_fields[ $f['field_key'] ] ); //unset old field key |
|
343 | + unset( $form_fields[$form_fields[$f['field_key']]] ); //unset old field id |
|
344 | + unset( $form_fields[$f['field_key']] ); //unset old field key |
|
345 | 345 | } else { |
346 | 346 | // if no matching field id or key in this form, create the field |
347 | 347 | self::create_imported_field( $f, $imported ); |
@@ -360,11 +360,11 @@ discard block |
||
360 | 360 | 'name' => (string) $field->name, |
361 | 361 | 'description' => (string) $field->description, |
362 | 362 | 'type' => (string) $field->type, |
363 | - 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value), |
|
363 | + 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value ), |
|
364 | 364 | 'field_order' => (int) $field->field_order, |
365 | 365 | 'form_id' => (int) $form_id, |
366 | 366 | 'required' => (int) $field->required, |
367 | - 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options), |
|
367 | + 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options ), |
|
368 | 368 | 'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ), |
369 | 369 | ); |
370 | 370 | } |
@@ -408,8 +408,8 @@ discard block |
||
408 | 408 | if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) { |
409 | 409 | if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) { |
410 | 410 | $form_select = $f['field_options']['form_select']; |
411 | - if ( isset( $imported['forms'][ $form_select ] ) ) { |
|
412 | - $f['field_options']['form_select'] = $imported['forms'][ $form_select ]; |
|
411 | + if ( isset( $imported['forms'][$form_select] ) ) { |
|
412 | + $f['field_options']['form_select'] = $imported['forms'][$form_select]; |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | } |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | |
430 | 430 | if ( FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) { |
431 | 431 | $old_form = $f['field_options']['get_values_form']; |
432 | - if ( isset( $imported['forms'][ $old_form ] ) ) { |
|
433 | - $f['field_options']['get_values_form'] = $imported['forms'][ $old_form ]; |
|
432 | + if ( isset( $imported['forms'][$old_form] ) ) { |
|
433 | + $f['field_options']['get_values_form'] = $imported['forms'][$old_form]; |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | private static function create_imported_field( $f, &$imported ) { |
446 | 446 | $new_id = FrmField::create( $f ); |
447 | 447 | if ( $new_id != false ) { |
448 | - $imported['imported']['fields']++; |
|
448 | + $imported['imported']['fields'] ++; |
|
449 | 449 | do_action( 'frm_after_field_is_imported', $f, $new_id ); |
450 | 450 | } |
451 | 451 | } |
@@ -544,9 +544,9 @@ discard block |
||
544 | 544 | ); |
545 | 545 | |
546 | 546 | $old_id = $post['post_id']; |
547 | - self::populate_post($post, $item, $imported); |
|
547 | + self::populate_post( $post, $item, $imported ); |
|
548 | 548 | |
549 | - unset($item); |
|
549 | + unset( $item ); |
|
550 | 550 | |
551 | 551 | $post_id = false; |
552 | 552 | if ( $post['post_type'] == $form_action_type ) { |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | if ( $action_control && is_object( $action_control ) ) { |
555 | 555 | $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] ); |
556 | 556 | } |
557 | - unset($action_control); |
|
557 | + unset( $action_control ); |
|
558 | 558 | } else if ( $post['post_type'] == 'frm_styles' ) { |
559 | 559 | // Properly encode post content before inserting the post |
560 | 560 | $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
@@ -567,26 +567,26 @@ discard block |
||
567 | 567 | $post_id = wp_insert_post( $post ); |
568 | 568 | } |
569 | 569 | |
570 | - if ( ! is_numeric($post_id) ) { |
|
570 | + if ( ! is_numeric( $post_id ) ) { |
|
571 | 571 | continue; |
572 | 572 | } |
573 | 573 | |
574 | - self::update_postmeta($post, $post_id); |
|
574 | + self::update_postmeta( $post, $post_id ); |
|
575 | 575 | |
576 | 576 | $this_type = 'posts'; |
577 | - if ( isset( $post_types[ $post['post_type'] ] ) ) { |
|
578 | - $this_type = $post_types[ $post['post_type'] ]; |
|
577 | + if ( isset( $post_types[$post['post_type']] ) ) { |
|
578 | + $this_type = $post_types[$post['post_type']]; |
|
579 | 579 | } |
580 | 580 | |
581 | - if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
582 | - $imported['updated'][ $this_type ]++; |
|
581 | + if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) { |
|
582 | + $imported['updated'][$this_type] ++; |
|
583 | 583 | } else { |
584 | - $imported['imported'][ $this_type ]++; |
|
584 | + $imported['imported'][$this_type] ++; |
|
585 | 585 | } |
586 | 586 | |
587 | - unset($post); |
|
587 | + unset( $post ); |
|
588 | 588 | |
589 | - $imported['posts'][ (int) $old_id ] = $post_id; |
|
589 | + $imported['posts'][(int) $old_id] = $post_id; |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | self::maybe_update_stylesheet( $imported ); |
@@ -595,13 +595,13 @@ discard block |
||
595 | 595 | } |
596 | 596 | |
597 | 597 | private static function populate_post( &$post, $item, $imported ) { |
598 | - if ( isset($item->attachment_url) ) { |
|
598 | + if ( isset( $item->attachment_url ) ) { |
|
599 | 599 | $post['attachment_url'] = (string) $item->attachment_url; |
600 | 600 | } |
601 | 601 | |
602 | - if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) { |
|
602 | + if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][(int) $post['menu_order']] ) ) { |
|
603 | 603 | // update to new form id |
604 | - $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
604 | + $post['menu_order'] = $imported['forms'][(int) $post['menu_order']]; |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // Don't allow default styles to take over a site's default style |
@@ -610,13 +610,13 @@ discard block |
||
610 | 610 | } |
611 | 611 | |
612 | 612 | foreach ( $item->postmeta as $meta ) { |
613 | - self::populate_postmeta($post, $meta, $imported); |
|
614 | - unset($meta); |
|
613 | + self::populate_postmeta( $post, $meta, $imported ); |
|
614 | + unset( $meta ); |
|
615 | 615 | } |
616 | 616 | |
617 | - self::populate_taxonomies($post, $item); |
|
617 | + self::populate_taxonomies( $post, $item ); |
|
618 | 618 | |
619 | - self::maybe_editing_post($post); |
|
619 | + self::maybe_editing_post( $post ); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | private static function populate_postmeta( &$post, $meta, $imported ) { |
@@ -628,27 +628,27 @@ discard block |
||
628 | 628 | ); |
629 | 629 | |
630 | 630 | //switch old form and field ids to new ones |
631 | - if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) { |
|
632 | - $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
631 | + if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][(int) $m['value']] ) ) { |
|
632 | + $m['value'] = $imported['forms'][(int) $m['value']]; |
|
633 | 633 | } else { |
634 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
634 | + $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
|
635 | 635 | |
636 | - if ( ! empty($frm_duplicate_ids) ) { |
|
636 | + if ( ! empty( $frm_duplicate_ids ) ) { |
|
637 | 637 | |
638 | 638 | if ( $m['key'] == 'frm_dyncontent' ) { |
639 | - $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
639 | + $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] ); |
|
640 | 640 | } else if ( $m['key'] == 'frm_options' ) { |
641 | 641 | |
642 | 642 | foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) { |
643 | - if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) { |
|
644 | - $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
|
643 | + if ( isset( $m['value'][$setting_name] ) && is_numeric( $m['value'][$setting_name] ) && isset( $frm_duplicate_ids[$m['value'][$setting_name]] ) ) { |
|
644 | + $m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]]; |
|
645 | 645 | } |
646 | 646 | } |
647 | 647 | |
648 | 648 | $check_dup_array = array(); |
649 | 649 | if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
650 | - if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
651 | - $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
650 | + if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[$m['value']['order_by']] ) ) { |
|
651 | + $m['value']['order_by'] = $frm_duplicate_ids[$m['value']['order_by']]; |
|
652 | 652 | } else if ( is_array( $m['value']['order_by'] ) ) { |
653 | 653 | $check_dup_array[] = 'order_by'; |
654 | 654 | } |
@@ -659,22 +659,22 @@ discard block |
||
659 | 659 | } |
660 | 660 | |
661 | 661 | foreach ( $check_dup_array as $check_k ) { |
662 | - foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) { |
|
663 | - if ( isset( $frm_duplicate_ids[ $mv ] ) ) { |
|
664 | - $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ]; |
|
662 | + foreach ( (array) $m['value'][$check_k] as $mk => $mv ) { |
|
663 | + if ( isset( $frm_duplicate_ids[$mv] ) ) { |
|
664 | + $m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv]; |
|
665 | 665 | } |
666 | - unset($mk, $mv); |
|
666 | + unset( $mk, $mv ); |
|
667 | 667 | } |
668 | 668 | } |
669 | 669 | } |
670 | 670 | } |
671 | 671 | } |
672 | 672 | |
673 | - if ( ! is_array($m['value']) ) { |
|
674 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
673 | + if ( ! is_array( $m['value'] ) ) { |
|
674 | + $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
|
675 | 675 | } |
676 | 676 | |
677 | - $post['postmeta'][ (string) $meta->meta_key ] = $m['value']; |
|
677 | + $post['postmeta'][(string) $meta->meta_key] = $m['value']; |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
@@ -690,23 +690,23 @@ discard block |
||
690 | 690 | } |
691 | 691 | |
692 | 692 | $taxonomy = (string) $att['domain']; |
693 | - if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
693 | + if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
694 | 694 | $name = (string) $att['nicename']; |
695 | - $h_term = get_term_by('slug', $name, $taxonomy); |
|
695 | + $h_term = get_term_by( 'slug', $name, $taxonomy ); |
|
696 | 696 | if ( $h_term ) { |
697 | 697 | $name = $h_term->term_id; |
698 | 698 | } |
699 | - unset($h_term); |
|
699 | + unset( $h_term ); |
|
700 | 700 | } else { |
701 | 701 | $name = (string) $c; |
702 | 702 | } |
703 | 703 | |
704 | - if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) { |
|
705 | - $post['tax_input'][ $taxonomy ] = array(); |
|
704 | + if ( ! isset( $post['tax_input'][$taxonomy] ) ) { |
|
705 | + $post['tax_input'][$taxonomy] = array(); |
|
706 | 706 | } |
707 | 707 | |
708 | - $post['tax_input'][ $taxonomy ][] = $name; |
|
709 | - unset($name); |
|
708 | + $post['tax_input'][$taxonomy][] = $name; |
|
709 | + unset( $name ); |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
@@ -723,29 +723,29 @@ discard block |
||
723 | 723 | |
724 | 724 | if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) { |
725 | 725 | $match_by['include'] = $post['post_id']; |
726 | - unset($match_by['name']); |
|
726 | + unset( $match_by['name'] ); |
|
727 | 727 | } |
728 | 728 | |
729 | - $editing = get_posts($match_by); |
|
729 | + $editing = get_posts( $match_by ); |
|
730 | 730 | |
731 | - if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
731 | + if ( ! empty( $editing ) && current( $editing )->post_date == $post['post_date'] ) { |
|
732 | 732 | // set the id of the post to edit |
733 | - $post['ID'] = current($editing)->ID; |
|
733 | + $post['ID'] = current( $editing )->ID; |
|
734 | 734 | } |
735 | 735 | } |
736 | 736 | |
737 | 737 | private static function update_postmeta( &$post, $post_id ) { |
738 | 738 | foreach ( $post['postmeta'] as $k => $v ) { |
739 | 739 | if ( '_edit_last' == $k ) { |
740 | - $v = FrmAppHelper::get_user_id_param($v); |
|
740 | + $v = FrmAppHelper::get_user_id_param( $v ); |
|
741 | 741 | } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
742 | 742 | //change the attachment ID |
743 | - $v = FrmProXMLHelper::get_file_id($v); |
|
743 | + $v = FrmProXMLHelper::get_file_id( $v ); |
|
744 | 744 | } |
745 | 745 | |
746 | - update_post_meta($post_id, $k, $v); |
|
746 | + update_post_meta( $post_id, $k, $v ); |
|
747 | 747 | |
748 | - unset($k, $v); |
|
748 | + unset( $k, $v ); |
|
749 | 749 | } |
750 | 750 | } |
751 | 751 | |
@@ -767,13 +767,13 @@ discard block |
||
767 | 767 | * @param string $message |
768 | 768 | */ |
769 | 769 | public static function parse_message( $result, &$message, &$errors ) { |
770 | - if ( is_wp_error($result) ) { |
|
770 | + if ( is_wp_error( $result ) ) { |
|
771 | 771 | $errors[] = $result->get_error_message(); |
772 | 772 | } else if ( ! $result ) { |
773 | 773 | return; |
774 | 774 | } |
775 | 775 | |
776 | - if ( ! is_array($result) ) { |
|
776 | + if ( ! is_array( $result ) ) { |
|
777 | 777 | $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
778 | 778 | return; |
779 | 779 | } |
@@ -785,20 +785,20 @@ discard block |
||
785 | 785 | |
786 | 786 | $message = '<ul>'; |
787 | 787 | foreach ( $result as $type => $results ) { |
788 | - if ( ! isset( $t_strings[ $type ] ) ) { |
|
788 | + if ( ! isset( $t_strings[$type] ) ) { |
|
789 | 789 | // only print imported and updated |
790 | 790 | continue; |
791 | 791 | } |
792 | 792 | |
793 | 793 | $s_message = array(); |
794 | 794 | foreach ( $results as $k => $m ) { |
795 | - self::item_count_message($m, $k, $s_message); |
|
796 | - unset($k, $m); |
|
795 | + self::item_count_message( $m, $k, $s_message ); |
|
796 | + unset( $k, $m ); |
|
797 | 797 | } |
798 | 798 | |
799 | - if ( ! empty($s_message) ) { |
|
800 | - $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> '; |
|
801 | - $message .= implode(', ', $s_message); |
|
799 | + if ( ! empty( $s_message ) ) { |
|
800 | + $message .= '<li><strong>' . $t_strings[$type] . ':</strong> '; |
|
801 | + $message .= implode( ', ', $s_message ); |
|
802 | 802 | $message .= '</li>'; |
803 | 803 | } |
804 | 804 | } |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
828 | 828 | ); |
829 | 829 | |
830 | - $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type ); |
|
830 | + $s_message[] = isset( $strings[$type] ) ? $strings[$type] : ' ' . $m . ' ' . ucfirst( $type ); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | /** |
@@ -859,14 +859,14 @@ discard block |
||
859 | 859 | } |
860 | 860 | |
861 | 861 | public static function cdata( $str ) { |
862 | - $str = maybe_unserialize($str); |
|
863 | - if ( is_array($str) ) { |
|
864 | - $str = json_encode($str); |
|
862 | + $str = maybe_unserialize( $str ); |
|
863 | + if ( is_array( $str ) ) { |
|
864 | + $str = json_encode( $str ); |
|
865 | 865 | } else if ( seems_utf8( $str ) == false ) { |
866 | 866 | $str = utf8_encode( $str ); |
867 | 867 | } |
868 | 868 | |
869 | - if ( is_numeric($str) ) { |
|
869 | + if ( is_numeric( $str ) ) { |
|
870 | 870 | return $str; |
871 | 871 | } |
872 | 872 | |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | * @param string $post_type |
912 | 912 | */ |
913 | 913 | private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
914 | - if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
914 | + if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) { |
|
915 | 915 | return; |
916 | 916 | } |
917 | 917 | |
@@ -932,10 +932,10 @@ discard block |
||
932 | 932 | ); |
933 | 933 | |
934 | 934 | foreach ( $post_settings as $post_setting ) { |
935 | - if ( isset( $form_options[ $post_setting ] ) ) { |
|
936 | - $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ]; |
|
935 | + if ( isset( $form_options[$post_setting] ) ) { |
|
936 | + $new_action['post_content'][$post_setting] = $form_options[$post_setting]; |
|
937 | 937 | } |
938 | - unset($post_setting); |
|
938 | + unset( $post_setting ); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | $new_action['event'] = array( 'create', 'update' ); |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | |
950 | 950 | $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields ); |
951 | 951 | } |
952 | - $new_action['post_content'] = json_encode($new_action['post_content']); |
|
952 | + $new_action['post_content'] = json_encode( $new_action['post_content'] ); |
|
953 | 953 | |
954 | 954 | $exists = get_posts( array( |
955 | 955 | 'name' => $new_action['post_name'], |
@@ -961,7 +961,7 @@ discard block |
||
961 | 961 | if ( ! $exists ) { |
962 | 962 | // this isn't an email, but we need to use a class that will always be included |
963 | 963 | FrmAppHelper::save_json_post( $new_action ); |
964 | - $imported['imported']['actions']++; |
|
964 | + $imported['imported']['actions'] ++; |
|
965 | 965 | } |
966 | 966 | } |
967 | 967 | |
@@ -993,11 +993,11 @@ discard block |
||
993 | 993 | foreach ( $post_content as $key => $setting ) { |
994 | 994 | if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
995 | 995 | // Replace old IDs with new IDs |
996 | - $post_content[ $key ] = str_replace( $old, $new, $setting ); |
|
996 | + $post_content[$key] = str_replace( $old, $new, $setting ); |
|
997 | 997 | } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
998 | 998 | foreach ( $setting as $k => $val ) { |
999 | 999 | // Replace old IDs with new IDs |
1000 | - $post_content[ $key ][ $k ] = str_replace( $old, $new, $val ); |
|
1000 | + $post_content[$key][$k] = str_replace( $old, $new, $val ); |
|
1001 | 1001 | } |
1002 | 1002 | } |
1003 | 1003 | unset( $key, $setting ); |
@@ -1020,14 +1020,14 @@ discard block |
||
1020 | 1020 | // Migrate autoresponders |
1021 | 1021 | self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
1022 | 1022 | |
1023 | - if ( empty( $notifications ) ) { |
|
1023 | + if ( empty( $notifications ) ) { |
|
1024 | 1024 | return; |
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | foreach ( $notifications as $new_notification ) { |
1028 | 1028 | $new_notification['post_type'] = $post_type; |
1029 | 1029 | $new_notification['post_excerpt'] = 'email'; |
1030 | - $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
|
1030 | + $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
|
1031 | 1031 | $new_notification['menu_order'] = $form_id; |
1032 | 1032 | $new_notification['post_status'] = 'publish'; |
1033 | 1033 | |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | // Switch all other field IDs in email |
1041 | 1041 | $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
1042 | 1042 | } |
1043 | - $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
1043 | + $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
1044 | 1044 | |
1045 | 1045 | $exists = get_posts( array( |
1046 | 1046 | 'name' => $new_notification['post_name'], |
@@ -1049,11 +1049,11 @@ discard block |
||
1049 | 1049 | 'numberposts' => 1, |
1050 | 1050 | ) ); |
1051 | 1051 | |
1052 | - if ( empty($exists) ) { |
|
1052 | + if ( empty( $exists ) ) { |
|
1053 | 1053 | FrmAppHelper::save_json_post( $new_notification ); |
1054 | - $imported['imported']['actions']++; |
|
1054 | + $imported['imported']['actions'] ++; |
|
1055 | 1055 | } |
1056 | - unset($new_notification); |
|
1056 | + unset( $new_notification ); |
|
1057 | 1057 | } |
1058 | 1058 | } |
1059 | 1059 | |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | $form_options['notification'] = array( 0 => $form_options['notification'] ); |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
1069 | + if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) { |
|
1070 | 1070 | foreach ( $form_options['notification'] as $email_key => $notification ) { |
1071 | 1071 | |
1072 | 1072 | $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
@@ -1094,12 +1094,12 @@ discard block |
||
1094 | 1094 | // Format the reply to email and name |
1095 | 1095 | $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
1096 | 1096 | foreach ( $reply_fields as $f => $val ) { |
1097 | - if ( isset( $notification[ $f ] ) ) { |
|
1098 | - $atts[ $f ] = $notification[ $f ]; |
|
1099 | - if ( 'custom' == $notification[ $f ] ) { |
|
1100 | - $atts[ $f ] = $notification[ 'cust_' . $f ]; |
|
1101 | - } else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) { |
|
1102 | - $atts[ $f ] = '[' . $atts[ $f ] . ']'; |
|
1097 | + if ( isset( $notification[$f] ) ) { |
|
1098 | + $atts[$f] = $notification[$f]; |
|
1099 | + if ( 'custom' == $notification[$f] ) { |
|
1100 | + $atts[$f] = $notification['cust_' . $f]; |
|
1101 | + } else if ( is_numeric( $atts[$f] ) && ! empty( $atts[$f] ) ) { |
|
1102 | + $atts[$f] = '[' . $atts[$f] . ']'; |
|
1103 | 1103 | } |
1104 | 1104 | } |
1105 | 1105 | unset( $f, $val ); |
@@ -1109,7 +1109,7 @@ discard block |
||
1109 | 1109 | $atts['event'] = array( 'create' ); |
1110 | 1110 | if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
1111 | 1111 | $atts['event'][] = 'update'; |
1112 | - } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
1112 | + } else if ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) { |
|
1113 | 1113 | $atts['event'] = array( 'update' ); |
1114 | 1114 | } |
1115 | 1115 | } |
@@ -1130,18 +1130,18 @@ discard block |
||
1130 | 1130 | foreach ( $atts['email_to'] as $key => $email_field ) { |
1131 | 1131 | |
1132 | 1132 | if ( is_numeric( $email_field ) ) { |
1133 | - $atts['email_to'][ $key ] = '[' . $email_field . ']'; |
|
1133 | + $atts['email_to'][$key] = '[' . $email_field . ']'; |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | - if ( strpos( $email_field, '|') ) { |
|
1136 | + if ( strpos( $email_field, '|' ) ) { |
|
1137 | 1137 | $email_opt = explode( '|', $email_field ); |
1138 | 1138 | if ( isset( $email_opt[0] ) ) { |
1139 | - $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
|
1139 | + $atts['email_to'][$key] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
|
1140 | 1140 | } |
1141 | 1141 | unset( $email_opt ); |
1142 | 1142 | } |
1143 | 1143 | } |
1144 | - $atts['email_to'] = implode(', ', $atts['email_to']); |
|
1144 | + $atts['email_to'] = implode( ', ', $atts['email_to'] ); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
@@ -1157,12 +1157,12 @@ discard block |
||
1157 | 1157 | // Add more fields to the new notification |
1158 | 1158 | $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
1159 | 1159 | foreach ( $add_fields as $add_field ) { |
1160 | - if ( isset( $notification[ $add_field ] ) ) { |
|
1161 | - $new_notification['post_content'][ $add_field ] = $notification[ $add_field ]; |
|
1160 | + if ( isset( $notification[$add_field] ) ) { |
|
1161 | + $new_notification['post_content'][$add_field] = $notification[$add_field]; |
|
1162 | 1162 | } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
1163 | - $new_notification['post_content'][ $add_field ] = 0; |
|
1163 | + $new_notification['post_content'][$add_field] = 0; |
|
1164 | 1164 | } else { |
1165 | - $new_notification['post_content'][ $add_field ] = ''; |
|
1165 | + $new_notification['post_content'][$add_field] = ''; |
|
1166 | 1166 | } |
1167 | 1167 | unset( $add_field ); |
1168 | 1168 | } |
@@ -1186,26 +1186,26 @@ discard block |
||
1186 | 1186 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
1187 | 1187 | foreach ( $post_content['conditions'] as $email_key => $val ) { |
1188 | 1188 | if ( is_numeric( $email_key ) ) { |
1189 | - $post_content['conditions'][ $email_key ] = self::switch_action_field_ids( $val, array( 'hide_field' ) ); |
|
1189 | + $post_content['conditions'][$email_key] = self::switch_action_field_ids( $val, array( 'hide_field' ) ); |
|
1190 | 1190 | } |
1191 | - unset( $email_key, $val); |
|
1191 | + unset( $email_key, $val ); |
|
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | } |
1195 | 1195 | |
1196 | 1196 | private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
1197 | - if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
1197 | + if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) { |
|
1198 | 1198 | // migrate autoresponder |
1199 | 1199 | |
1200 | - $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
1201 | - if ( strpos($email_field, '|') ) { |
|
1200 | + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0; |
|
1201 | + if ( strpos( $email_field, '|' ) ) { |
|
1202 | 1202 | // data from entries field |
1203 | - $email_field = explode('|', $email_field); |
|
1204 | - if ( isset($email_field[1]) ) { |
|
1203 | + $email_field = explode( '|', $email_field ); |
|
1204 | + if ( isset( $email_field[1] ) ) { |
|
1205 | 1205 | $email_field = $email_field[1]; |
1206 | 1206 | } |
1207 | 1207 | } |
1208 | - if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
1208 | + if ( is_numeric( $email_field ) && ! empty( $email_field ) ) { |
|
1209 | 1209 | $email_field = '[' . $email_field . ']'; |
1210 | 1210 | } |
1211 | 1211 | |
@@ -1213,16 +1213,16 @@ discard block |
||
1213 | 1213 | $new_notification2 = array( |
1214 | 1214 | 'post_content' => array( |
1215 | 1215 | 'email_message' => $notification['ar_email_message'], |
1216 | - 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
1216 | + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '', |
|
1217 | 1217 | 'email_to' => $email_field, |
1218 | - 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
1218 | + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0, |
|
1219 | 1219 | 'inc_user_info' => 0, |
1220 | 1220 | ), |
1221 | 1221 | 'post_name' => $form_id . '_email_' . count( $notifications ), |
1222 | 1222 | ); |
1223 | 1223 | |
1224 | - $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
1225 | - $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
1224 | + $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : ''; |
|
1225 | + $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : ''; |
|
1226 | 1226 | |
1227 | 1227 | if ( ! empty( $reply_to ) ) { |
1228 | 1228 | $new_notification2['post_content']['reply_to'] = $reply_to; |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <li id="frm_delete_field_<?php echo esc_attr( $field['id'] ); ?>-<?php echo esc_attr( $opt_key ) ?>_container" class="frm_single_option"> |
2 | 2 | <a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon" data-fid="<?php echo esc_attr( $field['id'] ); ?>"> </a> |
3 | 3 | <?php if ( $field['type'] != 'select' ) { ?> |
4 | - <input type="<?php echo esc_attr( $field['type'] ) ?>" name="<?php echo esc_attr( $field_name . ( $field['type'] == 'checkbox' ? '[]' : '' ) ); ?>" value="<?php echo esc_attr($field_val) ?>"<?php echo isset( $checked ) ? $checked : ''; ?>/> |
|
4 | + <input type="<?php echo esc_attr( $field['type'] ) ?>" name="<?php echo esc_attr( $field_name . ( $field['type'] == 'checkbox' ? '[]' : '' ) ); ?>" value="<?php echo esc_attr( $field_val ) ?>"<?php echo isset( $checked ) ? $checked : ''; ?>/> |
|
5 | 5 | <?php } ?> |
6 | 6 | |
7 | - <label class="frm_ipe_field_option field_<?php echo esc_attr( $field['id'] ) ?>_option <?php echo esc_attr( $field['separate_value'] ? 'frm_with_key' : '' ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ) ?>"><?php echo ($opt == '') ? __( '(Blank)', 'formidable' ) : $opt ?></label> |
|
7 | + <label class="frm_ipe_field_option field_<?php echo esc_attr( $field['id'] ) ?>_option <?php echo esc_attr( $field['separate_value'] ? 'frm_with_key' : '' ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ) ?>"><?php echo ( $opt == '' ) ? __( '(Blank)', 'formidable' ) : $opt ?></label> |
|
8 | 8 | <input type="hidden" name="field_options[options_<?php echo esc_attr( $field['id'] ) ?>][<?php echo esc_attr( $opt_key ) ?>][label]" value="<?php echo esc_attr( $opt ) ?>" /> |
9 | 9 | |
10 | 10 | <span class="frm_option_key field_<?php echo esc_attr( $field['id'] ) ?>_option_key<?php echo esc_attr( $field['separate_value'] ? '' : ' frm_hidden' ); ?>"> |
@@ -13,4 +13,4 @@ discard block |
||
13 | 13 | </span> |
14 | 14 | </li> |
15 | 15 | <?php |
16 | -unset($field_val, $opt, $opt_key); |
|
16 | +unset( $field_val, $opt, $opt_key ); |
@@ -2,129 +2,129 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmFieldsController { |
4 | 4 | |
5 | - public static function load_field() { |
|
5 | + public static function load_field() { |
|
6 | 6 | FrmAppHelper::permission_check('frm_edit_forms'); |
7 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
7 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
8 | 8 | |
9 | - $fields = $_POST['field']; |
|
10 | - if ( empty( $fields ) ) { |
|
11 | - wp_die(); |
|
12 | - } |
|
9 | + $fields = $_POST['field']; |
|
10 | + if ( empty( $fields ) ) { |
|
11 | + wp_die(); |
|
12 | + } |
|
13 | 13 | |
14 | - $_GET['page'] = 'formidable'; |
|
15 | - $fields = stripslashes_deep( $fields ); |
|
14 | + $_GET['page'] = 'formidable'; |
|
15 | + $fields = stripslashes_deep( $fields ); |
|
16 | 16 | |
17 | - $ajax = true; |
|
17 | + $ajax = true; |
|
18 | 18 | $values = array( 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ) ); |
19 | - $path = FrmAppHelper::plugin_path(); |
|
20 | - $field_html = array(); |
|
21 | - |
|
22 | - foreach ( $fields as $field ) { |
|
23 | - $field = htmlspecialchars_decode( nl2br( $field ) ); |
|
24 | - $field = json_decode( $field, true ); |
|
25 | - if ( ! isset( $field['id'] ) ) { |
|
26 | - // this field may have already been loaded |
|
27 | - continue; |
|
28 | - } |
|
19 | + $path = FrmAppHelper::plugin_path(); |
|
20 | + $field_html = array(); |
|
21 | + |
|
22 | + foreach ( $fields as $field ) { |
|
23 | + $field = htmlspecialchars_decode( nl2br( $field ) ); |
|
24 | + $field = json_decode( $field, true ); |
|
25 | + if ( ! isset( $field['id'] ) ) { |
|
26 | + // this field may have already been loaded |
|
27 | + continue; |
|
28 | + } |
|
29 | 29 | |
30 | - $field_id = absint( $field['id'] ); |
|
30 | + $field_id = absint( $field['id'] ); |
|
31 | 31 | |
32 | - if ( ! isset( $field['value'] ) ) { |
|
33 | - $field['value'] = ''; |
|
34 | - } |
|
32 | + if ( ! isset( $field['value'] ) ) { |
|
33 | + $field['value'] = ''; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | $field_name = 'item_meta[' . $field_id . ']'; |
37 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
37 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
38 | 38 | |
39 | - ob_start(); |
|
39 | + ob_start(); |
|
40 | 40 | include( $path . '/classes/views/frm-forms/add_field.php' ); |
41 | - $field_html[ $field_id ] = ob_get_contents(); |
|
42 | - ob_end_clean(); |
|
43 | - } |
|
41 | + $field_html[ $field_id ] = ob_get_contents(); |
|
42 | + ob_end_clean(); |
|
43 | + } |
|
44 | 44 | |
45 | - unset($path); |
|
45 | + unset($path); |
|
46 | 46 | |
47 | - echo json_encode($field_html); |
|
47 | + echo json_encode($field_html); |
|
48 | 48 | |
49 | - wp_die(); |
|
50 | - } |
|
49 | + wp_die(); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Create a new field with ajax |
54 | 54 | */ |
55 | - public static function create() { |
|
55 | + public static function create() { |
|
56 | 56 | FrmAppHelper::permission_check('frm_edit_forms'); |
57 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
57 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
58 | 58 | |
59 | 59 | $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); |
60 | 60 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
61 | 61 | |
62 | 62 | $field = self::include_new_field( $field_type, $form_id ); |
63 | 63 | |
64 | - // this hook will allow for multiple fields to be added at once |
|
65 | - do_action('frm_after_field_created', $field, $form_id); |
|
64 | + // this hook will allow for multiple fields to be added at once |
|
65 | + do_action('frm_after_field_created', $field, $form_id); |
|
66 | 66 | |
67 | - wp_die(); |
|
68 | - } |
|
67 | + wp_die(); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Set up and create a new field |
|
72 | - * |
|
73 | - * @param string $field_type |
|
74 | - * @param integer $form_id |
|
75 | - * @return array|bool |
|
76 | - */ |
|
70 | + /** |
|
71 | + * Set up and create a new field |
|
72 | + * |
|
73 | + * @param string $field_type |
|
74 | + * @param integer $form_id |
|
75 | + * @return array|bool |
|
76 | + */ |
|
77 | 77 | public static function include_new_field( $field_type, $form_id ) { |
78 | - $values = array(); |
|
79 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
80 | - $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
81 | - } |
|
78 | + $values = array(); |
|
79 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
80 | + $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
84 | - $field_values = apply_filters( 'frm_before_field_created', $field_values ); |
|
84 | + $field_values = apply_filters( 'frm_before_field_created', $field_values ); |
|
85 | 85 | |
86 | - $field_id = FrmField::create( $field_values ); |
|
86 | + $field_id = FrmField::create( $field_values ); |
|
87 | 87 | |
88 | - if ( ! $field_id ) { |
|
89 | - return false; |
|
90 | - } |
|
88 | + if ( ! $field_id ) { |
|
89 | + return false; |
|
90 | + } |
|
91 | 91 | |
92 | - $field = self::include_single_field($field_id, $values, $form_id); |
|
92 | + $field = self::include_single_field($field_id, $values, $form_id); |
|
93 | 93 | |
94 | - return $field; |
|
95 | - } |
|
94 | + return $field; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | public static function edit_name( $field = 'name', $id = '' ) { |
98 | 98 | FrmAppHelper::permission_check('frm_edit_forms'); |
99 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
99 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
100 | 100 | |
101 | - if ( empty($field) ) { |
|
102 | - $field = 'name'; |
|
103 | - } |
|
101 | + if ( empty($field) ) { |
|
102 | + $field = 'name'; |
|
103 | + } |
|
104 | 104 | |
105 | - if ( empty($id) ) { |
|
105 | + if ( empty($id) ) { |
|
106 | 106 | $id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
107 | 107 | $id = str_replace( 'field_label_', '', $id ); |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | 110 | $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ); |
111 | 111 | $value = trim( $value ); |
112 | - if ( trim(strip_tags($value)) == '' ) { |
|
113 | - // set blank value if there is no content |
|
114 | - $value = ''; |
|
115 | - } |
|
112 | + if ( trim(strip_tags($value)) == '' ) { |
|
113 | + // set blank value if there is no content |
|
114 | + $value = ''; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | FrmField::update( $id, array( $field => $value ) ); |
118 | 118 | |
119 | 119 | do_action( 'frm_after_update_field_' . $field, compact( 'id', 'value' ) ); |
120 | 120 | |
121 | 121 | echo stripslashes( wp_kses_post( $value ) ); |
122 | - wp_die(); |
|
123 | - } |
|
122 | + wp_die(); |
|
123 | + } |
|
124 | 124 | |
125 | - public static function update_ajax_option() { |
|
125 | + public static function update_ajax_option() { |
|
126 | 126 | FrmAppHelper::permission_check('frm_edit_forms'); |
127 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
127 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
128 | 128 | |
129 | 129 | $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' ); |
130 | 130 | if ( ! $field_id ) { |
@@ -139,388 +139,388 @@ discard block |
||
139 | 139 | unset($new_val); |
140 | 140 | } |
141 | 141 | |
142 | - FrmField::update( $field_id, array( |
|
143 | - 'field_options' => $field->field_options, |
|
142 | + FrmField::update( $field_id, array( |
|
143 | + 'field_options' => $field->field_options, |
|
144 | 144 | 'form_id' => $field->form_id, |
145 | - ) ); |
|
146 | - wp_die(); |
|
147 | - } |
|
145 | + ) ); |
|
146 | + wp_die(); |
|
147 | + } |
|
148 | 148 | |
149 | - public static function duplicate() { |
|
149 | + public static function duplicate() { |
|
150 | 150 | FrmAppHelper::permission_check('frm_edit_forms'); |
151 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
151 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
152 | 152 | |
153 | - global $wpdb; |
|
153 | + global $wpdb; |
|
154 | 154 | |
155 | 155 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
156 | 156 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
157 | 157 | |
158 | 158 | $copy_field = FrmField::getOne( $field_id ); |
159 | - if ( ! $copy_field ) { |
|
160 | - wp_die(); |
|
161 | - } |
|
159 | + if ( ! $copy_field ) { |
|
160 | + wp_die(); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | do_action( 'frm_duplicate_field', $copy_field, $form_id ); |
164 | 164 | do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id ); |
165 | 165 | |
166 | 166 | $values = array(); |
167 | - FrmFieldsHelper::fill_field( $values, $copy_field, $form_id ); |
|
167 | + FrmFieldsHelper::fill_field( $values, $copy_field, $form_id ); |
|
168 | 168 | |
169 | 169 | $field_count = FrmDb::get_count( $wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) ); |
170 | 170 | |
171 | - $values['field_order'] = $field_count + 1; |
|
171 | + $values['field_order'] = $field_count + 1; |
|
172 | 172 | |
173 | - $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
|
173 | + $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
|
174 | 174 | |
175 | - if ( ! $field_id = FrmField::create($values) ) { |
|
176 | - wp_die(); |
|
177 | - } |
|
175 | + if ( ! $field_id = FrmField::create($values) ) { |
|
176 | + wp_die(); |
|
177 | + } |
|
178 | 178 | |
179 | - self::include_single_field($field_id, $values); |
|
179 | + self::include_single_field($field_id, $values); |
|
180 | 180 | |
181 | - wp_die(); |
|
182 | - } |
|
181 | + wp_die(); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Load a single field in the form builder along with all needed variables |
|
186 | - */ |
|
187 | - public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
188 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
184 | + /** |
|
185 | + * Load a single field in the form builder along with all needed variables |
|
186 | + */ |
|
187 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
188 | + $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
189 | 189 | $field_name = 'item_meta[' . $field_id . ']'; |
190 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
191 | - $id = $form_id ? $form_id : $field['form_id']; |
|
192 | - if ( $field['type'] == 'html' ) { |
|
193 | - $field['stop_filter'] = true; |
|
194 | - } |
|
190 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
191 | + $id = $form_id ? $form_id : $field['form_id']; |
|
192 | + if ( $field['type'] == 'html' ) { |
|
193 | + $field['stop_filter'] = true; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' ); |
197 | 197 | |
198 | - return $field; |
|
199 | - } |
|
198 | + return $field; |
|
199 | + } |
|
200 | 200 | |
201 | - public static function destroy() { |
|
201 | + public static function destroy() { |
|
202 | 202 | FrmAppHelper::permission_check('frm_edit_forms'); |
203 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
203 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
204 | 204 | |
205 | 205 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
206 | 206 | FrmField::destroy( $field_id ); |
207 | - wp_die(); |
|
208 | - } |
|
207 | + wp_die(); |
|
208 | + } |
|
209 | 209 | |
210 | - /* Field Options */ |
|
210 | + /* Field Options */ |
|
211 | 211 | |
212 | - //Add Single Option or Other Option |
|
213 | - public static function add_option() { |
|
212 | + //Add Single Option or Other Option |
|
213 | + public static function add_option() { |
|
214 | 214 | FrmAppHelper::permission_check('frm_edit_forms'); |
215 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
215 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
216 | 216 | |
217 | 217 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
218 | 218 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
219 | 219 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' ); |
220 | 220 | |
221 | - $field = FrmField::getOne($id); |
|
221 | + $field = FrmField::getOne($id); |
|
222 | 222 | |
223 | - if ( 'other' == $opt_type ) { |
|
223 | + if ( 'other' == $opt_type ) { |
|
224 | 224 | $opt = __( 'Other', 'formidable' ); |
225 | - $other_val = ''; |
|
226 | - $opt_key = 'other_' . $opt_key; |
|
227 | - } else { |
|
225 | + $other_val = ''; |
|
226 | + $opt_key = 'other_' . $opt_key; |
|
227 | + } else { |
|
228 | 228 | $opt = __( 'New Option', 'formidable' ); |
229 | - } |
|
230 | - $field_val = $opt; |
|
229 | + } |
|
230 | + $field_val = $opt; |
|
231 | 231 | |
232 | - $field_data = $field; |
|
232 | + $field_data = $field; |
|
233 | 233 | $field = (array) $field; |
234 | 234 | $field['separate_value'] = isset( $field_data->field_options['separate_value'] ) ? $field_data->field_options['separate_value'] : 0; |
235 | 235 | unset( $field_data ); |
236 | 236 | |
237 | 237 | $field_name = 'item_meta[' . $id . ']'; |
238 | 238 | $html_id = FrmFieldsHelper::get_html_id( $field ); |
239 | - $checked = ''; |
|
239 | + $checked = ''; |
|
240 | 240 | |
241 | - if ( 'other' == $opt_type ) { |
|
241 | + if ( 'other' == $opt_type ) { |
|
242 | 242 | include( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' ); |
243 | - } else { |
|
243 | + } else { |
|
244 | 244 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
245 | - } |
|
246 | - wp_die(); |
|
247 | - } |
|
245 | + } |
|
246 | + wp_die(); |
|
247 | + } |
|
248 | 248 | |
249 | - public static function edit_option() { |
|
249 | + public static function edit_option() { |
|
250 | 250 | _deprecated_function( __FUNCTION__, '2.3' ); |
251 | - } |
|
251 | + } |
|
252 | 252 | |
253 | - public static function delete_option() { |
|
253 | + public static function delete_option() { |
|
254 | 254 | _deprecated_function( __FUNCTION__, '2.3' ); |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - public static function import_choices() { |
|
258 | - FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
257 | + public static function import_choices() { |
|
258 | + FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
259 | 259 | |
260 | 260 | $field_id = absint( $_REQUEST['field_id'] ); |
261 | 261 | |
262 | - global $current_screen, $hook_suffix; |
|
262 | + global $current_screen, $hook_suffix; |
|
263 | 263 | |
264 | - // Catch plugins that include admin-header.php before admin.php completes. |
|
265 | - if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
266 | - $hook_suffix = ''; |
|
267 | - set_current_screen(); |
|
268 | - } |
|
264 | + // Catch plugins that include admin-header.php before admin.php completes. |
|
265 | + if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
266 | + $hook_suffix = ''; |
|
267 | + set_current_screen(); |
|
268 | + } |
|
269 | 269 | |
270 | - if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
271 | - register_admin_color_schemes(); |
|
272 | - } |
|
270 | + if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
271 | + register_admin_color_schemes(); |
|
272 | + } |
|
273 | 273 | |
274 | - $hook_suffix = $admin_body_class = ''; |
|
274 | + $hook_suffix = $admin_body_class = ''; |
|
275 | 275 | |
276 | - if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
277 | - $admin_body_class .= ' folded'; |
|
278 | - } |
|
276 | + if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
277 | + $admin_body_class .= ' folded'; |
|
278 | + } |
|
279 | 279 | |
280 | - if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
281 | - $admin_body_class .= ' admin-bar'; |
|
282 | - } |
|
280 | + if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
281 | + $admin_body_class .= ' admin-bar'; |
|
282 | + } |
|
283 | 283 | |
284 | - if ( is_rtl() ) { |
|
285 | - $admin_body_class .= ' rtl'; |
|
286 | - } |
|
284 | + if ( is_rtl() ) { |
|
285 | + $admin_body_class .= ' rtl'; |
|
286 | + } |
|
287 | 287 | |
288 | - $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
289 | - $prepop = array(); |
|
290 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
288 | + $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
289 | + $prepop = array(); |
|
290 | + FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
291 | 291 | |
292 | - $field = FrmField::getOne($field_id); |
|
292 | + $field = FrmField::getOne($field_id); |
|
293 | 293 | |
294 | - wp_enqueue_script( 'utils' ); |
|
294 | + wp_enqueue_script( 'utils' ); |
|
295 | 295 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
296 | - FrmAppHelper::load_admin_wide_js(); |
|
296 | + FrmAppHelper::load_admin_wide_js(); |
|
297 | 297 | |
298 | 298 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' ); |
299 | - wp_die(); |
|
300 | - } |
|
299 | + wp_die(); |
|
300 | + } |
|
301 | 301 | |
302 | - public static function import_options() { |
|
302 | + public static function import_options() { |
|
303 | 303 | FrmAppHelper::permission_check('frm_edit_forms'); |
304 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
304 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
305 | 305 | |
306 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
307 | - return; |
|
308 | - } |
|
306 | + if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
307 | + return; |
|
308 | + } |
|
309 | 309 | |
310 | 310 | $field_id = absint( $_POST['field_id'] ); |
311 | - $field = FrmField::getOne($field_id); |
|
311 | + $field = FrmField::getOne($field_id); |
|
312 | 312 | |
313 | 313 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
314 | - return; |
|
315 | - } |
|
314 | + return; |
|
315 | + } |
|
316 | 316 | |
317 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
317 | + $field = FrmFieldsHelper::setup_edit_vars($field); |
|
318 | 318 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
319 | 319 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
320 | 320 | $opts = array_map( 'trim', $opts ); |
321 | 321 | |
322 | - if ( $field['separate_value'] ) { |
|
323 | - foreach ( $opts as $opt_key => $opt ) { |
|
324 | - if ( strpos($opt, '|') !== false ) { |
|
325 | - $vals = explode('|', $opt); |
|
326 | - if ( $vals[0] != $vals[1] ) { |
|
327 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
328 | - } |
|
329 | - unset($vals); |
|
330 | - } |
|
331 | - unset($opt_key, $opt); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - //Keep other options after bulk update |
|
336 | - if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
337 | - $other_array = array(); |
|
338 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
339 | - if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
340 | - $other_array[ $opt_key ] = $opt; |
|
341 | - } |
|
342 | - unset($opt_key, $opt); |
|
343 | - } |
|
344 | - if ( ! empty($other_array) ) { |
|
345 | - $opts = array_merge( $opts, $other_array); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - $field['options'] = $opts; |
|
350 | - |
|
351 | - if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
322 | + if ( $field['separate_value'] ) { |
|
323 | + foreach ( $opts as $opt_key => $opt ) { |
|
324 | + if ( strpos($opt, '|') !== false ) { |
|
325 | + $vals = explode('|', $opt); |
|
326 | + if ( $vals[0] != $vals[1] ) { |
|
327 | + $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
328 | + } |
|
329 | + unset($vals); |
|
330 | + } |
|
331 | + unset($opt_key, $opt); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + //Keep other options after bulk update |
|
336 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
337 | + $other_array = array(); |
|
338 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
339 | + if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
340 | + $other_array[ $opt_key ] = $opt; |
|
341 | + } |
|
342 | + unset($opt_key, $opt); |
|
343 | + } |
|
344 | + if ( ! empty($other_array) ) { |
|
345 | + $opts = array_merge( $opts, $other_array); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + $field['options'] = $opts; |
|
350 | + |
|
351 | + if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
352 | 352 | $field_name = 'item_meta[' . $id . ']'; |
353 | 353 | |
354 | 354 | // Get html_id which will be used in single-option.php |
355 | 355 | $html_id = FrmFieldsHelper::get_html_id( $field ); |
356 | 356 | |
357 | 357 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
358 | - } else { |
|
359 | - FrmFieldsHelper::show_single_option($field); |
|
360 | - } |
|
358 | + } else { |
|
359 | + FrmFieldsHelper::show_single_option($field); |
|
360 | + } |
|
361 | 361 | |
362 | - wp_die(); |
|
363 | - } |
|
362 | + wp_die(); |
|
363 | + } |
|
364 | 364 | |
365 | - public static function update_order() { |
|
365 | + public static function update_order() { |
|
366 | 366 | FrmAppHelper::permission_check('frm_edit_forms'); |
367 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
367 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
368 | 368 | |
369 | 369 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
370 | 370 | foreach ( (array) $fields as $position => $item ) { |
371 | 371 | FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) ); |
372 | 372 | } |
373 | - wp_die(); |
|
374 | - } |
|
373 | + wp_die(); |
|
374 | + } |
|
375 | 375 | |
376 | 376 | public static function change_type( $type ) { |
377 | - $type_switch = array( |
|
378 | - 'scale' => 'radio', |
|
379 | - '10radio' => 'radio', |
|
380 | - 'rte' => 'textarea', |
|
381 | - 'website' => 'url', |
|
382 | - ); |
|
383 | - if ( isset( $type_switch[ $type ] ) ) { |
|
384 | - $type = $type_switch[ $type ]; |
|
385 | - } |
|
377 | + $type_switch = array( |
|
378 | + 'scale' => 'radio', |
|
379 | + '10radio' => 'radio', |
|
380 | + 'rte' => 'textarea', |
|
381 | + 'website' => 'url', |
|
382 | + ); |
|
383 | + if ( isset( $type_switch[ $type ] ) ) { |
|
384 | + $type = $type_switch[ $type ]; |
|
385 | + } |
|
386 | 386 | |
387 | 387 | $frm_field_selection = FrmField::field_selection(); |
388 | - $types = array_keys($frm_field_selection); |
|
389 | - if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
390 | - $type = 'text'; |
|
391 | - } |
|
388 | + $types = array_keys($frm_field_selection); |
|
389 | + if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
390 | + $type = 'text'; |
|
391 | + } |
|
392 | 392 | |
393 | - return $type; |
|
394 | - } |
|
393 | + return $type; |
|
394 | + } |
|
395 | 395 | |
396 | 396 | public static function display_field_options( $display ) { |
397 | 397 | switch ( $display['type'] ) { |
398 | - case 'captcha': |
|
399 | - $display['required'] = false; |
|
400 | - $display['invalid'] = true; |
|
401 | - $display['default_blank'] = false; |
|
398 | + case 'captcha': |
|
399 | + $display['required'] = false; |
|
400 | + $display['invalid'] = true; |
|
401 | + $display['default_blank'] = false; |
|
402 | 402 | $display['captcha_size'] = true; |
403 | - break; |
|
404 | - case 'radio': |
|
405 | - $display['default_blank'] = false; |
|
406 | - break; |
|
407 | - case 'text': |
|
408 | - case 'textarea': |
|
409 | - $display['size'] = true; |
|
410 | - $display['clear_on_focus'] = true; |
|
411 | - break; |
|
412 | - case 'select': |
|
413 | - $display['size'] = true; |
|
414 | - break; |
|
415 | - case 'url': |
|
416 | - case 'website': |
|
417 | - case 'email': |
|
418 | - $display['size'] = true; |
|
419 | - $display['clear_on_focus'] = true; |
|
420 | - $display['invalid'] = true; |
|
421 | - } |
|
422 | - |
|
423 | - return $display; |
|
424 | - } |
|
425 | - |
|
426 | - public static function input_html( $field, $echo = true ) { |
|
427 | - $class = array(); //$field['type']; |
|
428 | - self::add_input_classes($field, $class); |
|
429 | - |
|
430 | - $add_html = array(); |
|
431 | - self::add_html_size($field, $add_html); |
|
432 | - self::add_html_length($field, $add_html); |
|
433 | - self::add_html_placeholder($field, $add_html, $class); |
|
403 | + break; |
|
404 | + case 'radio': |
|
405 | + $display['default_blank'] = false; |
|
406 | + break; |
|
407 | + case 'text': |
|
408 | + case 'textarea': |
|
409 | + $display['size'] = true; |
|
410 | + $display['clear_on_focus'] = true; |
|
411 | + break; |
|
412 | + case 'select': |
|
413 | + $display['size'] = true; |
|
414 | + break; |
|
415 | + case 'url': |
|
416 | + case 'website': |
|
417 | + case 'email': |
|
418 | + $display['size'] = true; |
|
419 | + $display['clear_on_focus'] = true; |
|
420 | + $display['invalid'] = true; |
|
421 | + } |
|
422 | + |
|
423 | + return $display; |
|
424 | + } |
|
425 | + |
|
426 | + public static function input_html( $field, $echo = true ) { |
|
427 | + $class = array(); //$field['type']; |
|
428 | + self::add_input_classes($field, $class); |
|
429 | + |
|
430 | + $add_html = array(); |
|
431 | + self::add_html_size($field, $add_html); |
|
432 | + self::add_html_length($field, $add_html); |
|
433 | + self::add_html_placeholder($field, $add_html, $class); |
|
434 | 434 | self::add_validation_messages( $field, $add_html ); |
435 | 435 | |
436 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
436 | + $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
437 | 437 | |
438 | 438 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
439 | 439 | |
440 | - self::add_shortcodes_to_html($field, $add_html); |
|
440 | + self::add_shortcodes_to_html($field, $add_html); |
|
441 | 441 | |
442 | 442 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
443 | 443 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
444 | 444 | |
445 | - if ( $echo ) { |
|
446 | - echo $add_html; |
|
447 | - } |
|
445 | + if ( $echo ) { |
|
446 | + echo $add_html; |
|
447 | + } |
|
448 | 448 | |
449 | - return $add_html; |
|
450 | - } |
|
449 | + return $add_html; |
|
450 | + } |
|
451 | 451 | |
452 | 452 | private static function add_input_classes( $field, array &$class ) { |
453 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
454 | - $class[] = $field['input_class']; |
|
455 | - } |
|
453 | + if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
454 | + $class[] = $field['input_class']; |
|
455 | + } |
|
456 | 456 | |
457 | - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
458 | - return; |
|
459 | - } |
|
457 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
458 | + return; |
|
459 | + } |
|
460 | 460 | |
461 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
462 | - $class[] = 'auto_width'; |
|
463 | - } |
|
464 | - } |
|
461 | + if ( isset($field['size']) && $field['size'] > 0 ) { |
|
462 | + $class[] = 'auto_width'; |
|
463 | + } |
|
464 | + } |
|
465 | 465 | |
466 | 466 | private static function add_html_size( $field, array &$add_html ) { |
467 | 467 | if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'file', 'lookup' ) ) ) { |
468 | - return; |
|
469 | - } |
|
468 | + return; |
|
469 | + } |
|
470 | 470 | |
471 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
472 | - return; |
|
473 | - } |
|
471 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
472 | + return; |
|
473 | + } |
|
474 | 474 | |
475 | - if ( is_numeric($field['size']) ) { |
|
476 | - $field['size'] .= 'px'; |
|
477 | - } |
|
475 | + if ( is_numeric($field['size']) ) { |
|
476 | + $field['size'] .= 'px'; |
|
477 | + } |
|
478 | 478 | |
479 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
480 | - // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
479 | + $important = apply_filters('frm_use_important_width', 1, $field); |
|
480 | + // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
481 | 481 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
482 | 482 | |
483 | - self::add_html_cols($field, $add_html); |
|
484 | - } |
|
483 | + self::add_html_cols($field, $add_html); |
|
484 | + } |
|
485 | 485 | |
486 | 486 | private static function add_html_cols( $field, array &$add_html ) { |
487 | 487 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { |
488 | - return; |
|
489 | - } |
|
488 | + return; |
|
489 | + } |
|
490 | 490 | |
491 | - // convert to cols for textareas |
|
492 | - $calc = array( |
|
493 | - '' => 9, |
|
494 | - 'px' => 9, |
|
495 | - 'rem' => 0.444, |
|
496 | - 'em' => 0.544, |
|
497 | - ); |
|
491 | + // convert to cols for textareas |
|
492 | + $calc = array( |
|
493 | + '' => 9, |
|
494 | + 'px' => 9, |
|
495 | + 'rem' => 0.444, |
|
496 | + 'em' => 0.544, |
|
497 | + ); |
|
498 | 498 | |
499 | - // include "col" for valid html |
|
500 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
499 | + // include "col" for valid html |
|
500 | + $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
501 | 501 | |
502 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
503 | - return; |
|
504 | - } |
|
502 | + if ( ! isset( $calc[ $unit ] ) ) { |
|
503 | + return; |
|
504 | + } |
|
505 | 505 | |
506 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
506 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
507 | 507 | |
508 | 508 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
509 | - } |
|
509 | + } |
|
510 | 510 | |
511 | 511 | private static function add_html_length( $field, array &$add_html ) { |
512 | - // check for max setting and if this field accepts maxlength |
|
512 | + // check for max setting and if this field accepts maxlength |
|
513 | 513 | if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden', 'file' ) ) ) { |
514 | - return; |
|
515 | - } |
|
514 | + return; |
|
515 | + } |
|
516 | 516 | |
517 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
518 | - // don't load on form builder page |
|
519 | - return; |
|
520 | - } |
|
517 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
518 | + // don't load on form builder page |
|
519 | + return; |
|
520 | + } |
|
521 | 521 | |
522 | 522 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
523 | - } |
|
523 | + } |
|
524 | 524 | |
525 | 525 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
526 | 526 | if ( empty( $field['default_value'] ) || FrmAppHelper::is_admin_page( 'formidable' ) ) { |
@@ -528,35 +528,35 @@ discard block |
||
528 | 528 | } |
529 | 529 | |
530 | 530 | $default_value_array = is_array( $field['default_value'] ); |
531 | - if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
531 | + if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
532 | 532 | if ( $default_value_array ) { |
533 | 533 | $field['default_value'] = json_encode( $field['default_value'] ); |
534 | 534 | } |
535 | 535 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
536 | - return; |
|
537 | - } |
|
536 | + return; |
|
537 | + } |
|
538 | 538 | |
539 | 539 | if ( $default_value_array ) { |
540 | 540 | // don't include a json placeholder |
541 | 541 | return; |
542 | 542 | } |
543 | 543 | |
544 | - $frm_settings = FrmAppHelper::get_settings(); |
|
544 | + $frm_settings = FrmAppHelper::get_settings(); |
|
545 | 545 | |
546 | 546 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
547 | - // use HMTL5 placeholder with js fallback |
|
547 | + // use HMTL5 placeholder with js fallback |
|
548 | 548 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
549 | - wp_enqueue_script('jquery-placeholder'); |
|
550 | - } else if ( ! $frm_settings->use_html ) { |
|
549 | + wp_enqueue_script('jquery-placeholder'); |
|
550 | + } else if ( ! $frm_settings->use_html ) { |
|
551 | 551 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
552 | 552 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
553 | - $class[] = 'frm_toggle_default'; |
|
553 | + $class[] = 'frm_toggle_default'; |
|
554 | 554 | |
555 | - if ( $field['value'] == $field['default_value'] ) { |
|
556 | - $class[] = 'frm_default'; |
|
557 | - } |
|
558 | - } |
|
559 | - } |
|
555 | + if ( $field['value'] == $field['default_value'] ) { |
|
556 | + $class[] = 'frm_default'; |
|
557 | + } |
|
558 | + } |
|
559 | + } |
|
560 | 560 | |
561 | 561 | private static function add_validation_messages( $field, array &$add_html ) { |
562 | 562 | if ( FrmField::is_required( $field ) ) { |
@@ -570,44 +570,44 @@ discard block |
||
570 | 570 | } |
571 | 571 | } |
572 | 572 | |
573 | - private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
574 | - if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
575 | - return; |
|
576 | - } |
|
573 | + private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
574 | + if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
575 | + return; |
|
576 | + } |
|
577 | 577 | |
578 | - foreach ( $field['shortcodes'] as $k => $v ) { |
|
579 | - if ( 'opt' === $k ) { |
|
580 | - continue; |
|
581 | - } |
|
578 | + foreach ( $field['shortcodes'] as $k => $v ) { |
|
579 | + if ( 'opt' === $k ) { |
|
580 | + continue; |
|
581 | + } |
|
582 | 582 | |
583 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
584 | - $add_html[] = $v; |
|
585 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
583 | + if ( is_numeric($k) && strpos($v, '=') ) { |
|
584 | + $add_html[] = $v; |
|
585 | + } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
586 | 586 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
587 | - } else { |
|
587 | + } else { |
|
588 | 588 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
589 | - } |
|
590 | - |
|
591 | - unset($k, $v); |
|
592 | - } |
|
593 | - } |
|
594 | - |
|
595 | - public static function check_value( $opt, $opt_key, $field ) { |
|
596 | - if ( is_array( $opt ) ) { |
|
597 | - if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
598 | - $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
599 | - } else { |
|
600 | - $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
601 | - } |
|
602 | - } |
|
603 | - return $opt; |
|
604 | - } |
|
589 | + } |
|
590 | + |
|
591 | + unset($k, $v); |
|
592 | + } |
|
593 | + } |
|
594 | + |
|
595 | + public static function check_value( $opt, $opt_key, $field ) { |
|
596 | + if ( is_array( $opt ) ) { |
|
597 | + if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
598 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
599 | + } else { |
|
600 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
601 | + } |
|
602 | + } |
|
603 | + return $opt; |
|
604 | + } |
|
605 | 605 | |
606 | 606 | public static function check_label( $opt ) { |
607 | - if ( is_array($opt) ) { |
|
608 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
609 | - } |
|
607 | + if ( is_array($opt) ) { |
|
608 | + $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
609 | + } |
|
610 | 610 | |
611 | - return $opt; |
|
612 | - } |
|
611 | + return $opt; |
|
612 | + } |
|
613 | 613 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | class FrmFieldsController { |
4 | 4 | |
5 | 5 | public static function load_field() { |
6 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
6 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
7 | 7 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
8 | 8 | |
9 | 9 | $fields = $_POST['field']; |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | $field_name = 'item_meta[' . $field_id . ']'; |
37 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
37 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
38 | 38 | |
39 | 39 | ob_start(); |
40 | 40 | include( $path . '/classes/views/frm-forms/add_field.php' ); |
41 | - $field_html[ $field_id ] = ob_get_contents(); |
|
41 | + $field_html[$field_id] = ob_get_contents(); |
|
42 | 42 | ob_end_clean(); |
43 | 43 | } |
44 | 44 | |
45 | - unset($path); |
|
45 | + unset( $path ); |
|
46 | 46 | |
47 | - echo json_encode($field_html); |
|
47 | + echo json_encode( $field_html ); |
|
48 | 48 | |
49 | 49 | wp_die(); |
50 | 50 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * Create a new field with ajax |
54 | 54 | */ |
55 | 55 | public static function create() { |
56 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
56 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
57 | 57 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
58 | 58 | |
59 | 59 | $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $field = self::include_new_field( $field_type, $form_id ); |
63 | 63 | |
64 | 64 | // this hook will allow for multiple fields to be added at once |
65 | - do_action('frm_after_field_created', $field, $form_id); |
|
65 | + do_action( 'frm_after_field_created', $field, $form_id ); |
|
66 | 66 | |
67 | 67 | wp_die(); |
68 | 68 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | public static function include_new_field( $field_type, $form_id ) { |
78 | 78 | $values = array(); |
79 | 79 | if ( FrmAppHelper::pro_is_installed() ) { |
80 | - $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
80 | + $values['post_type'] = FrmProFormsHelper::post_type( $form_id ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
@@ -89,27 +89,27 @@ discard block |
||
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
92 | - $field = self::include_single_field($field_id, $values, $form_id); |
|
92 | + $field = self::include_single_field( $field_id, $values, $form_id ); |
|
93 | 93 | |
94 | 94 | return $field; |
95 | 95 | } |
96 | 96 | |
97 | 97 | public static function edit_name( $field = 'name', $id = '' ) { |
98 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
98 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
99 | 99 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
100 | 100 | |
101 | - if ( empty($field) ) { |
|
101 | + if ( empty( $field ) ) { |
|
102 | 102 | $field = 'name'; |
103 | 103 | } |
104 | 104 | |
105 | - if ( empty($id) ) { |
|
105 | + if ( empty( $id ) ) { |
|
106 | 106 | $id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
107 | 107 | $id = str_replace( 'field_label_', '', $id ); |
108 | 108 | } |
109 | 109 | |
110 | 110 | $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ); |
111 | 111 | $value = trim( $value ); |
112 | - if ( trim(strip_tags($value)) == '' ) { |
|
112 | + if ( trim( strip_tags( $value ) ) == '' ) { |
|
113 | 113 | // set blank value if there is no content |
114 | 114 | $value = ''; |
115 | 115 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | public static function update_ajax_option() { |
126 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
126 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
127 | 127 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
128 | 128 | |
129 | 129 | $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' ); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | if ( isset( $_POST['separate_value'] ) ) { |
137 | 137 | $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1; |
138 | 138 | $field->field_options['separate_value'] = $new_val; |
139 | - unset($new_val); |
|
139 | + unset( $new_val ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | FrmField::update( $field_id, array( |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | public static function duplicate() { |
150 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
150 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
151 | 151 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
152 | 152 | |
153 | 153 | global $wpdb; |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | |
173 | 173 | $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
174 | 174 | |
175 | - if ( ! $field_id = FrmField::create($values) ) { |
|
175 | + if ( ! $field_id = FrmField::create( $values ) ) { |
|
176 | 176 | wp_die(); |
177 | 177 | } |
178 | 178 | |
179 | - self::include_single_field($field_id, $values); |
|
179 | + self::include_single_field( $field_id, $values ); |
|
180 | 180 | |
181 | 181 | wp_die(); |
182 | 182 | } |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | * Load a single field in the form builder along with all needed variables |
186 | 186 | */ |
187 | 187 | public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
188 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
188 | + $field = FrmFieldsHelper::setup_edit_vars( FrmField::getOne( $field_id ) ); |
|
189 | 189 | $field_name = 'item_meta[' . $field_id . ']'; |
190 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
190 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
191 | 191 | $id = $form_id ? $form_id : $field['form_id']; |
192 | 192 | if ( $field['type'] == 'html' ) { |
193 | 193 | $field['stop_filter'] = true; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | public static function destroy() { |
202 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
202 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
203 | 203 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
204 | 204 | |
205 | 205 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | |
212 | 212 | //Add Single Option or Other Option |
213 | 213 | public static function add_option() { |
214 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
214 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
215 | 215 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
216 | 216 | |
217 | 217 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
218 | 218 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
219 | 219 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' ); |
220 | 220 | |
221 | - $field = FrmField::getOne($id); |
|
221 | + $field = FrmField::getOne( $id ); |
|
222 | 222 | |
223 | 223 | if ( 'other' == $opt_type ) { |
224 | 224 | $opt = __( 'Other', 'formidable' ); |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | |
288 | 288 | $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
289 | 289 | $prepop = array(); |
290 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
290 | + FrmFieldsHelper::get_bulk_prefilled_opts( $prepop ); |
|
291 | 291 | |
292 | - $field = FrmField::getOne($field_id); |
|
292 | + $field = FrmField::getOne( $field_id ); |
|
293 | 293 | |
294 | 294 | wp_enqueue_script( 'utils' ); |
295 | 295 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
@@ -300,35 +300,35 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | public static function import_options() { |
303 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
303 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
304 | 304 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
305 | 305 | |
306 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
306 | + if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
|
307 | 307 | return; |
308 | 308 | } |
309 | 309 | |
310 | 310 | $field_id = absint( $_POST['field_id'] ); |
311 | - $field = FrmField::getOne($field_id); |
|
311 | + $field = FrmField::getOne( $field_id ); |
|
312 | 312 | |
313 | 313 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
314 | 314 | return; |
315 | 315 | } |
316 | 316 | |
317 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
317 | + $field = FrmFieldsHelper::setup_edit_vars( $field ); |
|
318 | 318 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
319 | 319 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
320 | 320 | $opts = array_map( 'trim', $opts ); |
321 | 321 | |
322 | 322 | if ( $field['separate_value'] ) { |
323 | 323 | foreach ( $opts as $opt_key => $opt ) { |
324 | - if ( strpos($opt, '|') !== false ) { |
|
325 | - $vals = explode('|', $opt); |
|
324 | + if ( strpos( $opt, '|' ) !== false ) { |
|
325 | + $vals = explode( '|', $opt ); |
|
326 | 326 | if ( $vals[0] != $vals[1] ) { |
327 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
327 | + $opts[$opt_key] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
328 | 328 | } |
329 | - unset($vals); |
|
329 | + unset( $vals ); |
|
330 | 330 | } |
331 | - unset($opt_key, $opt); |
|
331 | + unset( $opt_key, $opt ); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
@@ -337,12 +337,12 @@ discard block |
||
337 | 337 | $other_array = array(); |
338 | 338 | foreach ( $field['options'] as $opt_key => $opt ) { |
339 | 339 | if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
340 | - $other_array[ $opt_key ] = $opt; |
|
340 | + $other_array[$opt_key] = $opt; |
|
341 | 341 | } |
342 | - unset($opt_key, $opt); |
|
342 | + unset( $opt_key, $opt ); |
|
343 | 343 | } |
344 | - if ( ! empty($other_array) ) { |
|
345 | - $opts = array_merge( $opts, $other_array); |
|
344 | + if ( ! empty( $other_array ) ) { |
|
345 | + $opts = array_merge( $opts, $other_array ); |
|
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
@@ -356,14 +356,14 @@ discard block |
||
356 | 356 | |
357 | 357 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
358 | 358 | } else { |
359 | - FrmFieldsHelper::show_single_option($field); |
|
359 | + FrmFieldsHelper::show_single_option( $field ); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | wp_die(); |
363 | 363 | } |
364 | 364 | |
365 | 365 | public static function update_order() { |
366 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
366 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
367 | 367 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
368 | 368 | |
369 | 369 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
@@ -380,13 +380,13 @@ discard block |
||
380 | 380 | 'rte' => 'textarea', |
381 | 381 | 'website' => 'url', |
382 | 382 | ); |
383 | - if ( isset( $type_switch[ $type ] ) ) { |
|
384 | - $type = $type_switch[ $type ]; |
|
383 | + if ( isset( $type_switch[$type] ) ) { |
|
384 | + $type = $type_switch[$type]; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | $frm_field_selection = FrmField::field_selection(); |
388 | - $types = array_keys($frm_field_selection); |
|
389 | - if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
388 | + $types = array_keys( $frm_field_selection ); |
|
389 | + if ( ! in_array( $type, $types ) && $type != 'captcha' ) { |
|
390 | 390 | $type = 'text'; |
391 | 391 | } |
392 | 392 | |
@@ -425,19 +425,19 @@ discard block |
||
425 | 425 | |
426 | 426 | public static function input_html( $field, $echo = true ) { |
427 | 427 | $class = array(); //$field['type']; |
428 | - self::add_input_classes($field, $class); |
|
428 | + self::add_input_classes( $field, $class ); |
|
429 | 429 | |
430 | 430 | $add_html = array(); |
431 | - self::add_html_size($field, $add_html); |
|
432 | - self::add_html_length($field, $add_html); |
|
433 | - self::add_html_placeholder($field, $add_html, $class); |
|
431 | + self::add_html_size( $field, $add_html ); |
|
432 | + self::add_html_length( $field, $add_html ); |
|
433 | + self::add_html_placeholder( $field, $add_html, $class ); |
|
434 | 434 | self::add_validation_messages( $field, $add_html ); |
435 | 435 | |
436 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
436 | + $class = apply_filters( 'frm_field_classes', implode( ' ', $class ), $field ); |
|
437 | 437 | |
438 | 438 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
439 | 439 | |
440 | - self::add_shortcodes_to_html($field, $add_html); |
|
440 | + self::add_shortcodes_to_html( $field, $add_html ); |
|
441 | 441 | |
442 | 442 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
443 | 443 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | } |
451 | 451 | |
452 | 452 | private static function add_input_classes( $field, array &$class ) { |
453 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
453 | + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) { |
|
454 | 454 | $class[] = $field['input_class']; |
455 | 455 | } |
456 | 456 | |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
461 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
461 | + if ( isset( $field['size'] ) && $field['size'] > 0 ) { |
|
462 | 462 | $class[] = 'auto_width'; |
463 | 463 | } |
464 | 464 | } |
@@ -468,19 +468,19 @@ discard block |
||
468 | 468 | return; |
469 | 469 | } |
470 | 470 | |
471 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
471 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
472 | 472 | return; |
473 | 473 | } |
474 | 474 | |
475 | - if ( is_numeric($field['size']) ) { |
|
475 | + if ( is_numeric( $field['size'] ) ) { |
|
476 | 476 | $field['size'] .= 'px'; |
477 | 477 | } |
478 | 478 | |
479 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
479 | + $important = apply_filters( 'frm_use_important_width', 1, $field ); |
|
480 | 480 | // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
481 | 481 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
482 | 482 | |
483 | - self::add_html_cols($field, $add_html); |
|
483 | + self::add_html_cols( $field, $add_html ); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | private static function add_html_cols( $field, array &$add_html ) { |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | ); |
498 | 498 | |
499 | 499 | // include "col" for valid html |
500 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
500 | + $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
|
501 | 501 | |
502 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
502 | + if ( ! isset( $calc[$unit] ) ) { |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | |
506 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
506 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[$unit]; |
|
507 | 507 | |
508 | 508 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
509 | 509 | } |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
517 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
518 | 518 | // don't load on form builder page |
519 | 519 | return; |
520 | 520 | } |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
547 | 547 | // use HMTL5 placeholder with js fallback |
548 | 548 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
549 | - wp_enqueue_script('jquery-placeholder'); |
|
549 | + wp_enqueue_script( 'jquery-placeholder' ); |
|
550 | 550 | } else if ( ! $frm_settings->use_html ) { |
551 | 551 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
552 | 552 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
@@ -580,15 +580,15 @@ discard block |
||
580 | 580 | continue; |
581 | 581 | } |
582 | 582 | |
583 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
583 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { |
|
584 | 584 | $add_html[] = $v; |
585 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
586 | - $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
|
585 | + } else if ( ! empty( $k ) && isset( $add_html[$k] ) ) { |
|
586 | + $add_html[$k] = str_replace( $k . '="', $k . '="' . $v, $add_html[$k] ); |
|
587 | 587 | } else { |
588 | - $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
|
588 | + $add_html[$k] = $k . '="' . esc_attr( $v ) . '"'; |
|
589 | 589 | } |
590 | 590 | |
591 | - unset($k, $v); |
|
591 | + unset( $k, $v ); |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | |
@@ -604,8 +604,8 @@ discard block |
||
604 | 604 | } |
605 | 605 | |
606 | 606 | public static function check_label( $opt ) { |
607 | - if ( is_array($opt) ) { |
|
608 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
607 | + if ( is_array( $opt ) ) { |
|
608 | + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | return $opt; |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | if ( ! FrmAppHelper::pro_is_installed() ) { |
8 | 8 | $menu_label .= ' (Lite)'; |
9 | 9 | } |
10 | - add_submenu_page('formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' ); |
|
10 | + add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' ); |
|
11 | 11 | |
12 | 12 | self::maybe_load_listing_hooks(); |
13 | 13 | } |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | return; |
19 | 19 | } |
20 | 20 | |
21 | - add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' ); |
|
21 | + add_filter( 'get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' ); |
|
22 | 22 | |
23 | - add_filter('manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 ); |
|
24 | - add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' ); |
|
23 | + add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 ); |
|
24 | + add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' ); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public static function head() { |
28 | - wp_enqueue_script('formidable-editinplace'); |
|
28 | + wp_enqueue_script( 'formidable-editinplace' ); |
|
29 | 29 | |
30 | 30 | if ( wp_is_mobile() ) { |
31 | 31 | wp_enqueue_script( 'jquery-touch-punch' ); |
@@ -33,39 +33,39 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | public static function register_widgets() { |
36 | - require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php'); |
|
37 | - register_widget('FrmShowForm'); |
|
36 | + require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' ); |
|
37 | + register_widget( 'FrmShowForm' ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public static function list_form() { |
41 | - FrmAppHelper::permission_check('frm_view_forms'); |
|
41 | + FrmAppHelper::permission_check( 'frm_view_forms' ); |
|
42 | 42 | |
43 | 43 | $params = FrmForm::list_page_params(); |
44 | - $errors = self::process_bulk_form_actions( array()); |
|
45 | - $errors = apply_filters('frm_admin_list_form_action', $errors); |
|
44 | + $errors = self::process_bulk_form_actions( array() ); |
|
45 | + $errors = apply_filters( 'frm_admin_list_form_action', $errors ); |
|
46 | 46 | |
47 | 47 | return self::display_forms_list( $params, '', $errors ); |
48 | 48 | } |
49 | 49 | |
50 | 50 | public static function new_form( $values = array() ) { |
51 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
51 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
52 | 52 | |
53 | 53 | global $frm_vars; |
54 | 54 | |
55 | - $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
56 | - $action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ]; |
|
55 | + $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
56 | + $action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[$action]; |
|
57 | 57 | |
58 | 58 | if ( $action == 'create' ) { |
59 | - return self::create($values); |
|
59 | + return self::create( $values ); |
|
60 | 60 | } else if ( $action == 'new' ) { |
61 | 61 | $frm_field_selection = FrmField::field_selection(); |
62 | - $values = FrmFormsHelper::setup_new_vars($values); |
|
62 | + $values = FrmFormsHelper::setup_new_vars( $values ); |
|
63 | 63 | $id = FrmForm::create( $values ); |
64 | - $form = FrmForm::getOne($id); |
|
64 | + $form = FrmForm::getOne( $id ); |
|
65 | 65 | |
66 | 66 | // add default email notification |
67 | 67 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
68 | - $action_control->create($form->id); |
|
68 | + $action_control->create( $form->id ); |
|
69 | 69 | |
70 | 70 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | public static function create( $values = array() ) { |
78 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
78 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
79 | 79 | |
80 | 80 | global $frm_vars; |
81 | 81 | if ( empty( $values ) ) { |
@@ -87,22 +87,22 @@ discard block |
||
87 | 87 | $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
88 | 88 | } |
89 | 89 | |
90 | - $id = isset($values['id']) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
|
90 | + $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
|
91 | 91 | |
92 | 92 | if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) { |
93 | 93 | $frm_settings = FrmAppHelper::get_settings(); |
94 | 94 | $errors = array( 'form' => $frm_settings->admin_permission ); |
95 | 95 | } else { |
96 | - $errors = FrmForm::validate($values); |
|
96 | + $errors = FrmForm::validate( $values ); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( count($errors) > 0 ) { |
|
99 | + if ( count( $errors ) > 0 ) { |
|
100 | 100 | $hide_preview = true; |
101 | 101 | $frm_field_selection = FrmField::field_selection(); |
102 | 102 | $form = FrmForm::getOne( $id ); |
103 | - $fields = FrmField::get_all_for_form($id); |
|
103 | + $fields = FrmField::get_all_for_form( $id ); |
|
104 | 104 | |
105 | - $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true); |
|
105 | + $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true ); |
|
106 | 106 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
107 | 107 | |
108 | 108 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
@@ -114,32 +114,32 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | public static function edit( $values = false ) { |
117 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
117 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
118 | 118 | |
119 | 119 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
120 | - return self::get_edit_vars($id); |
|
120 | + return self::get_edit_vars( $id ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | public static function settings( $id = false, $message = '' ) { |
124 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
124 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
125 | 125 | |
126 | - if ( ! $id || ! is_numeric($id) ) { |
|
126 | + if ( ! $id || ! is_numeric( $id ) ) { |
|
127 | 127 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
128 | 128 | } |
129 | 129 | return self::get_settings_vars( $id, array(), $message ); |
130 | 130 | } |
131 | 131 | |
132 | 132 | public static function update_settings() { |
133 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
133 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
134 | 134 | |
135 | 135 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
136 | 136 | |
137 | - $errors = FrmForm::validate($_POST); |
|
138 | - if ( count($errors) > 0 ) { |
|
139 | - return self::get_settings_vars($id, $errors); |
|
137 | + $errors = FrmForm::validate( $_POST ); |
|
138 | + if ( count( $errors ) > 0 ) { |
|
139 | + return self::get_settings_vars( $id, $errors ); |
|
140 | 140 | } |
141 | 141 | |
142 | - do_action('frm_before_update_form_settings', $id); |
|
142 | + do_action( 'frm_before_update_form_settings', $id ); |
|
143 | 143 | |
144 | 144 | FrmForm::update( $id, $_POST ); |
145 | 145 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | private static function edit_in_place_value( $field ) { |
163 | 163 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
164 | - FrmAppHelper::permission_check('frm_edit_forms', 'hide'); |
|
164 | + FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
165 | 165 | |
166 | 166 | $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); |
167 | 167 | $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_filter_post_kses' ); |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @since 2.0 |
220 | 220 | */ |
221 | 221 | public static function _create_from_template() { |
222 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
222 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
223 | 223 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
224 | 224 | |
225 | 225 | $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' ); |
@@ -234,15 +234,15 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | public static function duplicate() { |
237 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
237 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
238 | 238 | |
239 | 239 | $params = FrmForm::list_page_params(); |
240 | 240 | $form = FrmForm::duplicate( $params['id'], $params['template'], true ); |
241 | - $message = ($params['template']) ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' ); |
|
241 | + $message = ( $params['template'] ) ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' ); |
|
242 | 242 | if ( $form ) { |
243 | 243 | return self::get_edit_vars( $form, array(), $message, true ); |
244 | 244 | } else { |
245 | - return self::display_forms_list($params, __( 'There was a problem creating the new template.', 'formidable' )); |
|
245 | + return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) ); |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | public static function bulk_untrash( $ids ) { |
308 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
308 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
309 | 309 | |
310 | 310 | $count = FrmForm::set_status( $ids, 'published' ); |
311 | 311 | |
312 | - $message = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 ); |
|
312 | + $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 ); |
|
313 | 313 | return $message; |
314 | 314 | } |
315 | 315 | |
@@ -328,11 +328,11 @@ discard block |
||
328 | 328 | 'trash' => array( 'permission' => 'frm_delete_forms', 'new_status' => 'trash' ), |
329 | 329 | ); |
330 | 330 | |
331 | - if ( ! isset( $available_status[ $status ] ) ) { |
|
331 | + if ( ! isset( $available_status[$status] ) ) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | |
335 | - FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
|
335 | + FrmAppHelper::permission_check( $available_status[$status]['permission'] ); |
|
336 | 336 | |
337 | 337 | $params = FrmForm::list_page_params(); |
338 | 338 | |
@@ -340,25 +340,25 @@ discard block |
||
340 | 340 | check_admin_referer( $status . '_form_' . $params['id'] ); |
341 | 341 | |
342 | 342 | $count = 0; |
343 | - if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
|
344 | - $count++; |
|
343 | + if ( FrmForm::set_status( $params['id'], $available_status[$status]['new_status'] ) ) { |
|
344 | + $count ++; |
|
345 | 345 | } |
346 | 346 | |
347 | - $available_status['untrash']['message'] = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count ); |
|
347 | + $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count ); |
|
348 | 348 | $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . ( isset( $_REQUEST['form_type'] ) ? sanitize_title( $_REQUEST['form_type'] ) : '' ) . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' ); |
349 | 349 | |
350 | - $message = $available_status[ $status ]['message']; |
|
350 | + $message = $available_status[$status]['message']; |
|
351 | 351 | |
352 | 352 | self::display_forms_list( $params, $message ); |
353 | 353 | } |
354 | 354 | |
355 | 355 | public static function bulk_trash( $ids ) { |
356 | - FrmAppHelper::permission_check('frm_delete_forms'); |
|
356 | + FrmAppHelper::permission_check( 'frm_delete_forms' ); |
|
357 | 357 | |
358 | 358 | $count = 0; |
359 | 359 | foreach ( $ids as $id ) { |
360 | 360 | if ( FrmForm::trash( $id ) ) { |
361 | - $count++; |
|
361 | + $count ++; |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | |
@@ -369,49 +369,49 @@ discard block |
||
369 | 369 | } |
370 | 370 | |
371 | 371 | public static function destroy() { |
372 | - FrmAppHelper::permission_check('frm_delete_forms'); |
|
372 | + FrmAppHelper::permission_check( 'frm_delete_forms' ); |
|
373 | 373 | |
374 | 374 | $params = FrmForm::list_page_params(); |
375 | 375 | |
376 | 376 | //check nonce url |
377 | - check_admin_referer('destroy_form_' . $params['id']); |
|
377 | + check_admin_referer( 'destroy_form_' . $params['id'] ); |
|
378 | 378 | |
379 | 379 | $count = 0; |
380 | 380 | if ( FrmForm::destroy( $params['id'] ) ) { |
381 | - $count++; |
|
381 | + $count ++; |
|
382 | 382 | } |
383 | 383 | |
384 | - $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
384 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
|
385 | 385 | |
386 | 386 | self::display_forms_list( $params, $message ); |
387 | 387 | } |
388 | 388 | |
389 | 389 | public static function bulk_destroy( $ids ) { |
390 | - FrmAppHelper::permission_check('frm_delete_forms'); |
|
390 | + FrmAppHelper::permission_check( 'frm_delete_forms' ); |
|
391 | 391 | |
392 | 392 | $count = 0; |
393 | 393 | foreach ( $ids as $id ) { |
394 | 394 | $d = FrmForm::destroy( $id ); |
395 | 395 | if ( $d ) { |
396 | - $count++; |
|
396 | + $count ++; |
|
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | - $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
400 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
|
401 | 401 | |
402 | 402 | return $message; |
403 | 403 | } |
404 | 404 | |
405 | 405 | private static function delete_all() { |
406 | 406 | //check nonce url |
407 | - $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable'); |
|
407 | + $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
|
408 | 408 | if ( $permission_error !== false ) { |
409 | 409 | self::display_forms_list( array(), '', array( $permission_error ) ); |
410 | 410 | return; |
411 | 411 | } |
412 | 412 | |
413 | 413 | $count = FrmForm::scheduled_delete( time() ); |
414 | - $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
414 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); |
|
415 | 415 | |
416 | 416 | self::display_forms_list( array(), $message ); |
417 | 417 | } |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * @since 2.0.15 |
429 | 429 | */ |
430 | 430 | public static function insert_form_button() { |
431 | - if ( current_user_can('frm_view_forms') ) { |
|
431 | + if ( current_user_can( 'frm_view_forms' ) ) { |
|
432 | 432 | $menu_name = FrmAppHelper::get_menu_name(); |
433 | 433 | $content = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '"> |
434 | 434 | <span class="frm-buttons-icon wp-media-buttons-icon"></span> ' . |
@@ -449,17 +449,17 @@ discard block |
||
449 | 449 | 'formidable' => array( 'name' => __( 'Form', 'formidable' ), 'label' => __( 'Insert a Form', 'formidable' ) ), |
450 | 450 | ); |
451 | 451 | |
452 | - $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes); |
|
452 | + $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes ); |
|
453 | 453 | |
454 | 454 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' ); |
455 | 455 | } |
456 | 456 | |
457 | 457 | public static function get_shortcode_opts() { |
458 | - FrmAppHelper::permission_check('frm_view_forms'); |
|
458 | + FrmAppHelper::permission_check( 'frm_view_forms' ); |
|
459 | 459 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
460 | 460 | |
461 | 461 | $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' ); |
462 | - if ( empty($shortcode) ) { |
|
462 | + if ( empty( $shortcode ) ) { |
|
463 | 463 | wp_die(); |
464 | 464 | } |
465 | 465 | |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | ); |
480 | 480 | break; |
481 | 481 | } |
482 | - $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode); |
|
482 | + $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode ); |
|
483 | 483 | |
484 | 484 | if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) { |
485 | 485 | // allow other shortcodes to use the required form id option |
@@ -596,11 +596,11 @@ discard block |
||
596 | 596 | } |
597 | 597 | |
598 | 598 | if ( $form->parent_form_id ) { |
599 | - wp_die( sprintf( __( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' )); |
|
599 | + wp_die( sprintf( __( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' ) ); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | $frm_field_selection = FrmField::field_selection(); |
603 | - $fields = FrmField::get_all_for_form($form->id); |
|
603 | + $fields = FrmField::get_all_for_form( $form->id ); |
|
604 | 604 | |
605 | 605 | // Automatically add end section fields if they don't exist (2.0 migration) |
606 | 606 | $reset_fields = false; |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
611 | 611 | } |
612 | 612 | |
613 | - unset($end_section_values, $last_order, $open, $reset_fields); |
|
613 | + unset( $end_section_values, $last_order, $open, $reset_fields ); |
|
614 | 614 | |
615 | 615 | $args = array( 'parent_form_id' => $form->id ); |
616 | 616 | $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true, array(), $args ); |
@@ -623,8 +623,8 @@ discard block |
||
623 | 623 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
624 | 624 | |
625 | 625 | if ( $form->default_template ) { |
626 | - wp_die(__( 'That template cannot be edited', 'formidable' )); |
|
627 | - } else if ( defined('DOING_AJAX') ) { |
|
626 | + wp_die( __( 'That template cannot be edited', 'formidable' ) ); |
|
627 | + } else if ( defined( 'DOING_AJAX' ) ) { |
|
628 | 628 | wp_die(); |
629 | 629 | } else if ( $create_link ) { |
630 | 630 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
@@ -640,28 +640,28 @@ discard block |
||
640 | 640 | |
641 | 641 | $form = FrmForm::getOne( $id ); |
642 | 642 | |
643 | - $fields = FrmField::get_all_for_form($id); |
|
644 | - $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true); |
|
643 | + $fields = FrmField::get_all_for_form( $id ); |
|
644 | + $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true ); |
|
645 | 645 | |
646 | - if ( isset($values['default_template']) && $values['default_template'] ) { |
|
647 | - wp_die(__( 'That template cannot be edited', 'formidable' )); |
|
646 | + if ( isset( $values['default_template'] ) && $values['default_template'] ) { |
|
647 | + wp_die( __( 'That template cannot be edited', 'formidable' ) ); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | $action_controls = FrmFormActionsController::get_form_actions(); |
651 | 651 | |
652 | - $sections = apply_filters('frm_add_form_settings_section', array(), $values); |
|
652 | + $sections = apply_filters( 'frm_add_form_settings_section', array(), $values ); |
|
653 | 653 | $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"'; |
654 | 654 | |
655 | - $styles = apply_filters('frm_get_style_opts', array()); |
|
655 | + $styles = apply_filters( 'frm_get_style_opts', array() ); |
|
656 | 656 | |
657 | 657 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); |
658 | 658 | } |
659 | 659 | |
660 | 660 | public static function mb_tags_box( $form_id, $class = '' ) { |
661 | - $fields = FrmField::get_all_for_form($form_id, '', 'include'); |
|
661 | + $fields = FrmField::get_all_for_form( $form_id, '', 'include' ); |
|
662 | 662 | $linked_forms = array(); |
663 | 663 | $col = 'one'; |
664 | - $settings_tab = FrmAppHelper::is_admin_page('formidable' ) ? true : false; |
|
664 | + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false; |
|
665 | 665 | |
666 | 666 | $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() ); |
667 | 667 | $adv_shortcodes = self::get_advanced_shortcodes(); |
@@ -739,13 +739,13 @@ discard block |
||
739 | 739 | |
740 | 740 | // Insert the form class setting into the form |
741 | 741 | public static function form_classes( $form ) { |
742 | - if ( isset($form->options['form_class']) ) { |
|
742 | + if ( isset( $form->options['form_class'] ) ) { |
|
743 | 743 | echo esc_attr( sanitize_text_field( $form->options['form_class'] ) ); |
744 | 744 | } |
745 | 745 | } |
746 | 746 | |
747 | 747 | public static function get_email_html() { |
748 | - FrmAppHelper::permission_check('frm_view_forms'); |
|
748 | + FrmAppHelper::permission_check( 'frm_view_forms' ); |
|
749 | 749 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
750 | 750 | echo FrmEntryFormat::show_entry( array( |
751 | 751 | 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), |
@@ -842,11 +842,11 @@ discard block |
||
842 | 842 | public static function add_default_templates( $path, $default = true, $template = true ) { |
843 | 843 | _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' ); |
844 | 844 | |
845 | - $path = untrailingslashit(trim($path)); |
|
845 | + $path = untrailingslashit( trim( $path ) ); |
|
846 | 846 | $templates = glob( $path . '/*.php' ); |
847 | 847 | |
848 | - for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) { |
|
849 | - $filename = str_replace( '.php', '', str_replace( $path . '/', '', $templates[ $i ] ) ); |
|
848 | + for ( $i = count( $templates ) - 1; $i >= 0; $i -- ) { |
|
849 | + $filename = str_replace( '.php', '', str_replace( $path . '/', '', $templates[$i] ) ); |
|
850 | 850 | $template_query = array( 'form_key' => $filename ); |
851 | 851 | if ( $template ) { |
852 | 852 | $template_query['is_template'] = 1; |
@@ -864,12 +864,12 @@ discard block |
||
864 | 864 | $values['default_template'] = 1; |
865 | 865 | } |
866 | 866 | |
867 | - include( $templates[ $i ] ); |
|
867 | + include( $templates[$i] ); |
|
868 | 868 | |
869 | 869 | //get updated form |
870 | - if ( isset($form) && ! empty($form) ) { |
|
870 | + if ( isset( $form ) && ! empty( $form ) ) { |
|
871 | 871 | $old_id = $form->id; |
872 | - $form = FrmForm::getOne($form->id); |
|
872 | + $form = FrmForm::getOne( $form->id ); |
|
873 | 873 | } else { |
874 | 874 | $old_id = false; |
875 | 875 | $form = FrmForm::getAll( $template_query, '', 1 ); |
@@ -882,24 +882,24 @@ discard block |
||
882 | 882 | } |
883 | 883 | |
884 | 884 | public static function route() { |
885 | - $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
885 | + $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
886 | 886 | $vars = array(); |
887 | 887 | if ( isset( $_POST['frm_compact_fields'] ) ) { |
888 | 888 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
889 | 889 | |
890 | - $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('"', '\\\"', $_POST['frm_compact_fields'] )))); |
|
891 | - $json_vars = json_decode($json_vars, true); |
|
892 | - if ( empty($json_vars) ) { |
|
890 | + $json_vars = htmlspecialchars_decode( nl2br( stripslashes( str_replace( '"', '\\\"', $_POST['frm_compact_fields'] ) ) ) ); |
|
891 | + $json_vars = json_decode( $json_vars, true ); |
|
892 | + if ( empty( $json_vars ) ) { |
|
893 | 893 | // json decoding failed so we should return an error message |
894 | 894 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
895 | 895 | if ( 'edit' == $action ) { |
896 | 896 | $action = 'update'; |
897 | 897 | } |
898 | 898 | |
899 | - add_filter('frm_validate_form', 'FrmFormsController::json_error'); |
|
899 | + add_filter( 'frm_validate_form', 'FrmFormsController::json_error' ); |
|
900 | 900 | } else { |
901 | - $vars = FrmAppHelper::json_to_array($json_vars); |
|
902 | - $action = $vars[ $action ]; |
|
901 | + $vars = FrmAppHelper::json_to_array( $json_vars ); |
|
902 | + $action = $vars[$action]; |
|
903 | 903 | unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); |
904 | 904 | $_REQUEST = array_merge( $_REQUEST, $vars ); |
905 | 905 | $_POST = array_merge( $_POST, $_REQUEST ); |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | |
918 | 918 | switch ( $action ) { |
919 | 919 | case 'new': |
920 | - return self::new_form($vars); |
|
920 | + return self::new_form( $vars ); |
|
921 | 921 | case 'create': |
922 | 922 | case 'edit': |
923 | 923 | case 'update': |
@@ -940,7 +940,7 @@ discard block |
||
940 | 940 | $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' ); |
941 | 941 | } |
942 | 942 | |
943 | - if ( strpos($action, 'bulk_') === 0 ) { |
|
943 | + if ( strpos( $action, 'bulk_' ) === 0 ) { |
|
944 | 944 | FrmAppHelper::remove_get_action(); |
945 | 945 | return self::list_form(); |
946 | 946 | } |
@@ -967,27 +967,27 @@ discard block |
||
967 | 967 | |
968 | 968 | public static function admin_bar_configure() { |
969 | 969 | global $frm_vars; |
970 | - if ( empty($frm_vars['forms_loaded']) ) { |
|
970 | + if ( empty( $frm_vars['forms_loaded'] ) ) { |
|
971 | 971 | return; |
972 | 972 | } |
973 | 973 | |
974 | 974 | $actions = array(); |
975 | 975 | foreach ( $frm_vars['forms_loaded'] as $form ) { |
976 | - if ( is_object($form) ) { |
|
977 | - $actions[ $form->id ] = $form->name; |
|
976 | + if ( is_object( $form ) ) { |
|
977 | + $actions[$form->id] = $form->name; |
|
978 | 978 | } |
979 | - unset($form); |
|
979 | + unset( $form ); |
|
980 | 980 | } |
981 | 981 | |
982 | - if ( empty($actions) ) { |
|
982 | + if ( empty( $actions ) ) { |
|
983 | 983 | return; |
984 | 984 | } |
985 | 985 | |
986 | - asort($actions); |
|
986 | + asort( $actions ); |
|
987 | 987 | |
988 | 988 | global $wp_admin_bar; |
989 | 989 | |
990 | - if ( count($actions) == 1 ) { |
|
990 | + if ( count( $actions ) == 1 ) { |
|
991 | 991 | $wp_admin_bar->add_menu( array( |
992 | 992 | 'title' => 'Edit Form', |
993 | 993 | 'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . current( array_keys( $actions ) ) ), |
@@ -1008,7 +1008,7 @@ discard block |
||
1008 | 1008 | $wp_admin_bar->add_menu( array( |
1009 | 1009 | 'parent' => 'frm-forms', |
1010 | 1010 | 'id' => 'edit_form_' . $form_id, |
1011 | - 'title' => empty($name) ? __( '(no title)') : $name, |
|
1011 | + 'title' => empty( $name ) ? __( '(no title)' ) : $name, |
|
1012 | 1012 | 'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ), |
1013 | 1013 | ) ); |
1014 | 1014 | } |
@@ -1018,7 +1018,7 @@ discard block |
||
1018 | 1018 | //formidable shortcode |
1019 | 1019 | public static function get_form_shortcode( $atts ) { |
1020 | 1020 | global $frm_vars; |
1021 | - if ( isset($frm_vars['skip_shortcode']) && $frm_vars['skip_shortcode'] ) { |
|
1021 | + if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) { |
|
1022 | 1022 | $sc = '[formidable'; |
1023 | 1023 | if ( ! empty( $atts ) ) { |
1024 | 1024 | foreach ( $atts as $k => $v ) { |
@@ -1032,8 +1032,8 @@ discard block |
||
1032 | 1032 | 'id' => '', 'key' => '', 'title' => false, 'description' => false, |
1033 | 1033 | 'readonly' => false, 'entry_id' => false, 'fields' => array(), |
1034 | 1034 | 'exclude_fields' => array(), 'minimize' => false, |
1035 | - ), $atts); |
|
1036 | - do_action('formidable_shortcode_atts', $shortcode_atts, $atts); |
|
1035 | + ), $atts ); |
|
1036 | + do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts ); |
|
1037 | 1037 | |
1038 | 1038 | return self::show_form( |
1039 | 1039 | $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], |
@@ -1121,51 +1121,51 @@ discard block |
||
1121 | 1121 | |
1122 | 1122 | $frm_settings = FrmAppHelper::get_settings(); |
1123 | 1123 | |
1124 | - $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value; |
|
1124 | + $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value; |
|
1125 | 1125 | |
1126 | 1126 | $user_ID = get_current_user_id(); |
1127 | 1127 | $params = FrmForm::get_params( $form ); |
1128 | 1128 | $message = $errors = ''; |
1129 | 1129 | |
1130 | 1130 | if ( $params['posted_form_id'] == $form->id && $_POST ) { |
1131 | - $errors = isset( $frm_vars['created_entries'][ $form->id ] ) ? $frm_vars['created_entries'][ $form->id ]['errors'] : array(); |
|
1131 | + $errors = isset( $frm_vars['created_entries'][$form->id] ) ? $frm_vars['created_entries'][$form->id]['errors'] : array(); |
|
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form ); |
1135 | 1135 | $fields = FrmFieldsHelper::get_form_fields( $form->id, ( isset( $errors ) && ! empty( $errors ) ) ); |
1136 | 1136 | |
1137 | 1137 | if ( $params['action'] != 'create' || $params['posted_form_id'] != $form->id || ! $_POST ) { |
1138 | - do_action('frm_display_form_action', $params, $fields, $form, $title, $description); |
|
1139 | - if ( apply_filters('frm_continue_to_new', true, $form->id, $params['action']) ) { |
|
1140 | - $values = FrmEntriesHelper::setup_new_vars($fields, $form); |
|
1138 | + do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description ); |
|
1139 | + if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) { |
|
1140 | + $values = FrmEntriesHelper::setup_new_vars( $fields, $form ); |
|
1141 | 1141 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' ); |
1142 | 1142 | } |
1143 | 1143 | return; |
1144 | 1144 | } |
1145 | 1145 | |
1146 | - if ( ! empty($errors) ) { |
|
1147 | - $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array(); |
|
1146 | + if ( ! empty( $errors ) ) { |
|
1147 | + $values = $fields ? FrmEntriesHelper::setup_new_vars( $fields, $form ) : array(); |
|
1148 | 1148 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' ); |
1149 | 1149 | return; |
1150 | 1150 | } |
1151 | 1151 | |
1152 | - do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description); |
|
1153 | - if ( ! apply_filters('frm_continue_to_create', true, $form->id) ) { |
|
1152 | + do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description ); |
|
1153 | + if ( ! apply_filters( 'frm_continue_to_create', true, $form->id ) ) { |
|
1154 | 1154 | return; |
1155 | 1155 | } |
1156 | 1156 | |
1157 | - $values = FrmEntriesHelper::setup_new_vars($fields, $form, true); |
|
1157 | + $values = FrmEntriesHelper::setup_new_vars( $fields, $form, true ); |
|
1158 | 1158 | $created = self::just_created_entry( $form->id ); |
1159 | - $conf_method = apply_filters('frm_success_filter', 'message', $form, 'create'); |
|
1159 | + $conf_method = apply_filters( 'frm_success_filter', 'message', $form, 'create' ); |
|
1160 | 1160 | |
1161 | - if ( $created && is_numeric($created) && $conf_method != 'message' ) { |
|
1162 | - do_action('frm_success_action', $conf_method, $form, $form->options, $created); |
|
1161 | + if ( $created && is_numeric( $created ) && $conf_method != 'message' ) { |
|
1162 | + do_action( 'frm_success_action', $conf_method, $form, $form->options, $created ); |
|
1163 | 1163 | do_action( 'frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form ) ); |
1164 | 1164 | return; |
1165 | 1165 | } |
1166 | 1166 | |
1167 | - if ( $created && is_numeric($created) ) { |
|
1168 | - $message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg; |
|
1167 | + if ( $created && is_numeric( $created ) ) { |
|
1168 | + $message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg; |
|
1169 | 1169 | $class = 'frm_message'; |
1170 | 1170 | } else { |
1171 | 1171 | $message = $frm_settings->failed_msg; |
@@ -1176,9 +1176,9 @@ discard block |
||
1176 | 1176 | 'message' => $message, 'form' => $form, |
1177 | 1177 | 'entry_id' => $created, 'class' => $class, |
1178 | 1178 | ) ); |
1179 | - $message = apply_filters('frm_main_feedback', $message, $form, $created); |
|
1179 | + $message = apply_filters( 'frm_main_feedback', $message, $form, $created ); |
|
1180 | 1180 | |
1181 | - if ( ! isset($form->options['show_form']) || $form->options['show_form'] ) { |
|
1181 | + if ( ! isset( $form->options['show_form'] ) || $form->options['show_form'] ) { |
|
1182 | 1182 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' ); |
1183 | 1183 | } else { |
1184 | 1184 | global $frm_vars; |
@@ -1196,7 +1196,7 @@ discard block |
||
1196 | 1196 | */ |
1197 | 1197 | public static function just_created_entry( $form_id ) { |
1198 | 1198 | global $frm_vars; |
1199 | - return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0; |
|
1199 | + return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][$form_id] ) && isset( $frm_vars['created_entries'][$form_id]['entry_id'] ) ) ? $frm_vars['created_entries'][$form_id]['entry_id'] : 0; |
|
1200 | 1200 | } |
1201 | 1201 | |
1202 | 1202 | public static function front_head() { |
@@ -159,6 +159,9 @@ discard block |
||
159 | 159 | wp_die(); |
160 | 160 | } |
161 | 161 | |
162 | + /** |
|
163 | + * @param string $field |
|
164 | + */ |
|
162 | 165 | private static function edit_in_place_value( $field ) { |
163 | 166 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
164 | 167 | FrmAppHelper::permission_check('frm_edit_forms', 'hide'); |
@@ -203,6 +206,9 @@ discard block |
||
203 | 206 | } |
204 | 207 | } |
205 | 208 | |
209 | + /** |
|
210 | + * @return string |
|
211 | + */ |
|
206 | 212 | public static function bulk_create_template( $ids ) { |
207 | 213 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
208 | 214 | |
@@ -698,6 +704,7 @@ discard block |
||
698 | 704 | /** |
699 | 705 | * Get an array of the helper shortcodes to display in the customization panel |
700 | 706 | * @since 2.0.6 |
707 | + * @param boolean $settings_tab |
|
701 | 708 | */ |
702 | 709 | private static function get_shortcode_helpers( $settings_tab ) { |
703 | 710 | $entry_shortcodes = array( |
@@ -771,6 +778,9 @@ discard block |
||
771 | 778 | return $content; |
772 | 779 | } |
773 | 780 | |
781 | + /** |
|
782 | + * @param boolean $entry |
|
783 | + */ |
|
774 | 784 | private static function get_entry_by_param( &$entry ) { |
775 | 785 | if ( ! $entry || ! is_object( $entry ) ) { |
776 | 786 | if ( ! $entry || ! is_numeric( $entry ) ) { |
@@ -1079,6 +1089,9 @@ discard block |
||
1079 | 1089 | return $form; |
1080 | 1090 | } |
1081 | 1091 | |
1092 | + /** |
|
1093 | + * @param string $id |
|
1094 | + */ |
|
1082 | 1095 | private static function maybe_get_form_to_show( $id ) { |
1083 | 1096 | $form = false; |
1084 | 1097 | |
@@ -1253,6 +1266,7 @@ discard block |
||
1253 | 1266 | |
1254 | 1267 | /** |
1255 | 1268 | * @since 2.0.8 |
1269 | + * @param string $content |
|
1256 | 1270 | */ |
1257 | 1271 | private static function maybe_minimize_form( $atts, &$content ) { |
1258 | 1272 | // check if minimizing is turned on |
@@ -1082,7 +1082,8 @@ |
||
1082 | 1082 | private static function maybe_get_form_to_show( $id ) { |
1083 | 1083 | $form = false; |
1084 | 1084 | |
1085 | - if ( ! empty( $id ) ) { // no form id or key set |
|
1085 | + if ( ! empty( $id ) ) { |
|
1086 | +// no form id or key set |
|
1086 | 1087 | $form = FrmForm::getOne( $id ); |
1087 | 1088 | if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) { |
1088 | 1089 | $form = false; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmFormsController { |
4 | 4 | |
5 | - public static function menu() { |
|
5 | + public static function menu() { |
|
6 | 6 | $menu_label = __( 'Forms', 'formidable' ); |
7 | 7 | if ( ! FrmAppHelper::pro_is_installed() ) { |
8 | 8 | $menu_label .= ' (Lite)'; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | add_submenu_page('formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' ); |
11 | 11 | |
12 | 12 | self::maybe_load_listing_hooks(); |
13 | - } |
|
13 | + } |
|
14 | 14 | |
15 | 15 | public static function maybe_load_listing_hooks() { |
16 | 16 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
@@ -24,128 +24,128 @@ discard block |
||
24 | 24 | add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' ); |
25 | 25 | } |
26 | 26 | |
27 | - public static function head() { |
|
28 | - wp_enqueue_script('formidable-editinplace'); |
|
27 | + public static function head() { |
|
28 | + wp_enqueue_script('formidable-editinplace'); |
|
29 | 29 | |
30 | - if ( wp_is_mobile() ) { |
|
31 | - wp_enqueue_script( 'jquery-touch-punch' ); |
|
32 | - } |
|
33 | - } |
|
30 | + if ( wp_is_mobile() ) { |
|
31 | + wp_enqueue_script( 'jquery-touch-punch' ); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - public static function register_widgets() { |
|
36 | - require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php'); |
|
37 | - register_widget('FrmShowForm'); |
|
38 | - } |
|
35 | + public static function register_widgets() { |
|
36 | + require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php'); |
|
37 | + register_widget('FrmShowForm'); |
|
38 | + } |
|
39 | 39 | |
40 | - public static function list_form() { |
|
41 | - FrmAppHelper::permission_check('frm_view_forms'); |
|
40 | + public static function list_form() { |
|
41 | + FrmAppHelper::permission_check('frm_view_forms'); |
|
42 | 42 | |
43 | 43 | $params = FrmForm::list_page_params(); |
44 | - $errors = self::process_bulk_form_actions( array()); |
|
45 | - $errors = apply_filters('frm_admin_list_form_action', $errors); |
|
44 | + $errors = self::process_bulk_form_actions( array()); |
|
45 | + $errors = apply_filters('frm_admin_list_form_action', $errors); |
|
46 | 46 | |
47 | 47 | return self::display_forms_list( $params, '', $errors ); |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | 50 | public static function new_form( $values = array() ) { |
51 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
51 | + FrmAppHelper::permission_check('frm_edit_forms'); |
|
52 | 52 | |
53 | - global $frm_vars; |
|
53 | + global $frm_vars; |
|
54 | 54 | |
55 | - $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
55 | + $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
56 | 56 | $action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ]; |
57 | 57 | |
58 | 58 | if ( $action == 'create' ) { |
59 | - return self::create($values); |
|
59 | + return self::create($values); |
|
60 | 60 | } else if ( $action == 'new' ) { |
61 | 61 | $frm_field_selection = FrmField::field_selection(); |
62 | - $values = FrmFormsHelper::setup_new_vars($values); |
|
63 | - $id = FrmForm::create( $values ); |
|
64 | - $form = FrmForm::getOne($id); |
|
62 | + $values = FrmFormsHelper::setup_new_vars($values); |
|
63 | + $id = FrmForm::create( $values ); |
|
64 | + $form = FrmForm::getOne($id); |
|
65 | 65 | |
66 | - // add default email notification |
|
67 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
68 | - $action_control->create($form->id); |
|
66 | + // add default email notification |
|
67 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
68 | + $action_control->create($form->id); |
|
69 | 69 | |
70 | 70 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
71 | 71 | |
72 | - $values['id'] = $id; |
|
72 | + $values['id'] = $id; |
|
73 | 73 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
74 | - } |
|
75 | - } |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | public static function create( $values = array() ) { |
78 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
78 | + FrmAppHelper::permission_check('frm_edit_forms'); |
|
79 | 79 | |
80 | - global $frm_vars; |
|
81 | - if ( empty( $values ) ) { |
|
82 | - $values = $_POST; |
|
83 | - } |
|
80 | + global $frm_vars; |
|
81 | + if ( empty( $values ) ) { |
|
82 | + $values = $_POST; |
|
83 | + } |
|
84 | 84 | |
85 | - //Set radio button and checkbox meta equal to "other" value |
|
86 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
87 | - $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
|
88 | - } |
|
85 | + //Set radio button and checkbox meta equal to "other" value |
|
86 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
87 | + $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | $id = isset($values['id']) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
91 | 91 | |
92 | - if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) { |
|
93 | - $frm_settings = FrmAppHelper::get_settings(); |
|
94 | - $errors = array( 'form' => $frm_settings->admin_permission ); |
|
95 | - } else { |
|
96 | - $errors = FrmForm::validate($values); |
|
97 | - } |
|
92 | + if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) { |
|
93 | + $frm_settings = FrmAppHelper::get_settings(); |
|
94 | + $errors = array( 'form' => $frm_settings->admin_permission ); |
|
95 | + } else { |
|
96 | + $errors = FrmForm::validate($values); |
|
97 | + } |
|
98 | 98 | |
99 | - if ( count($errors) > 0 ) { |
|
100 | - $hide_preview = true; |
|
99 | + if ( count($errors) > 0 ) { |
|
100 | + $hide_preview = true; |
|
101 | 101 | $frm_field_selection = FrmField::field_selection(); |
102 | - $form = FrmForm::getOne( $id ); |
|
103 | - $fields = FrmField::get_all_for_form($id); |
|
102 | + $form = FrmForm::getOne( $id ); |
|
103 | + $fields = FrmField::get_all_for_form($id); |
|
104 | 104 | |
105 | - $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true); |
|
105 | + $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true); |
|
106 | 106 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
107 | 107 | |
108 | 108 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
109 | - } else { |
|
110 | - FrmForm::update( $id, $values, true ); |
|
109 | + } else { |
|
110 | + FrmForm::update( $id, $values, true ); |
|
111 | 111 | $url = admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $id ); |
112 | 112 | die( FrmAppHelper::js_redirect( $url ) ); |
113 | - } |
|
114 | - } |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - public static function edit( $values = false ) { |
|
117 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
116 | + public static function edit( $values = false ) { |
|
117 | + FrmAppHelper::permission_check('frm_edit_forms'); |
|
118 | 118 | |
119 | 119 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
120 | - return self::get_edit_vars($id); |
|
121 | - } |
|
120 | + return self::get_edit_vars($id); |
|
121 | + } |
|
122 | 122 | |
123 | - public static function settings( $id = false, $message = '' ) { |
|
124 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
123 | + public static function settings( $id = false, $message = '' ) { |
|
124 | + FrmAppHelper::permission_check('frm_edit_forms'); |
|
125 | 125 | |
126 | - if ( ! $id || ! is_numeric($id) ) { |
|
126 | + if ( ! $id || ! is_numeric($id) ) { |
|
127 | 127 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
128 | - } |
|
128 | + } |
|
129 | 129 | return self::get_settings_vars( $id, array(), $message ); |
130 | - } |
|
130 | + } |
|
131 | 131 | |
132 | - public static function update_settings() { |
|
133 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
132 | + public static function update_settings() { |
|
133 | + FrmAppHelper::permission_check('frm_edit_forms'); |
|
134 | 134 | |
135 | 135 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
136 | 136 | |
137 | - $errors = FrmForm::validate($_POST); |
|
138 | - if ( count($errors) > 0 ) { |
|
139 | - return self::get_settings_vars($id, $errors); |
|
140 | - } |
|
137 | + $errors = FrmForm::validate($_POST); |
|
138 | + if ( count($errors) > 0 ) { |
|
139 | + return self::get_settings_vars($id, $errors); |
|
140 | + } |
|
141 | 141 | |
142 | - do_action('frm_before_update_form_settings', $id); |
|
142 | + do_action('frm_before_update_form_settings', $id); |
|
143 | 143 | |
144 | 144 | FrmForm::update( $id, $_POST ); |
145 | 145 | |
146 | - $message = __( 'Settings Successfully Updated', 'formidable' ); |
|
146 | + $message = __( 'Settings Successfully Updated', 'formidable' ); |
|
147 | 147 | return self::get_settings_vars( $id, array(), $message ); |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | 150 | public static function edit_key() { |
151 | 151 | $values = self::edit_in_place_value( 'form_key' ); |
@@ -175,43 +175,43 @@ discard block |
||
175 | 175 | |
176 | 176 | public static function update( $values = array() ) { |
177 | 177 | if ( empty( $values ) ) { |
178 | - $values = $_POST; |
|
179 | - } |
|
178 | + $values = $_POST; |
|
179 | + } |
|
180 | 180 | |
181 | - //Set radio button and checkbox meta equal to "other" value |
|
182 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
183 | - $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
|
184 | - } |
|
181 | + //Set radio button and checkbox meta equal to "other" value |
|
182 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
183 | + $values = FrmProEntry::mod_other_vals( $values, 'back' ); |
|
184 | + } |
|
185 | 185 | |
186 | - $errors = FrmForm::validate( $values ); |
|
187 | - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' ); |
|
188 | - if ( $permission_error !== false ) { |
|
189 | - $errors['form'] = $permission_error; |
|
190 | - } |
|
186 | + $errors = FrmForm::validate( $values ); |
|
187 | + $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' ); |
|
188 | + if ( $permission_error !== false ) { |
|
189 | + $errors['form'] = $permission_error; |
|
190 | + } |
|
191 | 191 | |
192 | 192 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
193 | 193 | |
194 | 194 | if ( count( $errors ) > 0 ) { |
195 | - return self::get_edit_vars( $id, $errors ); |
|
195 | + return self::get_edit_vars( $id, $errors ); |
|
196 | 196 | } else { |
197 | - FrmForm::update( $id, $values ); |
|
198 | - $message = __( 'Form was Successfully Updated', 'formidable' ); |
|
199 | - if ( defined( 'DOING_AJAX' ) ) { |
|
197 | + FrmForm::update( $id, $values ); |
|
198 | + $message = __( 'Form was Successfully Updated', 'formidable' ); |
|
199 | + if ( defined( 'DOING_AJAX' ) ) { |
|
200 | 200 | wp_die( $message ); |
201 | - } |
|
201 | + } |
|
202 | 202 | return self::get_edit_vars( $id, array(), $message ); |
203 | - } |
|
204 | - } |
|
203 | + } |
|
204 | + } |
|
205 | 205 | |
206 | - public static function bulk_create_template( $ids ) { |
|
207 | - FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
206 | + public static function bulk_create_template( $ids ) { |
|
207 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
208 | 208 | |
209 | - foreach ( $ids as $id ) { |
|
210 | - FrmForm::duplicate( $id, true, true ); |
|
211 | - } |
|
209 | + foreach ( $ids as $id ) { |
|
210 | + FrmForm::duplicate( $id, true, true ); |
|
211 | + } |
|
212 | 212 | |
213 | - return __( 'Form template was Successfully Created', 'formidable' ); |
|
214 | - } |
|
213 | + return __( 'Form template was Successfully Created', 'formidable' ); |
|
214 | + } |
|
215 | 215 | |
216 | 216 | /** |
217 | 217 | * Redirect to the url for creating from a template |
@@ -233,45 +233,45 @@ discard block |
||
233 | 233 | wp_die(); |
234 | 234 | } |
235 | 235 | |
236 | - public static function duplicate() { |
|
237 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
236 | + public static function duplicate() { |
|
237 | + FrmAppHelper::permission_check('frm_edit_forms'); |
|
238 | 238 | |
239 | 239 | $params = FrmForm::list_page_params(); |
240 | - $form = FrmForm::duplicate( $params['id'], $params['template'], true ); |
|
241 | - $message = ($params['template']) ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' ); |
|
242 | - if ( $form ) { |
|
240 | + $form = FrmForm::duplicate( $params['id'], $params['template'], true ); |
|
241 | + $message = ($params['template']) ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' ); |
|
242 | + if ( $form ) { |
|
243 | 243 | return self::get_edit_vars( $form, array(), $message, true ); |
244 | - } else { |
|
245 | - return self::display_forms_list($params, __( 'There was a problem creating the new template.', 'formidable' )); |
|
246 | - } |
|
247 | - } |
|
244 | + } else { |
|
245 | + return self::display_forms_list($params, __( 'There was a problem creating the new template.', 'formidable' )); |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - public static function page_preview() { |
|
249 | + public static function page_preview() { |
|
250 | 250 | $params = FrmForm::list_page_params(); |
251 | - if ( ! $params['form'] ) { |
|
252 | - return; |
|
253 | - } |
|
254 | - |
|
255 | - $form = FrmForm::getOne( $params['form'] ); |
|
256 | - if ( ! $form ) { |
|
257 | - return; |
|
258 | - } |
|
259 | - return self::show_form( $form->id, '', true, true ); |
|
260 | - } |
|
261 | - |
|
262 | - public static function preview() { |
|
263 | - do_action( 'frm_wp' ); |
|
264 | - |
|
265 | - global $frm_vars; |
|
266 | - $frm_vars['preview'] = true; |
|
267 | - |
|
268 | - if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) { |
|
269 | - global $wp; |
|
270 | - $root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ); |
|
251 | + if ( ! $params['form'] ) { |
|
252 | + return; |
|
253 | + } |
|
254 | + |
|
255 | + $form = FrmForm::getOne( $params['form'] ); |
|
256 | + if ( ! $form ) { |
|
257 | + return; |
|
258 | + } |
|
259 | + return self::show_form( $form->id, '', true, true ); |
|
260 | + } |
|
261 | + |
|
262 | + public static function preview() { |
|
263 | + do_action( 'frm_wp' ); |
|
264 | + |
|
265 | + global $frm_vars; |
|
266 | + $frm_vars['preview'] = true; |
|
267 | + |
|
268 | + if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) { |
|
269 | + global $wp; |
|
270 | + $root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ); |
|
271 | 271 | include_once( $root . '/wp-config.php' ); |
272 | - $wp->init(); |
|
273 | - $wp->register_globals(); |
|
274 | - } |
|
272 | + $wp->init(); |
|
273 | + $wp->register_globals(); |
|
274 | + } |
|
275 | 275 | |
276 | 276 | self::register_pro_scripts(); |
277 | 277 | |
@@ -285,11 +285,11 @@ discard block |
||
285 | 285 | $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 ); |
286 | 286 | if ( empty( $form ) ) { |
287 | 287 | $form = FrmForm::getAll( array(), '', 1 ); |
288 | - } |
|
288 | + } |
|
289 | 289 | |
290 | 290 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' ); |
291 | - wp_die(); |
|
292 | - } |
|
291 | + wp_die(); |
|
292 | + } |
|
293 | 293 | |
294 | 294 | public static function register_pro_scripts() { |
295 | 295 | if ( FrmAppHelper::pro_is_installed() ) { |
@@ -300,22 +300,22 @@ discard block |
||
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - public static function untrash() { |
|
303 | + public static function untrash() { |
|
304 | 304 | self::change_form_status( 'untrash' ); |
305 | - } |
|
305 | + } |
|
306 | 306 | |
307 | 307 | public static function bulk_untrash( $ids ) { |
308 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
308 | + FrmAppHelper::permission_check('frm_edit_forms'); |
|
309 | 309 | |
310 | - $count = FrmForm::set_status( $ids, 'published' ); |
|
310 | + $count = FrmForm::set_status( $ids, 'published' ); |
|
311 | 311 | |
312 | - $message = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 ); |
|
313 | - return $message; |
|
314 | - } |
|
312 | + $message = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 ); |
|
313 | + return $message; |
|
314 | + } |
|
315 | 315 | |
316 | - public static function trash() { |
|
316 | + public static function trash() { |
|
317 | 317 | self::change_form_status( 'trash' ); |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | 320 | /** |
321 | 321 | * @param string $status |
@@ -353,68 +353,68 @@ discard block |
||
353 | 353 | } |
354 | 354 | |
355 | 355 | public static function bulk_trash( $ids ) { |
356 | - FrmAppHelper::permission_check('frm_delete_forms'); |
|
356 | + FrmAppHelper::permission_check('frm_delete_forms'); |
|
357 | 357 | |
358 | - $count = 0; |
|
359 | - foreach ( $ids as $id ) { |
|
360 | - if ( FrmForm::trash( $id ) ) { |
|
361 | - $count++; |
|
362 | - } |
|
363 | - } |
|
358 | + $count = 0; |
|
359 | + foreach ( $ids as $id ) { |
|
360 | + if ( FrmForm::trash( $id ) ) { |
|
361 | + $count++; |
|
362 | + } |
|
363 | + } |
|
364 | 364 | |
365 | - $current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : ''; |
|
365 | + $current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : ''; |
|
366 | 366 | $message = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', '</a>' ); |
367 | 367 | |
368 | - return $message; |
|
369 | - } |
|
368 | + return $message; |
|
369 | + } |
|
370 | 370 | |
371 | - public static function destroy() { |
|
372 | - FrmAppHelper::permission_check('frm_delete_forms'); |
|
371 | + public static function destroy() { |
|
372 | + FrmAppHelper::permission_check('frm_delete_forms'); |
|
373 | 373 | |
374 | 374 | $params = FrmForm::list_page_params(); |
375 | 375 | |
376 | - //check nonce url |
|
377 | - check_admin_referer('destroy_form_' . $params['id']); |
|
376 | + //check nonce url |
|
377 | + check_admin_referer('destroy_form_' . $params['id']); |
|
378 | 378 | |
379 | - $count = 0; |
|
380 | - if ( FrmForm::destroy( $params['id'] ) ) { |
|
381 | - $count++; |
|
382 | - } |
|
379 | + $count = 0; |
|
380 | + if ( FrmForm::destroy( $params['id'] ) ) { |
|
381 | + $count++; |
|
382 | + } |
|
383 | 383 | |
384 | - $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
384 | + $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
385 | 385 | |
386 | 386 | self::display_forms_list( $params, $message ); |
387 | - } |
|
387 | + } |
|
388 | 388 | |
389 | 389 | public static function bulk_destroy( $ids ) { |
390 | - FrmAppHelper::permission_check('frm_delete_forms'); |
|
390 | + FrmAppHelper::permission_check('frm_delete_forms'); |
|
391 | 391 | |
392 | - $count = 0; |
|
393 | - foreach ( $ids as $id ) { |
|
394 | - $d = FrmForm::destroy( $id ); |
|
395 | - if ( $d ) { |
|
396 | - $count++; |
|
397 | - } |
|
398 | - } |
|
392 | + $count = 0; |
|
393 | + foreach ( $ids as $id ) { |
|
394 | + $d = FrmForm::destroy( $id ); |
|
395 | + if ( $d ) { |
|
396 | + $count++; |
|
397 | + } |
|
398 | + } |
|
399 | 399 | |
400 | - $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
400 | + $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
401 | 401 | |
402 | - return $message; |
|
403 | - } |
|
402 | + return $message; |
|
403 | + } |
|
404 | 404 | |
405 | - private static function delete_all() { |
|
406 | - //check nonce url |
|
407 | - $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable'); |
|
408 | - if ( $permission_error !== false ) { |
|
405 | + private static function delete_all() { |
|
406 | + //check nonce url |
|
407 | + $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable'); |
|
408 | + if ( $permission_error !== false ) { |
|
409 | 409 | self::display_forms_list( array(), '', array( $permission_error ) ); |
410 | - return; |
|
411 | - } |
|
410 | + return; |
|
411 | + } |
|
412 | 412 | |
413 | 413 | $count = FrmForm::scheduled_delete( time() ); |
414 | - $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
414 | + $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count); |
|
415 | 415 | |
416 | 416 | self::display_forms_list( array(), $message ); |
417 | - } |
|
417 | + } |
|
418 | 418 | |
419 | 419 | public static function scheduled_delete( $delete_timestamp = '' ) { |
420 | 420 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::scheduled_delete' ); |
@@ -422,11 +422,11 @@ discard block |
||
422 | 422 | } |
423 | 423 | |
424 | 424 | /** |
425 | - * Inserts Formidable button |
|
426 | - * Hook exists since 2.5.0 |
|
427 | - * |
|
428 | - * @since 2.0.15 |
|
429 | - */ |
|
425 | + * Inserts Formidable button |
|
426 | + * Hook exists since 2.5.0 |
|
427 | + * |
|
428 | + * @since 2.0.15 |
|
429 | + */ |
|
430 | 430 | public static function insert_form_button() { |
431 | 431 | if ( current_user_can('frm_view_forms') ) { |
432 | 432 | $menu_name = FrmAppHelper::get_menu_name(); |
@@ -437,49 +437,49 @@ discard block |
||
437 | 437 | } |
438 | 438 | } |
439 | 439 | |
440 | - public static function insert_form_popup() { |
|
440 | + public static function insert_form_popup() { |
|
441 | 441 | $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) ); |
442 | 442 | if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) { |
443 | - return; |
|
444 | - } |
|
443 | + return; |
|
444 | + } |
|
445 | 445 | |
446 | - FrmAppHelper::load_admin_wide_js(); |
|
446 | + FrmAppHelper::load_admin_wide_js(); |
|
447 | 447 | |
448 | - $shortcodes = array( |
|
448 | + $shortcodes = array( |
|
449 | 449 | 'formidable' => array( 'name' => __( 'Form', 'formidable' ), 'label' => __( 'Insert a Form', 'formidable' ) ), |
450 | - ); |
|
450 | + ); |
|
451 | 451 | |
452 | - $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes); |
|
452 | + $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes); |
|
453 | 453 | |
454 | 454 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' ); |
455 | - } |
|
455 | + } |
|
456 | 456 | |
457 | - public static function get_shortcode_opts() { |
|
457 | + public static function get_shortcode_opts() { |
|
458 | 458 | FrmAppHelper::permission_check('frm_view_forms'); |
459 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
459 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
460 | 460 | |
461 | 461 | $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' ); |
462 | - if ( empty($shortcode) ) { |
|
463 | - wp_die(); |
|
464 | - } |
|
462 | + if ( empty($shortcode) ) { |
|
463 | + wp_die(); |
|
464 | + } |
|
465 | 465 | |
466 | 466 | echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">'; |
467 | 467 | echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />'; |
468 | 468 | |
469 | - $form_id = ''; |
|
470 | - $opts = array(); |
|
469 | + $form_id = ''; |
|
470 | + $opts = array(); |
|
471 | 471 | switch ( $shortcode ) { |
472 | - case 'formidable': |
|
473 | - $opts = array( |
|
472 | + case 'formidable': |
|
473 | + $opts = array( |
|
474 | 474 | 'form_id' => 'id', |
475 | - //'key' => ', |
|
475 | + //'key' => ', |
|
476 | 476 | 'title' => array( 'val' => 1, 'label' => __( 'Display form title', 'formidable' ) ), |
477 | 477 | 'description' => array( 'val' => 1, 'label' => __( 'Display form description', 'formidable' ) ), |
478 | 478 | 'minimize' => array( 'val' => 1, 'label' => __( 'Minimize form HTML', 'formidable' ) ), |
479 | - ); |
|
480 | - break; |
|
481 | - } |
|
482 | - $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode); |
|
479 | + ); |
|
480 | + break; |
|
481 | + } |
|
482 | + $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode); |
|
483 | 483 | |
484 | 484 | if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) { |
485 | 485 | // allow other shortcodes to use the required form id option |
@@ -489,61 +489,61 @@ discard block |
||
489 | 489 | |
490 | 490 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' ); |
491 | 491 | |
492 | - echo '</div>'; |
|
492 | + echo '</div>'; |
|
493 | 493 | |
494 | - wp_die(); |
|
495 | - } |
|
494 | + wp_die(); |
|
495 | + } |
|
496 | 496 | |
497 | 497 | public static function display_forms_list( $params = array(), $message = '', $errors = array(), $deprecated_errors = array() ) { |
498 | - FrmAppHelper::permission_check( 'frm_view_forms' ); |
|
498 | + FrmAppHelper::permission_check( 'frm_view_forms' ); |
|
499 | 499 | if ( ! empty( $deprecated_errors ) ) { |
500 | 500 | $errors = $deprecated_errors; |
501 | 501 | _deprecated_argument( 'errors', '2.0.8' ); |
502 | 502 | } |
503 | 503 | |
504 | - global $wpdb, $frm_vars; |
|
504 | + global $wpdb, $frm_vars; |
|
505 | 505 | |
506 | 506 | if ( empty( $params ) ) { |
507 | 507 | $params = FrmForm::list_page_params(); |
508 | - } |
|
508 | + } |
|
509 | 509 | |
510 | - $wp_list_table = new FrmFormsListHelper( compact( 'params' ) ); |
|
510 | + $wp_list_table = new FrmFormsListHelper( compact( 'params' ) ); |
|
511 | 511 | |
512 | - $pagenum = $wp_list_table->get_pagenum(); |
|
512 | + $pagenum = $wp_list_table->get_pagenum(); |
|
513 | 513 | |
514 | - $wp_list_table->prepare_items(); |
|
514 | + $wp_list_table->prepare_items(); |
|
515 | 515 | |
516 | - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
517 | - if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
516 | + $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
517 | + if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
518 | 518 | wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) ); |
519 | - die(); |
|
520 | - } |
|
519 | + die(); |
|
520 | + } |
|
521 | 521 | |
522 | 522 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' ); |
523 | - } |
|
523 | + } |
|
524 | 524 | |
525 | 525 | public static function get_columns( $columns ) { |
526 | - $columns['cb'] = '<input type="checkbox" />'; |
|
527 | - $columns['id'] = 'ID'; |
|
526 | + $columns['cb'] = '<input type="checkbox" />'; |
|
527 | + $columns['id'] = 'ID'; |
|
528 | 528 | |
529 | - $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : 'published'; |
|
529 | + $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : 'published'; |
|
530 | 530 | |
531 | - if ( 'template' == $type ) { |
|
532 | - $columns['name'] = __( 'Template Name', 'formidable' ); |
|
533 | - $columns['type'] = __( 'Type', 'formidable' ); |
|
534 | - $columns['form_key'] = __( 'Key', 'formidable' ); |
|
535 | - } else { |
|
536 | - $columns['name'] = __( 'Form Title', 'formidable' ); |
|
537 | - $columns['entries'] = __( 'Entries', 'formidable' ); |
|
538 | - $columns['form_key'] = __( 'Key', 'formidable' ); |
|
539 | - $columns['shortcode'] = __( 'Shortcodes', 'formidable' ); |
|
540 | - } |
|
531 | + if ( 'template' == $type ) { |
|
532 | + $columns['name'] = __( 'Template Name', 'formidable' ); |
|
533 | + $columns['type'] = __( 'Type', 'formidable' ); |
|
534 | + $columns['form_key'] = __( 'Key', 'formidable' ); |
|
535 | + } else { |
|
536 | + $columns['name'] = __( 'Form Title', 'formidable' ); |
|
537 | + $columns['entries'] = __( 'Entries', 'formidable' ); |
|
538 | + $columns['form_key'] = __( 'Key', 'formidable' ); |
|
539 | + $columns['shortcode'] = __( 'Shortcodes', 'formidable' ); |
|
540 | + } |
|
541 | 541 | |
542 | - $columns['created_at'] = __( 'Date', 'formidable' ); |
|
542 | + $columns['created_at'] = __( 'Date', 'formidable' ); |
|
543 | 543 | |
544 | 544 | add_screen_option( 'per_page', array( 'label' => __( 'Forms', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_per_page' ) ); |
545 | 545 | |
546 | - return $columns; |
|
546 | + return $columns; |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | public static function get_sortable_columns() { |
@@ -557,111 +557,111 @@ discard block |
||
557 | 557 | } |
558 | 558 | |
559 | 559 | public static function hidden_columns( $result ) { |
560 | - $return = false; |
|
561 | - foreach ( (array) $result as $r ) { |
|
562 | - if ( ! empty( $r ) ) { |
|
563 | - $return = true; |
|
564 | - break; |
|
565 | - } |
|
566 | - } |
|
560 | + $return = false; |
|
561 | + foreach ( (array) $result as $r ) { |
|
562 | + if ( ! empty( $r ) ) { |
|
563 | + $return = true; |
|
564 | + break; |
|
565 | + } |
|
566 | + } |
|
567 | 567 | |
568 | - if ( $return ) { |
|
569 | - return $result; |
|
568 | + if ( $return ) { |
|
569 | + return $result; |
|
570 | 570 | } |
571 | 571 | |
572 | - $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : ''; |
|
572 | + $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : ''; |
|
573 | 573 | |
574 | - $result[] = 'created_at'; |
|
575 | - if ( $type == 'template' ) { |
|
576 | - $result[] = 'id'; |
|
577 | - $result[] = 'form_key'; |
|
578 | - } |
|
574 | + $result[] = 'created_at'; |
|
575 | + if ( $type == 'template' ) { |
|
576 | + $result[] = 'id'; |
|
577 | + $result[] = 'form_key'; |
|
578 | + } |
|
579 | 579 | |
580 | - return $result; |
|
581 | - } |
|
580 | + return $result; |
|
581 | + } |
|
582 | 582 | |
583 | 583 | public static function save_per_page( $save, $option, $value ) { |
584 | - if ( $option == 'formidable_page_formidable_per_page' ) { |
|
585 | - $save = (int) $value; |
|
586 | - } |
|
587 | - return $save; |
|
588 | - } |
|
584 | + if ( $option == 'formidable_page_formidable_per_page' ) { |
|
585 | + $save = (int) $value; |
|
586 | + } |
|
587 | + return $save; |
|
588 | + } |
|
589 | 589 | |
590 | 590 | private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { |
591 | - global $frm_vars; |
|
591 | + global $frm_vars; |
|
592 | 592 | |
593 | - $form = FrmForm::getOne( $id ); |
|
594 | - if ( ! $form ) { |
|
595 | - wp_die( __( 'You are trying to edit a form that does not exist.', 'formidable' ) ); |
|
596 | - } |
|
593 | + $form = FrmForm::getOne( $id ); |
|
594 | + if ( ! $form ) { |
|
595 | + wp_die( __( 'You are trying to edit a form that does not exist.', 'formidable' ) ); |
|
596 | + } |
|
597 | 597 | |
598 | - if ( $form->parent_form_id ) { |
|
598 | + if ( $form->parent_form_id ) { |
|
599 | 599 | wp_die( sprintf( __( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' )); |
600 | - } |
|
600 | + } |
|
601 | 601 | |
602 | 602 | $frm_field_selection = FrmField::field_selection(); |
603 | - $fields = FrmField::get_all_for_form($form->id); |
|
603 | + $fields = FrmField::get_all_for_form($form->id); |
|
604 | 604 | |
605 | - // Automatically add end section fields if they don't exist (2.0 migration) |
|
606 | - $reset_fields = false; |
|
607 | - FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
|
605 | + // Automatically add end section fields if they don't exist (2.0 migration) |
|
606 | + $reset_fields = false; |
|
607 | + FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
|
608 | 608 | |
609 | - if ( $reset_fields ) { |
|
610 | - $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
|
611 | - } |
|
609 | + if ( $reset_fields ) { |
|
610 | + $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
|
611 | + } |
|
612 | 612 | |
613 | - unset($end_section_values, $last_order, $open, $reset_fields); |
|
613 | + unset($end_section_values, $last_order, $open, $reset_fields); |
|
614 | 614 | |
615 | 615 | $args = array( 'parent_form_id' => $form->id ); |
616 | - $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true, array(), $args ); |
|
616 | + $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true, array(), $args ); |
|
617 | 617 | |
618 | - $edit_message = __( 'Form was Successfully Updated', 'formidable' ); |
|
619 | - if ( $form->is_template && $message == $edit_message ) { |
|
620 | - $message = __( 'Template was Successfully Updated', 'formidable' ); |
|
621 | - } |
|
618 | + $edit_message = __( 'Form was Successfully Updated', 'formidable' ); |
|
619 | + if ( $form->is_template && $message == $edit_message ) { |
|
620 | + $message = __( 'Template was Successfully Updated', 'formidable' ); |
|
621 | + } |
|
622 | 622 | |
623 | 623 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
624 | 624 | |
625 | - if ( $form->default_template ) { |
|
626 | - wp_die(__( 'That template cannot be edited', 'formidable' )); |
|
627 | - } else if ( defined('DOING_AJAX') ) { |
|
628 | - wp_die(); |
|
629 | - } else if ( $create_link ) { |
|
625 | + if ( $form->default_template ) { |
|
626 | + wp_die(__( 'That template cannot be edited', 'formidable' )); |
|
627 | + } else if ( defined('DOING_AJAX') ) { |
|
628 | + wp_die(); |
|
629 | + } else if ( $create_link ) { |
|
630 | 630 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' ); |
631 | - } else { |
|
631 | + } else { |
|
632 | 632 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); |
633 | - } |
|
634 | - } |
|
633 | + } |
|
634 | + } |
|
635 | 635 | |
636 | 636 | public static function get_settings_vars( $id, $errors = array(), $message = '' ) { |
637 | 637 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
638 | 638 | |
639 | - global $frm_vars; |
|
639 | + global $frm_vars; |
|
640 | 640 | |
641 | - $form = FrmForm::getOne( $id ); |
|
641 | + $form = FrmForm::getOne( $id ); |
|
642 | 642 | |
643 | - $fields = FrmField::get_all_for_form($id); |
|
644 | - $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true); |
|
643 | + $fields = FrmField::get_all_for_form($id); |
|
644 | + $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true); |
|
645 | 645 | |
646 | - if ( isset($values['default_template']) && $values['default_template'] ) { |
|
647 | - wp_die(__( 'That template cannot be edited', 'formidable' )); |
|
648 | - } |
|
646 | + if ( isset($values['default_template']) && $values['default_template'] ) { |
|
647 | + wp_die(__( 'That template cannot be edited', 'formidable' )); |
|
648 | + } |
|
649 | 649 | |
650 | - $action_controls = FrmFormActionsController::get_form_actions(); |
|
650 | + $action_controls = FrmFormActionsController::get_form_actions(); |
|
651 | 651 | |
652 | - $sections = apply_filters('frm_add_form_settings_section', array(), $values); |
|
653 | - $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"'; |
|
652 | + $sections = apply_filters('frm_add_form_settings_section', array(), $values); |
|
653 | + $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"'; |
|
654 | 654 | |
655 | - $styles = apply_filters('frm_get_style_opts', array()); |
|
655 | + $styles = apply_filters('frm_get_style_opts', array()); |
|
656 | 656 | |
657 | 657 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); |
658 | - } |
|
658 | + } |
|
659 | 659 | |
660 | - public static function mb_tags_box( $form_id, $class = '' ) { |
|
661 | - $fields = FrmField::get_all_for_form($form_id, '', 'include'); |
|
662 | - $linked_forms = array(); |
|
663 | - $col = 'one'; |
|
664 | - $settings_tab = FrmAppHelper::is_admin_page('formidable' ) ? true : false; |
|
660 | + public static function mb_tags_box( $form_id, $class = '' ) { |
|
661 | + $fields = FrmField::get_all_for_form($form_id, '', 'include'); |
|
662 | + $linked_forms = array(); |
|
663 | + $col = 'one'; |
|
664 | + $settings_tab = FrmAppHelper::is_admin_page('formidable' ) ? true : false; |
|
665 | 665 | |
666 | 666 | $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() ); |
667 | 667 | $adv_shortcodes = self::get_advanced_shortcodes(); |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
670 | 670 | |
671 | 671 | include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' ); |
672 | - } |
|
672 | + } |
|
673 | 673 | |
674 | 674 | /** |
675 | 675 | * Get an array of the options to display in the advanced tab |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | '' => '', |
711 | 711 | 'siteurl' => __( 'Site URL', 'formidable' ), |
712 | 712 | 'sitename' => __( 'Site Name', 'formidable' ), |
713 | - ); |
|
713 | + ); |
|
714 | 714 | |
715 | 715 | if ( ! FrmAppHelper::pro_is_installed() ) { |
716 | 716 | unset( $entry_shortcodes['post_id'] ); |
@@ -737,39 +737,39 @@ discard block |
||
737 | 737 | return $entry_shortcodes; |
738 | 738 | } |
739 | 739 | |
740 | - // Insert the form class setting into the form |
|
740 | + // Insert the form class setting into the form |
|
741 | 741 | public static function form_classes( $form ) { |
742 | - if ( isset($form->options['form_class']) ) { |
|
742 | + if ( isset($form->options['form_class']) ) { |
|
743 | 743 | echo esc_attr( sanitize_text_field( $form->options['form_class'] ) ); |
744 | - } |
|
745 | - } |
|
744 | + } |
|
745 | + } |
|
746 | 746 | |
747 | - public static function get_email_html() { |
|
747 | + public static function get_email_html() { |
|
748 | 748 | FrmAppHelper::permission_check('frm_view_forms'); |
749 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
749 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
750 | 750 | echo FrmEntryFormat::show_entry( array( |
751 | 751 | 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), |
752 | - 'default_email' => true, |
|
752 | + 'default_email' => true, |
|
753 | 753 | 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), |
754 | - ) ); |
|
755 | - wp_die(); |
|
754 | + ) ); |
|
755 | + wp_die(); |
|
756 | 756 | } |
757 | 757 | |
758 | - public static function filter_content( $content, $form, $entry = false ) { |
|
758 | + public static function filter_content( $content, $form, $entry = false ) { |
|
759 | 759 | self::get_entry_by_param( $entry ); |
760 | - if ( ! $entry ) { |
|
761 | - return $content; |
|
762 | - } |
|
760 | + if ( ! $entry ) { |
|
761 | + return $content; |
|
762 | + } |
|
763 | 763 | |
764 | - if ( is_object( $form ) ) { |
|
765 | - $form = $form->id; |
|
766 | - } |
|
764 | + if ( is_object( $form ) ) { |
|
765 | + $form = $form->id; |
|
766 | + } |
|
767 | 767 | |
768 | - $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
|
769 | - $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
|
768 | + $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
|
769 | + $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
|
770 | 770 | |
771 | - return $content; |
|
772 | - } |
|
771 | + return $content; |
|
772 | + } |
|
773 | 773 | |
774 | 774 | private static function get_entry_by_param( &$entry ) { |
775 | 775 | if ( ! $entry || ! is_object( $entry ) ) { |
@@ -781,282 +781,282 @@ discard block |
||
781 | 781 | } |
782 | 782 | } |
783 | 783 | |
784 | - public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
|
785 | - return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
|
786 | - } |
|
784 | + public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
|
785 | + return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
|
786 | + } |
|
787 | 787 | |
788 | - public static function process_bulk_form_actions( $errors ) { |
|
789 | - if ( ! $_REQUEST ) { |
|
790 | - return $errors; |
|
791 | - } |
|
788 | + public static function process_bulk_form_actions( $errors ) { |
|
789 | + if ( ! $_REQUEST ) { |
|
790 | + return $errors; |
|
791 | + } |
|
792 | 792 | |
793 | 793 | $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' ); |
794 | - if ( $bulkaction == -1 ) { |
|
794 | + if ( $bulkaction == -1 ) { |
|
795 | 795 | $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' ); |
796 | - } |
|
797 | - |
|
798 | - if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) { |
|
799 | - FrmAppHelper::remove_get_action(); |
|
800 | - |
|
801 | - $bulkaction = str_replace( 'bulk_', '', $bulkaction ); |
|
802 | - } |
|
803 | - |
|
804 | - $ids = FrmAppHelper::get_param( 'item-action', '' ); |
|
805 | - if ( empty( $ids ) ) { |
|
806 | - $errors[] = __( 'No forms were specified', 'formidable' ); |
|
807 | - return $errors; |
|
808 | - } |
|
809 | - |
|
810 | - $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
|
811 | - if ( $permission_error !== false ) { |
|
812 | - $errors[] = $permission_error; |
|
813 | - return $errors; |
|
814 | - } |
|
815 | - |
|
816 | - if ( ! is_array( $ids ) ) { |
|
817 | - $ids = explode( ',', $ids ); |
|
818 | - } |
|
819 | - |
|
820 | - switch ( $bulkaction ) { |
|
821 | - case 'delete': |
|
822 | - $message = self::bulk_destroy( $ids ); |
|
823 | - break; |
|
824 | - case 'trash': |
|
825 | - $message = self::bulk_trash( $ids ); |
|
826 | - break; |
|
827 | - case 'untrash': |
|
828 | - $message = self::bulk_untrash( $ids ); |
|
829 | - break; |
|
830 | - case 'create_template': |
|
831 | - $message = self::bulk_create_template( $ids ); |
|
832 | - break; |
|
833 | - } |
|
834 | - |
|
835 | - if ( isset( $message ) && ! empty( $message ) ) { |
|
796 | + } |
|
797 | + |
|
798 | + if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) { |
|
799 | + FrmAppHelper::remove_get_action(); |
|
800 | + |
|
801 | + $bulkaction = str_replace( 'bulk_', '', $bulkaction ); |
|
802 | + } |
|
803 | + |
|
804 | + $ids = FrmAppHelper::get_param( 'item-action', '' ); |
|
805 | + if ( empty( $ids ) ) { |
|
806 | + $errors[] = __( 'No forms were specified', 'formidable' ); |
|
807 | + return $errors; |
|
808 | + } |
|
809 | + |
|
810 | + $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
|
811 | + if ( $permission_error !== false ) { |
|
812 | + $errors[] = $permission_error; |
|
813 | + return $errors; |
|
814 | + } |
|
815 | + |
|
816 | + if ( ! is_array( $ids ) ) { |
|
817 | + $ids = explode( ',', $ids ); |
|
818 | + } |
|
819 | + |
|
820 | + switch ( $bulkaction ) { |
|
821 | + case 'delete': |
|
822 | + $message = self::bulk_destroy( $ids ); |
|
823 | + break; |
|
824 | + case 'trash': |
|
825 | + $message = self::bulk_trash( $ids ); |
|
826 | + break; |
|
827 | + case 'untrash': |
|
828 | + $message = self::bulk_untrash( $ids ); |
|
829 | + break; |
|
830 | + case 'create_template': |
|
831 | + $message = self::bulk_create_template( $ids ); |
|
832 | + break; |
|
833 | + } |
|
834 | + |
|
835 | + if ( isset( $message ) && ! empty( $message ) ) { |
|
836 | 836 | echo '<div id="message" class="updated frm_msg_padding">' . FrmAppHelper::kses( $message, array( 'a' ) ) . '</div>'; |
837 | - } |
|
837 | + } |
|
838 | 838 | |
839 | - return $errors; |
|
840 | - } |
|
839 | + return $errors; |
|
840 | + } |
|
841 | 841 | |
842 | - public static function add_default_templates( $path, $default = true, $template = true ) { |
|
843 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' ); |
|
842 | + public static function add_default_templates( $path, $default = true, $template = true ) { |
|
843 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' ); |
|
844 | 844 | |
845 | - $path = untrailingslashit(trim($path)); |
|
845 | + $path = untrailingslashit(trim($path)); |
|
846 | 846 | $templates = glob( $path . '/*.php' ); |
847 | 847 | |
848 | 848 | for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) { |
849 | 849 | $filename = str_replace( '.php', '', str_replace( $path . '/', '', $templates[ $i ] ) ); |
850 | 850 | $template_query = array( 'form_key' => $filename ); |
851 | - if ( $template ) { |
|
852 | - $template_query['is_template'] = 1; |
|
853 | - } |
|
854 | - if ( $default ) { |
|
855 | - $template_query['default_template'] = 1; |
|
856 | - } |
|
851 | + if ( $template ) { |
|
852 | + $template_query['is_template'] = 1; |
|
853 | + } |
|
854 | + if ( $default ) { |
|
855 | + $template_query['default_template'] = 1; |
|
856 | + } |
|
857 | 857 | $form = FrmForm::getAll( $template_query, '', 1 ); |
858 | 858 | |
859 | - $values = FrmFormsHelper::setup_new_vars(); |
|
860 | - $values['form_key'] = $filename; |
|
861 | - $values['is_template'] = $template; |
|
862 | - $values['status'] = 'published'; |
|
863 | - if ( $default ) { |
|
864 | - $values['default_template'] = 1; |
|
865 | - } |
|
866 | - |
|
867 | - include( $templates[ $i ] ); |
|
868 | - |
|
869 | - //get updated form |
|
870 | - if ( isset($form) && ! empty($form) ) { |
|
871 | - $old_id = $form->id; |
|
872 | - $form = FrmForm::getOne($form->id); |
|
873 | - } else { |
|
874 | - $old_id = false; |
|
859 | + $values = FrmFormsHelper::setup_new_vars(); |
|
860 | + $values['form_key'] = $filename; |
|
861 | + $values['is_template'] = $template; |
|
862 | + $values['status'] = 'published'; |
|
863 | + if ( $default ) { |
|
864 | + $values['default_template'] = 1; |
|
865 | + } |
|
866 | + |
|
867 | + include( $templates[ $i ] ); |
|
868 | + |
|
869 | + //get updated form |
|
870 | + if ( isset($form) && ! empty($form) ) { |
|
871 | + $old_id = $form->id; |
|
872 | + $form = FrmForm::getOne($form->id); |
|
873 | + } else { |
|
874 | + $old_id = false; |
|
875 | 875 | $form = FrmForm::getAll( $template_query, '', 1 ); |
876 | - } |
|
876 | + } |
|
877 | 877 | |
878 | - if ( $form ) { |
|
878 | + if ( $form ) { |
|
879 | 879 | do_action( 'frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id ) ); |
880 | - } |
|
881 | - } |
|
882 | - } |
|
880 | + } |
|
881 | + } |
|
882 | + } |
|
883 | 883 | |
884 | - public static function route() { |
|
885 | - $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
886 | - $vars = array(); |
|
884 | + public static function route() { |
|
885 | + $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
886 | + $vars = array(); |
|
887 | 887 | if ( isset( $_POST['frm_compact_fields'] ) ) { |
888 | 888 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
889 | 889 | |
890 | - $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('"', '\\\"', $_POST['frm_compact_fields'] )))); |
|
891 | - $json_vars = json_decode($json_vars, true); |
|
892 | - if ( empty($json_vars) ) { |
|
893 | - // json decoding failed so we should return an error message |
|
890 | + $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('"', '\\\"', $_POST['frm_compact_fields'] )))); |
|
891 | + $json_vars = json_decode($json_vars, true); |
|
892 | + if ( empty($json_vars) ) { |
|
893 | + // json decoding failed so we should return an error message |
|
894 | 894 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
895 | - if ( 'edit' == $action ) { |
|
896 | - $action = 'update'; |
|
897 | - } |
|
898 | - |
|
899 | - add_filter('frm_validate_form', 'FrmFormsController::json_error'); |
|
900 | - } else { |
|
901 | - $vars = FrmAppHelper::json_to_array($json_vars); |
|
902 | - $action = $vars[ $action ]; |
|
895 | + if ( 'edit' == $action ) { |
|
896 | + $action = 'update'; |
|
897 | + } |
|
898 | + |
|
899 | + add_filter('frm_validate_form', 'FrmFormsController::json_error'); |
|
900 | + } else { |
|
901 | + $vars = FrmAppHelper::json_to_array($json_vars); |
|
902 | + $action = $vars[ $action ]; |
|
903 | 903 | unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); |
904 | 904 | $_REQUEST = array_merge( $_REQUEST, $vars ); |
905 | 905 | $_POST = array_merge( $_POST, $_REQUEST ); |
906 | - } |
|
907 | - } else { |
|
906 | + } |
|
907 | + } else { |
|
908 | 908 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
909 | - if ( isset( $_REQUEST['delete_all'] ) ) { |
|
910 | - // override the action for this page |
|
911 | - $action = 'delete_all'; |
|
912 | - } |
|
913 | - } |
|
909 | + if ( isset( $_REQUEST['delete_all'] ) ) { |
|
910 | + // override the action for this page |
|
911 | + $action = 'delete_all'; |
|
912 | + } |
|
913 | + } |
|
914 | 914 | |
915 | 915 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
916 | - FrmAppHelper::trigger_hook_load( 'form' ); |
|
917 | - |
|
918 | - switch ( $action ) { |
|
919 | - case 'new': |
|
920 | - return self::new_form($vars); |
|
921 | - case 'create': |
|
922 | - case 'edit': |
|
923 | - case 'update': |
|
924 | - case 'duplicate': |
|
925 | - case 'trash': |
|
926 | - case 'untrash': |
|
927 | - case 'destroy': |
|
928 | - case 'delete_all': |
|
929 | - case 'settings': |
|
930 | - case 'update_settings': |
|
916 | + FrmAppHelper::trigger_hook_load( 'form' ); |
|
917 | + |
|
918 | + switch ( $action ) { |
|
919 | + case 'new': |
|
920 | + return self::new_form($vars); |
|
921 | + case 'create': |
|
922 | + case 'edit': |
|
923 | + case 'update': |
|
924 | + case 'duplicate': |
|
925 | + case 'trash': |
|
926 | + case 'untrash': |
|
927 | + case 'destroy': |
|
928 | + case 'delete_all': |
|
929 | + case 'settings': |
|
930 | + case 'update_settings': |
|
931 | 931 | return self::$action( $vars ); |
932 | - default: |
|
932 | + default: |
|
933 | 933 | do_action( 'frm_form_action_' . $action ); |
934 | 934 | if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) { |
935 | - return; |
|
936 | - } |
|
935 | + return; |
|
936 | + } |
|
937 | 937 | |
938 | 938 | $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' ); |
939 | - if ( $action == -1 ) { |
|
939 | + if ( $action == -1 ) { |
|
940 | 940 | $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' ); |
941 | - } |
|
941 | + } |
|
942 | 942 | |
943 | - if ( strpos($action, 'bulk_') === 0 ) { |
|
944 | - FrmAppHelper::remove_get_action(); |
|
945 | - return self::list_form(); |
|
946 | - } |
|
943 | + if ( strpos($action, 'bulk_') === 0 ) { |
|
944 | + FrmAppHelper::remove_get_action(); |
|
945 | + return self::list_form(); |
|
946 | + } |
|
947 | 947 | |
948 | - return self::display_forms_list(); |
|
949 | - } |
|
950 | - } |
|
948 | + return self::display_forms_list(); |
|
949 | + } |
|
950 | + } |
|
951 | 951 | |
952 | - public static function json_error( $errors ) { |
|
953 | - $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
|
954 | - return $errors; |
|
955 | - } |
|
952 | + public static function json_error( $errors ) { |
|
953 | + $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
|
954 | + return $errors; |
|
955 | + } |
|
956 | 956 | |
957 | 957 | |
958 | - /* FRONT-END FORMS */ |
|
959 | - public static function admin_bar_css() { |
|
958 | + /* FRONT-END FORMS */ |
|
959 | + public static function admin_bar_css() { |
|
960 | 960 | if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
961 | - return; |
|
962 | - } |
|
961 | + return; |
|
962 | + } |
|
963 | 963 | |
964 | 964 | add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' ); |
965 | 965 | FrmAppHelper::load_font_style(); |
966 | 966 | } |
967 | 967 | |
968 | 968 | public static function admin_bar_configure() { |
969 | - global $frm_vars; |
|
970 | - if ( empty($frm_vars['forms_loaded']) ) { |
|
971 | - return; |
|
972 | - } |
|
973 | - |
|
974 | - $actions = array(); |
|
975 | - foreach ( $frm_vars['forms_loaded'] as $form ) { |
|
976 | - if ( is_object($form) ) { |
|
977 | - $actions[ $form->id ] = $form->name; |
|
978 | - } |
|
979 | - unset($form); |
|
980 | - } |
|
981 | - |
|
982 | - if ( empty($actions) ) { |
|
983 | - return; |
|
984 | - } |
|
985 | - |
|
986 | - asort($actions); |
|
987 | - |
|
988 | - global $wp_admin_bar; |
|
989 | - |
|
990 | - if ( count($actions) == 1 ) { |
|
991 | - $wp_admin_bar->add_menu( array( |
|
992 | - 'title' => 'Edit Form', |
|
969 | + global $frm_vars; |
|
970 | + if ( empty($frm_vars['forms_loaded']) ) { |
|
971 | + return; |
|
972 | + } |
|
973 | + |
|
974 | + $actions = array(); |
|
975 | + foreach ( $frm_vars['forms_loaded'] as $form ) { |
|
976 | + if ( is_object($form) ) { |
|
977 | + $actions[ $form->id ] = $form->name; |
|
978 | + } |
|
979 | + unset($form); |
|
980 | + } |
|
981 | + |
|
982 | + if ( empty($actions) ) { |
|
983 | + return; |
|
984 | + } |
|
985 | + |
|
986 | + asort($actions); |
|
987 | + |
|
988 | + global $wp_admin_bar; |
|
989 | + |
|
990 | + if ( count($actions) == 1 ) { |
|
991 | + $wp_admin_bar->add_menu( array( |
|
992 | + 'title' => 'Edit Form', |
|
993 | 993 | 'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . current( array_keys( $actions ) ) ), |
994 | - 'id' => 'frm-forms', |
|
995 | - ) ); |
|
996 | - } else { |
|
997 | - $wp_admin_bar->add_menu( array( |
|
998 | - 'id' => 'frm-forms', |
|
999 | - 'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>', |
|
994 | + 'id' => 'frm-forms', |
|
995 | + ) ); |
|
996 | + } else { |
|
997 | + $wp_admin_bar->add_menu( array( |
|
998 | + 'id' => 'frm-forms', |
|
999 | + 'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>', |
|
1000 | 1000 | 'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . current( array_keys( $actions ) ) ), |
1001 | - 'meta' => array( |
|
1001 | + 'meta' => array( |
|
1002 | 1002 | 'title' => __( 'Edit Forms', 'formidable' ), |
1003 | - ), |
|
1004 | - ) ); |
|
1003 | + ), |
|
1004 | + ) ); |
|
1005 | 1005 | |
1006 | - foreach ( $actions as $form_id => $name ) { |
|
1006 | + foreach ( $actions as $form_id => $name ) { |
|
1007 | 1007 | |
1008 | - $wp_admin_bar->add_menu( array( |
|
1009 | - 'parent' => 'frm-forms', |
|
1008 | + $wp_admin_bar->add_menu( array( |
|
1009 | + 'parent' => 'frm-forms', |
|
1010 | 1010 | 'id' => 'edit_form_' . $form_id, |
1011 | - 'title' => empty($name) ? __( '(no title)') : $name, |
|
1011 | + 'title' => empty($name) ? __( '(no title)') : $name, |
|
1012 | 1012 | 'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ), |
1013 | - ) ); |
|
1014 | - } |
|
1015 | - } |
|
1016 | - } |
|
1013 | + ) ); |
|
1014 | + } |
|
1015 | + } |
|
1016 | + } |
|
1017 | 1017 | |
1018 | - //formidable shortcode |
|
1018 | + //formidable shortcode |
|
1019 | 1019 | public static function get_form_shortcode( $atts ) { |
1020 | - global $frm_vars; |
|
1021 | - if ( isset($frm_vars['skip_shortcode']) && $frm_vars['skip_shortcode'] ) { |
|
1022 | - $sc = '[formidable'; |
|
1020 | + global $frm_vars; |
|
1021 | + if ( isset($frm_vars['skip_shortcode']) && $frm_vars['skip_shortcode'] ) { |
|
1022 | + $sc = '[formidable'; |
|
1023 | 1023 | if ( ! empty( $atts ) ) { |
1024 | 1024 | foreach ( $atts as $k => $v ) { |
1025 | 1025 | $sc .= ' ' . $k . '="' . esc_attr( $v ) . '"'; |
1026 | 1026 | } |
1027 | 1027 | } |
1028 | 1028 | return $sc . ']'; |
1029 | - } |
|
1030 | - |
|
1031 | - $shortcode_atts = shortcode_atts( array( |
|
1032 | - 'id' => '', 'key' => '', 'title' => false, 'description' => false, |
|
1033 | - 'readonly' => false, 'entry_id' => false, 'fields' => array(), |
|
1034 | - 'exclude_fields' => array(), 'minimize' => false, |
|
1035 | - ), $atts); |
|
1036 | - do_action('formidable_shortcode_atts', $shortcode_atts, $atts); |
|
1037 | - |
|
1038 | - return self::show_form( |
|
1039 | - $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], |
|
1040 | - $shortcode_atts['description'], $atts |
|
1041 | - ); |
|
1042 | - } |
|
1043 | - |
|
1044 | - public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
|
1045 | - if ( empty( $id ) ) { |
|
1046 | - $id = $key; |
|
1047 | - } |
|
1048 | - |
|
1049 | - $form = self::maybe_get_form_to_show( $id ); |
|
1050 | - if ( ! $form ) { |
|
1051 | - return __( 'Please select a valid form', 'formidable' ); |
|
1052 | - } |
|
1029 | + } |
|
1030 | + |
|
1031 | + $shortcode_atts = shortcode_atts( array( |
|
1032 | + 'id' => '', 'key' => '', 'title' => false, 'description' => false, |
|
1033 | + 'readonly' => false, 'entry_id' => false, 'fields' => array(), |
|
1034 | + 'exclude_fields' => array(), 'minimize' => false, |
|
1035 | + ), $atts); |
|
1036 | + do_action('formidable_shortcode_atts', $shortcode_atts, $atts); |
|
1037 | + |
|
1038 | + return self::show_form( |
|
1039 | + $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], |
|
1040 | + $shortcode_atts['description'], $atts |
|
1041 | + ); |
|
1042 | + } |
|
1043 | + |
|
1044 | + public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
|
1045 | + if ( empty( $id ) ) { |
|
1046 | + $id = $key; |
|
1047 | + } |
|
1048 | + |
|
1049 | + $form = self::maybe_get_form_to_show( $id ); |
|
1050 | + if ( ! $form ) { |
|
1051 | + return __( 'Please select a valid form', 'formidable' ); |
|
1052 | + } |
|
1053 | 1053 | |
1054 | 1054 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
1055 | - FrmAppHelper::trigger_hook_load( 'form', $form ); |
|
1055 | + FrmAppHelper::trigger_hook_load( 'form', $form ); |
|
1056 | 1056 | |
1057 | - $form = apply_filters( 'frm_pre_display_form', $form ); |
|
1057 | + $form = apply_filters( 'frm_pre_display_form', $form ); |
|
1058 | 1058 | |
1059 | - $frm_settings = FrmAppHelper::get_settings(); |
|
1059 | + $frm_settings = FrmAppHelper::get_settings(); |
|
1060 | 1060 | |
1061 | 1061 | if ( self::is_viewable_draft_form( $form ) ) { |
1062 | 1062 | // don't show a draft form on a page |
@@ -1077,7 +1077,7 @@ discard block |
||
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | return $form; |
1080 | - } |
|
1080 | + } |
|
1081 | 1081 | |
1082 | 1082 | private static function maybe_get_form_to_show( $id ) { |
1083 | 1083 | $form = false; |
@@ -1106,98 +1106,98 @@ discard block |
||
1106 | 1106 | return $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] ); |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - public static function get_form( $form, $title, $description, $atts = array() ) { |
|
1110 | - ob_start(); |
|
1109 | + public static function get_form( $form, $title, $description, $atts = array() ) { |
|
1110 | + ob_start(); |
|
1111 | 1111 | |
1112 | - self::get_form_contents( $form, $title, $description, $atts ); |
|
1112 | + self::get_form_contents( $form, $title, $description, $atts ); |
|
1113 | 1113 | self::enqueue_scripts( FrmForm::get_params( $form ) ); |
1114 | 1114 | |
1115 | - $contents = ob_get_contents(); |
|
1116 | - ob_end_clean(); |
|
1115 | + $contents = ob_get_contents(); |
|
1116 | + ob_end_clean(); |
|
1117 | 1117 | |
1118 | 1118 | self::maybe_minimize_form( $atts, $contents ); |
1119 | 1119 | |
1120 | - return $contents; |
|
1121 | - } |
|
1120 | + return $contents; |
|
1121 | + } |
|
1122 | 1122 | |
1123 | 1123 | public static function enqueue_scripts( $params ) { |
1124 | 1124 | do_action( 'frm_enqueue_form_scripts', $params ); |
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | public static function get_form_contents( $form, $title, $description, $atts ) { |
1128 | - global $frm_vars; |
|
1128 | + global $frm_vars; |
|
1129 | 1129 | |
1130 | - $frm_settings = FrmAppHelper::get_settings(); |
|
1130 | + $frm_settings = FrmAppHelper::get_settings(); |
|
1131 | 1131 | |
1132 | - $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value; |
|
1132 | + $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value; |
|
1133 | 1133 | |
1134 | - $user_ID = get_current_user_id(); |
|
1134 | + $user_ID = get_current_user_id(); |
|
1135 | 1135 | $params = FrmForm::get_params( $form ); |
1136 | - $message = $errors = ''; |
|
1136 | + $message = $errors = ''; |
|
1137 | 1137 | |
1138 | - if ( $params['posted_form_id'] == $form->id && $_POST ) { |
|
1139 | - $errors = isset( $frm_vars['created_entries'][ $form->id ] ) ? $frm_vars['created_entries'][ $form->id ]['errors'] : array(); |
|
1140 | - } |
|
1138 | + if ( $params['posted_form_id'] == $form->id && $_POST ) { |
|
1139 | + $errors = isset( $frm_vars['created_entries'][ $form->id ] ) ? $frm_vars['created_entries'][ $form->id ]['errors'] : array(); |
|
1140 | + } |
|
1141 | 1141 | |
1142 | 1142 | $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form ); |
1143 | - $fields = FrmFieldsHelper::get_form_fields( $form->id, ( isset( $errors ) && ! empty( $errors ) ) ); |
|
1143 | + $fields = FrmFieldsHelper::get_form_fields( $form->id, ( isset( $errors ) && ! empty( $errors ) ) ); |
|
1144 | 1144 | |
1145 | - if ( $params['action'] != 'create' || $params['posted_form_id'] != $form->id || ! $_POST ) { |
|
1146 | - do_action('frm_display_form_action', $params, $fields, $form, $title, $description); |
|
1147 | - if ( apply_filters('frm_continue_to_new', true, $form->id, $params['action']) ) { |
|
1148 | - $values = FrmEntriesHelper::setup_new_vars($fields, $form); |
|
1145 | + if ( $params['action'] != 'create' || $params['posted_form_id'] != $form->id || ! $_POST ) { |
|
1146 | + do_action('frm_display_form_action', $params, $fields, $form, $title, $description); |
|
1147 | + if ( apply_filters('frm_continue_to_new', true, $form->id, $params['action']) ) { |
|
1148 | + $values = FrmEntriesHelper::setup_new_vars($fields, $form); |
|
1149 | 1149 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' ); |
1150 | - } |
|
1151 | - return; |
|
1152 | - } |
|
1150 | + } |
|
1151 | + return; |
|
1152 | + } |
|
1153 | 1153 | |
1154 | - if ( ! empty($errors) ) { |
|
1155 | - $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array(); |
|
1154 | + if ( ! empty($errors) ) { |
|
1155 | + $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array(); |
|
1156 | 1156 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' ); |
1157 | - return; |
|
1158 | - } |
|
1157 | + return; |
|
1158 | + } |
|
1159 | 1159 | |
1160 | - do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description); |
|
1161 | - if ( ! apply_filters('frm_continue_to_create', true, $form->id) ) { |
|
1162 | - return; |
|
1163 | - } |
|
1160 | + do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description); |
|
1161 | + if ( ! apply_filters('frm_continue_to_create', true, $form->id) ) { |
|
1162 | + return; |
|
1163 | + } |
|
1164 | 1164 | |
1165 | - $values = FrmEntriesHelper::setup_new_vars($fields, $form, true); |
|
1166 | - $created = self::just_created_entry( $form->id ); |
|
1167 | - $conf_method = apply_filters('frm_success_filter', 'message', $form, 'create'); |
|
1165 | + $values = FrmEntriesHelper::setup_new_vars($fields, $form, true); |
|
1166 | + $created = self::just_created_entry( $form->id ); |
|
1167 | + $conf_method = apply_filters('frm_success_filter', 'message', $form, 'create'); |
|
1168 | 1168 | |
1169 | - if ( $created && is_numeric($created) && $conf_method != 'message' ) { |
|
1170 | - do_action('frm_success_action', $conf_method, $form, $form->options, $created); |
|
1169 | + if ( $created && is_numeric($created) && $conf_method != 'message' ) { |
|
1170 | + do_action('frm_success_action', $conf_method, $form, $form->options, $created); |
|
1171 | 1171 | do_action( 'frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form ) ); |
1172 | - return; |
|
1173 | - } |
|
1172 | + return; |
|
1173 | + } |
|
1174 | 1174 | |
1175 | - if ( $created && is_numeric($created) ) { |
|
1176 | - $message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg; |
|
1177 | - $class = 'frm_message'; |
|
1178 | - } else { |
|
1179 | - $message = $frm_settings->failed_msg; |
|
1180 | - $class = FrmFormsHelper::form_error_class(); |
|
1181 | - } |
|
1175 | + if ( $created && is_numeric($created) ) { |
|
1176 | + $message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg; |
|
1177 | + $class = 'frm_message'; |
|
1178 | + } else { |
|
1179 | + $message = $frm_settings->failed_msg; |
|
1180 | + $class = FrmFormsHelper::form_error_class(); |
|
1181 | + } |
|
1182 | 1182 | |
1183 | 1183 | $message = FrmFormsHelper::get_success_message( array( |
1184 | 1184 | 'message' => $message, 'form' => $form, |
1185 | 1185 | 'entry_id' => $created, 'class' => $class, |
1186 | 1186 | ) ); |
1187 | - $message = apply_filters('frm_main_feedback', $message, $form, $created); |
|
1187 | + $message = apply_filters('frm_main_feedback', $message, $form, $created); |
|
1188 | 1188 | |
1189 | - if ( ! isset($form->options['show_form']) || $form->options['show_form'] ) { |
|
1189 | + if ( ! isset($form->options['show_form']) || $form->options['show_form'] ) { |
|
1190 | 1190 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' ); |
1191 | - } else { |
|
1192 | - global $frm_vars; |
|
1191 | + } else { |
|
1192 | + global $frm_vars; |
|
1193 | 1193 | self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] ); |
1194 | 1194 | |
1195 | 1195 | $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values ); |
1196 | 1196 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' ); |
1197 | - } |
|
1197 | + } |
|
1198 | 1198 | |
1199 | 1199 | do_action( 'frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form ) ); |
1200 | - } |
|
1200 | + } |
|
1201 | 1201 | |
1202 | 1202 | /** |
1203 | 1203 | * @since 2.2.7 |
@@ -1234,10 +1234,10 @@ discard block |
||
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | public static function defer_script_loading( $tag, $handle ) { |
1237 | - if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) { |
|
1238 | - $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag ); |
|
1237 | + if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) { |
|
1238 | + $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag ); |
|
1239 | 1239 | } |
1240 | - return $tag; |
|
1240 | + return $tag; |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | public static function footer_js( $location = 'footer' ) { |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | /* Check if logged in */ |
13 | 13 | if ( is_user_logged_in() ) { |
14 | - return $response; |
|
14 | + return $response; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /* Honeypot */ |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | - * Check for form submission time |
|
69 | - * |
|
70 | - * @return boolean TRUE if the action time is less than 5 seconds |
|
71 | - */ |
|
68 | + * Check for form submission time |
|
69 | + * |
|
70 | + * @return boolean TRUE if the action time is less than 5 seconds |
|
71 | + */ |
|
72 | 72 | |
73 | 73 | private static function _is_shortest_time() { |
74 | 74 | $too_short = false; |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | - * Check for an IPv6 address |
|
128 | - * |
|
129 | - * @param string $ip IP to validate |
|
130 | - * @return boolean TRUE if IPv6 |
|
131 | - */ |
|
127 | + * Check for an IPv6 address |
|
128 | + * |
|
129 | + * @param string $ip IP to validate |
|
130 | + * @return boolean TRUE if IPv6 |
|
131 | + */ |
|
132 | 132 | |
133 | 133 | private static function _is_ipv6( $ip ) { |
134 | 134 | if ( function_exists('filter_var') ) { |
@@ -98,6 +98,9 @@ discard block |
||
98 | 98 | return (bool) preg_match( '/\[url[=\]].*\[\/url\]/is', $body ); |
99 | 99 | } |
100 | 100 | |
101 | + /** |
|
102 | + * @param string $client_ip |
|
103 | + */ |
|
101 | 104 | private static function _is_fake_ip( $client_ip, $client_host = false ) { |
102 | 105 | /* Remote Host */ |
103 | 106 | $host_by_ip = gethostbyaddr( $client_ip ); |
@@ -159,6 +162,9 @@ discard block |
||
159 | 162 | } |
160 | 163 | } |
161 | 164 | |
165 | + /** |
|
166 | + * @param string $ip |
|
167 | + */ |
|
162 | 168 | private static function _cut_ip( $ip, $cut_end = true ) { |
163 | 169 | $separator = ( self::_is_ipv4( $ip ) ? '.' : ':' ); |
164 | 170 | $part = ( $cut_end ? strrchr( $ip, $separator ) : strstr( $ip, $separator ) ); |
@@ -252,6 +258,9 @@ discard block |
||
252 | 258 | return false; |
253 | 259 | } |
254 | 260 | |
261 | + /** |
|
262 | + * @param string $ip |
|
263 | + */ |
|
255 | 264 | private static function _is_dnsbl_spam( $ip ) { |
256 | 265 | |
257 | 266 | $response = wp_safe_remote_request( |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | |
140 | 140 | private static function _is_ipv6( $ip ) { |
141 | - if ( function_exists('filter_var') ) { |
|
141 | + if ( function_exists( 'filter_var' ) ) { |
|
142 | 142 | return filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) !== false; |
143 | 143 | } else { |
144 | 144 | return ! self::_is_ipv4( $ip ); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @return integer TRUE if IPv4 |
153 | 153 | */ |
154 | 154 | private static function _is_ipv4( $ip ) { |
155 | - if ( function_exists('filter_var') ) { |
|
155 | + if ( function_exists( 'filter_var' ) ) { |
|
156 | 156 | return filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) !== false; |
157 | 157 | } else { |
158 | 158 | return preg_match( '/^\d{1,3}(\.\d{1,3}){3,3}$/', $ip ); |
@@ -232,15 +232,15 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | /* Ignore non utf-8 chars */ |
235 | - $comment[ $field ] = ( function_exists('iconv') ? iconv( 'utf-8', 'utf-8//TRANSLIT', $comment[ $field ] ) : $comment[ $field ] ); |
|
235 | + $comment[$field] = ( function_exists( 'iconv' ) ? iconv( 'utf-8', 'utf-8//TRANSLIT', $comment[$field] ) : $comment[$field] ); |
|
236 | 236 | |
237 | - if ( empty( $comment[ $field ] ) ) { |
|
237 | + if ( empty( $comment[$field] ) ) { |
|
238 | 238 | continue; |
239 | 239 | } |
240 | 240 | |
241 | 241 | /* Perform regex */ |
242 | - if ( preg_match( '/' .$regexp. '/isu', $comment[ $field ] ) ) { |
|
243 | - $hits[ $field ] = true; |
|
242 | + if ( preg_match( '/' . $regexp . '/isu', $comment[$field] ) ) { |
|
243 | + $hits[$field] = true; |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 |
@@ -1,26 +1,26 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class FrmEntryValidate { |
4 | - public static function validate( $values, $exclude = false ) { |
|
5 | - global $wpdb; |
|
4 | + public static function validate( $values, $exclude = false ) { |
|
5 | + global $wpdb; |
|
6 | 6 | |
7 | - FrmEntry::sanitize_entry_post( $values ); |
|
8 | - $errors = array(); |
|
7 | + FrmEntry::sanitize_entry_post( $values ); |
|
8 | + $errors = array(); |
|
9 | 9 | |
10 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
11 | - $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
12 | - return $errors; |
|
13 | - } |
|
10 | + if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
11 | + $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
12 | + return $errors; |
|
13 | + } |
|
14 | 14 | |
15 | 15 | if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) { |
16 | - $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
17 | - } |
|
16 | + $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
17 | + } |
|
18 | 18 | |
19 | - if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
19 | + if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
20 | 20 | $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | - $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
23 | + $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
24 | 24 | // Don't get subfields |
25 | 25 | $where['fr.parent_form_id'] = array( null, 0 ); |
26 | 26 | // Don't get excluded fields (like file upload fields in the ajax validation) |
@@ -28,42 +28,42 @@ discard block |
||
28 | 28 | $where['fi.type not'] = $exclude; |
29 | 29 | } |
30 | 30 | |
31 | - $posted_fields = FrmField::getAll($where, 'field_order'); |
|
31 | + $posted_fields = FrmField::getAll($where, 'field_order'); |
|
32 | 32 | |
33 | - // Pass exclude value to validate_field function so it can be used for repeating sections |
|
34 | - $args = array( 'exclude' => $exclude ); |
|
33 | + // Pass exclude value to validate_field function so it can be used for repeating sections |
|
34 | + $args = array( 'exclude' => $exclude ); |
|
35 | 35 | |
36 | - foreach ( $posted_fields as $posted_field ) { |
|
37 | - self::validate_field($posted_field, $errors, $values, $args); |
|
38 | - unset($posted_field); |
|
39 | - } |
|
36 | + foreach ( $posted_fields as $posted_field ) { |
|
37 | + self::validate_field($posted_field, $errors, $values, $args); |
|
38 | + unset($posted_field); |
|
39 | + } |
|
40 | 40 | |
41 | - // check for spam |
|
42 | - self::spam_check( $exclude, $values, $errors ); |
|
41 | + // check for spam |
|
42 | + self::spam_check( $exclude, $values, $errors ); |
|
43 | 43 | |
44 | - $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
44 | + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
45 | 45 | |
46 | - return $errors; |
|
47 | - } |
|
46 | + return $errors; |
|
47 | + } |
|
48 | 48 | |
49 | - public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
50 | - $defaults = array( |
|
51 | - 'id' => $posted_field->id, |
|
52 | - 'parent_field_id' => '', // the id of the repeat or embed form |
|
53 | - 'key_pointer' => '', // the pointer in the posted array |
|
54 | - 'exclude' => array(), // exclude these field types from validation |
|
55 | - ); |
|
56 | - $args = wp_parse_args( $args, $defaults ); |
|
49 | + public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
50 | + $defaults = array( |
|
51 | + 'id' => $posted_field->id, |
|
52 | + 'parent_field_id' => '', // the id of the repeat or embed form |
|
53 | + 'key_pointer' => '', // the pointer in the posted array |
|
54 | + 'exclude' => array(), // exclude these field types from validation |
|
55 | + ); |
|
56 | + $args = wp_parse_args( $args, $defaults ); |
|
57 | 57 | |
58 | - if ( empty($args['parent_field_id']) ) { |
|
58 | + if ( empty($args['parent_field_id']) ) { |
|
59 | 59 | $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
60 | - } else { |
|
61 | - // value is from a nested form |
|
62 | - $value = $values; |
|
63 | - } |
|
60 | + } else { |
|
61 | + // value is from a nested form |
|
62 | + $value = $values; |
|
63 | + } |
|
64 | 64 | |
65 | - // Check for values in "Other" fields |
|
66 | - FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
65 | + // Check for values in "Other" fields |
|
66 | + FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
67 | 67 | |
68 | 68 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
69 | 69 | |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | $value = reset($value); |
73 | 73 | } |
74 | 74 | |
75 | - if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
75 | + if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
76 | 76 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
77 | - } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
78 | - $_POST['item_name'] = $value; |
|
79 | - } |
|
77 | + } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
78 | + $_POST['item_name'] = $value; |
|
79 | + } |
|
80 | 80 | |
81 | 81 | if ( $value != '' ) { |
82 | 82 | self::validate_url_field( $errors, $posted_field, $value, $args ); |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
86 | 86 | } |
87 | 87 | |
88 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
88 | + FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
89 | 89 | |
90 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
90 | + self::validate_recaptcha($errors, $posted_field, $args); |
|
91 | 91 | |
92 | 92 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
93 | 93 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | 96 | private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) { |
97 | 97 | if ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value ) { |
@@ -101,32 +101,32 @@ discard block |
||
101 | 101 | |
102 | 102 | public static function validate_url_field( &$errors, $field, &$value, $args ) { |
103 | 103 | if ( $value == '' || ! in_array( $field->type, array( 'website', 'url', 'image' ) ) ) { |
104 | - return; |
|
105 | - } |
|
104 | + return; |
|
105 | + } |
|
106 | 106 | |
107 | - if ( trim($value) == 'http://' ) { |
|
108 | - $value = ''; |
|
109 | - } else { |
|
110 | - $value = esc_url_raw( $value ); |
|
107 | + if ( trim($value) == 'http://' ) { |
|
108 | + $value = ''; |
|
109 | + } else { |
|
110 | + $value = esc_url_raw( $value ); |
|
111 | 111 | $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'http://' . $value; |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - // validate the url format |
|
114 | + // validate the url format |
|
115 | 115 | if ( ! preg_match('/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value) ) { |
116 | 116 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
117 | 117 | } |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | 120 | public static function validate_email_field( &$errors, $field, $value, $args ) { |
121 | - if ( $value == '' || $field->type != 'email' ) { |
|
122 | - return; |
|
123 | - } |
|
121 | + if ( $value == '' || $field->type != 'email' ) { |
|
122 | + return; |
|
123 | + } |
|
124 | 124 | |
125 | - //validate the email format |
|
126 | - if ( ! is_email($value) ) { |
|
125 | + //validate the email format |
|
126 | + if ( ! is_email($value) ) { |
|
127 | 127 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
128 | - } |
|
129 | - } |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | 131 | public static function validate_number_field( &$errors, $field, $value, $args ) { |
132 | 132 | //validate the number format |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | } |
221 | 221 | |
222 | 222 | public static function validate_recaptcha( &$errors, $field, $args ) { |
223 | - if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
224 | - return; |
|
225 | - } |
|
223 | + if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
224 | + return; |
|
225 | + } |
|
226 | 226 | |
227 | 227 | $frm_settings = FrmAppHelper::get_settings(); |
228 | 228 | if ( empty( $frm_settings->pubkey ) ) { |
@@ -230,57 +230,57 @@ discard block |
||
230 | 230 | return; |
231 | 231 | } |
232 | 232 | |
233 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
234 | - // If captcha is missing, check if it was already verified |
|
233 | + if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
234 | + // If captcha is missing, check if it was already verified |
|
235 | 235 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
236 | - // There was no captcha submitted |
|
236 | + // There was no captcha submitted |
|
237 | 237 | $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
238 | - } |
|
239 | - return; |
|
240 | - } |
|
238 | + } |
|
239 | + return; |
|
240 | + } |
|
241 | 241 | |
242 | - $arg_array = array( |
|
243 | - 'body' => array( |
|
242 | + $arg_array = array( |
|
243 | + 'body' => array( |
|
244 | 244 | 'secret' => $frm_settings->privkey, |
245 | 245 | 'response' => $_POST['g-recaptcha-response'], |
246 | 246 | 'remoteip' => FrmAppHelper::get_ip_address(), |
247 | 247 | ), |
248 | 248 | ); |
249 | - $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
250 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
249 | + $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
250 | + $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
251 | 251 | |
252 | - if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
253 | - // What happens when the CAPTCHA was entered incorrectly |
|
252 | + if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
253 | + // What happens when the CAPTCHA was entered incorrectly |
|
254 | 254 | $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
255 | - } else if ( is_wp_error( $resp ) ) { |
|
255 | + } else if ( is_wp_error( $resp ) ) { |
|
256 | 256 | $error_string = $resp->get_error_message(); |
257 | 257 | $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
258 | 258 | $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * check for spam |
|
264 | - * @param boolean $exclude |
|
265 | - * @param array $values |
|
266 | - * @param array $errors by reference |
|
267 | - */ |
|
268 | - public static function spam_check( $exclude, $values, &$errors ) { |
|
269 | - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
270 | - // only check spam if there are no other errors |
|
271 | - return; |
|
272 | - } |
|
273 | - |
|
274 | - if ( self::is_akismet_spam( $values ) ) { |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * check for spam |
|
264 | + * @param boolean $exclude |
|
265 | + * @param array $values |
|
266 | + * @param array $errors by reference |
|
267 | + */ |
|
268 | + public static function spam_check( $exclude, $values, &$errors ) { |
|
269 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
270 | + // only check spam if there are no other errors |
|
271 | + return; |
|
272 | + } |
|
273 | + |
|
274 | + if ( self::is_akismet_spam( $values ) ) { |
|
275 | 275 | if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) { |
276 | 276 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
277 | 277 | } |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - if ( self::blacklist_check( $values ) ) { |
|
281 | - $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
|
282 | - } |
|
283 | - } |
|
280 | + if ( self::blacklist_check( $values ) ) { |
|
281 | + $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
|
282 | + } |
|
283 | + } |
|
284 | 284 | |
285 | 285 | private static function is_akismet_spam( $values ) { |
286 | 286 | global $wpcom_api_key; |
@@ -292,21 +292,21 @@ discard block |
||
292 | 292 | return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ); |
293 | 293 | } |
294 | 294 | |
295 | - public static function blacklist_check( $values ) { |
|
296 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
297 | - return false; |
|
298 | - } |
|
295 | + public static function blacklist_check( $values ) { |
|
296 | + if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
297 | + return false; |
|
298 | + } |
|
299 | 299 | |
300 | - $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
300 | + $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
301 | 301 | |
302 | - if ( empty( $mod_keys ) ) { |
|
303 | - return false; |
|
304 | - } |
|
302 | + if ( empty( $mod_keys ) ) { |
|
303 | + return false; |
|
304 | + } |
|
305 | 305 | |
306 | - $content = FrmEntriesHelper::entry_array_to_string($values); |
|
306 | + $content = FrmEntriesHelper::entry_array_to_string($values); |
|
307 | 307 | |
308 | 308 | if ( empty($content) ) { |
309 | - return false; |
|
309 | + return false; |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $content = strtolower( $content ); |
@@ -314,10 +314,10 @@ discard block |
||
314 | 314 | $ip = FrmAppHelper::get_ip_address(); |
315 | 315 | $user_agent = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
316 | 316 | |
317 | - $words = explode( "\n", $mod_keys ); |
|
317 | + $words = explode( "\n", $mod_keys ); |
|
318 | 318 | |
319 | - foreach ( (array) $words as $word ) { |
|
320 | - $word = trim( $word ); |
|
319 | + foreach ( (array) $words as $word ) { |
|
320 | + $word = trim( $word ); |
|
321 | 321 | |
322 | 322 | if ( empty( $word ) ) { |
323 | 323 | continue; |
@@ -332,27 +332,27 @@ discard block |
||
332 | 332 | $in_content = preg_match( $pattern, $content ) || preg_match( $pattern, $content_without_html ); |
333 | 333 | $blacklist_user = preg_match( $pattern, $ip ) || preg_match( $pattern, $user_agent ); |
334 | 334 | if ( $in_content || $blacklist_user ) { |
335 | - return true; |
|
336 | - } |
|
337 | - } |
|
335 | + return true; |
|
336 | + } |
|
337 | + } |
|
338 | 338 | |
339 | - return false; |
|
340 | - } |
|
339 | + return false; |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * Check entries for spam |
|
344 | - * |
|
345 | - * @return boolean true if is spam |
|
346 | - */ |
|
347 | - public static function akismet( $values ) { |
|
348 | - $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
342 | + /** |
|
343 | + * Check entries for spam |
|
344 | + * |
|
345 | + * @return boolean true if is spam |
|
346 | + */ |
|
347 | + public static function akismet( $values ) { |
|
348 | + $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
349 | 349 | |
350 | 350 | if ( empty( $content ) ) { |
351 | - return false; |
|
351 | + return false; |
|
352 | 352 | } |
353 | 353 | |
354 | - $datas = array(); |
|
355 | - self::parse_akismet_array( $datas, $content ); |
|
354 | + $datas = array(); |
|
355 | + self::parse_akismet_array( $datas, $content ); |
|
356 | 356 | |
357 | 357 | $query_string = ''; |
358 | 358 | foreach ( $datas as $key => $data ) { |
@@ -360,35 +360,35 @@ discard block |
||
360 | 360 | unset( $key, $data ); |
361 | 361 | } |
362 | 362 | |
363 | - $response = Akismet::http_post($query_string, 'comment-check'); |
|
363 | + $response = Akismet::http_post($query_string, 'comment-check'); |
|
364 | 364 | |
365 | 365 | return ( is_array( $response ) && $response[1] == 'true' ); |
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * @since 2.0 |
|
370 | - * @param string $content |
|
371 | - */ |
|
372 | - private static function parse_akismet_array( &$datas, $content ) { |
|
373 | - $datas['blog'] = FrmAppHelper::site_url(); |
|
374 | - $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() ); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * @since 2.0 |
|
370 | + * @param string $content |
|
371 | + */ |
|
372 | + private static function parse_akismet_array( &$datas, $content ) { |
|
373 | + $datas['blog'] = FrmAppHelper::site_url(); |
|
374 | + $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() ); |
|
375 | 375 | $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
376 | 376 | $datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false; |
377 | - $datas['comment_type'] = 'formidable'; |
|
378 | - $datas['comment_content'] = $content; |
|
377 | + $datas['comment_type'] = 'formidable'; |
|
378 | + $datas['comment_content'] = $content; |
|
379 | 379 | |
380 | - if ( $permalink = get_permalink() ) { |
|
381 | - $datas['permalink'] = $permalink; |
|
382 | - } |
|
380 | + if ( $permalink = get_permalink() ) { |
|
381 | + $datas['permalink'] = $permalink; |
|
382 | + } |
|
383 | 383 | |
384 | - foreach ( $_SERVER as $key => $value ) { |
|
384 | + foreach ( $_SERVER as $key => $value ) { |
|
385 | 385 | if ( ! in_array( $key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) ) && is_string( $value ) ) { |
386 | 386 | $datas[ $key ] = wp_strip_all_tags( $value ); |
387 | - } else { |
|
387 | + } else { |
|
388 | 388 | $datas[ $key ] = ''; |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | - unset($key, $value); |
|
392 | - } |
|
393 | - } |
|
391 | + unset($key, $value); |
|
392 | + } |
|
393 | + } |
|
394 | 394 | } |
@@ -7,20 +7,20 @@ discard block |
||
7 | 7 | FrmEntry::sanitize_entry_post( $values ); |
8 | 8 | $errors = array(); |
9 | 9 | |
10 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
10 | + if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) { |
|
11 | 11 | $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
12 | 12 | return $errors; |
13 | 13 | } |
14 | 14 | |
15 | - if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) { |
|
15 | + if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values['frm_submit_entry_' . $values['form_id']] ) || ! wp_verify_nonce( $values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce' ) ) ) { |
|
16 | 16 | $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
17 | 17 | } |
18 | 18 | |
19 | - if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
19 | + if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) { |
|
20 | 20 | $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
21 | 21 | } |
22 | 22 | |
23 | - $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
23 | + $where = apply_filters( 'frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
24 | 24 | // Don't get subfields |
25 | 25 | $where['fr.parent_form_id'] = array( null, 0 ); |
26 | 26 | // Don't get excluded fields (like file upload fields in the ajax validation) |
@@ -28,20 +28,20 @@ discard block |
||
28 | 28 | $where['fi.type not'] = $exclude; |
29 | 29 | } |
30 | 30 | |
31 | - $posted_fields = FrmField::getAll($where, 'field_order'); |
|
31 | + $posted_fields = FrmField::getAll( $where, 'field_order' ); |
|
32 | 32 | |
33 | 33 | // Pass exclude value to validate_field function so it can be used for repeating sections |
34 | 34 | $args = array( 'exclude' => $exclude ); |
35 | 35 | |
36 | 36 | foreach ( $posted_fields as $posted_field ) { |
37 | - self::validate_field($posted_field, $errors, $values, $args); |
|
38 | - unset($posted_field); |
|
37 | + self::validate_field( $posted_field, $errors, $values, $args ); |
|
38 | + unset( $posted_field ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | // check for spam |
42 | 42 | self::spam_check( $exclude, $values, $errors ); |
43 | 43 | |
44 | - $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
44 | + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude' ) ); |
|
45 | 45 | |
46 | 46 | return $errors; |
47 | 47 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | ); |
56 | 56 | $args = wp_parse_args( $args, $defaults ); |
57 | 57 | |
58 | - if ( empty($args['parent_field_id']) ) { |
|
59 | - $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
|
58 | + if ( empty( $args['parent_field_id'] ) ) { |
|
59 | + $value = isset( $values['item_meta'][$args['id']] ) ? $values['item_meta'][$args['id']] : ''; |
|
60 | 60 | } else { |
61 | 61 | // value is from a nested form |
62 | 62 | $value = $values; |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
69 | 69 | |
70 | 70 | // Reset arrays with only one value if it's not a field where array keys need to be preserved |
71 | - if ( is_array($value) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
72 | - $value = reset($value); |
|
71 | + if ( is_array( $value ) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
72 | + $value = reset( $value ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
76 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
76 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
77 | 77 | } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
78 | 78 | $_POST['item_name'] = $value; |
79 | 79 | } |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
86 | 86 | } |
87 | 87 | |
88 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
88 | + FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
|
89 | 89 | |
90 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
90 | + self::validate_recaptcha( $errors, $posted_field, $args ); |
|
91 | 91 | |
92 | 92 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
93 | 93 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
107 | - if ( trim($value) == 'http://' ) { |
|
107 | + if ( trim( $value ) == 'http://' ) { |
|
108 | 108 | $value = ''; |
109 | 109 | } else { |
110 | 110 | $value = esc_url_raw( $value ); |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | // validate the url format |
115 | - if ( ! preg_match('/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value) ) { |
|
116 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
115 | + if ( ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) { |
|
116 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | //validate the email format |
126 | - if ( ! is_email($value) ) { |
|
127 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
126 | + if ( ! is_email( $value ) ) { |
|
127 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - if ( ! is_numeric( $value) ) { |
|
138 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
137 | + if ( ! is_numeric( $value ) ) { |
|
138 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | // validate number settings |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | if ( $frm_settings->use_html && isset( $field->field_options['minnum'] ) && isset( $field->field_options['maxnum'] ) ) { |
146 | 146 | //minnum maxnum |
147 | 147 | if ( (float) $value < $field->field_options['minnum'] ) { |
148 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' ); |
|
148 | + $errors['field' . $args['id']] = __( 'Please select a higher number', 'formidable' ); |
|
149 | 149 | } else if ( (float) $value > $field->field_options['maxnum'] ) { |
150 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' ); |
|
150 | + $errors['field' . $args['id']] = __( 'Please select a lower number', 'formidable' ); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $pattern = self::phone_format( $field ); |
160 | 160 | |
161 | 161 | if ( ! preg_match( $pattern, $value ) ) { |
162 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
162 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
@@ -230,11 +230,11 @@ discard block |
||
230 | 230 | return; |
231 | 231 | } |
232 | 232 | |
233 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
233 | + if ( ! isset( $_POST['g-recaptcha-response'] ) ) { |
|
234 | 234 | // If captcha is missing, check if it was already verified |
235 | 235 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
236 | 236 | // There was no captcha submitted |
237 | - $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
|
237 | + $errors['field' . $args['id']] = __( 'The captcha is missing from this form', 'formidable' ); |
|
238 | 238 | } |
239 | 239 | return; |
240 | 240 | } |
@@ -247,15 +247,15 @@ discard block |
||
247 | 247 | ), |
248 | 248 | ); |
249 | 249 | $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
250 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
250 | + $response = json_decode( wp_remote_retrieve_body( $resp ), true ); |
|
251 | 251 | |
252 | 252 | if ( isset( $response['success'] ) && ! $response['success'] ) { |
253 | 253 | // What happens when the CAPTCHA was entered incorrectly |
254 | - $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
254 | + $errors['field' . $args['id']] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
255 | 255 | } else if ( is_wp_error( $resp ) ) { |
256 | 256 | $error_string = $resp->get_error_message(); |
257 | - $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
258 | - $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
|
257 | + $errors['field' . $args['id']] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
258 | + $errors['field' . $args['id']] .= ' ' . $error_string; |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | |
285 | 285 | private static function is_akismet_spam( $values ) { |
286 | 286 | global $wpcom_api_key; |
287 | - return ( is_callable('Akismet::http_post') && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet( $values ) ); |
|
287 | + return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) ); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | private static function is_akismet_enabled_for_user( $form_id ) { |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | public static function blacklist_check( $values ) { |
296 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
296 | + if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) { |
|
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | |
306 | - $content = FrmEntriesHelper::entry_array_to_string($values); |
|
306 | + $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
307 | 307 | |
308 | - if ( empty($content) ) { |
|
308 | + if ( empty( $content ) ) { |
|
309 | 309 | return false; |
310 | 310 | } |
311 | 311 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | unset( $key, $data ); |
361 | 361 | } |
362 | 362 | |
363 | - $response = Akismet::http_post($query_string, 'comment-check'); |
|
363 | + $response = Akismet::http_post( $query_string, 'comment-check' ); |
|
364 | 364 | |
365 | 365 | return ( is_array( $response ) && $response[1] == 'true' ); |
366 | 366 | } |
@@ -383,12 +383,12 @@ discard block |
||
383 | 383 | |
384 | 384 | foreach ( $_SERVER as $key => $value ) { |
385 | 385 | if ( ! in_array( $key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) ) && is_string( $value ) ) { |
386 | - $datas[ $key ] = wp_strip_all_tags( $value ); |
|
386 | + $datas[$key] = wp_strip_all_tags( $value ); |
|
387 | 387 | } else { |
388 | - $datas[ $key ] = ''; |
|
388 | + $datas[$key] = ''; |
|
389 | 389 | } |
390 | 390 | |
391 | - unset($key, $value); |
|
391 | + unset( $key, $value ); |
|
392 | 392 | } |
393 | 393 | } |
394 | 394 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | color:<?php echo esc_html( $text_color . $important ) ?>; |
310 | 310 | background-color:<?php echo esc_html( $bg_color . $important ); ?>; |
311 | 311 | <?php if ( ! empty($important) ) { |
312 | - echo esc_html( 'background-image:none' . $important . ';' ); |
|
312 | + echo esc_html( 'background-image:none' . $important . ';' ); |
|
313 | 313 | } |
314 | 314 | ?> |
315 | 315 | border-color: <?php echo esc_html( $border_color . $important ) ?>; |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | color: <?php echo esc_html( $submit_active_color . $important ) ?>; |
553 | 553 | } |
554 | 554 | <?php |
555 | - } |
|
555 | + } |
|
556 | 556 | } |
557 | 557 | ?> |
558 | 558 | |
@@ -877,11 +877,11 @@ discard block |
||
877 | 877 | |
878 | 878 | .<?php echo esc_html( $style_class ) ?> .chosen-container-single .chosen-single div{ |
879 | 879 | <?php |
880 | - // calculate the top position based on field padding |
|
881 | - $top_pad = explode(' ', $field_pad); |
|
882 | - $top_pad = reset($top_pad); // the top padding is listed first |
|
883 | - $pad_unit = preg_replace('/[0-9]+/', '', $top_pad); //px, em, rem... |
|
884 | - $top_margin = (int) str_replace($pad_unit, '', $top_pad) / 2; |
|
880 | + // calculate the top position based on field padding |
|
881 | + $top_pad = explode(' ', $field_pad); |
|
882 | + $top_pad = reset($top_pad); // the top padding is listed first |
|
883 | + $pad_unit = preg_replace('/[0-9]+/', '', $top_pad); //px, em, rem... |
|
884 | + $top_margin = (int) str_replace($pad_unit, '', $top_pad) / 2; |
|
885 | 885 | ?> |
886 | 886 | top:<?php echo esc_html( $top_margin . $pad_unit . $important ) ?>; |
887 | 887 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | $settings = FrmStylesHelper::get_settings_for_output( $style ); |
4 | 4 | extract( $settings ); |
5 | 5 | |
6 | -$important = empty($important_style) ? '' : ' !important'; |
|
6 | +$important = empty( $important_style ) ? '' : ' !important'; |
|
7 | 7 | $label_margin = (int) $width + 10; |
8 | 8 | |
9 | 9 | $minus_icons = FrmStylesHelper::minus_icons(); |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | } |
112 | 112 | |
113 | 113 | .<?php echo esc_html( $style_class ) ?> .frm_icon_font.frm_minus_icon:before{ |
114 | - content:"\e<?php echo esc_html( isset( $minus_icons[ $repeat_icon ] ) ? $minus_icons[ $repeat_icon ]['-'] : $minus_icons[1]['-'] ) ?>"; |
|
114 | + content:"\e<?php echo esc_html( isset( $minus_icons[$repeat_icon] ) ? $minus_icons[$repeat_icon]['-'] : $minus_icons[1]['-'] ) ?>"; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | .<?php echo esc_html( $style_class ) ?> .frm_icon_font.frm_plus_icon:before{ |
118 | - content:"\e<?php echo esc_html( isset( $minus_icons[ $repeat_icon ] ) ? $minus_icons[ $repeat_icon ]['+'] : $minus_icons[1]['+'] ) ?>"; |
|
118 | + content:"\e<?php echo esc_html( isset( $minus_icons[$repeat_icon] ) ? $minus_icons[$repeat_icon]['+'] : $minus_icons[1]['+'] ) ?>"; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | .<?php echo esc_html( $style_class ) ?> .frm_icon_font.frm_minus_icon:before, |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | .<?php echo esc_html( $style_class ) ?> .frm_trigger.active .frm_icon_font.frm_arrow_icon:before{ |
127 | - content:"\e<?php echo esc_html( isset( $arrow_icons[ $collapse_icon ] ) ? $arrow_icons[ $collapse_icon ]['-'] : $arrow_icons[1]['-'] ) ?>"; |
|
127 | + content:"\e<?php echo esc_html( isset( $arrow_icons[$collapse_icon] ) ? $arrow_icons[$collapse_icon]['-'] : $arrow_icons[1]['-'] ) ?>"; |
|
128 | 128 | color:<?php echo esc_html( $section_color . $important ) ?>; |
129 | 129 | } |
130 | 130 | |
131 | 131 | .<?php echo esc_html( $style_class ) ?> .frm_trigger .frm_icon_font.frm_arrow_icon:before{ |
132 | - content:"\e<?php echo esc_html( isset( $arrow_icons[ $collapse_icon ] ) ? $arrow_icons[ $collapse_icon ]['+'] : $arrow_icons[1]['+'] ) ?>"; |
|
132 | + content:"\e<?php echo esc_html( isset( $arrow_icons[$collapse_icon] ) ? $arrow_icons[$collapse_icon]['+'] : $arrow_icons[1]['+'] ) ?>"; |
|
133 | 133 | color:<?php echo esc_html( $section_color . $important ) ?>; |
134 | 134 | } |
135 | 135 | |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | .<?php echo esc_html( $style_class ) ?> .chosen-container-single .chosen-single{ |
309 | 309 | color:<?php echo esc_html( $text_color . $important ) ?>; |
310 | 310 | background-color:<?php echo esc_html( $bg_color . $important ); ?>; |
311 | -<?php if ( ! empty($important) ) { |
|
311 | +<?php if ( ! empty( $important ) ) { |
|
312 | 312 | echo esc_html( 'background-image:none' . $important . ';' ); |
313 | 313 | } |
314 | 314 | ?> |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | line-height:normal<?php echo esc_html( $important ) ?>; |
497 | 497 | text-align:center; |
498 | 498 | background: <?php echo esc_html( $submit_bg_color ); |
499 | - if ( ! empty($submit_bg_img) ) { |
|
499 | + if ( ! empty( $submit_bg_img ) ) { |
|
500 | 500 | echo esc_html( ' url(' . $submit_bg_img . ')' ); |
501 | 501 | } |
502 | 502 | echo esc_html( $important ); ?>; |
@@ -878,10 +878,10 @@ discard block |
||
878 | 878 | .<?php echo esc_html( $style_class ) ?> .chosen-container-single .chosen-single div{ |
879 | 879 | <?php |
880 | 880 | // calculate the top position based on field padding |
881 | - $top_pad = explode(' ', $field_pad); |
|
882 | - $top_pad = reset($top_pad); // the top padding is listed first |
|
883 | - $pad_unit = preg_replace('/[0-9]+/', '', $top_pad); //px, em, rem... |
|
884 | - $top_margin = (int) str_replace($pad_unit, '', $top_pad) / 2; |
|
881 | + $top_pad = explode( ' ', $field_pad ); |
|
882 | + $top_pad = reset( $top_pad ); // the top padding is listed first |
|
883 | + $pad_unit = preg_replace( '/[0-9]+/', '', $top_pad ); //px, em, rem... |
|
884 | + $top_margin = (int) str_replace( $pad_unit, '', $top_pad ) / 2; |
|
885 | 885 | ?> |
886 | 886 | top:<?php echo esc_html( $top_margin . $pad_unit . $important ) ?>; |
887 | 887 | } |
@@ -2,70 +2,70 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmEntriesController { |
4 | 4 | |
5 | - public static function menu() { |
|
5 | + public static function menu() { |
|
6 | 6 | FrmAppHelper::force_capability( 'frm_view_entries' ); |
7 | 7 | |
8 | - add_submenu_page('formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
8 | + add_submenu_page('formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
9 | 9 | |
10 | 10 | if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show' ) ) ) { |
11 | 11 | $menu_name = FrmAppHelper::get_menu_name(); |
12 | 12 | add_filter( 'manage_' . sanitize_title( $menu_name ) . '_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' ); |
13 | 13 | add_filter( 'get_user_option_manage' . sanitize_title( $menu_name ) . '_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' ); |
14 | 14 | add_filter( 'manage_' . sanitize_title( $menu_name ) . '_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' ); |
15 | - } |
|
16 | - } |
|
15 | + } |
|
16 | + } |
|
17 | 17 | |
18 | - /* Display in Back End */ |
|
19 | - public static function route() { |
|
18 | + /* Display in Back End */ |
|
19 | + public static function route() { |
|
20 | 20 | $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' ); |
21 | 21 | |
22 | - switch ( $action ) { |
|
23 | - case 'show': |
|
24 | - case 'destroy': |
|
25 | - case 'destroy_all': |
|
26 | - return self::$action(); |
|
22 | + switch ( $action ) { |
|
23 | + case 'show': |
|
24 | + case 'destroy': |
|
25 | + case 'destroy_all': |
|
26 | + return self::$action(); |
|
27 | 27 | |
28 | - default: |
|
29 | - do_action( 'frm_entry_action_route', $action ); |
|
30 | - if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { |
|
31 | - return; |
|
32 | - } |
|
28 | + default: |
|
29 | + do_action( 'frm_entry_action_route', $action ); |
|
30 | + if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { |
|
31 | + return; |
|
32 | + } |
|
33 | 33 | |
34 | - return self::display_list(); |
|
35 | - } |
|
36 | - } |
|
34 | + return self::display_list(); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | 38 | public static function contextual_help( $help, $screen_id, $screen ) { |
39 | - // Only add to certain screens. add_help_tab was introduced in WordPress 3.3 |
|
40 | - if ( ! method_exists( $screen, 'add_help_tab' ) ) { |
|
41 | - return $help; |
|
42 | - } |
|
39 | + // Only add to certain screens. add_help_tab was introduced in WordPress 3.3 |
|
40 | + if ( ! method_exists( $screen, 'add_help_tab' ) ) { |
|
41 | + return $help; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
45 | 45 | $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
46 | 46 | if ( $page != 'formidable-entries' || ( ! empty( $action ) && $action != 'list' ) ) { |
47 | - return $help; |
|
48 | - } |
|
47 | + return $help; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | unset( $action, $page ); |
51 | 51 | |
52 | - $screen->add_help_tab( array( |
|
53 | - 'id' => 'formidable-entries-tab', |
|
54 | - 'title' => __( 'Overview', 'formidable' ), |
|
52 | + $screen->add_help_tab( array( |
|
53 | + 'id' => 'formidable-entries-tab', |
|
54 | + 'title' => __( 'Overview', 'formidable' ), |
|
55 | 55 | 'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) . '</p> <p>' . esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>', |
56 | - )); |
|
56 | + )); |
|
57 | 57 | |
58 | - $screen->set_help_sidebar( |
|
58 | + $screen->set_help_sidebar( |
|
59 | 59 | '<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' . |
60 | 60 | '<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/' ) ) . '" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' . |
61 | 61 | '<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'http://formidablepro.com/help-desk/' ) ) . '" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>' |
62 | - ); |
|
62 | + ); |
|
63 | 63 | |
64 | - return $help; |
|
65 | - } |
|
64 | + return $help; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | public static function manage_columns( $columns ) { |
68 | - global $frm_vars; |
|
68 | + global $frm_vars; |
|
69 | 69 | $form_id = FrmForm::get_current_form_id(); |
70 | 70 | |
71 | 71 | $columns[ $form_id . '_id' ] = 'ID'; |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' ); |
84 | 84 | $columns[ $form_id . '_ip' ] = 'IP'; |
85 | 85 | |
86 | - $frm_vars['cols'] = $columns; |
|
86 | + $frm_vars['cols'] = $columns; |
|
87 | 87 | |
88 | 88 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
89 | 89 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) { |
90 | 90 | add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) ); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - return $columns; |
|
94 | - } |
|
93 | + return $columns; |
|
94 | + } |
|
95 | 95 | |
96 | 96 | private static function get_columns_for_form( $form_id, &$columns ) { |
97 | 97 | $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' ); |
@@ -133,76 +133,76 @@ discard block |
||
133 | 133 | $menu_name = FrmAppHelper::get_menu_name(); |
134 | 134 | $this_page_name = 'manage' . sanitize_title( $menu_name ) . '_page_formidable-entriescolumnshidden'; |
135 | 135 | if ( $meta_key != $this_page_name || $meta_value == $prev_value ) { |
136 | - return $check; |
|
137 | - } |
|
136 | + return $check; |
|
137 | + } |
|
138 | 138 | |
139 | 139 | if ( empty( $prev_value ) ) { |
140 | 140 | $prev_value = get_metadata( 'user', $object_id, $meta_key, true ); |
141 | 141 | } |
142 | 142 | |
143 | - global $frm_vars; |
|
144 | - //add a check so we don't create a loop |
|
145 | - $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
143 | + global $frm_vars; |
|
144 | + //add a check so we don't create a loop |
|
145 | + $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
146 | 146 | |
147 | - return $check; |
|
148 | - } |
|
147 | + return $check; |
|
148 | + } |
|
149 | 149 | |
150 | - //add hidden columns back from other forms |
|
150 | + //add hidden columns back from other forms |
|
151 | 151 | public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { |
152 | 152 | $menu_name = FrmAppHelper::get_menu_name(); |
153 | 153 | $sanitized = sanitize_title( $menu_name ); |
154 | 154 | $this_page_name = 'manage' . $sanitized . '_page_formidable-entriescolumnshidden'; |
155 | 155 | if ( $meta_key != $this_page_name ) { |
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - global $frm_vars; |
|
160 | - if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
161 | - return; //don't continue if there's no previous value |
|
162 | - } |
|
163 | - |
|
164 | - foreach ( $meta_value as $mk => $mv ) { |
|
165 | - //remove blank values |
|
166 | - if ( empty( $mv ) ) { |
|
167 | - unset( $meta_value[ $mk ] ); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - $cur_form_prefix = reset($meta_value); |
|
172 | - $cur_form_prefix = explode('_', $cur_form_prefix); |
|
173 | - $cur_form_prefix = $cur_form_prefix[0]; |
|
174 | - $save = false; |
|
175 | - |
|
176 | - foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + global $frm_vars; |
|
160 | + if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
161 | + return; //don't continue if there's no previous value |
|
162 | + } |
|
163 | + |
|
164 | + foreach ( $meta_value as $mk => $mv ) { |
|
165 | + //remove blank values |
|
166 | + if ( empty( $mv ) ) { |
|
167 | + unset( $meta_value[ $mk ] ); |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + $cur_form_prefix = reset($meta_value); |
|
172 | + $cur_form_prefix = explode('_', $cur_form_prefix); |
|
173 | + $cur_form_prefix = $cur_form_prefix[0]; |
|
174 | + $save = false; |
|
175 | + |
|
176 | + foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { |
|
177 | 177 | if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) { |
178 | - //don't add blank cols or process included cols |
|
179 | - continue; |
|
180 | - } |
|
178 | + //don't add blank cols or process included cols |
|
179 | + continue; |
|
180 | + } |
|
181 | 181 | |
182 | 182 | $form_prefix = explode( '_', $prev_hidden ); |
183 | - $form_prefix = $form_prefix[0]; |
|
184 | - if ( $form_prefix == $cur_form_prefix ) { |
|
185 | - //don't add back columns that are meant to be hidden |
|
186 | - continue; |
|
187 | - } |
|
183 | + $form_prefix = $form_prefix[0]; |
|
184 | + if ( $form_prefix == $cur_form_prefix ) { |
|
185 | + //don't add back columns that are meant to be hidden |
|
186 | + continue; |
|
187 | + } |
|
188 | 188 | |
189 | - $meta_value[] = $prev_hidden; |
|
190 | - $save = true; |
|
191 | - unset($form_prefix); |
|
192 | - } |
|
189 | + $meta_value[] = $prev_hidden; |
|
190 | + $save = true; |
|
191 | + unset($form_prefix); |
|
192 | + } |
|
193 | 193 | |
194 | 194 | if ( $save ) { |
195 | - $user = wp_get_current_user(); |
|
195 | + $user = wp_get_current_user(); |
|
196 | 196 | update_user_option( $user->ID, $this_page_name, $meta_value, true ); |
197 | - } |
|
198 | - } |
|
197 | + } |
|
198 | + } |
|
199 | 199 | |
200 | 200 | public static function save_per_page( $save, $option, $value ) { |
201 | - if ( $option == 'formidable_page_formidable_entries_per_page' ) { |
|
202 | - $save = (int) $value; |
|
203 | - } |
|
204 | - return $save; |
|
205 | - } |
|
201 | + if ( $option == 'formidable_page_formidable_entries_per_page' ) { |
|
202 | + $save = (int) $value; |
|
203 | + } |
|
204 | + return $save; |
|
205 | + } |
|
206 | 206 | |
207 | 207 | public static function sortable_columns() { |
208 | 208 | $form_id = FrmForm::get_current_form_id(); |
@@ -228,46 +228,46 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | public static function hidden_columns( $result ) { |
231 | - global $frm_vars; |
|
231 | + global $frm_vars; |
|
232 | 232 | |
233 | 233 | $form_id = FrmForm::get_current_form_id(); |
234 | 234 | |
235 | - $return = false; |
|
236 | - foreach ( (array) $result as $r ) { |
|
237 | - if ( ! empty( $r ) ) { |
|
238 | - $form_prefix = explode( '_', $r ); |
|
239 | - $form_prefix = $form_prefix[0]; |
|
235 | + $return = false; |
|
236 | + foreach ( (array) $result as $r ) { |
|
237 | + if ( ! empty( $r ) ) { |
|
238 | + $form_prefix = explode( '_', $r ); |
|
239 | + $form_prefix = $form_prefix[0]; |
|
240 | 240 | |
241 | - if ( (int) $form_prefix == (int) $form_id ) { |
|
242 | - $return = true; |
|
243 | - break; |
|
244 | - } |
|
241 | + if ( (int) $form_prefix == (int) $form_id ) { |
|
242 | + $return = true; |
|
243 | + break; |
|
244 | + } |
|
245 | 245 | |
246 | - unset($form_prefix); |
|
247 | - } |
|
248 | - } |
|
246 | + unset($form_prefix); |
|
247 | + } |
|
248 | + } |
|
249 | 249 | |
250 | - if ( $return ) { |
|
250 | + if ( $return ) { |
|
251 | 251 | return $result; |
252 | 252 | } |
253 | 253 | |
254 | - $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
255 | - $max_columns = 8; |
|
256 | - if ( $i <= $max_columns ) { |
|
254 | + $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
255 | + $max_columns = 8; |
|
256 | + if ( $i <= $max_columns ) { |
|
257 | 257 | return $result; |
258 | 258 | } |
259 | 259 | |
260 | - global $frm_vars; |
|
261 | - if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
262 | - $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
263 | - } |
|
260 | + global $frm_vars; |
|
261 | + if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
262 | + $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
263 | + } |
|
264 | 264 | |
265 | 265 | $has_custom_hidden_columns = ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && isset( $frm_vars['current_form']->options['hidden_cols'] ) && ! empty( $frm_vars['current_form']->options['hidden_cols'] ) ); |
266 | 266 | if ( $has_custom_hidden_columns ) { |
267 | - $result = $frm_vars['current_form']->options['hidden_cols']; |
|
268 | - } else { |
|
269 | - $cols = $frm_vars['cols']; |
|
270 | - $cols = array_reverse($cols, true); |
|
267 | + $result = $frm_vars['current_form']->options['hidden_cols']; |
|
268 | + } else { |
|
269 | + $cols = $frm_vars['cols']; |
|
270 | + $cols = array_reverse($cols, true); |
|
271 | 271 | |
272 | 272 | if ( $form_id ) { |
273 | 273 | $result[] = $form_id . '_id'; |
@@ -275,59 +275,59 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | $result[] = $form_id . '_item_key'; |
278 | - $i--; |
|
278 | + $i--; |
|
279 | 279 | |
280 | 280 | foreach ( $cols as $col_key => $col ) { |
281 | - if ( $i > $max_columns ) { |
|
281 | + if ( $i > $max_columns ) { |
|
282 | 282 | $result[] = $col_key; |
283 | 283 | } |
284 | - //remove some columns by default |
|
285 | - $i--; |
|
286 | - unset($col_key, $col); |
|
287 | - } |
|
288 | - } |
|
284 | + //remove some columns by default |
|
285 | + $i--; |
|
286 | + unset($col_key, $col); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | - return $result; |
|
291 | - } |
|
290 | + return $result; |
|
291 | + } |
|
292 | 292 | |
293 | 293 | public static function display_list( $message = '', $errors = array() ) { |
294 | - global $wpdb, $frm_vars; |
|
294 | + global $wpdb, $frm_vars; |
|
295 | 295 | |
296 | 296 | $form = FrmForm::maybe_get_current_form(); |
297 | 297 | $params = FrmForm::get_admin_params( $form ); |
298 | 298 | |
299 | - if ( $form ) { |
|
300 | - $params['form'] = $form->id; |
|
301 | - $frm_vars['current_form'] = $form; |
|
299 | + if ( $form ) { |
|
300 | + $params['form'] = $form->id; |
|
301 | + $frm_vars['current_form'] = $form; |
|
302 | 302 | |
303 | 303 | self::get_delete_form_time( $form, $errors ); |
304 | 304 | } |
305 | 305 | |
306 | - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); |
|
306 | + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); |
|
307 | 307 | |
308 | - $wp_list_table = new $table_class( array( 'params' => $params ) ); |
|
308 | + $wp_list_table = new $table_class( array( 'params' => $params ) ); |
|
309 | 309 | |
310 | - $pagenum = $wp_list_table->get_pagenum(); |
|
310 | + $pagenum = $wp_list_table->get_pagenum(); |
|
311 | 311 | |
312 | - $wp_list_table->prepare_items(); |
|
312 | + $wp_list_table->prepare_items(); |
|
313 | 313 | |
314 | - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
315 | - if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
314 | + $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
315 | + if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
316 | 316 | $url = add_query_arg( 'paged', $total_pages ); |
317 | - if ( headers_sent() ) { |
|
318 | - echo FrmAppHelper::js_redirect($url); |
|
319 | - } else { |
|
320 | - wp_redirect( esc_url_raw( $url ) ); |
|
321 | - } |
|
322 | - die(); |
|
323 | - } |
|
324 | - |
|
325 | - if ( empty($message) && isset($_GET['import-message']) ) { |
|
326 | - $message = __( 'Your import is complete', 'formidable' ); |
|
327 | - } |
|
317 | + if ( headers_sent() ) { |
|
318 | + echo FrmAppHelper::js_redirect($url); |
|
319 | + } else { |
|
320 | + wp_redirect( esc_url_raw( $url ) ); |
|
321 | + } |
|
322 | + die(); |
|
323 | + } |
|
324 | + |
|
325 | + if ( empty($message) && isset($_GET['import-message']) ) { |
|
326 | + $message = __( 'Your import is complete', 'formidable' ); |
|
327 | + } |
|
328 | 328 | |
329 | 329 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' ); |
330 | - } |
|
330 | + } |
|
331 | 331 | |
332 | 332 | private static function get_delete_form_time( $form, &$errors ) { |
333 | 333 | if ( 'trash' == $form->status ) { |
@@ -337,19 +337,19 @@ discard block |
||
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
340 | - /* Back End CRUD */ |
|
340 | + /* Back End CRUD */ |
|
341 | 341 | public static function show( $id = 0 ) { |
342 | - FrmAppHelper::permission_check('frm_view_entries'); |
|
342 | + FrmAppHelper::permission_check('frm_view_entries'); |
|
343 | 343 | |
344 | - if ( ! $id ) { |
|
344 | + if ( ! $id ) { |
|
345 | 345 | $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
346 | 346 | |
347 | - if ( ! $id ) { |
|
347 | + if ( ! $id ) { |
|
348 | 348 | $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' ); |
349 | - } |
|
350 | - } |
|
349 | + } |
|
350 | + } |
|
351 | 351 | |
352 | - $entry = FrmEntry::getOne($id, true); |
|
352 | + $entry = FrmEntry::getOne($id, true); |
|
353 | 353 | if ( ! $entry ) { |
354 | 354 | echo '<div id="form_show_entry_page" class="wrap">' . |
355 | 355 | __( 'You are trying to view an entry that does not exist.', 'formidable' ) . |
@@ -357,110 +357,110 @@ discard block |
||
357 | 357 | return; |
358 | 358 | } |
359 | 359 | |
360 | - $data = maybe_unserialize($entry->description); |
|
360 | + $data = maybe_unserialize($entry->description); |
|
361 | 361 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
362 | 362 | $data = array( 'referrer' => $data ); |
363 | 363 | } |
364 | 364 | |
365 | 365 | $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' ); |
366 | - $to_emails = array(); |
|
366 | + $to_emails = array(); |
|
367 | 367 | |
368 | 368 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' ); |
369 | - } |
|
369 | + } |
|
370 | 370 | |
371 | - public static function destroy() { |
|
372 | - FrmAppHelper::permission_check('frm_delete_entries'); |
|
371 | + public static function destroy() { |
|
372 | + FrmAppHelper::permission_check('frm_delete_entries'); |
|
373 | 373 | |
374 | 374 | $params = FrmForm::get_admin_params(); |
375 | 375 | |
376 | - if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
377 | - //unlink entry from post |
|
378 | - global $wpdb; |
|
376 | + if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
377 | + //unlink entry from post |
|
378 | + global $wpdb; |
|
379 | 379 | $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) ); |
380 | - } |
|
380 | + } |
|
381 | 381 | |
382 | - $message = ''; |
|
383 | - if ( FrmEntry::destroy( $params['id'] ) ) { |
|
384 | - $message = __( 'Entry was Successfully Destroyed', 'formidable' ); |
|
385 | - } |
|
382 | + $message = ''; |
|
383 | + if ( FrmEntry::destroy( $params['id'] ) ) { |
|
384 | + $message = __( 'Entry was Successfully Destroyed', 'formidable' ); |
|
385 | + } |
|
386 | 386 | |
387 | - self::display_list( $message ); |
|
388 | - } |
|
387 | + self::display_list( $message ); |
|
388 | + } |
|
389 | 389 | |
390 | - public static function destroy_all() { |
|
391 | - if ( ! current_user_can( 'frm_delete_entries' ) ) { |
|
392 | - $frm_settings = FrmAppHelper::get_settings(); |
|
393 | - wp_die( $frm_settings->admin_permission ); |
|
394 | - } |
|
390 | + public static function destroy_all() { |
|
391 | + if ( ! current_user_can( 'frm_delete_entries' ) ) { |
|
392 | + $frm_settings = FrmAppHelper::get_settings(); |
|
393 | + wp_die( $frm_settings->admin_permission ); |
|
394 | + } |
|
395 | 395 | |
396 | - global $wpdb; |
|
396 | + global $wpdb; |
|
397 | 397 | $params = FrmForm::get_admin_params(); |
398 | - $message = ''; |
|
399 | - $errors = array(); |
|
400 | - $form_id = (int) $params['form']; |
|
398 | + $message = ''; |
|
399 | + $errors = array(); |
|
400 | + $form_id = (int) $params['form']; |
|
401 | 401 | |
402 | - if ( $form_id ) { |
|
403 | - $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) ); |
|
402 | + if ( $form_id ) { |
|
403 | + $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) ); |
|
404 | 404 | $action = FrmFormAction::get_action_for_form( $form_id, 'wppost', 1 ); |
405 | 405 | |
406 | - if ( $action ) { |
|
407 | - // this action takes a while, so only trigger it if there are posts to delete |
|
408 | - foreach ( $entry_ids as $entry_id ) { |
|
409 | - do_action( 'frm_before_destroy_entry', $entry_id ); |
|
410 | - unset( $entry_id ); |
|
411 | - } |
|
412 | - } |
|
413 | - |
|
414 | - $wpdb->query( $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id ) ); |
|
415 | - $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) ); |
|
416 | - if ( $results ) { |
|
406 | + if ( $action ) { |
|
407 | + // this action takes a while, so only trigger it if there are posts to delete |
|
408 | + foreach ( $entry_ids as $entry_id ) { |
|
409 | + do_action( 'frm_before_destroy_entry', $entry_id ); |
|
410 | + unset( $entry_id ); |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + $wpdb->query( $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id ) ); |
|
415 | + $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) ); |
|
416 | + if ( $results ) { |
|
417 | 417 | FrmEntry::clear_cache(); |
418 | - $message = __( 'Entries were Successfully Destroyed', 'formidable' ); |
|
419 | - } |
|
420 | - } else { |
|
421 | - $errors = __( 'No entries were specified', 'formidable' ); |
|
422 | - } |
|
423 | - |
|
424 | - self::display_list( $message, $errors ); |
|
425 | - } |
|
426 | - |
|
427 | - public static function show_form( $id = '', $key = '', $title = false, $description = false ) { |
|
428 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' ); |
|
429 | - return FrmFormsController::show_form( $id, $key, $title, $description ); |
|
430 | - } |
|
431 | - |
|
432 | - public static function get_form( $filename, $form, $title, $description ) { |
|
433 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' ); |
|
434 | - return FrmFormsController::get_form( $form, $title, $description ); |
|
435 | - } |
|
436 | - |
|
437 | - public static function process_entry( $errors = '', $ajax = false ) { |
|
418 | + $message = __( 'Entries were Successfully Destroyed', 'formidable' ); |
|
419 | + } |
|
420 | + } else { |
|
421 | + $errors = __( 'No entries were specified', 'formidable' ); |
|
422 | + } |
|
423 | + |
|
424 | + self::display_list( $message, $errors ); |
|
425 | + } |
|
426 | + |
|
427 | + public static function show_form( $id = '', $key = '', $title = false, $description = false ) { |
|
428 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' ); |
|
429 | + return FrmFormsController::show_form( $id, $key, $title, $description ); |
|
430 | + } |
|
431 | + |
|
432 | + public static function get_form( $filename, $form, $title, $description ) { |
|
433 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' ); |
|
434 | + return FrmFormsController::get_form( $form, $title, $description ); |
|
435 | + } |
|
436 | + |
|
437 | + public static function process_entry( $errors = '', $ajax = false ) { |
|
438 | 438 | $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); |
439 | 439 | if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { |
440 | - return; |
|
441 | - } |
|
440 | + return; |
|
441 | + } |
|
442 | 442 | |
443 | - global $frm_vars; |
|
443 | + global $frm_vars; |
|
444 | 444 | |
445 | 445 | $form = FrmForm::getOne( $form_id ); |
446 | - if ( ! $form ) { |
|
447 | - return; |
|
448 | - } |
|
446 | + if ( ! $form ) { |
|
447 | + return; |
|
448 | + } |
|
449 | 449 | |
450 | 450 | $params = FrmForm::get_params( $form ); |
451 | 451 | |
452 | - if ( ! isset( $frm_vars['form_params'] ) ) { |
|
453 | - $frm_vars['form_params'] = array(); |
|
454 | - } |
|
452 | + if ( ! isset( $frm_vars['form_params'] ) ) { |
|
453 | + $frm_vars['form_params'] = array(); |
|
454 | + } |
|
455 | 455 | $frm_vars['form_params'][ $form->id ] = $params; |
456 | 456 | |
457 | 457 | if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { |
458 | - return; |
|
459 | - } |
|
458 | + return; |
|
459 | + } |
|
460 | 460 | |
461 | - if ( $errors == '' && ! $ajax ) { |
|
461 | + if ( $errors == '' && ! $ajax ) { |
|
462 | 462 | $errors = FrmEntryValidate::validate( $_POST ); |
463 | - } |
|
463 | + } |
|
464 | 464 | |
465 | 465 | /** |
466 | 466 | * Use this filter to add trigger actions and add errors after |
@@ -471,106 +471,106 @@ discard block |
||
471 | 471 | |
472 | 472 | $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); |
473 | 473 | |
474 | - if ( empty( $errors ) ) { |
|
474 | + if ( empty( $errors ) ) { |
|
475 | 475 | $_POST['frm_skip_cookie'] = 1; |
476 | - if ( $params['action'] == 'create' ) { |
|
476 | + if ( $params['action'] == 'create' ) { |
|
477 | 477 | if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
478 | 478 | $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); |
479 | - } |
|
480 | - } |
|
479 | + } |
|
480 | + } |
|
481 | 481 | |
482 | - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
|
482 | + do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
|
483 | 483 | unset( $_POST['frm_skip_cookie'] ); |
484 | - } |
|
485 | - } |
|
486 | - |
|
487 | - public static function delete_entry_before_redirect( $url, $form, $atts ) { |
|
488 | - self::_delete_entry( $atts['id'], $form ); |
|
489 | - return $url; |
|
490 | - } |
|
491 | - |
|
492 | - //Delete entry if not redirected |
|
493 | - public static function delete_entry_after_save( $atts ) { |
|
494 | - self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
|
495 | - } |
|
496 | - |
|
497 | - private static function _delete_entry( $entry_id, $form ) { |
|
498 | - if ( ! $form ) { |
|
499 | - return; |
|
500 | - } |
|
501 | - |
|
502 | - $form->options = maybe_unserialize( $form->options ); |
|
503 | - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
|
504 | - FrmEntry::destroy( $entry_id ); |
|
505 | - } |
|
506 | - } |
|
484 | + } |
|
485 | + } |
|
486 | + |
|
487 | + public static function delete_entry_before_redirect( $url, $form, $atts ) { |
|
488 | + self::_delete_entry( $atts['id'], $form ); |
|
489 | + return $url; |
|
490 | + } |
|
491 | + |
|
492 | + //Delete entry if not redirected |
|
493 | + public static function delete_entry_after_save( $atts ) { |
|
494 | + self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
|
495 | + } |
|
496 | + |
|
497 | + private static function _delete_entry( $entry_id, $form ) { |
|
498 | + if ( ! $form ) { |
|
499 | + return; |
|
500 | + } |
|
501 | + |
|
502 | + $form->options = maybe_unserialize( $form->options ); |
|
503 | + if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
|
504 | + FrmEntry::destroy( $entry_id ); |
|
505 | + } |
|
506 | + } |
|
507 | 507 | |
508 | 508 | public static function show_entry_shortcode( $atts ) { |
509 | 509 | return FrmEntryFormat::show_entry( $atts ); |
510 | 510 | } |
511 | 511 | |
512 | - public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) { |
|
512 | + public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) { |
|
513 | 513 | if ( isset( $atts['field'] ) ) { |
514 | 514 | $field = $atts['field']; |
515 | 515 | } else { |
516 | 516 | $field = FrmField::getOne( $meta->field_id ); |
517 | 517 | } |
518 | - if ( ! $field ) { |
|
519 | - return $value; |
|
520 | - } |
|
518 | + if ( ! $field ) { |
|
519 | + return $value; |
|
520 | + } |
|
521 | 521 | |
522 | - $value = self::filter_display_value($value, $field, $atts); |
|
523 | - return $value; |
|
524 | - } |
|
522 | + $value = self::filter_display_value($value, $field, $atts); |
|
523 | + return $value; |
|
524 | + } |
|
525 | 525 | |
526 | 526 | public static function &filter_shortcode_value( $value, $tag, $atts, $field ) { |
527 | - $plain_text = add_filter('frm_plain_text_email', true); |
|
527 | + $plain_text = add_filter('frm_plain_text_email', true); |
|
528 | 528 | FrmEntryFormat::textarea_display_value( $field->type, $plain_text, $value ); |
529 | 529 | |
530 | - if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
531 | - return $value; |
|
532 | - } |
|
530 | + if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
531 | + return $value; |
|
532 | + } |
|
533 | 533 | |
534 | - return self::filter_display_value($value, $field, $atts); |
|
535 | - } |
|
534 | + return self::filter_display_value($value, $field, $atts); |
|
535 | + } |
|
536 | 536 | |
537 | - public static function &filter_display_value( $value, $field, $atts = array() ) { |
|
538 | - $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false; |
|
537 | + public static function &filter_display_value( $value, $field, $atts = array() ) { |
|
538 | + $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false; |
|
539 | 539 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'radio', 'select' ) ) || ! FrmField::is_option_true( $field, 'separate_value' ) || $saved_value ) { |
540 | - return $value; |
|
541 | - } |
|
542 | - |
|
543 | - $f_values = $f_labels = array(); |
|
544 | - |
|
545 | - foreach ( $field->options as $opt_key => $opt ) { |
|
546 | - if ( ! is_array($opt) ) { |
|
547 | - continue; |
|
548 | - } |
|
549 | - |
|
550 | - $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt); |
|
551 | - $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ]; |
|
552 | - if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) { |
|
553 | - unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] ); |
|
554 | - } |
|
555 | - unset($opt_key, $opt); |
|
556 | - } |
|
557 | - |
|
558 | - if ( ! empty($f_values) ) { |
|
559 | - foreach ( (array) $value as $v_key => $val ) { |
|
560 | - if ( in_array($val, $f_values) ) { |
|
561 | - $opt = array_search($val, $f_values); |
|
562 | - if ( is_array($value) ) { |
|
563 | - $value[ $v_key ] = $f_labels[ $opt ]; |
|
564 | - } else { |
|
565 | - $value = $f_labels[ $opt ]; |
|
566 | - } |
|
567 | - } |
|
568 | - unset($v_key, $val); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - return $value; |
|
573 | - } |
|
540 | + return $value; |
|
541 | + } |
|
542 | + |
|
543 | + $f_values = $f_labels = array(); |
|
544 | + |
|
545 | + foreach ( $field->options as $opt_key => $opt ) { |
|
546 | + if ( ! is_array($opt) ) { |
|
547 | + continue; |
|
548 | + } |
|
549 | + |
|
550 | + $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt); |
|
551 | + $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ]; |
|
552 | + if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) { |
|
553 | + unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] ); |
|
554 | + } |
|
555 | + unset($opt_key, $opt); |
|
556 | + } |
|
557 | + |
|
558 | + if ( ! empty($f_values) ) { |
|
559 | + foreach ( (array) $value as $v_key => $val ) { |
|
560 | + if ( in_array($val, $f_values) ) { |
|
561 | + $opt = array_search($val, $f_values); |
|
562 | + if ( is_array($value) ) { |
|
563 | + $value[ $v_key ] = $f_labels[ $opt ]; |
|
564 | + } else { |
|
565 | + $value = $f_labels[ $opt ]; |
|
566 | + } |
|
567 | + } |
|
568 | + unset($v_key, $val); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + return $value; |
|
573 | + } |
|
574 | 574 | |
575 | 575 | public static function get_params( $form = null ) { |
576 | 576 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_params' ); |
@@ -578,13 +578,13 @@ discard block |
||
578 | 578 | } |
579 | 579 | |
580 | 580 | public static function entry_sidebar( $entry ) { |
581 | - $data = maybe_unserialize($entry->description); |
|
582 | - $date_format = get_option('date_format'); |
|
583 | - $time_format = get_option('time_format'); |
|
581 | + $data = maybe_unserialize($entry->description); |
|
582 | + $date_format = get_option('date_format'); |
|
583 | + $time_format = get_option('time_format'); |
|
584 | 584 | if ( isset( $data['browser'] ) ) { |
585 | 585 | $browser = FrmEntryFormat::get_browser( $data['browser'] ); |
586 | 586 | } |
587 | 587 | |
588 | 588 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' ); |
589 | - } |
|
589 | + } |
|
590 | 590 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | public static function menu() { |
6 | 6 | FrmAppHelper::force_capability( 'frm_view_entries' ); |
7 | 7 | |
8 | - add_submenu_page('formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
8 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
9 | 9 | |
10 | 10 | if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show' ) ) ) { |
11 | 11 | $menu_name = FrmAppHelper::get_menu_name(); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | 'id' => 'formidable-entries-tab', |
54 | 54 | 'title' => __( 'Overview', 'formidable' ), |
55 | 55 | 'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) . '</p> <p>' . esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>', |
56 | - )); |
|
56 | + ) ); |
|
57 | 57 | |
58 | 58 | $screen->set_help_sidebar( |
59 | 59 | '<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' . |
@@ -68,20 +68,20 @@ discard block |
||
68 | 68 | global $frm_vars; |
69 | 69 | $form_id = FrmForm::get_current_form_id(); |
70 | 70 | |
71 | - $columns[ $form_id . '_id' ] = 'ID'; |
|
72 | - $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' ); |
|
71 | + $columns[$form_id . '_id'] = 'ID'; |
|
72 | + $columns[$form_id . '_item_key'] = esc_html__( 'Entry Key', 'formidable' ); |
|
73 | 73 | |
74 | 74 | if ( $form_id ) { |
75 | 75 | self::get_columns_for_form( $form_id, $columns ); |
76 | 76 | } else { |
77 | - $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' ); |
|
78 | - $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' ); |
|
79 | - $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' ); |
|
77 | + $columns[$form_id . '_form_id'] = __( 'Form', 'formidable' ); |
|
78 | + $columns[$form_id . '_name'] = __( 'Entry Name', 'formidable' ); |
|
79 | + $columns[$form_id . '_user_id'] = __( 'Created By', 'formidable' ); |
|
80 | 80 | } |
81 | 81 | |
82 | - $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' ); |
|
83 | - $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' ); |
|
84 | - $columns[ $form_id . '_ip' ] = 'IP'; |
|
82 | + $columns[$form_id . '_created_at'] = __( 'Entry creation date', 'formidable' ); |
|
83 | + $columns[$form_id . '_updated_at'] = __( 'Entry update date', 'formidable' ); |
|
84 | + $columns[$form_id . '_ip'] = 'IP'; |
|
85 | 85 | |
86 | 86 | $frm_vars['cols'] = $columns; |
87 | 87 | |
@@ -107,24 +107,24 @@ discard block |
||
107 | 107 | if ( $sub_form_cols ) { |
108 | 108 | foreach ( $sub_form_cols as $k => $sub_form_col ) { |
109 | 109 | if ( FrmField::is_no_save_field( $sub_form_col->type ) ) { |
110 | - unset( $sub_form_cols[ $k ] ); |
|
110 | + unset( $sub_form_cols[$k] ); |
|
111 | 111 | continue; |
112 | 112 | } |
113 | - $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
|
114 | - unset($sub_form_col); |
|
113 | + $columns[$form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
|
114 | + unset( $sub_form_col ); |
|
115 | 115 | } |
116 | 116 | } |
117 | - unset($sub_form_cols); |
|
117 | + unset( $sub_form_cols ); |
|
118 | 118 | } else { |
119 | 119 | $col_id = $form_col->field_key; |
120 | 120 | if ( $form_col->form_id != $form_id ) { |
121 | 121 | $col_id .= '-_-form' . $form_col->form_id; |
122 | 122 | } |
123 | 123 | |
124 | - if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) { |
|
125 | - $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
124 | + if ( isset( $form_col->field_options['separate_value'] ) && $form_col->field_options['separate_value'] ) { |
|
125 | + $columns[$form_id . '_frmsep_' . $col_id] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
126 | 126 | } |
127 | - $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
127 | + $columns[$form_id . '_' . $col_id] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | global $frm_vars; |
144 | 144 | //add a check so we don't create a loop |
145 | - $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
145 | + $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
146 | 146 | |
147 | 147 | return $check; |
148 | 148 | } |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | global $frm_vars; |
160 | - if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
160 | + if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) { |
|
161 | 161 | return; //don't continue if there's no previous value |
162 | 162 | } |
163 | 163 | |
164 | 164 | foreach ( $meta_value as $mk => $mv ) { |
165 | 165 | //remove blank values |
166 | - if ( empty( $mv ) ) { |
|
167 | - unset( $meta_value[ $mk ] ); |
|
166 | + if ( empty( $mv ) ) { |
|
167 | + unset( $meta_value[$mk] ); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - $cur_form_prefix = reset($meta_value); |
|
172 | - $cur_form_prefix = explode('_', $cur_form_prefix); |
|
171 | + $cur_form_prefix = reset( $meta_value ); |
|
172 | + $cur_form_prefix = explode( '_', $cur_form_prefix ); |
|
173 | 173 | $cur_form_prefix = $cur_form_prefix[0]; |
174 | 174 | $save = false; |
175 | 175 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | $meta_value[] = $prev_hidden; |
190 | 190 | $save = true; |
191 | - unset($form_prefix); |
|
191 | + unset( $form_prefix ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | if ( $save ) { |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | foreach ( $fields as $field ) { |
221 | 221 | if ( $field->type != 'checkbox' && ( ! isset( $field->field_options['post_field'] ) || $field->field_options['post_field'] == '' ) ) { |
222 | 222 | // Can't sort on checkboxes because they are stored serialized, or post fields |
223 | - $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id; |
|
223 | + $columns[$form_id . '_' . $field->field_key] = 'meta_' . $field->id; |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | break; |
244 | 244 | } |
245 | 245 | |
246 | - unset($form_prefix); |
|
246 | + unset( $form_prefix ); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -251,15 +251,15 @@ discard block |
||
251 | 251 | return $result; |
252 | 252 | } |
253 | 253 | |
254 | - $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
254 | + $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; |
|
255 | 255 | $max_columns = 8; |
256 | 256 | if ( $i <= $max_columns ) { |
257 | 257 | return $result; |
258 | 258 | } |
259 | 259 | |
260 | 260 | global $frm_vars; |
261 | - if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
262 | - $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
261 | + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] ) { |
|
262 | + $frm_vars['current_form']->options = maybe_unserialize( $frm_vars['current_form']->options ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | $has_custom_hidden_columns = ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && isset( $frm_vars['current_form']->options['hidden_cols'] ) && ! empty( $frm_vars['current_form']->options['hidden_cols'] ) ); |
@@ -267,23 +267,23 @@ discard block |
||
267 | 267 | $result = $frm_vars['current_form']->options['hidden_cols']; |
268 | 268 | } else { |
269 | 269 | $cols = $frm_vars['cols']; |
270 | - $cols = array_reverse($cols, true); |
|
270 | + $cols = array_reverse( $cols, true ); |
|
271 | 271 | |
272 | 272 | if ( $form_id ) { |
273 | 273 | $result[] = $form_id . '_id'; |
274 | - $i--; |
|
274 | + $i --; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $result[] = $form_id . '_item_key'; |
278 | - $i--; |
|
278 | + $i --; |
|
279 | 279 | |
280 | 280 | foreach ( $cols as $col_key => $col ) { |
281 | 281 | if ( $i > $max_columns ) { |
282 | 282 | $result[] = $col_key; |
283 | 283 | } |
284 | 284 | //remove some columns by default |
285 | - $i--; |
|
286 | - unset($col_key, $col); |
|
285 | + $i --; |
|
286 | + unset( $col_key, $col ); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
@@ -315,14 +315,14 @@ discard block |
||
315 | 315 | if ( $pagenum > $total_pages && $total_pages > 0 ) { |
316 | 316 | $url = add_query_arg( 'paged', $total_pages ); |
317 | 317 | if ( headers_sent() ) { |
318 | - echo FrmAppHelper::js_redirect($url); |
|
318 | + echo FrmAppHelper::js_redirect( $url ); |
|
319 | 319 | } else { |
320 | 320 | wp_redirect( esc_url_raw( $url ) ); |
321 | 321 | } |
322 | 322 | die(); |
323 | 323 | } |
324 | 324 | |
325 | - if ( empty($message) && isset($_GET['import-message']) ) { |
|
325 | + if ( empty( $message ) && isset( $_GET['import-message'] ) ) { |
|
326 | 326 | $message = __( 'Your import is complete', 'formidable' ); |
327 | 327 | } |
328 | 328 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | |
340 | 340 | /* Back End CRUD */ |
341 | 341 | public static function show( $id = 0 ) { |
342 | - FrmAppHelper::permission_check('frm_view_entries'); |
|
342 | + FrmAppHelper::permission_check( 'frm_view_entries' ); |
|
343 | 343 | |
344 | 344 | if ( ! $id ) { |
345 | 345 | $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | - $entry = FrmEntry::getOne($id, true); |
|
352 | + $entry = FrmEntry::getOne( $id, true ); |
|
353 | 353 | if ( ! $entry ) { |
354 | 354 | echo '<div id="form_show_entry_page" class="wrap">' . |
355 | 355 | __( 'You are trying to view an entry that does not exist.', 'formidable' ) . |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | return; |
358 | 358 | } |
359 | 359 | |
360 | - $data = maybe_unserialize($entry->description); |
|
360 | + $data = maybe_unserialize( $entry->description ); |
|
361 | 361 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
362 | 362 | $data = array( 'referrer' => $data ); |
363 | 363 | } |
@@ -369,11 +369,11 @@ discard block |
||
369 | 369 | } |
370 | 370 | |
371 | 371 | public static function destroy() { |
372 | - FrmAppHelper::permission_check('frm_delete_entries'); |
|
372 | + FrmAppHelper::permission_check( 'frm_delete_entries' ); |
|
373 | 373 | |
374 | 374 | $params = FrmForm::get_admin_params(); |
375 | 375 | |
376 | - if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
376 | + if ( isset( $params['keep_post'] ) && $params['keep_post'] ) { |
|
377 | 377 | //unlink entry from post |
378 | 378 | global $wpdb; |
379 | 379 | $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) ); |
@@ -452,9 +452,9 @@ discard block |
||
452 | 452 | if ( ! isset( $frm_vars['form_params'] ) ) { |
453 | 453 | $frm_vars['form_params'] = array(); |
454 | 454 | } |
455 | - $frm_vars['form_params'][ $form->id ] = $params; |
|
455 | + $frm_vars['form_params'][$form->id] = $params; |
|
456 | 456 | |
457 | - if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { |
|
457 | + if ( isset( $frm_vars['created_entries'][$form_id] ) ) { |
|
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
@@ -469,13 +469,13 @@ discard block |
||
469 | 469 | */ |
470 | 470 | $errors = apply_filters( 'frm_entries_before_create', $errors, $form ); |
471 | 471 | |
472 | - $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); |
|
472 | + $frm_vars['created_entries'][$form_id] = array( 'errors' => $errors ); |
|
473 | 473 | |
474 | 474 | if ( empty( $errors ) ) { |
475 | 475 | $_POST['frm_skip_cookie'] = 1; |
476 | 476 | if ( $params['action'] == 'create' ) { |
477 | - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
|
478 | - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); |
|
477 | + if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][$form_id]['entry_id'] ) ) { |
|
478 | + $frm_vars['created_entries'][$form_id]['entry_id'] = FrmEntry::create( $_POST ); |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
@@ -519,23 +519,23 @@ discard block |
||
519 | 519 | return $value; |
520 | 520 | } |
521 | 521 | |
522 | - $value = self::filter_display_value($value, $field, $atts); |
|
522 | + $value = self::filter_display_value( $value, $field, $atts ); |
|
523 | 523 | return $value; |
524 | 524 | } |
525 | 525 | |
526 | 526 | public static function &filter_shortcode_value( $value, $tag, $atts, $field ) { |
527 | - $plain_text = add_filter('frm_plain_text_email', true); |
|
527 | + $plain_text = add_filter( 'frm_plain_text_email', true ); |
|
528 | 528 | FrmEntryFormat::textarea_display_value( $field->type, $plain_text, $value ); |
529 | 529 | |
530 | - if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
530 | + if ( isset( $atts['show'] ) && $atts['show'] == 'value' ) { |
|
531 | 531 | return $value; |
532 | 532 | } |
533 | 533 | |
534 | - return self::filter_display_value($value, $field, $atts); |
|
534 | + return self::filter_display_value( $value, $field, $atts ); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | public static function &filter_display_value( $value, $field, $atts = array() ) { |
538 | - $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false; |
|
538 | + $saved_value = ( isset( $atts['saved_value'] ) && $atts['saved_value'] ) ? true : false; |
|
539 | 539 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'radio', 'select' ) ) || ! FrmField::is_option_true( $field, 'separate_value' ) || $saved_value ) { |
540 | 540 | return $value; |
541 | 541 | } |
@@ -543,29 +543,29 @@ discard block |
||
543 | 543 | $f_values = $f_labels = array(); |
544 | 544 | |
545 | 545 | foreach ( $field->options as $opt_key => $opt ) { |
546 | - if ( ! is_array($opt) ) { |
|
546 | + if ( ! is_array( $opt ) ) { |
|
547 | 547 | continue; |
548 | 548 | } |
549 | 549 | |
550 | - $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt); |
|
551 | - $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ]; |
|
552 | - if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) { |
|
553 | - unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] ); |
|
550 | + $f_labels[$opt_key] = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
551 | + $f_values[$opt_key] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[$opt_key]; |
|
552 | + if ( $f_labels[$opt_key] == $f_values[$opt_key] ) { |
|
553 | + unset( $f_values[$opt_key], $f_labels[$opt_key] ); |
|
554 | 554 | } |
555 | - unset($opt_key, $opt); |
|
555 | + unset( $opt_key, $opt ); |
|
556 | 556 | } |
557 | 557 | |
558 | - if ( ! empty($f_values) ) { |
|
558 | + if ( ! empty( $f_values ) ) { |
|
559 | 559 | foreach ( (array) $value as $v_key => $val ) { |
560 | - if ( in_array($val, $f_values) ) { |
|
561 | - $opt = array_search($val, $f_values); |
|
562 | - if ( is_array($value) ) { |
|
563 | - $value[ $v_key ] = $f_labels[ $opt ]; |
|
560 | + if ( in_array( $val, $f_values ) ) { |
|
561 | + $opt = array_search( $val, $f_values ); |
|
562 | + if ( is_array( $value ) ) { |
|
563 | + $value[$v_key] = $f_labels[$opt]; |
|
564 | 564 | } else { |
565 | - $value = $f_labels[ $opt ]; |
|
565 | + $value = $f_labels[$opt]; |
|
566 | 566 | } |
567 | 567 | } |
568 | - unset($v_key, $val); |
|
568 | + unset( $v_key, $val ); |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | } |
579 | 579 | |
580 | 580 | public static function entry_sidebar( $entry ) { |
581 | - $data = maybe_unserialize($entry->description); |
|
582 | - $date_format = get_option('date_format'); |
|
583 | - $time_format = get_option('time_format'); |
|
581 | + $data = maybe_unserialize( $entry->description ); |
|
582 | + $date_format = get_option( 'date_format' ); |
|
583 | + $time_format = get_option( 'time_format' ); |
|
584 | 584 | if ( isset( $data['browser'] ) ) { |
585 | 585 | $browser = FrmEntryFormat::get_browser( $data['browser'] ); |
586 | 586 | } |