PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wp-all-import2
/
helpers
<?php function wp_all_import_get_image_from_gallery($image_name, $targetDir = FALSE, $bundle_type = 'images', $logger = false) { $search_image_by_wp_attached_file = apply_filters('wp_all_import_search_image_by_wp_attached_file', true); if (!$search_image_by_wp_attached_file){ return false; } global $wpdb; $original_image_name = $image_name; if (!$targetDir) { $wp_uploads = wp_upload_dir(); $targetDir = $wp_uploads['path']; } $attch = ''; // search attachment by attached file $attachment_metas = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND (meta_value = %s OR meta_value LIKE %s ESCAPE '$');", '_wp_attached_file', $image_name, "%/" . str_replace('_', '$_', $image_name))); if (!empty($attachment_metas)) { foreach ($attachment_metas as $attachment_meta) { $attch = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE ID = %d;", $attachment_meta->post_id)); if (!empty($attch)) { $logger and call_user_func($logger, sprintf(__('- Found existing image with ID `%s` by meta key _wp_attached_file equals to `%s`...', 'wp_all_import_plugin'), $attch->ID, trim($image_name))); break; } } } if (empty($attch)) { $attachment_metas = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND (meta_value = %s OR meta_value LIKE %s ESCAPE '$');", '_wp_attached_file', sanitize_file_name($image_name), "%/" . str_replace('_', '$_', sanitize_file_name($image_name)))); if (!empty($attachment_metas)) { foreach ($attachment_metas as $attachment_meta) { $attch = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE ID = %d;", $attachment_meta->post_id)); if (!empty($attch)) { $logger and call_user_func($logger, sprintf(__('- Found existing image with ID `%s` by meta key _wp_attached_file equals to `%s`...', 'wp_all_import_plugin'), $attch->ID, sanitize_file_name($image_name))); break; } } } } if (empty($attch)) { // Search attachment by file name with extension. $attch = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE (post_title = %s OR post_name = %s) AND post_type = %s", $image_name, sanitize_title($image_name), "attachment") . " AND post_mime_type LIKE 'image%';"); if (!empty($attch)) { $logger and call_user_func($logger, sprintf(__('- Found existing image with ID `%s` by post_title or post_name equals to `%s`...', 'wp_all_import_plugin'), $attch->ID, $image_name)); } } // Search attachment by file headers. if (empty($attch) and @file_exists($targetDir . DIRECTORY_SEPARATOR . $original_image_name)) { if ( ! function_exists('wp_read_image_metadata') ) { require_once( ABSPATH . 'wp-admin/includes/image.php' ); } if ($bundle_type == 'images' and ($img_meta = wp_read_image_metadata($targetDir . DIRECTORY_SEPARATOR . $original_image_name))) { if (trim($img_meta['title']) && !is_numeric(sanitize_title($img_meta['title']))) { $img_title = $img_meta['title']; $attch = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE post_title = %s AND post_type = %s AND post_mime_type LIKE %s;", $img_title, "attachment", "image%")); if (!empty($attch)){ $logger and call_user_func($logger, sprintf(__('- Found existing image with ID `%s` by post_title equals to `%s`...', 'wp_all_import_plugin'), $attch->ID, $img_title)); } } } if (empty($attch)) { @unlink($targetDir . DIRECTORY_SEPARATOR . $original_image_name); } } return apply_filters('wp_all_import_get_image_from_gallery', $attch, $original_image_name, $targetDir); }
[+]
..
[-] wp_all_import_json_to_xml.php
[edit]
[-] wp_all_import_xml2array.php
[edit]
[-] backward.php
[edit]
[-] wp_all_import_rand_char.php
[edit]
[-] wp_all_import_sanitize_filename.php
[edit]
[-] functions.php
[edit]
[-] wp_all_import_get_parent_terms.php
[edit]
[-] wp_all_import_template_notifications.php
[edit]
[-] wp_delete_attachments.php
[edit]
[-] wp_all_import_strip_tags_content.php
[edit]
[-] wpai_util_map.php
[edit]
[-] str_getcsv.php
[edit]
[-] wp_all_import_addon_notifications.php
[edit]
[-] is_exists_term.php
[edit]
[-] pmxi_findDuplicates.php
[edit]
[-] wp_all_import_clear_directory.php
[edit]
[-] wp_all_import_rmdir.php
[edit]
[-] wp_all_import_get_reader_engine.php
[edit]
[-] wp_all_import_is_json.php
[edit]
[-] wp_redirect_or_javascript.php
[edit]
[-] import_custom_meta_box.php
[edit]
[-] wp_all_import_remove_source.php
[edit]
[-] wp_all_import_ctx_mapping.php
[edit]
[-] wp_all_import_get_feed_type.php
[edit]
[-] wp_all_import_get_gz.php
[edit]
[-] wp_all_import_url_title.php
[edit]
[-] wp_all_import_secure_file.php
[edit]
[-] wp_all_import_get_image_from_gallery.php
[edit]
[-] get_taxonomies_by_object_type.php
[edit]
[-] get_file_curl.php
[edit]
[-] reverse_taxonomies_html.php
[edit]
[-] pmxi_recursion_taxes.php
[edit]
[-] wp_all_import_get_parent_post.php
[edit]
[-] wp_all_import_get_url.php
[edit]
[-] wp_all_import_is_update_cf.php
[edit]