@@ -58,9 +58,9 @@ |
||
58 | 58 | <tr> |
59 | 59 | <th>Included AddOns</th> |
60 | 60 | <td>None</td> |
61 | - <td><a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url('https://formidableforms.com/pricing/#addon-lists') ) ?>" target="_blank">Premium Addons</a></td> |
|
62 | - <td><a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url('https://formidableforms.com/pricing/#addon-lists') ) ?>" target="_blank">Advanced Addons</a></td> |
|
63 | - <td><a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url('https://formidableforms.com/pricing/#addon-lists') ) ?>" target="_blank">Enterprise Addons</a></td> |
|
61 | + <td><a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/pricing/#addon-lists' ) ) ?>" target="_blank">Premium Addons</a></td> |
|
62 | + <td><a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/pricing/#addon-lists' ) ) ?>" target="_blank">Advanced Addons</a></td> |
|
63 | + <td><a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/pricing/#addon-lists' ) ) ?>" target="_blank">Enterprise Addons</a></td> |
|
64 | 64 | </tr> |
65 | 65 | </tbody> |
66 | 66 | </table> |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <div class="frmcenter frm_no_entries_form"> |
2 | 2 | <?php |
3 | -if ( $form && isset($form->options['no_save']) && $form->options['no_save'] ) { ?> |
|
3 | +if ( $form && isset( $form->options['no_save'] ) && $form->options['no_save'] ) { ?> |
|
4 | 4 | <h3><?php _e( 'This form is not set to save any entries.', 'formidable' ) ?></h3> |
5 | 5 | <p>If you would like entries in this form to be saved, go to the <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) . '&frm_action=settings&id=' . $form->id ) ?>">form Settings</a> page and uncheck the "Do not store any entries submitted from this form" box.</p> |
6 | 6 | <?php |
7 | 7 | } else if ( $form ) { |
8 | 8 | ?> |
9 | -<div class="frm_no_entries_header"><?php printf(__( 'No Entries for form: %s', 'formidable' ), $form->name); ?></div> |
|
10 | -<p class="frm_no_entries_text"><?php printf( __( 'For instructions on publishing your form see %1$sthe docs%2$s or click "%3$sAdd New%4$s" above to add an entry from here (Requires License)', 'formidable' ), '<a href="https://formidableforms.com/knowledgebase/publish-your-forms/" target="_blank">', '</a> <br/>', '<a href="' . esc_url( admin_url('admin.php?page=formidable-entries&frm_action=new&form=' . $form->id ) ) . '">', '</a>' ); ?></p> |
|
9 | +<div class="frm_no_entries_header"><?php printf( __( 'No Entries for form: %s', 'formidable' ), $form->name ); ?></div> |
|
10 | +<p class="frm_no_entries_text"><?php printf( __( 'For instructions on publishing your form see %1$sthe docs%2$s or click "%3$sAdd New%4$s" above to add an entry from here (Requires License)', 'formidable' ), '<a href="https://formidableforms.com/knowledgebase/publish-your-forms/" target="_blank">', '</a> <br/>', '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&frm_action=new&form=' . $form->id ) ) . '">', '</a>' ); ?></p> |
|
11 | 11 | <?php |
12 | 12 | } else { |
13 | 13 | ?> |
@@ -1,16 +1,16 @@ discard block |
||
1 | -<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('post_excerpt', '') ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" /> |
|
2 | -<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('ID', '') ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" /> |
|
1 | +<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'post_excerpt', '' ) ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" /> |
|
2 | +<input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'ID', '' ) ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" /> |
|
3 | 3 | |
4 | 4 | <table class="form-table"> |
5 | 5 | <tr> |
6 | 6 | <th> |
7 | - <label <?php FrmAppHelper::maybe_add_tooltip('action_title') ?>><?php _e( 'Label', 'formidable' ) ?></label> |
|
7 | + <label <?php FrmAppHelper::maybe_add_tooltip( 'action_title' ) ?>><?php _e( 'Label', 'formidable' ) ?></label> |
|
8 | 8 | </th> |
9 | - <td><input type="text" name="<?php echo esc_attr( $action_control->get_field_name('post_title', '') ) ?>" value="<?php echo esc_attr($form_action->post_title); ?>" class="large-text <?php FrmAppHelper::maybe_add_tooltip('action_title', 'open') ?>" id="<?php echo esc_attr( $action_control->get_field_id('action_post_title') ) ?>" /> |
|
9 | + <td><input type="text" name="<?php echo esc_attr( $action_control->get_field_name( 'post_title', '' ) ) ?>" value="<?php echo esc_attr( $form_action->post_title ); ?>" class="large-text <?php FrmAppHelper::maybe_add_tooltip( 'action_title', 'open' ) ?>" id="<?php echo esc_attr( $action_control->get_field_id( 'action_post_title' ) ) ?>" /> |
|
10 | 10 | </td> |
11 | 11 | </tr> |
12 | 12 | </table> |
13 | -<?php $action_control->form($form_action, compact('form', 'action_key', 'values')); ?> |
|
13 | +<?php $action_control->form( $form_action, compact( 'form', 'action_key', 'values' ) ); ?> |
|
14 | 14 | |
15 | 15 | <table class="form-table frm-no-margin"> |
16 | 16 | <tr><td> |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | if ( count( $action_control->action_options['event'] ) == 1 || $action_control->action_options['force_event'] ) { |
27 | 27 | foreach ( $action_control->action_options['event'] as $e ) { ?> |
28 | - <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('event') ) ?>[]" value="<?php echo esc_attr( $e ) ?>" /> |
|
28 | + <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'event' ) ) ?>[]" value="<?php echo esc_attr( $e ) ?>" /> |
|
29 | 29 | <?php |
30 | 30 | } |
31 | 31 | } else { |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | <tr> |
37 | 37 | <td> |
38 | 38 | <label class="frm_left_label"><?php _e( 'Trigger this action after', 'formidable' ) ?></label> |
39 | - <select name="<?php echo esc_attr( $action_control->get_field_name('event') ) ?>[]" multiple="multiple" class="frm_multiselect" id="<?php echo esc_attr( $action_control->get_field_id('event') ) ?>"> |
|
39 | + <select name="<?php echo esc_attr( $action_control->get_field_name( 'event' ) ) ?>[]" multiple="multiple" class="frm_multiselect" id="<?php echo esc_attr( $action_control->get_field_id( 'event' ) ) ?>"> |
|
40 | 40 | <?php |
41 | 41 | |
42 | 42 | $event_labels = FrmFormAction::trigger_labels(); |
43 | 43 | foreach ( $action_control->action_options['event'] as $event ) { ?> |
44 | - <option value="<?php echo esc_attr( $event ) ?>" <?php echo in_array( $event, (array) $form_action->post_content['event'] ) ? ' selected="selected"' : ''; ?> ><?php echo isset( $event_labels[ $event ] ) ? $event_labels[ $event ] : $event; ?></option> |
|
44 | + <option value="<?php echo esc_attr( $event ) ?>" <?php echo in_array( $event, (array) $form_action->post_content['event'] ) ? ' selected="selected"' : ''; ?> ><?php echo isset( $event_labels[$event] ) ? $event_labels[$event] : $event; ?></option> |
|
45 | 45 | <?php |
46 | 46 | } |
47 | 47 | ?> </select> |
@@ -56,6 +56,6 @@ discard block |
||
56 | 56 | do_action( 'frm_additional_action_settings', $form_action, $pass_args ); |
57 | 57 | |
58 | 58 | ?> |
59 | - <span class="alignright frm_action_id <?php echo empty( $form_action->ID ) ? 'frm_hidden' : ''; ?>"><?php printf( __( 'Action ID: %1$s', 'formidable' ), $form_action->ID); ?></span> |
|
59 | + <span class="alignright frm_action_id <?php echo empty( $form_action->ID ) ? 'frm_hidden' : ''; ?>"><?php printf( __( 'Action ID: %1$s', 'formidable' ), $form_action->ID ); ?></span> |
|
60 | 60 | </td></tr> |
61 | 61 | </table> |
@@ -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,144 +139,144 @@ 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 | 175 | $field_id = FrmField::create( $values ); |
176 | 176 | if ( ! $field_id ) { |
177 | 177 | wp_die(); |
178 | 178 | } |
179 | 179 | |
180 | - self::include_single_field($field_id, $values); |
|
180 | + self::include_single_field($field_id, $values); |
|
181 | 181 | |
182 | - wp_die(); |
|
183 | - } |
|
182 | + wp_die(); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Load a single field in the form builder along with all needed variables |
|
187 | - */ |
|
188 | - public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
189 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
185 | + /** |
|
186 | + * Load a single field in the form builder along with all needed variables |
|
187 | + */ |
|
188 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
189 | + $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
190 | 190 | $field_name = 'item_meta[' . $field_id . ']'; |
191 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
192 | - $id = $form_id ? $form_id : $field['form_id']; |
|
193 | - if ( $field['type'] == 'html' ) { |
|
194 | - $field['stop_filter'] = true; |
|
195 | - } |
|
191 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
192 | + $id = $form_id ? $form_id : $field['form_id']; |
|
193 | + if ( $field['type'] == 'html' ) { |
|
194 | + $field['stop_filter'] = true; |
|
195 | + } |
|
196 | 196 | |
197 | 197 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' ); |
198 | 198 | |
199 | - return $field; |
|
200 | - } |
|
199 | + return $field; |
|
200 | + } |
|
201 | 201 | |
202 | - public static function destroy() { |
|
202 | + public static function destroy() { |
|
203 | 203 | FrmAppHelper::permission_check('frm_edit_forms'); |
204 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
204 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
205 | 205 | |
206 | 206 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
207 | 207 | FrmField::destroy( $field_id ); |
208 | - wp_die(); |
|
209 | - } |
|
208 | + wp_die(); |
|
209 | + } |
|
210 | 210 | |
211 | - /* Field Options */ |
|
211 | + /* Field Options */ |
|
212 | 212 | |
213 | - //Add Single Option or Other Option |
|
214 | - public static function add_option() { |
|
213 | + //Add Single Option or Other Option |
|
214 | + public static function add_option() { |
|
215 | 215 | FrmAppHelper::permission_check('frm_edit_forms'); |
216 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
216 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
217 | 217 | |
218 | 218 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
219 | 219 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
220 | 220 | |
221 | - //Get the field |
|
222 | - $field = FrmField::getOne($id); |
|
221 | + //Get the field |
|
222 | + $field = FrmField::getOne($id); |
|
223 | 223 | |
224 | 224 | if ( ! empty( $field->options ) ) { |
225 | 225 | $keys = array_keys( $field->options ); |
226 | - $last = str_replace( 'other_', '', end( $keys ) ); |
|
227 | - } else { |
|
228 | - $last = 0; |
|
229 | - } |
|
230 | - $opt_key = $last + 1; |
|
226 | + $last = str_replace( 'other_', '', end( $keys ) ); |
|
227 | + } else { |
|
228 | + $last = 0; |
|
229 | + } |
|
230 | + $opt_key = $last + 1; |
|
231 | 231 | |
232 | - if ( 'other' == $opt_type ) { |
|
232 | + if ( 'other' == $opt_type ) { |
|
233 | 233 | $opt = esc_html__( 'Other', 'formidable' ); |
234 | - $other_val = ''; |
|
235 | - $opt_key = 'other_' . $opt_key; |
|
236 | - |
|
237 | - //Update value of "other" in DB |
|
238 | - $field_options = maybe_unserialize( $field->field_options ); |
|
239 | - $field_options['other'] = 1; |
|
240 | - FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
|
241 | - } else { |
|
234 | + $other_val = ''; |
|
235 | + $opt_key = 'other_' . $opt_key; |
|
236 | + |
|
237 | + //Update value of "other" in DB |
|
238 | + $field_options = maybe_unserialize( $field->field_options ); |
|
239 | + $field_options['other'] = 1; |
|
240 | + FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
|
241 | + } else { |
|
242 | 242 | $first_opt = reset( $field->options ); |
243 | 243 | $next_opt = count( $field->options ); |
244 | - if ( $first_opt != '' ) { |
|
245 | - $next_opt++; |
|
246 | - } |
|
244 | + if ( $first_opt != '' ) { |
|
245 | + $next_opt++; |
|
246 | + } |
|
247 | 247 | $opt = esc_html__( 'Option', 'formidable' ) . ' ' . $next_opt; |
248 | - unset($next_opt); |
|
249 | - } |
|
250 | - $field_val = $opt; |
|
248 | + unset($next_opt); |
|
249 | + } |
|
250 | + $field_val = $opt; |
|
251 | 251 | $field->options[ $opt_key ] = $opt; |
252 | 252 | |
253 | - //Update options in DB |
|
253 | + //Update options in DB |
|
254 | 254 | FrmField::update( $id, array( 'options' => $field->options ) ); |
255 | 255 | |
256 | - $field_data = $field; |
|
257 | - $field = array( |
|
258 | - 'type' => $field_data->type, |
|
259 | - 'id' => $id, |
|
260 | - 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0, |
|
261 | - 'form_id' => $field_data->form_id, |
|
262 | - 'field_key' => $field_data->field_key, |
|
263 | - ); |
|
256 | + $field_data = $field; |
|
257 | + $field = array( |
|
258 | + 'type' => $field_data->type, |
|
259 | + 'id' => $id, |
|
260 | + 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0, |
|
261 | + 'form_id' => $field_data->form_id, |
|
262 | + 'field_key' => $field_data->field_key, |
|
263 | + ); |
|
264 | 264 | |
265 | 265 | $field_name = 'item_meta[' . $id . ']'; |
266 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
267 | - $checked = ''; |
|
266 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
267 | + $checked = ''; |
|
268 | 268 | |
269 | - if ( 'other' == $opt_type ) { |
|
269 | + if ( 'other' == $opt_type ) { |
|
270 | 270 | require( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' ); |
271 | - } else { |
|
271 | + } else { |
|
272 | 272 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
273 | - } |
|
274 | - wp_die(); |
|
275 | - } |
|
273 | + } |
|
274 | + wp_die(); |
|
275 | + } |
|
276 | 276 | |
277 | - public static function edit_option() { |
|
277 | + public static function edit_option() { |
|
278 | 278 | FrmAppHelper::permission_check('frm_edit_forms'); |
279 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
279 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
280 | 280 | |
281 | 281 | $element_id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
282 | 282 | $ids = explode( '-', $element_id ); |
@@ -285,43 +285,43 @@ discard block |
||
285 | 285 | $orig_update_value = trim( FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ) ); |
286 | 286 | $update_value = $orig_update_value; |
287 | 287 | if ( strpos( $element_id, 'key_' ) ) { |
288 | - $new_value = $update_value; |
|
289 | - } else { |
|
290 | - $new_label = $update_value; |
|
291 | - } |
|
288 | + $new_value = $update_value; |
|
289 | + } else { |
|
290 | + $new_label = $update_value; |
|
291 | + } |
|
292 | 292 | |
293 | - $field = FrmField::getOne($id); |
|
294 | - $separate_values = FrmField::is_option_true( $field, 'separate_value' ); |
|
293 | + $field = FrmField::getOne($id); |
|
294 | + $separate_values = FrmField::is_option_true( $field, 'separate_value' ); |
|
295 | 295 | |
296 | - $this_opt_id = end($ids); |
|
296 | + $this_opt_id = end($ids); |
|
297 | 297 | $this_opt = (array) $field->options[ $this_opt_id ]; |
298 | 298 | $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ); |
299 | 299 | |
300 | - $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt); |
|
301 | - $value = isset($this_opt['value']) ? $this_opt['value'] : ''; |
|
300 | + $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt); |
|
301 | + $value = isset($this_opt['value']) ? $this_opt['value'] : ''; |
|
302 | 302 | |
303 | - if ( ! isset( $new_label ) ) { |
|
304 | - $new_label = $label; |
|
305 | - } |
|
303 | + if ( ! isset( $new_label ) ) { |
|
304 | + $new_label = $label; |
|
305 | + } |
|
306 | 306 | |
307 | - if ( isset($new_value) || isset($value) ) { |
|
308 | - $update_value = isset($new_value) ? $new_value : $value; |
|
309 | - } |
|
307 | + if ( isset($new_value) || isset($value) ) { |
|
308 | + $update_value = isset($new_value) ? $new_value : $value; |
|
309 | + } |
|
310 | 310 | |
311 | 311 | if ( $update_value != $new_label && $other_opt === false && $separate_values ) { |
312 | 312 | $field->options[ $this_opt_id ] = array( 'value' => $update_value, 'label' => $new_label ); |
313 | - } else { |
|
313 | + } else { |
|
314 | 314 | $field->options[ $this_opt_id ] = $orig_update_value; |
315 | - } |
|
315 | + } |
|
316 | 316 | |
317 | 317 | FrmField::update( $field->id, array( 'options' => $field->options ) ); |
318 | 318 | echo ( $orig_update_value == '' ) ? esc_html__( '(Blank)', 'formidable' ) : stripslashes( $orig_update_value ); |
319 | - wp_die(); |
|
320 | - } |
|
319 | + wp_die(); |
|
320 | + } |
|
321 | 321 | |
322 | - public static function delete_option() { |
|
322 | + public static function delete_option() { |
|
323 | 323 | FrmAppHelper::permission_check('frm_edit_forms'); |
324 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
324 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
325 | 325 | |
326 | 326 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
327 | 327 | $field = FrmField::getOne( $field_id ); |
@@ -329,170 +329,170 @@ discard block |
||
329 | 329 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'sanitize_title' ); |
330 | 330 | |
331 | 331 | $options = $field->options; |
332 | - unset( $options[ $opt_key ] ); |
|
333 | - $response = array( 'other' => true ); |
|
332 | + unset( $options[ $opt_key ] ); |
|
333 | + $response = array( 'other' => true ); |
|
334 | 334 | |
335 | - //If the deleted option is an "other" option |
|
335 | + //If the deleted option is an "other" option |
|
336 | 336 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
337 | - //Assume all other options are gone, unless proven otherwise |
|
338 | - $other = false; |
|
337 | + //Assume all other options are gone, unless proven otherwise |
|
338 | + $other = false; |
|
339 | 339 | |
340 | - //Check if all other options are really gone |
|
341 | - foreach ( $options as $o_key => $o_val ) { |
|
342 | - //If there is still an other option in the field, set other to true |
|
340 | + //Check if all other options are really gone |
|
341 | + foreach ( $options as $o_key => $o_val ) { |
|
342 | + //If there is still an other option in the field, set other to true |
|
343 | 343 | if ( FrmFieldsHelper::is_other_opt( $o_key ) ) { |
344 | - $other = true; |
|
345 | - break; |
|
346 | - } |
|
347 | - unset( $o_key, $o_val ); |
|
348 | - } |
|
349 | - |
|
350 | - //If all other options are gone |
|
351 | - if ( false === $other ) { |
|
352 | - $field_options = maybe_unserialize( $field->field_options ); |
|
353 | - $field_options['other'] = 0; |
|
344 | + $other = true; |
|
345 | + break; |
|
346 | + } |
|
347 | + unset( $o_key, $o_val ); |
|
348 | + } |
|
349 | + |
|
350 | + //If all other options are gone |
|
351 | + if ( false === $other ) { |
|
352 | + $field_options = maybe_unserialize( $field->field_options ); |
|
353 | + $field_options['other'] = 0; |
|
354 | 354 | FrmField::update( $field_id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
355 | - $response = array( 'other' => false ); |
|
356 | - } |
|
357 | - } |
|
358 | - echo json_encode( $response ); |
|
355 | + $response = array( 'other' => false ); |
|
356 | + } |
|
357 | + } |
|
358 | + echo json_encode( $response ); |
|
359 | 359 | |
360 | 360 | FrmField::update( $field_id, array( 'options' => maybe_serialize( $options ) ) ); |
361 | 361 | |
362 | - wp_die(); |
|
363 | - } |
|
362 | + wp_die(); |
|
363 | + } |
|
364 | 364 | |
365 | - public static function import_choices() { |
|
366 | - FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
365 | + public static function import_choices() { |
|
366 | + FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
367 | 367 | |
368 | 368 | $field_id = absint( $_REQUEST['field_id'] ); |
369 | 369 | |
370 | - global $current_screen, $hook_suffix; |
|
370 | + global $current_screen, $hook_suffix; |
|
371 | 371 | |
372 | - // Catch plugins that include admin-header.php before admin.php completes. |
|
373 | - if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
374 | - $hook_suffix = ''; |
|
375 | - set_current_screen(); |
|
376 | - } |
|
372 | + // Catch plugins that include admin-header.php before admin.php completes. |
|
373 | + if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
374 | + $hook_suffix = ''; |
|
375 | + set_current_screen(); |
|
376 | + } |
|
377 | 377 | |
378 | - if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
379 | - register_admin_color_schemes(); |
|
380 | - } |
|
378 | + if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
379 | + register_admin_color_schemes(); |
|
380 | + } |
|
381 | 381 | |
382 | 382 | $hook_suffix = ''; |
383 | 383 | $admin_body_class = ''; |
384 | 384 | |
385 | - if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
386 | - $admin_body_class .= ' folded'; |
|
387 | - } |
|
385 | + if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
386 | + $admin_body_class .= ' folded'; |
|
387 | + } |
|
388 | 388 | |
389 | - if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
390 | - $admin_body_class .= ' admin-bar'; |
|
391 | - } |
|
389 | + if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
390 | + $admin_body_class .= ' admin-bar'; |
|
391 | + } |
|
392 | 392 | |
393 | - if ( is_rtl() ) { |
|
394 | - $admin_body_class .= ' rtl'; |
|
395 | - } |
|
393 | + if ( is_rtl() ) { |
|
394 | + $admin_body_class .= ' rtl'; |
|
395 | + } |
|
396 | 396 | |
397 | - $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
398 | - $prepop = array(); |
|
399 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
397 | + $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
398 | + $prepop = array(); |
|
399 | + FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
400 | 400 | |
401 | - $field = FrmField::getOne($field_id); |
|
401 | + $field = FrmField::getOne($field_id); |
|
402 | 402 | |
403 | - wp_enqueue_script( 'utils' ); |
|
403 | + wp_enqueue_script( 'utils' ); |
|
404 | 404 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
405 | - FrmAppHelper::load_admin_wide_js(); |
|
405 | + FrmAppHelper::load_admin_wide_js(); |
|
406 | 406 | |
407 | 407 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' ); |
408 | - wp_die(); |
|
409 | - } |
|
408 | + wp_die(); |
|
409 | + } |
|
410 | 410 | |
411 | - public static function import_options() { |
|
411 | + public static function import_options() { |
|
412 | 412 | FrmAppHelper::permission_check('frm_edit_forms'); |
413 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
413 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
414 | 414 | |
415 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
416 | - return; |
|
417 | - } |
|
415 | + if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
416 | + return; |
|
417 | + } |
|
418 | 418 | |
419 | 419 | $field_id = absint( $_POST['field_id'] ); |
420 | - $field = FrmField::getOne($field_id); |
|
420 | + $field = FrmField::getOne($field_id); |
|
421 | 421 | |
422 | 422 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
423 | - return; |
|
424 | - } |
|
423 | + return; |
|
424 | + } |
|
425 | 425 | |
426 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
426 | + $field = FrmFieldsHelper::setup_edit_vars($field); |
|
427 | 427 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
428 | 428 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
429 | 429 | $opts = array_map( 'trim', $opts ); |
430 | 430 | |
431 | - if ( $field['separate_value'] ) { |
|
432 | - foreach ( $opts as $opt_key => $opt ) { |
|
433 | - if ( strpos($opt, '|') !== false ) { |
|
434 | - $vals = explode('|', $opt); |
|
435 | - if ( $vals[0] != $vals[1] ) { |
|
436 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
437 | - } |
|
438 | - unset($vals); |
|
439 | - } |
|
440 | - unset($opt_key, $opt); |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - //Keep other options after bulk update |
|
445 | - if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
446 | - $other_array = array(); |
|
447 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
448 | - if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
449 | - $other_array[ $opt_key ] = $opt; |
|
450 | - } |
|
451 | - unset($opt_key, $opt); |
|
452 | - } |
|
453 | - if ( ! empty($other_array) ) { |
|
454 | - $opts = array_merge( $opts, $other_array); |
|
455 | - } |
|
456 | - } |
|
457 | - |
|
458 | - FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) ); |
|
459 | - |
|
460 | - $field['options'] = $opts; |
|
461 | - $field_name = $field['name']; |
|
462 | - |
|
463 | - // Get html_id which will be used in single-option.php |
|
464 | - $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
465 | - |
|
466 | - if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
431 | + if ( $field['separate_value'] ) { |
|
432 | + foreach ( $opts as $opt_key => $opt ) { |
|
433 | + if ( strpos($opt, '|') !== false ) { |
|
434 | + $vals = explode('|', $opt); |
|
435 | + if ( $vals[0] != $vals[1] ) { |
|
436 | + $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
437 | + } |
|
438 | + unset($vals); |
|
439 | + } |
|
440 | + unset($opt_key, $opt); |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + //Keep other options after bulk update |
|
445 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
446 | + $other_array = array(); |
|
447 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
448 | + if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
449 | + $other_array[ $opt_key ] = $opt; |
|
450 | + } |
|
451 | + unset($opt_key, $opt); |
|
452 | + } |
|
453 | + if ( ! empty($other_array) ) { |
|
454 | + $opts = array_merge( $opts, $other_array); |
|
455 | + } |
|
456 | + } |
|
457 | + |
|
458 | + FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) ); |
|
459 | + |
|
460 | + $field['options'] = $opts; |
|
461 | + $field_name = $field['name']; |
|
462 | + |
|
463 | + // Get html_id which will be used in single-option.php |
|
464 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
465 | + |
|
466 | + if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
467 | 467 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
468 | - } else { |
|
469 | - FrmFieldsHelper::show_single_option($field); |
|
470 | - } |
|
468 | + } else { |
|
469 | + FrmFieldsHelper::show_single_option($field); |
|
470 | + } |
|
471 | 471 | |
472 | - wp_die(); |
|
473 | - } |
|
472 | + wp_die(); |
|
473 | + } |
|
474 | 474 | |
475 | - public static function update_order() { |
|
475 | + public static function update_order() { |
|
476 | 476 | FrmAppHelper::permission_check('frm_edit_forms'); |
477 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
477 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
478 | 478 | |
479 | 479 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
480 | 480 | foreach ( (array) $fields as $position => $item ) { |
481 | 481 | FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) ); |
482 | 482 | } |
483 | - wp_die(); |
|
484 | - } |
|
483 | + wp_die(); |
|
484 | + } |
|
485 | 485 | |
486 | 486 | public static function change_type( $type ) { |
487 | - $type_switch = array( |
|
488 | - 'scale' => 'radio', |
|
489 | - '10radio' => 'radio', |
|
490 | - 'rte' => 'textarea', |
|
491 | - 'website' => 'url', |
|
492 | - ); |
|
493 | - if ( isset( $type_switch[ $type ] ) ) { |
|
494 | - $type = $type_switch[ $type ]; |
|
495 | - } |
|
487 | + $type_switch = array( |
|
488 | + 'scale' => 'radio', |
|
489 | + '10radio' => 'radio', |
|
490 | + 'rte' => 'textarea', |
|
491 | + 'website' => 'url', |
|
492 | + ); |
|
493 | + if ( isset( $type_switch[ $type ] ) ) { |
|
494 | + $type = $type_switch[ $type ]; |
|
495 | + } |
|
496 | 496 | |
497 | 497 | $pro_fields = FrmField::pro_field_selection(); |
498 | 498 | $types = array_keys( $pro_fields ); |
@@ -500,137 +500,137 @@ discard block |
||
500 | 500 | $type = 'text'; |
501 | 501 | } |
502 | 502 | |
503 | - return $type; |
|
504 | - } |
|
503 | + return $type; |
|
504 | + } |
|
505 | 505 | |
506 | 506 | public static function display_field_options( $display ) { |
507 | 507 | switch ( $display['type'] ) { |
508 | - case 'captcha': |
|
509 | - $display['required'] = false; |
|
510 | - $display['invalid'] = true; |
|
511 | - $display['default_blank'] = false; |
|
508 | + case 'captcha': |
|
509 | + $display['required'] = false; |
|
510 | + $display['invalid'] = true; |
|
511 | + $display['default_blank'] = false; |
|
512 | 512 | $display['captcha_size'] = true; |
513 | - break; |
|
514 | - case 'radio': |
|
515 | - $display['default_blank'] = false; |
|
516 | - break; |
|
517 | - case 'text': |
|
518 | - case 'textarea': |
|
519 | - $display['size'] = true; |
|
520 | - $display['clear_on_focus'] = true; |
|
521 | - break; |
|
522 | - case 'select': |
|
523 | - $display['size'] = true; |
|
524 | - break; |
|
525 | - case 'url': |
|
526 | - case 'website': |
|
527 | - case 'email': |
|
528 | - $display['size'] = true; |
|
529 | - $display['clear_on_focus'] = true; |
|
530 | - $display['invalid'] = true; |
|
531 | - } |
|
532 | - |
|
533 | - return $display; |
|
534 | - } |
|
535 | - |
|
536 | - public static function input_html( $field, $echo = true ) { |
|
537 | - $class = array(); //$field['type']; |
|
538 | - self::add_input_classes($field, $class); |
|
539 | - |
|
540 | - $add_html = array(); |
|
541 | - self::add_html_size($field, $add_html); |
|
542 | - self::add_html_length($field, $add_html); |
|
543 | - self::add_html_placeholder($field, $add_html, $class); |
|
513 | + break; |
|
514 | + case 'radio': |
|
515 | + $display['default_blank'] = false; |
|
516 | + break; |
|
517 | + case 'text': |
|
518 | + case 'textarea': |
|
519 | + $display['size'] = true; |
|
520 | + $display['clear_on_focus'] = true; |
|
521 | + break; |
|
522 | + case 'select': |
|
523 | + $display['size'] = true; |
|
524 | + break; |
|
525 | + case 'url': |
|
526 | + case 'website': |
|
527 | + case 'email': |
|
528 | + $display['size'] = true; |
|
529 | + $display['clear_on_focus'] = true; |
|
530 | + $display['invalid'] = true; |
|
531 | + } |
|
532 | + |
|
533 | + return $display; |
|
534 | + } |
|
535 | + |
|
536 | + public static function input_html( $field, $echo = true ) { |
|
537 | + $class = array(); //$field['type']; |
|
538 | + self::add_input_classes($field, $class); |
|
539 | + |
|
540 | + $add_html = array(); |
|
541 | + self::add_html_size($field, $add_html); |
|
542 | + self::add_html_length($field, $add_html); |
|
543 | + self::add_html_placeholder($field, $add_html, $class); |
|
544 | 544 | self::add_validation_messages( $field, $add_html ); |
545 | 545 | |
546 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
546 | + $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
547 | 547 | |
548 | 548 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
549 | 549 | |
550 | - self::add_shortcodes_to_html($field, $add_html); |
|
550 | + self::add_shortcodes_to_html($field, $add_html); |
|
551 | 551 | |
552 | 552 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
553 | 553 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
554 | 554 | |
555 | - if ( $echo ) { |
|
556 | - echo $add_html; |
|
557 | - } |
|
555 | + if ( $echo ) { |
|
556 | + echo $add_html; |
|
557 | + } |
|
558 | 558 | |
559 | - return $add_html; |
|
560 | - } |
|
559 | + return $add_html; |
|
560 | + } |
|
561 | 561 | |
562 | 562 | private static function add_input_classes( $field, array &$class ) { |
563 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
564 | - $class[] = $field['input_class']; |
|
565 | - } |
|
563 | + if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
564 | + $class[] = $field['input_class']; |
|
565 | + } |
|
566 | 566 | |
567 | - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
568 | - return; |
|
569 | - } |
|
567 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
568 | + return; |
|
569 | + } |
|
570 | 570 | |
571 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
572 | - $class[] = 'auto_width'; |
|
573 | - } |
|
574 | - } |
|
571 | + if ( isset($field['size']) && $field['size'] > 0 ) { |
|
572 | + $class[] = 'auto_width'; |
|
573 | + } |
|
574 | + } |
|
575 | 575 | |
576 | 576 | private static function add_html_size( $field, array &$add_html ) { |
577 | 577 | if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'file', 'lookup' ) ) ) { |
578 | - return; |
|
579 | - } |
|
578 | + return; |
|
579 | + } |
|
580 | 580 | |
581 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
582 | - return; |
|
583 | - } |
|
581 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
582 | + return; |
|
583 | + } |
|
584 | 584 | |
585 | - if ( is_numeric($field['size']) ) { |
|
586 | - $field['size'] .= 'px'; |
|
587 | - } |
|
585 | + if ( is_numeric($field['size']) ) { |
|
586 | + $field['size'] .= 'px'; |
|
587 | + } |
|
588 | 588 | |
589 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
590 | - // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
589 | + $important = apply_filters('frm_use_important_width', 1, $field); |
|
590 | + // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
591 | 591 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
592 | 592 | |
593 | - self::add_html_cols($field, $add_html); |
|
594 | - } |
|
593 | + self::add_html_cols($field, $add_html); |
|
594 | + } |
|
595 | 595 | |
596 | 596 | private static function add_html_cols( $field, array &$add_html ) { |
597 | 597 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { |
598 | - return; |
|
599 | - } |
|
598 | + return; |
|
599 | + } |
|
600 | 600 | |
601 | - // convert to cols for textareas |
|
602 | - $calc = array( |
|
603 | - '' => 9, |
|
604 | - 'px' => 9, |
|
605 | - 'rem' => 0.444, |
|
606 | - 'em' => 0.544, |
|
607 | - ); |
|
601 | + // convert to cols for textareas |
|
602 | + $calc = array( |
|
603 | + '' => 9, |
|
604 | + 'px' => 9, |
|
605 | + 'rem' => 0.444, |
|
606 | + 'em' => 0.544, |
|
607 | + ); |
|
608 | 608 | |
609 | - // include "col" for valid html |
|
610 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
609 | + // include "col" for valid html |
|
610 | + $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
611 | 611 | |
612 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
613 | - return; |
|
614 | - } |
|
612 | + if ( ! isset( $calc[ $unit ] ) ) { |
|
613 | + return; |
|
614 | + } |
|
615 | 615 | |
616 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
616 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
617 | 617 | |
618 | 618 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
619 | - } |
|
619 | + } |
|
620 | 620 | |
621 | 621 | private static function add_html_length( $field, array &$add_html ) { |
622 | - // check for max setting and if this field accepts maxlength |
|
622 | + // check for max setting and if this field accepts maxlength |
|
623 | 623 | if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden', 'file' ) ) ) { |
624 | - return; |
|
625 | - } |
|
624 | + return; |
|
625 | + } |
|
626 | 626 | |
627 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
628 | - // don't load on form builder page |
|
629 | - return; |
|
630 | - } |
|
627 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
628 | + // don't load on form builder page |
|
629 | + return; |
|
630 | + } |
|
631 | 631 | |
632 | 632 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
633 | - } |
|
633 | + } |
|
634 | 634 | |
635 | 635 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
636 | 636 | if ( empty( $field['default_value'] ) || FrmAppHelper::is_admin_page( 'formidable' ) ) { |
@@ -638,35 +638,35 @@ discard block |
||
638 | 638 | } |
639 | 639 | |
640 | 640 | $default_value_array = is_array( $field['default_value'] ); |
641 | - if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
641 | + if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
642 | 642 | if ( $default_value_array ) { |
643 | 643 | $field['default_value'] = json_encode( $field['default_value'] ); |
644 | 644 | } |
645 | 645 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
646 | - return; |
|
647 | - } |
|
646 | + return; |
|
647 | + } |
|
648 | 648 | |
649 | 649 | if ( $default_value_array ) { |
650 | 650 | // don't include a json placeholder |
651 | 651 | return; |
652 | 652 | } |
653 | 653 | |
654 | - $frm_settings = FrmAppHelper::get_settings(); |
|
654 | + $frm_settings = FrmAppHelper::get_settings(); |
|
655 | 655 | |
656 | 656 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
657 | - // use HMTL5 placeholder with js fallback |
|
657 | + // use HMTL5 placeholder with js fallback |
|
658 | 658 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
659 | - wp_enqueue_script('jquery-placeholder'); |
|
660 | - } else if ( ! $frm_settings->use_html ) { |
|
659 | + wp_enqueue_script('jquery-placeholder'); |
|
660 | + } else if ( ! $frm_settings->use_html ) { |
|
661 | 661 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
662 | 662 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
663 | - $class[] = 'frm_toggle_default'; |
|
663 | + $class[] = 'frm_toggle_default'; |
|
664 | 664 | |
665 | - if ( $field['value'] == $field['default_value'] ) { |
|
666 | - $class[] = 'frm_default'; |
|
667 | - } |
|
668 | - } |
|
669 | - } |
|
665 | + if ( $field['value'] == $field['default_value'] ) { |
|
666 | + $class[] = 'frm_default'; |
|
667 | + } |
|
668 | + } |
|
669 | + } |
|
670 | 670 | |
671 | 671 | private static function add_validation_messages( $field, array &$add_html ) { |
672 | 672 | if ( FrmField::is_required( $field ) ) { |
@@ -680,44 +680,44 @@ discard block |
||
680 | 680 | } |
681 | 681 | } |
682 | 682 | |
683 | - private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
684 | - if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
685 | - return; |
|
686 | - } |
|
683 | + private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
684 | + if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
685 | + return; |
|
686 | + } |
|
687 | 687 | |
688 | - foreach ( $field['shortcodes'] as $k => $v ) { |
|
689 | - if ( 'opt' === $k ) { |
|
690 | - continue; |
|
691 | - } |
|
688 | + foreach ( $field['shortcodes'] as $k => $v ) { |
|
689 | + if ( 'opt' === $k ) { |
|
690 | + continue; |
|
691 | + } |
|
692 | 692 | |
693 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
694 | - $add_html[] = $v; |
|
695 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
693 | + if ( is_numeric($k) && strpos($v, '=') ) { |
|
694 | + $add_html[] = $v; |
|
695 | + } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
696 | 696 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
697 | - } else { |
|
697 | + } else { |
|
698 | 698 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
699 | - } |
|
700 | - |
|
701 | - unset($k, $v); |
|
702 | - } |
|
703 | - } |
|
704 | - |
|
705 | - public static function check_value( $opt, $opt_key, $field ) { |
|
706 | - if ( is_array( $opt ) ) { |
|
707 | - if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
708 | - $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
709 | - } else { |
|
710 | - $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
711 | - } |
|
712 | - } |
|
713 | - return $opt; |
|
714 | - } |
|
699 | + } |
|
700 | + |
|
701 | + unset($k, $v); |
|
702 | + } |
|
703 | + } |
|
704 | + |
|
705 | + public static function check_value( $opt, $opt_key, $field ) { |
|
706 | + if ( is_array( $opt ) ) { |
|
707 | + if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
708 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
709 | + } else { |
|
710 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
711 | + } |
|
712 | + } |
|
713 | + return $opt; |
|
714 | + } |
|
715 | 715 | |
716 | 716 | public static function check_label( $opt ) { |
717 | - if ( is_array($opt) ) { |
|
718 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
719 | - } |
|
717 | + if ( is_array($opt) ) { |
|
718 | + $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
719 | + } |
|
720 | 720 | |
721 | - return $opt; |
|
722 | - } |
|
721 | + return $opt; |
|
722 | + } |
|
723 | 723 | } |
@@ -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; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | wp_die(); |
178 | 178 | } |
179 | 179 | |
180 | - self::include_single_field($field_id, $values); |
|
180 | + self::include_single_field( $field_id, $values ); |
|
181 | 181 | |
182 | 182 | wp_die(); |
183 | 183 | } |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | * Load a single field in the form builder along with all needed variables |
187 | 187 | */ |
188 | 188 | public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
189 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
189 | + $field = FrmFieldsHelper::setup_edit_vars( FrmField::getOne( $field_id ) ); |
|
190 | 190 | $field_name = 'item_meta[' . $field_id . ']'; |
191 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
191 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
192 | 192 | $id = $form_id ? $form_id : $field['form_id']; |
193 | 193 | if ( $field['type'] == 'html' ) { |
194 | 194 | $field['stop_filter'] = true; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | public static function destroy() { |
203 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
203 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
204 | 204 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
205 | 205 | |
206 | 206 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | |
213 | 213 | //Add Single Option or Other Option |
214 | 214 | public static function add_option() { |
215 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
215 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
216 | 216 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
217 | 217 | |
218 | 218 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
219 | 219 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
220 | 220 | |
221 | 221 | //Get the field |
222 | - $field = FrmField::getOne($id); |
|
222 | + $field = FrmField::getOne( $id ); |
|
223 | 223 | |
224 | 224 | if ( ! empty( $field->options ) ) { |
225 | 225 | $keys = array_keys( $field->options ); |
@@ -242,13 +242,13 @@ discard block |
||
242 | 242 | $first_opt = reset( $field->options ); |
243 | 243 | $next_opt = count( $field->options ); |
244 | 244 | if ( $first_opt != '' ) { |
245 | - $next_opt++; |
|
245 | + $next_opt ++; |
|
246 | 246 | } |
247 | 247 | $opt = esc_html__( 'Option', 'formidable' ) . ' ' . $next_opt; |
248 | - unset($next_opt); |
|
248 | + unset( $next_opt ); |
|
249 | 249 | } |
250 | 250 | $field_val = $opt; |
251 | - $field->options[ $opt_key ] = $opt; |
|
251 | + $field->options[$opt_key] = $opt; |
|
252 | 252 | |
253 | 253 | //Update options in DB |
254 | 254 | FrmField::update( $id, array( 'options' => $field->options ) ); |
@@ -257,13 +257,13 @@ discard block |
||
257 | 257 | $field = array( |
258 | 258 | 'type' => $field_data->type, |
259 | 259 | 'id' => $id, |
260 | - 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0, |
|
260 | + 'separate_value' => isset( $field_data->field_options['separate_value'] ) ? $field_data->field_options['separate_value'] : 0, |
|
261 | 261 | 'form_id' => $field_data->form_id, |
262 | 262 | 'field_key' => $field_data->field_key, |
263 | 263 | ); |
264 | 264 | |
265 | 265 | $field_name = 'item_meta[' . $id . ']'; |
266 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
266 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
267 | 267 | $checked = ''; |
268 | 268 | |
269 | 269 | if ( 'other' == $opt_type ) { |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | public static function edit_option() { |
278 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
278 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
279 | 279 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
280 | 280 | |
281 | 281 | $element_id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
@@ -290,28 +290,28 @@ discard block |
||
290 | 290 | $new_label = $update_value; |
291 | 291 | } |
292 | 292 | |
293 | - $field = FrmField::getOne($id); |
|
293 | + $field = FrmField::getOne( $id ); |
|
294 | 294 | $separate_values = FrmField::is_option_true( $field, 'separate_value' ); |
295 | 295 | |
296 | - $this_opt_id = end($ids); |
|
297 | - $this_opt = (array) $field->options[ $this_opt_id ]; |
|
298 | - $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ); |
|
296 | + $this_opt_id = end( $ids ); |
|
297 | + $this_opt = (array) $field->options[$this_opt_id]; |
|
298 | + $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other' ) !== false ); |
|
299 | 299 | |
300 | - $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt); |
|
301 | - $value = isset($this_opt['value']) ? $this_opt['value'] : ''; |
|
300 | + $label = isset( $this_opt['label'] ) ? $this_opt['label'] : reset( $this_opt ); |
|
301 | + $value = isset( $this_opt['value'] ) ? $this_opt['value'] : ''; |
|
302 | 302 | |
303 | 303 | if ( ! isset( $new_label ) ) { |
304 | 304 | $new_label = $label; |
305 | 305 | } |
306 | 306 | |
307 | - if ( isset($new_value) || isset($value) ) { |
|
308 | - $update_value = isset($new_value) ? $new_value : $value; |
|
307 | + if ( isset( $new_value ) || isset( $value ) ) { |
|
308 | + $update_value = isset( $new_value ) ? $new_value : $value; |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | if ( $update_value != $new_label && $other_opt === false && $separate_values ) { |
312 | - $field->options[ $this_opt_id ] = array( 'value' => $update_value, 'label' => $new_label ); |
|
312 | + $field->options[$this_opt_id] = array( 'value' => $update_value, 'label' => $new_label ); |
|
313 | 313 | } else { |
314 | - $field->options[ $this_opt_id ] = $orig_update_value; |
|
314 | + $field->options[$this_opt_id] = $orig_update_value; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | FrmField::update( $field->id, array( 'options' => $field->options ) ); |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | } |
321 | 321 | |
322 | 322 | public static function delete_option() { |
323 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
323 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
324 | 324 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
325 | 325 | |
326 | 326 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'sanitize_title' ); |
330 | 330 | |
331 | 331 | $options = $field->options; |
332 | - unset( $options[ $opt_key ] ); |
|
332 | + unset( $options[$opt_key] ); |
|
333 | 333 | $response = array( 'other' => true ); |
334 | 334 | |
335 | 335 | //If the deleted option is an "other" option |
@@ -396,9 +396,9 @@ discard block |
||
396 | 396 | |
397 | 397 | $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
398 | 398 | $prepop = array(); |
399 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
399 | + FrmFieldsHelper::get_bulk_prefilled_opts( $prepop ); |
|
400 | 400 | |
401 | - $field = FrmField::getOne($field_id); |
|
401 | + $field = FrmField::getOne( $field_id ); |
|
402 | 402 | |
403 | 403 | wp_enqueue_script( 'utils' ); |
404 | 404 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
@@ -409,35 +409,35 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | public static function import_options() { |
412 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
412 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
413 | 413 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
414 | 414 | |
415 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
415 | + if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
|
416 | 416 | return; |
417 | 417 | } |
418 | 418 | |
419 | 419 | $field_id = absint( $_POST['field_id'] ); |
420 | - $field = FrmField::getOne($field_id); |
|
420 | + $field = FrmField::getOne( $field_id ); |
|
421 | 421 | |
422 | 422 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
423 | 423 | return; |
424 | 424 | } |
425 | 425 | |
426 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
426 | + $field = FrmFieldsHelper::setup_edit_vars( $field ); |
|
427 | 427 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
428 | 428 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
429 | 429 | $opts = array_map( 'trim', $opts ); |
430 | 430 | |
431 | 431 | if ( $field['separate_value'] ) { |
432 | 432 | foreach ( $opts as $opt_key => $opt ) { |
433 | - if ( strpos($opt, '|') !== false ) { |
|
434 | - $vals = explode('|', $opt); |
|
433 | + if ( strpos( $opt, '|' ) !== false ) { |
|
434 | + $vals = explode( '|', $opt ); |
|
435 | 435 | if ( $vals[0] != $vals[1] ) { |
436 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
436 | + $opts[$opt_key] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
437 | 437 | } |
438 | - unset($vals); |
|
438 | + unset( $vals ); |
|
439 | 439 | } |
440 | - unset($opt_key, $opt); |
|
440 | + unset( $opt_key, $opt ); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
@@ -446,12 +446,12 @@ discard block |
||
446 | 446 | $other_array = array(); |
447 | 447 | foreach ( $field['options'] as $opt_key => $opt ) { |
448 | 448 | if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
449 | - $other_array[ $opt_key ] = $opt; |
|
449 | + $other_array[$opt_key] = $opt; |
|
450 | 450 | } |
451 | - unset($opt_key, $opt); |
|
451 | + unset( $opt_key, $opt ); |
|
452 | 452 | } |
453 | - if ( ! empty($other_array) ) { |
|
454 | - $opts = array_merge( $opts, $other_array); |
|
453 | + if ( ! empty( $other_array ) ) { |
|
454 | + $opts = array_merge( $opts, $other_array ); |
|
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
@@ -466,14 +466,14 @@ discard block |
||
466 | 466 | if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
467 | 467 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
468 | 468 | } else { |
469 | - FrmFieldsHelper::show_single_option($field); |
|
469 | + FrmFieldsHelper::show_single_option( $field ); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | wp_die(); |
473 | 473 | } |
474 | 474 | |
475 | 475 | public static function update_order() { |
476 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
476 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
477 | 477 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
478 | 478 | |
479 | 479 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
@@ -490,8 +490,8 @@ discard block |
||
490 | 490 | 'rte' => 'textarea', |
491 | 491 | 'website' => 'url', |
492 | 492 | ); |
493 | - if ( isset( $type_switch[ $type ] ) ) { |
|
494 | - $type = $type_switch[ $type ]; |
|
493 | + if ( isset( $type_switch[$type] ) ) { |
|
494 | + $type = $type_switch[$type]; |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | $pro_fields = FrmField::pro_field_selection(); |
@@ -535,19 +535,19 @@ discard block |
||
535 | 535 | |
536 | 536 | public static function input_html( $field, $echo = true ) { |
537 | 537 | $class = array(); //$field['type']; |
538 | - self::add_input_classes($field, $class); |
|
538 | + self::add_input_classes( $field, $class ); |
|
539 | 539 | |
540 | 540 | $add_html = array(); |
541 | - self::add_html_size($field, $add_html); |
|
542 | - self::add_html_length($field, $add_html); |
|
543 | - self::add_html_placeholder($field, $add_html, $class); |
|
541 | + self::add_html_size( $field, $add_html ); |
|
542 | + self::add_html_length( $field, $add_html ); |
|
543 | + self::add_html_placeholder( $field, $add_html, $class ); |
|
544 | 544 | self::add_validation_messages( $field, $add_html ); |
545 | 545 | |
546 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
546 | + $class = apply_filters( 'frm_field_classes', implode( ' ', $class ), $field ); |
|
547 | 547 | |
548 | 548 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
549 | 549 | |
550 | - self::add_shortcodes_to_html($field, $add_html); |
|
550 | + self::add_shortcodes_to_html( $field, $add_html ); |
|
551 | 551 | |
552 | 552 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
553 | 553 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | } |
561 | 561 | |
562 | 562 | private static function add_input_classes( $field, array &$class ) { |
563 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
563 | + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) { |
|
564 | 564 | $class[] = $field['input_class']; |
565 | 565 | } |
566 | 566 | |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | return; |
569 | 569 | } |
570 | 570 | |
571 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
571 | + if ( isset( $field['size'] ) && $field['size'] > 0 ) { |
|
572 | 572 | $class[] = 'auto_width'; |
573 | 573 | } |
574 | 574 | } |
@@ -578,19 +578,19 @@ discard block |
||
578 | 578 | return; |
579 | 579 | } |
580 | 580 | |
581 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
581 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
582 | 582 | return; |
583 | 583 | } |
584 | 584 | |
585 | - if ( is_numeric($field['size']) ) { |
|
585 | + if ( is_numeric( $field['size'] ) ) { |
|
586 | 586 | $field['size'] .= 'px'; |
587 | 587 | } |
588 | 588 | |
589 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
589 | + $important = apply_filters( 'frm_use_important_width', 1, $field ); |
|
590 | 590 | // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
591 | 591 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
592 | 592 | |
593 | - self::add_html_cols($field, $add_html); |
|
593 | + self::add_html_cols( $field, $add_html ); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | private static function add_html_cols( $field, array &$add_html ) { |
@@ -607,13 +607,13 @@ discard block |
||
607 | 607 | ); |
608 | 608 | |
609 | 609 | // include "col" for valid html |
610 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
610 | + $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
|
611 | 611 | |
612 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
612 | + if ( ! isset( $calc[$unit] ) ) { |
|
613 | 613 | return; |
614 | 614 | } |
615 | 615 | |
616 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
616 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[$unit]; |
|
617 | 617 | |
618 | 618 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
619 | 619 | } |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | return; |
625 | 625 | } |
626 | 626 | |
627 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
627 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
628 | 628 | // don't load on form builder page |
629 | 629 | return; |
630 | 630 | } |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
657 | 657 | // use HMTL5 placeholder with js fallback |
658 | 658 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
659 | - wp_enqueue_script('jquery-placeholder'); |
|
659 | + wp_enqueue_script( 'jquery-placeholder' ); |
|
660 | 660 | } else if ( ! $frm_settings->use_html ) { |
661 | 661 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
662 | 662 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
@@ -690,15 +690,15 @@ discard block |
||
690 | 690 | continue; |
691 | 691 | } |
692 | 692 | |
693 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
693 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { |
|
694 | 694 | $add_html[] = $v; |
695 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
696 | - $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
|
695 | + } else if ( ! empty( $k ) && isset( $add_html[$k] ) ) { |
|
696 | + $add_html[$k] = str_replace( $k . '="', $k . '="' . $v, $add_html[$k] ); |
|
697 | 697 | } else { |
698 | - $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
|
698 | + $add_html[$k] = $k . '="' . esc_attr( $v ) . '"'; |
|
699 | 699 | } |
700 | 700 | |
701 | - unset($k, $v); |
|
701 | + unset( $k, $v ); |
|
702 | 702 | } |
703 | 703 | } |
704 | 704 | |
@@ -714,8 +714,8 @@ discard block |
||
714 | 714 | } |
715 | 715 | |
716 | 716 | public static function check_label( $opt ) { |
717 | - if ( is_array($opt) ) { |
|
718 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
717 | + if ( is_array( $opt ) ) { |
|
718 | + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | return $opt; |
@@ -2,201 +2,201 @@ 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( 'https://formidableforms.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( 'https://formidableforms.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, $wpdb; |
|
68 | + global $frm_vars, $wpdb; |
|
69 | 69 | $form_id = FrmForm::get_current_form_id(); |
70 | 70 | |
71 | 71 | $columns[ $form_id . '_id' ] = 'ID'; |
72 | 72 | $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' ); |
73 | 73 | |
74 | - if ( ! $form_id ) { |
|
75 | - return $columns; |
|
76 | - } |
|
74 | + if ( ! $form_id ) { |
|
75 | + return $columns; |
|
76 | + } |
|
77 | 77 | |
78 | - $form_cols = FrmField::get_all_for_form($form_id, '', 'include'); |
|
78 | + $form_cols = FrmField::get_all_for_form($form_id, '', 'include'); |
|
79 | 79 | |
80 | - foreach ( $form_cols as $form_col ) { |
|
80 | + foreach ( $form_cols as $form_col ) { |
|
81 | 81 | if ( FrmField::is_no_save_field( $form_col->type ) ) { |
82 | - continue; |
|
83 | - } |
|
82 | + continue; |
|
83 | + } |
|
84 | 84 | |
85 | - if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) { |
|
85 | + if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) { |
|
86 | 86 | $sub_form_cols = FrmField::get_all_for_form( $form_col->field_options['form_select'] ); |
87 | 87 | |
88 | - if ( $sub_form_cols ) { |
|
89 | - foreach ( $sub_form_cols as $k => $sub_form_col ) { |
|
88 | + if ( $sub_form_cols ) { |
|
89 | + foreach ( $sub_form_cols as $k => $sub_form_col ) { |
|
90 | 90 | if ( FrmField::is_no_save_field( $sub_form_col->type ) ) { |
91 | - unset( $sub_form_cols[ $k ] ); |
|
92 | - continue; |
|
93 | - } |
|
91 | + unset( $sub_form_cols[ $k ] ); |
|
92 | + continue; |
|
93 | + } |
|
94 | 94 | $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
95 | - unset($sub_form_col); |
|
96 | - } |
|
97 | - } |
|
98 | - unset($sub_form_cols); |
|
99 | - } else { |
|
100 | - $col_id = $form_col->field_key; |
|
101 | - if ( $form_col->form_id != $form_id ) { |
|
95 | + unset($sub_form_col); |
|
96 | + } |
|
97 | + } |
|
98 | + unset($sub_form_cols); |
|
99 | + } else { |
|
100 | + $col_id = $form_col->field_key; |
|
101 | + if ( $form_col->form_id != $form_id ) { |
|
102 | 102 | $col_id .= '-_-form' . $form_col->form_id; |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | - if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) { |
|
105 | + if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) { |
|
106 | 106 | $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
107 | - } |
|
107 | + } |
|
108 | 108 | $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
109 | - } |
|
110 | - } |
|
109 | + } |
|
110 | + } |
|
111 | 111 | |
112 | 112 | $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' ); |
113 | 113 | $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' ); |
114 | 114 | $columns[ $form_id . '_ip' ] = 'IP'; |
115 | 115 | |
116 | - $frm_vars['cols'] = $columns; |
|
116 | + $frm_vars['cols'] = $columns; |
|
117 | 117 | |
118 | 118 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
119 | 119 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) { |
120 | 120 | add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) ); |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - return $columns; |
|
124 | - } |
|
123 | + return $columns; |
|
124 | + } |
|
125 | 125 | |
126 | 126 | public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) { |
127 | 127 | $menu_name = FrmAppHelper::get_menu_name(); |
128 | 128 | $this_page_name = 'manage' . sanitize_title( $menu_name ) . '_page_formidable-entriescolumnshidden'; |
129 | 129 | if ( $meta_key != $this_page_name || $meta_value == $prev_value ) { |
130 | - return $check; |
|
131 | - } |
|
130 | + return $check; |
|
131 | + } |
|
132 | 132 | |
133 | 133 | if ( empty( $prev_value ) ) { |
134 | 134 | $prev_value = get_metadata( 'user', $object_id, $meta_key, true ); |
135 | 135 | } |
136 | 136 | |
137 | - global $frm_vars; |
|
138 | - //add a check so we don't create a loop |
|
139 | - $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
137 | + global $frm_vars; |
|
138 | + //add a check so we don't create a loop |
|
139 | + $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
140 | 140 | |
141 | - return $check; |
|
142 | - } |
|
141 | + return $check; |
|
142 | + } |
|
143 | 143 | |
144 | - //add hidden columns back from other forms |
|
144 | + //add hidden columns back from other forms |
|
145 | 145 | public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { |
146 | 146 | $menu_name = FrmAppHelper::get_menu_name(); |
147 | 147 | $sanitized = sanitize_title( $menu_name ); |
148 | 148 | $this_page_name = 'manage' . $sanitized . '_page_formidable-entriescolumnshidden'; |
149 | 149 | if ( $meta_key != $this_page_name ) { |
150 | - return; |
|
151 | - } |
|
152 | - |
|
153 | - global $frm_vars; |
|
154 | - if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
155 | - return; //don't continue if there's no previous value |
|
156 | - } |
|
157 | - |
|
158 | - foreach ( $meta_value as $mk => $mv ) { |
|
159 | - //remove blank values |
|
160 | - if ( empty( $mv ) ) { |
|
161 | - unset( $meta_value[ $mk ] ); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - $cur_form_prefix = reset($meta_value); |
|
166 | - $cur_form_prefix = explode('_', $cur_form_prefix); |
|
167 | - $cur_form_prefix = $cur_form_prefix[0]; |
|
168 | - $save = false; |
|
169 | - |
|
170 | - foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { |
|
150 | + return; |
|
151 | + } |
|
152 | + |
|
153 | + global $frm_vars; |
|
154 | + if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
155 | + return; //don't continue if there's no previous value |
|
156 | + } |
|
157 | + |
|
158 | + foreach ( $meta_value as $mk => $mv ) { |
|
159 | + //remove blank values |
|
160 | + if ( empty( $mv ) ) { |
|
161 | + unset( $meta_value[ $mk ] ); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + $cur_form_prefix = reset($meta_value); |
|
166 | + $cur_form_prefix = explode('_', $cur_form_prefix); |
|
167 | + $cur_form_prefix = $cur_form_prefix[0]; |
|
168 | + $save = false; |
|
169 | + |
|
170 | + foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { |
|
171 | 171 | if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) { |
172 | - //don't add blank cols or process included cols |
|
173 | - continue; |
|
174 | - } |
|
172 | + //don't add blank cols or process included cols |
|
173 | + continue; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | $form_prefix = explode( '_', $prev_hidden ); |
177 | - $form_prefix = $form_prefix[0]; |
|
178 | - if ( $form_prefix == $cur_form_prefix ) { |
|
179 | - //don't add back columns that are meant to be hidden |
|
180 | - continue; |
|
181 | - } |
|
177 | + $form_prefix = $form_prefix[0]; |
|
178 | + if ( $form_prefix == $cur_form_prefix ) { |
|
179 | + //don't add back columns that are meant to be hidden |
|
180 | + continue; |
|
181 | + } |
|
182 | 182 | |
183 | - $meta_value[] = $prev_hidden; |
|
184 | - $save = true; |
|
185 | - unset($form_prefix); |
|
186 | - } |
|
183 | + $meta_value[] = $prev_hidden; |
|
184 | + $save = true; |
|
185 | + unset($form_prefix); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | if ( $save ) { |
189 | - $user = wp_get_current_user(); |
|
189 | + $user = wp_get_current_user(); |
|
190 | 190 | update_user_option( $user->ID, $this_page_name, $meta_value, true ); |
191 | - } |
|
192 | - } |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | 194 | public static function save_per_page( $save, $option, $value ) { |
195 | - if ( $option == 'formidable_page_formidable_entries_per_page' ) { |
|
196 | - $save = (int) $value; |
|
197 | - } |
|
198 | - return $save; |
|
199 | - } |
|
195 | + if ( $option == 'formidable_page_formidable_entries_per_page' ) { |
|
196 | + $save = (int) $value; |
|
197 | + } |
|
198 | + return $save; |
|
199 | + } |
|
200 | 200 | |
201 | 201 | public static function sortable_columns() { |
202 | 202 | $form_id = FrmForm::get_current_form_id(); |
@@ -222,122 +222,122 @@ discard block |
||
222 | 222 | } |
223 | 223 | |
224 | 224 | public static function hidden_columns( $result ) { |
225 | - global $frm_vars; |
|
225 | + global $frm_vars; |
|
226 | 226 | |
227 | 227 | $form_id = FrmForm::get_current_form_id(); |
228 | 228 | |
229 | - $return = false; |
|
230 | - foreach ( (array) $result as $r ) { |
|
231 | - if ( ! empty( $r ) ) { |
|
232 | - $form_prefix = explode( '_', $r ); |
|
233 | - $form_prefix = $form_prefix[0]; |
|
229 | + $return = false; |
|
230 | + foreach ( (array) $result as $r ) { |
|
231 | + if ( ! empty( $r ) ) { |
|
232 | + $form_prefix = explode( '_', $r ); |
|
233 | + $form_prefix = $form_prefix[0]; |
|
234 | 234 | |
235 | - if ( (int) $form_prefix == (int) $form_id ) { |
|
236 | - $return = true; |
|
237 | - break; |
|
238 | - } |
|
235 | + if ( (int) $form_prefix == (int) $form_id ) { |
|
236 | + $return = true; |
|
237 | + break; |
|
238 | + } |
|
239 | 239 | |
240 | - unset($form_prefix); |
|
241 | - } |
|
242 | - } |
|
240 | + unset($form_prefix); |
|
241 | + } |
|
242 | + } |
|
243 | 243 | |
244 | - if ( $return ) { |
|
244 | + if ( $return ) { |
|
245 | 245 | return $result; |
246 | 246 | } |
247 | 247 | |
248 | - $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
249 | - $max_columns = 8; |
|
250 | - if ( $i <= $max_columns ) { |
|
248 | + $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
249 | + $max_columns = 8; |
|
250 | + if ( $i <= $max_columns ) { |
|
251 | 251 | return $result; |
252 | 252 | } |
253 | 253 | |
254 | - global $frm_vars; |
|
255 | - if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
256 | - $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
257 | - } |
|
254 | + global $frm_vars; |
|
255 | + if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
256 | + $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
257 | + } |
|
258 | 258 | |
259 | - if ( 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']) ) { |
|
260 | - $result = $frm_vars['current_form']->options['hidden_cols']; |
|
261 | - } else { |
|
262 | - $cols = $frm_vars['cols']; |
|
263 | - $cols = array_reverse($cols, true); |
|
259 | + if ( 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']) ) { |
|
260 | + $result = $frm_vars['current_form']->options['hidden_cols']; |
|
261 | + } else { |
|
262 | + $cols = $frm_vars['cols']; |
|
263 | + $cols = array_reverse($cols, true); |
|
264 | 264 | |
265 | 265 | $result[] = $form_id . '_id'; |
266 | - $i--; |
|
266 | + $i--; |
|
267 | 267 | |
268 | 268 | $result[] = $form_id . '_item_key'; |
269 | - $i--; |
|
269 | + $i--; |
|
270 | 270 | |
271 | 271 | foreach ( $cols as $col_key => $col ) { |
272 | - if ( $i > $max_columns ) { |
|
272 | + if ( $i > $max_columns ) { |
|
273 | 273 | $result[] = $col_key; |
274 | 274 | } |
275 | - //remove some columns by default |
|
276 | - $i--; |
|
277 | - unset($col_key, $col); |
|
278 | - } |
|
279 | - } |
|
275 | + //remove some columns by default |
|
276 | + $i--; |
|
277 | + unset($col_key, $col); |
|
278 | + } |
|
279 | + } |
|
280 | 280 | |
281 | - return $result; |
|
282 | - } |
|
281 | + return $result; |
|
282 | + } |
|
283 | 283 | |
284 | 284 | public static function display_list( $message = '', $errors = array() ) { |
285 | - global $wpdb, $frm_vars; |
|
285 | + global $wpdb, $frm_vars; |
|
286 | 286 | |
287 | 287 | $form = FrmForm::get_current_form(); |
288 | 288 | $params = FrmForm::get_admin_params( $form ); |
289 | 289 | |
290 | - if ( $form ) { |
|
291 | - $params['form'] = $form->id; |
|
292 | - $frm_vars['current_form'] = $form; |
|
290 | + if ( $form ) { |
|
291 | + $params['form'] = $form->id; |
|
292 | + $frm_vars['current_form'] = $form; |
|
293 | 293 | |
294 | - if ( 'trash' == $form->status ) { |
|
295 | - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
|
296 | - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) ); |
|
297 | - $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete ); |
|
298 | - unset( $time_to_delete, $delete_timestamp ); |
|
299 | - } |
|
294 | + if ( 'trash' == $form->status ) { |
|
295 | + $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
|
296 | + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) ); |
|
297 | + $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete ); |
|
298 | + unset( $time_to_delete, $delete_timestamp ); |
|
299 | + } |
|
300 | 300 | } |
301 | 301 | |
302 | - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); |
|
302 | + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); |
|
303 | 303 | |
304 | - $wp_list_table = new $table_class( array( 'params' => $params ) ); |
|
304 | + $wp_list_table = new $table_class( array( 'params' => $params ) ); |
|
305 | 305 | |
306 | - $pagenum = $wp_list_table->get_pagenum(); |
|
306 | + $pagenum = $wp_list_table->get_pagenum(); |
|
307 | 307 | |
308 | - $wp_list_table->prepare_items(); |
|
308 | + $wp_list_table->prepare_items(); |
|
309 | 309 | |
310 | - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
311 | - if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
310 | + $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
311 | + if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
312 | 312 | $url = add_query_arg( 'paged', $total_pages ); |
313 | - if ( headers_sent() ) { |
|
314 | - echo FrmAppHelper::js_redirect($url); |
|
315 | - } else { |
|
316 | - wp_redirect( esc_url_raw( $url ) ); |
|
317 | - } |
|
318 | - die(); |
|
319 | - } |
|
320 | - |
|
321 | - if ( empty($message) && isset($_GET['import-message']) ) { |
|
322 | - $message = __( 'Your import is complete', 'formidable' ); |
|
323 | - } |
|
313 | + if ( headers_sent() ) { |
|
314 | + echo FrmAppHelper::js_redirect($url); |
|
315 | + } else { |
|
316 | + wp_redirect( esc_url_raw( $url ) ); |
|
317 | + } |
|
318 | + die(); |
|
319 | + } |
|
320 | + |
|
321 | + if ( empty($message) && isset($_GET['import-message']) ) { |
|
322 | + $message = __( 'Your import is complete', 'formidable' ); |
|
323 | + } |
|
324 | 324 | |
325 | 325 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' ); |
326 | - } |
|
326 | + } |
|
327 | 327 | |
328 | - /* Back End CRUD */ |
|
328 | + /* Back End CRUD */ |
|
329 | 329 | public static function show( $id = 0 ) { |
330 | - FrmAppHelper::permission_check('frm_view_entries'); |
|
330 | + FrmAppHelper::permission_check('frm_view_entries'); |
|
331 | 331 | |
332 | - if ( ! $id ) { |
|
332 | + if ( ! $id ) { |
|
333 | 333 | $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
334 | 334 | |
335 | - if ( ! $id ) { |
|
335 | + if ( ! $id ) { |
|
336 | 336 | $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' ); |
337 | - } |
|
338 | - } |
|
337 | + } |
|
338 | + } |
|
339 | 339 | |
340 | - $entry = FrmEntry::getOne($id, true); |
|
340 | + $entry = FrmEntry::getOne($id, true); |
|
341 | 341 | if ( ! $entry ) { |
342 | 342 | echo '<div id="form_show_entry_page" class="wrap">' . |
343 | 343 | __( 'You are trying to view an entry that does not exist.', 'formidable' ) . |
@@ -345,110 +345,110 @@ discard block |
||
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - $data = maybe_unserialize($entry->description); |
|
348 | + $data = maybe_unserialize($entry->description); |
|
349 | 349 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
350 | 350 | $data = array( 'referrer' => $data ); |
351 | 351 | } |
352 | 352 | |
353 | 353 | $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' ); |
354 | - $to_emails = array(); |
|
354 | + $to_emails = array(); |
|
355 | 355 | |
356 | 356 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' ); |
357 | - } |
|
357 | + } |
|
358 | 358 | |
359 | - public static function destroy() { |
|
360 | - FrmAppHelper::permission_check('frm_delete_entries'); |
|
359 | + public static function destroy() { |
|
360 | + FrmAppHelper::permission_check('frm_delete_entries'); |
|
361 | 361 | |
362 | 362 | $params = FrmForm::get_admin_params(); |
363 | 363 | |
364 | - if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
365 | - //unlink entry from post |
|
366 | - global $wpdb; |
|
364 | + if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
365 | + //unlink entry from post |
|
366 | + global $wpdb; |
|
367 | 367 | $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) ); |
368 | - } |
|
368 | + } |
|
369 | 369 | |
370 | - $message = ''; |
|
371 | - if ( FrmEntry::destroy( $params['id'] ) ) { |
|
372 | - $message = __( 'Entry was Successfully Destroyed', 'formidable' ); |
|
373 | - } |
|
370 | + $message = ''; |
|
371 | + if ( FrmEntry::destroy( $params['id'] ) ) { |
|
372 | + $message = __( 'Entry was Successfully Destroyed', 'formidable' ); |
|
373 | + } |
|
374 | 374 | |
375 | - self::display_list( $message ); |
|
376 | - } |
|
375 | + self::display_list( $message ); |
|
376 | + } |
|
377 | 377 | |
378 | - public static function destroy_all() { |
|
379 | - if ( ! current_user_can( 'frm_delete_entries' ) ) { |
|
380 | - $frm_settings = FrmAppHelper::get_settings(); |
|
381 | - wp_die( $frm_settings->admin_permission ); |
|
382 | - } |
|
378 | + public static function destroy_all() { |
|
379 | + if ( ! current_user_can( 'frm_delete_entries' ) ) { |
|
380 | + $frm_settings = FrmAppHelper::get_settings(); |
|
381 | + wp_die( $frm_settings->admin_permission ); |
|
382 | + } |
|
383 | 383 | |
384 | - global $wpdb; |
|
384 | + global $wpdb; |
|
385 | 385 | $params = FrmForm::get_admin_params(); |
386 | - $message = ''; |
|
387 | - $errors = array(); |
|
388 | - $form_id = (int) $params['form']; |
|
386 | + $message = ''; |
|
387 | + $errors = array(); |
|
388 | + $form_id = (int) $params['form']; |
|
389 | 389 | |
390 | - if ( $form_id ) { |
|
391 | - $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) ); |
|
390 | + if ( $form_id ) { |
|
391 | + $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) ); |
|
392 | 392 | $action = FrmFormAction::get_action_for_form( $form_id, 'wppost', 1 ); |
393 | 393 | |
394 | - if ( $action ) { |
|
395 | - // this action takes a while, so only trigger it if there are posts to delete |
|
396 | - foreach ( $entry_ids as $entry_id ) { |
|
397 | - do_action( 'frm_before_destroy_entry', $entry_id ); |
|
398 | - unset( $entry_id ); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - $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 ) ); |
|
403 | - $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) ); |
|
404 | - if ( $results ) { |
|
394 | + if ( $action ) { |
|
395 | + // this action takes a while, so only trigger it if there are posts to delete |
|
396 | + foreach ( $entry_ids as $entry_id ) { |
|
397 | + do_action( 'frm_before_destroy_entry', $entry_id ); |
|
398 | + unset( $entry_id ); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + $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 ) ); |
|
403 | + $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) ); |
|
404 | + if ( $results ) { |
|
405 | 405 | FrmEntry::clear_cache(); |
406 | - $message = __( 'Entries were Successfully Destroyed', 'formidable' ); |
|
407 | - } |
|
408 | - } else { |
|
409 | - $errors = __( 'No entries were specified', 'formidable' ); |
|
410 | - } |
|
411 | - |
|
412 | - self::display_list( $message, $errors ); |
|
413 | - } |
|
414 | - |
|
415 | - public static function show_form( $id = '', $key = '', $title = false, $description = false ) { |
|
416 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' ); |
|
417 | - return FrmFormsController::show_form( $id, $key, $title, $description ); |
|
418 | - } |
|
419 | - |
|
420 | - public static function get_form( $filename, $form, $title, $description ) { |
|
421 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' ); |
|
422 | - return FrmFormsController::get_form( $form, $title, $description ); |
|
423 | - } |
|
424 | - |
|
425 | - public static function process_entry( $errors = '', $ajax = false ) { |
|
406 | + $message = __( 'Entries were Successfully Destroyed', 'formidable' ); |
|
407 | + } |
|
408 | + } else { |
|
409 | + $errors = __( 'No entries were specified', 'formidable' ); |
|
410 | + } |
|
411 | + |
|
412 | + self::display_list( $message, $errors ); |
|
413 | + } |
|
414 | + |
|
415 | + public static function show_form( $id = '', $key = '', $title = false, $description = false ) { |
|
416 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' ); |
|
417 | + return FrmFormsController::show_form( $id, $key, $title, $description ); |
|
418 | + } |
|
419 | + |
|
420 | + public static function get_form( $filename, $form, $title, $description ) { |
|
421 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' ); |
|
422 | + return FrmFormsController::get_form( $form, $title, $description ); |
|
423 | + } |
|
424 | + |
|
425 | + public static function process_entry( $errors = '', $ajax = false ) { |
|
426 | 426 | $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); |
427 | 427 | if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { |
428 | - return; |
|
429 | - } |
|
428 | + return; |
|
429 | + } |
|
430 | 430 | |
431 | - global $frm_vars; |
|
431 | + global $frm_vars; |
|
432 | 432 | |
433 | 433 | $form = FrmForm::getOne( $form_id ); |
434 | - if ( ! $form ) { |
|
435 | - return; |
|
436 | - } |
|
434 | + if ( ! $form ) { |
|
435 | + return; |
|
436 | + } |
|
437 | 437 | |
438 | 438 | $params = FrmForm::get_params( $form ); |
439 | 439 | |
440 | - if ( ! isset( $frm_vars['form_params'] ) ) { |
|
441 | - $frm_vars['form_params'] = array(); |
|
442 | - } |
|
440 | + if ( ! isset( $frm_vars['form_params'] ) ) { |
|
441 | + $frm_vars['form_params'] = array(); |
|
442 | + } |
|
443 | 443 | $frm_vars['form_params'][ $form->id ] = $params; |
444 | 444 | |
445 | 445 | if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { |
446 | - return; |
|
447 | - } |
|
446 | + return; |
|
447 | + } |
|
448 | 448 | |
449 | - if ( $errors == '' && ! $ajax ) { |
|
449 | + if ( $errors == '' && ! $ajax ) { |
|
450 | 450 | $errors = FrmEntryValidate::validate( $_POST ); |
451 | - } |
|
451 | + } |
|
452 | 452 | |
453 | 453 | /** |
454 | 454 | * Use this filter to add trigger actions and add errors after |
@@ -459,54 +459,54 @@ discard block |
||
459 | 459 | |
460 | 460 | $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); |
461 | 461 | |
462 | - if ( empty( $errors ) ) { |
|
462 | + if ( empty( $errors ) ) { |
|
463 | 463 | $_POST['frm_skip_cookie'] = 1; |
464 | - if ( $params['action'] == 'create' ) { |
|
464 | + if ( $params['action'] == 'create' ) { |
|
465 | 465 | if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
466 | 466 | $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); |
467 | - } |
|
468 | - } |
|
467 | + } |
|
468 | + } |
|
469 | 469 | |
470 | - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
|
470 | + do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
|
471 | 471 | unset( $_POST['frm_skip_cookie'] ); |
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - public static function delete_entry_before_redirect( $url, $form, $atts ) { |
|
476 | - self::_delete_entry( $atts['id'], $form ); |
|
477 | - return $url; |
|
478 | - } |
|
479 | - |
|
480 | - //Delete entry if not redirected |
|
481 | - public static function delete_entry_after_save( $atts ) { |
|
482 | - self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
|
483 | - } |
|
484 | - |
|
485 | - private static function _delete_entry( $entry_id, $form ) { |
|
486 | - if ( ! $form ) { |
|
487 | - return; |
|
488 | - } |
|
489 | - |
|
490 | - $form->options = maybe_unserialize( $form->options ); |
|
491 | - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
|
492 | - FrmEntry::destroy( $entry_id ); |
|
493 | - } |
|
494 | - } |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + public static function delete_entry_before_redirect( $url, $form, $atts ) { |
|
476 | + self::_delete_entry( $atts['id'], $form ); |
|
477 | + return $url; |
|
478 | + } |
|
479 | + |
|
480 | + //Delete entry if not redirected |
|
481 | + public static function delete_entry_after_save( $atts ) { |
|
482 | + self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
|
483 | + } |
|
484 | + |
|
485 | + private static function _delete_entry( $entry_id, $form ) { |
|
486 | + if ( ! $form ) { |
|
487 | + return; |
|
488 | + } |
|
489 | + |
|
490 | + $form->options = maybe_unserialize( $form->options ); |
|
491 | + if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
|
492 | + FrmEntry::destroy( $entry_id ); |
|
493 | + } |
|
494 | + } |
|
495 | 495 | |
496 | 496 | public static function show_entry_shortcode( $atts ) { |
497 | 497 | return FrmEntryFormat::show_entry( $atts ); |
498 | 498 | } |
499 | 499 | |
500 | 500 | public static function filter_shortcode_value( $value, $tag, $atts, $field ) { |
501 | - $plain_text = add_filter('frm_plain_text_email', true); |
|
501 | + $plain_text = add_filter('frm_plain_text_email', true); |
|
502 | 502 | FrmEntryFormat::textarea_display_value( $field->type, $plain_text, $value ); |
503 | 503 | |
504 | - if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
505 | - return $value; |
|
506 | - } |
|
504 | + if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
505 | + return $value; |
|
506 | + } |
|
507 | 507 | |
508 | - return $value; |
|
509 | - } |
|
508 | + return $value; |
|
509 | + } |
|
510 | 510 | |
511 | 511 | public static function get_params( $form = null ) { |
512 | 512 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_params' ); |
@@ -514,15 +514,15 @@ discard block |
||
514 | 514 | } |
515 | 515 | |
516 | 516 | public static function entry_sidebar( $entry ) { |
517 | - $data = maybe_unserialize($entry->description); |
|
518 | - $date_format = get_option('date_format'); |
|
519 | - $time_format = get_option('time_format'); |
|
517 | + $data = maybe_unserialize($entry->description); |
|
518 | + $date_format = get_option('date_format'); |
|
519 | + $time_format = get_option('time_format'); |
|
520 | 520 | if ( isset( $data['browser'] ) ) { |
521 | 521 | $browser = FrmEntryFormat::get_browser( $data['browser'] ); |
522 | 522 | } |
523 | 523 | |
524 | 524 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' ); |
525 | - } |
|
525 | + } |
|
526 | 526 | |
527 | 527 | /*********************************************************************** |
528 | 528 | * Deprecated Functions |
@@ -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,14 +68,14 @@ discard block |
||
68 | 68 | global $frm_vars, $wpdb; |
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 | return $columns; |
76 | 76 | } |
77 | 77 | |
78 | - $form_cols = FrmField::get_all_for_form($form_id, '', 'include'); |
|
78 | + $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' ); |
|
79 | 79 | |
80 | 80 | foreach ( $form_cols as $form_col ) { |
81 | 81 | if ( FrmField::is_no_save_field( $form_col->type ) ) { |
@@ -88,30 +88,30 @@ discard block |
||
88 | 88 | if ( $sub_form_cols ) { |
89 | 89 | foreach ( $sub_form_cols as $k => $sub_form_col ) { |
90 | 90 | if ( FrmField::is_no_save_field( $sub_form_col->type ) ) { |
91 | - unset( $sub_form_cols[ $k ] ); |
|
91 | + unset( $sub_form_cols[$k] ); |
|
92 | 92 | continue; |
93 | 93 | } |
94 | - $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
|
95 | - unset($sub_form_col); |
|
94 | + $columns[$form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
|
95 | + unset( $sub_form_col ); |
|
96 | 96 | } |
97 | 97 | } |
98 | - unset($sub_form_cols); |
|
98 | + unset( $sub_form_cols ); |
|
99 | 99 | } else { |
100 | 100 | $col_id = $form_col->field_key; |
101 | 101 | if ( $form_col->form_id != $form_id ) { |
102 | 102 | $col_id .= '-_-form' . $form_col->form_id; |
103 | 103 | } |
104 | 104 | |
105 | - if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) { |
|
106 | - $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
105 | + if ( isset( $form_col->field_options['separate_value'] ) && $form_col->field_options['separate_value'] ) { |
|
106 | + $columns[$form_id . '_frmsep_' . $col_id] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
107 | 107 | } |
108 | - $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
108 | + $columns[$form_id . '_' . $col_id] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' ); |
|
113 | - $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' ); |
|
114 | - $columns[ $form_id . '_ip' ] = 'IP'; |
|
112 | + $columns[$form_id . '_created_at'] = __( 'Entry creation date', 'formidable' ); |
|
113 | + $columns[$form_id . '_updated_at'] = __( 'Entry update date', 'formidable' ); |
|
114 | + $columns[$form_id . '_ip'] = 'IP'; |
|
115 | 115 | |
116 | 116 | $frm_vars['cols'] = $columns; |
117 | 117 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | global $frm_vars; |
138 | 138 | //add a check so we don't create a loop |
139 | - $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
139 | + $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
140 | 140 | |
141 | 141 | return $check; |
142 | 142 | } |
@@ -151,19 +151,19 @@ discard block |
||
151 | 151 | } |
152 | 152 | |
153 | 153 | global $frm_vars; |
154 | - if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
154 | + if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) { |
|
155 | 155 | return; //don't continue if there's no previous value |
156 | 156 | } |
157 | 157 | |
158 | 158 | foreach ( $meta_value as $mk => $mv ) { |
159 | 159 | //remove blank values |
160 | 160 | if ( empty( $mv ) ) { |
161 | - unset( $meta_value[ $mk ] ); |
|
161 | + unset( $meta_value[$mk] ); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | - $cur_form_prefix = reset($meta_value); |
|
166 | - $cur_form_prefix = explode('_', $cur_form_prefix); |
|
165 | + $cur_form_prefix = reset( $meta_value ); |
|
166 | + $cur_form_prefix = explode( '_', $cur_form_prefix ); |
|
167 | 167 | $cur_form_prefix = $cur_form_prefix[0]; |
168 | 168 | $save = false; |
169 | 169 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | $meta_value[] = $prev_hidden; |
184 | 184 | $save = true; |
185 | - unset($form_prefix); |
|
185 | + unset( $form_prefix ); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | if ( $save ) { |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | foreach ( $fields as $field ) { |
215 | 215 | if ( $field->type != 'checkbox' && ( ! isset( $field->field_options['post_field'] ) || $field->field_options['post_field'] == '' ) ) { |
216 | 216 | // Can't sort on checkboxes because they are stored serialized, or post fields |
217 | - $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id; |
|
217 | + $columns[$form_id . '_' . $field->field_key] = 'meta_' . $field->id; |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | break; |
238 | 238 | } |
239 | 239 | |
240 | - unset($form_prefix); |
|
240 | + unset( $form_prefix ); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
@@ -245,36 +245,36 @@ discard block |
||
245 | 245 | return $result; |
246 | 246 | } |
247 | 247 | |
248 | - $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
248 | + $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; |
|
249 | 249 | $max_columns = 8; |
250 | 250 | if ( $i <= $max_columns ) { |
251 | 251 | return $result; |
252 | 252 | } |
253 | 253 | |
254 | 254 | global $frm_vars; |
255 | - if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
256 | - $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
255 | + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] ) { |
|
256 | + $frm_vars['current_form']->options = maybe_unserialize( $frm_vars['current_form']->options ); |
|
257 | 257 | } |
258 | 258 | |
259 | - if ( 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']) ) { |
|
259 | + if ( 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'] ) ) { |
|
260 | 260 | $result = $frm_vars['current_form']->options['hidden_cols']; |
261 | 261 | } else { |
262 | 262 | $cols = $frm_vars['cols']; |
263 | - $cols = array_reverse($cols, true); |
|
263 | + $cols = array_reverse( $cols, true ); |
|
264 | 264 | |
265 | 265 | $result[] = $form_id . '_id'; |
266 | - $i--; |
|
266 | + $i --; |
|
267 | 267 | |
268 | 268 | $result[] = $form_id . '_item_key'; |
269 | - $i--; |
|
269 | + $i --; |
|
270 | 270 | |
271 | 271 | foreach ( $cols as $col_key => $col ) { |
272 | 272 | if ( $i > $max_columns ) { |
273 | 273 | $result[] = $col_key; |
274 | 274 | } |
275 | 275 | //remove some columns by default |
276 | - $i--; |
|
277 | - unset($col_key, $col); |
|
276 | + $i --; |
|
277 | + unset( $col_key, $col ); |
|
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
@@ -311,14 +311,14 @@ discard block |
||
311 | 311 | if ( $pagenum > $total_pages && $total_pages > 0 ) { |
312 | 312 | $url = add_query_arg( 'paged', $total_pages ); |
313 | 313 | if ( headers_sent() ) { |
314 | - echo FrmAppHelper::js_redirect($url); |
|
314 | + echo FrmAppHelper::js_redirect( $url ); |
|
315 | 315 | } else { |
316 | 316 | wp_redirect( esc_url_raw( $url ) ); |
317 | 317 | } |
318 | 318 | die(); |
319 | 319 | } |
320 | 320 | |
321 | - if ( empty($message) && isset($_GET['import-message']) ) { |
|
321 | + if ( empty( $message ) && isset( $_GET['import-message'] ) ) { |
|
322 | 322 | $message = __( 'Your import is complete', 'formidable' ); |
323 | 323 | } |
324 | 324 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | /* Back End CRUD */ |
329 | 329 | public static function show( $id = 0 ) { |
330 | - FrmAppHelper::permission_check('frm_view_entries'); |
|
330 | + FrmAppHelper::permission_check( 'frm_view_entries' ); |
|
331 | 331 | |
332 | 332 | if ( ! $id ) { |
333 | 333 | $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
340 | - $entry = FrmEntry::getOne($id, true); |
|
340 | + $entry = FrmEntry::getOne( $id, true ); |
|
341 | 341 | if ( ! $entry ) { |
342 | 342 | echo '<div id="form_show_entry_page" class="wrap">' . |
343 | 343 | __( 'You are trying to view an entry that does not exist.', 'formidable' ) . |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - $data = maybe_unserialize($entry->description); |
|
348 | + $data = maybe_unserialize( $entry->description ); |
|
349 | 349 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
350 | 350 | $data = array( 'referrer' => $data ); |
351 | 351 | } |
@@ -357,11 +357,11 @@ discard block |
||
357 | 357 | } |
358 | 358 | |
359 | 359 | public static function destroy() { |
360 | - FrmAppHelper::permission_check('frm_delete_entries'); |
|
360 | + FrmAppHelper::permission_check( 'frm_delete_entries' ); |
|
361 | 361 | |
362 | 362 | $params = FrmForm::get_admin_params(); |
363 | 363 | |
364 | - if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
364 | + if ( isset( $params['keep_post'] ) && $params['keep_post'] ) { |
|
365 | 365 | //unlink entry from post |
366 | 366 | global $wpdb; |
367 | 367 | $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) ); |
@@ -440,9 +440,9 @@ discard block |
||
440 | 440 | if ( ! isset( $frm_vars['form_params'] ) ) { |
441 | 441 | $frm_vars['form_params'] = array(); |
442 | 442 | } |
443 | - $frm_vars['form_params'][ $form->id ] = $params; |
|
443 | + $frm_vars['form_params'][$form->id] = $params; |
|
444 | 444 | |
445 | - if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { |
|
445 | + if ( isset( $frm_vars['created_entries'][$form_id] ) ) { |
|
446 | 446 | return; |
447 | 447 | } |
448 | 448 | |
@@ -457,13 +457,13 @@ discard block |
||
457 | 457 | */ |
458 | 458 | $errors = apply_filters( 'frm_entries_before_create', $errors, $form ); |
459 | 459 | |
460 | - $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); |
|
460 | + $frm_vars['created_entries'][$form_id] = array( 'errors' => $errors ); |
|
461 | 461 | |
462 | 462 | if ( empty( $errors ) ) { |
463 | 463 | $_POST['frm_skip_cookie'] = 1; |
464 | 464 | if ( $params['action'] == 'create' ) { |
465 | - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
|
466 | - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); |
|
465 | + if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][$form_id]['entry_id'] ) ) { |
|
466 | + $frm_vars['created_entries'][$form_id]['entry_id'] = FrmEntry::create( $_POST ); |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | |
@@ -498,10 +498,10 @@ discard block |
||
498 | 498 | } |
499 | 499 | |
500 | 500 | public static function filter_shortcode_value( $value, $tag, $atts, $field ) { |
501 | - $plain_text = add_filter('frm_plain_text_email', true); |
|
501 | + $plain_text = add_filter( 'frm_plain_text_email', true ); |
|
502 | 502 | FrmEntryFormat::textarea_display_value( $field->type, $plain_text, $value ); |
503 | 503 | |
504 | - if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
504 | + if ( isset( $atts['show'] ) && $atts['show'] == 'value' ) { |
|
505 | 505 | return $value; |
506 | 506 | } |
507 | 507 | |
@@ -514,9 +514,9 @@ discard block |
||
514 | 514 | } |
515 | 515 | |
516 | 516 | public static function entry_sidebar( $entry ) { |
517 | - $data = maybe_unserialize($entry->description); |
|
518 | - $date_format = get_option('date_format'); |
|
519 | - $time_format = get_option('time_format'); |
|
517 | + $data = maybe_unserialize( $entry->description ); |
|
518 | + $date_format = get_option( 'date_format' ); |
|
519 | + $time_format = get_option( 'time_format' ); |
|
520 | 520 | if ( isset( $data['browser'] ) ) { |
521 | 521 | $browser = FrmEntryFormat::get_browser( $data['browser'] ); |
522 | 522 | } |
@@ -14,44 +14,44 @@ |
||
14 | 14 | <div class="inside"> |
15 | 15 | <table class="form-table"><tbody> |
16 | 16 | <?php |
17 | - $first_h3 = 'frm_first_h3'; |
|
18 | - foreach ( $fields as $field ) { |
|
17 | + $first_h3 = 'frm_first_h3'; |
|
18 | + foreach ( $fields as $field ) { |
|
19 | 19 | if ( in_array( $field->type, array( 'captcha', 'html', 'end_divider', 'form' ) ) ) { |
20 | - continue; |
|
21 | - } |
|
20 | + continue; |
|
21 | + } |
|
22 | 22 | |
23 | - if ( in_array($field->type, array( 'break', 'divider' ) ) ) { |
|
24 | - ?> |
|
23 | + if ( in_array($field->type, array( 'break', 'divider' ) ) ) { |
|
24 | + ?> |
|
25 | 25 | </tbody></table> |
26 | 26 | <br/><h3 class="<?php echo esc_attr( $first_h3 ) ?>"><?php echo esc_html( $field->name ) ?></h3> |
27 | 27 | <table class="form-table"><tbody> |
28 | 28 | <?php |
29 | - $first_h3 = ''; |
|
30 | - } else { |
|
31 | - ?> |
|
29 | + $first_h3 = ''; |
|
30 | + } else { |
|
31 | + ?> |
|
32 | 32 | <tr> |
33 | 33 | <th scope="row"><?php echo esc_html( $field->name ) ?>:</th> |
34 | 34 | <td> |
35 | 35 | <?php |
36 | 36 | $embedded_field_id = ( $entry->form_id != $field->form_id ) ? 'form' . $field->form_id : 0; |
37 | - $atts = array( |
|
38 | - 'type' => $field->type, 'post_id' => $entry->post_id, |
|
39 | - 'show_filename' => true, 'show_icon' => true, 'entry_id' => $entry->id, |
|
40 | - 'embedded_field_id' => $embedded_field_id, |
|
41 | - ); |
|
37 | + $atts = array( |
|
38 | + 'type' => $field->type, 'post_id' => $entry->post_id, |
|
39 | + 'show_filename' => true, 'show_icon' => true, 'entry_id' => $entry->id, |
|
40 | + 'embedded_field_id' => $embedded_field_id, |
|
41 | + ); |
|
42 | 42 | $display_value = FrmEntriesHelper::prepare_display_value( $entry, $field, $atts ); |
43 | 43 | echo $display_value; |
44 | 44 | |
45 | - if ( is_email($display_value) && ! in_array($display_value, $to_emails) ) { |
|
46 | - $to_emails[] = $display_value; |
|
47 | - } |
|
48 | - ?> |
|
45 | + if ( is_email($display_value) && ! in_array($display_value, $to_emails) ) { |
|
46 | + $to_emails[] = $display_value; |
|
47 | + } |
|
48 | + ?> |
|
49 | 49 | </td> |
50 | 50 | </tr> |
51 | 51 | <?php } |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | - ?> |
|
54 | + ?> |
|
55 | 55 | |
56 | 56 | <?php if ( $entry->parent_item_id ) { ?> |
57 | 57 | <tr><th><?php _e( 'Parent Entry ID', 'formidable' ) ?>:</th> |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <div id="form_show_entry_page" class="wrap"> |
2 | 2 | <h2 class="frm_no_print"><?php _e( 'View Entry', 'formidable' ) ?> |
3 | - <?php do_action('frm_entry_inside_h2', $entry->form_id); ?> |
|
3 | + <?php do_action( 'frm_entry_inside_h2', $entry->form_id ); ?> |
|
4 | 4 | </h2> |
5 | 5 | |
6 | 6 | <div class="frm_forms"> |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | <div id="poststuff"> |
9 | 9 | <div id="post-body" class="metabox-holder columns-2"> |
10 | 10 | <div id="post-body-content"> |
11 | - <?php FrmAppController::get_form_nav($entry->form_id, true); ?> |
|
11 | + <?php FrmAppController::get_form_nav( $entry->form_id, true ); ?> |
|
12 | 12 | <div class="postbox"> |
13 | 13 | <h3 class="hndle"><span><?php _e( 'Entry', 'formidable' ) ?></span></h3> |
14 | 14 | <div class="inside"> |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | continue; |
21 | 21 | } |
22 | 22 | |
23 | - if ( in_array($field->type, array( 'break', 'divider' ) ) ) { |
|
23 | + if ( in_array( $field->type, array( 'break', 'divider' ) ) ) { |
|
24 | 24 | ?> |
25 | 25 | </tbody></table> |
26 | 26 | <br/><h3 class="<?php echo esc_attr( $first_h3 ) ?>"><?php echo esc_html( $field->name ) ?></h3> |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $display_value = FrmEntriesHelper::prepare_display_value( $entry, $field, $atts ); |
43 | 43 | echo $display_value; |
44 | 44 | |
45 | - if ( is_email($display_value) && ! in_array($display_value, $to_emails) ) { |
|
45 | + if ( is_email( $display_value ) && ! in_array( $display_value, $to_emails ) ) { |
|
46 | 46 | $to_emails[] = $display_value; |
47 | 47 | } |
48 | 48 | ?> |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | </td></tr> |
60 | 60 | <?php } ?> |
61 | 61 | </tbody></table> |
62 | - <?php do_action('frm_show_entry', $entry); ?> |
|
62 | + <?php do_action( 'frm_show_entry', $entry ); ?> |
|
63 | 63 | </div> |
64 | 64 | </div> |
65 | 65 | |
66 | - <?php do_action('frm_after_show_entry', $entry); ?> |
|
66 | + <?php do_action( 'frm_after_show_entry', $entry ); ?> |
|
67 | 67 | |
68 | 68 | </div> |
69 | 69 | <?php require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-show.php' ); ?> |
@@ -2,80 +2,80 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmNotification { |
4 | 4 | public function __construct() { |
5 | - if ( ! defined('ABSPATH') ) { |
|
6 | - die('You are not allowed to call this page directly.'); |
|
7 | - } |
|
8 | - add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
9 | - } |
|
5 | + if ( ! defined('ABSPATH') ) { |
|
6 | + die('You are not allowed to call this page directly.'); |
|
7 | + } |
|
8 | + add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
9 | + } |
|
10 | 10 | |
11 | 11 | public static function trigger_email( $action, $entry, $form ) { |
12 | - $notification = $action->post_content; |
|
13 | - $email_key = $action->ID; |
|
12 | + $notification = $action->post_content; |
|
13 | + $email_key = $action->ID; |
|
14 | 14 | |
15 | - // Set the subject |
|
16 | - if ( empty($notification['email_subject']) ) { |
|
17 | - $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
18 | - } |
|
15 | + // Set the subject |
|
16 | + if ( empty($notification['email_subject']) ) { |
|
17 | + $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
18 | + } |
|
19 | 19 | |
20 | - $plain_text = $notification['plain_text'] ? true : false; |
|
20 | + $plain_text = $notification['plain_text'] ? true : false; |
|
21 | 21 | |
22 | - //Filter these fields |
|
23 | - $filter_fields = array( |
|
24 | - 'email_to', 'cc', 'bcc', |
|
25 | - 'reply_to', 'from', |
|
26 | - 'email_subject', 'email_message', |
|
27 | - ); |
|
22 | + //Filter these fields |
|
23 | + $filter_fields = array( |
|
24 | + 'email_to', 'cc', 'bcc', |
|
25 | + 'reply_to', 'from', |
|
26 | + 'email_subject', 'email_message', |
|
27 | + ); |
|
28 | 28 | |
29 | - add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
29 | + add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
30 | 30 | |
31 | - //Get all values in entry in order to get User ID field ID |
|
32 | - $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
|
31 | + //Get all values in entry in order to get User ID field ID |
|
32 | + $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
|
33 | 33 | $user_id_field = ''; |
34 | 34 | $user_id_key = ''; |
35 | - foreach ( $values as $value ) { |
|
36 | - if ( $value->field_type == 'user_id' ) { |
|
37 | - $user_id_field = $value->field_id; |
|
38 | - $user_id_key = $value->field_key; |
|
39 | - break; |
|
40 | - } |
|
41 | - unset($value); |
|
42 | - } |
|
43 | - |
|
44 | - //Filter and prepare the email fields |
|
45 | - foreach ( $filter_fields as $f ) { |
|
46 | - //Don't allow empty From |
|
35 | + foreach ( $values as $value ) { |
|
36 | + if ( $value->field_type == 'user_id' ) { |
|
37 | + $user_id_field = $value->field_id; |
|
38 | + $user_id_key = $value->field_key; |
|
39 | + break; |
|
40 | + } |
|
41 | + unset($value); |
|
42 | + } |
|
43 | + |
|
44 | + //Filter and prepare the email fields |
|
45 | + foreach ( $filter_fields as $f ) { |
|
46 | + //Don't allow empty From |
|
47 | 47 | if ( $f == 'from' && empty( $notification[ $f ] ) ) { |
48 | 48 | $notification[ $f ] = '[admin_email]'; |
49 | 49 | } else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) { |
50 | 50 | //Remove brackets |
51 | - //Add a space in case there isn't one |
|
51 | + //Add a space in case there isn't one |
|
52 | 52 | $notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] ); |
53 | 53 | $notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] ); |
54 | 54 | |
55 | - //Switch userID shortcode to email address |
|
55 | + //Switch userID shortcode to email address |
|
56 | 56 | if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) { |
57 | 57 | $user_data = get_userdata( $entry->metas[ $user_id_field ] ); |
58 | - $user_email = $user_data->user_email; |
|
58 | + $user_email = $user_data->user_email; |
|
59 | 59 | $notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] ); |
60 | - } |
|
61 | - } |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | $notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry ); |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - //Put recipients, cc, and bcc into an array if they aren't empty |
|
66 | + //Put recipients, cc, and bcc into an array if they aren't empty |
|
67 | 67 | $to_emails = self::explode_emails( $notification['email_to'] ); |
68 | 68 | $cc = self::explode_emails( $notification['cc'] ); |
69 | 69 | $bcc = self::explode_emails( $notification['bcc'] ); |
70 | 70 | |
71 | - $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
71 | + $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
72 | 72 | |
73 | - // Stop now if there aren't any recipients |
|
74 | - if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
|
75 | - return; |
|
76 | - } |
|
73 | + // Stop now if there aren't any recipients |
|
74 | + if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - $to_emails = array_unique( (array) $to_emails ); |
|
78 | + $to_emails = array_unique( (array) $to_emails ); |
|
79 | 79 | |
80 | 80 | $prev_mail_body = $notification['email_message']; |
81 | 81 | $mail_body = FrmEntriesHelper::replace_default_message( $prev_mail_body, array( |
@@ -83,48 +83,48 @@ discard block |
||
83 | 83 | 'user_info' => ( isset( $notification['inc_user_info'] ) ? $notification['inc_user_info'] : false ), |
84 | 84 | ) ); |
85 | 85 | |
86 | - // Add the user info if it isn't already included |
|
87 | - if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
|
88 | - $data = maybe_unserialize($entry->description); |
|
86 | + // Add the user info if it isn't already included |
|
87 | + if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
|
88 | + $data = maybe_unserialize($entry->description); |
|
89 | 89 | $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
90 | 90 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $entry->ip . "\r\n"; |
91 | 91 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n"; |
92 | 92 | $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
93 | - } |
|
94 | - unset($prev_mail_body); |
|
95 | - |
|
96 | - // Add attachments |
|
97 | - $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
98 | - |
|
99 | - if ( ! empty($notification['email_subject']) ) { |
|
100 | - $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
101 | - } |
|
102 | - |
|
103 | - // check for a phone number |
|
104 | - foreach ( (array) $to_emails as $email_key => $e ) { |
|
105 | - if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
106 | - $e = explode(' ', $e); |
|
107 | - |
|
108 | - //If to_email has name <[email protected]> format |
|
109 | - if ( is_email(end($e)) ) { |
|
110 | - continue; |
|
111 | - } |
|
112 | - |
|
113 | - do_action('frm_send_to_not_email', array( |
|
114 | - 'e' => $e, |
|
115 | - 'subject' => $notification['email_subject'], |
|
116 | - 'mail_body' => $mail_body, |
|
117 | - 'reply_to' => $notification['reply_to'], |
|
118 | - 'from' => $notification['from'], |
|
119 | - 'plain_text' => $plain_text, |
|
120 | - 'attachments' => $attachments, |
|
121 | - 'form' => $form, |
|
122 | - 'email_key' => $email_key, |
|
123 | - ) ); |
|
93 | + } |
|
94 | + unset($prev_mail_body); |
|
95 | + |
|
96 | + // Add attachments |
|
97 | + $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
98 | + |
|
99 | + if ( ! empty($notification['email_subject']) ) { |
|
100 | + $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
101 | + } |
|
102 | + |
|
103 | + // check for a phone number |
|
104 | + foreach ( (array) $to_emails as $email_key => $e ) { |
|
105 | + if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
106 | + $e = explode(' ', $e); |
|
107 | + |
|
108 | + //If to_email has name <[email protected]> format |
|
109 | + if ( is_email(end($e)) ) { |
|
110 | + continue; |
|
111 | + } |
|
112 | + |
|
113 | + do_action('frm_send_to_not_email', array( |
|
114 | + 'e' => $e, |
|
115 | + 'subject' => $notification['email_subject'], |
|
116 | + 'mail_body' => $mail_body, |
|
117 | + 'reply_to' => $notification['reply_to'], |
|
118 | + 'from' => $notification['from'], |
|
119 | + 'plain_text' => $plain_text, |
|
120 | + 'attachments' => $attachments, |
|
121 | + 'form' => $form, |
|
122 | + 'email_key' => $email_key, |
|
123 | + ) ); |
|
124 | 124 | |
125 | 125 | unset( $to_emails[ $email_key ] ); |
126 | - } |
|
127 | - } |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | 129 | /** |
130 | 130 | * Send a separate email for email address in the "to" section |
@@ -132,38 +132,38 @@ discard block |
||
132 | 132 | */ |
133 | 133 | $send_single_recipient = apply_filters( 'frm_send_separate_emails', false, compact( 'action', 'entry', 'form' ) ); |
134 | 134 | |
135 | - // Send the email now |
|
136 | - $sent_to = self::send_email( array( |
|
137 | - 'to_email' => $to_emails, |
|
138 | - 'subject' => $notification['email_subject'], |
|
139 | - 'message' => $mail_body, |
|
140 | - 'from' => $notification['from'], |
|
141 | - 'plain_text' => $plain_text, |
|
142 | - 'reply_to' => $notification['reply_to'], |
|
143 | - 'attachments' => $attachments, |
|
144 | - 'cc' => $cc, |
|
145 | - 'bcc' => $bcc, |
|
135 | + // Send the email now |
|
136 | + $sent_to = self::send_email( array( |
|
137 | + 'to_email' => $to_emails, |
|
138 | + 'subject' => $notification['email_subject'], |
|
139 | + 'message' => $mail_body, |
|
140 | + 'from' => $notification['from'], |
|
141 | + 'plain_text' => $plain_text, |
|
142 | + 'reply_to' => $notification['reply_to'], |
|
143 | + 'attachments' => $attachments, |
|
144 | + 'cc' => $cc, |
|
145 | + 'bcc' => $bcc, |
|
146 | 146 | 'single_recipient' => $send_single_recipient, |
147 | - ) ); |
|
147 | + ) ); |
|
148 | 148 | |
149 | - return $sent_to; |
|
150 | - } |
|
149 | + return $sent_to; |
|
150 | + } |
|
151 | 151 | |
152 | 152 | public function entry_created( $entry_id, $form_id ) { |
153 | 153 | $new_function = 'FrmFormActionsController::trigger_actions("create", ' . $form_id . ', ' . $entry_id . ', "email")'; |
154 | 154 | _deprecated_function( __FUNCTION__, '2.0', $new_function ); |
155 | - FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
156 | - } |
|
155 | + FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) { |
159 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
|
159 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
|
160 | 160 | |
161 | - return self::send_email(compact( |
|
162 | - 'to_email', 'subject', 'message', |
|
163 | - 'from', 'from_name', 'plain_text', |
|
164 | - 'attachments', 'reply_to' |
|
165 | - )); |
|
166 | - } |
|
161 | + return self::send_email(compact( |
|
162 | + 'to_email', 'subject', 'message', |
|
163 | + 'from', 'from_name', 'plain_text', |
|
164 | + 'attachments', 'reply_to' |
|
165 | + )); |
|
166 | + } |
|
167 | 167 | |
168 | 168 | /** |
169 | 169 | * Extract the emails from cc and bcc. Allow separation by , or ;. |
@@ -181,53 +181,53 @@ discard block |
||
181 | 181 | return $emails; |
182 | 182 | } |
183 | 183 | |
184 | - /** |
|
185 | - * Put To, BCC, CC, Reply To, and From fields in Name <[email protected]> format |
|
186 | - * Formats that should work: Name, "Name", [email protected], <[email protected]>, Name <[email protected]>, |
|
187 | - * "Name" <[email protected]>, Name [email protected], "Name" [email protected], Name<[email protected]>, "Name"<[email protected]> |
|
188 | - * "First Last" <[email protected]> |
|
189 | - * |
|
190 | - * Things that won't work: First Last (with no email entered) |
|
191 | - * @since 2.0 |
|
192 | - * @param array $atts array of email fields, pass by reference |
|
193 | - * @param $admin_email |
|
194 | - */ |
|
195 | - private static function format_email_fields( &$atts, $admin_email ) { |
|
196 | - |
|
197 | - // If from is empty or is set to admin_email, set it now |
|
198 | - $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
199 | - |
|
200 | - // Filter values in these fields |
|
184 | + /** |
|
185 | + * Put To, BCC, CC, Reply To, and From fields in Name <[email protected]> format |
|
186 | + * Formats that should work: Name, "Name", [email protected], <[email protected]>, Name <[email protected]>, |
|
187 | + * "Name" <[email protected]>, Name [email protected], "Name" [email protected], Name<[email protected]>, "Name"<[email protected]> |
|
188 | + * "First Last" <[email protected]> |
|
189 | + * |
|
190 | + * Things that won't work: First Last (with no email entered) |
|
191 | + * @since 2.0 |
|
192 | + * @param array $atts array of email fields, pass by reference |
|
193 | + * @param $admin_email |
|
194 | + */ |
|
195 | + private static function format_email_fields( &$atts, $admin_email ) { |
|
196 | + |
|
197 | + // If from is empty or is set to admin_email, set it now |
|
198 | + $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
199 | + |
|
200 | + // Filter values in these fields |
|
201 | 201 | $filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' ); |
202 | 202 | |
203 | - foreach ( $filter_fields as $f ) { |
|
204 | - // If empty, just skip it |
|
203 | + foreach ( $filter_fields as $f ) { |
|
204 | + // If empty, just skip it |
|
205 | 205 | if ( empty( $atts[ $f ] ) ) { |
206 | - continue; |
|
207 | - } |
|
206 | + continue; |
|
207 | + } |
|
208 | 208 | |
209 | - // to_email, cc, and bcc can be an array |
|
209 | + // to_email, cc, and bcc can be an array |
|
210 | 210 | if ( is_array( $atts[ $f ] ) ) { |
211 | 211 | foreach ( $atts[ $f ] as $key => $val ) { |
212 | - self::format_single_field( $atts, $f, $val, $key ); |
|
213 | - unset( $key, $val ); |
|
214 | - } |
|
215 | - unset($f); |
|
216 | - continue; |
|
217 | - } |
|
212 | + self::format_single_field( $atts, $f, $val, $key ); |
|
213 | + unset( $key, $val ); |
|
214 | + } |
|
215 | + unset($f); |
|
216 | + continue; |
|
217 | + } |
|
218 | 218 | |
219 | 219 | self::format_single_field( $atts, $f, $atts[ $f ] ); |
220 | - } |
|
220 | + } |
|
221 | 221 | |
222 | - // If reply-to isn't set, make it match the from settings |
|
223 | - if ( empty( $atts['reply_to'] ) ) { |
|
224 | - $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
|
225 | - } |
|
222 | + // If reply-to isn't set, make it match the from settings |
|
223 | + if ( empty( $atts['reply_to'] ) ) { |
|
224 | + $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
|
225 | + } |
|
226 | 226 | |
227 | - if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
228 | - $atts['to_email'] = $admin_email; |
|
229 | - } |
|
230 | - } |
|
227 | + if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
228 | + $atts['to_email'] = $admin_email; |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | 232 | private static function get_email_from_formatted_string( $value ) { |
233 | 233 | if ( strpos( $value, '<' ) !== false ) { |
@@ -237,48 +237,48 @@ discard block |
||
237 | 237 | return $value; |
238 | 238 | } |
239 | 239 | |
240 | - /** |
|
241 | - * Format individual email fields |
|
242 | - * |
|
243 | - * @since 2.0 |
|
244 | - * @param array $atts pass by reference |
|
245 | - * @param string $f (to, from, reply_to, etc) |
|
246 | - * @param string $val value saved in field |
|
247 | - * @param int $key if in array, this will be set |
|
248 | - */ |
|
249 | - private static function format_single_field( &$atts, $f, $val, $key = false ) { |
|
250 | - $val = trim($val); |
|
251 | - |
|
252 | - // If just a plain email is used |
|
253 | - if ( is_email($val) ) { |
|
254 | - // add sender's name if not included in $from |
|
255 | - if ( $f == 'from' ) { |
|
240 | + /** |
|
241 | + * Format individual email fields |
|
242 | + * |
|
243 | + * @since 2.0 |
|
244 | + * @param array $atts pass by reference |
|
245 | + * @param string $f (to, from, reply_to, etc) |
|
246 | + * @param string $val value saved in field |
|
247 | + * @param int $key if in array, this will be set |
|
248 | + */ |
|
249 | + private static function format_single_field( &$atts, $f, $val, $key = false ) { |
|
250 | + $val = trim($val); |
|
251 | + |
|
252 | + // If just a plain email is used |
|
253 | + if ( is_email($val) ) { |
|
254 | + // add sender's name if not included in $from |
|
255 | + if ( $f == 'from' ) { |
|
256 | 256 | $part_2 = $atts[ $f ]; |
257 | - $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
258 | - } else { |
|
259 | - return; |
|
260 | - } |
|
261 | - } else { |
|
262 | - $parts = explode(' ', $val); |
|
263 | - $part_2 = end($parts); |
|
264 | - |
|
265 | - // If inputted correcly, $part_2 should be an email |
|
266 | - if ( is_email( $part_2 ) ) { |
|
267 | - $part_1 = trim( str_replace( $part_2, '', $val ) ); |
|
268 | - } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
|
257 | + $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
258 | + } else { |
|
259 | + return; |
|
260 | + } |
|
261 | + } else { |
|
262 | + $parts = explode(' ', $val); |
|
263 | + $part_2 = end($parts); |
|
264 | + |
|
265 | + // If inputted correcly, $part_2 should be an email |
|
266 | + if ( is_email( $part_2 ) ) { |
|
267 | + $part_1 = trim( str_replace( $part_2, '', $val ) ); |
|
268 | + } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
|
269 | 269 | // In case someone just puts a name in the From or Reply To field |
270 | 270 | $part_1 = $val; |
271 | - $part_2 = get_option('admin_email'); |
|
272 | - } else { |
|
271 | + $part_2 = get_option('admin_email'); |
|
272 | + } else { |
|
273 | 273 | // In case someone just puts a name in any other email field |
274 | - if ( false !== $key ) { |
|
274 | + if ( false !== $key ) { |
|
275 | 275 | unset( $atts[ $f ][ $key ] ); |
276 | - return; |
|
277 | - } |
|
276 | + return; |
|
277 | + } |
|
278 | 278 | $atts[ $f ] = ''; |
279 | - return; |
|
280 | - } |
|
281 | - } |
|
279 | + return; |
|
280 | + } |
|
281 | + } |
|
282 | 282 | |
283 | 283 | // if sending the email from a yahoo address, change it to the WordPress default |
284 | 284 | if ( $f == 'from' && strpos( $part_2, '@yahoo.com' ) ) { |
@@ -291,60 +291,60 @@ discard block |
||
291 | 291 | $part_2 = 'wordpress@' . $sitename; |
292 | 292 | } |
293 | 293 | |
294 | - // Set up formatted value |
|
294 | + // Set up formatted value |
|
295 | 295 | $final_val = str_replace( '"', '', $part_1 ) . ' <' . $part_2 . '>'; |
296 | 296 | |
297 | - // If value is an array |
|
298 | - if ( false !== $key ) { |
|
297 | + // If value is an array |
|
298 | + if ( false !== $key ) { |
|
299 | 299 | $atts[ $f ][ $key ] = $final_val; |
300 | - return; |
|
301 | - } |
|
300 | + return; |
|
301 | + } |
|
302 | 302 | $atts[ $f ] = $final_val; |
303 | - } |
|
303 | + } |
|
304 | 304 | |
305 | 305 | public static function send_email( $atts ) { |
306 | - $admin_email = get_option('admin_email'); |
|
307 | - $defaults = array( |
|
308 | - 'to_email' => $admin_email, |
|
309 | - 'subject' => '', |
|
310 | - 'message' => '', |
|
311 | - 'from' => $admin_email, |
|
312 | - 'from_name' => '', |
|
313 | - 'cc' => '', |
|
314 | - 'bcc' => '', |
|
315 | - 'plain_text' => true, |
|
316 | - 'reply_to' => $admin_email, |
|
317 | - 'attachments' => array(), |
|
306 | + $admin_email = get_option('admin_email'); |
|
307 | + $defaults = array( |
|
308 | + 'to_email' => $admin_email, |
|
309 | + 'subject' => '', |
|
310 | + 'message' => '', |
|
311 | + 'from' => $admin_email, |
|
312 | + 'from_name' => '', |
|
313 | + 'cc' => '', |
|
314 | + 'bcc' => '', |
|
315 | + 'plain_text' => true, |
|
316 | + 'reply_to' => $admin_email, |
|
317 | + 'attachments' => array(), |
|
318 | 318 | 'single_recipient' => false, |
319 | - ); |
|
320 | - $atts = wp_parse_args($atts, $defaults); |
|
319 | + ); |
|
320 | + $atts = wp_parse_args($atts, $defaults); |
|
321 | 321 | |
322 | - // Put To, BCC, CC, Reply To, and From fields in the correct format |
|
323 | - self::format_email_fields( $atts, $admin_email ); |
|
322 | + // Put To, BCC, CC, Reply To, and From fields in the correct format |
|
323 | + self::format_email_fields( $atts, $admin_email ); |
|
324 | 324 | |
325 | - $header = array(); |
|
326 | - $header[] = 'From: ' . $atts['from']; |
|
325 | + $header = array(); |
|
326 | + $header[] = 'From: ' . $atts['from']; |
|
327 | 327 | |
328 | - //Allow for cc and bcc arrays |
|
328 | + //Allow for cc and bcc arrays |
|
329 | 329 | $array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] ); |
330 | 330 | $cc = array( 'CC' => array(), 'BCC' => array() ); |
331 | - foreach ( $array_fields as $key => $a_field ) { |
|
332 | - if ( empty($a_field) ) { |
|
333 | - continue; |
|
334 | - } |
|
331 | + foreach ( $array_fields as $key => $a_field ) { |
|
332 | + if ( empty($a_field) ) { |
|
333 | + continue; |
|
334 | + } |
|
335 | 335 | |
336 | 336 | foreach ( (array) $a_field as $email ) { |
337 | 337 | $cc[ $key ][] = $email; |
338 | - } |
|
339 | - unset($key, $a_field); |
|
340 | - } |
|
338 | + } |
|
339 | + unset($key, $a_field); |
|
340 | + } |
|
341 | 341 | $cc = array_filter( $cc ); // remove cc and bcc if they are empty |
342 | 342 | |
343 | 343 | foreach ( $cc as $k => $v ) { |
344 | 344 | $header[] = $k . ': ' . implode( ',', $v ); |
345 | 345 | } |
346 | 346 | |
347 | - $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
|
347 | + $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
|
348 | 348 | $atts['charset'] = get_option('blog_charset'); |
349 | 349 | |
350 | 350 | $header[] = 'Reply-To: ' . $atts['reply_to']; |
@@ -353,12 +353,12 @@ discard block |
||
353 | 353 | |
354 | 354 | $atts['message'] = do_shortcode( $atts['message'] ); |
355 | 355 | |
356 | - if ( $atts['plain_text'] ) { |
|
356 | + if ( $atts['plain_text'] ) { |
|
357 | 357 | $atts['message'] = wp_specialchars_decode( strip_tags( $atts['message'] ), ENT_QUOTES ); |
358 | - } else { |
|
358 | + } else { |
|
359 | 359 | // remove line breaks in HTML emails to prevent conflicts with Mandrill |
360 | - add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
|
361 | - } |
|
360 | + add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
|
361 | + } |
|
362 | 362 | $atts['message'] = apply_filters( 'frm_email_message', $atts['message'], $atts ); |
363 | 363 | |
364 | 364 | /** |
@@ -388,10 +388,10 @@ discard block |
||
388 | 388 | // remove the filter now so other emails can still use it |
389 | 389 | remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
390 | 390 | |
391 | - if ( $sent ) { |
|
391 | + if ( $sent ) { |
|
392 | 392 | return self::return_emails_sent( $atts ); |
393 | - } |
|
394 | - } |
|
393 | + } |
|
394 | + } |
|
395 | 395 | |
396 | 396 | private static function send_single_email( $recipient, $atts, $header ) { |
397 | 397 | $header = apply_filters( 'frm_email_header', $header, array( |
@@ -2,10 +2,10 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmNotification { |
4 | 4 | public function __construct() { |
5 | - if ( ! defined('ABSPATH') ) { |
|
6 | - die('You are not allowed to call this page directly.'); |
|
5 | + if ( ! defined( 'ABSPATH' ) ) { |
|
6 | + die( 'You are not allowed to call this page directly.' ); |
|
7 | 7 | } |
8 | - add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
8 | + add_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3 ); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | public static function trigger_email( $action, $entry, $form ) { |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | $email_key = $action->ID; |
14 | 14 | |
15 | 15 | // Set the subject |
16 | - if ( empty($notification['email_subject']) ) { |
|
17 | - $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
16 | + if ( empty( $notification['email_subject'] ) ) { |
|
17 | + $notification['email_subject'] = sprintf( __( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]' ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | $plain_text = $notification['plain_text'] ? true : false; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | 'email_subject', 'email_message', |
27 | 27 | ); |
28 | 28 | |
29 | - add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
29 | + add_filter( 'frm_plain_text_email', ( $plain_text ? '__return_true' : '__return_false' ) ); |
|
30 | 30 | |
31 | 31 | //Get all values in entry in order to get User ID field ID |
32 | 32 | $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
@@ -38,29 +38,29 @@ discard block |
||
38 | 38 | $user_id_key = $value->field_key; |
39 | 39 | break; |
40 | 40 | } |
41 | - unset($value); |
|
41 | + unset( $value ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | //Filter and prepare the email fields |
45 | 45 | foreach ( $filter_fields as $f ) { |
46 | 46 | //Don't allow empty From |
47 | - if ( $f == 'from' && empty( $notification[ $f ] ) ) { |
|
48 | - $notification[ $f ] = '[admin_email]'; |
|
47 | + if ( $f == 'from' && empty( $notification[$f] ) ) { |
|
48 | + $notification[$f] = '[admin_email]'; |
|
49 | 49 | } else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) { |
50 | 50 | //Remove brackets |
51 | 51 | //Add a space in case there isn't one |
52 | - $notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] ); |
|
53 | - $notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] ); |
|
52 | + $notification[$f] = str_replace( '<', ' ', $notification[$f] ); |
|
53 | + $notification[$f] = str_replace( array( '"', '>' ), '', $notification[$f] ); |
|
54 | 54 | |
55 | 55 | //Switch userID shortcode to email address |
56 | - if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) { |
|
57 | - $user_data = get_userdata( $entry->metas[ $user_id_field ] ); |
|
56 | + if ( strpos( $notification[$f], '[' . $user_id_field . ']' ) !== false || strpos( $notification[$f], '[' . $user_id_key . ']' ) !== false ) { |
|
57 | + $user_data = get_userdata( $entry->metas[$user_id_field] ); |
|
58 | 58 | $user_email = $user_data->user_email; |
59 | - $notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] ); |
|
59 | + $notification[$f] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[$f] ); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
63 | - $notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry ); |
|
63 | + $notification[$f] = FrmFieldsHelper::basic_replace_shortcodes( $notification[$f], $form, $entry ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | //Put recipients, cc, and bcc into an array if they aren't empty |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $cc = self::explode_emails( $notification['cc'] ); |
69 | 69 | $bcc = self::explode_emails( $notification['bcc'] ); |
70 | 70 | |
71 | - $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
71 | + $to_emails = apply_filters( 'frm_to_email', $to_emails, $values, $form->id, compact( 'email_key', 'entry', 'form' ) ); |
|
72 | 72 | |
73 | 73 | // Stop now if there aren't any recipients |
74 | 74 | if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
@@ -85,32 +85,32 @@ discard block |
||
85 | 85 | |
86 | 86 | // Add the user info if it isn't already included |
87 | 87 | if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
88 | - $data = maybe_unserialize($entry->description); |
|
88 | + $data = maybe_unserialize( $entry->description ); |
|
89 | 89 | $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
90 | 90 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $entry->ip . "\r\n"; |
91 | 91 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n"; |
92 | 92 | $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
93 | 93 | } |
94 | - unset($prev_mail_body); |
|
94 | + unset( $prev_mail_body ); |
|
95 | 95 | |
96 | 96 | // Add attachments |
97 | - $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
97 | + $attachments = apply_filters( 'frm_notification_attachment', array(), $form, compact( 'entry', 'email_key' ) ); |
|
98 | 98 | |
99 | - if ( ! empty($notification['email_subject']) ) { |
|
100 | - $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
99 | + if ( ! empty( $notification['email_subject'] ) ) { |
|
100 | + $notification['email_subject'] = apply_filters( 'frm_email_subject', $notification['email_subject'], compact( 'form', 'entry', 'email_key' ) ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | // check for a phone number |
104 | 104 | foreach ( (array) $to_emails as $email_key => $e ) { |
105 | - if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
106 | - $e = explode(' ', $e); |
|
105 | + if ( $e != '[admin_email]' && ! is_email( $e ) ) { |
|
106 | + $e = explode( ' ', $e ); |
|
107 | 107 | |
108 | 108 | //If to_email has name <[email protected]> format |
109 | - if ( is_email(end($e)) ) { |
|
109 | + if ( is_email( end( $e ) ) ) { |
|
110 | 110 | continue; |
111 | 111 | } |
112 | 112 | |
113 | - do_action('frm_send_to_not_email', array( |
|
113 | + do_action( 'frm_send_to_not_email', array( |
|
114 | 114 | 'e' => $e, |
115 | 115 | 'subject' => $notification['email_subject'], |
116 | 116 | 'mail_body' => $mail_body, |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | 'email_key' => $email_key, |
123 | 123 | ) ); |
124 | 124 | |
125 | - unset( $to_emails[ $email_key ] ); |
|
125 | + unset( $to_emails[$email_key] ); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -152,17 +152,17 @@ discard block |
||
152 | 152 | public function entry_created( $entry_id, $form_id ) { |
153 | 153 | $new_function = 'FrmFormActionsController::trigger_actions("create", ' . $form_id . ', ' . $entry_id . ', "email")'; |
154 | 154 | _deprecated_function( __FUNCTION__, '2.0', $new_function ); |
155 | - FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
155 | + FrmFormActionsController::trigger_actions( 'create', $form_id, $entry_id, 'email' ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) { |
159 | 159 | _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
160 | 160 | |
161 | - return self::send_email(compact( |
|
161 | + return self::send_email( compact( |
|
162 | 162 | 'to_email', 'subject', 'message', |
163 | 163 | 'from', 'from_name', 'plain_text', |
164 | 164 | 'attachments', 'reply_to' |
165 | - )); |
|
165 | + ) ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -195,28 +195,28 @@ discard block |
||
195 | 195 | private static function format_email_fields( &$atts, $admin_email ) { |
196 | 196 | |
197 | 197 | // If from is empty or is set to admin_email, set it now |
198 | - $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
198 | + $atts['from'] = ( empty( $atts['from'] ) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
199 | 199 | |
200 | 200 | // Filter values in these fields |
201 | 201 | $filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' ); |
202 | 202 | |
203 | 203 | foreach ( $filter_fields as $f ) { |
204 | 204 | // If empty, just skip it |
205 | - if ( empty( $atts[ $f ] ) ) { |
|
205 | + if ( empty( $atts[$f] ) ) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | |
209 | 209 | // to_email, cc, and bcc can be an array |
210 | - if ( is_array( $atts[ $f ] ) ) { |
|
211 | - foreach ( $atts[ $f ] as $key => $val ) { |
|
210 | + if ( is_array( $atts[$f] ) ) { |
|
211 | + foreach ( $atts[$f] as $key => $val ) { |
|
212 | 212 | self::format_single_field( $atts, $f, $val, $key ); |
213 | 213 | unset( $key, $val ); |
214 | 214 | } |
215 | - unset($f); |
|
215 | + unset( $f ); |
|
216 | 216 | continue; |
217 | 217 | } |
218 | 218 | |
219 | - self::format_single_field( $atts, $f, $atts[ $f ] ); |
|
219 | + self::format_single_field( $atts, $f, $atts[$f] ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // If reply-to isn't set, make it match the from settings |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
225 | 225 | } |
226 | 226 | |
227 | - if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
227 | + if ( ! is_array( $atts['to_email'] ) && '[admin_email]' == $atts['to_email'] ) { |
|
228 | 228 | $atts['to_email'] = $admin_email; |
229 | 229 | } |
230 | 230 | } |
@@ -247,20 +247,20 @@ discard block |
||
247 | 247 | * @param int $key if in array, this will be set |
248 | 248 | */ |
249 | 249 | private static function format_single_field( &$atts, $f, $val, $key = false ) { |
250 | - $val = trim($val); |
|
250 | + $val = trim( $val ); |
|
251 | 251 | |
252 | 252 | // If just a plain email is used |
253 | - if ( is_email($val) ) { |
|
253 | + if ( is_email( $val ) ) { |
|
254 | 254 | // add sender's name if not included in $from |
255 | 255 | if ( $f == 'from' ) { |
256 | - $part_2 = $atts[ $f ]; |
|
257 | - $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
256 | + $part_2 = $atts[$f]; |
|
257 | + $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
258 | 258 | } else { |
259 | 259 | return; |
260 | 260 | } |
261 | 261 | } else { |
262 | - $parts = explode(' ', $val); |
|
263 | - $part_2 = end($parts); |
|
262 | + $parts = explode( ' ', $val ); |
|
263 | + $part_2 = end( $parts ); |
|
264 | 264 | |
265 | 265 | // If inputted correcly, $part_2 should be an email |
266 | 266 | if ( is_email( $part_2 ) ) { |
@@ -268,14 +268,14 @@ discard block |
||
268 | 268 | } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
269 | 269 | // In case someone just puts a name in the From or Reply To field |
270 | 270 | $part_1 = $val; |
271 | - $part_2 = get_option('admin_email'); |
|
271 | + $part_2 = get_option( 'admin_email' ); |
|
272 | 272 | } else { |
273 | 273 | // In case someone just puts a name in any other email field |
274 | 274 | if ( false !== $key ) { |
275 | - unset( $atts[ $f ][ $key ] ); |
|
275 | + unset( $atts[$f][$key] ); |
|
276 | 276 | return; |
277 | 277 | } |
278 | - $atts[ $f ] = ''; |
|
278 | + $atts[$f] = ''; |
|
279 | 279 | return; |
280 | 280 | } |
281 | 281 | } |
@@ -296,14 +296,14 @@ discard block |
||
296 | 296 | |
297 | 297 | // If value is an array |
298 | 298 | if ( false !== $key ) { |
299 | - $atts[ $f ][ $key ] = $final_val; |
|
299 | + $atts[$f][$key] = $final_val; |
|
300 | 300 | return; |
301 | 301 | } |
302 | - $atts[ $f ] = $final_val; |
|
302 | + $atts[$f] = $final_val; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | public static function send_email( $atts ) { |
306 | - $admin_email = get_option('admin_email'); |
|
306 | + $admin_email = get_option( 'admin_email' ); |
|
307 | 307 | $defaults = array( |
308 | 308 | 'to_email' => $admin_email, |
309 | 309 | 'subject' => '', |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | 'attachments' => array(), |
318 | 318 | 'single_recipient' => false, |
319 | 319 | ); |
320 | - $atts = wp_parse_args($atts, $defaults); |
|
320 | + $atts = wp_parse_args( $atts, $defaults ); |
|
321 | 321 | |
322 | 322 | // Put To, BCC, CC, Reply To, and From fields in the correct format |
323 | 323 | self::format_email_fields( $atts, $admin_email ); |
@@ -329,14 +329,14 @@ discard block |
||
329 | 329 | $array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] ); |
330 | 330 | $cc = array( 'CC' => array(), 'BCC' => array() ); |
331 | 331 | foreach ( $array_fields as $key => $a_field ) { |
332 | - if ( empty($a_field) ) { |
|
332 | + if ( empty( $a_field ) ) { |
|
333 | 333 | continue; |
334 | 334 | } |
335 | 335 | |
336 | 336 | foreach ( (array) $a_field as $email ) { |
337 | - $cc[ $key ][] = $email; |
|
337 | + $cc[$key][] = $email; |
|
338 | 338 | } |
339 | - unset($key, $a_field); |
|
339 | + unset( $key, $a_field ); |
|
340 | 340 | } |
341 | 341 | $cc = array_filter( $cc ); // remove cc and bcc if they are empty |
342 | 342 | |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | $header[] = $k . ': ' . implode( ',', $v ); |
345 | 345 | } |
346 | 346 | |
347 | - $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
|
348 | - $atts['charset'] = get_option('blog_charset'); |
|
347 | + $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
|
348 | + $atts['charset'] = get_option( 'blog_charset' ); |
|
349 | 349 | |
350 | 350 | $header[] = 'Reply-To: ' . $atts['reply_to']; |
351 | 351 | $header[] = 'Content-Type: ' . $content_type . '; charset="' . esc_attr( $atts['charset'] ) . '"'; |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | } |
414 | 414 | |
415 | 415 | private static function encode_subject( $charset, &$subject ) { |
416 | - if ( apply_filters('frm_encode_subject', 1, $subject ) ) { |
|
416 | + if ( apply_filters( 'frm_encode_subject', 1, $subject ) ) { |
|
417 | 417 | $subject = '=?' . $charset . '?B?' . base64_encode( $subject ) . '?='; |
418 | 418 | } |
419 | 419 | } |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | |
430 | 430 | if ( apply_filters( 'frm_echo_emails', false ) ) { |
431 | 431 | $temp = str_replace( '<', '<', $sent_to ); |
432 | - echo ' ' . FrmAppHelper::kses( implode(', ', (array) $temp ) ); |
|
432 | + echo ' ' . FrmAppHelper::kses( implode( ', ', (array) $temp ) ); |
|
433 | 433 | } |
434 | 434 | return $sent_to; |
435 | 435 | } |
@@ -1,388 +1,388 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('ABSPATH') ) { |
3 | - die('You are not allowed to call this page directly.'); |
|
3 | + die('You are not allowed to call this page directly.'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | class FrmForm { |
7 | 7 | |
8 | - /** |
|
9 | - * @return int|boolean id on success or false on failure |
|
10 | - */ |
|
11 | - public static function create( $values ) { |
|
12 | - global $wpdb; |
|
8 | + /** |
|
9 | + * @return int|boolean id on success or false on failure |
|
10 | + */ |
|
11 | + public static function create( $values ) { |
|
12 | + global $wpdb; |
|
13 | 13 | |
14 | - $new_values = array( |
|
14 | + $new_values = array( |
|
15 | 15 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
16 | - 'name' => $values['name'], |
|
17 | - 'description' => $values['description'], |
|
18 | - 'status' => isset($values['status']) ? $values['status'] : 'draft', |
|
19 | - 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0, |
|
20 | - 'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0, |
|
16 | + 'name' => $values['name'], |
|
17 | + 'description' => $values['description'], |
|
18 | + 'status' => isset($values['status']) ? $values['status'] : 'draft', |
|
19 | + 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0, |
|
20 | + 'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0, |
|
21 | 21 | 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0, |
22 | - 'editable' => isset($values['editable']) ? (int) $values['editable'] : 0, |
|
23 | - 'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0, |
|
24 | - 'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1), |
|
25 | - ); |
|
22 | + 'editable' => isset($values['editable']) ? (int) $values['editable'] : 0, |
|
23 | + 'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0, |
|
24 | + 'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1), |
|
25 | + ); |
|
26 | 26 | |
27 | 27 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
28 | 28 | FrmFormsHelper::fill_form_options( $options, $values ); |
29 | 29 | |
30 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
31 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
32 | - $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
30 | + $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
31 | + $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
32 | + $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
33 | 33 | |
34 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
35 | - $new_values['options'] = serialize($options); |
|
34 | + $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
35 | + $new_values['options'] = serialize($options); |
|
36 | 36 | |
37 | - //if(isset($values['id']) && is_numeric($values['id'])) |
|
38 | - // $new_values['id'] = $values['id']; |
|
37 | + //if(isset($values['id']) && is_numeric($values['id'])) |
|
38 | + // $new_values['id'] = $values['id']; |
|
39 | 39 | |
40 | 40 | $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
41 | 41 | |
42 | - $id = $wpdb->insert_id; |
|
42 | + $id = $wpdb->insert_id; |
|
43 | 43 | |
44 | 44 | // Clear form caching |
45 | 45 | self::clear_form_cache(); |
46 | 46 | |
47 | - return $id; |
|
48 | - } |
|
47 | + return $id; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return int|boolean ID on success or false on failure |
|
52 | - */ |
|
53 | - public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
|
54 | - global $wpdb; |
|
50 | + /** |
|
51 | + * @return int|boolean ID on success or false on failure |
|
52 | + */ |
|
53 | + public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
|
54 | + global $wpdb; |
|
55 | 55 | |
56 | - $values = self::getOne( $id, $blog_id ); |
|
57 | - if ( ! $values ) { |
|
58 | - return false; |
|
59 | - } |
|
56 | + $values = self::getOne( $id, $blog_id ); |
|
57 | + if ( ! $values ) { |
|
58 | + return false; |
|
59 | + } |
|
60 | 60 | |
61 | - $new_key = $copy_keys ? $values->form_key : ''; |
|
61 | + $new_key = $copy_keys ? $values->form_key : ''; |
|
62 | 62 | |
63 | - $new_values = array( |
|
63 | + $new_values = array( |
|
64 | 64 | 'form_key' => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ), |
65 | - 'name' => $values->name, |
|
66 | - 'description' => $values->description, |
|
67 | - 'status' => $template ? 'published' : 'draft', |
|
68 | - 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
|
69 | - 'editable' => $values->editable ? $values->editable : 0, |
|
70 | - 'created_at' => current_time('mysql', 1), |
|
71 | - 'is_template' => $template ? 1 : 0, |
|
72 | - ); |
|
73 | - |
|
74 | - if ( $blog_id ) { |
|
75 | - $new_values['status'] = 'published'; |
|
76 | - $new_options = maybe_unserialize($values->options); |
|
77 | - $new_options['email_to'] = get_option('admin_email'); |
|
78 | - $new_options['copy'] = false; |
|
79 | - $new_values['options'] = $new_options; |
|
80 | - } else { |
|
81 | - $new_values['options'] = $values->options; |
|
82 | - } |
|
83 | - |
|
84 | - if ( is_array($new_values['options']) ) { |
|
85 | - $new_values['options'] = serialize($new_values['options']); |
|
86 | - } |
|
65 | + 'name' => $values->name, |
|
66 | + 'description' => $values->description, |
|
67 | + 'status' => $template ? 'published' : 'draft', |
|
68 | + 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
|
69 | + 'editable' => $values->editable ? $values->editable : 0, |
|
70 | + 'created_at' => current_time('mysql', 1), |
|
71 | + 'is_template' => $template ? 1 : 0, |
|
72 | + ); |
|
73 | + |
|
74 | + if ( $blog_id ) { |
|
75 | + $new_values['status'] = 'published'; |
|
76 | + $new_options = maybe_unserialize($values->options); |
|
77 | + $new_options['email_to'] = get_option('admin_email'); |
|
78 | + $new_options['copy'] = false; |
|
79 | + $new_values['options'] = $new_options; |
|
80 | + } else { |
|
81 | + $new_values['options'] = $values->options; |
|
82 | + } |
|
83 | + |
|
84 | + if ( is_array($new_values['options']) ) { |
|
85 | + $new_values['options'] = serialize($new_values['options']); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
89 | 89 | |
90 | - if ( $query_results ) { |
|
90 | + if ( $query_results ) { |
|
91 | 91 | // Clear form caching |
92 | 92 | self::clear_form_cache(); |
93 | 93 | |
94 | - $form_id = $wpdb->insert_id; |
|
95 | - FrmField::duplicate($id, $form_id, $copy_keys, $blog_id); |
|
94 | + $form_id = $wpdb->insert_id; |
|
95 | + FrmField::duplicate($id, $form_id, $copy_keys, $blog_id); |
|
96 | 96 | |
97 | - // update form settings after fields are created |
|
97 | + // update form settings after fields are created |
|
98 | 98 | do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) ); |
99 | - return $form_id; |
|
100 | - } |
|
99 | + return $form_id; |
|
100 | + } |
|
101 | 101 | |
102 | - return false; |
|
103 | - } |
|
102 | + return false; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | public static function after_duplicate( $form_id, $values ) { |
106 | 106 | $new_opts = maybe_unserialize( $values['options'] ); |
107 | 107 | $values['options'] = $new_opts; |
108 | 108 | |
109 | - if ( isset($new_opts['success_msg']) ) { |
|
110 | - $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); |
|
111 | - } |
|
109 | + if ( isset($new_opts['success_msg']) ) { |
|
110 | + $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); |
|
111 | + } |
|
112 | 112 | |
113 | - $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); |
|
113 | + $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); |
|
114 | 114 | |
115 | - if ( $new_opts != $values['options'] ) { |
|
116 | - global $wpdb; |
|
115 | + if ( $new_opts != $values['options'] ) { |
|
116 | + global $wpdb; |
|
117 | 117 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) ); |
118 | - } |
|
119 | - } |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @return int|boolean |
|
123 | - */ |
|
124 | - public static function update( $id, $values, $create_link = false ) { |
|
125 | - global $wpdb; |
|
121 | + /** |
|
122 | + * @return int|boolean |
|
123 | + */ |
|
124 | + public static function update( $id, $values, $create_link = false ) { |
|
125 | + global $wpdb; |
|
126 | 126 | |
127 | - if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
128 | - $values['status'] = 'published'; |
|
129 | - } |
|
127 | + if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
128 | + $values['status'] = 'published'; |
|
129 | + } |
|
130 | 130 | |
131 | - if ( isset($values['form_key']) ) { |
|
131 | + if ( isset($values['form_key']) ) { |
|
132 | 132 | $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id ); |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
|
135 | + $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
|
136 | 136 | |
137 | - $new_values = self::set_update_options( array(), $values); |
|
137 | + $new_values = self::set_update_options( array(), $values); |
|
138 | 138 | |
139 | - foreach ( $values as $value_key => $value ) { |
|
139 | + foreach ( $values as $value_key => $value ) { |
|
140 | 140 | if ( $value_key && in_array( $value_key, $form_fields ) ) { |
141 | 141 | $new_values[ $value_key ] = $value; |
142 | - } |
|
143 | - } |
|
142 | + } |
|
143 | + } |
|
144 | 144 | |
145 | - if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
146 | - $new_values['status'] = $values['new_status']; |
|
147 | - } |
|
145 | + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
146 | + $new_values['status'] = $values['new_status']; |
|
147 | + } |
|
148 | 148 | |
149 | - if ( ! empty( $new_values ) ) { |
|
149 | + if ( ! empty( $new_values ) ) { |
|
150 | 150 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) ); |
151 | - if ( $query_results ) { |
|
151 | + if ( $query_results ) { |
|
152 | 152 | self::clear_form_cache(); |
153 | - } |
|
154 | - } else { |
|
155 | - $query_results = true; |
|
156 | - } |
|
157 | - unset($new_values); |
|
153 | + } |
|
154 | + } else { |
|
155 | + $query_results = true; |
|
156 | + } |
|
157 | + unset($new_values); |
|
158 | 158 | |
159 | - $values = self::update_fields($id, $values); |
|
159 | + $values = self::update_fields($id, $values); |
|
160 | 160 | |
161 | 161 | do_action( 'frm_update_form', $id, $values ); |
162 | 162 | do_action( 'frm_update_form_' . $id, $values ); |
163 | 163 | |
164 | - return $query_results; |
|
165 | - } |
|
164 | + return $query_results; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @return array |
|
169 | - */ |
|
167 | + /** |
|
168 | + * @return array |
|
169 | + */ |
|
170 | 170 | public static function set_update_options( $new_values, $values ) { |
171 | - if ( ! isset($values['options']) ) { |
|
172 | - return $new_values; |
|
173 | - } |
|
171 | + if ( ! isset($values['options']) ) { |
|
172 | + return $new_values; |
|
173 | + } |
|
174 | 174 | |
175 | 175 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
176 | 176 | FrmFormsHelper::fill_form_options( $options, $values ); |
177 | 177 | |
178 | - $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; |
|
179 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
180 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
181 | - $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
178 | + $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; |
|
179 | + $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
180 | + $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
181 | + $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
182 | 182 | |
183 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
184 | - $new_values['options'] = serialize($options); |
|
183 | + $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
184 | + $new_values['options'] = serialize($options); |
|
185 | 185 | |
186 | - return $new_values; |
|
187 | - } |
|
186 | + return $new_values; |
|
187 | + } |
|
188 | 188 | |
189 | 189 | |
190 | - /** |
|
191 | - * @return array |
|
192 | - */ |
|
190 | + /** |
|
191 | + * @return array |
|
192 | + */ |
|
193 | 193 | public static function update_fields( $id, $values ) { |
194 | 194 | |
195 | - if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) { |
|
196 | - return $values; |
|
197 | - } |
|
195 | + if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) { |
|
196 | + return $values; |
|
197 | + } |
|
198 | 198 | |
199 | - $all_fields = FrmField::get_all_for_form($id); |
|
200 | - if ( empty($all_fields) ) { |
|
201 | - return $values; |
|
202 | - } |
|
199 | + $all_fields = FrmField::get_all_for_form($id); |
|
200 | + if ( empty($all_fields) ) { |
|
201 | + return $values; |
|
202 | + } |
|
203 | 203 | |
204 | - if ( ! isset($values['item_meta']) ) { |
|
205 | - $values['item_meta'] = array(); |
|
206 | - } |
|
204 | + if ( ! isset($values['item_meta']) ) { |
|
205 | + $values['item_meta'] = array(); |
|
206 | + } |
|
207 | 207 | |
208 | - $field_array = array(); |
|
209 | - $existing_keys = array_keys($values['item_meta']); |
|
210 | - foreach ( $all_fields as $fid ) { |
|
211 | - if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) { |
|
208 | + $field_array = array(); |
|
209 | + $existing_keys = array_keys($values['item_meta']); |
|
210 | + foreach ( $all_fields as $fid ) { |
|
211 | + if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) { |
|
212 | 212 | $values['item_meta'][ $fid->id ] = ''; |
213 | - } |
|
213 | + } |
|
214 | 214 | $field_array[ $fid->id ] = $fid; |
215 | - } |
|
216 | - unset($all_fields); |
|
215 | + } |
|
216 | + unset($all_fields); |
|
217 | 217 | |
218 | - foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
218 | + foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
219 | 219 | if ( isset( $field_array[ $field_id ] ) ) { |
220 | 220 | $field = $field_array[ $field_id ]; |
221 | - } else { |
|
222 | - $field = FrmField::getOne($field_id); |
|
223 | - } |
|
221 | + } else { |
|
222 | + $field = FrmField::getOne($field_id); |
|
223 | + } |
|
224 | 224 | |
225 | - if ( ! $field ) { |
|
226 | - continue; |
|
227 | - } |
|
225 | + if ( ! $field ) { |
|
226 | + continue; |
|
227 | + } |
|
228 | 228 | |
229 | 229 | $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
230 | 230 | if ( $is_settings_page ) { |
231 | - //updating the settings page |
|
231 | + //updating the settings page |
|
232 | 232 | if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
233 | 233 | $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) ); |
234 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
234 | + $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
235 | 235 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
236 | - } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
|
237 | - $prev_opts = $field->field_options; |
|
238 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
239 | - if ( $prev_opts != $field->field_options ) { |
|
236 | + } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
|
237 | + $prev_opts = $field->field_options; |
|
238 | + $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
239 | + if ( $prev_opts != $field->field_options ) { |
|
240 | 240 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
241 | - } |
|
242 | - unset($prev_opts); |
|
243 | - } |
|
244 | - } |
|
241 | + } |
|
242 | + unset($prev_opts); |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | 246 | if ( $is_settings_page && ! defined( 'WP_IMPORTING' ) ) { |
247 | - continue; |
|
248 | - } |
|
247 | + continue; |
|
248 | + } |
|
249 | 249 | |
250 | - //updating the form |
|
250 | + //updating the form |
|
251 | 251 | $update_options = FrmFieldsHelper::get_default_field_opts( $field->type, $field, true ); |
252 | 252 | unset( $update_options['custom_html'] ); // don't check for POST html |
253 | 253 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
254 | 254 | |
255 | 255 | foreach ( $update_options as $opt => $default ) { |
256 | 256 | $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default; |
257 | - } |
|
257 | + } |
|
258 | 258 | |
259 | - $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
259 | + $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
260 | 260 | $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
261 | 261 | $field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key; |
262 | 262 | $required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false; |
263 | 263 | $field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type; |
264 | 264 | $field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description; |
265 | 265 | |
266 | - FrmField::update($field_id, array( |
|
267 | - 'field_key' => $field_key, 'type' => $field_type, |
|
268 | - 'default_value' => $default_value, 'field_options' => $field->field_options, |
|
269 | - 'description' => $field_description, 'required' => $required, |
|
270 | - ) ); |
|
266 | + FrmField::update($field_id, array( |
|
267 | + 'field_key' => $field_key, 'type' => $field_type, |
|
268 | + 'default_value' => $default_value, 'field_options' => $field->field_options, |
|
269 | + 'description' => $field_description, 'required' => $required, |
|
270 | + ) ); |
|
271 | 271 | |
272 | - FrmField::delete_form_transient($field->form_id); |
|
273 | - } |
|
272 | + FrmField::delete_form_transient($field->form_id); |
|
273 | + } |
|
274 | 274 | self::clear_form_cache(); |
275 | 275 | |
276 | - return $values; |
|
277 | - } |
|
276 | + return $values; |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * @param string $status |
|
281 | - * @return int|boolean |
|
282 | - */ |
|
279 | + /** |
|
280 | + * @param string $status |
|
281 | + * @return int|boolean |
|
282 | + */ |
|
283 | 283 | public static function set_status( $id, $status ) { |
284 | - if ( 'trash' == $status ) { |
|
285 | - return self::trash($id); |
|
286 | - } |
|
284 | + if ( 'trash' == $status ) { |
|
285 | + return self::trash($id); |
|
286 | + } |
|
287 | 287 | |
288 | 288 | $statuses = array( 'published', 'draft', 'trash' ); |
289 | - if ( ! in_array( $status, $statuses ) ) { |
|
290 | - return false; |
|
291 | - } |
|
289 | + if ( ! in_array( $status, $statuses ) ) { |
|
290 | + return false; |
|
291 | + } |
|
292 | 292 | |
293 | - global $wpdb; |
|
293 | + global $wpdb; |
|
294 | 294 | |
295 | - if ( is_array($id) ) { |
|
295 | + if ( is_array($id) ) { |
|
296 | 296 | $where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 ); |
297 | 297 | FrmDb::get_where_clause_and_values( $where ); |
298 | 298 | array_unshift( $where['values'], $status ); |
299 | 299 | |
300 | 300 | $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); |
301 | - } else { |
|
301 | + } else { |
|
302 | 302 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
303 | 303 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) ); |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | - if ( $query_results ) { |
|
306 | + if ( $query_results ) { |
|
307 | 307 | self::clear_form_cache(); |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - return $query_results; |
|
311 | - } |
|
310 | + return $query_results; |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * @return int|boolean |
|
315 | - */ |
|
313 | + /** |
|
314 | + * @return int|boolean |
|
315 | + */ |
|
316 | 316 | public static function trash( $id ) { |
317 | - if ( ! EMPTY_TRASH_DAYS ) { |
|
318 | - return self::destroy( $id ); |
|
319 | - } |
|
317 | + if ( ! EMPTY_TRASH_DAYS ) { |
|
318 | + return self::destroy( $id ); |
|
319 | + } |
|
320 | 320 | |
321 | - $form = self::getOne($id); |
|
322 | - if ( ! $form ) { |
|
323 | - return false; |
|
324 | - } |
|
321 | + $form = self::getOne($id); |
|
322 | + if ( ! $form ) { |
|
323 | + return false; |
|
324 | + } |
|
325 | 325 | |
326 | - $options = $form->options; |
|
327 | - $options['trash_time'] = time(); |
|
326 | + $options = $form->options; |
|
327 | + $options['trash_time'] = time(); |
|
328 | 328 | |
329 | - global $wpdb; |
|
330 | - $query_results = $wpdb->update( |
|
329 | + global $wpdb; |
|
330 | + $query_results = $wpdb->update( |
|
331 | 331 | $wpdb->prefix . 'frm_forms', |
332 | 332 | array( 'status' => 'trash', 'options' => serialize( $options ) ), |
333 | 333 | array( 'id' => $id ) |
334 | - ); |
|
334 | + ); |
|
335 | 335 | |
336 | - $wpdb->update( |
|
336 | + $wpdb->update( |
|
337 | 337 | $wpdb->prefix . 'frm_forms', |
338 | 338 | array( 'status' => 'trash', 'options' => serialize( $options ) ), |
339 | 339 | array( 'parent_form_id' => $id ) |
340 | - ); |
|
340 | + ); |
|
341 | 341 | |
342 | - if ( $query_results ) { |
|
342 | + if ( $query_results ) { |
|
343 | 343 | self::clear_form_cache(); |
344 | - } |
|
344 | + } |
|
345 | 345 | |
346 | - return $query_results; |
|
347 | - } |
|
346 | + return $query_results; |
|
347 | + } |
|
348 | 348 | |
349 | - /** |
|
350 | - * @return int|boolean |
|
351 | - */ |
|
349 | + /** |
|
350 | + * @return int|boolean |
|
351 | + */ |
|
352 | 352 | public static function destroy( $id ) { |
353 | - global $wpdb; |
|
353 | + global $wpdb; |
|
354 | 354 | |
355 | - $form = self::getOne($id); |
|
356 | - if ( ! $form ) { |
|
357 | - return false; |
|
358 | - } |
|
355 | + $form = self::getOne($id); |
|
356 | + if ( ! $form ) { |
|
357 | + return false; |
|
358 | + } |
|
359 | 359 | $id = $form->id; |
360 | 360 | |
361 | - // Disconnect the entries from this form |
|
361 | + // Disconnect the entries from this form |
|
362 | 362 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
363 | - foreach ( $entries as $entry_id ) { |
|
364 | - FrmEntry::destroy($entry_id); |
|
365 | - unset($entry_id); |
|
366 | - } |
|
363 | + foreach ( $entries as $entry_id ) { |
|
364 | + FrmEntry::destroy($entry_id); |
|
365 | + unset($entry_id); |
|
366 | + } |
|
367 | 367 | |
368 | - // Disconnect the fields from this form |
|
368 | + // Disconnect the fields from this form |
|
369 | 369 | $wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) ); |
370 | 370 | |
371 | 371 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
372 | - if ( $query_results ) { |
|
373 | - // Delete all form actions linked to this form |
|
374 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
375 | - $action_control->destroy($id, 'all'); |
|
372 | + if ( $query_results ) { |
|
373 | + // Delete all form actions linked to this form |
|
374 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
375 | + $action_control->destroy($id, 'all'); |
|
376 | 376 | |
377 | 377 | // Clear form caching |
378 | 378 | self::clear_form_cache(); |
379 | 379 | |
380 | 380 | do_action( 'frm_destroy_form', $id ); |
381 | 381 | do_action( 'frm_destroy_form_' . $id ); |
382 | - } |
|
382 | + } |
|
383 | 383 | |
384 | - return $query_results; |
|
385 | - } |
|
384 | + return $query_results; |
|
385 | + } |
|
386 | 386 | |
387 | 387 | /** |
388 | 388 | * Delete trashed forms based on how long they have been trashed |
@@ -414,49 +414,49 @@ discard block |
||
414 | 414 | return $count; |
415 | 415 | } |
416 | 416 | |
417 | - /** |
|
418 | - * @return string form name |
|
419 | - */ |
|
420 | - public static function &getName( $id ) { |
|
421 | - global $wpdb; |
|
422 | - |
|
423 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
424 | - if ( $form ) { |
|
425 | - $r = stripslashes($form->name); |
|
426 | - return $r; |
|
427 | - } |
|
428 | - |
|
429 | - $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
430 | - $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
431 | - $r = stripslashes($r); |
|
432 | - |
|
433 | - return $r; |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * @param string $key |
|
438 | - * @return int form id |
|
439 | - */ |
|
417 | + /** |
|
418 | + * @return string form name |
|
419 | + */ |
|
420 | + public static function &getName( $id ) { |
|
421 | + global $wpdb; |
|
422 | + |
|
423 | + $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
424 | + if ( $form ) { |
|
425 | + $r = stripslashes($form->name); |
|
426 | + return $r; |
|
427 | + } |
|
428 | + |
|
429 | + $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
430 | + $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
431 | + $r = stripslashes($r); |
|
432 | + |
|
433 | + return $r; |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * @param string $key |
|
438 | + * @return int form id |
|
439 | + */ |
|
440 | 440 | public static function &getIdByKey( $key ) { |
441 | - $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
442 | - return $id; |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * @param int $id |
|
447 | - * @return string form key |
|
448 | - */ |
|
441 | + $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
442 | + return $id; |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * @param int $id |
|
447 | + * @return string form key |
|
448 | + */ |
|
449 | 449 | public static function &getKeyById( $id ) { |
450 | - $id = (int) $id; |
|
451 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
452 | - if ( $cache ) { |
|
453 | - return $cache->form_key; |
|
454 | - } |
|
450 | + $id = (int) $id; |
|
451 | + $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
452 | + if ( $cache ) { |
|
453 | + return $cache->form_key; |
|
454 | + } |
|
455 | 455 | |
456 | - $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
456 | + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
457 | 457 | |
458 | - return $key; |
|
459 | - } |
|
458 | + return $key; |
|
459 | + } |
|
460 | 460 | |
461 | 461 | /** |
462 | 462 | * If $form is numeric, get the form object |
@@ -469,47 +469,47 @@ discard block |
||
469 | 469 | } |
470 | 470 | } |
471 | 471 | |
472 | - /** |
|
473 | - * @return object form |
|
474 | - */ |
|
475 | - public static function getOne( $id, $blog_id = false ) { |
|
476 | - global $wpdb; |
|
472 | + /** |
|
473 | + * @return object form |
|
474 | + */ |
|
475 | + public static function getOne( $id, $blog_id = false ) { |
|
476 | + global $wpdb; |
|
477 | 477 | |
478 | - if ( $blog_id && is_multisite() ) { |
|
479 | - global $wpmuBaseTablePrefix; |
|
478 | + if ( $blog_id && is_multisite() ) { |
|
479 | + global $wpmuBaseTablePrefix; |
|
480 | 480 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); |
481 | 481 | |
482 | 482 | $table_name = $prefix . 'frm_forms'; |
483 | - } else { |
|
483 | + } else { |
|
484 | 484 | $table_name = $wpdb->prefix . 'frm_forms'; |
485 | - $cache = wp_cache_get($id, 'frm_form'); |
|
486 | - if ( $cache ) { |
|
487 | - if ( isset($cache->options) ) { |
|
488 | - $cache->options = maybe_unserialize($cache->options); |
|
489 | - } |
|
485 | + $cache = wp_cache_get($id, 'frm_form'); |
|
486 | + if ( $cache ) { |
|
487 | + if ( isset($cache->options) ) { |
|
488 | + $cache->options = maybe_unserialize($cache->options); |
|
489 | + } |
|
490 | 490 | |
491 | - return stripslashes_deep($cache); |
|
492 | - } |
|
493 | - } |
|
491 | + return stripslashes_deep($cache); |
|
492 | + } |
|
493 | + } |
|
494 | 494 | |
495 | - if ( is_numeric($id) ) { |
|
496 | - $where = array( 'id' => $id ); |
|
497 | - } else { |
|
498 | - $where = array( 'form_key' => $id ); |
|
499 | - } |
|
495 | + if ( is_numeric($id) ) { |
|
496 | + $where = array( 'id' => $id ); |
|
497 | + } else { |
|
498 | + $where = array( 'form_key' => $id ); |
|
499 | + } |
|
500 | 500 | |
501 | - $results = FrmDb::get_row( $table_name, $where ); |
|
501 | + $results = FrmDb::get_row( $table_name, $where ); |
|
502 | 502 | |
503 | - if ( isset($results->options) ) { |
|
503 | + if ( isset($results->options) ) { |
|
504 | 504 | FrmAppHelper::set_cache( $results->id, $results, 'frm_form' ); |
505 | - $results->options = maybe_unserialize($results->options); |
|
506 | - } |
|
507 | - return stripslashes_deep($results); |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * @return object|array of objects |
|
512 | - */ |
|
505 | + $results->options = maybe_unserialize($results->options); |
|
506 | + } |
|
507 | + return stripslashes_deep($results); |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * @return object|array of objects |
|
512 | + */ |
|
513 | 513 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
514 | 514 | if ( is_array( $where ) && ! empty( $where ) ) { |
515 | 515 | $results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) ); |
@@ -533,8 +533,8 @@ discard block |
||
533 | 533 | $results = reset( $results ); |
534 | 534 | } |
535 | 535 | |
536 | - return stripslashes_deep($results); |
|
537 | - } |
|
536 | + return stripslashes_deep($results); |
|
537 | + } |
|
538 | 538 | |
539 | 539 | /** |
540 | 540 | * Get all published forms |
@@ -552,47 +552,47 @@ discard block |
||
552 | 552 | return $forms; |
553 | 553 | } |
554 | 554 | |
555 | - /** |
|
556 | - * @return int count of forms |
|
557 | - */ |
|
558 | - public static function &get_count() { |
|
559 | - global $wpdb; |
|
555 | + /** |
|
556 | + * @return int count of forms |
|
557 | + */ |
|
558 | + public static function &get_count() { |
|
559 | + global $wpdb; |
|
560 | 560 | |
561 | - $cache_key = 'frm_form_counts'; |
|
561 | + $cache_key = 'frm_form_counts'; |
|
562 | 562 | |
563 | - $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
564 | - if ( false !== $counts ) { |
|
565 | - return $counts; |
|
566 | - } |
|
563 | + $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
564 | + if ( false !== $counts ) { |
|
565 | + return $counts; |
|
566 | + } |
|
567 | 567 | |
568 | - $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
568 | + $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
569 | 569 | |
570 | 570 | $statuses = array( 'published', 'draft', 'template', 'trash' ); |
571 | - $counts = array_fill_keys( $statuses, 0 ); |
|
571 | + $counts = array_fill_keys( $statuses, 0 ); |
|
572 | 572 | |
573 | - foreach ( $results as $row ) { |
|
574 | - if ( 'trash' != $row->status ) { |
|
575 | - if ( $row->is_template ) { |
|
573 | + foreach ( $results as $row ) { |
|
574 | + if ( 'trash' != $row->status ) { |
|
575 | + if ( $row->is_template ) { |
|
576 | 576 | $counts['template']++; |
577 | - } else { |
|
577 | + } else { |
|
578 | 578 | $counts['published']++; |
579 | - } |
|
580 | - } else { |
|
579 | + } |
|
580 | + } else { |
|
581 | 581 | $counts['trash']++; |
582 | - } |
|
582 | + } |
|
583 | 583 | |
584 | - if ( 'draft' == $row->status ) { |
|
584 | + if ( 'draft' == $row->status ) { |
|
585 | 585 | $counts['draft']++; |
586 | - } |
|
586 | + } |
|
587 | 587 | |
588 | - unset($row); |
|
589 | - } |
|
588 | + unset($row); |
|
589 | + } |
|
590 | 590 | |
591 | - $counts = (object) $counts; |
|
591 | + $counts = (object) $counts; |
|
592 | 592 | FrmAppHelper::set_cache( $cache_key, $counts, 'frm_form' ); |
593 | 593 | |
594 | - return $counts; |
|
595 | - } |
|
594 | + return $counts; |
|
595 | + } |
|
596 | 596 | |
597 | 597 | /** |
598 | 598 | * Clear form caching |
@@ -605,14 +605,14 @@ discard block |
||
605 | 605 | FrmAppHelper::cache_delete_group( 'frm_form' ); |
606 | 606 | } |
607 | 607 | |
608 | - /** |
|
609 | - * @return array of errors |
|
610 | - */ |
|
608 | + /** |
|
609 | + * @return array of errors |
|
610 | + */ |
|
611 | 611 | public static function validate( $values ) { |
612 | - $errors = array(); |
|
612 | + $errors = array(); |
|
613 | 613 | |
614 | - return apply_filters('frm_validate_form', $errors, $values); |
|
615 | - } |
|
614 | + return apply_filters('frm_validate_form', $errors, $values); |
|
615 | + } |
|
616 | 616 | |
617 | 617 | public static function get_params( $form = null ) { |
618 | 618 | global $frm_vars; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
3 | - die('You are not allowed to call this page directly.'); |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + die( 'You are not allowed to call this page directly.' ); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | class FrmForm { |
@@ -15,24 +15,24 @@ discard block |
||
15 | 15 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
16 | 16 | 'name' => $values['name'], |
17 | 17 | 'description' => $values['description'], |
18 | - 'status' => isset($values['status']) ? $values['status'] : 'draft', |
|
19 | - 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0, |
|
20 | - 'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0, |
|
18 | + 'status' => isset( $values['status'] ) ? $values['status'] : 'draft', |
|
19 | + 'logged_in' => isset( $values['logged_in'] ) ? $values['logged_in'] : 0, |
|
20 | + 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0, |
|
21 | 21 | 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0, |
22 | - 'editable' => isset($values['editable']) ? (int) $values['editable'] : 0, |
|
23 | - 'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0, |
|
24 | - 'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1), |
|
22 | + 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0, |
|
23 | + 'default_template' => isset( $values['default_template'] ) ? (int) $values['default_template'] : 0, |
|
24 | + 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ), |
|
25 | 25 | ); |
26 | 26 | |
27 | 27 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
28 | 28 | FrmFormsHelper::fill_form_options( $options, $values ); |
29 | 29 | |
30 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
31 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
32 | - $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
30 | + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); |
|
31 | + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); |
|
32 | + $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); |
|
33 | 33 | |
34 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
35 | - $new_values['options'] = serialize($options); |
|
34 | + $options = apply_filters( 'frm_form_options_before_update', $options, $values ); |
|
35 | + $new_values['options'] = serialize( $options ); |
|
36 | 36 | |
37 | 37 | //if(isset($values['id']) && is_numeric($values['id'])) |
38 | 38 | // $new_values['id'] = $values['id']; |
@@ -67,22 +67,22 @@ discard block |
||
67 | 67 | 'status' => $template ? 'published' : 'draft', |
68 | 68 | 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
69 | 69 | 'editable' => $values->editable ? $values->editable : 0, |
70 | - 'created_at' => current_time('mysql', 1), |
|
70 | + 'created_at' => current_time( 'mysql', 1 ), |
|
71 | 71 | 'is_template' => $template ? 1 : 0, |
72 | 72 | ); |
73 | 73 | |
74 | 74 | if ( $blog_id ) { |
75 | 75 | $new_values['status'] = 'published'; |
76 | - $new_options = maybe_unserialize($values->options); |
|
77 | - $new_options['email_to'] = get_option('admin_email'); |
|
76 | + $new_options = maybe_unserialize( $values->options ); |
|
77 | + $new_options['email_to'] = get_option( 'admin_email' ); |
|
78 | 78 | $new_options['copy'] = false; |
79 | 79 | $new_values['options'] = $new_options; |
80 | 80 | } else { |
81 | 81 | $new_values['options'] = $values->options; |
82 | 82 | } |
83 | 83 | |
84 | - if ( is_array($new_values['options']) ) { |
|
85 | - $new_values['options'] = serialize($new_values['options']); |
|
84 | + if ( is_array( $new_values['options'] ) ) { |
|
85 | + $new_values['options'] = serialize( $new_values['options'] ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | self::clear_form_cache(); |
93 | 93 | |
94 | 94 | $form_id = $wpdb->insert_id; |
95 | - FrmField::duplicate($id, $form_id, $copy_keys, $blog_id); |
|
95 | + FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id ); |
|
96 | 96 | |
97 | 97 | // update form settings after fields are created |
98 | 98 | do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) ); |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | $new_opts = maybe_unserialize( $values['options'] ); |
107 | 107 | $values['options'] = $new_opts; |
108 | 108 | |
109 | - if ( isset($new_opts['success_msg']) ) { |
|
110 | - $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); |
|
109 | + if ( isset( $new_opts['success_msg'] ) ) { |
|
110 | + $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids( $new_opts['success_msg'] ); |
|
111 | 111 | } |
112 | 112 | |
113 | - $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); |
|
113 | + $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id ); |
|
114 | 114 | |
115 | 115 | if ( $new_opts != $values['options'] ) { |
116 | 116 | global $wpdb; |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | $values['status'] = 'published'; |
129 | 129 | } |
130 | 130 | |
131 | - if ( isset($values['form_key']) ) { |
|
131 | + if ( isset( $values['form_key'] ) ) { |
|
132 | 132 | $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id ); |
133 | 133 | } |
134 | 134 | |
135 | 135 | $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
136 | 136 | |
137 | - $new_values = self::set_update_options( array(), $values); |
|
137 | + $new_values = self::set_update_options( array(), $values ); |
|
138 | 138 | |
139 | 139 | foreach ( $values as $value_key => $value ) { |
140 | 140 | if ( $value_key && in_array( $value_key, $form_fields ) ) { |
141 | - $new_values[ $value_key ] = $value; |
|
141 | + $new_values[$value_key] = $value; |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | } else { |
155 | 155 | $query_results = true; |
156 | 156 | } |
157 | - unset($new_values); |
|
157 | + unset( $new_values ); |
|
158 | 158 | |
159 | - $values = self::update_fields($id, $values); |
|
159 | + $values = self::update_fields( $id, $values ); |
|
160 | 160 | |
161 | 161 | do_action( 'frm_update_form', $id, $values ); |
162 | 162 | do_action( 'frm_update_form_' . $id, $values ); |
@@ -168,20 +168,20 @@ discard block |
||
168 | 168 | * @return array |
169 | 169 | */ |
170 | 170 | public static function set_update_options( $new_values, $values ) { |
171 | - if ( ! isset($values['options']) ) { |
|
171 | + if ( ! isset( $values['options'] ) ) { |
|
172 | 172 | return $new_values; |
173 | 173 | } |
174 | 174 | |
175 | 175 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
176 | 176 | FrmFormsHelper::fill_form_options( $options, $values ); |
177 | 177 | |
178 | - $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; |
|
179 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
180 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
181 | - $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
178 | + $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0; |
|
179 | + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); |
|
180 | + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); |
|
181 | + $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && $values['options']['submit_html'] != '' ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); |
|
182 | 182 | |
183 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
184 | - $new_values['options'] = serialize($options); |
|
183 | + $options = apply_filters( 'frm_form_options_before_update', $options, $values ); |
|
184 | + $new_values['options'] = serialize( $options ); |
|
185 | 185 | |
186 | 186 | return $new_values; |
187 | 187 | } |
@@ -192,54 +192,54 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public static function update_fields( $id, $values ) { |
194 | 194 | |
195 | - if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) { |
|
195 | + if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) { |
|
196 | 196 | return $values; |
197 | 197 | } |
198 | 198 | |
199 | - $all_fields = FrmField::get_all_for_form($id); |
|
200 | - if ( empty($all_fields) ) { |
|
199 | + $all_fields = FrmField::get_all_for_form( $id ); |
|
200 | + if ( empty( $all_fields ) ) { |
|
201 | 201 | return $values; |
202 | 202 | } |
203 | 203 | |
204 | - if ( ! isset($values['item_meta']) ) { |
|
204 | + if ( ! isset( $values['item_meta'] ) ) { |
|
205 | 205 | $values['item_meta'] = array(); |
206 | 206 | } |
207 | 207 | |
208 | 208 | $field_array = array(); |
209 | - $existing_keys = array_keys($values['item_meta']); |
|
209 | + $existing_keys = array_keys( $values['item_meta'] ); |
|
210 | 210 | foreach ( $all_fields as $fid ) { |
211 | - if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) { |
|
212 | - $values['item_meta'][ $fid->id ] = ''; |
|
211 | + if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) { |
|
212 | + $values['item_meta'][$fid->id] = ''; |
|
213 | 213 | } |
214 | - $field_array[ $fid->id ] = $fid; |
|
214 | + $field_array[$fid->id] = $fid; |
|
215 | 215 | } |
216 | - unset($all_fields); |
|
216 | + unset( $all_fields ); |
|
217 | 217 | |
218 | 218 | foreach ( $values['item_meta'] as $field_id => $default_value ) { |
219 | - if ( isset( $field_array[ $field_id ] ) ) { |
|
220 | - $field = $field_array[ $field_id ]; |
|
219 | + if ( isset( $field_array[$field_id] ) ) { |
|
220 | + $field = $field_array[$field_id]; |
|
221 | 221 | } else { |
222 | - $field = FrmField::getOne($field_id); |
|
222 | + $field = FrmField::getOne( $field_id ); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | if ( ! $field ) { |
226 | 226 | continue; |
227 | 227 | } |
228 | 228 | |
229 | - $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
|
229 | + $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ); |
|
230 | 230 | if ( $is_settings_page ) { |
231 | 231 | //updating the settings page |
232 | - if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
|
233 | - $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) ); |
|
234 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
232 | + if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) { |
|
233 | + $field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field_id] ) ? $values['field_options']['custom_html_' . $field_id] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) ); |
|
234 | + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
|
235 | 235 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
236 | 236 | } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
237 | 237 | $prev_opts = $field->field_options; |
238 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
238 | + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
|
239 | 239 | if ( $prev_opts != $field->field_options ) { |
240 | 240 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
241 | 241 | } |
242 | - unset($prev_opts); |
|
242 | + unset( $prev_opts ); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
@@ -253,23 +253,23 @@ discard block |
||
253 | 253 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
254 | 254 | |
255 | 255 | foreach ( $update_options as $opt => $default ) { |
256 | - $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default; |
|
256 | + $field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( sanitize_text_field( $values['field_options'][$opt . '_' . $field_id] ) ) : $default; |
|
257 | 257 | } |
258 | 258 | |
259 | - $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
260 | - $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
|
261 | - $field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key; |
|
262 | - $required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false; |
|
263 | - $field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type; |
|
264 | - $field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description; |
|
259 | + $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
|
260 | + $default_value = maybe_serialize( $values['item_meta'][$field_id] ); |
|
261 | + $field_key = isset( $values['field_options']['field_key_' . $field_id] ) ? $values['field_options']['field_key_' . $field_id] : $field->field_key; |
|
262 | + $required = isset( $values['field_options']['required_' . $field_id] ) ? $values['field_options']['required_' . $field_id] : false; |
|
263 | + $field_type = isset( $values['field_options']['type_' . $field_id] ) ? $values['field_options']['type_' . $field_id] : $field->type; |
|
264 | + $field_description = isset( $values['field_options']['description_' . $field_id] ) ? $values['field_options']['description_' . $field_id] : $field->description; |
|
265 | 265 | |
266 | - FrmField::update($field_id, array( |
|
266 | + FrmField::update( $field_id, array( |
|
267 | 267 | 'field_key' => $field_key, 'type' => $field_type, |
268 | 268 | 'default_value' => $default_value, 'field_options' => $field->field_options, |
269 | 269 | 'description' => $field_description, 'required' => $required, |
270 | 270 | ) ); |
271 | 271 | |
272 | - FrmField::delete_form_transient($field->form_id); |
|
272 | + FrmField::delete_form_transient( $field->form_id ); |
|
273 | 273 | } |
274 | 274 | self::clear_form_cache(); |
275 | 275 | |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public static function set_status( $id, $status ) { |
284 | 284 | if ( 'trash' == $status ) { |
285 | - return self::trash($id); |
|
285 | + return self::trash( $id ); |
|
286 | 286 | } |
287 | 287 | |
288 | - $statuses = array( 'published', 'draft', 'trash' ); |
|
288 | + $statuses = array( 'published', 'draft', 'trash' ); |
|
289 | 289 | if ( ! in_array( $status, $statuses ) ) { |
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | 293 | global $wpdb; |
294 | 294 | |
295 | - if ( is_array($id) ) { |
|
295 | + if ( is_array( $id ) ) { |
|
296 | 296 | $where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 ); |
297 | 297 | FrmDb::get_where_clause_and_values( $where ); |
298 | 298 | array_unshift( $where['values'], $status ); |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | return self::destroy( $id ); |
319 | 319 | } |
320 | 320 | |
321 | - $form = self::getOne($id); |
|
321 | + $form = self::getOne( $id ); |
|
322 | 322 | if ( ! $form ) { |
323 | 323 | return false; |
324 | 324 | } |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | public static function destroy( $id ) { |
353 | 353 | global $wpdb; |
354 | 354 | |
355 | - $form = self::getOne($id); |
|
355 | + $form = self::getOne( $id ); |
|
356 | 356 | if ( ! $form ) { |
357 | 357 | return false; |
358 | 358 | } |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | // Disconnect the entries from this form |
362 | 362 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
363 | 363 | foreach ( $entries as $entry_id ) { |
364 | - FrmEntry::destroy($entry_id); |
|
365 | - unset($entry_id); |
|
364 | + FrmEntry::destroy( $entry_id ); |
|
365 | + unset( $entry_id ); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | // Disconnect the fields from this form |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | if ( $query_results ) { |
373 | 373 | // Delete all form actions linked to this form |
374 | 374 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
375 | - $action_control->destroy($id, 'all'); |
|
375 | + $action_control->destroy( $id, 'all' ); |
|
376 | 376 | |
377 | 377 | // Clear form caching |
378 | 378 | self::clear_form_cache(); |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | $form->options = maybe_unserialize( $form->options ); |
407 | 407 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
408 | 408 | self::destroy( $form->id ); |
409 | - $count++; |
|
409 | + $count ++; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | unset( $form ); |
@@ -420,15 +420,15 @@ discard block |
||
420 | 420 | public static function &getName( $id ) { |
421 | 421 | global $wpdb; |
422 | 422 | |
423 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
423 | + $form = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
424 | 424 | if ( $form ) { |
425 | - $r = stripslashes($form->name); |
|
425 | + $r = stripslashes( $form->name ); |
|
426 | 426 | return $r; |
427 | 427 | } |
428 | 428 | |
429 | 429 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
430 | 430 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
431 | - $r = stripslashes($r); |
|
431 | + $r = stripslashes( $r ); |
|
432 | 432 | |
433 | 433 | return $r; |
434 | 434 | } |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | */ |
449 | 449 | public static function &getKeyById( $id ) { |
450 | 450 | $id = (int) $id; |
451 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
451 | + $cache = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
452 | 452 | if ( $cache ) { |
453 | 453 | return $cache->form_key; |
454 | 454 | } |
@@ -482,17 +482,17 @@ discard block |
||
482 | 482 | $table_name = $prefix . 'frm_forms'; |
483 | 483 | } else { |
484 | 484 | $table_name = $wpdb->prefix . 'frm_forms'; |
485 | - $cache = wp_cache_get($id, 'frm_form'); |
|
485 | + $cache = wp_cache_get( $id, 'frm_form' ); |
|
486 | 486 | if ( $cache ) { |
487 | - if ( isset($cache->options) ) { |
|
488 | - $cache->options = maybe_unserialize($cache->options); |
|
487 | + if ( isset( $cache->options ) ) { |
|
488 | + $cache->options = maybe_unserialize( $cache->options ); |
|
489 | 489 | } |
490 | 490 | |
491 | - return stripslashes_deep($cache); |
|
491 | + return stripslashes_deep( $cache ); |
|
492 | 492 | } |
493 | 493 | } |
494 | 494 | |
495 | - if ( is_numeric($id) ) { |
|
495 | + if ( is_numeric( $id ) ) { |
|
496 | 496 | $where = array( 'id' => $id ); |
497 | 497 | } else { |
498 | 498 | $where = array( 'form_key' => $id ); |
@@ -500,11 +500,11 @@ discard block |
||
500 | 500 | |
501 | 501 | $results = FrmDb::get_row( $table_name, $where ); |
502 | 502 | |
503 | - if ( isset($results->options) ) { |
|
503 | + if ( isset( $results->options ) ) { |
|
504 | 504 | FrmAppHelper::set_cache( $results->id, $results, 'frm_form' ); |
505 | - $results->options = maybe_unserialize($results->options); |
|
505 | + $results->options = maybe_unserialize( $results->options ); |
|
506 | 506 | } |
507 | - return stripslashes_deep($results); |
|
507 | + return stripslashes_deep( $results ); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $results = reset( $results ); |
534 | 534 | } |
535 | 535 | |
536 | - return stripslashes_deep($results); |
|
536 | + return stripslashes_deep( $results ); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -573,19 +573,19 @@ discard block |
||
573 | 573 | foreach ( $results as $row ) { |
574 | 574 | if ( 'trash' != $row->status ) { |
575 | 575 | if ( $row->is_template ) { |
576 | - $counts['template']++; |
|
576 | + $counts['template'] ++; |
|
577 | 577 | } else { |
578 | - $counts['published']++; |
|
578 | + $counts['published'] ++; |
|
579 | 579 | } |
580 | 580 | } else { |
581 | - $counts['trash']++; |
|
581 | + $counts['trash'] ++; |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | if ( 'draft' == $row->status ) { |
585 | - $counts['draft']++; |
|
585 | + $counts['draft'] ++; |
|
586 | 586 | } |
587 | 587 | |
588 | - unset($row); |
|
588 | + unset( $row ); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | $counts = (object) $counts; |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | public static function validate( $values ) { |
612 | 612 | $errors = array(); |
613 | 613 | |
614 | - return apply_filters('frm_validate_form', $errors, $values); |
|
614 | + return apply_filters( 'frm_validate_form', $errors, $values ); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | public static function get_params( $form = null ) { |
@@ -623,11 +623,11 @@ discard block |
||
623 | 623 | self::maybe_get_form( $form ); |
624 | 624 | } |
625 | 625 | |
626 | - if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
|
627 | - return $frm_vars['form_params'][ $form->id ]; |
|
626 | + if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) { |
|
627 | + return $frm_vars['form_params'][$form->id]; |
|
628 | 628 | } |
629 | 629 | |
630 | - $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
630 | + $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
631 | 631 | $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form ); |
632 | 632 | |
633 | 633 | $default_values = array( |
@@ -645,15 +645,15 @@ discard block |
||
645 | 645 | //if there are two forms on the same page, make sure not to submit both |
646 | 646 | foreach ( $default_values as $var => $default ) { |
647 | 647 | if ( $var == 'action' ) { |
648 | - $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
648 | + $values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
649 | 649 | } else { |
650 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
650 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
651 | 651 | } |
652 | 652 | unset( $var, $default ); |
653 | 653 | } |
654 | 654 | } else { |
655 | 655 | foreach ( $default_values as $var => $default ) { |
656 | - $values[ $var ] = $default; |
|
656 | + $values[$var] = $default; |
|
657 | 657 | unset( $var, $default ); |
658 | 658 | } |
659 | 659 | } |
@@ -668,7 +668,7 @@ discard block |
||
668 | 668 | public static function list_page_params() { |
669 | 669 | $values = array(); |
670 | 670 | foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) { |
671 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
671 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | return $values; |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '', |
689 | 689 | 'keep_post' => '', |
690 | 690 | ) as $var => $default ) { |
691 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
691 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | return $values; |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | $small_form = new stdClass(); |
731 | 731 | foreach ( array( 'id', 'form_key', 'name' ) as $var ) { |
732 | 732 | $small_form->{$var} = $form->{$var}; |
733 | - unset($var); |
|
733 | + unset( $var ); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | $frm_vars['forms_loaded'][] = $small_form; |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | $frm_vars['load_css'] = true; |
741 | 741 | } |
742 | 742 | |
743 | - return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
743 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | public static function show_submit( $form ) { |
@@ -1,27 +1,27 @@ 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 | 19 | if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) { |
20 | 20 | $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
21 | 21 | $_POST['item_key'] = $values['item_key']; |
22 | 22 | } |
23 | 23 | |
24 | - $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
24 | + $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
25 | 25 | // Don't get subfields |
26 | 26 | $where['fr.parent_form_id'] = array( null, 0 ); |
27 | 27 | // Don't get excluded fields (like file upload fields in the ajax validation) |
@@ -29,42 +29,42 @@ discard block |
||
29 | 29 | $where['fi.type not'] = $exclude; |
30 | 30 | } |
31 | 31 | |
32 | - $posted_fields = FrmField::getAll($where, 'field_order'); |
|
32 | + $posted_fields = FrmField::getAll($where, 'field_order'); |
|
33 | 33 | |
34 | - // Pass exclude value to validate_field function so it can be used for repeating sections |
|
35 | - $args = array( 'exclude' => $exclude ); |
|
34 | + // Pass exclude value to validate_field function so it can be used for repeating sections |
|
35 | + $args = array( 'exclude' => $exclude ); |
|
36 | 36 | |
37 | - foreach ( $posted_fields as $posted_field ) { |
|
38 | - self::validate_field($posted_field, $errors, $values, $args); |
|
39 | - unset($posted_field); |
|
40 | - } |
|
37 | + foreach ( $posted_fields as $posted_field ) { |
|
38 | + self::validate_field($posted_field, $errors, $values, $args); |
|
39 | + unset($posted_field); |
|
40 | + } |
|
41 | 41 | |
42 | - // check for spam |
|
43 | - self::spam_check( $exclude, $values, $errors ); |
|
42 | + // check for spam |
|
43 | + self::spam_check( $exclude, $values, $errors ); |
|
44 | 44 | |
45 | - $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
45 | + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
46 | 46 | |
47 | - return $errors; |
|
48 | - } |
|
47 | + return $errors; |
|
48 | + } |
|
49 | 49 | |
50 | - public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
51 | - $defaults = array( |
|
52 | - 'id' => $posted_field->id, |
|
53 | - 'parent_field_id' => '', // the id of the repeat or embed form |
|
54 | - 'key_pointer' => '', // the pointer in the posted array |
|
55 | - 'exclude' => array(), // exclude these field types from validation |
|
56 | - ); |
|
57 | - $args = wp_parse_args( $args, $defaults ); |
|
50 | + public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
51 | + $defaults = array( |
|
52 | + 'id' => $posted_field->id, |
|
53 | + 'parent_field_id' => '', // the id of the repeat or embed form |
|
54 | + 'key_pointer' => '', // the pointer in the posted array |
|
55 | + 'exclude' => array(), // exclude these field types from validation |
|
56 | + ); |
|
57 | + $args = wp_parse_args( $args, $defaults ); |
|
58 | 58 | |
59 | - if ( empty($args['parent_field_id']) ) { |
|
59 | + if ( empty($args['parent_field_id']) ) { |
|
60 | 60 | $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
61 | - } else { |
|
62 | - // value is from a nested form |
|
63 | - $value = $values; |
|
64 | - } |
|
61 | + } else { |
|
62 | + // value is from a nested form |
|
63 | + $value = $values; |
|
64 | + } |
|
65 | 65 | |
66 | - // Check for values in "Other" fields |
|
67 | - FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
66 | + // Check for values in "Other" fields |
|
67 | + FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
68 | 68 | |
69 | 69 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
70 | 70 | |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | $value = reset($value); |
74 | 74 | } |
75 | 75 | |
76 | - if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
76 | + if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
77 | 77 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
78 | - } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
79 | - $_POST['item_name'] = $value; |
|
80 | - } |
|
78 | + } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
79 | + $_POST['item_name'] = $value; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | if ( $value != '' ) { |
83 | 83 | self::validate_url_field( $errors, $posted_field, $value, $args ); |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
87 | 87 | } |
88 | 88 | |
89 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
89 | + FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
90 | 90 | |
91 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
91 | + self::validate_recaptcha($errors, $posted_field, $args); |
|
92 | 92 | |
93 | 93 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
94 | 94 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | 97 | private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) { |
98 | 98 | if ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value ) { |
@@ -102,32 +102,32 @@ discard block |
||
102 | 102 | |
103 | 103 | public static function validate_url_field( &$errors, $field, &$value, $args ) { |
104 | 104 | if ( $value == '' || ! in_array( $field->type, array( 'website', 'url', 'image' ) ) ) { |
105 | - return; |
|
106 | - } |
|
105 | + return; |
|
106 | + } |
|
107 | 107 | |
108 | - if ( trim($value) == 'http://' ) { |
|
109 | - $value = ''; |
|
110 | - } else { |
|
111 | - $value = esc_url_raw( $value ); |
|
108 | + if ( trim($value) == 'http://' ) { |
|
109 | + $value = ''; |
|
110 | + } else { |
|
111 | + $value = esc_url_raw( $value ); |
|
112 | 112 | $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'http://' . $value; |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - // validate the url format |
|
115 | + // validate the url format |
|
116 | 116 | if ( ! preg_match('/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value) ) { |
117 | 117 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
118 | 118 | } |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | public static function validate_email_field( &$errors, $field, $value, $args ) { |
122 | - if ( $value == '' || $field->type != 'email' ) { |
|
123 | - return; |
|
124 | - } |
|
122 | + if ( $value == '' || $field->type != 'email' ) { |
|
123 | + return; |
|
124 | + } |
|
125 | 125 | |
126 | - //validate the email format |
|
127 | - if ( ! is_email($value) ) { |
|
126 | + //validate the email format |
|
127 | + if ( ! is_email($value) ) { |
|
128 | 128 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
129 | - } |
|
130 | - } |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | 132 | public static function validate_number_field( &$errors, $field, $value, $args ) { |
133 | 133 | //validate the number format |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | } |
222 | 222 | |
223 | 223 | public static function validate_recaptcha( &$errors, $field, $args ) { |
224 | - if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
225 | - return; |
|
226 | - } |
|
224 | + if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | $frm_settings = FrmAppHelper::get_settings(); |
229 | 229 | if ( empty( $frm_settings->pubkey ) ) { |
@@ -231,57 +231,57 @@ discard block |
||
231 | 231 | return; |
232 | 232 | } |
233 | 233 | |
234 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
235 | - // If captcha is missing, check if it was already verified |
|
234 | + if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
235 | + // If captcha is missing, check if it was already verified |
|
236 | 236 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
237 | - // There was no captcha submitted |
|
237 | + // There was no captcha submitted |
|
238 | 238 | $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
239 | - } |
|
240 | - return; |
|
241 | - } |
|
239 | + } |
|
240 | + return; |
|
241 | + } |
|
242 | 242 | |
243 | - $arg_array = array( |
|
244 | - 'body' => array( |
|
243 | + $arg_array = array( |
|
244 | + 'body' => array( |
|
245 | 245 | 'secret' => $frm_settings->privkey, |
246 | 246 | 'response' => $_POST['g-recaptcha-response'], |
247 | 247 | 'remoteip' => FrmAppHelper::get_ip_address(), |
248 | 248 | ), |
249 | 249 | ); |
250 | - $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
251 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
250 | + $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
251 | + $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
252 | 252 | |
253 | - if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
254 | - // What happens when the CAPTCHA was entered incorrectly |
|
253 | + if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
254 | + // What happens when the CAPTCHA was entered incorrectly |
|
255 | 255 | $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
256 | - } else if ( is_wp_error( $resp ) ) { |
|
256 | + } else if ( is_wp_error( $resp ) ) { |
|
257 | 257 | $error_string = $resp->get_error_message(); |
258 | 258 | $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
259 | 259 | $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * check for spam |
|
265 | - * @param boolean $exclude |
|
266 | - * @param array $values |
|
267 | - * @param array $errors by reference |
|
268 | - */ |
|
269 | - public static function spam_check( $exclude, $values, &$errors ) { |
|
270 | - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
271 | - // only check spam if there are no other errors |
|
272 | - return; |
|
273 | - } |
|
274 | - |
|
275 | - if ( self::blacklist_check( $values ) ) { |
|
276 | - $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
277 | - } |
|
278 | - |
|
279 | - if ( self::is_akismet_spam( $values ) ) { |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * check for spam |
|
265 | + * @param boolean $exclude |
|
266 | + * @param array $values |
|
267 | + * @param array $errors by reference |
|
268 | + */ |
|
269 | + public static function spam_check( $exclude, $values, &$errors ) { |
|
270 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
271 | + // only check spam if there are no other errors |
|
272 | + return; |
|
273 | + } |
|
274 | + |
|
275 | + if ( self::blacklist_check( $values ) ) { |
|
276 | + $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
277 | + } |
|
278 | + |
|
279 | + if ( self::is_akismet_spam( $values ) ) { |
|
280 | 280 | if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) { |
281 | 281 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
282 | 282 | } |
283 | - } |
|
284 | - } |
|
283 | + } |
|
284 | + } |
|
285 | 285 | |
286 | 286 | private static function is_akismet_spam( $values ) { |
287 | 287 | global $wpcom_api_key; |
@@ -293,15 +293,15 @@ discard block |
||
293 | 293 | return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ); |
294 | 294 | } |
295 | 295 | |
296 | - public static function blacklist_check( $values ) { |
|
297 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
298 | - return false; |
|
299 | - } |
|
296 | + public static function blacklist_check( $values ) { |
|
297 | + if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
298 | + return false; |
|
299 | + } |
|
300 | 300 | |
301 | - $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
302 | - if ( empty( $mod_keys ) ) { |
|
303 | - return false; |
|
304 | - } |
|
301 | + $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
302 | + if ( empty( $mod_keys ) ) { |
|
303 | + return false; |
|
304 | + } |
|
305 | 305 | |
306 | 306 | $content = FrmEntriesHelper::entry_array_to_string( $values ); |
307 | 307 | if ( empty( $content ) ) { |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | $user_info = self::get_spam_check_user_info( $values ); |
314 | 314 | |
315 | 315 | return wp_blacklist_check( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent ); |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * Check entries for Akismet spam |
@@ -7,12 +7,12 @@ 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 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | $_POST['item_key'] = $values['item_key']; |
22 | 22 | } |
23 | 23 | |
24 | - $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
24 | + $where = apply_filters( 'frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
25 | 25 | // Don't get subfields |
26 | 26 | $where['fr.parent_form_id'] = array( null, 0 ); |
27 | 27 | // Don't get excluded fields (like file upload fields in the ajax validation) |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | $where['fi.type not'] = $exclude; |
30 | 30 | } |
31 | 31 | |
32 | - $posted_fields = FrmField::getAll($where, 'field_order'); |
|
32 | + $posted_fields = FrmField::getAll( $where, 'field_order' ); |
|
33 | 33 | |
34 | 34 | // Pass exclude value to validate_field function so it can be used for repeating sections |
35 | 35 | $args = array( 'exclude' => $exclude ); |
36 | 36 | |
37 | 37 | foreach ( $posted_fields as $posted_field ) { |
38 | - self::validate_field($posted_field, $errors, $values, $args); |
|
39 | - unset($posted_field); |
|
38 | + self::validate_field( $posted_field, $errors, $values, $args ); |
|
39 | + unset( $posted_field ); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | // check for spam |
43 | 43 | self::spam_check( $exclude, $values, $errors ); |
44 | 44 | |
45 | - $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
45 | + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude' ) ); |
|
46 | 46 | |
47 | 47 | return $errors; |
48 | 48 | } |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | ); |
57 | 57 | $args = wp_parse_args( $args, $defaults ); |
58 | 58 | |
59 | - if ( empty($args['parent_field_id']) ) { |
|
60 | - $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
|
59 | + if ( empty( $args['parent_field_id'] ) ) { |
|
60 | + $value = isset( $values['item_meta'][$args['id']] ) ? $values['item_meta'][$args['id']] : ''; |
|
61 | 61 | } else { |
62 | 62 | // value is from a nested form |
63 | 63 | $value = $values; |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
70 | 70 | |
71 | 71 | // Reset arrays with only one value if it's not a field where array keys need to be preserved |
72 | - if ( is_array($value) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
73 | - $value = reset($value); |
|
72 | + if ( is_array( $value ) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
73 | + $value = reset( $value ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
77 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
77 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
78 | 78 | } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
79 | 79 | $_POST['item_name'] = $value; |
80 | 80 | } |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
87 | 87 | } |
88 | 88 | |
89 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
89 | + FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
|
90 | 90 | |
91 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
91 | + self::validate_recaptcha( $errors, $posted_field, $args ); |
|
92 | 92 | |
93 | 93 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
94 | 94 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | return; |
106 | 106 | } |
107 | 107 | |
108 | - if ( trim($value) == 'http://' ) { |
|
108 | + if ( trim( $value ) == 'http://' ) { |
|
109 | 109 | $value = ''; |
110 | 110 | } else { |
111 | 111 | $value = esc_url_raw( $value ); |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | // validate the url format |
116 | - if ( ! preg_match('/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value) ) { |
|
117 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
116 | + if ( ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) { |
|
117 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | //validate the email format |
127 | - if ( ! is_email($value) ) { |
|
128 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
127 | + if ( ! is_email( $value ) ) { |
|
128 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | return; |
136 | 136 | } |
137 | 137 | |
138 | - if ( ! is_numeric( $value) ) { |
|
139 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
138 | + if ( ! is_numeric( $value ) ) { |
|
139 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // validate number settings |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | if ( $frm_settings->use_html && isset( $field->field_options['minnum'] ) && isset( $field->field_options['maxnum'] ) ) { |
147 | 147 | //minnum maxnum |
148 | 148 | if ( (float) $value < $field->field_options['minnum'] ) { |
149 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' ); |
|
149 | + $errors['field' . $args['id']] = __( 'Please select a higher number', 'formidable' ); |
|
150 | 150 | } else if ( (float) $value > $field->field_options['maxnum'] ) { |
151 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' ); |
|
151 | + $errors['field' . $args['id']] = __( 'Please select a lower number', 'formidable' ); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $pattern = self::phone_format( $field ); |
161 | 161 | |
162 | 162 | if ( ! preg_match( $pattern, $value ) ) { |
163 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
163 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | } |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | return; |
232 | 232 | } |
233 | 233 | |
234 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
234 | + if ( ! isset( $_POST['g-recaptcha-response'] ) ) { |
|
235 | 235 | // If captcha is missing, check if it was already verified |
236 | 236 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
237 | 237 | // There was no captcha submitted |
238 | - $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
|
238 | + $errors['field' . $args['id']] = __( 'The captcha is missing from this form', 'formidable' ); |
|
239 | 239 | } |
240 | 240 | return; |
241 | 241 | } |
@@ -248,15 +248,15 @@ discard block |
||
248 | 248 | ), |
249 | 249 | ); |
250 | 250 | $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
251 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
251 | + $response = json_decode( wp_remote_retrieve_body( $resp ), true ); |
|
252 | 252 | |
253 | 253 | if ( isset( $response['success'] ) && ! $response['success'] ) { |
254 | 254 | // What happens when the CAPTCHA was entered incorrectly |
255 | - $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
255 | + $errors['field' . $args['id']] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
256 | 256 | } else if ( is_wp_error( $resp ) ) { |
257 | 257 | $error_string = $resp->get_error_message(); |
258 | - $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
259 | - $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
|
258 | + $errors['field' . $args['id']] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
259 | + $errors['field' . $args['id']] .= ' ' . $error_string; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | |
286 | 286 | private static function is_akismet_spam( $values ) { |
287 | 287 | global $wpcom_api_key; |
288 | - return ( is_callable('Akismet::http_post') && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet( $values ) ); |
|
288 | + return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) ); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | private static function is_akismet_enabled_for_user( $form_id ) { |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | public static function blacklist_check( $values ) { |
297 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
297 | + if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) { |
|
298 | 298 | return false; |
299 | 299 | } |
300 | 300 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
351 | 351 | $datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false; |
352 | 352 | $datas['blog_lang'] = get_locale(); |
353 | - $datas['blog_charset'] = get_option('blog_charset'); |
|
353 | + $datas['blog_charset'] = get_option( 'blog_charset' ); |
|
354 | 354 | |
355 | 355 | if ( akismet_test_mode() ) { |
356 | 356 | $datas['is_test'] = 'true'; |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | |
405 | 405 | // Send any potentially useful $_SERVER vars, but avoid sending junk we don't need. |
406 | 406 | if ( $include_value ) { |
407 | - $datas[ $key ] = $value; |
|
407 | + $datas[$key] = $value; |
|
408 | 408 | } |
409 | 409 | unset( $key, $value ); |
410 | 410 | } |