| @@ -79,49 +79,20 @@ | ||
| 79 | 79 | } |
| 80 | 80 | return $attach_id; |
| 81 | 81 | } |
| 82 | 82 | else{ |
| 83 | - $attachment_id = $wpdb->get_results( | |
| 84 | - $wpdb->prepare( | |
| 85 | - "SELECT ID FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' AND guid LIKE %s", | |
| 86 | - '%' . $wpdb->esc_like( $image_title ) . '%' | |
| 87 | - ), | |
| 88 | - ARRAY_A | |
| 89 | - ); | |
| 83 | + $attachment_id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' AND guid LIKE '%$image_title%'", ARRAY_A); | |
| 90 | 84 | |
| 91 | 85 | } |
| 92 | 86 | if(is_array($attachment_id) && !empty($attachment_id[0]['ID']) && $image_type != 'Featured'){ |
| 93 | 87 | $table_name = $wpdb->prefix . 'smackcsv_file_events'; |
| 94 | - $post_title = $wpdb->get_var( | |
| 95 | - $wpdb->prepare( | |
| 96 | - "SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = %d AND post_status != 'trash'", | |
| 97 | - absint( $post_id ) | |
| 98 | - ) | |
| 99 | - ); | |
| 100 | - $file_name = $wpdb->get_var( | |
| 101 | - $wpdb->prepare( | |
| 102 | - "SELECT file_name FROM $table_name WHERE hash_key = %s", | |
| 103 | - $hash_key | |
| 104 | - ) | |
| 105 | - ); | |
| 88 | + $post_title = $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = '{$post_id}' AND post_status != 'trash'"); | |
| 89 | + $file_name = $wpdb->get_var("SELECT file_name FROM $table_name WHERE hash_key = '$hash_key'"); | |
| 106 | 90 | $shortcode_table = $wpdb->prefix . "ultimate_csv_importer_shortcode_manager"; |
| 107 | 91 | $attach_id = $attachment_id[0]['ID']; |
| 108 | - $check_id = $wpdb->get_results( | |
| 109 | - $wpdb->prepare( | |
| 110 | - "SELECT ID FROM {$wpdb->prefix}posts WHERE ID = %d AND post_title ='image-failed' AND post_type = 'attachment' AND guid LIKE %s", | |
| 111 | - absint( $attach_id ), | |
| 112 | - '%' . $wpdb->esc_like( $image_title ) . '%' | |
| 113 | - ), | |
| 114 | - ARRAY_A | |
| 115 | - ); | |
| 92 | + $check_id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE ID ='{$attach_id}' AND post_title ='image-failed' AND post_type = 'attachment' AND guid LIKE '%$image_title%'", ARRAY_A); | |
| 116 | 93 | if(!empty($check_id)){ |
| 117 | - $failed_ids = $wpdb->get_results( | |
| 118 | - $wpdb->prepare( | |
| 119 | - "SELECT * FROM {$wpdb->prefix}ultimate_csv_importer_shortcode_manager WHERE post_id = %d AND media_id = %d", | |
| 120 | - absint( $post_id ), | |
| 121 | - absint( $attach_id ) | |
| 122 | - ) | |
| 123 | - ); | |
| 94 | + $failed_ids = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}ultimate_csv_importer_shortcode_manager WHERE post_id='{$post_id}' AND media_id = '{$attach_id}'"); | |
| 124 | 95 | if(!empty($failed_ids) && $failed_ids[0]->post_id != $post_id){ |
| 125 | 96 | $attach_id = $check_id[0]['ID'];; |
| 126 | 97 | $insert_status = $wpdb->insert($shortcode_table, |
| 127 | 98 | array( |
| @@ -258,14 +229,10 @@ | ||
| 258 | 229 | $fimg_name = @basename($f_img); |
| 259 | 230 | $fimg_name = str_replace(' ', '-', trim($fimg_name)); |
| 260 | 231 | $fimg_name = preg_replace('/[^a-zA-Z0-9._\-\s]/', '', $fimg_name); |
| 261 | 232 | } |
| 262 | - $attachment_id = $wpdb->get_var( | |
| 263 | - $wpdb->prepare( | |
| 264 | - "SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'attachment' AND guid LIKE %s", | |
| 265 | - '%' . $wpdb->esc_like( $fimg_name ) | |
| 266 | - ) | |
| 267 | - ); | |
| 233 | + $attachment_id = $wpdb->get_var("SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'attachment' AND guid LIKE '%$fimg_name'"); | |
| 234 | + | |
| 268 | 235 | if($attachment_id){ |
| 269 | 236 | if(!empty($data_array['featured_image'])){ |
| 270 | 237 | set_post_thumbnail( $post_id, $attachment_id ); |
| 271 | 238 | return $attachment_id; |
| @@ -430,27 +397,11 @@ | ||
| 430 | 397 | } |
| 431 | 398 | public function image_meta_table_entry($line_number ,$post_values, $post_id ,$acf_wpname_element, $acf_csv_name, $hash_key, $plugin,$get_import_type,$templatekey = null,$gmode = null,$header_array = null, $value_array = null,$imgformat = null,$typecct = null,$indexs=null){ |
| 432 | 399 | global $wpdb; |
| 433 | 400 | $table_name = $wpdb->prefix . 'smackcsv_file_events'; |
| 434 | - $file_name = $wpdb->get_var( | |
| 435 | - $wpdb->prepare( | |
| 436 | - "SELECT file_name FROM $table_name WHERE hash_key = %s", | |
| 437 | - $hash_key | |
| 438 | - ) | |
| 439 | - ); | |
| 440 | - $post_title = $wpdb->get_var( | |
| 441 | - $wpdb->prepare( | |
| 442 | - "SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = %d AND post_status != 'trash'", | |
| 443 | - absint( $post_id ) | |
| 444 | - ) | |
| 445 | - ); | |
| 446 | - $failed_ids = $wpdb->get_results( | |
| 447 | - $wpdb->prepare( | |
| 448 | - "SELECT post_title,post_id,image_shortcode,media_id,original_image FROM {$wpdb->prefix}ultimate_csv_importer_shortcode_manager WHERE image_shortcode ='Featured_image_' AND post_id = %d AND original_image = %s", | |
| 449 | - absint( $post_id ), | |
| 450 | - $acf_csv_name | |
| 451 | - ) | |
| 452 | - ); | |
| 401 | + $file_name = $wpdb->get_var("SELECT file_name FROM $table_name WHERE hash_key = '$hash_key'"); | |
| 402 | + $post_title = $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = '{$post_id}' AND post_status != 'trash'"); | |
| 403 | + $failed_ids = $wpdb->get_results("SELECT post_title,post_id,image_shortcode,media_id,original_image FROM {$wpdb->prefix}ultimate_csv_importer_shortcode_manager WHERE image_shortcode ='Featured_image_' AND post_id = '{$post_id}' AND original_image = '{$acf_csv_name}' "); | |
| 453 | 404 | //$core_instance = CoreFieldsImport::getInstance(); |
| 454 | 405 | //$core_instance = new WooCommerceCoreImport; |
| 455 | 406 | $shortcode_table = $wpdb->prefix . "ultimate_csv_importer_shortcode_manager"; |
| 456 | 407 | |
| @@ -472,16 +423,9 @@ | ||
| 472 | 423 | $acf_image_meta =json_encode($image_meta_value); |
| 473 | 424 | } |
| 474 | 425 | $acf_image_meta = isset($acf_image_meta) ? $acf_image_meta : null; |
| 475 | 426 | $attach_id = $this->media_handling($acf_csv_name, $post_id, $post_values,$get_import_type,$plugin,$hash_key,'',$header_array,$value_array,$indexs,$acf_wpname_element,$acf_image_meta); |
| 476 | - $failed_id = $wpdb->get_results( | |
| 477 | - $wpdb->prepare( | |
| 478 | - "SELECT post_title,post_id,image_shortcode,media_id,original_image FROM {$wpdb->prefix}ultimate_csv_importer_shortcode_manager WHERE post_id = %d AND original_image = %s AND image_shortcode = %s", | |
| 479 | - absint( $post_id ), | |
| 480 | - $acf_csv_name, | |
| 481 | - $plugin . '_image__' . $acf_wpname_element | |
| 482 | - ) | |
| 483 | - ); | |
| 427 | + $failed_id = $wpdb->get_results("SELECT post_title,post_id,image_shortcode,media_id,original_image FROM {$wpdb->prefix}ultimate_csv_importer_shortcode_manager WHERE post_id = '{$post_id}' AND original_image = '{$acf_csv_name}' AND image_shortcode = '" . esc_sql($plugin.'_image__'.$acf_wpname_element) . "' "); | |
| 484 | 428 | if(!empty($attach_id)){ |
| 485 | 429 | $this->store_image_ids($attach_id ); //store the image id |
| 486 | 430 | return $attach_id; |
| 487 | 431 | } |
| @@ -541,27 +485,14 @@ | ||
| 541 | 485 | } |
| 542 | 486 | } |
| 543 | 487 | else{ |
| 544 | 488 | $media_id = $failed_id[0]->media_id; |
| 545 | - $attachment_id = $wpdb->get_results( | |
| 546 | - $wpdb->prepare( | |
| 547 | - "SELECT ID FROM {$wpdb->prefix}posts WHERE ID = %d AND post_title ='image-failed' AND post_type = 'attachment' AND guid LIKE %s", | |
| 548 | - absint( $media_id ), | |
| 549 | - '%' . $wpdb->esc_like( $fimg_name ) . '%' | |
| 550 | - ), | |
| 551 | - ARRAY_A | |
| 552 | - ); | |
| 489 | + $attachment_id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE ID = $media_id AND post_title ='image-failed' AND post_type = 'attachment' AND guid LIKE '%$fimg_name%'", ARRAY_A); | |
| 553 | 490 | $attach_id= $attachment_id[0]['ID']; |
| 554 | 491 | } |
| 555 | 492 | return isset($attach_id) ? $attach_id : ''; |
| 556 | 493 | }else{ |
| 557 | - $attachment_id = $wpdb->get_results( | |
| 558 | - $wpdb->prepare( | |
| 559 | - "SELECT ID FROM {$wpdb->prefix}posts WHERE post_title ='image-failed' AND post_type = 'attachment' AND guid LIKE %s", | |
| 560 | - '%' . $wpdb->esc_like( $fimg_name ) . '%' | |
| 561 | - ), | |
| 562 | - ARRAY_A | |
| 563 | - ); | |
| 494 | + $attachment_id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title ='image-failed' AND post_type = 'attachment' AND guid LIKE '%$fimg_name%'", ARRAY_A); | |
| 564 | 495 | } |
| 565 | 496 | return $attach_id; |
| 566 | 497 | } |
| 567 | 498 | } |