Completed
Push — master ( 98f099...4b7b9e )
by Stephanie
04:13
created

FrmFormsController::enqueue_scripts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
class FrmFormsController {
4
5
    public static function menu() {
6
        add_submenu_page('formidable', 'Formidable | '. __( 'Forms', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
7
8
	    add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' );
9
10
	    add_filter('manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
11
		add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
12
    }
13
14
    public static function head() {
15
        wp_enqueue_script('formidable-editinplace');
16
17
        if ( wp_is_mobile() ) {
18
    		wp_enqueue_script( 'jquery-touch-punch' );
19
    	}
20
    }
21
22
    public static function register_widgets() {
23
        require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php');
24
        register_widget('FrmShowForm');
25
    }
26
27
    public static function list_form() {
28
        FrmAppHelper::permission_check('frm_view_forms');
29
30
		$params = FrmForm::list_page_params();
31
        $errors = self::process_bulk_form_actions( array());
32
        $errors = apply_filters('frm_admin_list_form_action', $errors);
33
34
		return self::display_forms_list( $params, '', $errors );
35
    }
36
37
	public static function new_form( $values = array() ) {
38
        FrmAppHelper::permission_check('frm_edit_forms');
39
40
        global $frm_vars;
41
42
        $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
43
		$action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ];
44
45
		if ( $action == 'create' ) {
46
            return self::create($values);
47
		} else if ( $action == 'new' ) {
48
			$frm_field_selection = FrmField::field_selection();
49
            $values = FrmFormsHelper::setup_new_vars($values);
50
            $id = FrmForm::create( $values );
51
            $form = FrmForm::getOne($id);
52
53
            // add default email notification
54
            $action_control = FrmFormActionsController::get_form_actions( 'email' );
55
            $action_control->create($form->id);
56
57
			$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
58
59
            $values['id'] = $id;
60
            require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
61
        }
62
    }
63
64
	public static function create( $values = array() ) {
65
        FrmAppHelper::permission_check('frm_edit_forms');
66
67
        global $frm_vars;
68
        if ( empty( $values ) ) {
69
            $values = $_POST;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
70
        }
71
72
        //Set radio button and checkbox meta equal to "other" value
73
        if ( FrmAppHelper::pro_is_installed() ) {
74
            $values = FrmProEntry::mod_other_vals( $values, 'back' );
75
        }
76
77
		$id = isset($values['id']) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
78
79
        if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) {
80
            $frm_settings = FrmAppHelper::get_settings();
81
            $errors = array( 'form' => $frm_settings->admin_permission );
82
        } else {
83
            $errors = FrmForm::validate($values);
84
        }
85
86
        if ( count($errors) > 0 ) {
87
            $hide_preview = true;
88
			$frm_field_selection = FrmField::field_selection();
89
            $form = FrmForm::getOne( $id );
90
            $fields = FrmField::get_all_for_form($id);
91
92
            $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
93
			$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
94
95
            require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
96
        } else {
97
            FrmForm::update( $id, $values, true );
98
            die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
99
        }
100
    }
101
102
    public static function edit( $values = false ) {
103
        FrmAppHelper::permission_check('frm_edit_forms');
104
105
		$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
106
        return self::get_edit_vars($id);
107
    }
108
109
    public static function settings( $id = false, $message = '' ) {
110
        FrmAppHelper::permission_check('frm_edit_forms');
111
112
        if ( ! $id || ! is_numeric($id) ) {
113
			$id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
114
        }
115
		return self::get_settings_vars( $id, array(), $message );
116
    }
117
118
    public static function update_settings() {
119
        FrmAppHelper::permission_check('frm_edit_forms');
120
121
		$id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
122
123
        $errors = FrmForm::validate($_POST);
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
124
        if ( count($errors) > 0 ) {
125
            return self::get_settings_vars($id, $errors);
126
        }
127
128
        do_action('frm_before_update_form_settings', $id);
129
130
		FrmForm::update( $id, $_POST );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
131
132
        $message = __( 'Settings Successfully Updated', 'formidable' );
133
		return self::get_settings_vars( $id, array(), $message );
134
    }
135
136
	public static function edit_key() {
137
		$values = self::edit_in_place_value( 'form_key' );
138
		echo stripslashes( FrmForm::getKeyById( $values['form_id'] ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'stripslashes'
Loading history...
139
		wp_die();
140
	}
141
142
	public static function edit_description() {
143
		$values = self::edit_in_place_value( 'description' );
144
		echo FrmAppHelper::use_wpautop( stripslashes( $values['description'] ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'FrmAppHelper'
Loading history...
145
		wp_die();
146
	}
147
148
	private static function edit_in_place_value( $field ) {
149
		check_ajax_referer( 'frm_ajax', 'nonce' );
150
		FrmAppHelper::permission_check('frm_edit_forms', 'hide');
151
152
		$form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
153
		$value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_filter_post_kses' );
154
155
		$values = array( $field => trim( $value ) );
156
		FrmForm::update( $form_id, $values );
157
		$values['form_id'] = $form_id;
158
159
		return $values;
160
	}
161
162
	public static function update( $values = array() ) {
163
		if ( empty( $values ) ) {
164
            $values = $_POST;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
165
        }
166
167
        //Set radio button and checkbox meta equal to "other" value
168
        if ( FrmAppHelper::pro_is_installed() ) {
169
            $values = FrmProEntry::mod_other_vals( $values, 'back' );
170
        }
171
172
        $errors = FrmForm::validate( $values );
173
        $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
174
        if ( $permission_error !== false ) {
175
            $errors['form'] = $permission_error;
176
        }
177
178
		$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
179
180
		if ( count( $errors ) > 0 ) {
181
            return self::get_edit_vars( $id, $errors );
182
		} else {
183
            FrmForm::update( $id, $values );
184
            $message = __( 'Form was Successfully Updated', 'formidable' );
185
            if ( defined( 'DOING_AJAX' ) ) {
186
				wp_die( $message );
187
            }
188
			return self::get_edit_vars( $id, array(), $message );
189
        }
190
    }
191
192
    public static function bulk_create_template( $ids ) {
193
        FrmAppHelper::permission_check( 'frm_edit_forms' );
194
195
        foreach ( $ids as $id ) {
196
            FrmForm::duplicate( $id, true, true );
197
        }
198
199
        return __( 'Form template was Successfully Created', 'formidable' );
200
    }
201
202
	/**
203
	 * Redirect to the url for creating from a template
204
	 * Also delete the current form
205
	 * @since 2.0
206
	 */
207
	public static function _create_from_template() {
208
		check_ajax_referer( 'frm_ajax', 'nonce' );
209
210
		$current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
211
		$template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
212
213
		if ( $current_form ) {
214
			FrmForm::destroy( $current_form );
215
		}
216
217
		echo esc_url_raw( admin_url( 'admin.php?page=formidable&action=duplicate&id=' . $template_id ) );
218
		wp_die();
219
	}
220
221
    public static function duplicate() {
222
        FrmAppHelper::permission_check('frm_edit_forms');
223
224
		$params = FrmForm::list_page_params();
225
        $form = FrmForm::duplicate( $params['id'], $params['template'], true );
226
        $message = ($params['template']) ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
227
        if ( $form ) {
228
			return self::get_edit_vars( $form, array(), $message, true );
229
        } else {
230
            return self::display_forms_list($params, __( 'There was a problem creating the new template.', 'formidable' ));
231
        }
232
    }
233
234
    public static function page_preview() {
235
		$params = FrmForm::list_page_params();
236
        if ( ! $params['form'] ) {
237
            return;
238
        }
239
240
        $form = FrmForm::getOne( $params['form'] );
241
        if ( ! $form ) {
242
            return;
243
        }
244
        return self::show_form( $form->id, '', true, true );
245
    }
246
247
    public static function preview() {
248
        do_action( 'frm_wp' );
249
250
        global $frm_vars;
251
        $frm_vars['preview'] = true;
252
253
        if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) {
254
            global $wp;
255
            $root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
256
            include_once( $root.'/wp-config.php' );
257
            $wp->init();
258
            $wp->register_globals();
259
        }
260
261
		self::register_pro_scripts();
262
263
		header( 'Content-Type: text/html; charset='. get_option( 'blog_charset' ) );
264
265
		$key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
266
		if ( $key == '' ) {
267
			$key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
268
		}
269
270
		$form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
271
		if ( empty( $form ) ) {
272
			$form = FrmForm::getAll( array(), '', 1 );
273
        }
274
275
        require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
276
        wp_die();
277
    }
278
279
	public static function register_pro_scripts() {
280
		if ( FrmAppHelper::pro_is_installed() ) {
281
			wp_register_script( 'jquery-frm-rating', FrmAppHelper::plugin_url() . '/pro/js/jquery.rating.min.js', array( 'jquery' ), '4.11', true );
282
			wp_register_script( 'jquery-maskedinput', FrmAppHelper::plugin_url() . '/pro/js/jquery.maskedinput.min.js', array( 'jquery' ), '1.4', true );
283
			wp_register_script( 'jquery-chosen', FrmAppHelper::plugin_url() .'/pro/js/chosen.jquery.min.js', array( 'jquery' ), '1.2.0', true );
284
		}
285
	}
286
287
    public static function untrash() {
288
		self::change_form_status( 'untrash' );
289
    }
290
291
	public static function bulk_untrash( $ids ) {
292
        FrmAppHelper::permission_check('frm_edit_forms');
293
294
        $count = FrmForm::set_status( $ids, 'published' );
295
296
        $message = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
297
        return $message;
298
    }
299
300
    public static function trash() {
301
		self::change_form_status( 'trash' );
302
    }
303
304
	/**
305
	 * @param string $status
306
	 *
307
	 * @return int The number of forms changed
308
	 */
309
	public static function change_form_status( $status ) {
310
		$available_status = array(
311
			'untrash' => array( 'permission' => 'frm_edit_forms', 'new_status' => 'published' ),
312
			'trash'   => array( 'permission' => 'frm_delete_forms', 'new_status' => 'trash' ),
313
		);
314
315
		if ( ! isset( $available_status[ $status ] ) ) {
316
			return;
317
		}
318
319
		FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
320
321
		$params = FrmForm::list_page_params();
322
323
		//check nonce url
324
		check_admin_referer($status .'_form_' . $params['id']);
325
326
		$count = 0;
327
		if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
328
			$count++;
329
		}
330
331
		$available_status['untrash']['message'] = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
332
		$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>' );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
333
334
		$message = $available_status[ $status ]['message'];
335
336
		self::display_forms_list( $params, $message );
337
	}
338
339
	public static function bulk_trash( $ids ) {
340
        FrmAppHelper::permission_check('frm_delete_forms');
341
342
        $count = 0;
343
        foreach ( $ids as $id ) {
344
            if ( FrmForm::trash( $id ) ) {
345
                $count++;
346
            }
347
        }
348
349
        $current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
350
        $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('item-action[]=', $ids), 'bulk-toplevel_page_formidable' )) .'">', '</a>' );
351
352
        return $message;
353
    }
354
355
    public static function destroy() {
356
        FrmAppHelper::permission_check('frm_delete_forms');
357
358
		$params = FrmForm::list_page_params();
359
360
        //check nonce url
361
        check_admin_referer('destroy_form_' . $params['id']);
362
363
        $count = 0;
364
        if ( FrmForm::destroy( $params['id'] ) ) {
365
            $count++;
366
        }
367
368
        $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
369
370
		self::display_forms_list( $params, $message );
371
    }
372
373
	public static function bulk_destroy( $ids ) {
374
        FrmAppHelper::permission_check('frm_delete_forms');
375
376
        $count = 0;
377
        foreach ( $ids as $id ) {
378
            $d = FrmForm::destroy( $id );
379
            if ( $d ) {
380
                $count++;
381
            }
382
        }
383
384
        $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
385
386
        return $message;
387
    }
388
389
    private static function delete_all() {
390
        //check nonce url
391
        $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable');
392
        if ( $permission_error !== false ) {
393
			self::display_forms_list( array(), '', array( $permission_error ) );
394
            return;
395
        }
396
397
		$count = FrmForm::scheduled_delete( time() );
398
        $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
399
400
		self::display_forms_list( array(), $message );
401
    }
402
403
	public static function scheduled_delete( $delete_timestamp = '' ) {
404
		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::scheduled_delete' );
405
		return FrmForm::scheduled_delete( $delete_timestamp );
406
	}
407
408
	/**
409
	* Inserts Formidable button
410
	* Hook exists since 2.5.0
411
	*
412
	* @since 2.0.15
413
	*/
414
	public static function insert_form_button() {
415
		if ( current_user_can('frm_view_forms') ) {
416
			$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' ) . '"><span class="frm-buttons-icon wp-media-buttons-icon"></span> Formidable</a>';
417
			echo wp_kses_post( $content );
418
		}
419
	}
420
421
    public static function insert_form_popup() {
422
		$page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
423
		if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
424
            return;
425
        }
426
427
        FrmAppHelper::load_admin_wide_js();
428
429
        $shortcodes = array(
430
			'formidable' => array( 'name' => __( 'Form', 'formidable' ), 'label' => __( 'Insert a Form', 'formidable' ) ),
431
        );
432
433
        $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
434
435
        include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/insert_form_popup.php');
436
    }
437
438
    public static function get_shortcode_opts() {
439
        check_ajax_referer( 'frm_ajax', 'nonce' );
440
441
		$shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
442
        if ( empty($shortcode) ) {
443
            wp_die();
444
        }
445
446
        echo '<div id="sc-opts-'. esc_attr( $shortcode ) .'" class="frm_shortcode_option">';
447
        echo '<input type="radio" name="frmsc" value="'. esc_attr($shortcode) .'" id="sc-'. esc_attr($shortcode) .'" class="frm_hidden" />';
448
449
        $form_id = '';
450
        $opts = array();
451
		switch ( $shortcode ) {
452
            case 'formidable':
453
                $opts = array(
454
					'form_id'       => 'id',
455
                    //'key' => ',
456
					'title'         => array( 'val' => 1, 'label' => __( 'Display form title', 'formidable' ) ),
457
					'description'   => array( 'val' => 1, 'label' => __( 'Display form description', 'formidable' ) ),
458
					'minimize'      => array( 'val' => 1, 'label' => __( 'Minimize form HTML', 'formidable' ) ),
459
                );
460
            break;
461
        }
462
        $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode);
463
464
		if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
465
			// allow other shortcodes to use the required form id option
466
			$form_id = $opts['form_id'];
467
			unset( $opts['form_id'] );
468
		}
469
470
        include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/shortcode_opts.php');
471
472
        echo '</div>';
473
474
        wp_die();
475
    }
476
477
	public static function display_forms_list( $params = array(), $message = '', $errors = array(), $deprecated_errors = array() ) {
478
        FrmAppHelper::permission_check( 'frm_view_forms' );
479
		if ( ! empty( $deprecated_errors ) ) {
480
			$errors = $deprecated_errors;
481
			_deprecated_argument( 'errors', '2.0.8' );
482
		}
483
484
        global $wpdb, $frm_vars;
485
486
		if ( empty( $params ) ) {
487
			$params = FrmForm::list_page_params();
488
        }
489
490
        $wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
491
492
        $pagenum = $wp_list_table->get_pagenum();
493
494
        $wp_list_table->prepare_items();
495
496
        $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
497
        if ( $pagenum > $total_pages && $total_pages > 0 ) {
498
			wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
499
            die();
500
        }
501
502
        require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/list.php');
503
    }
504
505
	public static function get_columns( $columns ) {
506
	    $columns['cb'] = '<input type="checkbox" />';
507
	    $columns['id'] = 'ID';
508
509
        $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : 'published';
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
510
511
        if ( 'template' == $type ) {
512
            $columns['name']        = __( 'Template Name', 'formidable' );
513
            $columns['type']        = __( 'Type', 'formidable' );
514
            $columns['form_key']    = __( 'Key', 'formidable' );
515
        } else {
516
            $columns['name']        = __( 'Form Title', 'formidable' );
517
            $columns['entries']     = __( 'Entries', 'formidable' );
518
            $columns['form_key']    = __( 'Key', 'formidable' );
519
            $columns['shortcode']   = __( 'Shortcodes', 'formidable' );
520
        }
521
522
        $columns['created_at'] = __( 'Date', 'formidable' );
523
524
		add_screen_option( 'per_page', array( 'label' => __( 'Forms', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_per_page' ) );
525
526
        return $columns;
527
	}
528
529
	public static function get_sortable_columns() {
530
		return array(
531
			'id'            => 'id',
532
			'name'          => 'name',
533
			'description'   => 'description',
534
			'form_key'      => 'form_key',
535
			'created_at'    => 'created_at',
536
		);
537
	}
538
539
	public static function hidden_columns( $result ) {
540
        $return = false;
541
        foreach ( (array) $result as $r ) {
542
            if ( ! empty( $r ) ) {
543
                $return = true;
544
                break;
545
            }
546
        }
547
548
        if ( $return ) {
549
            return $result;
550
		}
551
552
        $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
553
554
        $result[] = 'created_at';
555
        if ( $type == 'template' ) {
556
            $result[] = 'id';
557
            $result[] = 'form_key';
558
        }
559
560
        return $result;
561
    }
562
563
	public static function save_per_page( $save, $option, $value ) {
564
        if ( $option == 'formidable_page_formidable_per_page' ) {
565
            $save = (int) $value;
566
        }
567
        return $save;
568
    }
569
570
	private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
571
        global $frm_vars;
572
573
        $form = FrmForm::getOne( $id );
574
        if ( ! $form ) {
575
            wp_die( __( 'You are trying to edit a form that does not exist.', 'formidable' ) );
576
        }
577
578
        if ( $form->parent_form_id ) {
579
            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>' ));
580
        }
581
582
		$frm_field_selection = FrmField::field_selection();
583
        $fields = FrmField::get_all_for_form($form->id);
584
585
        // Automatically add end section fields if they don't exist (2.0 migration)
586
        $reset_fields = false;
587
        FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
588
589
        if ( $reset_fields ) {
590
            $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
591
        }
592
593
        unset($end_section_values, $last_order, $open, $reset_fields);
594
595
        $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
596
597
        $edit_message = __( 'Form was Successfully Updated', 'formidable' );
598
        if ( $form->is_template && $message == $edit_message ) {
599
            $message = __( 'Template was Successfully Updated', 'formidable' );
600
        }
601
602
		$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
603
604
        if ( $form->default_template ) {
605
            wp_die(__( 'That template cannot be edited', 'formidable' ));
606
        } else if ( defined('DOING_AJAX') ) {
607
            wp_die();
608
        } else if ( $create_link ) {
609
            require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
610
        } else {
611
            require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/edit.php');
612
        }
613
    }
614
615
	public static function get_settings_vars( $id, $errors = array(), $message = '' ) {
616
		FrmAppHelper::permission_check( 'frm_edit_forms' );
617
618
        global $frm_vars;
619
620
        $form = FrmForm::getOne( $id );
621
622
        $fields = FrmField::get_all_for_form($id);
623
        $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
624
625
        if ( isset($values['default_template']) && $values['default_template'] ) {
626
            wp_die(__( 'That template cannot be edited', 'formidable' ));
627
        }
628
629
        $action_controls = FrmFormActionsController::get_form_actions();
630
631
        $sections = apply_filters('frm_add_form_settings_section', array(), $values);
632
        $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"';
633
634
        $styles = apply_filters('frm_get_style_opts', array());
635
636
        require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/settings.php');
637
    }
638
639
    public static function mb_tags_box( $form_id, $class = '' ) {
640
        $fields = FrmField::get_all_for_form($form_id, '', 'include');
641
        $linked_forms = array();
642
        $col = 'one';
643
        $settings_tab = FrmAppHelper::is_admin_page('formidable' ) ? true : false;
644
645
		$cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
646
		$adv_shortcodes = self::get_advanced_shortcodes();
647
		$user_fields = apply_filters( 'frm_user_shortcodes', array() );
648
		$entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
649
650
		include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
651
    }
652
653
	/**
654
	 * Get an array of the options to display in the advanced tab
655
	 * of the customization panel
656
	 * @since 2.0.6
657
	 */
658
	private static function get_advanced_shortcodes() {
659
		$adv_shortcodes = array(
660
			'sep=", "'       => array(
661
				'label' => __( 'Separator', 'formidable' ),
662
				'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
663
			),
664
			'format="d-m-Y"' => __( 'Date Format', 'formidable' ),
665
			'show="field_label"' => __( 'Field Label', 'formidable' ),
666
			'wpautop=0'      => array(
667
				'label' => __( 'No Auto P', 'formidable' ),
668
				'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
669
			),
670
		);
671
		$adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
672
		// __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
673
674
		return $adv_shortcodes;
675
	}
676
677
	/**
678
	 * Get an array of the helper shortcodes to display in the customization panel
679
	 * @since 2.0.6
680
	 */
681
	private static function get_shortcode_helpers( $settings_tab ) {
682
		$entry_shortcodes = array(
683
			'id'        => __( 'Entry ID', 'formidable' ),
684
			'key'       => __( 'Entry Key', 'formidable' ),
685
			'post_id'   => __( 'Post ID', 'formidable' ),
686
			'ip'        => __( 'User IP', 'formidable' ),
687
			'created-at' => __( 'Entry created', 'formidable' ),
688
			'updated-at' => __( 'Entry updated', 'formidable' ),
689
			''          => '',
690
			'siteurl'   => __( 'Site URL', 'formidable' ),
691
			'sitename'  => __( 'Site Name', 'formidable' ),
692
        );
693
694
		if ( ! FrmAppHelper::pro_is_installed() ) {
695
			unset( $entry_shortcodes['post_id'] );
696
		}
697
698
		if ( $settings_tab ) {
699
			$entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
700
			$entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
701
			$entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
702
		} else {
703
			$entry_shortcodes['detaillink'] = __( 'Detail Link', 'formidable' );
704
			$entry_shortcodes['editlink location="front" label="Edit" page_id=x'] = __( 'Edit Entry Link', 'formidable' );
705
			$entry_shortcodes['evenodd'] = __( 'Even/Odd', 'formidable' );
706
			$entry_shortcodes['entry_count'] = __( 'Entry Count', 'formidable' );
707
		}
708
709
		/**
710
		 * Use this hook to add or remove buttons in the helpers section
711
		 * in the customization panel
712
		 * @since 2.0.6
713
		 */
714
		$entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
715
716
		return $entry_shortcodes;
717
	}
718
719
    // Insert the form class setting into the form
720
	public static function form_classes( $form ) {
721
        if ( isset($form->options['form_class']) ) {
722
			echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
723
        }
724
    }
725
726
    public static function get_email_html() {
727
        check_ajax_referer( 'frm_ajax', 'nonce' );
728
		echo FrmEntryFormat::show_entry( array(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'FrmEntryFormat'
Loading history...
729
			'form_id'       => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
730
	        'default_email' => true,
731
			'plain_text'    => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
732
	    ) );
733
	    wp_die();
734
	}
735
736
    public static function filter_content( $content, $form, $entry = false ) {
737
		self::get_entry_by_param( $entry );
738
        if ( ! $entry ) {
739
            return $content;
740
        }
741
742
        if ( is_object( $form ) ) {
743
            $form = $form->id;
744
        }
745
746
        $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
747
        $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
748
749
        return $content;
750
    }
751
752
	private static function get_entry_by_param( &$entry ) {
753
		if ( ! $entry || ! is_object( $entry ) ) {
754
			if ( ! $entry || ! is_numeric( $entry ) ) {
755
				$entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
756
			}
757
758
			FrmEntry::maybe_get_entry( $entry );
759
		}
760
	}
761
762
    public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
763
        return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
764
    }
765
766
    public static function process_bulk_form_actions( $errors ) {
767
        if ( ! $_REQUEST ) {
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
768
            return $errors;
769
        }
770
771
		$bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
772
        if ( $bulkaction == -1 ) {
773
			$bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
774
        }
775
776
        if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
777
            FrmAppHelper::remove_get_action();
778
779
            $bulkaction = str_replace( 'bulk_', '', $bulkaction );
780
        }
781
782
        $ids = FrmAppHelper::get_param( 'item-action', '' );
783
        if ( empty( $ids ) ) {
784
            $errors[] = __( 'No forms were specified', 'formidable' );
785
            return $errors;
786
        }
787
788
        $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
789
        if ( $permission_error !== false ) {
790
            $errors[] = $permission_error;
791
            return $errors;
792
        }
793
794
        if ( ! is_array( $ids ) ) {
795
            $ids = explode( ',', $ids );
796
        }
797
798
        switch ( $bulkaction ) {
799
            case 'delete':
800
                $message = self::bulk_destroy( $ids );
801
            break;
802
            case 'trash':
803
                $message = self::bulk_trash( $ids );
804
            break;
805
            case 'untrash':
806
                $message = self::bulk_untrash( $ids );
807
            break;
808
            case 'create_template':
809
                $message = self::bulk_create_template( $ids );
810
            break;
811
        }
812
813
        if ( isset( $message ) && ! empty( $message ) ) {
814
			echo '<div id="message" class="updated frm_msg_padding">' . FrmAppHelper::kses( $message ) . '</div>';
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'FrmAppHelper'
Loading history...
815
        }
816
817
        return $errors;
818
    }
819
820
    public static function add_default_templates( $path, $default = true, $template = true ) {
821
        _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
822
823
        $path = untrailingslashit(trim($path));
824
        $templates = glob( $path .'/*.php' );
825
826
		for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) {
827
            $filename = str_replace( '.php', '', str_replace( $path.'/', '', $templates[ $i ] ) );
828
			$template_query = array( 'form_key' => $filename );
829
            if ( $template ) {
830
                $template_query['is_template'] = 1;
831
            }
832
            if ( $default ) {
833
                $template_query['default_template'] = 1;
834
            }
835
			$form = FrmForm::getAll( $template_query, '', 1 );
836
837
            $values = FrmFormsHelper::setup_new_vars();
838
            $values['form_key'] = $filename;
839
            $values['is_template'] = $template;
840
            $values['status'] = 'published';
841
            if ( $default ) {
842
                $values['default_template'] = 1;
843
            }
844
845
            include( $templates[ $i ] );
846
847
            //get updated form
848
            if ( isset($form) && ! empty($form) ) {
849
                $old_id = $form->id;
850
                $form = FrmForm::getOne($form->id);
851
            } else {
852
                $old_id = false;
853
				$form = FrmForm::getAll( $template_query, '', 1 );
854
            }
855
856
            if ( $form ) {
857
				do_action( 'frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id ) );
858
            }
859
        }
860
    }
861
862
    public static function route() {
863
        $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
864
        $vars = array();
865
		if ( isset( $_POST['frm_compact_fields'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
866
			FrmAppHelper::permission_check( 'frm_edit_forms' );
867
868
            $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('&quot;', '\\\"', $_POST['frm_compact_fields'] ))));
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
869
            $json_vars = json_decode($json_vars, true);
870
            if ( empty($json_vars) ) {
871
                // json decoding failed so we should return an error message
872
				$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
873
                if ( 'edit' == $action ) {
874
                    $action = 'update';
875
                }
876
877
                add_filter('frm_validate_form', 'FrmFormsController::json_error');
878
            } else {
879
                $vars = FrmAppHelper::json_to_array($json_vars);
880
                $action = $vars[ $action ];
881
				unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
882
				$_REQUEST = array_merge( $_REQUEST, $vars );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
883
				$_POST = array_merge( $_POST, $_REQUEST );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
884
            }
885
        } else {
886
			$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
887
    		if ( isset( $_REQUEST['delete_all'] ) ) {
888
                // override the action for this page
889
    			$action = 'delete_all';
890
            }
891
        }
892
893
		add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
894
        FrmAppHelper::trigger_hook_load( 'form' );
895
896
        switch ( $action ) {
897
            case 'new':
898
                return self::new_form($vars);
899
            case 'create':
900
            case 'edit':
901
            case 'update':
902
            case 'duplicate':
903
            case 'trash':
904
            case 'untrash':
905
            case 'destroy':
906
            case 'delete_all':
907
            case 'settings':
908
            case 'update_settings':
909
				return self::$action( $vars );
910
            default:
911
                do_action('frm_form_action_'. $action);
912
                if ( apply_filters('frm_form_stop_action_'. $action, false) ) {
913
                    return;
914
                }
915
916
				$action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
917
                if ( $action == -1 ) {
918
					$action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
919
                }
920
921
                if ( strpos($action, 'bulk_') === 0 ) {
922
                    FrmAppHelper::remove_get_action();
923
                    return self::list_form();
924
                }
925
926
                return self::display_forms_list();
927
        }
928
    }
929
930
    public static function json_error( $errors ) {
931
        $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
932
        return $errors;
933
    }
934
935
936
    /* FRONT-END FORMS */
937
    public static function admin_bar_css() {
938
		if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
939
            return;
940
        }
941
942
		add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
943
		FrmAppHelper::load_font_style();
944
	}
945
946
	public static function admin_bar_configure() {
947
        global $frm_vars;
948
        if ( empty($frm_vars['forms_loaded']) ) {
949
            return;
950
        }
951
952
        $actions = array();
953
        foreach ( $frm_vars['forms_loaded'] as $form ) {
954
            if ( is_object($form) ) {
955
                $actions[ $form->id ] = $form->name;
956
            }
957
            unset($form);
958
        }
959
960
        if ( empty($actions) ) {
961
            return;
962
        }
963
964
        asort($actions);
965
966
        global $wp_admin_bar;
967
968
        if ( count($actions) == 1 ) {
969
            $wp_admin_bar->add_menu( array(
970
                'title' => 'Edit Form',
971
                'href'  => admin_url('admin.php?page=formidable&frm_action=edit&id='. current( array_keys( $actions ) )),
972
                'id'    => 'frm-forms',
973
            ) );
974
        } else {
975
            $wp_admin_bar->add_menu( array(
976
        		'id'    => 'frm-forms',
977
        		'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>',
978
        		'href'  => admin_url( 'admin.php?page=formidable&frm_action=edit&id='. current( array_keys( $actions ) ) ),
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'current'
Loading history...
979
        		'meta'  => array(
980
					'title' => __( 'Edit Forms', 'formidable' ),
981
        		),
982
        	) );
983
984
        	foreach ( $actions as $form_id => $name ) {
985
986
        		$wp_admin_bar->add_menu( array(
987
        			'parent'    => 'frm-forms',
988
        			'id'        => 'edit_form_'. $form_id,
989
        			'title'     => empty($name) ? __( '(no title)') : $name,
990
					'href'      => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ),
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
991
        		) );
992
        	}
993
        }
994
    }
995
996
    //formidable shortcode
997
	public static function get_form_shortcode( $atts ) {
998
        global $frm_vars;
999
        if ( isset($frm_vars['skip_shortcode']) && $frm_vars['skip_shortcode'] ) {
1000
            $sc = '[formidable';
1001
			if ( ! empty( $atts ) ) {
1002
				foreach ( $atts as $k => $v ) {
1003
					$sc .= ' ' . $k . '="' . esc_attr( $v ) . '"';
1004
				}
1005
			}
1006
            return $sc .']';
1007
        }
1008
1009
        $shortcode_atts = shortcode_atts( array(
1010
            'id' => '', 'key' => '', 'title' => false, 'description' => false,
1011
            'readonly' => false, 'entry_id' => false, 'fields' => array(),
1012
            'exclude_fields' => array(), 'minimize' => false,
1013
        ), $atts);
1014
        do_action('formidable_shortcode_atts', $shortcode_atts, $atts);
1015
1016
        return self::show_form(
1017
            $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'],
1018
            $shortcode_atts['description'], $atts
1019
        );
1020
    }
1021
1022
    public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1023
        if ( empty( $id ) ) {
1024
            $id = $key;
1025
        }
1026
1027
        // no form id or key set
1028
        if ( empty( $id ) ) {
1029
            return __( 'Please select a valid form', 'formidable' );
1030
        }
1031
1032
        $form = FrmForm::getOne( $id );
1033
        if ( ! $form || $form->parent_form_id ) {
1034
            return __( 'Please select a valid form', 'formidable' );
1035
        }
1036
1037
		add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1038
        FrmAppHelper::trigger_hook_load( 'form', $form );
1039
1040
        $form = apply_filters( 'frm_pre_display_form', $form );
1041
1042
        $frm_settings = FrmAppHelper::get_settings();
1043
1044
		if ( self::is_viewable_draft_form( $form ) ) {
1045
			// don't show a draft form on a page
1046
			$form = __( 'Please select a valid form', 'formidable' );
1047
		} else if ( self::user_should_login( $form ) ) {
1048
			$form = do_shortcode( $frm_settings->login_msg );
1049
		} else if ( self::user_has_permission_to_view( $form ) ) {
1050
			$form = do_shortcode( $frm_settings->login_msg );
1051
		} else {
1052
			$form = self::get_form( $form, $title, $description, $atts );
1053
1054
			/**
1055
			 * Use this shortcode to check for external shortcodes that may span
1056
			 * across multiple fields in the customizable HTML
1057
			 * @since 2.0.8
1058
			 */
1059
			$form = apply_filters( 'frm_filter_final_form', $form );
1060
		}
1061
1062
		return $form;
1063
    }
1064
1065
	private static function is_viewable_draft_form( $form ) {
1066
		global $post;
1067
		$frm_settings = FrmAppHelper::get_settings();
1068
		return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ( ! $post || $post->ID != $frm_settings->preview_page_id ) && ! FrmAppHelper::is_preview_page();
1069
	}
1070
1071
	private static function user_should_login( $form ) {
1072
		return $form->logged_in && ! is_user_logged_in();
1073
	}
1074
1075
	private static function user_has_permission_to_view( $form ) {
1076
		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'] );
1077
	}
1078
1079
    public static function get_form( $form, $title, $description, $atts = array() ) {
1080
        ob_start();
1081
1082
        self::get_form_contents( $form, $title, $description, $atts );
1083
		self::enqueue_scripts( FrmForm::get_params( $form ) );
1084
1085
        $contents = ob_get_contents();
1086
        ob_end_clean();
1087
1088
		self::maybe_minimize_form( $atts, $contents );
1089
1090
        return $contents;
1091
    }
1092
1093
	public static function enqueue_scripts( $params ) {
1094
		do_action( 'frm_enqueue_form_scripts', $params );
1095
	}
1096
1097
	public static function get_form_contents( $form, $title, $description, $atts ) {
1098
        global $frm_vars;
1099
1100
        $frm_settings = FrmAppHelper::get_settings();
1101
1102
        $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
1103
1104
        $user_ID = get_current_user_id();
1105
		$params = FrmForm::get_params( $form );
1106
        $message = $errors = '';
1107
1108
        if ( $params['posted_form_id'] == $form->id && $_POST ) {
1109
            $errors = isset( $frm_vars['created_entries'][ $form->id ] ) ? $frm_vars['created_entries'][ $form->id ]['errors'] : array();
1110
        }
1111
1112
		$include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
1113
        $fields = FrmFieldsHelper::get_form_fields( $form->id, ( isset( $errors ) && ! empty( $errors ) ) );
1114
1115
        if ( $params['action'] != 'create' || $params['posted_form_id'] != $form->id || ! $_POST ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
1116
            do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
1117
            if ( apply_filters('frm_continue_to_new', true, $form->id, $params['action']) ) {
1118
                $values = FrmEntriesHelper::setup_new_vars($fields, $form);
1119
                include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
1120
            }
1121
            return;
1122
        }
1123
1124
        if ( ! empty($errors) ) {
1125
            $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
1126
            include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
1127
            return;
1128
        }
1129
1130
        do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
1131
        if ( ! apply_filters('frm_continue_to_create', true, $form->id) ) {
1132
            return;
1133
        }
1134
1135
        $values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
1136
        $created = ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form->id ] ) ) ? $frm_vars['created_entries'][ $form->id ]['entry_id'] : 0;
1137
        $conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
1138
1139
        if ( $created && is_numeric($created) && $conf_method != 'message' ) {
1140
            do_action('frm_success_action', $conf_method, $form, $form->options, $created);
1141
			do_action( 'frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form ) );
1142
            return;
1143
        }
1144
1145
        if ( $created && is_numeric($created) ) {
1146
            $message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
1147
            $class = 'frm_message';
1148
        } else {
1149
            $message = $frm_settings->failed_msg;
1150
            $class = 'frm_error_style';
1151
        }
1152
1153
		$message = FrmFormsHelper::get_success_message( array(
1154
			'message' => $message, 'form' => $form,
1155
			'entry_id' => $created, 'class' => $class,
1156
		) );
1157
        $message = apply_filters('frm_main_feedback', $message, $form, $created);
1158
1159
        if ( ! isset($form->options['show_form']) || $form->options['show_form'] ) {
1160
            require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
1161
        } else {
1162
            global $frm_vars;
1163
			self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
1164
1165
            $include_extra_container = 'frm_forms'. FrmFormsHelper::get_form_style_class($values);
1166
            include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
1167
        }
1168
1169
		do_action( 'frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form ) );
1170
    }
1171
1172
	public static function front_head() {
1173
		$version = FrmAppHelper::plugin_version();
1174
		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1175
		wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
1176
		wp_register_script( 'jquery-placeholder', FrmAppHelper::plugin_url() . '/js/jquery/jquery.placeholder.js', array( 'jquery' ), '2.0.7', true );
1177
1178
		if ( FrmAppHelper::is_admin() ) {
1179
			// don't load this in back-end
1180
			return;
1181
		}
1182
1183
		FrmAppHelper::localize_script( 'front' );
1184
		FrmStylesController::enqueue_css( 'register' );
1185
	}
1186
1187
	public static function maybe_load_css( $form, $this_load, $global_load ) {
1188
		$load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
1189
1190
		if ( $load_css ) {
1191
			global $frm_vars;
1192
			self::footer_js( 'header' );
1193
			$frm_vars['css_loaded'] = true;
1194
		}
1195
	}
1196
1197
	public static function footer_js( $location = 'footer' ) {
1198
		global $frm_vars;
1199
1200
		FrmStylesController::enqueue_css();
1201
1202
		if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
1203
			//load formidable js
1204
			wp_enqueue_script( 'formidable' );
1205
		}
1206
	}
1207
1208
	/**
1209
	 * @since 2.0.8
1210
	 */
1211
	private static function maybe_minimize_form( $atts, &$content ) {
1212
		// check if minimizing is turned on
1213
		if ( self::is_minification_on( $atts ) ) {
1214
			$content = str_replace( array( "\r\n", "\r", "\n", "\t", '    ' ), '', $content );
1215
		}
1216
	}
1217
1218
	/**
1219
	 * @since 2.0.8
1220
	 * @return boolean
1221
	 */
1222
	private static function is_minification_on( $atts ) {
1223
		return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
1224
	}
1225
}
1226