PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmXMLController.php +87 -401 6.263.06.06 View file →
@@ -1,29 +1,20 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 class FrmXMLController {
7 4
8 - /**
9 - * @return void
10 - */
11 5 public static function menu() {
12 6 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' );
13 7 }
14 8
15 - /**
16 - * @return void
17 - */
18 9 public static function add_default_templates() {
19 - if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
20 - // XML import is not enabled on your server.
10 + if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
11 + // XML import is not enabled on your server
21 12 return;
22 13 }
23 14
24 15 $set_err = libxml_use_internal_errors( true );
25 - $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
16 + $loader = libxml_disable_entity_loader( true );
26 17
27 18 $files = apply_filters( 'frm_default_templates_files', array() );
28 19
29 20 foreach ( (array) $files as $file ) {
@@ -33,42 +24,23 @@
33 24
34 25 unset( $files );
35 26
36 27 libxml_use_internal_errors( $set_err );
37 - FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
28 + libxml_disable_entity_loader( $loader );
38 29 }
39 30
31 +
40 32 /**
41 33 * Use the template link to install the XML template
42 34 *
43 35 * @since 3.06
44 - *
45 - * @return void
46 36 */
47 37 public static function install_template() {
48 - FrmAppHelper::permission_check( 'frm_edit_forms' );
38 + FrmAppHelper::permission_check( 'frm_create_forms' );
49 39 check_ajax_referer( 'frm_ajax', 'nonce' );
50 40
51 - if ( ! function_exists( 'simplexml_load_string' ) ) {
52 - $response = array(
53 - 'message' => __( 'Your server is missing the Simple XML extension. This is required to install a template.', 'formidable' ),
54 - );
55 - echo wp_json_encode( $response );
56 - wp_die();
57 - }
41 + $url = FrmAppHelper::get_param( 'xml', '', 'post', 'esc_url_raw' );
58 42
59 - $form = self::get_posted_form();
60 - $url = FrmAppHelper::get_param( 'xml', '', 'post', 'esc_url_raw' );
61 - self::override_url( $form, $url );
62 -
63 - if ( ! self::validate_xml_url( $url ) ) {
64 - $response = array(
65 - 'message' => __( 'The template you are trying to install could not be validated.', 'formidable' ),
66 - );
67 - echo wp_json_encode( $response );
68 - wp_die();
69 - }
70 -
71 43 $response = wp_remote_get( $url );
72 44 $body = wp_remote_retrieve_body( $response );
73 45 $xml = simplexml_load_string( $body );
74 46
@@ -73,9 +45,9 @@
73 45 $xml = simplexml_load_string( $body );
74 46
75 47 if ( ! $xml ) {
76 48 $response = array(
77 - 'message' => __( 'There was an error reading the form template.', 'formidable' ),
49 + 'message' => __( 'There was an error reading the form template', 'formidable' ),
78 50 );
79 51 echo wp_json_encode( $response );
80 52 wp_die();
81 53 }
@@ -81,189 +53,35 @@
81 53 }
82 54
83 55 self::set_new_form_name( $xml );
84 56
85 - $imported = FrmXMLHelper::import_xml_now( $xml, true );
86 -
87 - if ( ! empty( $imported['form_status'] ) ) {
57 + $imported = FrmXMLHelper::import_xml_now( $xml );
58 + if ( isset( $imported['form_status'] ) && ! empty( $imported['form_status'] ) ) {
88 59 // Get the last form id in case there are child forms.
89 60 end( $imported['form_status'] );
90 - $form_id = key( $imported['form_status'] );
61 + $form_id = key( $imported['form_status'] );
91 62 $response = array(
92 63 'id' => $form_id,
93 - 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
64 + 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form_id ) ),
94 65 'success' => 1,
95 66 );
96 -
97 - if ( ! empty( $imported['imported']['posts'] ) ) {
98 - // Return the link to the last page created.
99 - $pages = $imported['posts'];
100 - }
101 -
102 - if ( ! empty( $form ) ) {
103 - // Create selected pages with the correct shortcodes.
104 - $pages = self::create_pages_for_import( $form );
105 - }
106 -
107 - if ( ! empty( $pages ) ) {
108 - $post_id = end( $pages );
109 - $response['redirect'] = get_permalink( $post_id );
110 - }
111 67 } else {
112 - if ( isset( $imported['error'] ) ) {
113 - $message = $imported['error'];
114 - } else {
115 - $message = __( 'There was an error importing form', 'formidable' );
116 - }
117 -
118 68 $response = array(
119 - 'message' => $message,
69 + 'message' => __( 'There was an error importing form', 'formidable' ),
120 70 );
71 + }
121 72
122 - }//end if
123 -
124 - /**
125 - * @since 6.18 Added `url` to the $args.
126 - */
127 - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported', 'url' ) );
128 -
129 73 echo wp_json_encode( $response );
130 74 wp_die();
131 75 }
132 76
133 77 /**
134 - * Make sure that the XML file we're trying to load is in fact an XML file, and that it's coming from our S3 bucket.
135 - * This is to make sure that the URL can't be exploited for a SSRF attack.
136 - *
137 - * @since 5.5.5
138 - *
139 - * @param string $url
140 - *
141 - * @return bool True on success, False on error.
142 - */
143 - private static function validate_xml_url( $url ) {
144 - return FrmAppHelper::validate_url_is_in_s3_bucket( $url, 'xml' );
145 - }
146 -
147 - /**
148 - * @since 4.06.02
149 - *
150 - * @return mixed
151 - */
152 - private static function get_posted_form() {
153 - $form = FrmAppHelper::get_param( 'form', '', 'post', 'wp_unslash' );
154 -
155 - if ( empty( $form ) ) {
156 - return $form;
157 - }
158 -
159 - $form = json_decode( $form, true );
160 - return $form;
161 - }
162 -
163 - /**
164 - * Get a different URL depending on the selection in the form.
165 - *
166 - * @since 4.06.02
167 - *
168 - * @param array $form The posted form values.
169 - * @param string $url The URL to override.
170 - *
171 - * @return void
172 - */
173 - private static function override_url( $form, &$url ) {
174 - $selected_form = self::get_selected_in_form( $form, 'form' );
175 -
176 - if ( empty( $selected_form ) ) {
177 - return;
178 - }
179 -
180 - $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : '';
181 -
182 - if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) {
183 - return;
184 - }
185 -
186 - $url = $selected_xml;
187 - }
188 -
189 - /**
190 - * @since 4.06.02
191 - *
192 - * @param array $form
193 - * @param string $value
194 - *
195 - * @return string
196 - */
197 - private static function get_selected_in_form( $form, $value = 'form' ) {
198 - if ( ! empty( $form ) && ! empty( $form[ $value ] ) ) {
199 - return $form[ $value ];
200 - }
201 -
202 - return '';
203 - }
204 -
205 - /**
206 - * @since 4.06.02
207 - *
208 - * @param array $form The posted form values.
209 - *
210 - * @return array|null The array of created pages.
211 - */
212 - private static function create_pages_for_import( $form ) {
213 - if ( empty( $form['pages'] ) ) {
214 - return null;
215 - }
216 -
217 - $form_key = self::get_selected_in_form( $form, 'form' );
218 - $view_keys = self::get_selected_in_form( $form, 'view' );
219 -
220 - $page_ids = array();
221 -
222 - foreach ( (array) $form['pages'] as $for => $name ) {
223 - if ( empty( $name ) ) {
224 - // Don't create a page if no title is given.
225 - continue;
226 - }
227 -
228 - if ( $for === 'view' ) {
229 - $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys;
230 - $shortcode = '[display-frm-data id=%1$s filter=limited]';
231 - } elseif ( $for === 'form' ) {
232 - $item_key = $form_key;
233 - $shortcode = '[formidable id=%1$s]';
234 - } else {
235 - $item_key = self::get_selected_in_form( $form, 'form' );
236 - $shortcode = '[' . esc_html( $for ) . ' id=%1$s]';
237 - }
238 -
239 - if ( empty( $item_key ) ) {
240 - // Don't create it if the shortcode won't show anything.
241 - continue;
242 - }
243 -
244 - $page_ids[ $for ] = wp_insert_post(
245 - array(
246 - 'post_title' => $name,
247 - 'post_type' => 'page',
248 - 'post_content' => sprintf( $shortcode, $item_key ),
249 - )
250 - );
251 - }//end foreach
252 -
253 - return $page_ids;
254 - }
255 -
256 - /**
257 78 * Change the name of the last form that is not a child.
258 79 * This will allow for lookup fields and embedded forms
259 80 * since we redirect to the last form.
260 81 *
261 82 * @since 3.06
262 - *
263 83 * @param object $xml The values included in the XML.
264 - *
265 - * @return void
266 84 */
267 85 private static function set_new_form_name( &$xml ) {
268 86 if ( ! isset( $xml->form ) ) {
269 87 return;
@@ -268,60 +86,41 @@
268 86 if ( ! isset( $xml->form ) ) {
269 87 return;
270 88 }
271 89
272 - $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
273 - $description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
274 -
275 - if ( ! $name && ! $description ) {
276 - return;
277 - }
278 -
279 90 // Get the main form ID.
280 91 $set_name = 0;
281 -
282 92 foreach ( $xml->form as $form ) {
283 - if ( empty( $form->parent_form_id ) ) {
284 - $set_name = (int) $form->id;
93 + if ( ! isset( $form->parent_form_id ) || empty( $form->parent_form_id ) ) {
94 + $set_name = $form->id;
285 95 }
286 96 }
287 97
288 98 foreach ( $xml->form as $form ) {
289 99 // Maybe set the form name if this isn't a child form.
290 - if ( $set_name === (int) $form->id ) {
291 - $form->name = $name;
292 - $form->description = $description;
100 + if ( $set_name == $form->id ) {
101 + $form->name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
102 + $form->description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
293 103 }
294 104
295 105 // Use a unique key to prevent editing existing form.
296 - $sanitized_form_name = sanitize_title( $form->name );
297 - $form->form_key = FrmAppHelper::get_unique_key( $sanitized_form_name, 'frm_forms', 'form_key' );
106 + $name = sanitize_title( $form->name );
107 + $form->form_key = FrmAppHelper::get_unique_key( $name, 'frm_forms', 'form_key' );
298 108 }
299 109 }
300 110
301 - /**
302 - * @return void
303 - */
304 111 public static function route() {
305 112 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
306 113 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
307 - FrmAppHelper::include_svg();
308 -
309 114 if ( 'import_xml' === $action ) {
310 - self::import_xml();
115 + return self::import_xml();
311 116 } elseif ( 'export_xml' === $action ) {
312 - self::export_xml();
117 + return self::export_xml();
313 118 } elseif ( apply_filters( 'frm_xml_route', true, $action ) ) {
314 - self::form();
119 + return self::form();
315 120 }
316 121 }
317 122
318 - /**
319 - * @param string[] $errors
320 - * @param string $message
321 - *
322 - * @return void
323 - */
324 123 public static function form( $errors = array(), $message = '' ) {
325 124 $where = array(
326 125 'status' => array( null, '', 'published' ),
327 126 );
@@ -346,48 +145,40 @@
346 145 ),
347 146 );
348 147 $export_format = apply_filters( 'frm_export_formats', $export_format );
349 148
350 - include FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php';
149 + include( FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php' );
351 150 }
352 151
353 - /**
354 - * @return void
355 - */
356 152 public static function import_xml() {
357 - $errors = array();
153 + $errors = array();
358 154 $message = '';
359 155
360 156 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' );
361 -
362 157 if ( false !== $permission_error ) {
363 158 $errors[] = $permission_error;
364 159 self::form( $errors );
365 -
366 160 return;
367 161 }
368 162
369 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
370 - $has_file = ! empty( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0;
371 -
163 + $has_file = isset( $_FILES ) && isset( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0;
372 164 if ( ! $has_file ) {
373 165 $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
374 166 self::form( $errors );
375 -
376 167 return;
377 168 }
378 169
379 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
380 - $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : '';
170 + $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? $_FILES['frm_import_file']['tmp_name'] : '';
381 171
382 172 if ( ! is_uploaded_file( $file ) ) {
383 173 unset( $file );
384 174 $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
385 175 self::form( $errors );
386 -
387 176 return;
388 177 }
389 178
179 + //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
180 +
390 181 $export_format = array(
391 182 'xml' => array(
392 183 'name' => 'XML',
393 184 'support' => 'forms',
@@ -395,29 +186,24 @@
395 186 ),
396 187 );
397 188 $export_format = apply_filters( 'frm_export_formats', $export_format );
398 189
399 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
400 - $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] );
401 - $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) );
402 -
190 + $file_type = strtolower( pathinfo( $_FILES['frm_import_file']['name'], PATHINFO_EXTENSION ) );
403 191 if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) {
404 192 // allow other file types to be imported
405 193 do_action( 'frm_before_import_' . $file_type );
406 -
407 194 return;
408 195 }
409 196 unset( $file_type );
410 197
411 - if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
198 + if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
412 199 $errors[] = __( 'XML import is not enabled on your server with the libxml_disable_entity_loader function.', 'formidable' );
413 200 self::form( $errors );
414 -
415 201 return;
416 202 }
417 203
418 204 $set_err = libxml_use_internal_errors( true );
419 - $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
205 + $loader = libxml_disable_entity_loader( true );
420 206
421 207 $result = FrmXMLHelper::import_xml( $file );
422 208 FrmXMLHelper::parse_message( $result, $message, $errors );
423 209
@@ -423,25 +209,21 @@
423 209
424 210 unset( $file );
425 211
426 212 libxml_use_internal_errors( $set_err );
427 - FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
213 + libxml_disable_entity_loader( $loader );
428 214
429 215 self::form( $errors, $message );
430 216 }
431 217
432 - /**
433 - * @return void
434 - */
435 218 public static function export_xml() {
436 219 $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' );
437 -
438 220 if ( ! empty( $error ) ) {
439 221 wp_die( esc_html( $error ) );
440 222 }
441 223
442 - $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array(), 'sanitize_text_field' );
443 - $type = FrmAppHelper::get_post_param( 'type', array(), 'sanitize_text_field' );
224 + $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() );
225 + $type = FrmAppHelper::get_post_param( 'type', array() );
444 226 $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' );
445 227
446 228 if ( ! headers_sent() && ! $type ) {
447 229 wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) );
@@ -458,40 +240,25 @@
458 240
459 241 wp_die();
460 242 }
461 243
462 - /**
463 - * @param array<string>|string $type
464 - * @param array $args
465 - *
466 - * @psalm-param array{ids?: mixed} $args
467 - *
468 - * @return void
469 - */
470 244 public static function generate_xml( $type, $args = array() ) {
471 245 global $wpdb;
472 246
473 247 self::prepare_types_array( $type );
474 248
475 - if ( ! is_array( $type ) ) {
476 - // This shouldn't be possible.
477 - // It is cast to array in prepare_types_array.
478 - // This is just for static analysis.
479 - return;
480 - }
481 -
482 249 $tables = array(
483 - 'items' => $wpdb->prefix . 'frm_items',
484 - 'forms' => $wpdb->prefix . 'frm_forms',
485 - 'posts' => $wpdb->posts,
486 - 'styles' => $wpdb->posts,
487 - 'actions' => $wpdb->posts,
250 + 'items' => $wpdb->prefix . 'frm_items',
251 + 'forms' => $wpdb->prefix . 'frm_forms',
252 + 'posts' => $wpdb->posts,
253 + 'styles' => $wpdb->posts,
254 + 'actions' => $wpdb->posts,
488 255 );
489 256
490 257 $defaults = array(
491 258 'ids' => false,
492 259 );
493 - $args = wp_parse_args( $args, $defaults );
260 + $args = wp_parse_args( $args, $defaults );
494 261
495 262 // Make sure ids are numeric.
496 263 if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
497 264 $args['ids'] = array_filter( $args['ids'], 'is_numeric' );
@@ -500,21 +267,21 @@
500 267 $records = array();
501 268
502 269 foreach ( $type as $tb_type ) {
503 270 $where = array();
504 - $join = '';
271 + $join = '';
505 272 $table = $tables[ $tb_type ];
506 273
507 - $select = $table . '.id';
274 + $select = $table . '.id';
508 275 $query_vars = array();
509 276
510 277 switch ( $tb_type ) {
511 278 case 'forms':
512 - // Add forms.
279 + //add forms
513 280 if ( $args['ids'] ) {
514 281 $where[] = array(
515 - 'or' => 1,
516 - $table . '.id' => $args['ids'],
282 + 'or' => 1,
283 + $table . '.id' => $args['ids'],
517 284 $table . '.parent_form_id' => $args['ids'],
518 285 );
519 286 } else {
520 287 $where[ $table . '.status !' ] = 'draft';
@@ -520,32 +287,29 @@
520 287 $where[ $table . '.status !' ] = 'draft';
521 288 }
522 289 break;
523 290 case 'actions':
524 - $select = $table . '.ID';
291 + $select = $table . '.ID';
525 292 $where['post_type'] = FrmFormActionsController::$action_post_type;
526 -
527 293 if ( ! empty( $args['ids'] ) ) {
528 294 $where['menu_order'] = $args['ids'];
529 295 }
530 296 break;
531 297 case 'items':
532 - // $join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
298 + //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
533 299 if ( $args['ids'] ) {
534 300 $where[ $table . '.form_id' ] = $args['ids'];
535 301 }
536 302 break;
537 303 case 'styles':
538 - // Loop through all exported forms and get their selected style IDs.
539 - $frm_style = new FrmStyle();
304 + // Loop through all exported forms and get their selected style IDs
305 + $frm_style = new FrmStyle();
540 306 $default_style = $frm_style->get_default_style();
541 - $form_ids = $args['ids'];
542 - $style_ids = array();
543 -
307 + $form_ids = $args['ids'];
308 + $style_ids = array();
544 309 foreach ( $form_ids as $form_id ) {
545 310 $form_data = FrmForm::getOne( $form_id );
546 -
547 - // For forms that have not been updated while running 2.0, check if custom_style is set.
311 + // For forms that have not been updated while running 2.0, check if custom_style is set
548 312 if ( isset( $form_data->options['custom_style'] ) ) {
549 313 if ( 1 === absint( $form_data->options['custom_style'] ) ) {
550 314 $style_ids[] = $default_style->ID;
551 315 } else {
@@ -553,20 +317,19 @@
553 317 }
554 318 }
555 319 unset( $form_id, $form_data );
556 320 }
557 -
558 - $select = $table . '.ID';
321 + $select = $table . '.ID';
559 322 $where['post_type'] = 'frm_styles';
560 323
561 - // Only export selected styles.
324 + // Only export selected styles
562 325 if ( ! empty( $style_ids ) ) {
563 326 $where['ID'] = $style_ids;
564 327 }
565 328 break;
566 329 default:
567 - $select = $table . '.ID';
568 - $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
330 + $select = $table . '.ID';
331 + $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
569 332 $where['pm.meta_key'] = 'frm_form_id';
570 333
571 334 if ( empty( $args['ids'] ) ) {
572 335 $where['pm.meta_value >'] = 1;
@@ -572,15 +335,15 @@
572 335 $where['pm.meta_value >'] = 1;
573 336 } else {
574 337 $where['pm.meta_value'] = $args['ids'];
575 338 }
576 - }//end switch
339 + }
577 340
578 341 $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select );
579 342 unset( $tb_type );
580 - }//end foreach
343 + }
581 344
582 - $filename = self::get_file_name( $args, $records );
345 + $filename = self::get_file_name( $args, $type, $records );
583 346
584 347 header( 'Content-Description: File Transfer' );
585 348 header( 'Content-Disposition: attachment; filename=' . $filename );
586 349 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
@@ -585,50 +348,19 @@
585 348 header( 'Content-Disposition: attachment; filename=' . $filename );
586 349 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
587 350
588 351 echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo( 'charset' ) ) . "\" ?>\n";
589 - include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php';
352 + include( FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php' );
590 353 }
591 354
592 - /**
593 - * Returns an array that has parent term slugs for the terms provided.
594 - *
595 - * @since 6.8.3
596 - *
597 - * @param array $terms
598 - *
599 - * @return array
600 - */
601 - public static function get_parent_terms_slugs( $terms ) {
602 - $parent_term_ids = array_filter( array_unique( wp_list_pluck( $terms, 'parent' ) ) );
603 - $parent_slugs = array();
604 -
605 - if ( ! $parent_term_ids ) {
606 - return $parent_slugs;
607 - }
608 -
609 - $results = FrmDb::get_results( 'terms', array( 'term_id' => $parent_term_ids ), 'term_id, slug' );
610 - $parent_slugs = wp_list_pluck( $results, 'slug', 'term_id' );
611 -
612 - return $parent_slugs;
613 - }
614 -
615 - /**
616 - * Prepare the types array.
617 - *
618 - * @param array<string>|string $type
619 - *
620 - * @return void
621 - */
622 355 private static function prepare_types_array( &$type ) {
623 356 $type = (array) $type;
624 -
625 - if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) {
357 + if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) {
626 358 // make sure the form is included if there are entries
627 359 $type[] = 'forms';
628 360 }
629 361
630 - if ( in_array( 'forms', $type, true ) ) {
362 + if ( in_array( 'forms', $type ) ) {
631 363 // include actions with forms
632 364 $type[] = 'actions';
633 365 }
634 366 }
@@ -638,28 +370,20 @@
638 370 * Use the nme of the form if only one form is exported.
639 371 *
640 372 * @since 3.06
641 373 *
642 - * @param array $args
643 - * @param array $records
644 - *
645 374 * @return string
646 375 */
647 - private static function get_file_name( $args, $records ) {
648 - $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1;
649 -
376 + private static function get_file_name( $args, $type, $records ) {
377 + $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1;
650 378 if ( $has_one_form ) {
651 379 // one form is being exported
652 380 $selected_form_id = reset( $args['ids'] );
653 - $filename = 'form-' . $selected_form_id . '.xml';
654 -
655 381 foreach ( $records['forms'] as $form_id ) {
656 382 $filename = 'form-' . $form_id . '.xml';
657 -
658 383 if ( $selected_form_id === $form_id ) {
659 - $form = FrmForm::getOne( $form_id );
660 - $filename = $form->name !== '' ? $form->name : $form->form_key;
661 - $filename = sanitize_title( $filename ) . '-form.xml';
384 + $form = FrmForm::getOne( $form_id );
385 + $filename = sanitize_title( $form->name ) . '-form.xml';
662 386 break;
663 387 }
664 388 }
665 389 } else {
@@ -667,28 +391,15 @@
667 391
668 392 if ( ! empty( $sitename ) ) {
669 393 $sitename .= '.';
670 394 }
671 -
672 - $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml';
673 - }//end if
674 -
675 - /**
676 - * @since 5.3
677 - *
678 - * @param string $filename
679 - */
680 - return apply_filters( 'frm_xml_filename', $filename );
395 + $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
396 + }
397 + return $filename;
681 398 }
682 399
683 - /**
684 - * @param array $atts
685 - *
686 - * @return void
687 - */
688 400 public static function generate_csv( $atts ) {
689 401 $form_ids = $atts['ids'];
690 -
691 402 if ( empty( $form_ids ) ) {
692 403 wp_die( esc_html__( 'Please select a form', 'formidable' ) );
693 404 }
694 405 self::csv( reset( $form_ids ) );
@@ -697,14 +408,8 @@
697 408 /**
698 409 * Export to CSV
699 410 *
700 411 * @since 2.0.19
701 - *
702 - * @param false|int|string $form_id
703 - * @param string $search
704 - * @param string $fid
705 - *
706 - * @return void
707 412 */
708 413 public static function csv( $form_id = false, $search = '', $fid = '' ) {
709 414 FrmAppHelper::permission_check( 'frm_view_entries' );
710 415
@@ -709,19 +414,14 @@
709 414 FrmAppHelper::permission_check( 'frm_view_entries' );
710 415
711 416 if ( ! $form_id ) {
712 417 $form_id = FrmAppHelper::get_param( 'form', '', 'get', 'sanitize_text_field' );
713 - $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' );
714 - $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' );
418 + $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' );
419 + $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' );
715 420 }
716 421
717 - // Remove time limit to execute this function.
718 - if ( function_exists( 'set_time_limit' ) ) {
719 - set_time_limit( 0 );
720 - }
721 -
422 + set_time_limit( 0 ); //Remove time limit to execute this function
722 423 $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) );
723 -
724 424 if ( (int) $mem_limit < 256 ) {
725 425 wp_raise_memory_limit();
726 426 }
727 427
@@ -727,19 +427,13 @@
727 427
728 428 global $wpdb;
729 429
730 430 $form = FrmForm::getOne( $form_id );
431 + $form_id = $form->id;
731 432
732 - if ( ! $form ) {
733 - esc_html_e( 'Form not found.', 'formidable' );
734 - wp_die();
735 - }
736 -
737 - $form_id = $form->id;
738 433 $form_cols = self::get_fields_for_csv_export( $form_id, $form );
739 434
740 435 $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' );
741 -
742 436 if ( ! empty( $item_id ) ) {
743 437 $item_id = explode( ',', $item_id );
744 438 }
745 439
@@ -771,36 +465,28 @@
771 465 wp_die();
772 466 }
773 467
774 468 /**
775 - * Get the fields that should be included in the CSV export
776 - *
777 - * @since 2.0.19
778 - * @since 5.0.16 function went from private to public.
779 - *
780 - * @param int $form_id
781 - * @param object $form
782 - *
783 - * @return array $csv_fields
784 - */
785 - public static function get_fields_for_csv_export( $form_id, $form ) {
786 - $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' );
469 + * Get the fields that should be included in the CSV export
470 + *
471 + * @since 2.0.19
472 + *
473 + * @param int $form_id
474 + * @param object $form
475 + * @return array $csv_fields
476 + */
477 + private static function get_fields_for_csv_export( $form_id, $form ) {
478 + $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' );
787 479 $no_export_fields = FrmField::no_save_fields();
788 -
789 480 foreach ( $csv_fields as $k => $f ) {
790 - if ( in_array( $f->type, $no_export_fields, true ) ) {
481 + if ( in_array( $f->type, $no_export_fields ) ) {
791 482 unset( $csv_fields[ $k ] );
792 483 }
793 484 }
794 485
795 - return apply_filters( 'frm_fields_for_csv_export', $csv_fields, compact( 'form' ) );
486 + return $csv_fields;
796 487 }
797 488
798 - /**
799 - * @param array $mimes
800 - *
801 - * @return array
802 - */
803 489 public static function allow_mime( $mimes ) {
804 490 if ( ! isset( $mimes['csv'] ) ) {
805 491 // allow csv files
806 492 $mimes['csv'] = 'text/csv';