| @@ -8,9 +8,9 @@ | ||
| 8 | 8 | /** |
| 9 | 9 | * @return void |
| 10 | 10 | */ |
| 11 | 11 | public static function menu() { |
| 12 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 12 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' ); | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * @return void |
| @@ -16,16 +16,17 @@ | ||
| 16 | 16 | * @return void |
| 17 | 17 | */ |
| 18 | 18 | public static function add_default_templates() { |
| 19 | 19 | if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) { |
| 20 | - // XML import is not enabled on your server. | |
| 20 | + // XML import is not enabled on your server | |
| 21 | 21 | return; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | $set_err = libxml_use_internal_errors( true ); |
| 25 | 25 | $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true ); |
| 26 | - $files = apply_filters( 'frm_default_templates_files', array() ); | |
| 27 | 26 | |
| 27 | + $files = apply_filters( 'frm_default_templates_files', array() ); | |
| 28 | + | |
| 28 | 29 | foreach ( (array) $files as $file ) { |
| 29 | 30 | FrmXMLHelper::import_xml( $file ); |
| 30 | 31 | unset( $file ); |
| 31 | 32 | } |
| @@ -39,9 +40,8 @@ | ||
| 39 | 40 | /** |
| 40 | 41 | * Use the template link to install the XML template |
| 41 | 42 | * |
| 42 | 43 | * @since 3.06 |
| 43 | - * | |
| 44 | 44 | * @return void |
| 45 | 45 | */ |
| 46 | 46 | public static function install_template() { |
| 47 | 47 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| @@ -81,44 +81,45 @@ | ||
| 81 | 81 | |
| 82 | 82 | self::set_new_form_name( $xml ); |
| 83 | 83 | |
| 84 | 84 | $imported = FrmXMLHelper::import_xml_now( $xml, true ); |
| 85 | - | |
| 86 | 85 | if ( ! empty( $imported['form_status'] ) ) { |
| 87 | 86 | // Get the last form id in case there are child forms. |
| 88 | - $form_id = array_key_last( $imported['form_status'] ); | |
| 87 | + end( $imported['form_status'] ); | |
| 88 | + $form_id = key( $imported['form_status'] ); | |
| 89 | 89 | $response = array( |
| 90 | 90 | 'id' => $form_id, |
| 91 | - 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 91 | + 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 92 | 92 | 'success' => 1, |
| 93 | 93 | ); |
| 94 | - | |
| 95 | 94 | if ( ! empty( $imported['imported']['posts'] ) ) { |
| 96 | 95 | // Return the link to the last page created. |
| 97 | 96 | $pages = $imported['posts']; |
| 98 | 97 | } |
| 99 | 98 | |
| 100 | - if ( $form ) { | |
| 99 | + if ( ! empty( $form ) ) { | |
| 101 | 100 | // Create selected pages with the correct shortcodes. |
| 102 | 101 | $pages = self::create_pages_for_import( $form ); |
| 103 | 102 | } |
| 104 | 103 | |
| 105 | - if ( ! empty( $pages ) ) { | |
| 106 | - $post_id = end( $pages ); | |
| 104 | + if ( isset( $pages ) && ! empty( $pages ) ) { | |
| 105 | + $post_id = end( $pages ); | |
| 107 | 106 | $response['redirect'] = get_permalink( $post_id ); |
| 108 | 107 | } |
| 109 | 108 | } else { |
| 110 | - $message = $imported['error'] ?? __( 'There was an error importing form', 'formidable' ); | |
| 109 | + if ( isset( $imported['error'] ) ) { | |
| 110 | + $message = $imported['error']; | |
| 111 | + } else { | |
| 112 | + $message = __( 'There was an error importing form', 'formidable' ); | |
| 113 | + } | |
| 111 | 114 | $response = array( |
| 112 | 115 | 'message' => $message, |
| 113 | 116 | ); |
| 114 | - }//end if | |
| 115 | 117 | |
| 116 | - /** | |
| 117 | - * @since 6.18 Added `url` to the $args. | |
| 118 | - */ | |
| 119 | - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported', 'url' ) ); | |
| 118 | + } | |
| 120 | 119 | |
| 120 | + $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) ); | |
| 121 | + | |
| 121 | 122 | echo wp_json_encode( $response ); |
| 122 | 123 | wp_die(); |
| 123 | 124 | } |
| 124 | 125 | |
| @@ -126,9 +127,8 @@ | ||
| 126 | 127 | * 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. |
| 127 | 128 | * This is to make sure that the URL can't be exploited for a SSRF attack. |
| 128 | 129 | * |
| 129 | 130 | * @since 5.5.5 |
| 130 | - * | |
| 131 | 131 | * @param string $url |
| 132 | 132 | * |
| 133 | 133 | * @return bool True on success, False on error. |
| 134 | 134 | */ |
| @@ -142,9 +142,13 @@ | ||
| 142 | 142 | * @return mixed |
| 143 | 143 | */ |
| 144 | 144 | private static function get_posted_form() { |
| 145 | 145 | $form = FrmAppHelper::get_param( 'form', '', 'post', 'wp_unslash' ); |
| 146 | - return $form ? json_decode( $form, true ) : $form; | |
| 146 | + if ( empty( $form ) ) { | |
| 147 | + return $form; | |
| 148 | + } | |
| 149 | + $form = json_decode( $form, true ); | |
| 150 | + return $form; | |
| 147 | 151 | } |
| 148 | 152 | |
| 149 | 153 | /** |
| 150 | 154 | * Get a different URL depending on the selection in the form. |
| @@ -150,23 +154,18 @@ | ||
| 150 | 154 | * Get a different URL depending on the selection in the form. |
| 151 | 155 | * |
| 152 | 156 | * @since 4.06.02 |
| 153 | 157 | * |
| 154 | - * @param array $form The posted form values. | |
| 155 | - * @param string $url The URL to override. | |
| 156 | - * | |
| 157 | 158 | * @return void |
| 158 | 159 | */ |
| 159 | 160 | private static function override_url( $form, &$url ) { |
| 160 | 161 | $selected_form = self::get_selected_in_form( $form, 'form' ); |
| 161 | - | |
| 162 | - if ( ! $selected_form ) { | |
| 162 | + if ( empty( $selected_form ) ) { | |
| 163 | 163 | return; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 167 | - | |
| 168 | - if ( ! $selected_xml || ! str_starts_with( $selected_xml, 'http' ) ) { | |
| 166 | + $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 167 | + if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) { | |
| 169 | 168 | return; |
| 170 | 169 | } |
| 171 | 170 | |
| 172 | 171 | $url = $selected_xml; |
| @@ -174,15 +173,13 @@ | ||
| 174 | 173 | |
| 175 | 174 | /** |
| 176 | 175 | * @since 4.06.02 |
| 177 | 176 | * |
| 178 | - * @param array $form | |
| 179 | 177 | * @param string $value |
| 180 | - * | |
| 181 | - * @return string | |
| 178 | + * @param array $form | |
| 182 | 179 | */ |
| 183 | 180 | private static function get_selected_in_form( $form, $value = 'form' ) { |
| 184 | - if ( $form && ! empty( $form[ $value ] ) ) { | |
| 181 | + if ( ! empty( $form ) && isset( $form[ $value ] ) && ! empty( $form[ $value ] ) ) { | |
| 185 | 182 | return $form[ $value ]; |
| 186 | 183 | } |
| 187 | 184 | |
| 188 | 185 | return ''; |
| @@ -192,21 +189,21 @@ | ||
| 192 | 189 | * @since 4.06.02 |
| 193 | 190 | * |
| 194 | 191 | * @param array $form The posted form values. |
| 195 | 192 | * |
| 196 | - * @return array|null The array of created pages. | |
| 193 | + * @return array The array of created pages. | |
| 197 | 194 | */ |
| 198 | 195 | private static function create_pages_for_import( $form ) { |
| 199 | - if ( empty( $form['pages'] ) ) { | |
| 200 | - return null; | |
| 196 | + if ( ! isset( $form['pages'] ) || empty( $form['pages'] ) ) { | |
| 197 | + return; | |
| 201 | 198 | } |
| 202 | 199 | |
| 203 | - $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 200 | + $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 204 | 201 | $view_keys = self::get_selected_in_form( $form, 'view' ); |
| 205 | - $page_ids = array(); | |
| 206 | 202 | |
| 203 | + $page_ids = array(); | |
| 207 | 204 | foreach ( (array) $form['pages'] as $for => $name ) { |
| 208 | - if ( ! $name ) { | |
| 205 | + if ( empty( $name ) ) { | |
| 209 | 206 | // Don't create a page if no title is given. |
| 210 | 207 | continue; |
| 211 | 208 | } |
| 212 | 209 | |
| @@ -213,9 +210,9 @@ | ||
| 213 | 210 | if ( $for === 'view' ) { |
| 214 | 211 | $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys; |
| 215 | 212 | $shortcode = '[display-frm-data id=%1$s filter=limited]'; |
| 216 | 213 | } elseif ( $for === 'form' ) { |
| 217 | - $item_key = $form_key; | |
| 214 | + $item_key = $form_key; | |
| 218 | 215 | $shortcode = '[formidable id=%1$s]'; |
| 219 | 216 | } else { |
| 220 | 217 | $item_key = self::get_selected_in_form( $form, 'form' ); |
| 221 | 218 | $shortcode = '[' . esc_html( $for ) . ' id=%1$s]'; |
| @@ -232,9 +229,9 @@ | ||
| 232 | 229 | 'post_type' => 'page', |
| 233 | 230 | 'post_content' => sprintf( $shortcode, $item_key ), |
| 234 | 231 | ) |
| 235 | 232 | ); |
| 236 | - }//end foreach | |
| 233 | + } | |
| 237 | 234 | |
| 238 | 235 | return $page_ids; |
| 239 | 236 | } |
| 240 | 237 | |
| @@ -245,9 +242,8 @@ | ||
| 245 | 242 | * |
| 246 | 243 | * @since 3.06 |
| 247 | 244 | * |
| 248 | 245 | * @param object $xml The values included in the XML. |
| 249 | - * | |
| 250 | 246 | * @return void |
| 251 | 247 | */ |
| 252 | 248 | private static function set_new_form_name( &$xml ) { |
| 253 | 249 | if ( ! isset( $xml->form ) ) { |
| @@ -255,9 +251,8 @@ | ||
| 255 | 251 | } |
| 256 | 252 | |
| 257 | 253 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 258 | 254 | $description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 259 | - | |
| 260 | 255 | if ( ! $name && ! $description ) { |
| 261 | 256 | return; |
| 262 | 257 | } |
| 263 | 258 | |
| @@ -262,9 +257,8 @@ | ||
| 262 | 257 | } |
| 263 | 258 | |
| 264 | 259 | // Get the main form ID. |
| 265 | 260 | $set_name = 0; |
| 266 | - | |
| 267 | 261 | foreach ( $xml->form as $form ) { |
| 268 | 262 | if ( empty( $form->parent_form_id ) ) { |
| 269 | 263 | $set_name = (int) $form->id; |
| 270 | 264 | } |
| @@ -301,15 +295,15 @@ | ||
| 301 | 295 | } |
| 302 | 296 | |
| 303 | 297 | /** |
| 304 | 298 | * @param string[] $errors |
| 305 | - * @param string $message | |
| 299 | + * @param string $message | |
| 306 | 300 | * |
| 307 | 301 | * @return void |
| 308 | 302 | */ |
| 309 | 303 | public static function form( $errors = array(), $message = '' ) { |
| 310 | 304 | $where = array( |
| 311 | - 'status' => array( null, '', 'published' ), | |
| 305 | + 'status' => array( null, '', 'published' ), | |
| 312 | 306 | ); |
| 313 | 307 | $forms = FrmForm::getAll( $where, 'name' ); |
| 314 | 308 | |
| 315 | 309 | $export_types = array( |
| @@ -338,12 +332,12 @@ | ||
| 338 | 332 | /** |
| 339 | 333 | * @return void |
| 340 | 334 | */ |
| 341 | 335 | public static function import_xml() { |
| 342 | - $errors = array(); | |
| 343 | - $message = ''; | |
| 336 | + $errors = array(); | |
| 337 | + $message = ''; | |
| 338 | + | |
| 344 | 339 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' ); |
| 345 | - | |
| 346 | 340 | if ( false !== $permission_error ) { |
| 347 | 341 | $errors[] = $permission_error; |
| 348 | 342 | self::form( $errors ); |
| 349 | 343 | |
| @@ -349,11 +343,9 @@ | ||
| 349 | 343 | |
| 350 | 344 | return; |
| 351 | 345 | } |
| 352 | 346 | |
| 353 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 354 | - $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; | |
| 355 | - | |
| 347 | + $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; | |
| 356 | 348 | if ( ! $has_file ) { |
| 357 | 349 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 358 | 350 | self::form( $errors ); |
| 359 | 351 | |
| @@ -359,9 +351,9 @@ | ||
| 359 | 351 | |
| 360 | 352 | return; |
| 361 | 353 | } |
| 362 | 354 | |
| 363 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 355 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 364 | 356 | $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : ''; |
| 365 | 357 | |
| 366 | 358 | if ( ! is_uploaded_file( $file ) ) { |
| 367 | 359 | unset( $file ); |
| @@ -370,8 +362,10 @@ | ||
| 370 | 362 | |
| 371 | 363 | return; |
| 372 | 364 | } |
| 373 | 365 | |
| 366 | + //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); | |
| 367 | + | |
| 374 | 368 | $export_format = array( |
| 375 | 369 | 'xml' => array( |
| 376 | 370 | 'name' => 'XML', |
| 377 | 371 | 'support' => 'forms', |
| @@ -379,14 +373,13 @@ | ||
| 379 | 373 | ), |
| 380 | 374 | ); |
| 381 | 375 | $export_format = apply_filters( 'frm_export_formats', $export_format ); |
| 382 | 376 | |
| 383 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 377 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 384 | 378 | $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] ); |
| 385 | 379 | $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) ); |
| 386 | - | |
| 387 | 380 | if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) { |
| 388 | - // Allow other file types to be imported | |
| 381 | + // allow other file types to be imported | |
| 389 | 382 | do_action( 'frm_before_import_' . $file_type ); |
| 390 | 383 | |
| 391 | 384 | return; |
| 392 | 385 | } |
| @@ -400,9 +393,10 @@ | ||
| 400 | 393 | } |
| 401 | 394 | |
| 402 | 395 | $set_err = libxml_use_internal_errors( true ); |
| 403 | 396 | $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true ); |
| 404 | - $result = FrmXMLHelper::import_xml( $file ); | |
| 397 | + | |
| 398 | + $result = FrmXMLHelper::import_xml( $file ); | |
| 405 | 399 | FrmXMLHelper::parse_message( $result, $message, $errors ); |
| 406 | 400 | |
| 407 | 401 | unset( $file ); |
| 408 | 402 | |
| @@ -416,10 +410,9 @@ | ||
| 416 | 410 | * @return void |
| 417 | 411 | */ |
| 418 | 412 | public static function export_xml() { |
| 419 | 413 | $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
| 420 | - | |
| 421 | - if ( $error ) { | |
| 414 | + if ( ! empty( $error ) ) { | |
| 422 | 415 | wp_die( esc_html( $error ) ); |
| 423 | 416 | } |
| 424 | 417 | |
| 425 | 418 | $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array(), 'sanitize_text_field' ); |
| @@ -426,9 +419,9 @@ | ||
| 426 | 419 | $type = FrmAppHelper::get_post_param( 'type', array(), 'sanitize_text_field' ); |
| 427 | 420 | $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' ); |
| 428 | 421 | |
| 429 | 422 | if ( ! headers_sent() && ! $type ) { |
| 430 | - wp_safe_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) ); | |
| 423 | + wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) ); | |
| 431 | 424 | die(); |
| 432 | 425 | } |
| 433 | 426 | |
| 434 | 427 | if ( 'xml' === $format ) { |
| @@ -442,27 +435,19 @@ | ||
| 442 | 435 | wp_die(); |
| 443 | 436 | } |
| 444 | 437 | |
| 445 | 438 | /** |
| 446 | - * @param array<string>|string $type | |
| 447 | - * @param array $args | |
| 439 | + * @param array $args | |
| 448 | 440 | * |
| 449 | 441 | * @psalm-param array{ids?: mixed} $args |
| 450 | 442 | * |
| 451 | 443 | * @return void |
| 452 | 444 | */ |
| 453 | - public static function generate_xml( $type, $args = array() ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 445 | + public static function generate_xml( $type, $args = array() ) { | |
| 454 | 446 | global $wpdb; |
| 455 | 447 | |
| 456 | 448 | self::prepare_types_array( $type ); |
| 457 | 449 | |
| 458 | - if ( ! is_array( $type ) ) { | |
| 459 | - // This shouldn't be possible. | |
| 460 | - // It is cast to array in prepare_types_array. | |
| 461 | - // This is just for static analysis. | |
| 462 | - return; | |
| 463 | - } | |
| 464 | - | |
| 465 | 450 | $tables = array( |
| 466 | 451 | 'items' => $wpdb->prefix . 'frm_items', |
| 467 | 452 | 'forms' => $wpdb->prefix . 'frm_forms', |
| 468 | 453 | 'posts' => $wpdb->posts, |
| @@ -475,9 +460,9 @@ | ||
| 475 | 460 | ); |
| 476 | 461 | $args = wp_parse_args( $args, $defaults ); |
| 477 | 462 | |
| 478 | 463 | // Make sure ids are numeric. |
| 479 | - if ( is_array( $args['ids'] ) && $args['ids'] ) { | |
| 464 | + if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) { | |
| 480 | 465 | $args['ids'] = array_filter( $args['ids'], 'is_numeric' ); |
| 481 | 466 | } |
| 482 | 467 | |
| 483 | 468 | $records = array(); |
| @@ -482,17 +467,18 @@ | ||
| 482 | 467 | |
| 483 | 468 | $records = array(); |
| 484 | 469 | |
| 485 | 470 | foreach ( $type as $tb_type ) { |
| 486 | - $where = array(); | |
| 487 | - $join = ''; | |
| 488 | - $table = $tables[ $tb_type ]; | |
| 471 | + $where = array(); | |
| 472 | + $join = ''; | |
| 473 | + $table = $tables[ $tb_type ]; | |
| 474 | + | |
| 489 | 475 | $select = $table . '.id'; |
| 490 | 476 | $query_vars = array(); |
| 491 | 477 | |
| 492 | 478 | switch ( $tb_type ) { |
| 493 | 479 | case 'forms': |
| 494 | - // Add forms. | |
| 480 | + //add forms | |
| 495 | 481 | if ( $args['ids'] ) { |
| 496 | 482 | $where[] = array( |
| 497 | 483 | 'or' => 1, |
| 498 | 484 | $table . '.id' => $args['ids'], |
| @@ -504,9 +490,8 @@ | ||
| 504 | 490 | break; |
| 505 | 491 | case 'actions': |
| 506 | 492 | $select = $table . '.ID'; |
| 507 | 493 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
| 508 | - | |
| 509 | 494 | if ( ! empty( $args['ids'] ) ) { |
| 510 | 495 | $where['menu_order'] = $args['ids']; |
| 511 | 496 | } |
| 512 | 497 | break; |
| @@ -521,12 +506,10 @@ | ||
| 521 | 506 | $frm_style = new FrmStyle(); |
| 522 | 507 | $default_style = $frm_style->get_default_style(); |
| 523 | 508 | $form_ids = $args['ids']; |
| 524 | 509 | $style_ids = array(); |
| 525 | - | |
| 526 | 510 | foreach ( $form_ids as $form_id ) { |
| 527 | 511 | $form_data = FrmForm::getOne( $form_id ); |
| 528 | - | |
| 529 | 512 | // For forms that have not been updated while running 2.0, check if custom_style is set. |
| 530 | 513 | if ( isset( $form_data->options['custom_style'] ) ) { |
| 531 | 514 | if ( 1 === absint( $form_data->options['custom_style'] ) ) { |
| 532 | 515 | $style_ids[] = $default_style->ID; |
| @@ -535,14 +518,13 @@ | ||
| 535 | 518 | } |
| 536 | 519 | } |
| 537 | 520 | unset( $form_id, $form_data ); |
| 538 | 521 | } |
| 539 | - | |
| 540 | 522 | $select = $table . '.ID'; |
| 541 | 523 | $where['post_type'] = 'frm_styles'; |
| 542 | 524 | |
| 543 | 525 | // Only export selected styles. |
| 544 | - if ( $style_ids ) { | |
| 526 | + if ( ! empty( $style_ids ) ) { | |
| 545 | 527 | $where['ID'] = $style_ids; |
| 546 | 528 | } |
| 547 | 529 | break; |
| 548 | 530 | default: |
| @@ -554,15 +536,15 @@ | ||
| 554 | 536 | $where['pm.meta_value >'] = 1; |
| 555 | 537 | } else { |
| 556 | 538 | $where['pm.meta_value'] = $args['ids']; |
| 557 | 539 | } |
| 558 | - }//end switch | |
| 540 | + } | |
| 559 | 541 | |
| 560 | 542 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
| 561 | 543 | unset( $tb_type ); |
| 562 | - }//end foreach | |
| 544 | + } | |
| 563 | 545 | |
| 564 | - $filename = self::get_file_name( $args, $records ); | |
| 546 | + $filename = self::get_file_name( $args, $type, $records ); | |
| 565 | 547 | |
| 566 | 548 | header( 'Content-Description: File Transfer' ); |
| 567 | 549 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 568 | 550 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
| @@ -571,46 +553,19 @@ | ||
| 571 | 553 | include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php'; |
| 572 | 554 | } |
| 573 | 555 | |
| 574 | 556 | /** |
| 575 | - * Returns an array that has parent term slugs for the terms provided. | |
| 576 | - * | |
| 577 | - * @since 6.8.3 | |
| 578 | - * | |
| 579 | - * @param array $terms | |
| 580 | - * | |
| 581 | - * @return array | |
| 582 | - */ | |
| 583 | - public static function get_parent_terms_slugs( $terms ) { | |
| 584 | - $parent_term_ids = array_filter( array_unique( wp_list_pluck( $terms, 'parent' ) ) ); | |
| 585 | - $parent_slugs = array(); | |
| 586 | - | |
| 587 | - if ( ! $parent_term_ids ) { | |
| 588 | - return $parent_slugs; | |
| 589 | - } | |
| 590 | - | |
| 591 | - $results = FrmDb::get_results( 'terms', array( 'term_id' => $parent_term_ids ), 'term_id, slug' ); | |
| 592 | - | |
| 593 | - return wp_list_pluck( $results, 'slug', 'term_id' ); | |
| 594 | - } | |
| 595 | - | |
| 596 | - /** | |
| 597 | - * Prepare the types array. | |
| 598 | - * | |
| 599 | - * @param array<string>|string $type | |
| 600 | - * | |
| 601 | 557 | * @return void |
| 602 | 558 | */ |
| 603 | 559 | private static function prepare_types_array( &$type ) { |
| 604 | 560 | $type = (array) $type; |
| 605 | - | |
| 606 | - if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) { | |
| 607 | - // Make sure the form is included if there are entries | |
| 561 | + if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) { | |
| 562 | + // make sure the form is included if there are entries | |
| 608 | 563 | $type[] = 'forms'; |
| 609 | 564 | } |
| 610 | 565 | |
| 611 | - if ( in_array( 'forms', $type, true ) ) { | |
| 612 | - // Include actions with forms | |
| 566 | + if ( in_array( 'forms', $type ) ) { | |
| 567 | + // include actions with forms | |
| 613 | 568 | $type[] = 'actions'; |
| 614 | 569 | } |
| 615 | 570 | } |
| 616 | 571 | |
| @@ -619,24 +574,23 @@ | ||
| 619 | 574 | * Use the nme of the form if only one form is exported. |
| 620 | 575 | * |
| 621 | 576 | * @since 3.06 |
| 622 | 577 | * |
| 578 | + * @param array $type | |
| 579 | + * @param array $records | |
| 623 | 580 | * @param array $args |
| 624 | - * @param array $records | |
| 625 | 581 | * |
| 626 | 582 | * @return string |
| 627 | 583 | */ |
| 628 | - private static function get_file_name( $args, $records ) { | |
| 629 | - $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 630 | - | |
| 584 | + private static function get_file_name( $args, $type, $records ) { | |
| 585 | + $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 631 | 586 | if ( $has_one_form ) { |
| 632 | - // One form is being exported | |
| 587 | + // one form is being exported | |
| 633 | 588 | $selected_form_id = reset( $args['ids'] ); |
| 634 | 589 | $filename = 'form-' . $selected_form_id . '.xml'; |
| 635 | 590 | |
| 636 | 591 | foreach ( $records['forms'] as $form_id ) { |
| 637 | 592 | $filename = 'form-' . $form_id . '.xml'; |
| 638 | - | |
| 639 | 593 | if ( $selected_form_id === $form_id ) { |
| 640 | 594 | $form = FrmForm::getOne( $form_id ); |
| 641 | 595 | $filename = $form->name !== '' ? $form->name : $form->form_key; |
| 642 | 596 | $filename = sanitize_title( $filename ) . '-form.xml'; |
| @@ -645,14 +599,13 @@ | ||
| 645 | 599 | } |
| 646 | 600 | } else { |
| 647 | 601 | $sitename = sanitize_key( get_bloginfo( 'name' ) ); |
| 648 | 602 | |
| 649 | - if ( $sitename ) { | |
| 603 | + if ( ! empty( $sitename ) ) { | |
| 650 | 604 | $sitename .= '.'; |
| 651 | 605 | } |
| 652 | - | |
| 653 | 606 | $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml'; |
| 654 | - }//end if | |
| 607 | + } | |
| 655 | 608 | |
| 656 | 609 | /** |
| 657 | 610 | * @since 5.3 |
| 658 | 611 | * |
| @@ -667,10 +620,9 @@ | ||
| 667 | 620 | * @return void |
| 668 | 621 | */ |
| 669 | 622 | public static function generate_csv( $atts ) { |
| 670 | 623 | $form_ids = $atts['ids']; |
| 671 | - | |
| 672 | - if ( ! $form_ids ) { | |
| 624 | + if ( empty( $form_ids ) ) { | |
| 673 | 625 | wp_die( esc_html__( 'Please select a form', 'formidable' ) ); |
| 674 | 626 | } |
| 675 | 627 | self::csv( reset( $form_ids ) ); |
| 676 | 628 | } |
| @@ -679,12 +631,8 @@ | ||
| 679 | 631 | * Export to CSV |
| 680 | 632 | * |
| 681 | 633 | * @since 2.0.19 |
| 682 | 634 | * |
| 683 | - * @param false|int|string $form_id | |
| 684 | - * @param string $search | |
| 685 | - * @param string $fid | |
| 686 | - * | |
| 687 | 635 | * @return void |
| 688 | 636 | */ |
| 689 | 637 | public static function csv( $form_id = false, $search = '', $fid = '' ) { |
| 690 | 638 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| @@ -690,19 +638,14 @@ | ||
| 690 | 638 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| 691 | 639 | |
| 692 | 640 | if ( ! $form_id ) { |
| 693 | 641 | $form_id = FrmAppHelper::get_param( 'form', '', 'get', 'sanitize_text_field' ); |
| 694 | - $search = FrmAppHelper::get_param( isset( $_REQUEST['s'] ) ? 's' : 'search', '', 'get', 'sanitize_text_field' ); | |
| 642 | + $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' ); | |
| 695 | 643 | $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' ); |
| 696 | 644 | } |
| 697 | 645 | |
| 698 | - // Remove time limit to execute this function. | |
| 699 | - if ( function_exists( 'set_time_limit' ) ) { | |
| 700 | - set_time_limit( 0 ); | |
| 701 | - } | |
| 702 | - | |
| 646 | + set_time_limit( 0 ); //Remove time limit to execute this function | |
| 703 | 647 | $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
| 704 | - | |
| 705 | 648 | if ( (int) $mem_limit < 256 ) { |
| 706 | 649 | wp_raise_memory_limit(); |
| 707 | 650 | } |
| 708 | 651 | |
| @@ -716,11 +659,11 @@ | ||
| 716 | 659 | } |
| 717 | 660 | |
| 718 | 661 | $form_id = $form->id; |
| 719 | 662 | $form_cols = self::get_fields_for_csv_export( $form_id, $form ); |
| 720 | - $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' ); | |
| 721 | 663 | |
| 722 | - if ( $item_id ) { | |
| 664 | + $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' ); | |
| 665 | + if ( ! empty( $item_id ) ) { | |
| 723 | 666 | $item_id = explode( ',', $item_id ); |
| 724 | 667 | } |
| 725 | 668 | |
| 726 | 669 | $query = array( |
| @@ -741,9 +684,9 @@ | ||
| 741 | 684 | |
| 742 | 685 | $entry_ids = FrmDb::get_col( $wpdb->prefix . 'frm_items it', $query ); |
| 743 | 686 | unset( $query ); |
| 744 | 687 | |
| 745 | - if ( ! $entry_ids ) { | |
| 688 | + if ( empty( $entry_ids ) ) { | |
| 746 | 689 | esc_html_e( 'There are no entries for that form.', 'formidable' ); |
| 747 | 690 | } else { |
| 748 | 691 | FrmCSVExportHelper::generate_csv( compact( 'form', 'entry_ids', 'form_cols' ) ); |
| 749 | 692 | } |
| @@ -756,17 +699,16 @@ | ||
| 756 | 699 | * |
| 757 | 700 | * @since 2.0.19 |
| 758 | 701 | * @since 5.0.16 function went from private to public. |
| 759 | 702 | * |
| 760 | - * @param int $form_id | |
| 703 | + * @param int $form_id | |
| 761 | 704 | * @param object $form |
| 762 | 705 | * |
| 763 | - * @return array CSV fields. | |
| 706 | + * @return array $csv_fields | |
| 764 | 707 | */ |
| 765 | 708 | public static function get_fields_for_csv_export( $form_id, $form ) { |
| 766 | 709 | $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' ); |
| 767 | 710 | $no_export_fields = FrmField::no_save_fields(); |
| 768 | - | |
| 769 | 711 | foreach ( $csv_fields as $k => $f ) { |
| 770 | 712 | if ( in_array( $f->type, $no_export_fields, true ) ) { |
| 771 | 713 | unset( $csv_fields[ $k ] ); |
| 772 | 714 | } |
| @@ -774,21 +716,16 @@ | ||
| 774 | 716 | |
| 775 | 717 | return apply_filters( 'frm_fields_for_csv_export', $csv_fields, compact( 'form' ) ); |
| 776 | 718 | } |
| 777 | 719 | |
| 778 | - /** | |
| 779 | - * @param array $mimes | |
| 780 | - * | |
| 781 | - * @return array | |
| 782 | - */ | |
| 783 | 720 | public static function allow_mime( $mimes ) { |
| 784 | 721 | if ( ! isset( $mimes['csv'] ) ) { |
| 785 | - // Allow csv files | |
| 722 | + // allow csv files | |
| 786 | 723 | $mimes['csv'] = 'text/csv'; |
| 787 | 724 | } |
| 788 | 725 | |
| 789 | 726 | if ( ! isset( $mimes['xml'] ) ) { |
| 790 | - // Allow xml | |
| 727 | + // allow xml | |
| 791 | 728 | $mimes['xml'] = 'text/xml'; |
| 792 | 729 | } |
| 793 | 730 | |
| 794 | 731 | return $mimes; |