@@ -1,262 +1,262 @@ 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 | 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 | |
262 | 262 | $new_field = array( |
@@ -268,12 +268,12 @@ discard block |
||
268 | 268 | |
269 | 269 | FrmField::update( $field_id, $new_field ); |
270 | 270 | |
271 | - FrmField::delete_form_transient($field->form_id); |
|
272 | - } |
|
271 | + FrmField::delete_form_transient($field->form_id); |
|
272 | + } |
|
273 | 273 | self::clear_form_cache(); |
274 | 274 | |
275 | - return $values; |
|
276 | - } |
|
275 | + return $values; |
|
276 | + } |
|
277 | 277 | |
278 | 278 | private static function prepare_field_update_values( $field, $values, &$new_field ) { |
279 | 279 | $field_cols = array( |
@@ -286,113 +286,113 @@ discard block |
||
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
289 | - /** |
|
290 | - * @param string $status |
|
291 | - * @return int|boolean |
|
292 | - */ |
|
289 | + /** |
|
290 | + * @param string $status |
|
291 | + * @return int|boolean |
|
292 | + */ |
|
293 | 293 | public static function set_status( $id, $status ) { |
294 | - if ( 'trash' == $status ) { |
|
295 | - return self::trash($id); |
|
296 | - } |
|
294 | + if ( 'trash' == $status ) { |
|
295 | + return self::trash($id); |
|
296 | + } |
|
297 | 297 | |
298 | 298 | $statuses = array( 'published', 'draft', 'trash' ); |
299 | - if ( ! in_array( $status, $statuses ) ) { |
|
300 | - return false; |
|
301 | - } |
|
299 | + if ( ! in_array( $status, $statuses ) ) { |
|
300 | + return false; |
|
301 | + } |
|
302 | 302 | |
303 | - global $wpdb; |
|
303 | + global $wpdb; |
|
304 | 304 | |
305 | - if ( is_array($id) ) { |
|
305 | + if ( is_array($id) ) { |
|
306 | 306 | $where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 ); |
307 | 307 | FrmDb::get_where_clause_and_values( $where ); |
308 | 308 | array_unshift( $where['values'], $status ); |
309 | 309 | |
310 | 310 | $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); |
311 | - } else { |
|
311 | + } else { |
|
312 | 312 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
313 | 313 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) ); |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | - if ( $query_results ) { |
|
316 | + if ( $query_results ) { |
|
317 | 317 | self::clear_form_cache(); |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - return $query_results; |
|
321 | - } |
|
320 | + return $query_results; |
|
321 | + } |
|
322 | 322 | |
323 | - /** |
|
324 | - * @return int|boolean |
|
325 | - */ |
|
323 | + /** |
|
324 | + * @return int|boolean |
|
325 | + */ |
|
326 | 326 | public static function trash( $id ) { |
327 | - if ( ! EMPTY_TRASH_DAYS ) { |
|
328 | - return self::destroy( $id ); |
|
329 | - } |
|
327 | + if ( ! EMPTY_TRASH_DAYS ) { |
|
328 | + return self::destroy( $id ); |
|
329 | + } |
|
330 | 330 | |
331 | - $form = self::getOne($id); |
|
332 | - if ( ! $form ) { |
|
333 | - return false; |
|
334 | - } |
|
331 | + $form = self::getOne($id); |
|
332 | + if ( ! $form ) { |
|
333 | + return false; |
|
334 | + } |
|
335 | 335 | |
336 | - $options = $form->options; |
|
337 | - $options['trash_time'] = time(); |
|
336 | + $options = $form->options; |
|
337 | + $options['trash_time'] = time(); |
|
338 | 338 | |
339 | - global $wpdb; |
|
340 | - $query_results = $wpdb->update( |
|
339 | + global $wpdb; |
|
340 | + $query_results = $wpdb->update( |
|
341 | 341 | $wpdb->prefix . 'frm_forms', |
342 | 342 | array( 'status' => 'trash', 'options' => serialize( $options ) ), |
343 | 343 | array( 'id' => $id ) |
344 | - ); |
|
344 | + ); |
|
345 | 345 | |
346 | - $wpdb->update( |
|
346 | + $wpdb->update( |
|
347 | 347 | $wpdb->prefix . 'frm_forms', |
348 | 348 | array( 'status' => 'trash', 'options' => serialize( $options ) ), |
349 | 349 | array( 'parent_form_id' => $id ) |
350 | - ); |
|
350 | + ); |
|
351 | 351 | |
352 | - if ( $query_results ) { |
|
352 | + if ( $query_results ) { |
|
353 | 353 | self::clear_form_cache(); |
354 | - } |
|
354 | + } |
|
355 | 355 | |
356 | - return $query_results; |
|
357 | - } |
|
356 | + return $query_results; |
|
357 | + } |
|
358 | 358 | |
359 | - /** |
|
360 | - * @return int|boolean |
|
361 | - */ |
|
359 | + /** |
|
360 | + * @return int|boolean |
|
361 | + */ |
|
362 | 362 | public static function destroy( $id ) { |
363 | - global $wpdb; |
|
363 | + global $wpdb; |
|
364 | 364 | |
365 | - $form = self::getOne($id); |
|
366 | - if ( ! $form ) { |
|
367 | - return false; |
|
368 | - } |
|
365 | + $form = self::getOne($id); |
|
366 | + if ( ! $form ) { |
|
367 | + return false; |
|
368 | + } |
|
369 | 369 | $id = $form->id; |
370 | 370 | |
371 | - // Disconnect the entries from this form |
|
371 | + // Disconnect the entries from this form |
|
372 | 372 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
373 | - foreach ( $entries as $entry_id ) { |
|
374 | - FrmEntry::destroy($entry_id); |
|
375 | - unset($entry_id); |
|
376 | - } |
|
373 | + foreach ( $entries as $entry_id ) { |
|
374 | + FrmEntry::destroy($entry_id); |
|
375 | + unset($entry_id); |
|
376 | + } |
|
377 | 377 | |
378 | - // Disconnect the fields from this form |
|
378 | + // Disconnect the fields from this form |
|
379 | 379 | $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 ) ); |
380 | 380 | |
381 | 381 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
382 | - if ( $query_results ) { |
|
383 | - // Delete all form actions linked to this form |
|
384 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
385 | - $action_control->destroy($id, 'all'); |
|
382 | + if ( $query_results ) { |
|
383 | + // Delete all form actions linked to this form |
|
384 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
385 | + $action_control->destroy($id, 'all'); |
|
386 | 386 | |
387 | 387 | // Clear form caching |
388 | 388 | self::clear_form_cache(); |
389 | 389 | |
390 | 390 | do_action( 'frm_destroy_form', $id ); |
391 | 391 | do_action( 'frm_destroy_form_' . $id ); |
392 | - } |
|
392 | + } |
|
393 | 393 | |
394 | - return $query_results; |
|
395 | - } |
|
394 | + return $query_results; |
|
395 | + } |
|
396 | 396 | |
397 | 397 | /** |
398 | 398 | * Delete trashed forms based on how long they have been trashed |
@@ -424,47 +424,47 @@ discard block |
||
424 | 424 | return $count; |
425 | 425 | } |
426 | 426 | |
427 | - /** |
|
428 | - * @return string form name |
|
429 | - */ |
|
430 | - public static function getName( $id ) { |
|
431 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
432 | - if ( $form ) { |
|
433 | - $r = stripslashes($form->name); |
|
434 | - return $r; |
|
435 | - } |
|
436 | - |
|
437 | - $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
438 | - $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
439 | - $r = stripslashes($r); |
|
440 | - |
|
441 | - return $r; |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * @param string $key |
|
446 | - * @return int form id |
|
447 | - */ |
|
427 | + /** |
|
428 | + * @return string form name |
|
429 | + */ |
|
430 | + public static function getName( $id ) { |
|
431 | + $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
432 | + if ( $form ) { |
|
433 | + $r = stripslashes($form->name); |
|
434 | + return $r; |
|
435 | + } |
|
436 | + |
|
437 | + $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
438 | + $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
439 | + $r = stripslashes($r); |
|
440 | + |
|
441 | + return $r; |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * @param string $key |
|
446 | + * @return int form id |
|
447 | + */ |
|
448 | 448 | public static function getIdByKey( $key ) { |
449 | - $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
450 | - return $id; |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * @param int $id |
|
455 | - * @return string form key |
|
456 | - */ |
|
449 | + $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
450 | + return $id; |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * @param int $id |
|
455 | + * @return string form key |
|
456 | + */ |
|
457 | 457 | public static function getKeyById( $id ) { |
458 | - $id = (int) $id; |
|
459 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
460 | - if ( $cache ) { |
|
461 | - return $cache->form_key; |
|
462 | - } |
|
458 | + $id = (int) $id; |
|
459 | + $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
460 | + if ( $cache ) { |
|
461 | + return $cache->form_key; |
|
462 | + } |
|
463 | 463 | |
464 | - $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
464 | + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
465 | 465 | |
466 | - return $key; |
|
467 | - } |
|
466 | + return $key; |
|
467 | + } |
|
468 | 468 | |
469 | 469 | /** |
470 | 470 | * If $form is numeric, get the form object |
@@ -477,47 +477,47 @@ discard block |
||
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
480 | - /** |
|
481 | - * @return object form |
|
482 | - */ |
|
483 | - public static function getOne( $id, $blog_id = false ) { |
|
484 | - global $wpdb; |
|
480 | + /** |
|
481 | + * @return object form |
|
482 | + */ |
|
483 | + public static function getOne( $id, $blog_id = false ) { |
|
484 | + global $wpdb; |
|
485 | 485 | |
486 | - if ( $blog_id && is_multisite() ) { |
|
487 | - global $wpmuBaseTablePrefix; |
|
486 | + if ( $blog_id && is_multisite() ) { |
|
487 | + global $wpmuBaseTablePrefix; |
|
488 | 488 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); |
489 | 489 | |
490 | 490 | $table_name = $prefix . 'frm_forms'; |
491 | - } else { |
|
491 | + } else { |
|
492 | 492 | $table_name = $wpdb->prefix . 'frm_forms'; |
493 | - $cache = wp_cache_get($id, 'frm_form'); |
|
494 | - if ( $cache ) { |
|
495 | - if ( isset($cache->options) ) { |
|
496 | - $cache->options = maybe_unserialize($cache->options); |
|
497 | - } |
|
493 | + $cache = wp_cache_get($id, 'frm_form'); |
|
494 | + if ( $cache ) { |
|
495 | + if ( isset($cache->options) ) { |
|
496 | + $cache->options = maybe_unserialize($cache->options); |
|
497 | + } |
|
498 | 498 | |
499 | - return stripslashes_deep($cache); |
|
500 | - } |
|
501 | - } |
|
499 | + return stripslashes_deep($cache); |
|
500 | + } |
|
501 | + } |
|
502 | 502 | |
503 | - if ( is_numeric($id) ) { |
|
504 | - $where = array( 'id' => $id ); |
|
505 | - } else { |
|
506 | - $where = array( 'form_key' => $id ); |
|
507 | - } |
|
503 | + if ( is_numeric($id) ) { |
|
504 | + $where = array( 'id' => $id ); |
|
505 | + } else { |
|
506 | + $where = array( 'form_key' => $id ); |
|
507 | + } |
|
508 | 508 | |
509 | - $results = FrmDb::get_row( $table_name, $where ); |
|
509 | + $results = FrmDb::get_row( $table_name, $where ); |
|
510 | 510 | |
511 | - if ( isset($results->options) ) { |
|
511 | + if ( isset($results->options) ) { |
|
512 | 512 | FrmAppHelper::set_cache( $results->id, $results, 'frm_form' ); |
513 | - $results->options = maybe_unserialize($results->options); |
|
514 | - } |
|
515 | - return stripslashes_deep($results); |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * @return object|array of objects |
|
520 | - */ |
|
513 | + $results->options = maybe_unserialize($results->options); |
|
514 | + } |
|
515 | + return stripslashes_deep($results); |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * @return object|array of objects |
|
520 | + */ |
|
521 | 521 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
522 | 522 | if ( is_array( $where ) && ! empty( $where ) ) { |
523 | 523 | $results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) ); |
@@ -541,8 +541,8 @@ discard block |
||
541 | 541 | $results = reset( $results ); |
542 | 542 | } |
543 | 543 | |
544 | - return stripslashes_deep($results); |
|
545 | - } |
|
544 | + return stripslashes_deep($results); |
|
545 | + } |
|
546 | 546 | |
547 | 547 | /** |
548 | 548 | * Get all published forms |
@@ -560,47 +560,47 @@ discard block |
||
560 | 560 | return $forms; |
561 | 561 | } |
562 | 562 | |
563 | - /** |
|
564 | - * @return int count of forms |
|
565 | - */ |
|
566 | - public static function get_count() { |
|
567 | - global $wpdb; |
|
563 | + /** |
|
564 | + * @return int count of forms |
|
565 | + */ |
|
566 | + public static function get_count() { |
|
567 | + global $wpdb; |
|
568 | 568 | |
569 | - $cache_key = 'frm_form_counts'; |
|
569 | + $cache_key = 'frm_form_counts'; |
|
570 | 570 | |
571 | - $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
572 | - if ( false !== $counts ) { |
|
573 | - return $counts; |
|
574 | - } |
|
571 | + $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
572 | + if ( false !== $counts ) { |
|
573 | + return $counts; |
|
574 | + } |
|
575 | 575 | |
576 | - $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
576 | + $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
577 | 577 | |
578 | 578 | $statuses = array( 'published', 'draft', 'template', 'trash' ); |
579 | - $counts = array_fill_keys( $statuses, 0 ); |
|
579 | + $counts = array_fill_keys( $statuses, 0 ); |
|
580 | 580 | |
581 | - foreach ( $results as $row ) { |
|
582 | - if ( 'trash' != $row->status ) { |
|
583 | - if ( $row->is_template ) { |
|
581 | + foreach ( $results as $row ) { |
|
582 | + if ( 'trash' != $row->status ) { |
|
583 | + if ( $row->is_template ) { |
|
584 | 584 | $counts['template']++; |
585 | - } else { |
|
585 | + } else { |
|
586 | 586 | $counts['published']++; |
587 | - } |
|
588 | - } else { |
|
587 | + } |
|
588 | + } else { |
|
589 | 589 | $counts['trash']++; |
590 | - } |
|
590 | + } |
|
591 | 591 | |
592 | - if ( 'draft' == $row->status ) { |
|
592 | + if ( 'draft' == $row->status ) { |
|
593 | 593 | $counts['draft']++; |
594 | - } |
|
594 | + } |
|
595 | 595 | |
596 | - unset($row); |
|
597 | - } |
|
596 | + unset($row); |
|
597 | + } |
|
598 | 598 | |
599 | - $counts = (object) $counts; |
|
599 | + $counts = (object) $counts; |
|
600 | 600 | FrmAppHelper::set_cache( $cache_key, $counts, 'frm_form' ); |
601 | 601 | |
602 | - return $counts; |
|
603 | - } |
|
602 | + return $counts; |
|
603 | + } |
|
604 | 604 | |
605 | 605 | /** |
606 | 606 | * Clear form caching |
@@ -613,14 +613,14 @@ discard block |
||
613 | 613 | FrmAppHelper::cache_delete_group( 'frm_form' ); |
614 | 614 | } |
615 | 615 | |
616 | - /** |
|
617 | - * @return array of errors |
|
618 | - */ |
|
616 | + /** |
|
617 | + * @return array of errors |
|
618 | + */ |
|
619 | 619 | public static function validate( $values ) { |
620 | - $errors = array(); |
|
620 | + $errors = array(); |
|
621 | 621 | |
622 | - return apply_filters('frm_validate_form', $errors, $values); |
|
623 | - } |
|
622 | + return apply_filters('frm_validate_form', $errors, $values); |
|
623 | + } |
|
624 | 624 | |
625 | 625 | public static function get_params( $form = null ) { |
626 | 626 | 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,11 +253,11 @@ 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 ] ); |
|
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 | 261 | |
262 | 262 | $new_field = array( |
263 | 263 | 'field_options' => $field->field_options, |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | |
269 | 269 | FrmField::update( $field_id, $new_field ); |
270 | 270 | |
271 | - FrmField::delete_form_transient($field->form_id); |
|
271 | + FrmField::delete_form_transient( $field->form_id ); |
|
272 | 272 | } |
273 | 273 | self::clear_form_cache(); |
274 | 274 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | ); |
283 | 283 | foreach ( $field_cols as $col => $default ) { |
284 | 284 | $default = ( $default === '' ) ? $field->{$col} : $default; |
285 | - $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; |
|
285 | + $new_field[$col] = isset( $values['field_options'][$col . '_' . $field->id] ) ? $values['field_options'][$col . '_' . $field->id] : $default; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
@@ -292,17 +292,17 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public static function set_status( $id, $status ) { |
294 | 294 | if ( 'trash' == $status ) { |
295 | - return self::trash($id); |
|
295 | + return self::trash( $id ); |
|
296 | 296 | } |
297 | 297 | |
298 | - $statuses = array( 'published', 'draft', 'trash' ); |
|
298 | + $statuses = array( 'published', 'draft', 'trash' ); |
|
299 | 299 | if ( ! in_array( $status, $statuses ) ) { |
300 | 300 | return false; |
301 | 301 | } |
302 | 302 | |
303 | 303 | global $wpdb; |
304 | 304 | |
305 | - if ( is_array($id) ) { |
|
305 | + if ( is_array( $id ) ) { |
|
306 | 306 | $where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 ); |
307 | 307 | FrmDb::get_where_clause_and_values( $where ); |
308 | 308 | array_unshift( $where['values'], $status ); |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | return self::destroy( $id ); |
329 | 329 | } |
330 | 330 | |
331 | - $form = self::getOne($id); |
|
331 | + $form = self::getOne( $id ); |
|
332 | 332 | if ( ! $form ) { |
333 | 333 | return false; |
334 | 334 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | public static function destroy( $id ) { |
363 | 363 | global $wpdb; |
364 | 364 | |
365 | - $form = self::getOne($id); |
|
365 | + $form = self::getOne( $id ); |
|
366 | 366 | if ( ! $form ) { |
367 | 367 | return false; |
368 | 368 | } |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | // Disconnect the entries from this form |
372 | 372 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
373 | 373 | foreach ( $entries as $entry_id ) { |
374 | - FrmEntry::destroy($entry_id); |
|
375 | - unset($entry_id); |
|
374 | + FrmEntry::destroy( $entry_id ); |
|
375 | + unset( $entry_id ); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | // Disconnect the fields from this form |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | if ( $query_results ) { |
383 | 383 | // Delete all form actions linked to this form |
384 | 384 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
385 | - $action_control->destroy($id, 'all'); |
|
385 | + $action_control->destroy( $id, 'all' ); |
|
386 | 386 | |
387 | 387 | // Clear form caching |
388 | 388 | self::clear_form_cache(); |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $form->options = maybe_unserialize( $form->options ); |
417 | 417 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
418 | 418 | self::destroy( $form->id ); |
419 | - $count++; |
|
419 | + $count ++; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | unset( $form ); |
@@ -428,15 +428,15 @@ discard block |
||
428 | 428 | * @return string form name |
429 | 429 | */ |
430 | 430 | public static function getName( $id ) { |
431 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
431 | + $form = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
432 | 432 | if ( $form ) { |
433 | - $r = stripslashes($form->name); |
|
433 | + $r = stripslashes( $form->name ); |
|
434 | 434 | return $r; |
435 | 435 | } |
436 | 436 | |
437 | 437 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
438 | 438 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
439 | - $r = stripslashes($r); |
|
439 | + $r = stripslashes( $r ); |
|
440 | 440 | |
441 | 441 | return $r; |
442 | 442 | } |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | */ |
457 | 457 | public static function getKeyById( $id ) { |
458 | 458 | $id = (int) $id; |
459 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
459 | + $cache = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
460 | 460 | if ( $cache ) { |
461 | 461 | return $cache->form_key; |
462 | 462 | } |
@@ -490,17 +490,17 @@ discard block |
||
490 | 490 | $table_name = $prefix . 'frm_forms'; |
491 | 491 | } else { |
492 | 492 | $table_name = $wpdb->prefix . 'frm_forms'; |
493 | - $cache = wp_cache_get($id, 'frm_form'); |
|
493 | + $cache = wp_cache_get( $id, 'frm_form' ); |
|
494 | 494 | if ( $cache ) { |
495 | - if ( isset($cache->options) ) { |
|
496 | - $cache->options = maybe_unserialize($cache->options); |
|
495 | + if ( isset( $cache->options ) ) { |
|
496 | + $cache->options = maybe_unserialize( $cache->options ); |
|
497 | 497 | } |
498 | 498 | |
499 | - return stripslashes_deep($cache); |
|
499 | + return stripslashes_deep( $cache ); |
|
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
503 | - if ( is_numeric($id) ) { |
|
503 | + if ( is_numeric( $id ) ) { |
|
504 | 504 | $where = array( 'id' => $id ); |
505 | 505 | } else { |
506 | 506 | $where = array( 'form_key' => $id ); |
@@ -508,11 +508,11 @@ discard block |
||
508 | 508 | |
509 | 509 | $results = FrmDb::get_row( $table_name, $where ); |
510 | 510 | |
511 | - if ( isset($results->options) ) { |
|
511 | + if ( isset( $results->options ) ) { |
|
512 | 512 | FrmAppHelper::set_cache( $results->id, $results, 'frm_form' ); |
513 | - $results->options = maybe_unserialize($results->options); |
|
513 | + $results->options = maybe_unserialize( $results->options ); |
|
514 | 514 | } |
515 | - return stripslashes_deep($results); |
|
515 | + return stripslashes_deep( $results ); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | $results = reset( $results ); |
542 | 542 | } |
543 | 543 | |
544 | - return stripslashes_deep($results); |
|
544 | + return stripslashes_deep( $results ); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -581,19 +581,19 @@ discard block |
||
581 | 581 | foreach ( $results as $row ) { |
582 | 582 | if ( 'trash' != $row->status ) { |
583 | 583 | if ( $row->is_template ) { |
584 | - $counts['template']++; |
|
584 | + $counts['template'] ++; |
|
585 | 585 | } else { |
586 | - $counts['published']++; |
|
586 | + $counts['published'] ++; |
|
587 | 587 | } |
588 | 588 | } else { |
589 | - $counts['trash']++; |
|
589 | + $counts['trash'] ++; |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | if ( 'draft' == $row->status ) { |
593 | - $counts['draft']++; |
|
593 | + $counts['draft'] ++; |
|
594 | 594 | } |
595 | 595 | |
596 | - unset($row); |
|
596 | + unset( $row ); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | $counts = (object) $counts; |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | public static function validate( $values ) { |
620 | 620 | $errors = array(); |
621 | 621 | |
622 | - return apply_filters('frm_validate_form', $errors, $values); |
|
622 | + return apply_filters( 'frm_validate_form', $errors, $values ); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | public static function get_params( $form = null ) { |
@@ -631,11 +631,11 @@ discard block |
||
631 | 631 | self::maybe_get_form( $form ); |
632 | 632 | } |
633 | 633 | |
634 | - if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
|
635 | - return $frm_vars['form_params'][ $form->id ]; |
|
634 | + if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) { |
|
635 | + return $frm_vars['form_params'][$form->id]; |
|
636 | 636 | } |
637 | 637 | |
638 | - $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
638 | + $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
639 | 639 | $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form ); |
640 | 640 | |
641 | 641 | $default_values = array( |
@@ -653,15 +653,15 @@ discard block |
||
653 | 653 | //if there are two forms on the same page, make sure not to submit both |
654 | 654 | foreach ( $default_values as $var => $default ) { |
655 | 655 | if ( $var == 'action' ) { |
656 | - $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
656 | + $values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
657 | 657 | } else { |
658 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
658 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
659 | 659 | } |
660 | 660 | unset( $var, $default ); |
661 | 661 | } |
662 | 662 | } else { |
663 | 663 | foreach ( $default_values as $var => $default ) { |
664 | - $values[ $var ] = $default; |
|
664 | + $values[$var] = $default; |
|
665 | 665 | unset( $var, $default ); |
666 | 666 | } |
667 | 667 | } |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | public static function list_page_params() { |
677 | 677 | $values = array(); |
678 | 678 | foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) { |
679 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
679 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | return $values; |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '', |
697 | 697 | 'keep_post' => '', |
698 | 698 | ) as $var => $default ) { |
699 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
699 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | return $values; |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | $small_form = new stdClass(); |
754 | 754 | foreach ( array( 'id', 'form_key', 'name' ) as $var ) { |
755 | 755 | $small_form->{$var} = $form->{$var}; |
756 | - unset($var); |
|
756 | + unset( $var ); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | $frm_vars['forms_loaded'][] = $small_form; |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | $frm_vars['load_css'] = true; |
764 | 764 | } |
765 | 765 | |
766 | - return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
766 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | public static function show_submit( $form ) { |
@@ -777,6 +777,6 @@ discard block |
||
777 | 777 | */ |
778 | 778 | public static function get_option( $atts ) { |
779 | 779 | $form = $atts['form']; |
780 | - return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default']; |
|
780 | + return isset( $form->options[$atts['option']] ) ? $form->options[$atts['option']] : $atts['default']; |
|
781 | 781 | } |
782 | 782 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | |
6 | 6 | class FrmField { |
7 | 7 | |
8 | - static $use_cache = true; |
|
8 | + static $use_cache = true; |
|
9 | 9 | static $transient_size = 200; |
10 | 10 | |
11 | 11 | public static function field_selection() { |
@@ -52,39 +52,39 @@ discard block |
||
52 | 52 | )); |
53 | 53 | } |
54 | 54 | |
55 | - public static function create( $values, $return = true ) { |
|
56 | - global $wpdb, $frm_duplicate_ids; |
|
55 | + public static function create( $values, $return = true ) { |
|
56 | + global $wpdb, $frm_duplicate_ids; |
|
57 | 57 | |
58 | - $new_values = array(); |
|
59 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
58 | + $new_values = array(); |
|
59 | + $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
60 | 60 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
61 | 61 | |
62 | 62 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
63 | 63 | $new_values[ $col ] = $values[ $col ]; |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - $new_values['options'] = $values['options']; |
|
66 | + $new_values['options'] = $values['options']; |
|
67 | 67 | |
68 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
69 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
70 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
71 | - $new_values['field_options'] = $values['field_options']; |
|
72 | - $new_values['created_at'] = current_time('mysql', 1); |
|
68 | + $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
69 | + $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
70 | + $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
71 | + $new_values['field_options'] = $values['field_options']; |
|
72 | + $new_values['created_at'] = current_time('mysql', 1); |
|
73 | 73 | |
74 | 74 | if ( isset( $values['id'] ) ) { |
75 | 75 | $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
76 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
77 | - } |
|
76 | + $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | foreach ( $new_values as $k => $v ) { |
80 | - if ( is_array( $v ) ) { |
|
80 | + if ( is_array( $v ) ) { |
|
81 | 81 | $new_values[ $k ] = serialize( $v ); |
82 | 82 | } |
83 | - unset( $k, $v ); |
|
84 | - } |
|
83 | + unset( $k, $v ); |
|
84 | + } |
|
85 | 85 | |
86 | - //if(isset($values['id']) and is_numeric($values['id'])) |
|
87 | - // $new_values['id'] = $values['id']; |
|
86 | + //if(isset($values['id']) and is_numeric($values['id'])) |
|
87 | + // $new_values['id'] = $values['id']; |
|
88 | 88 | |
89 | 89 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values ); |
90 | 90 | $new_id = 0; |
@@ -105,22 +105,22 @@ discard block |
||
105 | 105 | } else { |
106 | 106 | return false; |
107 | 107 | } |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | - public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
111 | - global $frm_duplicate_ids; |
|
110 | + public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
111 | + global $frm_duplicate_ids; |
|
112 | 112 | |
113 | 113 | $where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) ); |
114 | 114 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
115 | 115 | |
116 | - foreach ( (array) $fields as $field ) { |
|
117 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
118 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
119 | - $new_key = rtrim($new_key, 2); |
|
120 | - } |
|
116 | + foreach ( (array) $fields as $field ) { |
|
117 | + $new_key = ($copy_keys) ? $field->field_key : ''; |
|
118 | + if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
119 | + $new_key = rtrim($new_key, 2); |
|
120 | + } |
|
121 | 121 | |
122 | - $values = array(); |
|
123 | - FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
122 | + $values = array(); |
|
123 | + FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
124 | 124 | |
125 | 125 | // If this is a repeating section, create new form |
126 | 126 | if ( self::is_repeating_field( $field ) ) { |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | $values['form_id'] = $new_repeat_form_id; |
140 | 140 | } |
141 | 141 | |
142 | - $values = apply_filters('frm_duplicated_field', $values); |
|
143 | - $new_id = self::create($values); |
|
144 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
145 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
146 | - unset($field); |
|
147 | - } |
|
148 | - } |
|
142 | + $values = apply_filters('frm_duplicated_field', $values); |
|
143 | + $new_id = self::create($values); |
|
144 | + $frm_duplicate_ids[ $field->id ] = $new_id; |
|
145 | + $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
146 | + unset($field); |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | 150 | public static function update( $id, $values ) { |
151 | - global $wpdb; |
|
151 | + global $wpdb; |
|
152 | 152 | |
153 | 153 | $id = absint( $id ); |
154 | 154 | |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
157 | 157 | } |
158 | 158 | |
159 | - if ( isset($values['required']) ) { |
|
160 | - $values['required'] = (int) $values['required']; |
|
161 | - } |
|
159 | + if ( isset($values['required']) ) { |
|
160 | + $values['required'] = (int) $values['required']; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | self::preserve_format_option_backslashes( $values ); |
164 | 164 | |
@@ -175,41 +175,41 @@ discard block |
||
175 | 175 | |
176 | 176 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) ); |
177 | 177 | |
178 | - $form_id = 0; |
|
178 | + $form_id = 0; |
|
179 | 179 | if ( isset( $values['form_id'] ) ) { |
180 | - $form_id = absint( $values['form_id'] ); |
|
180 | + $form_id = absint( $values['form_id'] ); |
|
181 | 181 | } else { |
182 | - $field = self::getOne($id); |
|
183 | - if ( $field ) { |
|
184 | - $form_id = $field->form_id; |
|
185 | - } |
|
186 | - unset($field); |
|
187 | - } |
|
188 | - unset($values); |
|
182 | + $field = self::getOne($id); |
|
183 | + if ( $field ) { |
|
184 | + $form_id = $field->form_id; |
|
185 | + } |
|
186 | + unset($field); |
|
187 | + } |
|
188 | + unset($values); |
|
189 | 189 | |
190 | 190 | if ( $query_results ) { |
191 | - wp_cache_delete( $id, 'frm_field' ); |
|
192 | - if ( $form_id ) { |
|
193 | - self::delete_form_transient( $form_id ); |
|
194 | - } |
|
195 | - } |
|
191 | + wp_cache_delete( $id, 'frm_field' ); |
|
192 | + if ( $form_id ) { |
|
193 | + self::delete_form_transient( $form_id ); |
|
194 | + } |
|
195 | + } |
|
196 | 196 | |
197 | - return $query_results; |
|
198 | - } |
|
197 | + return $query_results; |
|
198 | + } |
|
199 | 199 | |
200 | 200 | /** |
201 | - * Keep backslashes in the phone format option |
|
202 | - * |
|
203 | - * @since 2.0.8 |
|
204 | - * @param $values array - pass by reference |
|
205 | - */ |
|
201 | + * Keep backslashes in the phone format option |
|
202 | + * |
|
203 | + * @since 2.0.8 |
|
204 | + * @param $values array - pass by reference |
|
205 | + */ |
|
206 | 206 | private static function preserve_format_option_backslashes( &$values ) { |
207 | 207 | if ( isset( $values['field_options']['format'] ) ) { |
208 | 208 | $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] ); |
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - public static function destroy( $id ) { |
|
212 | + public static function destroy( $id ) { |
|
213 | 213 | global $wpdb; |
214 | 214 | |
215 | 215 | do_action( 'frm_before_destroy_field', $id ); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) ); |
226 | 226 | return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) ); |
227 | - } |
|
227 | + } |
|
228 | 228 | |
229 | 229 | public static function delete_form_transient( $form_id ) { |
230 | 230 | $form_id = absint( $form_id ); |
@@ -238,11 +238,11 @@ discard block |
||
238 | 238 | |
239 | 239 | FrmAppHelper::cache_delete_group( 'frm_field' ); |
240 | 240 | |
241 | - $form = FrmForm::getOne($form_id); |
|
242 | - if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
|
243 | - self::delete_form_transient( $form->parent_form_id ); |
|
244 | - } |
|
245 | - } |
|
241 | + $form = FrmForm::getOne($form_id); |
|
242 | + if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
|
243 | + self::delete_form_transient( $form->parent_form_id ); |
|
244 | + } |
|
245 | + } |
|
246 | 246 | |
247 | 247 | /** |
248 | 248 | * If $field is numeric, get the field object |
@@ -258,131 +258,131 @@ discard block |
||
258 | 258 | return null; |
259 | 259 | } |
260 | 260 | |
261 | - global $wpdb; |
|
261 | + global $wpdb; |
|
262 | 262 | |
263 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
263 | + $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
264 | 264 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
265 | 265 | |
266 | - $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
266 | + $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
267 | 267 | |
268 | - if ( empty($results) ) { |
|
269 | - return $results; |
|
270 | - } |
|
268 | + if ( empty($results) ) { |
|
269 | + return $results; |
|
270 | + } |
|
271 | 271 | |
272 | - if ( is_numeric($id) ) { |
|
272 | + if ( is_numeric($id) ) { |
|
273 | 273 | FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' ); |
274 | - } else if ( $results ) { |
|
274 | + } else if ( $results ) { |
|
275 | 275 | FrmAppHelper::set_cache( $results->id, $results, 'frm_field' ); |
276 | - } |
|
276 | + } |
|
277 | 277 | |
278 | 278 | self::prepare_options( $results ); |
279 | 279 | |
280 | - return stripslashes_deep($results); |
|
281 | - } |
|
280 | + return stripslashes_deep($results); |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * Get the field type by key or id |
|
285 | - * @param int|string The field id or key |
|
283 | + /** |
|
284 | + * Get the field type by key or id |
|
285 | + * @param int|string The field id or key |
|
286 | 286 | * @param mixed $col The name of the column in the fields database table |
287 | - */ |
|
288 | - public static function get_type( $id, $col = 'type' ) { |
|
289 | - $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
290 | - if ( $field ) { |
|
291 | - $type = $field->{$col}; |
|
292 | - } else { |
|
293 | - $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
294 | - } |
|
295 | - |
|
296 | - return $type; |
|
297 | - } |
|
287 | + */ |
|
288 | + public static function get_type( $id, $col = 'type' ) { |
|
289 | + $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
290 | + if ( $field ) { |
|
291 | + $type = $field->{$col}; |
|
292 | + } else { |
|
293 | + $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
294 | + } |
|
295 | + |
|
296 | + return $type; |
|
297 | + } |
|
298 | 298 | |
299 | 299 | public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) { |
300 | - if ( ! $form_id ) { |
|
301 | - return array(); |
|
302 | - } |
|
300 | + if ( ! $form_id ) { |
|
301 | + return array(); |
|
302 | + } |
|
303 | 303 | |
304 | 304 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) ); |
305 | 305 | if ( ! empty( $results ) ) { |
306 | - $fields = array(); |
|
307 | - $count = 0; |
|
308 | - foreach ( $results as $result ) { |
|
309 | - if ( $type != $result->type ) { |
|
310 | - continue; |
|
311 | - } |
|
306 | + $fields = array(); |
|
307 | + $count = 0; |
|
308 | + foreach ( $results as $result ) { |
|
309 | + if ( $type != $result->type ) { |
|
310 | + continue; |
|
311 | + } |
|
312 | 312 | |
313 | 313 | $fields[ $result->id ] = $result; |
314 | - $count++; |
|
315 | - if ( $limit == 1 ) { |
|
316 | - $fields = $result; |
|
317 | - break; |
|
318 | - } |
|
314 | + $count++; |
|
315 | + if ( $limit == 1 ) { |
|
316 | + $fields = $result; |
|
317 | + break; |
|
318 | + } |
|
319 | 319 | |
320 | - if ( ! empty($limit) && $count >= $limit ) { |
|
321 | - break; |
|
322 | - } |
|
320 | + if ( ! empty($limit) && $count >= $limit ) { |
|
321 | + break; |
|
322 | + } |
|
323 | 323 | |
324 | - unset($result); |
|
325 | - } |
|
326 | - return stripslashes_deep($fields); |
|
327 | - } |
|
324 | + unset($result); |
|
325 | + } |
|
326 | + return stripslashes_deep($fields); |
|
327 | + } |
|
328 | 328 | |
329 | - self::$use_cache = false; |
|
329 | + self::$use_cache = false; |
|
330 | 330 | |
331 | 331 | $where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type ); |
332 | 332 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
333 | 333 | $results = self::getAll( $where, 'field_order', $limit ); |
334 | - self::$use_cache = true; |
|
335 | - self::include_sub_fields($results, $inc_sub, $type); |
|
334 | + self::$use_cache = true; |
|
335 | + self::include_sub_fields($results, $inc_sub, $type); |
|
336 | 336 | |
337 | - return $results; |
|
338 | - } |
|
337 | + return $results; |
|
338 | + } |
|
339 | 339 | |
340 | 340 | public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) { |
341 | - if ( ! (int) $form_id ) { |
|
342 | - return array(); |
|
343 | - } |
|
341 | + if ( ! (int) $form_id ) { |
|
342 | + return array(); |
|
343 | + } |
|
344 | 344 | |
345 | 345 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
346 | 346 | if ( ! empty( $results ) ) { |
347 | - if ( empty($limit) ) { |
|
347 | + if ( empty($limit) ) { |
|
348 | 348 | return $results; |
349 | - } |
|
349 | + } |
|
350 | 350 | |
351 | - $fields = array(); |
|
352 | - $count = 0; |
|
353 | - foreach ( $results as $result ) { |
|
351 | + $fields = array(); |
|
352 | + $count = 0; |
|
353 | + foreach ( $results as $result ) { |
|
354 | 354 | $fields[ $result->id ] = $result; |
355 | - if ( ! empty($limit) && $count >= $limit ) { |
|
356 | - break; |
|
357 | - } |
|
358 | - } |
|
355 | + if ( ! empty($limit) && $count >= $limit ) { |
|
356 | + break; |
|
357 | + } |
|
358 | + } |
|
359 | 359 | |
360 | 360 | return $fields; |
361 | - } |
|
361 | + } |
|
362 | 362 | |
363 | - self::$use_cache = false; |
|
363 | + self::$use_cache = false; |
|
364 | 364 | |
365 | 365 | $where = array( 'fi.form_id' => absint( $form_id ) ); |
366 | 366 | self::maybe_include_repeating_fields( $inc_repeat, $where ); |
367 | 367 | $results = self::getAll( $where, 'field_order', $limit ); |
368 | 368 | |
369 | - self::$use_cache = true; |
|
369 | + self::$use_cache = true; |
|
370 | 370 | |
371 | 371 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
372 | 372 | |
373 | - if ( empty($limit) ) { |
|
373 | + if ( empty($limit) ) { |
|
374 | 374 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
375 | - } |
|
375 | + } |
|
376 | 376 | |
377 | 377 | return $results; |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | 380 | /** |
381 | - * If repeating fields should be included, adjust $where accordingly |
|
382 | - * |
|
383 | - * @param string $inc_repeat |
|
384 | - * @param array $where - pass by reference |
|
385 | - */ |
|
381 | + * If repeating fields should be included, adjust $where accordingly |
|
382 | + * |
|
383 | + * @param string $inc_repeat |
|
384 | + * @param array $where - pass by reference |
|
385 | + */ |
|
386 | 386 | private static function maybe_include_repeating_fields( $inc_repeat, &$where ) { |
387 | 387 | if ( $inc_repeat == 'include' ) { |
388 | 388 | $form_id = $where['fi.form_id']; |
@@ -393,77 +393,77 @@ discard block |
||
393 | 393 | |
394 | 394 | public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) { |
395 | 395 | if ( 'include' != $inc_embed || empty( $results ) ) { |
396 | - return; |
|
397 | - } |
|
396 | + return; |
|
397 | + } |
|
398 | 398 | |
399 | - $form_fields = $results; |
|
399 | + $form_fields = $results; |
|
400 | 400 | $index_offset = 1; |
401 | - foreach ( $form_fields as $k => $field ) { |
|
402 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
403 | - continue; |
|
404 | - } |
|
405 | - |
|
406 | - if ( $type == 'all' ) { |
|
407 | - $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
408 | - } else { |
|
409 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
410 | - } |
|
411 | - |
|
412 | - if ( ! empty($sub_fields) ) { |
|
401 | + foreach ( $form_fields as $k => $field ) { |
|
402 | + if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
403 | + continue; |
|
404 | + } |
|
405 | + |
|
406 | + if ( $type == 'all' ) { |
|
407 | + $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
408 | + } else { |
|
409 | + $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
410 | + } |
|
411 | + |
|
412 | + if ( ! empty($sub_fields) ) { |
|
413 | 413 | $index = $k + $index_offset; |
414 | 414 | $index_offset += count( $sub_fields ); |
415 | 415 | array_splice($results, $index, 0, $sub_fields); |
416 | - } |
|
417 | - unset($field, $sub_fields); |
|
418 | - } |
|
419 | - } |
|
416 | + } |
|
417 | + unset($field, $sub_fields); |
|
418 | + } |
|
419 | + } |
|
420 | 420 | |
421 | 421 | public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) { |
422 | 422 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
423 | - if ( self::$use_cache ) { |
|
424 | - // make sure old cache doesn't get saved as a transient |
|
425 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
426 | - if ( false !== $results ) { |
|
427 | - return stripslashes_deep($results); |
|
428 | - } |
|
429 | - } |
|
430 | - |
|
431 | - global $wpdb; |
|
432 | - |
|
433 | - if ( $blog_id && is_multisite() ) { |
|
434 | - global $wpmuBaseTablePrefix; |
|
435 | - if ( $wpmuBaseTablePrefix ) { |
|
423 | + if ( self::$use_cache ) { |
|
424 | + // make sure old cache doesn't get saved as a transient |
|
425 | + $results = wp_cache_get($cache_key, 'frm_field'); |
|
426 | + if ( false !== $results ) { |
|
427 | + return stripslashes_deep($results); |
|
428 | + } |
|
429 | + } |
|
430 | + |
|
431 | + global $wpdb; |
|
432 | + |
|
433 | + if ( $blog_id && is_multisite() ) { |
|
434 | + global $wpmuBaseTablePrefix; |
|
435 | + if ( $wpmuBaseTablePrefix ) { |
|
436 | 436 | $prefix = $wpmuBaseTablePrefix . $blog_id . '_'; |
437 | - } else { |
|
438 | - $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
439 | - } |
|
437 | + } else { |
|
438 | + $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
439 | + } |
|
440 | 440 | |
441 | 441 | $table_name = $prefix . 'frm_fields'; |
442 | 442 | $form_table_name = $prefix . 'frm_forms'; |
443 | 443 | } else { |
444 | 444 | $table_name = $wpdb->prefix . 'frm_fields'; |
445 | 445 | $form_table_name = $wpdb->prefix . 'frm_forms'; |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | 448 | if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) { |
449 | 449 | $order_by = ' ORDER BY ' . $order_by; |
450 | 450 | } |
451 | 451 | |
452 | - $limit = FrmAppHelper::esc_limit($limit); |
|
452 | + $limit = FrmAppHelper::esc_limit($limit); |
|
453 | 453 | |
454 | - $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
|
455 | - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
454 | + $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
|
455 | + $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
456 | 456 | |
457 | - if ( is_array($where) ) { |
|
458 | - $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
|
457 | + if ( is_array($where) ) { |
|
458 | + $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
|
459 | 459 | } else { |
460 | 460 | // if the query is not an array, then it has already been prepared |
461 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
461 | + $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
462 | 462 | |
463 | 463 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
464 | 464 | $results = $wpdb->$function_name( $query ); |
465 | - } |
|
466 | - unset( $where ); |
|
465 | + } |
|
466 | + unset( $where ); |
|
467 | 467 | |
468 | 468 | self::format_field_results( $results ); |
469 | 469 | |
@@ -701,8 +701,8 @@ discard block |
||
701 | 701 | } |
702 | 702 | |
703 | 703 | /** |
704 | - * @since 2.0.09 |
|
705 | - */ |
|
704 | + * @since 2.0.09 |
|
705 | + */ |
|
706 | 706 | public static function is_repeating_field( $field ) { |
707 | 707 | if ( is_array( $field ) ) { |
708 | 708 | $is_repeating_field = ( 'divider' == $field['type'] ); |
@@ -712,14 +712,14 @@ discard block |
||
712 | 712 | return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) ); |
713 | 713 | } |
714 | 714 | |
715 | - /** |
|
716 | - * @param string $key |
|
717 | - * @return int field id |
|
718 | - */ |
|
715 | + /** |
|
716 | + * @param string $key |
|
717 | + * @return int field id |
|
718 | + */ |
|
719 | 719 | public static function get_id_by_key( $key ) { |
720 | - $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
721 | - return $id; |
|
722 | - } |
|
720 | + $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
721 | + return $id; |
|
722 | + } |
|
723 | 723 | |
724 | 724 | /** |
725 | 725 | * @param string $id |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | static $transient_size = 200; |
10 | 10 | |
11 | 11 | public static function field_selection() { |
12 | - $fields = apply_filters('frm_available_fields', array( |
|
12 | + $fields = apply_filters( 'frm_available_fields', array( |
|
13 | 13 | 'text' => __( 'Single Line Text', 'formidable' ), |
14 | 14 | 'textarea' => __( 'Paragraph Text', 'formidable' ), |
15 | 15 | 'checkbox' => __( 'Checkboxes', 'formidable' ), |
@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | 'email' => __( 'Email Address', 'formidable' ), |
19 | 19 | 'url' => __( 'Website/URL', 'formidable' ), |
20 | 20 | 'captcha' => __( 'reCAPTCHA', 'formidable' ), |
21 | - )); |
|
21 | + ) ); |
|
22 | 22 | |
23 | 23 | return $fields; |
24 | 24 | } |
25 | 25 | |
26 | 26 | public static function pro_field_selection() { |
27 | - return apply_filters('frm_pro_available_fields', array( |
|
27 | + return apply_filters( 'frm_pro_available_fields', array( |
|
28 | 28 | 'end_divider' => array( |
29 | 29 | 'name' => __( 'End Section', 'formidable' ), |
30 | 30 | 'switch_from' => 'divider', |
@@ -49,36 +49,36 @@ discard block |
||
49 | 49 | 'tag' => __( 'Tags', 'formidable' ), |
50 | 50 | 'credit_card' => __( 'Credit Card', 'formidable' ), |
51 | 51 | 'address' => __( 'Address', 'formidable' ), |
52 | - )); |
|
52 | + ) ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | public static function create( $values, $return = true ) { |
56 | 56 | global $wpdb, $frm_duplicate_ids; |
57 | 57 | |
58 | 58 | $new_values = array(); |
59 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
59 | + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name']; |
|
60 | 60 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
61 | 61 | |
62 | 62 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
63 | - $new_values[ $col ] = $values[ $col ]; |
|
63 | + $new_values[$col] = $values[$col]; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | $new_values['options'] = $values['options']; |
67 | 67 | |
68 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
69 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
70 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
68 | + $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null; |
|
69 | + $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0; |
|
70 | + $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
|
71 | 71 | $new_values['field_options'] = $values['field_options']; |
72 | - $new_values['created_at'] = current_time('mysql', 1); |
|
72 | + $new_values['created_at'] = current_time( 'mysql', 1 ); |
|
73 | 73 | |
74 | 74 | if ( isset( $values['id'] ) ) { |
75 | - $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
|
76 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
75 | + $frm_duplicate_ids[$values['field_key']] = $new_values['field_key']; |
|
76 | + $new_values = apply_filters( 'frm_duplicated_field', $new_values ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | foreach ( $new_values as $k => $v ) { |
80 | 80 | if ( is_array( $v ) ) { |
81 | - $new_values[ $k ] = serialize( $v ); |
|
81 | + $new_values[$k] = serialize( $v ); |
|
82 | 82 | } |
83 | 83 | unset( $k, $v ); |
84 | 84 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | if ( $query_results ) { |
101 | 101 | if ( isset( $values['id'] ) ) { |
102 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; |
|
102 | + $frm_duplicate_ids[$values['id']] = $new_id; |
|
103 | 103 | } |
104 | 104 | return $new_id; |
105 | 105 | } else { |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
115 | 115 | |
116 | 116 | foreach ( (array) $fields as $field ) { |
117 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
118 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
119 | - $new_key = rtrim($new_key, 2); |
|
117 | + $new_key = ( $copy_keys ) ? $field->field_key : ''; |
|
118 | + if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) { |
|
119 | + $new_key = rtrim( $new_key, 2 ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $values = array(); |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | $values['form_id'] = $new_repeat_form_id; |
140 | 140 | } |
141 | 141 | |
142 | - $values = apply_filters('frm_duplicated_field', $values); |
|
143 | - $new_id = self::create($values); |
|
144 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
145 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
146 | - unset($field); |
|
142 | + $values = apply_filters( 'frm_duplicated_field', $values ); |
|
143 | + $new_id = self::create( $values ); |
|
144 | + $frm_duplicate_ids[$field->id] = $new_id; |
|
145 | + $frm_duplicate_ids[$field->field_key] = $new_id; |
|
146 | + unset( $field ); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
157 | 157 | } |
158 | 158 | |
159 | - if ( isset($values['required']) ) { |
|
159 | + if ( isset( $values['required'] ) ) { |
|
160 | 160 | $values['required'] = (int) $values['required']; |
161 | 161 | } |
162 | 162 | |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | |
169 | 169 | // serialize array values |
170 | 170 | foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) { |
171 | - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) { |
|
172 | - $values[ $opt ] = serialize( $values[ $opt ] ); |
|
171 | + if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) { |
|
172 | + $values[$opt] = serialize( $values[$opt] ); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
@@ -179,13 +179,13 @@ discard block |
||
179 | 179 | if ( isset( $values['form_id'] ) ) { |
180 | 180 | $form_id = absint( $values['form_id'] ); |
181 | 181 | } else { |
182 | - $field = self::getOne($id); |
|
182 | + $field = self::getOne( $id ); |
|
183 | 183 | if ( $field ) { |
184 | 184 | $form_id = $field->form_id; |
185 | 185 | } |
186 | - unset($field); |
|
186 | + unset( $field ); |
|
187 | 187 | } |
188 | - unset($values); |
|
188 | + unset( $values ); |
|
189 | 189 | |
190 | 190 | if ( $query_results ) { |
191 | 191 | wp_cache_delete( $id, 'frm_field' ); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | FrmAppHelper::cache_delete_group( 'frm_field' ); |
240 | 240 | |
241 | - $form = FrmForm::getOne($form_id); |
|
241 | + $form = FrmForm::getOne( $form_id ); |
|
242 | 242 | if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
243 | 243 | self::delete_form_transient( $form->parent_form_id ); |
244 | 244 | } |
@@ -260,16 +260,16 @@ discard block |
||
260 | 260 | |
261 | 261 | global $wpdb; |
262 | 262 | |
263 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
263 | + $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s'; |
|
264 | 264 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
265 | 265 | |
266 | 266 | $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
267 | 267 | |
268 | - if ( empty($results) ) { |
|
268 | + if ( empty( $results ) ) { |
|
269 | 269 | return $results; |
270 | 270 | } |
271 | 271 | |
272 | - if ( is_numeric($id) ) { |
|
272 | + if ( is_numeric( $id ) ) { |
|
273 | 273 | FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' ); |
274 | 274 | } else if ( $results ) { |
275 | 275 | FrmAppHelper::set_cache( $results->id, $results, 'frm_field' ); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | |
278 | 278 | self::prepare_options( $results ); |
279 | 279 | |
280 | - return stripslashes_deep($results); |
|
280 | + return stripslashes_deep( $results ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -310,20 +310,20 @@ discard block |
||
310 | 310 | continue; |
311 | 311 | } |
312 | 312 | |
313 | - $fields[ $result->id ] = $result; |
|
314 | - $count++; |
|
313 | + $fields[$result->id] = $result; |
|
314 | + $count ++; |
|
315 | 315 | if ( $limit == 1 ) { |
316 | 316 | $fields = $result; |
317 | 317 | break; |
318 | 318 | } |
319 | 319 | |
320 | - if ( ! empty($limit) && $count >= $limit ) { |
|
320 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
321 | 321 | break; |
322 | 322 | } |
323 | 323 | |
324 | - unset($result); |
|
324 | + unset( $result ); |
|
325 | 325 | } |
326 | - return stripslashes_deep($fields); |
|
326 | + return stripslashes_deep( $fields ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | self::$use_cache = false; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
333 | 333 | $results = self::getAll( $where, 'field_order', $limit ); |
334 | 334 | self::$use_cache = true; |
335 | - self::include_sub_fields($results, $inc_sub, $type); |
|
335 | + self::include_sub_fields( $results, $inc_sub, $type ); |
|
336 | 336 | |
337 | 337 | return $results; |
338 | 338 | } |
@@ -344,15 +344,15 @@ discard block |
||
344 | 344 | |
345 | 345 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
346 | 346 | if ( ! empty( $results ) ) { |
347 | - if ( empty($limit) ) { |
|
347 | + if ( empty( $limit ) ) { |
|
348 | 348 | return $results; |
349 | 349 | } |
350 | 350 | |
351 | 351 | $fields = array(); |
352 | 352 | $count = 0; |
353 | 353 | foreach ( $results as $result ) { |
354 | - $fields[ $result->id ] = $result; |
|
355 | - if ( ! empty($limit) && $count >= $limit ) { |
|
354 | + $fields[$result->id] = $result; |
|
355 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
356 | 356 | break; |
357 | 357 | } |
358 | 358 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | |
371 | 371 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
372 | 372 | |
373 | - if ( empty($limit) ) { |
|
373 | + if ( empty( $limit ) ) { |
|
374 | 374 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
375 | 375 | } |
376 | 376 | |
@@ -399,22 +399,22 @@ discard block |
||
399 | 399 | $form_fields = $results; |
400 | 400 | $index_offset = 1; |
401 | 401 | foreach ( $form_fields as $k => $field ) { |
402 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
402 | + if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) { |
|
403 | 403 | continue; |
404 | 404 | } |
405 | 405 | |
406 | 406 | if ( $type == 'all' ) { |
407 | 407 | $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
408 | 408 | } else { |
409 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
409 | + $sub_fields = self::get_all_types_in_form( $field->form_id, $type ); |
|
410 | 410 | } |
411 | 411 | |
412 | - if ( ! empty($sub_fields) ) { |
|
412 | + if ( ! empty( $sub_fields ) ) { |
|
413 | 413 | $index = $k + $index_offset; |
414 | 414 | $index_offset += count( $sub_fields ); |
415 | - array_splice($results, $index, 0, $sub_fields); |
|
415 | + array_splice( $results, $index, 0, $sub_fields ); |
|
416 | 416 | } |
417 | - unset($field, $sub_fields); |
|
417 | + unset( $field, $sub_fields ); |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
@@ -422,9 +422,9 @@ discard block |
||
422 | 422 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
423 | 423 | if ( self::$use_cache ) { |
424 | 424 | // make sure old cache doesn't get saved as a transient |
425 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
425 | + $results = wp_cache_get( $cache_key, 'frm_field' ); |
|
426 | 426 | if ( false !== $results ) { |
427 | - return stripslashes_deep($results); |
|
427 | + return stripslashes_deep( $results ); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | |
@@ -449,16 +449,16 @@ discard block |
||
449 | 449 | $order_by = ' ORDER BY ' . $order_by; |
450 | 450 | } |
451 | 451 | |
452 | - $limit = FrmAppHelper::esc_limit($limit); |
|
452 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
453 | 453 | |
454 | 454 | $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
455 | 455 | $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
456 | 456 | |
457 | - if ( is_array($where) ) { |
|
457 | + if ( is_array( $where ) ) { |
|
458 | 458 | $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
459 | 459 | } else { |
460 | 460 | // if the query is not an array, then it has already been prepared |
461 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
461 | + $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
462 | 462 | |
463 | 463 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
464 | 464 | $results = $wpdb->$function_name( $query ); |
@@ -481,9 +481,9 @@ discard block |
||
481 | 481 | FrmAppHelper::set_cache( $result->id, $result, 'frm_field' ); |
482 | 482 | FrmAppHelper::set_cache( $result->field_key, $result, 'frm_field' ); |
483 | 483 | |
484 | - $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options ); |
|
485 | - $results[ $r_key ]->options = maybe_unserialize( $result->options ); |
|
486 | - $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value ); |
|
484 | + $results[$r_key]->field_options = maybe_unserialize( $result->field_options ); |
|
485 | + $results[$r_key]->options = maybe_unserialize( $result->options ); |
|
486 | + $results[$r_key]->default_value = maybe_unserialize( $result->default_value ); |
|
487 | 487 | |
488 | 488 | unset( $r_key, $result ); |
489 | 489 | } |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | private static function prepare_options( &$results ) { |
503 | 503 | $results->field_options = maybe_unserialize( $results->field_options ); |
504 | 504 | |
505 | - $results->options = maybe_unserialize($results->options); |
|
506 | - $results->default_value = maybe_unserialize($results->default_value); |
|
505 | + $results->options = maybe_unserialize( $results->options ); |
|
506 | + $results->default_value = maybe_unserialize( $results->default_value ); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | |
531 | 531 | if ( count( $next_fields ) >= self::$transient_size ) { |
532 | 532 | // if this transient is full, check for another |
533 | - $next++; |
|
533 | + $next ++; |
|
534 | 534 | self::get_next_transient( $fields, $base_name, $next ); |
535 | 535 | } |
536 | 536 | } |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | return; |
557 | 557 | } |
558 | 558 | |
559 | - $next++; |
|
559 | + $next ++; |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | $field_type = is_array( $field ) ? $field['type'] : $field->type; |
611 | 611 | $data_type = self::get_option( $field, 'data_type' ); |
612 | 612 | |
613 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select') ) ); |
|
613 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select' ) ) ); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | /** |
@@ -656,23 +656,23 @@ discard block |
||
656 | 656 | } |
657 | 657 | |
658 | 658 | public static function is_option_true_in_array( $field, $option ) { |
659 | - return isset( $field[ $option ] ) && $field[ $option ]; |
|
659 | + return isset( $field[$option] ) && $field[$option]; |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | public static function is_option_true_in_object( $field, $option ) { |
663 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ]; |
|
663 | + return isset( $field->field_options[$option] ) && $field->field_options[$option]; |
|
664 | 664 | } |
665 | 665 | |
666 | 666 | public static function is_option_empty_in_array( $field, $option ) { |
667 | - return ! isset( $field[ $option ] ) || empty( $field[ $option ] ); |
|
667 | + return ! isset( $field[$option] ) || empty( $field[$option] ); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | public static function is_option_empty_in_object( $field, $option ) { |
671 | - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] ); |
|
671 | + return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] ); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | public static function is_option_value_in_object( $field, $option ) { |
675 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != ''; |
|
675 | + return isset( $field->field_options[$option] ) && $field->field_options[$option] != ''; |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -688,11 +688,11 @@ discard block |
||
688 | 688 | } |
689 | 689 | |
690 | 690 | public static function get_option_in_array( $field, $option ) { |
691 | - return $field[ $option ]; |
|
691 | + return $field[$option]; |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | public static function get_option_in_object( $field, $option ) { |
695 | - return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : ''; |
|
695 | + return isset( $field->field_options[$option] ) ? $field->field_options[$option] : ''; |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
@@ -1,18 +1,18 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class FrmEntryValidate { |
4 | - public static function validate( $values, $exclude = false ) { |
|
5 | - FrmEntry::sanitize_entry_post( $values ); |
|
6 | - $errors = array(); |
|
4 | + public static function validate( $values, $exclude = false ) { |
|
5 | + FrmEntry::sanitize_entry_post( $values ); |
|
6 | + $errors = array(); |
|
7 | 7 | |
8 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
9 | - $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
10 | - return $errors; |
|
11 | - } |
|
8 | + if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
9 | + $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
10 | + return $errors; |
|
11 | + } |
|
12 | 12 | |
13 | 13 | 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' ) ) ) { |
14 | - $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
15 | - } |
|
14 | + $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
15 | + } |
|
16 | 16 | |
17 | 17 | self::set_item_key( $values ); |
18 | 18 | |
@@ -69,24 +69,24 @@ discard block |
||
69 | 69 | return FrmField::getAll( $where, 'field_order' ); |
70 | 70 | } |
71 | 71 | |
72 | - public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
73 | - $defaults = array( |
|
74 | - 'id' => $posted_field->id, |
|
75 | - 'parent_field_id' => '', // the id of the repeat or embed form |
|
76 | - 'key_pointer' => '', // the pointer in the posted array |
|
77 | - 'exclude' => array(), // exclude these field types from validation |
|
78 | - ); |
|
79 | - $args = wp_parse_args( $args, $defaults ); |
|
72 | + public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
73 | + $defaults = array( |
|
74 | + 'id' => $posted_field->id, |
|
75 | + 'parent_field_id' => '', // the id of the repeat or embed form |
|
76 | + 'key_pointer' => '', // the pointer in the posted array |
|
77 | + 'exclude' => array(), // exclude these field types from validation |
|
78 | + ); |
|
79 | + $args = wp_parse_args( $args, $defaults ); |
|
80 | 80 | |
81 | - if ( empty($args['parent_field_id']) ) { |
|
81 | + if ( empty($args['parent_field_id']) ) { |
|
82 | 82 | $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
83 | - } else { |
|
84 | - // value is from a nested form |
|
85 | - $value = $values; |
|
86 | - } |
|
83 | + } else { |
|
84 | + // value is from a nested form |
|
85 | + $value = $values; |
|
86 | + } |
|
87 | 87 | |
88 | - // Check for values in "Other" fields |
|
89 | - FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
88 | + // Check for values in "Other" fields |
|
89 | + FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
90 | 90 | |
91 | 91 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
92 | 92 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | $value = reset($value); |
96 | 96 | } |
97 | 97 | |
98 | - if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
98 | + if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
99 | 99 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
100 | - } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
101 | - $_POST['item_name'] = $value; |
|
102 | - } |
|
100 | + } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
101 | + $_POST['item_name'] = $value; |
|
102 | + } |
|
103 | 103 | |
104 | 104 | if ( $value != '' ) { |
105 | 105 | self::validate_url_field( $errors, $posted_field, $value, $args ); |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
109 | 109 | } |
110 | 110 | |
111 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
111 | + FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
112 | 112 | |
113 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
113 | + self::validate_recaptcha($errors, $posted_field, $args); |
|
114 | 114 | |
115 | 115 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
116 | 116 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
117 | - } |
|
117 | + } |
|
118 | 118 | |
119 | 119 | private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) { |
120 | 120 | if ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value ) { |
@@ -124,32 +124,32 @@ discard block |
||
124 | 124 | |
125 | 125 | public static function validate_url_field( &$errors, $field, &$value, $args ) { |
126 | 126 | if ( $value == '' || ! in_array( $field->type, array( 'website', 'url', 'image' ) ) ) { |
127 | - return; |
|
128 | - } |
|
127 | + return; |
|
128 | + } |
|
129 | 129 | |
130 | - if ( trim($value) == 'http://' ) { |
|
131 | - $value = ''; |
|
132 | - } else { |
|
133 | - $value = esc_url_raw( $value ); |
|
130 | + if ( trim($value) == 'http://' ) { |
|
131 | + $value = ''; |
|
132 | + } else { |
|
133 | + $value = esc_url_raw( $value ); |
|
134 | 134 | $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'http://' . $value; |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | - // validate the url format |
|
137 | + // validate the url format |
|
138 | 138 | if ( ! preg_match('/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value) ) { |
139 | 139 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
140 | 140 | } |
141 | - } |
|
141 | + } |
|
142 | 142 | |
143 | 143 | public static function validate_email_field( &$errors, $field, $value, $args ) { |
144 | - if ( $value == '' || $field->type != 'email' ) { |
|
145 | - return; |
|
146 | - } |
|
144 | + if ( $value == '' || $field->type != 'email' ) { |
|
145 | + return; |
|
146 | + } |
|
147 | 147 | |
148 | - //validate the email format |
|
149 | - if ( ! is_email($value) ) { |
|
148 | + //validate the email format |
|
149 | + if ( ! is_email($value) ) { |
|
150 | 150 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
151 | - } |
|
152 | - } |
|
151 | + } |
|
152 | + } |
|
153 | 153 | |
154 | 154 | public static function validate_number_field( &$errors, $field, $value, $args ) { |
155 | 155 | //validate the number format |
@@ -243,9 +243,9 @@ discard block |
||
243 | 243 | } |
244 | 244 | |
245 | 245 | public static function validate_recaptcha( &$errors, $field, $args ) { |
246 | - if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
247 | - return; |
|
248 | - } |
|
246 | + if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
247 | + return; |
|
248 | + } |
|
249 | 249 | |
250 | 250 | $frm_settings = FrmAppHelper::get_settings(); |
251 | 251 | if ( empty( $frm_settings->pubkey ) ) { |
@@ -253,61 +253,61 @@ discard block |
||
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
257 | - // If captcha is missing, check if it was already verified |
|
256 | + if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
257 | + // If captcha is missing, check if it was already verified |
|
258 | 258 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
259 | - // There was no captcha submitted |
|
259 | + // There was no captcha submitted |
|
260 | 260 | $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
261 | - } |
|
262 | - return; |
|
263 | - } |
|
261 | + } |
|
262 | + return; |
|
263 | + } |
|
264 | 264 | |
265 | - $arg_array = array( |
|
266 | - 'body' => array( |
|
265 | + $arg_array = array( |
|
266 | + 'body' => array( |
|
267 | 267 | 'secret' => $frm_settings->privkey, |
268 | 268 | 'response' => $_POST['g-recaptcha-response'], |
269 | 269 | 'remoteip' => FrmAppHelper::get_ip_address(), |
270 | 270 | ), |
271 | 271 | ); |
272 | - $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
273 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
272 | + $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
273 | + $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
274 | 274 | |
275 | - if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
276 | - // What happens when the CAPTCHA was entered incorrectly |
|
275 | + if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
276 | + // What happens when the CAPTCHA was entered incorrectly |
|
277 | 277 | $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
278 | - } else if ( is_wp_error( $resp ) ) { |
|
278 | + } else if ( is_wp_error( $resp ) ) { |
|
279 | 279 | $error_string = $resp->get_error_message(); |
280 | 280 | $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
281 | 281 | $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * check for spam |
|
287 | - * @param boolean $exclude |
|
288 | - * @param array $values |
|
289 | - * @param array $errors by reference |
|
290 | - */ |
|
291 | - public static function spam_check( $exclude, $values, &$errors ) { |
|
292 | - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
293 | - // only check spam if there are no other errors |
|
294 | - return; |
|
295 | - } |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * check for spam |
|
287 | + * @param boolean $exclude |
|
288 | + * @param array $values |
|
289 | + * @param array $errors by reference |
|
290 | + */ |
|
291 | + public static function spam_check( $exclude, $values, &$errors ) { |
|
292 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
293 | + // only check spam if there are no other errors |
|
294 | + return; |
|
295 | + } |
|
296 | 296 | |
297 | 297 | if ( self::is_honeypot_spam() || self::is_spam_bot() ) { |
298 | 298 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
299 | 299 | } |
300 | 300 | |
301 | - if ( self::blacklist_check( $values ) ) { |
|
302 | - $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
303 | - } |
|
301 | + if ( self::blacklist_check( $values ) ) { |
|
302 | + $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
303 | + } |
|
304 | 304 | |
305 | - if ( self::is_akismet_spam( $values ) ) { |
|
305 | + if ( self::is_akismet_spam( $values ) ) { |
|
306 | 306 | if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) { |
307 | 307 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
308 | 308 | } |
309 | - } |
|
310 | - } |
|
309 | + } |
|
310 | + } |
|
311 | 311 | |
312 | 312 | private static function is_honeypot_spam() { |
313 | 313 | $honeypot_value = FrmAppHelper::get_param( 'frm_verify', '', 'get', 'sanitize_text_field' ); |
@@ -329,15 +329,15 @@ discard block |
||
329 | 329 | return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ); |
330 | 330 | } |
331 | 331 | |
332 | - public static function blacklist_check( $values ) { |
|
333 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
334 | - return false; |
|
335 | - } |
|
332 | + public static function blacklist_check( $values ) { |
|
333 | + if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
334 | + return false; |
|
335 | + } |
|
336 | 336 | |
337 | - $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
338 | - if ( empty( $mod_keys ) ) { |
|
339 | - return false; |
|
340 | - } |
|
337 | + $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
338 | + if ( empty( $mod_keys ) ) { |
|
339 | + return false; |
|
340 | + } |
|
341 | 341 | |
342 | 342 | $content = FrmEntriesHelper::entry_array_to_string( $values ); |
343 | 343 | if ( empty( $content ) ) { |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | $user_info = self::get_spam_check_user_info( $values ); |
350 | 350 | |
351 | 351 | return wp_blacklist_check( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent ); |
352 | - } |
|
352 | + } |
|
353 | 353 | |
354 | 354 | /** |
355 | 355 | * Check entries for Akismet spam |
@@ -5,12 +5,12 @@ discard block |
||
5 | 5 | FrmEntry::sanitize_entry_post( $values ); |
6 | 6 | $errors = array(); |
7 | 7 | |
8 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
8 | + if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) { |
|
9 | 9 | $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
10 | 10 | return $errors; |
11 | 11 | } |
12 | 12 | |
13 | - 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' ) ) ) { |
|
13 | + 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' ) ) ) { |
|
14 | 14 | $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
15 | 15 | } |
16 | 16 | |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | ); |
68 | 68 | $args = wp_parse_args( $args, $defaults ); |
69 | 69 | |
70 | - if ( empty($args['parent_field_id']) ) { |
|
71 | - $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
|
70 | + if ( empty( $args['parent_field_id'] ) ) { |
|
71 | + $value = isset( $values['item_meta'][$args['id']] ) ? $values['item_meta'][$args['id']] : ''; |
|
72 | 72 | } else { |
73 | 73 | // value is from a nested form |
74 | 74 | $value = $values; |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
81 | 81 | |
82 | 82 | // Reset arrays with only one value if it's not a field where array keys need to be preserved |
83 | - if ( is_array($value) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
84 | - $value = reset($value); |
|
83 | + if ( is_array( $value ) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
84 | + $value = reset( $value ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
88 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
88 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
89 | 89 | } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
90 | 90 | $_POST['item_name'] = $value; |
91 | 91 | } |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
98 | 98 | } |
99 | 99 | |
100 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
100 | + FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
|
101 | 101 | |
102 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
102 | + self::validate_recaptcha( $errors, $posted_field, $args ); |
|
103 | 103 | |
104 | 104 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
105 | 105 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | - if ( trim($value) == 'http://' ) { |
|
119 | + if ( trim( $value ) == 'http://' ) { |
|
120 | 120 | $value = ''; |
121 | 121 | } else { |
122 | 122 | $value = esc_url_raw( $value ); |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | // validate the url format |
127 | - if ( ! preg_match('/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value) ) { |
|
128 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
127 | + if ( ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $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 | } |
136 | 136 | |
137 | 137 | //validate the email format |
138 | - if ( ! is_email($value) ) { |
|
139 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
138 | + if ( ! is_email( $value ) ) { |
|
139 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | return; |
147 | 147 | } |
148 | 148 | |
149 | - if ( ! is_numeric( $value) ) { |
|
150 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
149 | + if ( ! is_numeric( $value ) ) { |
|
150 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // validate number settings |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | if ( $frm_settings->use_html && isset( $field->field_options['minnum'] ) && isset( $field->field_options['maxnum'] ) ) { |
158 | 158 | //minnum maxnum |
159 | 159 | if ( (float) $value < $field->field_options['minnum'] ) { |
160 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' ); |
|
160 | + $errors['field' . $args['id']] = __( 'Please select a higher number', 'formidable' ); |
|
161 | 161 | } else if ( (float) $value > $field->field_options['maxnum'] ) { |
162 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' ); |
|
162 | + $errors['field' . $args['id']] = __( 'Please select a lower number', 'formidable' ); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $pattern = self::phone_format( $field ); |
172 | 172 | |
173 | 173 | if ( ! preg_match( $pattern, $value ) ) { |
174 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
174 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | } |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | return; |
243 | 243 | } |
244 | 244 | |
245 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
245 | + if ( ! isset( $_POST['g-recaptcha-response'] ) ) { |
|
246 | 246 | // If captcha is missing, check if it was already verified |
247 | 247 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
248 | 248 | // There was no captcha submitted |
249 | - $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
|
249 | + $errors['field' . $args['id']] = __( 'The captcha is missing from this form', 'formidable' ); |
|
250 | 250 | } |
251 | 251 | return; |
252 | 252 | } |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | ), |
260 | 260 | ); |
261 | 261 | $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
262 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
262 | + $response = json_decode( wp_remote_retrieve_body( $resp ), true ); |
|
263 | 263 | |
264 | 264 | if ( isset( $response['success'] ) && ! $response['success'] ) { |
265 | 265 | // What happens when the CAPTCHA was entered incorrectly |
266 | - $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
266 | + $errors['field' . $args['id']] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
267 | 267 | } else if ( is_wp_error( $resp ) ) { |
268 | 268 | $error_string = $resp->get_error_message(); |
269 | - $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
270 | - $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
|
269 | + $errors['field' . $args['id']] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
270 | + $errors['field' . $args['id']] .= ' ' . $error_string; |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | |
311 | 311 | private static function is_akismet_spam( $values ) { |
312 | 312 | global $wpcom_api_key; |
313 | - return ( is_callable('Akismet::http_post') && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet( $values ) ); |
|
313 | + return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) ); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | private static function is_akismet_enabled_for_user( $form_id ) { |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | public static function blacklist_check( $values ) { |
322 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
322 | + if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) { |
|
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
376 | 376 | $datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false; |
377 | 377 | $datas['blog_lang'] = get_locale(); |
378 | - $datas['blog_charset'] = get_option('blog_charset'); |
|
378 | + $datas['blog_charset'] = get_option( 'blog_charset' ); |
|
379 | 379 | |
380 | 380 | if ( akismet_test_mode() ) { |
381 | 381 | $datas['is_test'] = 'true'; |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | |
430 | 430 | // Send any potentially useful $_SERVER vars, but avoid sending junk we don't need. |
431 | 431 | if ( $include_value ) { |
432 | - $datas[ $key ] = $value; |
|
432 | + $datas[$key] = $value; |
|
433 | 433 | } |
434 | 434 | unset( $key, $value ); |
435 | 435 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | </div> |
6 | 6 | </div> |
7 | 7 | <?php |
8 | - return; |
|
8 | + return; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | global $frm_vars; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | } else { |
37 | 37 | do_action( 'frm_show_other_field_type', $field, $form, array( 'action' => $form_action ) ); |
38 | 38 | } |
39 | - do_action('frm_get_field_scripts', $field, $form, $form->id); |
|
39 | + do_action('frm_get_field_scripts', $field, $form, $form->id); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | |
62 | 62 | // close open collapsible toggle div |
63 | 63 | if ( isset($frm_vars['collapse_div']) && $frm_vars['collapse_div'] ) { |
64 | - echo "</div>\n"; |
|
65 | - unset($frm_vars['collapse_div']); |
|
64 | + echo "</div>\n"; |
|
65 | + unset($frm_vars['collapse_div']); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | echo FrmFormsHelper::replace_shortcodes($values['after_html'], $form); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( empty($values) || ! isset($values['fields']) || empty($values['fields']) ) { ?> |
|
3 | -<div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class($form); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container"> |
|
2 | +if ( empty( $values ) || ! isset( $values['fields'] ) || empty( $values['fields'] ) ) { ?> |
|
3 | +<div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class( $form ); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container"> |
|
4 | 4 | <div class="frm_error_style"><strong><?php _e( 'Oops!', 'formidable' ) ?></strong> <?php printf( __( 'You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable' ), '<a href="' . esc_url( admin_url( '?page=formidable&frm_action=edit&id=' . $form->id ) ) . '">', '</a>' ) ?> |
5 | 5 | </div> |
6 | 6 | </div> |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | <div class="frm_form_fields <?php echo esc_attr( apply_filters( 'frm_form_fields_class', '', $values ) ); ?>"> |
19 | 19 | <fieldset> |
20 | 20 | <?php echo FrmFormsHelper::replace_shortcodes( $values['before_html'], $form, $title, $description ); ?> |
21 | -<?php do_action( 'frm_after_title', compact('form') ) ?> |
|
22 | -<input type="hidden" name="frm_action" value="<?php echo esc_attr($form_action) ?>" /> |
|
23 | -<input type="hidden" name="form_id" value="<?php echo esc_attr($form->id) ?>" /> |
|
24 | -<input type="hidden" name="frm_hide_fields_<?php echo esc_attr( $form->id ) ?>" id="frm_hide_fields_<?php echo esc_attr( $form->id ) ?>" value="<?php echo esc_attr($frm_hide_fields) ?>" /> |
|
25 | -<input type="hidden" name="form_key" value="<?php echo esc_attr($form->form_key) ?>" /> |
|
21 | +<?php do_action( 'frm_after_title', compact( 'form' ) ) ?> |
|
22 | +<input type="hidden" name="frm_action" value="<?php echo esc_attr( $form_action ) ?>" /> |
|
23 | +<input type="hidden" name="form_id" value="<?php echo esc_attr( $form->id ) ?>" /> |
|
24 | +<input type="hidden" name="frm_hide_fields_<?php echo esc_attr( $form->id ) ?>" id="frm_hide_fields_<?php echo esc_attr( $form->id ) ?>" value="<?php echo esc_attr( $frm_hide_fields ) ?>" /> |
|
25 | +<input type="hidden" name="form_key" value="<?php echo esc_attr( $form->form_key ) ?>" /> |
|
26 | 26 | <input type="hidden" name="item_meta[0]" value="" /> |
27 | 27 | <?php wp_nonce_field( 'frm_submit_entry_nonce', 'frm_submit_entry_' . $form->id ); ?> |
28 | -<input type="text" class="frm_hidden frm_verify" id="frm_verify_<?php echo esc_attr( $form->id ) ?>" name="frm_verify" value="<?php echo esc_attr( FrmAppHelper::get_param('frm_verify' ) ) ?>" <?php FrmFormsHelper::maybe_hide_inline() ?> /> |
|
28 | +<input type="text" class="frm_hidden frm_verify" id="frm_verify_<?php echo esc_attr( $form->id ) ?>" name="frm_verify" value="<?php echo esc_attr( FrmAppHelper::get_param( 'frm_verify' ) ) ?>" <?php FrmFormsHelper::maybe_hide_inline() ?> /> |
|
29 | 29 | |
30 | 30 | <?php if ( isset( $id ) ) { ?><input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" /><?php } |
31 | 31 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | } else { |
37 | 37 | do_action( 'frm_show_other_field_type', $field, $form, array( 'action' => $form_action ) ); |
38 | 38 | } |
39 | - do_action('frm_get_field_scripts', $field, $form, $form->id); |
|
39 | + do_action( 'frm_get_field_scripts', $field, $form, $form->id ); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | if ( FrmAppHelper::is_admin() ) { ?> |
45 | 45 | <div class="frm_form_field form-field"> |
46 | 46 | <label class="frm_primary_label"><?php _e( 'Entry Key', 'formidable' ) ?></label> |
47 | -<input type="text" name="item_key" value="<?php echo esc_attr($values['item_key']) ?>" /> |
|
47 | +<input type="text" name="item_key" value="<?php echo esc_attr( $values['item_key'] ) ?>" /> |
|
48 | 48 | </div> |
49 | 49 | <?php } else { ?> |
50 | -<input type="hidden" name="item_key" value="<?php echo esc_attr($values['item_key']) ?>" /> |
|
50 | +<input type="hidden" name="item_key" value="<?php echo esc_attr( $values['item_key'] ) ?>" /> |
|
51 | 51 | <?php } |
52 | 52 | |
53 | -do_action('frm_entry_form', $form, $form_action, $errors); |
|
53 | +do_action( 'frm_entry_form', $form, $form_action, $errors ); |
|
54 | 54 | |
55 | 55 | global $frm_vars; |
56 | 56 | // close open section div |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | // close open collapsible toggle div |
63 | -if ( isset($frm_vars['collapse_div']) && $frm_vars['collapse_div'] ) { |
|
63 | +if ( isset( $frm_vars['collapse_div'] ) && $frm_vars['collapse_div'] ) { |
|
64 | 64 | echo "</div>\n"; |
65 | - unset($frm_vars['collapse_div']); |
|
65 | + unset( $frm_vars['collapse_div'] ); |
|
66 | 66 | } |
67 | 67 | |
68 | -echo FrmFormsHelper::replace_shortcodes($values['after_html'], $form); |
|
68 | +echo FrmFormsHelper::replace_shortcodes( $values['after_html'], $form ); |
|
69 | 69 | |
70 | 70 | if ( FrmForm::show_submit( $form ) ) { |
71 | 71 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | </fieldset> |
79 | 79 | </div> |
80 | 80 | <?php |
81 | -if ( has_action('frm_entries_footer_scripts') ) { |
|
81 | +if ( has_action( 'frm_entries_footer_scripts' ) ) { |
|
82 | 82 | ?><script type="text/javascript"><?php |
83 | 83 | do_action( 'frm_entries_footer_scripts', $values['fields'], $form ); |
84 | 84 | ?></script><?php |
@@ -180,6 +180,7 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @param int $id |
182 | 182 | * @param array $values |
183 | + * @param string $update_type |
|
183 | 184 | * @return boolean|int $query_results |
184 | 185 | */ |
185 | 186 | private static function update_entry( $id, $values, $update_type ) { |
@@ -563,6 +564,9 @@ discard block |
||
563 | 564 | return $new_values; |
564 | 565 | } |
565 | 566 | |
567 | + /** |
|
568 | + * @param string $name |
|
569 | + */ |
|
566 | 570 | private static function get_entry_value( $values, $name, $default ) { |
567 | 571 | return isset( $values[ $name ] ) ? $values[ $name ] : $default; |
568 | 572 | } |
@@ -6,11 +6,11 @@ discard block |
||
6 | 6 | class FrmEntry { |
7 | 7 | |
8 | 8 | /** |
9 | - * Create a new entry |
|
10 | - * |
|
11 | - * @param array $values |
|
12 | - * @return int | boolean $entry_id |
|
13 | - */ |
|
9 | + * Create a new entry |
|
10 | + * |
|
11 | + * @param array $values |
|
12 | + * @return int | boolean $entry_id |
|
13 | + */ |
|
14 | 14 | public static function create( $values ) { |
15 | 15 | $entry_id = self::create_entry( $values, 'standard' ); |
16 | 16 | |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | - * Create a new entry with some differences depending on type |
|
22 | - * |
|
23 | - * @param array $values |
|
24 | - * @param string $type |
|
25 | - * @return int | boolean $entry_id |
|
26 | - */ |
|
21 | + * Create a new entry with some differences depending on type |
|
22 | + * |
|
23 | + * @param array $values |
|
24 | + * @param string $type |
|
25 | + * @return int | boolean $entry_id |
|
26 | + */ |
|
27 | 27 | private static function create_entry( $values, $type ) { |
28 | 28 | $new_values = self::before_insert_entry_in_database( $values, $type ); |
29 | 29 | |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | return $entry_id; |
38 | 38 | } |
39 | 39 | |
40 | - /** |
|
41 | - * check for duplicate entries created in the last minute |
|
42 | - * @return boolean |
|
43 | - */ |
|
40 | + /** |
|
41 | + * check for duplicate entries created in the last minute |
|
42 | + * @return boolean |
|
43 | + */ |
|
44 | 44 | public static function is_duplicate( $new_values, $values ) { |
45 | 45 | $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values ); |
46 | 46 | |
@@ -48,55 +48,55 @@ discard block |
||
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
51 | - $check_val = $new_values; |
|
51 | + $check_val = $new_values; |
|
52 | 52 | $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) ); |
53 | 53 | |
54 | 54 | unset( $check_val['created_at'], $check_val['updated_at'] ); |
55 | 55 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
56 | 56 | |
57 | - if ( $new_values['item_key'] == $new_values['name'] ) { |
|
58 | - unset($check_val['name']); |
|
59 | - } |
|
57 | + if ( $new_values['item_key'] == $new_values['name'] ) { |
|
58 | + unset($check_val['name']); |
|
59 | + } |
|
60 | 60 | |
61 | - global $wpdb; |
|
61 | + global $wpdb; |
|
62 | 62 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
63 | 63 | |
64 | - if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
65 | - return false; |
|
66 | - } |
|
64 | + if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
65 | + return false; |
|
66 | + } |
|
67 | 67 | |
68 | - $is_duplicate = false; |
|
69 | - foreach ( $entry_exists as $entry_exist ) { |
|
70 | - $is_duplicate = true; |
|
68 | + $is_duplicate = false; |
|
69 | + foreach ( $entry_exists as $entry_exist ) { |
|
70 | + $is_duplicate = true; |
|
71 | 71 | |
72 | - //add more checks here to make sure it's a duplicate |
|
73 | - $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
74 | - $field_metas = array(); |
|
75 | - foreach ( $metas as $meta ) { |
|
72 | + //add more checks here to make sure it's a duplicate |
|
73 | + $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
74 | + $field_metas = array(); |
|
75 | + foreach ( $metas as $meta ) { |
|
76 | 76 | $field_metas[ $meta->field_id ] = $meta->meta_value; |
77 | - } |
|
78 | - |
|
79 | - // If prev entry is empty and current entry is not, they are not duplicates |
|
80 | - $filtered_vals = array_filter( $values['item_meta'] ); |
|
81 | - if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
82 | - return false; |
|
83 | - } |
|
84 | - |
|
85 | - $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
86 | - foreach ( $diff as $field_id => $meta_value ) { |
|
87 | - if ( ! empty($meta_value) ) { |
|
88 | - $is_duplicate = false; |
|
89 | - continue; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - if ( $is_duplicate ) { |
|
77 | + } |
|
78 | + |
|
79 | + // If prev entry is empty and current entry is not, they are not duplicates |
|
80 | + $filtered_vals = array_filter( $values['item_meta'] ); |
|
81 | + if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
82 | + return false; |
|
83 | + } |
|
84 | + |
|
85 | + $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
86 | + foreach ( $diff as $field_id => $meta_value ) { |
|
87 | + if ( ! empty($meta_value) ) { |
|
88 | + $is_duplicate = false; |
|
89 | + continue; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + if ( $is_duplicate ) { |
|
94 | 94 | break; |
95 | - } |
|
96 | - } |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - return $is_duplicate; |
|
99 | - } |
|
98 | + return $is_duplicate; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Determine if an entry needs to be checked as a possible duplicate |
@@ -125,48 +125,48 @@ discard block |
||
125 | 125 | return true; |
126 | 126 | } |
127 | 127 | |
128 | - public static function duplicate( $id ) { |
|
129 | - global $wpdb; |
|
128 | + public static function duplicate( $id ) { |
|
129 | + global $wpdb; |
|
130 | 130 | |
131 | - $values = self::getOne( $id ); |
|
131 | + $values = self::getOne( $id ); |
|
132 | 132 | |
133 | - $new_values = array(); |
|
133 | + $new_values = array(); |
|
134 | 134 | $new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
135 | - $new_values['name'] = $values->name; |
|
136 | - $new_values['is_draft'] = $values->is_draft; |
|
135 | + $new_values['name'] = $values->name; |
|
136 | + $new_values['is_draft'] = $values->is_draft; |
|
137 | 137 | $new_values['user_id'] = (int) $values->user_id; |
138 | 138 | $new_values['updated_by'] = (int) $values->user_id; |
139 | - $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
139 | + $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
140 | 140 | $new_values['created_at'] = current_time( 'mysql', 1 ); |
141 | 141 | $new_values['updated_at'] = $new_values['created_at']; |
142 | 142 | |
143 | 143 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
144 | - if ( ! $query_results ) { |
|
145 | - return false; |
|
146 | - } |
|
144 | + if ( ! $query_results ) { |
|
145 | + return false; |
|
146 | + } |
|
147 | 147 | |
148 | - $entry_id = $wpdb->insert_id; |
|
148 | + $entry_id = $wpdb->insert_id; |
|
149 | 149 | |
150 | - global $frm_vars; |
|
151 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
152 | - $frm_vars['saved_entries'] = array(); |
|
153 | - } |
|
154 | - $frm_vars['saved_entries'][] = (int) $entry_id; |
|
150 | + global $frm_vars; |
|
151 | + if ( ! isset($frm_vars['saved_entries']) ) { |
|
152 | + $frm_vars['saved_entries'] = array(); |
|
153 | + } |
|
154 | + $frm_vars['saved_entries'][] = (int) $entry_id; |
|
155 | 155 | |
156 | - FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
156 | + FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
157 | 157 | self::clear_cache(); |
158 | 158 | |
159 | 159 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
160 | - return $entry_id; |
|
161 | - } |
|
160 | + return $entry_id; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | /** |
164 | - * Update an entry (not via XML) |
|
165 | - * |
|
166 | - * @param int $id |
|
167 | - * @param array $values |
|
168 | - * @return boolean|int $update_results |
|
169 | - */ |
|
164 | + * Update an entry (not via XML) |
|
165 | + * |
|
166 | + * @param int $id |
|
167 | + * @param array $values |
|
168 | + * @return boolean|int $update_results |
|
169 | + */ |
|
170 | 170 | public static function update( $id, $values ) { |
171 | 171 | $update_results = self::update_entry( $id, $values, 'standard' ); |
172 | 172 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Update an entry with some differences depending on the update type |
|
178 | - * |
|
179 | - * @since 2.0.16 |
|
180 | - * |
|
181 | - * @param int $id |
|
182 | - * @param array $values |
|
183 | - * @return boolean|int $query_results |
|
184 | - */ |
|
177 | + * Update an entry with some differences depending on the update type |
|
178 | + * |
|
179 | + * @since 2.0.16 |
|
180 | + * |
|
181 | + * @param int $id |
|
182 | + * @param array $values |
|
183 | + * @return boolean|int $query_results |
|
184 | + */ |
|
185 | 185 | private static function update_entry( $id, $values, $update_type ) { |
186 | 186 | global $wpdb; |
187 | 187 | |
@@ -200,34 +200,34 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | public static function destroy( $id ) { |
203 | - global $wpdb; |
|
204 | - $id = (int) $id; |
|
203 | + global $wpdb; |
|
204 | + $id = (int) $id; |
|
205 | 205 | |
206 | 206 | $entry = self::getOne( $id ); |
207 | - if ( ! $entry ) { |
|
208 | - $result = false; |
|
209 | - return $result; |
|
210 | - } |
|
207 | + if ( ! $entry ) { |
|
208 | + $result = false; |
|
209 | + return $result; |
|
210 | + } |
|
211 | 211 | |
212 | - do_action('frm_before_destroy_entry', $id, $entry); |
|
212 | + do_action('frm_before_destroy_entry', $id, $entry); |
|
213 | 213 | |
214 | 214 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) ); |
215 | 215 | $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) ); |
216 | 216 | |
217 | 217 | self::clear_cache(); |
218 | 218 | |
219 | - return $result; |
|
220 | - } |
|
219 | + return $result; |
|
220 | + } |
|
221 | 221 | |
222 | 222 | public static function update_form( $id, $value, $form_id ) { |
223 | - global $wpdb; |
|
224 | - $form_id = isset($value) ? $form_id : null; |
|
223 | + global $wpdb; |
|
224 | + $form_id = isset($value) ? $form_id : null; |
|
225 | 225 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
226 | 226 | if ( $result ) { |
227 | 227 | self::clear_cache(); |
228 | 228 | } |
229 | - return $result; |
|
230 | - } |
|
229 | + return $result; |
|
230 | + } |
|
231 | 231 | |
232 | 232 | /** |
233 | 233 | * Clear entry caching |
@@ -263,159 +263,159 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | public static function getOne( $id, $meta = false ) { |
266 | - global $wpdb; |
|
266 | + global $wpdb; |
|
267 | 267 | |
268 | - $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
268 | + $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
269 | 269 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
270 | 270 | |
271 | - $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
272 | - $query_args = array( $id ); |
|
273 | - $query = $wpdb->prepare( $query, $query_args ); |
|
271 | + $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
272 | + $query_args = array( $id ); |
|
273 | + $query = $wpdb->prepare( $query, $query_args ); |
|
274 | 274 | |
275 | - if ( ! $meta ) { |
|
275 | + if ( ! $meta ) { |
|
276 | 276 | $entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
277 | - return stripslashes_deep($entry); |
|
278 | - } |
|
277 | + return stripslashes_deep($entry); |
|
278 | + } |
|
279 | 279 | |
280 | - $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
|
281 | - if ( $entry !== false ) { |
|
282 | - return stripslashes_deep($entry); |
|
283 | - } |
|
280 | + $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
|
281 | + if ( $entry !== false ) { |
|
282 | + return stripslashes_deep($entry); |
|
283 | + } |
|
284 | 284 | |
285 | - $entry = $wpdb->get_row( $query ); |
|
286 | - $entry = self::get_meta($entry); |
|
285 | + $entry = $wpdb->get_row( $query ); |
|
286 | + $entry = self::get_meta($entry); |
|
287 | 287 | |
288 | - return stripslashes_deep($entry); |
|
289 | - } |
|
288 | + return stripslashes_deep($entry); |
|
289 | + } |
|
290 | 290 | |
291 | 291 | public static function get_meta( $entry ) { |
292 | - if ( ! $entry ) { |
|
293 | - return $entry; |
|
294 | - } |
|
292 | + if ( ! $entry ) { |
|
293 | + return $entry; |
|
294 | + } |
|
295 | 295 | |
296 | - global $wpdb; |
|
296 | + global $wpdb; |
|
297 | 297 | $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0 ), 'field_id, meta_value, field_key, item_id' ); |
298 | 298 | |
299 | - $entry->metas = array(); |
|
299 | + $entry->metas = array(); |
|
300 | 300 | |
301 | 301 | $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) ); |
302 | - foreach ( $metas as $meta_val ) { |
|
303 | - if ( $meta_val->item_id == $entry->id ) { |
|
302 | + foreach ( $metas as $meta_val ) { |
|
303 | + if ( $meta_val->item_id == $entry->id ) { |
|
304 | 304 | $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
305 | 305 | if ( $include_key ) { |
306 | 306 | $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
307 | 307 | } |
308 | - continue; |
|
309 | - } |
|
308 | + continue; |
|
309 | + } |
|
310 | 310 | |
311 | - // include sub entries in an array |
|
311 | + // include sub entries in an array |
|
312 | 312 | if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
313 | 313 | $entry->metas[ $meta_val->field_id ] = array(); |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | 316 | $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
317 | 317 | |
318 | - unset($meta_val); |
|
319 | - } |
|
320 | - unset($metas); |
|
318 | + unset($meta_val); |
|
319 | + } |
|
320 | + unset($metas); |
|
321 | 321 | |
322 | 322 | FrmAppHelper::set_cache( $entry->id, $entry, 'frm_entry' ); |
323 | 323 | |
324 | - return $entry; |
|
325 | - } |
|
324 | + return $entry; |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
328 | - * @param string $id |
|
329 | - */ |
|
327 | + /** |
|
328 | + * @param string $id |
|
329 | + */ |
|
330 | 330 | public static function exists( $id ) { |
331 | - global $wpdb; |
|
332 | - |
|
333 | - if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) { |
|
334 | - $exists = true; |
|
335 | - return $exists; |
|
336 | - } |
|
337 | - |
|
338 | - if ( is_numeric($id) ) { |
|
339 | - $where = array( 'id' => $id ); |
|
340 | - } else { |
|
341 | - $where = array( 'item_key' => $id ); |
|
342 | - } |
|
331 | + global $wpdb; |
|
332 | + |
|
333 | + if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) { |
|
334 | + $exists = true; |
|
335 | + return $exists; |
|
336 | + } |
|
337 | + |
|
338 | + if ( is_numeric($id) ) { |
|
339 | + $where = array( 'id' => $id ); |
|
340 | + } else { |
|
341 | + $where = array( 'item_key' => $id ); |
|
342 | + } |
|
343 | 343 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
344 | 344 | |
345 | - $exists = ($id && $id > 0) ? true : false; |
|
346 | - return $exists; |
|
347 | - } |
|
345 | + $exists = ($id && $id > 0) ? true : false; |
|
346 | + return $exists; |
|
347 | + } |
|
348 | 348 | |
349 | - public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
349 | + public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
350 | 350 | global $wpdb; |
351 | 351 | |
352 | - $limit = FrmAppHelper::esc_limit($limit); |
|
352 | + $limit = FrmAppHelper::esc_limit($limit); |
|
353 | 353 | |
354 | - $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
355 | - $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
354 | + $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
355 | + $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
356 | 356 | |
357 | - if ( false === $entries ) { |
|
358 | - $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
357 | + if ( false === $entries ) { |
|
358 | + $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
359 | 359 | $table = $wpdb->prefix . 'frm_items it '; |
360 | 360 | |
361 | - if ( $inc_form ) { |
|
362 | - $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
363 | - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
364 | - } |
|
361 | + if ( $inc_form ) { |
|
362 | + $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
363 | + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
364 | + } |
|
365 | 365 | |
366 | - if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
367 | - // sort by a requested field |
|
368 | - $field_id = (int) $order_matches[1]; |
|
366 | + if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
367 | + // sort by a requested field |
|
368 | + $field_id = (int) $order_matches[1]; |
|
369 | 369 | $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id; |
370 | 370 | unset( $order_matches, $field_id ); |
371 | - } |
|
371 | + } |
|
372 | 372 | |
373 | 373 | // prepare the query |
374 | 374 | $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
375 | 375 | |
376 | - $entries = $wpdb->get_results($query, OBJECT_K); |
|
377 | - unset($query); |
|
376 | + $entries = $wpdb->get_results($query, OBJECT_K); |
|
377 | + unset($query); |
|
378 | 378 | |
379 | 379 | FrmAppHelper::set_cache( $cache_key, $entries, 'frm_entry' ); |
380 | - } |
|
380 | + } |
|
381 | 381 | |
382 | - if ( ! $meta || ! $entries ) { |
|
383 | - return stripslashes_deep($entries); |
|
384 | - } |
|
385 | - unset($meta); |
|
382 | + if ( ! $meta || ! $entries ) { |
|
383 | + return stripslashes_deep($entries); |
|
384 | + } |
|
385 | + unset($meta); |
|
386 | 386 | |
387 | - if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
387 | + if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
388 | 388 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | - $meta_where = array( 'field_id !' => 0 ); |
|
392 | - if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
393 | - $meta_where['fi.form_id'] = $where['it.form_id']; |
|
394 | - } else { |
|
395 | - $meta_where['item_id'] = array_keys( $entries ); |
|
396 | - } |
|
391 | + $meta_where = array( 'field_id !' => 0 ); |
|
392 | + if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
393 | + $meta_where['fi.form_id'] = $where['it.form_id']; |
|
394 | + } else { |
|
395 | + $meta_where['item_id'] = array_keys( $entries ); |
|
396 | + } |
|
397 | 397 | |
398 | - $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
398 | + $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
399 | 399 | |
400 | - unset( $meta_where ); |
|
400 | + unset( $meta_where ); |
|
401 | 401 | |
402 | - if ( ! $metas ) { |
|
403 | - return stripslashes_deep($entries); |
|
404 | - } |
|
402 | + if ( ! $metas ) { |
|
403 | + return stripslashes_deep($entries); |
|
404 | + } |
|
405 | 405 | |
406 | - foreach ( $metas as $m_key => $meta_val ) { |
|
407 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
408 | - continue; |
|
409 | - } |
|
406 | + foreach ( $metas as $m_key => $meta_val ) { |
|
407 | + if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
408 | + continue; |
|
409 | + } |
|
410 | 410 | |
411 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
411 | + if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
412 | 412 | $entries[ $meta_val->item_id ]->metas = array(); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | 415 | $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
416 | 416 | |
417 | - unset($m_key, $meta_val); |
|
418 | - } |
|
417 | + unset($m_key, $meta_val); |
|
418 | + } |
|
419 | 419 | |
420 | 420 | if ( ! FrmAppHelper::prevent_caching() ) { |
421 | 421 | foreach ( $entries as $entry ) { |
@@ -424,31 +424,31 @@ discard block |
||
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - return stripslashes_deep($entries); |
|
428 | - } |
|
427 | + return stripslashes_deep($entries); |
|
428 | + } |
|
429 | 429 | |
430 | - // Pagination Methods |
|
431 | - public static function getRecordCount( $where = '' ) { |
|
432 | - global $wpdb; |
|
430 | + // Pagination Methods |
|
431 | + public static function getRecordCount( $where = '' ) { |
|
432 | + global $wpdb; |
|
433 | 433 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
434 | 434 | |
435 | - if ( is_numeric($where) ) { |
|
436 | - $table_join = 'frm_items'; |
|
437 | - $where = array( 'form_id' => $where ); |
|
438 | - } |
|
435 | + if ( is_numeric($where) ) { |
|
436 | + $table_join = 'frm_items'; |
|
437 | + $where = array( 'form_id' => $where ); |
|
438 | + } |
|
439 | 439 | |
440 | - if ( is_array( $where ) ) { |
|
441 | - $count = FrmDb::get_count( $table_join, $where ); |
|
442 | - } else { |
|
440 | + if ( is_array( $where ) ) { |
|
441 | + $count = FrmDb::get_count( $table_join, $where ); |
|
442 | + } else { |
|
443 | 443 | $cache_key = 'count_' . maybe_serialize( $where ); |
444 | 444 | $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ); |
445 | 445 | $count = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_var' ); |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - return $count; |
|
449 | - } |
|
448 | + return $count; |
|
449 | + } |
|
450 | 450 | |
451 | - public static function getPageCount( $p_size, $where = '' ) { |
|
451 | + public static function getPageCount( $p_size, $where = '' ) { |
|
452 | 452 | $p_size = (int) $p_size; |
453 | 453 | $count = 1; |
454 | 454 | if ( $p_size ) { |
@@ -459,16 +459,16 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | return $count; |
462 | - } |
|
462 | + } |
|
463 | 463 | |
464 | 464 | /** |
465 | - * Prepare the data before inserting it into the database |
|
466 | - * |
|
467 | - * @since 2.0.16 |
|
468 | - * @param array $values |
|
469 | - * @param string $type |
|
470 | - * @return array $new_values |
|
471 | - */ |
|
465 | + * Prepare the data before inserting it into the database |
|
466 | + * |
|
467 | + * @since 2.0.16 |
|
468 | + * @param array $values |
|
469 | + * @param string $type |
|
470 | + * @return array $new_values |
|
471 | + */ |
|
472 | 472 | private static function before_insert_entry_in_database( &$values, $type ) { |
473 | 473 | |
474 | 474 | self::sanitize_entry_post( $values ); |
@@ -483,13 +483,13 @@ discard block |
||
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
486 | - * Create an entry and perform after create actions |
|
487 | - * |
|
488 | - * @since 2.0.16 |
|
489 | - * @param array $values |
|
490 | - * @param array $new_values |
|
491 | - * @return boolean|int $entry_id |
|
492 | - */ |
|
486 | + * Create an entry and perform after create actions |
|
487 | + * |
|
488 | + * @since 2.0.16 |
|
489 | + * @param array $values |
|
490 | + * @param array $new_values |
|
491 | + * @return boolean|int $entry_id |
|
492 | + */ |
|
493 | 493 | private static function continue_to_create_entry( $values, $new_values ) { |
494 | 494 | $entry_id = self::insert_entry_into_database( $new_values ); |
495 | 495 | if ( ! $entry_id ) { |
@@ -501,37 +501,37 @@ discard block |
||
501 | 501 | return $entry_id; |
502 | 502 | } |
503 | 503 | |
504 | - /** |
|
505 | - * Sanitize the POST values before we use them |
|
506 | - * |
|
507 | - * @since 2.0 |
|
508 | - * @param array $values The POST values by reference |
|
509 | - */ |
|
510 | - public static function sanitize_entry_post( &$values ) { |
|
511 | - $sanitize_method = array( |
|
512 | - 'form_id' => 'absint', |
|
513 | - 'frm_action' => 'sanitize_title', |
|
514 | - 'form_key' => 'sanitize_title', |
|
515 | - 'item_key' => 'sanitize_title', |
|
516 | - 'item_name' => 'sanitize_text_field', |
|
517 | - 'frm_saving_draft' => 'absint', |
|
518 | - 'is_draft' => 'absint', |
|
519 | - 'post_id' => 'absint', |
|
520 | - 'parent_item_id' => 'absint', |
|
521 | - 'created_at' => 'sanitize_text_field', |
|
522 | - 'updated_at' => 'sanitize_text_field', |
|
523 | - ); |
|
524 | - |
|
525 | - FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
526 | - } |
|
504 | + /** |
|
505 | + * Sanitize the POST values before we use them |
|
506 | + * |
|
507 | + * @since 2.0 |
|
508 | + * @param array $values The POST values by reference |
|
509 | + */ |
|
510 | + public static function sanitize_entry_post( &$values ) { |
|
511 | + $sanitize_method = array( |
|
512 | + 'form_id' => 'absint', |
|
513 | + 'frm_action' => 'sanitize_title', |
|
514 | + 'form_key' => 'sanitize_title', |
|
515 | + 'item_key' => 'sanitize_title', |
|
516 | + 'item_name' => 'sanitize_text_field', |
|
517 | + 'frm_saving_draft' => 'absint', |
|
518 | + 'is_draft' => 'absint', |
|
519 | + 'post_id' => 'absint', |
|
520 | + 'parent_item_id' => 'absint', |
|
521 | + 'created_at' => 'sanitize_text_field', |
|
522 | + 'updated_at' => 'sanitize_text_field', |
|
523 | + ); |
|
524 | + |
|
525 | + FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
526 | + } |
|
527 | 527 | |
528 | 528 | /** |
529 | - * Prepare the new values for inserting into the database |
|
530 | - * |
|
531 | - * @since 2.0.16 |
|
532 | - * @param array $values |
|
533 | - * @return array $new_values |
|
534 | - */ |
|
529 | + * Prepare the new values for inserting into the database |
|
530 | + * |
|
531 | + * @since 2.0.16 |
|
532 | + * @param array $values |
|
533 | + * @return array $new_values |
|
534 | + */ |
|
535 | 535 | private static function package_entry_data( &$values ) { |
536 | 536 | global $wpdb; |
537 | 537 | |
@@ -584,34 +584,34 @@ discard block |
||
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
587 | - * Get the is_draft value for a new entry |
|
588 | - * |
|
589 | - * @since 2.0.16 |
|
590 | - * @param array $values |
|
591 | - * @return int |
|
592 | - */ |
|
587 | + * Get the is_draft value for a new entry |
|
588 | + * |
|
589 | + * @since 2.0.16 |
|
590 | + * @param array $values |
|
591 | + * @return int |
|
592 | + */ |
|
593 | 593 | private static function get_is_draft_value( $values ) { |
594 | 594 | return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
598 | - * Get the created_at value for a new entry |
|
599 | - * |
|
600 | - * @since 2.0.16 |
|
601 | - * @param array $values |
|
602 | - * @return string |
|
603 | - */ |
|
598 | + * Get the created_at value for a new entry |
|
599 | + * |
|
600 | + * @since 2.0.16 |
|
601 | + * @param array $values |
|
602 | + * @return string |
|
603 | + */ |
|
604 | 604 | private static function get_created_at( $values ) { |
605 | 605 | return self::get_entry_value( $values, 'created_at', current_time( 'mysql', 1 ) ); |
606 | 606 | } |
607 | 607 | |
608 | 608 | /** |
609 | - * Get the updated_at value for a new entry |
|
610 | - * |
|
611 | - * @since 2.0.16 |
|
612 | - * @param array $values |
|
613 | - * @return string |
|
614 | - */ |
|
609 | + * Get the updated_at value for a new entry |
|
610 | + * |
|
611 | + * @since 2.0.16 |
|
612 | + * @param array $values |
|
613 | + * @return string |
|
614 | + */ |
|
615 | 615 | private static function get_updated_at( $values ) { |
616 | 616 | if ( isset( $values['updated_at'] ) ) { |
617 | 617 | $updated_at = $values['updated_at']; |
@@ -623,12 +623,12 @@ discard block |
||
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
626 | - * Get the description value for a new entry |
|
627 | - * |
|
628 | - * @since 2.0.16 |
|
629 | - * @param array $values |
|
630 | - * @return string |
|
631 | - */ |
|
626 | + * Get the description value for a new entry |
|
627 | + * |
|
628 | + * @since 2.0.16 |
|
629 | + * @param array $values |
|
630 | + * @return string |
|
631 | + */ |
|
632 | 632 | private static function get_entry_description( $values ) { |
633 | 633 | if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) { |
634 | 634 | $description = maybe_serialize( $values['description'] ); |
@@ -643,12 +643,12 @@ discard block |
||
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
646 | - * Get the user_id value for a new entry |
|
647 | - * |
|
648 | - * @since 2.0.16 |
|
649 | - * @param array $values |
|
650 | - * @return int |
|
651 | - */ |
|
646 | + * Get the user_id value for a new entry |
|
647 | + * |
|
648 | + * @since 2.0.16 |
|
649 | + * @param array $values |
|
650 | + * @return int |
|
651 | + */ |
|
652 | 652 | private static function get_entry_user_id( $values ) { |
653 | 653 | if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) { |
654 | 654 | $user_id = $values['frm_user_id']; |
@@ -661,12 +661,12 @@ discard block |
||
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
664 | - * Insert new entry into the database |
|
665 | - * |
|
666 | - * @since 2.0.16 |
|
667 | - * @param array $new_values |
|
668 | - * @return int | boolean $entry_id |
|
669 | - */ |
|
664 | + * Insert new entry into the database |
|
665 | + * |
|
666 | + * @since 2.0.16 |
|
667 | + * @param array $new_values |
|
668 | + * @return int | boolean $entry_id |
|
669 | + */ |
|
670 | 670 | private static function insert_entry_into_database( $new_values ) { |
671 | 671 | global $wpdb; |
672 | 672 | |
@@ -682,11 +682,11 @@ discard block |
||
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
685 | - * Add the new entry to global $frm_vars |
|
686 | - * |
|
687 | - * @since 2.0.16 |
|
688 | - * @param int $entry_id |
|
689 | - */ |
|
685 | + * Add the new entry to global $frm_vars |
|
686 | + * |
|
687 | + * @since 2.0.16 |
|
688 | + * @param int $entry_id |
|
689 | + */ |
|
690 | 690 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
691 | 691 | global $frm_vars; |
692 | 692 | |
@@ -698,12 +698,12 @@ discard block |
||
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
701 | - * Add entry metas, if there are any |
|
702 | - * |
|
703 | - * @since 2.0.16 |
|
704 | - * @param array $values |
|
705 | - * @param int $entry_id |
|
706 | - */ |
|
701 | + * Add entry metas, if there are any |
|
702 | + * |
|
703 | + * @since 2.0.16 |
|
704 | + * @param array $values |
|
705 | + * @param int $entry_id |
|
706 | + */ |
|
707 | 707 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
708 | 708 | if ( isset($values['item_meta']) ) { |
709 | 709 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
@@ -711,12 +711,12 @@ discard block |
||
711 | 711 | } |
712 | 712 | |
713 | 713 | /** |
714 | - * Trigger frm_after_create_entry hooks |
|
715 | - * |
|
716 | - * @since 2.0.16 |
|
717 | - * @param int $entry_id |
|
718 | - * @param array $new_values |
|
719 | - */ |
|
714 | + * Trigger frm_after_create_entry hooks |
|
715 | + * |
|
716 | + * @since 2.0.16 |
|
717 | + * @param int $entry_id |
|
718 | + * @param array $new_values |
|
719 | + */ |
|
720 | 720 | private static function after_entry_created_actions( $entry_id, $values, $new_values ) { |
721 | 721 | // this is a child entry |
722 | 722 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
@@ -726,13 +726,13 @@ discard block |
||
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
729 | - * Actions to perform immediately after an entry is inserted in the frm_items database |
|
730 | - * |
|
731 | - * @since 2.0.16 |
|
732 | - * @param array $values |
|
733 | - * @param array $new_values |
|
734 | - * @param int $entry_id |
|
735 | - */ |
|
729 | + * Actions to perform immediately after an entry is inserted in the frm_items database |
|
730 | + * |
|
731 | + * @since 2.0.16 |
|
732 | + * @param array $values |
|
733 | + * @param array $new_values |
|
734 | + * @param int $entry_id |
|
735 | + */ |
|
736 | 736 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
737 | 737 | |
738 | 738 | self::add_new_entry_to_frm_vars( $entry_id ); |
@@ -745,14 +745,14 @@ discard block |
||
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
748 | - * Perform some actions right before updating an entry |
|
749 | - * |
|
750 | - * @since 2.0.16 |
|
751 | - * @param int $id |
|
752 | - * @param array $values |
|
753 | - * @param string $update_type |
|
754 | - * @return boolean $update |
|
755 | - */ |
|
748 | + * Perform some actions right before updating an entry |
|
749 | + * |
|
750 | + * @since 2.0.16 |
|
751 | + * @param int $id |
|
752 | + * @param array $values |
|
753 | + * @param string $update_type |
|
754 | + * @return boolean $update |
|
755 | + */ |
|
756 | 756 | private static function before_update_entry( $id, &$values, $update_type ) { |
757 | 757 | $update = true; |
758 | 758 | |
@@ -770,13 +770,13 @@ discard block |
||
770 | 770 | } |
771 | 771 | |
772 | 772 | /** |
773 | - * Package the entry data for updating |
|
774 | - * |
|
775 | - * @since 2.0.16 |
|
776 | - * @param int $id |
|
777 | - * @param array $values |
|
778 | - * @return array $new_values |
|
779 | - */ |
|
773 | + * Package the entry data for updating |
|
774 | + * |
|
775 | + * @since 2.0.16 |
|
776 | + * @param int $id |
|
777 | + * @param array $values |
|
778 | + * @return array $new_values |
|
779 | + */ |
|
780 | 780 | private static function package_entry_to_update( $id, $values ) { |
781 | 781 | global $wpdb; |
782 | 782 | |
@@ -810,14 +810,14 @@ discard block |
||
810 | 810 | } |
811 | 811 | |
812 | 812 | /** |
813 | - * Perform some actions right after updating an entry |
|
814 | - * |
|
815 | - * @since 2.0.16 |
|
816 | - * @param boolean|int $query_results |
|
817 | - * @param int $id |
|
818 | - * @param array $values |
|
819 | - * @param array $new_values |
|
820 | - */ |
|
813 | + * Perform some actions right after updating an entry |
|
814 | + * |
|
815 | + * @since 2.0.16 |
|
816 | + * @param boolean|int $query_results |
|
817 | + * @param int $id |
|
818 | + * @param array $values |
|
819 | + * @param array $new_values |
|
820 | + */ |
|
821 | 821 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
822 | 822 | if ( $query_results ) { |
823 | 823 | self::clear_cache(); |
@@ -839,13 +839,13 @@ discard block |
||
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
842 | - * Create entry from an XML import |
|
843 | - * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
844 | - * |
|
845 | - * @since 2.0.16 |
|
846 | - * @param array $values |
|
847 | - * @return int | boolean $entry_id |
|
848 | - */ |
|
842 | + * Create entry from an XML import |
|
843 | + * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
844 | + * |
|
845 | + * @since 2.0.16 |
|
846 | + * @param array $values |
|
847 | + * @return int | boolean $entry_id |
|
848 | + */ |
|
849 | 849 | public static function create_entry_from_xml( $values ) { |
850 | 850 | $entry_id = self::create_entry( $values, 'xml' ); |
851 | 851 | |
@@ -853,28 +853,28 @@ discard block |
||
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
856 | - * Update entry from an XML import |
|
857 | - * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
858 | - * |
|
859 | - * @since 2.0.16 |
|
860 | - * @param int $id |
|
861 | - * @param array $values |
|
862 | - * @return int | boolean $updated |
|
863 | - */ |
|
856 | + * Update entry from an XML import |
|
857 | + * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
858 | + * |
|
859 | + * @since 2.0.16 |
|
860 | + * @param int $id |
|
861 | + * @param array $values |
|
862 | + * @return int | boolean $updated |
|
863 | + */ |
|
864 | 864 | public static function update_entry_from_xml( $id, $values ) { |
865 | 865 | $updated = self::update_entry( $id, $values, 'xml' ); |
866 | 866 | |
867 | 867 | return $updated; |
868 | 868 | } |
869 | 869 | |
870 | - /** |
|
871 | - * @param string $key |
|
872 | - * @return int entry_id |
|
873 | - */ |
|
870 | + /** |
|
871 | + * @param string $key |
|
872 | + * @return int entry_id |
|
873 | + */ |
|
874 | 874 | public static function get_id_by_key( $key ) { |
875 | - $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
876 | - return $entry_id; |
|
877 | - } |
|
875 | + $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
876 | + return $entry_id; |
|
877 | + } |
|
878 | 878 | |
879 | 879 | public static function validate( $values, $exclude = false ) { |
880 | 880 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryValidate::validate' ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
56 | 56 | |
57 | 57 | if ( $new_values['item_key'] == $new_values['name'] ) { |
58 | - unset($check_val['name']); |
|
58 | + unset( $check_val['name'] ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | global $wpdb; |
62 | 62 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
63 | 63 | |
64 | - if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
64 | + if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | $is_duplicate = true; |
71 | 71 | |
72 | 72 | //add more checks here to make sure it's a duplicate |
73 | - $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
73 | + $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); |
|
74 | 74 | $field_metas = array(); |
75 | 75 | foreach ( $metas as $meta ) { |
76 | - $field_metas[ $meta->field_id ] = $meta->meta_value; |
|
76 | + $field_metas[$meta->field_id] = $meta->meta_value; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | // If prev entry is empty and current entry is not, they are not duplicates |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | return false; |
83 | 83 | } |
84 | 84 | |
85 | - $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
85 | + $diff = array_diff_assoc( $field_metas, array_map( 'maybe_serialize', $values['item_meta'] ) ); |
|
86 | 86 | foreach ( $diff as $field_id => $meta_value ) { |
87 | - if ( ! empty($meta_value) ) { |
|
87 | + if ( ! empty( $meta_value ) ) { |
|
88 | 88 | $is_duplicate = false; |
89 | 89 | continue; |
90 | 90 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | // If CSV is importing, don't check for duplicates |
116 | - if ( defined('WP_IMPORTING') && WP_IMPORTING ) { |
|
116 | + if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
117 | 117 | return false; |
118 | 118 | } |
119 | 119 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $new_values['is_draft'] = $values->is_draft; |
137 | 137 | $new_values['user_id'] = (int) $values->user_id; |
138 | 138 | $new_values['updated_by'] = (int) $values->user_id; |
139 | - $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
139 | + $new_values['form_id'] = $values->form_id ? (int) $values->form_id : null; |
|
140 | 140 | $new_values['created_at'] = current_time( 'mysql', 1 ); |
141 | 141 | $new_values['updated_at'] = $new_values['created_at']; |
142 | 142 | |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | $entry_id = $wpdb->insert_id; |
149 | 149 | |
150 | 150 | global $frm_vars; |
151 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
151 | + if ( ! isset( $frm_vars['saved_entries'] ) ) { |
|
152 | 152 | $frm_vars['saved_entries'] = array(); |
153 | 153 | } |
154 | 154 | $frm_vars['saved_entries'][] = (int) $entry_id; |
155 | 155 | |
156 | - FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
156 | + FrmEntryMeta::duplicate_entry_metas( $id, $entry_id ); |
|
157 | 157 | self::clear_cache(); |
158 | 158 | |
159 | 159 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | $new_values = self::package_entry_to_update( $id, $values ); |
194 | 194 | |
195 | - $query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact('id') ); |
|
195 | + $query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) ); |
|
196 | 196 | |
197 | 197 | self::after_update_entry( $query_results, $id, $values, $new_values ); |
198 | 198 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | return $result; |
210 | 210 | } |
211 | 211 | |
212 | - do_action('frm_before_destroy_entry', $id, $entry); |
|
212 | + do_action( 'frm_before_destroy_entry', $id, $entry ); |
|
213 | 213 | |
214 | 214 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) ); |
215 | 215 | $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) ); |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | |
222 | 222 | public static function update_form( $id, $value, $form_id ) { |
223 | 223 | global $wpdb; |
224 | - $form_id = isset($value) ? $form_id : null; |
|
224 | + $form_id = isset( $value ) ? $form_id : null; |
|
225 | 225 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
226 | 226 | if ( $result ) { |
227 | 227 | self::clear_cache(); |
@@ -268,24 +268,24 @@ discard block |
||
268 | 268 | $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
269 | 269 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
270 | 270 | |
271 | - $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
271 | + $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s'; |
|
272 | 272 | $query_args = array( $id ); |
273 | 273 | $query = $wpdb->prepare( $query, $query_args ); |
274 | 274 | |
275 | 275 | if ( ! $meta ) { |
276 | 276 | $entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
277 | - return stripslashes_deep($entry); |
|
277 | + return stripslashes_deep( $entry ); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
281 | 281 | if ( $entry !== false ) { |
282 | - return stripslashes_deep($entry); |
|
282 | + return stripslashes_deep( $entry ); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | $entry = $wpdb->get_row( $query ); |
286 | - $entry = self::get_meta($entry); |
|
286 | + $entry = self::get_meta( $entry ); |
|
287 | 287 | |
288 | - return stripslashes_deep($entry); |
|
288 | + return stripslashes_deep( $entry ); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | public static function get_meta( $entry ) { |
@@ -301,23 +301,23 @@ discard block |
||
301 | 301 | $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) ); |
302 | 302 | foreach ( $metas as $meta_val ) { |
303 | 303 | if ( $meta_val->item_id == $entry->id ) { |
304 | - $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
|
304 | + $entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value ); |
|
305 | 305 | if ( $include_key ) { |
306 | - $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
|
306 | + $entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id]; |
|
307 | 307 | } |
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // include sub entries in an array |
312 | - if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
|
313 | - $entry->metas[ $meta_val->field_id ] = array(); |
|
312 | + if ( ! isset( $entry_metas[$meta_val->field_id] ) ) { |
|
313 | + $entry->metas[$meta_val->field_id] = array(); |
|
314 | 314 | } |
315 | 315 | |
316 | - $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
|
316 | + $entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value ); |
|
317 | 317 | |
318 | - unset($meta_val); |
|
318 | + unset( $meta_val ); |
|
319 | 319 | } |
320 | - unset($metas); |
|
320 | + unset( $metas ); |
|
321 | 321 | |
322 | 322 | FrmAppHelper::set_cache( $entry->id, $entry, 'frm_entry' ); |
323 | 323 | |
@@ -335,24 +335,24 @@ discard block |
||
335 | 335 | return $exists; |
336 | 336 | } |
337 | 337 | |
338 | - if ( is_numeric($id) ) { |
|
338 | + if ( is_numeric( $id ) ) { |
|
339 | 339 | $where = array( 'id' => $id ); |
340 | 340 | } else { |
341 | 341 | $where = array( 'item_key' => $id ); |
342 | 342 | } |
343 | 343 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
344 | 344 | |
345 | - $exists = ($id && $id > 0) ? true : false; |
|
345 | + $exists = ( $id && $id > 0 ) ? true : false; |
|
346 | 346 | return $exists; |
347 | 347 | } |
348 | 348 | |
349 | 349 | public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
350 | 350 | global $wpdb; |
351 | 351 | |
352 | - $limit = FrmAppHelper::esc_limit($limit); |
|
352 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
353 | 353 | |
354 | - $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
355 | - $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
354 | + $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form; |
|
355 | + $entries = wp_cache_get( $cache_key, 'frm_entry' ); |
|
356 | 356 | |
357 | 357 | if ( false === $entries ) { |
358 | 358 | $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
@@ -371,25 +371,25 @@ discard block |
||
371 | 371 | } |
372 | 372 | |
373 | 373 | // prepare the query |
374 | - $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
374 | + $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
375 | 375 | |
376 | - $entries = $wpdb->get_results($query, OBJECT_K); |
|
377 | - unset($query); |
|
376 | + $entries = $wpdb->get_results( $query, OBJECT_K ); |
|
377 | + unset( $query ); |
|
378 | 378 | |
379 | 379 | FrmAppHelper::set_cache( $cache_key, $entries, 'frm_entry' ); |
380 | 380 | } |
381 | 381 | |
382 | 382 | if ( ! $meta || ! $entries ) { |
383 | - return stripslashes_deep($entries); |
|
383 | + return stripslashes_deep( $entries ); |
|
384 | 384 | } |
385 | - unset($meta); |
|
385 | + unset( $meta ); |
|
386 | 386 | |
387 | - if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
387 | + if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) { |
|
388 | 388 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
389 | 389 | } |
390 | 390 | |
391 | 391 | $meta_where = array( 'field_id !' => 0 ); |
392 | - if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
392 | + if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) { |
|
393 | 393 | $meta_where['fi.form_id'] = $where['it.form_id']; |
394 | 394 | } else { |
395 | 395 | $meta_where['item_id'] = array_keys( $entries ); |
@@ -400,21 +400,21 @@ discard block |
||
400 | 400 | unset( $meta_where ); |
401 | 401 | |
402 | 402 | if ( ! $metas ) { |
403 | - return stripslashes_deep($entries); |
|
403 | + return stripslashes_deep( $entries ); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | foreach ( $metas as $m_key => $meta_val ) { |
407 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
407 | + if ( ! isset( $entries[$meta_val->item_id] ) ) { |
|
408 | 408 | continue; |
409 | 409 | } |
410 | 410 | |
411 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
412 | - $entries[ $meta_val->item_id ]->metas = array(); |
|
411 | + if ( ! isset( $entries[$meta_val->item_id]->metas ) ) { |
|
412 | + $entries[$meta_val->item_id]->metas = array(); |
|
413 | 413 | } |
414 | 414 | |
415 | - $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
|
415 | + $entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value ); |
|
416 | 416 | |
417 | - unset($m_key, $meta_val); |
|
417 | + unset( $m_key, $meta_val ); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | if ( ! FrmAppHelper::prevent_caching() ) { |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - return stripslashes_deep($entries); |
|
427 | + return stripslashes_deep( $entries ); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | // Pagination Methods |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | global $wpdb; |
433 | 433 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
434 | 434 | |
435 | - if ( is_numeric($where) ) { |
|
435 | + if ( is_numeric( $where ) ) { |
|
436 | 436 | $table_join = 'frm_items'; |
437 | 437 | $where = array( 'form_id' => $where ); |
438 | 438 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | self::sanitize_entry_post( $values ); |
475 | 475 | |
476 | 476 | if ( $type != 'xml' ) { |
477 | - $values = apply_filters('frm_pre_create_entry', $values); |
|
477 | + $values = apply_filters( 'frm_pre_create_entry', $values ); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | $new_values = self::package_entry_data( $values ); |
@@ -554,17 +554,17 @@ discard block |
||
554 | 554 | 'user_id' => self::get_entry_user_id( $values ), |
555 | 555 | ); |
556 | 556 | |
557 | - if ( is_array($new_values['name']) ) { |
|
558 | - $new_values['name'] = reset($new_values['name']); |
|
557 | + if ( is_array( $new_values['name'] ) ) { |
|
558 | + $new_values['name'] = reset( $new_values['name'] ); |
|
559 | 559 | } |
560 | 560 | |
561 | - $new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id']; |
|
561 | + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id']; |
|
562 | 562 | |
563 | 563 | return $new_values; |
564 | 564 | } |
565 | 565 | |
566 | 566 | private static function get_entry_value( $values, $name, $default ) { |
567 | - return isset( $values[ $name ] ) ? $values[ $name ] : $default; |
|
567 | + return isset( $values[$name] ) ? $values[$name] : $default; |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | } |
582 | 582 | |
583 | 583 | $ip = FrmAppHelper::get_ip_address(); |
584 | - if ( defined('WP_IMPORTING') && WP_IMPORTING ) { |
|
584 | + if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
585 | 585 | $ip = self::get_entry_value( $values, 'ip', $ip ); |
586 | 586 | } |
587 | 587 | return $ip; |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
695 | 695 | global $frm_vars; |
696 | 696 | |
697 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
697 | + if ( ! isset( $frm_vars['saved_entries'] ) ) { |
|
698 | 698 | $frm_vars['saved_entries'] = array(); |
699 | 699 | } |
700 | 700 | |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | * @param int $entry_id |
710 | 710 | */ |
711 | 711 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
712 | - if ( isset($values['item_meta']) ) { |
|
712 | + if ( isset( $values['item_meta'] ) ) { |
|
713 | 713 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
714 | 714 | } |
715 | 715 | } |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
727 | 727 | |
728 | 728 | do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) ); |
729 | - do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id , compact( 'is_child' ) ); |
|
729 | + do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) ); |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | /** |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | } |
768 | 768 | |
769 | 769 | if ( $update && $update_type != 'xml' ) { |
770 | - $values = apply_filters('frm_pre_update_entry', $values, $id); |
|
770 | + $values = apply_filters( 'frm_pre_update_entry', $values, $id ); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | return $update; |
@@ -788,27 +788,27 @@ discard block |
||
788 | 788 | 'name' => self::get_new_entry_name( $values ), |
789 | 789 | 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ), |
790 | 790 | 'is_draft' => self::get_is_draft_value( $values ), |
791 | - 'updated_at' => current_time('mysql', 1), |
|
792 | - 'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : get_current_user_id(), |
|
791 | + 'updated_at' => current_time( 'mysql', 1 ), |
|
792 | + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(), |
|
793 | 793 | ); |
794 | 794 | |
795 | - if ( isset($values['post_id']) ) { |
|
795 | + if ( isset( $values['post_id'] ) ) { |
|
796 | 796 | $new_values['post_id'] = (int) $values['post_id']; |
797 | 797 | } |
798 | 798 | |
799 | - if ( isset($values['item_key']) ) { |
|
799 | + if ( isset( $values['item_key'] ) ) { |
|
800 | 800 | $new_values['item_key'] = FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id ); |
801 | 801 | } |
802 | 802 | |
803 | - if ( isset($values['parent_item_id']) ) { |
|
803 | + if ( isset( $values['parent_item_id'] ) ) { |
|
804 | 804 | $new_values['parent_item_id'] = (int) $values['parent_item_id']; |
805 | 805 | } |
806 | 806 | |
807 | - if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) { |
|
807 | + if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) { |
|
808 | 808 | $new_values['user_id'] = $values['frm_user_id']; |
809 | 809 | } |
810 | 810 | |
811 | - $new_values = apply_filters('frm_update_entry', $new_values, $id); |
|
811 | + $new_values = apply_filters( 'frm_update_entry', $new_values, $id ); |
|
812 | 812 | |
813 | 813 | return $new_values; |
814 | 814 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<div class="general_settings metabox-holder tabs-panel frm_license_box <?php echo ($a == 'general_settings') ? 'frm_block' : 'frm_hidden'; ?>"> |
|
1 | +<div class="general_settings metabox-holder tabs-panel frm_license_box <?php echo ( $a == 'general_settings' ) ? 'frm_block' : 'frm_hidden'; ?>"> |
|
2 | 2 | <?php if ( ! is_multisite() || current_user_can( 'setup_network' ) ) { ?> |
3 | 3 | <div class="postbox"> |
4 | 4 | <div class="inside"> |
@@ -1,11 +1,11 @@ |
||
1 | -<div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class($values); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container" <?php echo apply_filters( 'frm_form_div_attributes', '', $form ); ?>> |
|
1 | +<div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class( $values ); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container" <?php echo apply_filters( 'frm_form_div_attributes', '', $form ); ?>> |
|
2 | 2 | <?php |
3 | 3 | if ( ! isset( $include_form_tag ) || $include_form_tag ) { |
4 | 4 | ?> |
5 | -<form enctype="<?php echo esc_attr( apply_filters( 'frm_form_enctype', 'multipart/form-data', $form ) ) ?>" method="post" class="frm-show-form <?php do_action('frm_form_classes', $form) ?>" id="form_<?php echo esc_attr( $form->form_key ) ?>" <?php echo $frm_settings->use_html ? '' : 'action=""'; ?> <?php echo apply_filters( 'frm_form_attributes', '', $form ); ?>> |
|
5 | +<form enctype="<?php echo esc_attr( apply_filters( 'frm_form_enctype', 'multipart/form-data', $form ) ) ?>" method="post" class="frm-show-form <?php do_action( 'frm_form_classes', $form ) ?>" id="form_<?php echo esc_attr( $form->form_key ) ?>" <?php echo $frm_settings->use_html ? '' : 'action=""'; ?> <?php echo apply_filters( 'frm_form_attributes', '', $form ); ?>> |
|
6 | 6 | <?php |
7 | 7 | } else { ?> |
8 | -<div id="form_<?php echo esc_attr( $form->form_key ) ?>" class="frm-show-form <?php do_action('frm_form_classes', $form) ?>" > |
|
8 | +<div id="form_<?php echo esc_attr( $form->form_key ) ?>" class="frm-show-form <?php do_action( 'frm_form_classes', $form ) ?>" > |
|
9 | 9 | <?php |
10 | 10 | } |
11 | 11 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | } |
9 | 9 | |
10 | 10 | public function widget( $args, $instance ) { |
11 | - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
|
11 | + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
|
12 | 12 | |
13 | 13 | echo $args['before_widget']; |
14 | 14 | |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | public function form( $instance ) { |
37 | - //Defaults |
|
37 | + //Defaults |
|
38 | 38 | $instance = wp_parse_args( (array) $instance, array( |
39 | - 'title' => false, 'form' => false, 'description' => false, |
|
39 | + 'title' => false, 'form' => false, 'description' => false, |
|
40 | 40 | ) ); |
41 | 41 | ?> |
42 | 42 | <p><label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php _e( 'Title', 'formidable' ) ?>:</label><br/> |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | |
45 | 45 | <p><label for="<?php echo esc_attr( $this->get_field_id('form') ); ?>"><?php _e( 'Form', 'formidable' ) ?>:</label><br/> |
46 | 46 | <?php |
47 | - FrmFormsHelper::forms_dropdown( $this->get_field_name('form'), $instance['form'], array( |
|
48 | - 'blank' => false, 'field_id' => $this->get_field_id('form'), |
|
49 | - 'class' => 'widefat', |
|
50 | - ) ); |
|
47 | + FrmFormsHelper::forms_dropdown( $this->get_field_name('form'), $instance['form'], array( |
|
48 | + 'blank' => false, 'field_id' => $this->get_field_id('form'), |
|
49 | + 'class' => 'widefat', |
|
50 | + ) ); |
|
51 | 51 | ?> |
52 | 52 | </p> |
53 | 53 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | public function __construct() { |
6 | 6 | $widget_ops = array( 'description' => __( 'Display a Formidable Form', 'formidable' ) ); |
7 | - parent::__construct('frm_show_form', __( 'Formidable Form', 'formidable' ), $widget_ops); |
|
7 | + parent::__construct( 'frm_show_form', __( 'Formidable Form', 'formidable' ), $widget_ops ); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | public function widget( $args, $instance ) { |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | echo '<div class="frm_form_widget">'; |
16 | 16 | if ( $title ) { |
17 | - echo $args['before_title'] . stripslashes($title) . $args['after_title']; |
|
17 | + echo $args['before_title'] . stripslashes( $title ) . $args['after_title']; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | $form_atts = array( |
@@ -39,19 +39,19 @@ discard block |
||
39 | 39 | 'title' => false, 'form' => false, 'description' => false, |
40 | 40 | ) ); |
41 | 41 | ?> |
42 | - <p><label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php _e( 'Title', 'formidable' ) ?>:</label><br/> |
|
43 | - <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" value="<?php echo esc_attr( stripslashes($instance['title']) ); ?>" /></p> |
|
42 | + <p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title', 'formidable' ) ?>:</label><br/> |
|
43 | + <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( stripslashes( $instance['title'] ) ); ?>" /></p> |
|
44 | 44 | |
45 | - <p><label for="<?php echo esc_attr( $this->get_field_id('form') ); ?>"><?php _e( 'Form', 'formidable' ) ?>:</label><br/> |
|
45 | + <p><label for="<?php echo esc_attr( $this->get_field_id( 'form' ) ); ?>"><?php _e( 'Form', 'formidable' ) ?>:</label><br/> |
|
46 | 46 | <?php |
47 | - FrmFormsHelper::forms_dropdown( $this->get_field_name('form'), $instance['form'], array( |
|
48 | - 'blank' => false, 'field_id' => $this->get_field_id('form'), |
|
47 | + FrmFormsHelper::forms_dropdown( $this->get_field_name( 'form' ), $instance['form'], array( |
|
48 | + 'blank' => false, 'field_id' => $this->get_field_id( 'form' ), |
|
49 | 49 | 'class' => 'widefat', |
50 | 50 | ) ); |
51 | 51 | ?> |
52 | 52 | </p> |
53 | 53 | |
54 | - <p><label for="<?php echo esc_attr( $this->get_field_id('description') ); ?>"><input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo esc_attr( $this->get_field_id('description') ); ?>" name="<?php echo esc_attr( $this->get_field_name('description') ); ?>" value="1" /> |
|
54 | + <p><label for="<?php echo esc_attr( $this->get_field_id( 'description' ) ); ?>"><input class="checkbox" type="checkbox" <?php checked( $instance['description'], true ) ?> id="<?php echo esc_attr( $this->get_field_id( 'description' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'description' ) ); ?>" value="1" /> |
|
55 | 55 | <?php _e( 'Show Description', 'formidable' ) ?></label></p> |
56 | 56 | <?php |
57 | 57 | } |
@@ -194,7 +194,7 @@ |
||
194 | 194 | } |
195 | 195 | $addon['link'] = FrmAppHelper::make_affiliate_url( $addon['link'] ); |
196 | 196 | |
197 | - $addons[ $slug ] = $addon; |
|
197 | + $addons[$slug] = $addon; |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 |