public function parse()
 {
     $tmpname = wp_unique_filename($this->targetDir, str_replace("sql", "xml", basename($this->_filename)));
     $this->xml_path = $this->targetDir . '/' . url_title($tmpname);
     $this->toXML();
     return $this->xml_path;
 }
 /**
  * Change the slide image.
  *
  * This creates a copy of the selected (new) image and assigns the copy to our existing media file/slide.
  */
 public function ajax_change_slide_image()
 {
     if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'metaslider_changeslide')) {
         wp_die(json_encode(array('status' => 'fail', 'msg' => __("Security check failed. Refresh page and try again.", "ml-slider"))));
     }
     $slide_from = absint($_POST['slide_from']);
     $slide_to = absint($_POST['slide_to']);
     // find the paths for the image we want to change to
     // Absolute path
     $abs_path = get_attached_file($slide_to);
     $abs_path_parts = pathinfo($abs_path);
     $abs_file_directory = $abs_path_parts['dirname'];
     // Relative path
     $rel_path = get_post_meta($slide_to, '_wp_attached_file', true);
     $rel_path_parts = pathinfo($rel_path);
     $rel_file_directory = $rel_path_parts['dirname'];
     // old file name
     $file_name = $abs_path_parts['basename'];
     // new file name
     $dest_file_name = wp_unique_filename($abs_file_directory, $file_name);
     // generate absolute and relative paths for the new file name
     $dest_abs_path = trailingslashit($abs_file_directory) . $dest_file_name;
     $dest_rel_path = trailingslashit($rel_file_directory) . $dest_file_name;
     // make a copy of the image
     if (@copy($abs_path, $dest_abs_path)) {
         // update the path on our slide
         update_post_meta($slide_from, '_wp_attached_file', $dest_rel_path);
         wp_update_attachment_metadata($slide_from, wp_generate_attachment_metadata($slide_from, $dest_abs_path));
         update_attached_file($slide_from, $dest_rel_path);
         wp_die(json_encode(array('status' => 'success')));
     }
     wp_die(json_encode(array('status' => 'fail', 'msg' => __("File copy failed. Please check upload directory permissions.", "ml-slider"))));
 }
 public function output()
 {
     $attachments = array();
     if ($this->query->have_posts()) {
         while ($this->query->have_posts()) {
             $this->query->the_post();
             global $post;
             $invoice = WC_Germanized_Pro()->invoice_factory->get_invoice($post);
             if ($invoice->has_attachment()) {
                 $attachments[$invoice->id] = array('path' => $invoice->get_pdf_path(), 'filename' => $invoice->get_filename());
             }
         }
     }
     if (!empty($attachments)) {
         $upload_dir = WC_germanized_pro()->get_upload_dir();
         $this->filename = wp_unique_filename($upload_dir['path'], $this->filename);
         $this->filepath = trailingslashit($upload_dir['path']) . $this->filename;
         $zip = new ZipArchive();
         $zip->open($this->filepath, ZipArchive::CREATE);
         foreach ($attachments as $attachment) {
             $zip->addFile($attachment['path'], $attachment['filename']);
         }
         $zip->close();
         header('Content-Length: ' . filesize($this->filepath));
         readfile($this->filepath);
     }
 }
 private function get_temporary_file_path($filename)
 {
     $uploads_dir = $this->settings->get_runtime_option('awpcp-uploads-dir');
     $tempory_dir_path = implode(DIRECTORY_SEPARATOR, array($uploads_dir, 'tmp'));
     $pathinfo = awpcp_utf8_pathinfo($filename);
     $new_name = wp_hash($pathinfo['basename']) . '.' . $pathinfo['extension'];
     $unique_filename = wp_unique_filename($tempory_dir_path, $new_name);
     return $tempory_dir_path . DIRECTORY_SEPARATOR . $unique_filename;
 }
Beispiel #5
0
/**
 * @param $file A $_FILES item
 */
function awpcp_upload_image_file($directory, $filename, $tmpname, $min_size, $max_size, $min_width, $min_height, $uploaded = true)
{
    $filename = sanitize_file_name($filename);
    $newname = wp_unique_filename($directory, $filename);
    $newpath = trailingslashit($directory) . $newname;
    if (!file_exists($tmpname)) {
        return sprintf(__('The specified image file does not exists: %s.', 'AWPCP'), $filename);
    }
    $ext = strtolower(awpcp_get_file_extension($filename));
    $imginfo = getimagesize($tmpname);
    $size = filesize($tmpname);
    $allowed_extensions = array('gif', 'jpg', 'jpeg', 'png');
    if (empty($filename)) {
        return __('No file was selected.', 'AWPCP');
    }
    if ($uploaded && !is_uploaded_file($tmpname)) {
        return __('Unknown error encountered while uploading the image.', 'AWPCP');
    }
    if (empty($size) || $size <= 0) {
        $message = "There was an error trying to find out the file size of the image %s.";
        return __(sprintf($message, $filename), 'AWPCP');
    }
    if (!in_array($ext, $allowed_extensions)) {
        return sprintf(__('The file %s has an invalid extension and was rejected.', 'AWPCP'), $filename);
    } elseif ($size < $min_size) {
        $message = __('The size of %1$s was too small. The file was not uploaded. File size must be greater than %2$d bytes.', 'AWPCP');
        return sprintf($message, $filename, $min_size);
    } elseif ($size > $max_size) {
        $message = __('The file %s was larger than the maximum allowed file size of %s bytes. The file was not uploaded.', 'AWPCP');
        return sprintf($message, $filename, $max_size);
    } elseif (!isset($imginfo[0]) && !isset($imginfo[1])) {
        return sprintf(__('The file %s does not appear to be a valid image file.', 'AWPCP'), $filename);
    } elseif ($imginfo[0] < $min_width) {
        $message = __('The image %s did not meet the minimum width of %s pixels. The file was not uploaded.', 'AWPCP');
        return sprintf($message, $filename, $min_width);
    } elseif ($imginfo[1] < $min_height) {
        $message = __('The image %s did not meet the minimum height of %s pixels. The file was not uploaded.', 'AWPCP');
        return sprintf($message, $filename, $min_height);
    }
    if ($uploaded && !@move_uploaded_file($tmpname, $newpath)) {
        $message = __('The file %s could not be moved to the destination directory.', 'AWPCP');
        return sprintf($message, $filename);
    } else {
        if (!$uploaded && !@copy($tmpname, $newpath)) {
            $message = __('The file %s could not be moved to the destination directory.', 'AWPCP');
            return sprintf($message, $filename);
        }
    }
    if (!awpcp_create_image_versions($newname, $directory)) {
        $message = __('Could not create resized versions of image %s.', 'AWPCP');
        # TODO: unlink resized version, thumbnail and primary image
        @unlink($newpath);
        return sprintf($message, $filename);
    }
    @chmod($newpath, 0644);
    return array('original' => $filename, 'filename' => $newname);
}
 function wp_all_import_get_gz($filename, $use_include_path = 0, $targetDir = false)
 {
     $type = 'csv';
     $uploads = wp_upload_dir();
     $targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
     $tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
     $localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
     $fp = @fopen($localPath, 'w');
     $file = @gzopen($filename, 'rb', $use_include_path);
     if ($file) {
         $first_chunk = true;
         while (!gzeof($file)) {
             $chunk = gzread($file, 1024);
             if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
                 $type = 'xml';
                 $first_chunk = false;
             }
             // if it's a 1st chunk, then chunk <? symbols to detect XML file
             @fwrite($fp, $chunk);
         }
         gzclose($file);
     } else {
         $tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
         $localGZpath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
         $request = get_file_curl($filename, $localGZpath, false, true);
         if (!is_wp_error($request)) {
             $file = @gzopen($localGZpath, 'rb', $use_include_path);
             if ($file) {
                 $first_chunk = true;
                 while (!gzeof($file)) {
                     $chunk = gzread($file, 1024);
                     if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
                         $type = 'xml';
                         $first_chunk = false;
                     }
                     // if it's a 1st chunk, then chunk <? symbols to detect XML file
                     @fwrite($fp, $chunk);
                 }
                 gzclose($file);
             }
             @unlink($localGZpath);
         } else {
             return $request;
         }
     }
     @fclose($fp);
     if (preg_match('%\\W(gz)$%i', basename($localPath))) {
         if (@rename($localPath, str_replace('.gz', '.' . $type, $localPath))) {
             $localPath = str_replace('.gz', '.' . $type, $localPath);
         }
     } else {
         if (@rename($localPath, $localPath . '.' . $type)) {
             $localPath = $localPath . '.' . $type;
         }
     }
     return array('type' => $type, 'localPath' => $localPath);
 }
 /**
  * Caller should handle removal of the temp file when finished.
  *
  * @param string $ext The extension to be given to the temp file.
  *
  * @return string A temp file with the given extension.
  */
 public static function getTempFile($ext = 'png')
 {
     static $base = null;
     static $tmp;
     if (is_null($base)) {
         $base = md5(time());
         $tmp = untrailingslashit(get_temp_dir());
     }
     return $tmp . DIRECTORY_SEPARATOR . wp_unique_filename($tmp, $base . '.' . $ext);
 }
function hs_get_auto_post_photo_url($size = "")
{
    $photo = wp_unique_filename(wp_upload_dir()["url"], $_FILES["image"]["name"][0]);
    $photo = wp_upload_dir()["url"] . "/" . $photo;
    if ($size == "small") {
        $extension_position = strrpos($photo, ".");
        $photo_extension = substr($photo, $extension_position);
        $photo = substr($photo, 0, $extension_position) . "-150x150" . $photo_extension;
    }
    return $photo;
}
 public static function setTempPath($sFilePath = '')
 {
     $_sDir = get_temp_dir();
     $sFilePath = basename($sFilePath);
     if (empty($sFilePath)) {
         $sFilePath = time() . '.tmp';
     }
     $sFilePath = $_sDir . wp_unique_filename($_sDir, $sFilePath);
     touch($sFilePath);
     return $sFilePath;
 }
 private function get_uploaded_thumbnail_path()
 {
     $thumbnail = $this->request->post('thumbnail');
     if (!preg_match('/data:([^;]*);base64,(.*)/', $thumbnail, $matches)) {
         throw new AWPCP_Exception(__('No thumbnail data found.', 'AWPCP'));
     }
     $uploads_dir = $this->settings->get_runtime_option('awpcp-uploads-dir');
     $filename = wp_unique_filename($uploads_dir, 'uploaded-thumbnail.png');
     $uploaded_thumbnail_path = $uploads_dir . DIRECTORY_SEPARATOR . $filename;
     file_put_contents($uploaded_thumbnail_path, base64_decode($matches[2]));
     return $uploaded_thumbnail_path;
 }
 function rh_css_settings_saved($notused1, $notused2)
 {
     $css = apply_filters('filter_rh_css', '');
     $upload_dir = wp_upload_dir();
     if (isset($upload_dir['error']) && false == $upload_dir['error']) {
         $filename = wp_unique_filename($upload_dir['path'], 'righthere_styles.css');
         $save_filename = $upload_dir['path'] . "/" . $filename;
         if (false !== file_put_contents($save_filename, $css)) {
             $url = $upload_dir['url'] . "/" . $filename;
             update_option('righthere_styles_url', $url);
         }
     }
 }
 public function create_submission($data = null)
 {
     $settings = get_option('fwe_settings');
     $form_id = $settings['hire_us_form_id'];
     $upload_dir = WP_CONTENT_DIR . '/rfp-uploads';
     $success_msg = array_key_exists('hire_us_success_message', $settings) ? $settings['hire_us_success_message'] : 'Thank you!';
     $mime_type = $data[19];
     if ($mime_type && !in_array($mime_type, $this->allowed_mime_types)) {
         return new WP_Error('That file type is not allowed.');
     }
     $invalid_fields = $this->validate_submission($data);
     if (!empty($invalid_fields)) {
         return new WP_Error('The following required fields were invalid: ' . implode(', ', $invalid_fields));
     }
     // Make the uploads folder if it doesn't exist
     if (!is_dir($upload_dir)) {
         $mkdir_success = wp_mkdir_p($upload_dir);
         if (!$mkdir_success) {
             return new WP_Error('Could not create upload directory.');
         }
     }
     // Save the RFP file data as a file on the server
     if (!empty($data['rfp_file_data'])) {
         $filename = wp_unique_filename($upload_dir, $data[20]);
         $file_data = $this->get_binary_data($data['rfp_file_data']);
         $upload_path = trailingslashit($upload_dir) . $filename;
         $file_url = content_url('/rfp-uploads/' . $filename);
         if (!file_put_contents($upload_path, $file_data)) {
             return new WP_Error('Error saving RFP file.');
         }
         // Don't store base64 garbage in the database
         unset($data['rfp_file_data']);
     }
     // Store the form responses in Gravity Forms
     $data['form_id'] = $form_id;
     $data['date_created'] = strftime('%Y-%m-%d %H:%M');
     $data[21] = $file_url;
     $entry_id = GFAPI::add_entry($data);
     // Give the user back a sanitized version of their input for displaying on the Thank You message
     $response_data = array_merge($data, array('status' => 'OK', 'entry_id' => $entry_id, 'message' => $success_msg));
     unset($response_data[21]);
     $response = new WP_JSON_Response();
     $response->set_data($response_data);
     return $response;
 }
function wpdmp_create_attachment_from_file($filepath)
{
    if (empty($filepath)) {
        return 0;
    }
    global $current_user;
    get_currentuserinfo();
    $logged_in_user = $current_user->ID;
    // load up a variable with the upload direcotry
    $uploads = wp_upload_dir();
    $file = array('name' => strtolower(pathinfo($filepath, PATHINFO_FILENAME) . "." . pathinfo($filepath, PATHINFO_EXTENSION)), 'tmp_name' => $filepath);
    $filename = wp_unique_filename($uploads['path'], $file['name'], $unique_filename_callback);
    // Move the file to the uploads dir
    $new_file = $uploads['path'] . "/{$filename}";
    if (false === @copy($file['tmp_name'], $new_file)) {
        if (0 === strpos($uploads['basedir'], ABSPATH)) {
            $error_path = str_replace(ABSPATH, '', $uploads['basedir']) . $uploads['subdir'];
        } else {
            $error_path = basename($uploads['basedir']) . $uploads['subdir'];
        }
        return sprintf(__('The uploaded file could not be moved to %s.', 'wp-design-maps-and-places'), $error_path);
    }
    // Set correct file permissions
    $stat = stat(dirname($new_file));
    $perms = $stat['mode'] & 0666;
    @chmod($new_file, $perms);
    // Compute the URL
    $url = $uploads['url'] . "/{$filename}";
    // checks the file type and stores in in a variable
    $wp_filetype = wp_check_filetype(basename($new_file), null);
    // set up the array of arguments for "wp_insert_post();"
    $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($new_file)), 'post_content' => '', 'post_author' => $logged_in_user, 'post_status' => 'inherit', 'post_type' => 'attachment', 'guid' => $url);
    // insert the attachment post type and get the ID
    //$attachment_id = wp_insert_post( $attachment );
    $attachment_id = wp_insert_attachment($attachment, $new_file);
    // generate the attachment metadata
    $attach_data = wp_generate_attachment_metadata($attachment_id, $new_file);
    // update the attachment metadata
    wp_update_attachment_metadata($attachment_id, $attach_data);
    return $attachment_id;
}
 public function create_media_attachment()
 {
     $image_name = basename($this->external_url);
     $upload_dir = wp_upload_dir();
     $image_data = $this->get_image_data($this->external_url);
     $unique_file_name = wp_unique_filename($upload_dir['path'], $image_name);
     $filename = basename($unique_file_name);
     // Check folder permission and define file location
     if (wp_mkdir_p($upload_dir['path'])) {
         $file = $upload_dir['path'] . '/' . $filename;
     } else {
         $file = $upload_dir['basedir'] . '/' . $filename;
     }
     // Create the image file on the server
     file_put_contents($file, $image_data);
     $wp_filetype = wp_check_filetype($filename, null);
     // Set attachment data
     $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit');
     // Create the attachment
     $attach_id = wp_insert_attachment($attachment, $file);
     return $attach_id;
 }
 public function save()
 {
     Helpers::debug("Upload::save called");
     if (!(($uploads = wp_upload_dir($this->time)) && false === $uploads['error'])) {
         throw new \Exception($uploads['error']);
     }
     $this->name = $this->getProperName();
     $filename = wp_unique_filename($uploads['path'], $this->name, NULL);
     // Move the file to the uploads dir
     $new_file = $uploads['path'] . "/{$filename}";
     if (false === @move_uploaded_file($this->tmp_name, $new_file)) {
         throw new \Exception(sprintf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
     }
     $this->path = $new_file;
     $this->stat = stat(dirname($new_file));
     $this->perms = $this->stat['mode'] & 0666;
     @chmod($new_file, $this->perms);
     // Compute the URL
     $this->url = $uploads['url'] . "/{$filename}";
     if (is_multisite()) {
         delete_transient('dirsize_cache');
     }
     Helpers::debug("Upload::save finished");
 }
Beispiel #16
0
/**
 * Create a file in the upload folder with given content.
 *
 * If there is an error, then the key 'error' will exist with the error message.
 * If success, then the key 'file' will have the unique file path, the 'url' key
 * will have the link to the new file. and the 'error' key will be set to false.
 *
 * This function will not move an uploaded file to the upload folder. It will
 * create a new file with the content in $bits parameter. If you move the upload
 * file, read the content of the uploaded file, and then you can give the
 * filename and content to this function, which will add it to the upload
 * folder.
 *
 * The permissions will be set on the new file automatically by this function.
 *
 * @since 2.0.0
 *
 * @param string       $name       Filename.
 * @param null|string  $deprecated Never used. Set to null.
 * @param mixed        $bits       File content
 * @param string       $time       Optional. Time formatted in 'yyyy/mm'. Default null.
 * @return array
 */
function wp_upload_bits($name, $deprecated, $bits, $time = null)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.0');
    }
    if (empty($name)) {
        return array('error' => __('Empty filename'));
    }
    $wp_filetype = wp_check_filetype($name);
    if (!$wp_filetype['ext'] && !current_user_can('unfiltered_upload')) {
        return array('error' => __('Invalid file type'));
    }
    $upload = wp_upload_dir($time);
    if ($upload['error'] !== false) {
        return $upload;
    }
    /**
     * Filter whether to treat the upload bits as an error.
     *
     * Passing a non-array to the filter will effectively short-circuit preparing
     * the upload bits, returning that value instead.
     *
     * @since 3.0.0
     *
     * @param mixed $upload_bits_error An array of upload bits data, or a non-array error to return.
     */
    $upload_bits_error = apply_filters('wp_upload_bits', array('name' => $name, 'bits' => $bits, 'time' => $time));
    if (!is_array($upload_bits_error)) {
        $upload['error'] = $upload_bits_error;
        return $upload;
    }
    $filename = wp_unique_filename($upload['path'], $name);
    $new_file = $upload['path'] . "/{$filename}";
    if (!wp_mkdir_p(dirname($new_file))) {
        if (0 === strpos($upload['basedir'], ABSPATH)) {
            $error_path = str_replace(ABSPATH, '', $upload['basedir']) . $upload['subdir'];
        } else {
            $error_path = basename($upload['basedir']) . $upload['subdir'];
        }
        $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $error_path);
        return array('error' => $message);
    }
    $ifp = @fopen($new_file, 'wb');
    if (!$ifp) {
        return array('error' => sprintf(__('Could not write file %s'), $new_file));
    }
    @fwrite($ifp, $bits);
    fclose($ifp);
    clearstatcache();
    // Set correct file permissions
    $stat = @stat(dirname($new_file));
    $perms = $stat['mode'] & 07777;
    $perms = $perms & 0666;
    @chmod($new_file, $perms);
    clearstatcache();
    // Compute the URL
    $url = $upload['url'] . "/{$filename}";
    /** This filter is documented in wp-admin/includes/file.php */
    return apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $wp_filetype['type'], 'error' => false), 'sideload');
}
Beispiel #17
0
function postie_handle_upload(&$file, $overrides = false, $time = null)
{
    // The default error handler.
    if (!function_exists('wp_handle_upload_error')) {
        function wp_handle_upload_error(&$file, $message)
        {
            return array('error' => $message);
        }
    }
    // You may define your own function and pass the name in $overrides['upload_error_handler']
    $upload_error_handler = 'wp_handle_upload_error';
    // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
    $action = 'wp_handle_upload';
    // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
    $upload_error_strings = array(false, __("The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."), __("The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."), __("The uploaded file was only partially uploaded."), __("No file was uploaded."), '', __("Missing a temporary folder."), __("Failed to write file to disk."));
    // Install user overrides. Did we mention that this voids your warranty?
    if (is_array($overrides)) {
        extract($overrides, EXTR_OVERWRITE);
    }
    // A successful upload will pass this test. It makes no sense to override this one.
    if ($file['error'] > 0) {
        return $upload_error_handler($file, $upload_error_strings[$file['error']]);
    }
    // A non-empty file will pass this test.
    if (!($file['size'] > 0)) {
        return $upload_error_handler($file, __('File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini.'));
    }
    // A properly uploaded file will pass this test. There should be no reason to override this one.
    if (!file_exists($file['tmp_name'])) {
        return $upload_error_handler($file, __('Specified file failed upload test.'));
    }
    // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
    $wp_filetype = wp_check_filetype($file['name']);
    DebugEcho("postie_handle_upload: detected file type for " . $file['name'] . " is " . $wp_filetype['type']);
    extract($wp_filetype);
    if ((!$type || !$ext) && !current_user_can('unfiltered_upload')) {
        return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.'));
    }
    if (!$ext) {
        $ext = ltrim(strrchr($file['name'], '.'), '.');
    }
    if (!$type) {
        $type = $file['type'];
    }
    // A writable uploads dir will pass this test. Again, there's no point overriding this one.
    if (!(($uploads = wp_upload_dir($time)) && false === $uploads['error'])) {
        return $upload_error_handler($file, $uploads['error']);
    }
    // fix filename (encode non-standard characters)
    $file['name'] = filename_fix($file['name']);
    $filename = wp_unique_filename($uploads['path'], $file['name']);
    DebugEcho("wp_unique_filename: {$filename}");
    // Move the file to the uploads dir
    $new_file = $uploads['path'] . "/{$filename}";
    if (false === @rename($file['tmp_name'], $new_file)) {
        DebugEcho("upload: rename failed");
        DebugEcho("new file: {$new_file}");
        //DebugDump($file);
        //DebugDump($uploads);
        return $upload_error_handler($file, sprintf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
    }
    // Set correct file permissions
    $stat = stat(dirname($new_file));
    $perms = $stat['mode'] & 0666;
    @chmod($new_file, $perms);
    // Compute the URL
    $url = $uploads['url'] . "/{$filename}";
    $return = apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type));
    return $return;
}
 private static function copy_post_image($url, $post_id)
 {
     $time = current_time('mysql');
     if ($post = get_post($post_id)) {
         if (substr($post->post_date, 0, 4) > 0) {
             $time = $post->post_date;
         }
     }
     //making sure there is a valid upload folder
     if (!(($uploads = wp_upload_dir($time)) && false === $uploads['error'])) {
         return false;
     }
     $name = basename($url);
     $filename = wp_unique_filename($uploads['path'], $name);
     // Move the file to the uploads dir
     $new_file = $uploads['path'] . "/{$filename}";
     $uploaddir = wp_upload_dir();
     $path = str_replace($uploaddir['baseurl'], $uploaddir['basedir'], $url);
     if (!copy($path, $new_file)) {
         return false;
     }
     // Set correct file permissions
     $stat = stat(dirname($new_file));
     $perms = $stat['mode'] & 0666;
     @chmod($new_file, $perms);
     // Compute the URL
     $url = $uploads['url'] . "/{$filename}";
     if (is_multisite()) {
         delete_transient('dirsize_cache');
     }
     $type = wp_check_filetype($new_file);
     return array('file' => $new_file, 'url' => $url, 'type' => $type['type']);
 }
 /**
  * Send an HTTP request to a URI.
  *
  * Please note: The only URI that are supported in the HTTP Transport implementation
  * are the HTTP and HTTPS protocols.
  *
  * @access public
  * @since 2.7.0
  *
  * @global string $wp_version
  *
  * @param string       $url  The request URL.
  * @param string|array $args {
  *     Optional. Array or string of HTTP request arguments.
  *
  *     @type string       $method              Request method. Accepts 'GET', 'POST', 'HEAD', or 'PUT'.
  *                                             Some transports technically allow others, but should not be
  *                                             assumed. Default 'GET'.
  *     @type int          $timeout             How long the connection should stay open in seconds. Default 5.
  *     @type int          $redirection         Number of allowed redirects. Not supported by all transports
  *                                             Default 5.
  *     @type string       $httpversion         Version of the HTTP protocol to use. Accepts '1.0' and '1.1'.
  *                                             Default '1.0'.
  *     @type string       $user-agent          User-agent value sent.
  *                                             Default WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ).
  *     @type bool         $reject_unsafe_urls  Whether to pass URLs through {@see wp_http_validate_url()}.
  *                                             Default false.
  *     @type bool         $blocking            Whether the calling code requires the result of the request.
  *                                             If set to false, the request will be sent to the remote server,
  *                                             and processing returned to the calling code immediately, the caller
  *                                             will know if the request succeeded or failed, but will not receive
  *                                             any response from the remote server. Default true.
  *     @type string|array $headers             Array or string of headers to send with the request.
  *                                             Default empty array.
  *     @type array        $cookies             List of cookies to send with the request. Default empty array.
  *     @type string|array $body                Body to send with the request. Default null.
  *     @type bool         $compress            Whether to compress the $body when sending the request.
  *                                             Default false.
  *     @type bool         $decompress          Whether to decompress a compressed response. If set to false and
  *                                             compressed content is returned in the response anyway, it will
  *                                             need to be separately decompressed. Default true.
  *     @type bool         $sslverify           Whether to verify SSL for the request. Default true.
  *     @type string       sslcertificates      Absolute path to an SSL certificate .crt file.
  *                                             Default ABSPATH . WPINC . '/certificates/ca-bundle.crt'.
  *     @type bool         $stream              Whether to stream to a file. If set to true and no filename was
  *                                             given, it will be droped it in the WP temp dir and its name will
  *                                             be set using the basename of the URL. Default false.
  *     @type string       $filename            Filename of the file to write to when streaming. $stream must be
  *                                             set to true. Default null.
  *     @type int          $limit_response_size Size in bytes to limit the response to. Default null.
  *
  * }
  * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
  *                        A WP_Error instance upon error.
  */
 public function request($url, $args = array())
 {
     global $wp_version;
     $defaults = array('method' => 'GET', 'timeout' => apply_filters('http_request_timeout', 5), 'redirection' => apply_filters('http_request_redirection_count', 5), 'httpversion' => apply_filters('http_request_version', '1.0'), 'user-agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')), 'reject_unsafe_urls' => apply_filters('http_request_reject_unsafe_urls', false), 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true, 'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt', 'stream' => false, 'filename' => null, 'limit_response_size' => null);
     // Pre-parse for the HEAD checks.
     $args = wp_parse_args($args);
     // By default, Head requests do not cause redirections.
     if (isset($args['method']) && 'HEAD' == $args['method']) {
         $defaults['redirection'] = 0;
     }
     $r = wp_parse_args($args, $defaults);
     /**
      * Filter the arguments used in an HTTP request.
      *
      * @since 2.7.0
      *
      * @param array  $r   An array of HTTP request arguments.
      * @param string $url The request URL.
      */
     $r = apply_filters('http_request_args', $r, $url);
     // The transports decrement this, store a copy of the original value for loop purposes.
     if (!isset($r['_redirection'])) {
         $r['_redirection'] = $r['redirection'];
     }
     /**
      * Filter whether to preempt an HTTP request's return value.
      *
      * Returning a non-false value from the filter will short-circuit the HTTP request and return
      * early with that value. A filter should return either:
      *
      *  - An array containing 'headers', 'body', 'response', 'cookies', and 'filename' elements
      *  - A WP_Error instance
      *  - boolean false (to avoid short-circuiting the response)
      *
      * Returning any other value may result in unexpected behaviour.
      *
      * @since 2.9.0
      *
      * @param false|array|WP_Error $preempt Whether to preempt an HTTP request's return value. Default false.
      * @param array               $r        HTTP request arguments.
      * @param string              $url      The request URL.
      */
     $pre = apply_filters('pre_http_request', false, $r, $url);
     if (false !== $pre) {
         return $pre;
     }
     if (function_exists('wp_kses_bad_protocol')) {
         if ($r['reject_unsafe_urls']) {
             $url = wp_http_validate_url($url);
         }
         if ($url) {
             $url = wp_kses_bad_protocol($url, array('http', 'https', 'ssl'));
         }
     }
     $arrURL = @parse_url($url);
     if (empty($url) || empty($arrURL['scheme'])) {
         return new WP_Error('http_request_failed', __('A valid URL was not provided.'));
     }
     if ($this->block_request($url)) {
         return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
     }
     /*
      * Determine if this is a https call and pass that on to the transport functions
      * so that we can blacklist the transports that do not support ssl verification
      */
     $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
     // Determine if this request is to OUR install of WordPress.
     $homeURL = parse_url(get_bloginfo('url'));
     $r['local'] = 'localhost' == $arrURL['host'] || isset($homeURL['host']) && $homeURL['host'] == $arrURL['host'];
     unset($homeURL);
     /*
      * If we are streaming to a file but no filename was given drop it in the WP temp dir
      * and pick its name using the basename of the $url.
      */
     if ($r['stream'] && empty($r['filename'])) {
         $r['filename'] = get_temp_dir() . wp_unique_filename(get_temp_dir(), basename($url));
     }
     /*
      * Force some settings if we are streaming to a file and check for existence and perms
      * of destination directory.
      */
     if ($r['stream']) {
         $r['blocking'] = true;
         if (!wp_is_writable(dirname($r['filename']))) {
             return new WP_Error('http_request_failed', __('Destination directory for file streaming does not exist or is not writable.'));
         }
     }
     if (is_null($r['headers'])) {
         $r['headers'] = array();
     }
     if (!is_array($r['headers'])) {
         $processedHeaders = self::processHeaders($r['headers'], $url);
         $r['headers'] = $processedHeaders['headers'];
     }
     if (isset($r['headers']['User-Agent'])) {
         $r['user-agent'] = $r['headers']['User-Agent'];
         unset($r['headers']['User-Agent']);
     }
     if (isset($r['headers']['user-agent'])) {
         $r['user-agent'] = $r['headers']['user-agent'];
         unset($r['headers']['user-agent']);
     }
     if ('1.1' == $r['httpversion'] && !isset($r['headers']['connection'])) {
         $r['headers']['connection'] = 'close';
     }
     // Construct Cookie: header if any cookies are set.
     self::buildCookieHeader($r);
     // Avoid issues where mbstring.func_overload is enabled.
     mbstring_binary_safe_encoding();
     if (!isset($r['headers']['Accept-Encoding'])) {
         if ($encoding = WP_Http_Encoding::accept_encoding($url, $r)) {
             $r['headers']['Accept-Encoding'] = $encoding;
         }
     }
     if (!is_null($r['body']) && '' != $r['body'] || 'POST' == $r['method'] || 'PUT' == $r['method']) {
         if (is_array($r['body']) || is_object($r['body'])) {
             $r['body'] = http_build_query($r['body'], null, '&');
             if (!isset($r['headers']['Content-Type'])) {
                 $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
             }
         }
         if ('' === $r['body']) {
             $r['body'] = null;
         }
         if (!isset($r['headers']['Content-Length']) && !isset($r['headers']['content-length'])) {
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
     }
     $response = $this->_dispatch_request($url, $r);
     reset_mbstring_encoding();
     if (is_wp_error($response)) {
         return $response;
     }
     // Append cookies that were used in this request to the response
     if (!empty($r['cookies'])) {
         $cookies_set = wp_list_pluck($response['cookies'], 'name');
         foreach ($r['cookies'] as $cookie) {
             if (!in_array($cookie->name, $cookies_set) && $cookie->test($url)) {
                 $response['cookies'][] = $cookie;
             }
         }
     }
     return $response;
 }
 function __construct($form, $urlholder)
 {
     if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
         wp_die($uploads['error']);
     }
     if (empty($_FILES[$form]['name']) && empty($_GET[$urlholder])) {
         wp_die(__('Please select a file'));
     }
     if (!empty($_FILES)) {
         $this->filename = $_FILES[$form]['name'];
     } else {
         if (isset($_GET[$urlholder])) {
             $this->filename = $_GET[$urlholder];
         }
     }
     //Handle a newly uploaded file, Else assume its already been uploaded
     if (!empty($_FILES)) {
         $this->filename = wp_unique_filename($uploads['basedir'], $this->filename);
         $this->package = $uploads['basedir'] . '/' . $this->filename;
         // Move the file to the uploads dir
         if (false === @move_uploaded_file($_FILES[$form]['tmp_name'], $this->package)) {
             wp_die(sprintf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
         }
     } else {
         $this->package = $uploads['basedir'] . '/' . $this->filename;
     }
 }
     // Drop-in replace and we don't even care if you uploaded something that is the wrong file-type.
     // That's your own fault, because we warned you!
     emr_delete_current_files($current_file);
     // Move new file to old location/name
     move_uploaded_file($_FILES["userfile"]["tmp_name"], $current_file);
     // Chmod new file to original file permissions
     @chmod($current_file, $original_file_perms);
     // Make thumb and/or update metadata
     wp_update_attachment_metadata((int) $_POST["ID"], wp_generate_attachment_metadata((int) $_POST["ID"], $current_file));
     // Trigger possible updates on CDN and other plugins
     update_attached_file((int) $_POST["ID"], $current_file);
 } elseif ('replace_and_search' == $replace_type && apply_filters('emr_enable_replace_and_search', true)) {
     // Replace file, replace file name, update meta data, replace links pointing to old file name
     emr_delete_current_files($current_file);
     // Massage new filename to adhere to WordPress standards
     $new_filename = wp_unique_filename($current_path, $new_filename);
     // Move new file to old location, new name
     $new_file = $current_path . "/" . $new_filename;
     move_uploaded_file($_FILES["userfile"]["tmp_name"], $new_file);
     // Chmod new file to original file permissions
     @chmod($current_file, $original_file_perms);
     $new_filetitle = preg_replace('/\\.[^.]+$/', '', basename($new_file));
     $new_filetitle = apply_filters('enable_media_replace_title', $new_filetitle);
     // Thanks Jonas Lundman (http://wordpress.org/support/topic/add-filter-hook-suggestion-to)
     $new_guid = str_replace($current_filename, $new_filename, $current_guid);
     // Update database file name
     $sql = $wpdb->prepare("UPDATE {$table_name} SET post_title = '{$new_filetitle}', post_name = '{$new_filetitle}', guid = '{$new_guid}', post_mime_type = '{$new_filetype}' WHERE ID = %d;", (int) $_POST["ID"]);
     $wpdb->query($sql);
     // Update the postmeta file name
     // Get old postmeta _wp_attached_file
     $sql = $wpdb->prepare("SELECT meta_value FROM {$postmeta_table_name} WHERE meta_key = '_wp_attached_file' AND post_id = %d;", (int) $_POST["ID"]);
Beispiel #22
0
 public static function upload_image($pid, $img_url, $download_images, $logger, $create_image = false, $image_name = "", $file_type = 'images')
 {
     if (empty($img_url)) {
         return false;
     }
     $url = str_replace(" ", "%20", trim($img_url));
     $bn = wp_all_import_sanitize_filename(basename($url));
     if ($image_name == "") {
         $img_ext = pmxi_getExtensionFromStr($url);
         $default_extension = pmxi_getExtension($bn);
         if ($img_ext == "") {
             $img_ext = pmxi_get_remote_image_ext($url);
         }
         // generate local file name
         $image_name = apply_filters("wp_all_import_image_filename", urldecode(sanitize_file_name($img_ext ? str_replace("." . $default_extension, "", $bn) : $bn)) . ("" != $img_ext ? '.' . $img_ext : ''));
     }
     $uploads = wp_upload_dir();
     $targetDir = $uploads['path'];
     $targetUrl = $uploads['url'];
     $download_image = true;
     $result = false;
     $wp_filetype = false;
     global $wpdb;
     $attch = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_mime_type LIKE %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", "image%"));
     if ($attch != null) {
         return $attch->ID;
     }
     $image_filename = wp_unique_filename($targetDir, $image_name);
     $image_filepath = $targetDir . '/' . $image_filename;
     // do not download images
     if ("yes" != $download_images) {
         $image_filename = $image_name;
         $image_filepath = $targetDir . '/' . $image_filename;
         $wpai_uploads = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR;
         $wpai_image_path = $wpai_uploads . str_replace('%20', ' ', $url);
         $logger and call_user_func($logger, sprintf(__('- Searching for existing image `%s` in `%s` folder', 'wp_all_import_plugin'), $wpai_image_path, $wpai_uploads));
         if (@file_exists($wpai_image_path) and @copy($wpai_image_path, $image_filepath)) {
             $download_image = false;
             // valdate import attachments
             if ($file_type == 'files') {
                 if (!($wp_filetype = wp_check_filetype(basename($image_filepath), null))) {
                     $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($image_filepath)));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     @unlink($image_filepath);
                 } else {
                     $result = true;
                     $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully found', 'wp_all_import_plugin'), $wpai_image_path));
                 }
             } elseif ($file_type == 'images') {
                 if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                     $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $image_filepath));
                     @unlink($image_filepath);
                 } else {
                     $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully found', 'wp_all_import_plugin'), $wpai_image_path));
                     $result = true;
                 }
             }
         }
     }
     if ($download_image) {
         if ($file_type == 'images') {
             $logger and call_user_func($logger, sprintf(__('- Downloading image from `%s`', 'wp_all_import_plugin'), $url));
         } elseif ($file_type == 'files') {
             $logger and call_user_func($logger, sprintf(__('- Downloading file from `%s`', 'wp_all_import_plugin'), $url));
         }
         $request = get_file_curl($url, $image_filepath);
         if ((is_wp_error($request) or $request === false) and !@file_put_contents($image_filepath, @file_get_contents($url))) {
             @unlink($image_filepath);
             // delete file since failed upload may result in empty file created
         } else {
             if ($file_type == 'images') {
                 if ($image_info = @getimagesize($image_filepath) and in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                     $result = true;
                     $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                 }
             } elseif ($file_type == 'files') {
                 if ($wp_filetype = wp_check_filetype(basename($image_filepath), null)) {
                     $result = true;
                     $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                 }
             }
         }
         if (!$result) {
             $url = str_replace(" ", "%20", trim(pmxi_convert_encoding($img_url)));
             $request = get_file_curl($url, $image_filepath);
             if ((is_wp_error($request) or $request === false) and !@file_put_contents($image_filepath, @file_get_contents($url))) {
                 $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s cannot be saved locally as %s', 'wp_all_import_plugin'), $url, $image_filepath));
                 @unlink($image_filepath);
                 // delete file since failed upload may result in empty file created
             } else {
                 if ($file_type == 'images') {
                     if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                         $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $url));
                         @unlink($image_filepath);
                     } else {
                         $result = true;
                         $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                     }
                 } elseif ($file_type == 'files') {
                     if (!($wp_filetype = wp_check_filetype(basename($image_filepath), null))) {
                         $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($url)));
                         @unlink($image_filepath);
                     } else {
                         $result = true;
                         $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully found', 'wp_all_import_plugin'), $url));
                     }
                 }
             }
         }
     }
     if ($create_image and $result) {
         if ($file_type == 'images') {
             $logger and call_user_func($logger, sprintf(__('- Creating an attachment for image `%s`', 'wp_all_import_plugin'), $targetUrl . '/' . $image_filename));
         } else {
             $logger and call_user_func($logger, sprintf(__('- Creating an attachment for file `%s`', 'wp_all_import_plugin'), $targetUrl . '/' . $image_filename));
         }
         $attachment = array('post_mime_type' => $file_type == 'images' ? image_type_to_mime_type($image_info[2]) : $wp_filetype['type'], 'guid' => $targetUrl . '/' . $image_filename, 'post_title' => $image_filename, 'post_content' => '');
         if ($file_type == 'images' and $image_meta = wp_read_image_metadata($image_filepath)) {
             if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
                 $attachment['post_title'] = $image_meta['title'];
             }
             if (trim($image_meta['caption'])) {
                 $attachment['post_content'] = $image_meta['caption'];
             }
         }
         $attid = wp_insert_attachment($attachment, $image_filepath, $pid);
         if (is_wp_error($attid)) {
             $logger and call_user_func($logger, __('- <b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $attid->get_error_message());
             return false;
         } else {
             // you must first include the image.php file
             // for the function wp_generate_attachment_metadata() to work
             require_once ABSPATH . 'wp-admin/includes/image.php';
             wp_update_attachment_metadata($attid, wp_generate_attachment_metadata($attid, $image_filepath));
             $logger and call_user_func($logger, sprintf(__('- Attachment has been successfully created for image `%s`', 'wp_all_import_plugin'), $targetUrl . '/' . $image_filename));
             return $attid;
         }
     } else {
         return $result;
     }
 }
/**
 * {@internal Missing Short Description}}
 *
 * Pass this function an array similar to that of a $_FILES POST array.
 *
 * @since unknown
 *
 * @param unknown_type $file
 * @param unknown_type $overrides
 * @return unknown
 */
function wp_handle_sideload(&$file, $overrides = false)
{
    // The default error handler.
    if (!function_exists('wp_handle_upload_error')) {
        function wp_handle_upload_error(&$file, $message)
        {
            return array('error' => $message);
        }
    }
    // You may define your own function and pass the name in $overrides['upload_error_handler']
    $upload_error_handler = 'wp_handle_upload_error';
    // You may define your own function and pass the name in $overrides['unique_filename_callback']
    $unique_filename_callback = null;
    // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
    $action = 'wp_handle_sideload';
    // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
    $upload_error_strings = array(false, __("The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."), __("The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."), __("The uploaded file was only partially uploaded."), __("No file was uploaded."), '', __("Missing a temporary folder."), __("Failed to write file to disk."), __("File upload stopped by extension."));
    // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
    $test_form = true;
    $test_size = true;
    // If you override this, you must provide $ext and $type!!!!
    $test_type = true;
    $mimes = false;
    // Install user overrides. Did we mention that this voids your warranty?
    if (is_array($overrides)) {
        extract($overrides, EXTR_OVERWRITE);
    }
    // A correct form post will pass this test.
    if ($test_form && (!isset($_POST['action']) || $_POST['action'] != $action)) {
        return $upload_error_handler($file, __('Invalid form submission.'));
    }
    // A successful upload will pass this test. It makes no sense to override this one.
    if ($file['error'] > 0) {
        return $upload_error_handler($file, $upload_error_strings[$file['error']]);
    }
    // A non-empty file will pass this test.
    if ($test_size && !(filesize($file['tmp_name']) > 0)) {
        return $upload_error_handler($file, __('File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini.'));
    }
    // A properly uploaded file will pass this test. There should be no reason to override this one.
    if (!@is_file($file['tmp_name'])) {
        return $upload_error_handler($file, __('Specified file does not exist.'));
    }
    // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
    if ($test_type) {
        $wp_filetype = wp_check_filetype($file['name'], $mimes);
        extract($wp_filetype);
        if ((!$type || !$ext) && !current_user_can('unfiltered_upload')) {
            return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.'));
        }
        if (!$ext) {
            $ext = ltrim(strrchr($file['name'], '.'), '.');
        }
        if (!$type) {
            $type = $file['type'];
        }
    }
    // A writable uploads dir will pass this test. Again, there's no point overriding this one.
    if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
        return $upload_error_handler($file, $uploads['error']);
    }
    $filename = wp_unique_filename($uploads['path'], $file['name'], $unique_filename_callback);
    // Strip the query strings.
    $filename = str_replace('?', '-', $filename);
    $filename = str_replace('&', '-', $filename);
    // Move the file to the uploads dir
    $new_file = $uploads['path'] . "/{$filename}";
    if (false === @rename($file['tmp_name'], $new_file)) {
        return $upload_error_handler($file, sprintf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
    }
    // Set correct file permissions
    $stat = stat(dirname($new_file));
    $perms = $stat['mode'] & 0666;
    @chmod($new_file, $perms);
    // Compute the URL
    $url = $uploads['url'] . "/{$filename}";
    $return = apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type));
    return $return;
}
Beispiel #24
0
function synved_option_wp_upgrader_pre_install($perform, $extra)
{
    if (!isset($extra['plugin'])) {
        return $perform;
    }
    $upgrade_transfer = get_option('synved_option_wp_upgrade_addon_transfer');
    if ($upgrade_transfer != null) {
        $upgrade_transfer_time = get_option('synved_option_wp_upgrade_addon_transfer_time');
        if ($upgrade_transfer_time == null || time() - $upgrade_transfer_time > 60 * 60 * 1) {
            $upgrade_transfer = null;
            update_option('synved_option_wp_upgrade_addon_transfer', '');
        }
    }
    $module_list = array();
    if (function_exists('synved_plugout_get_module_list')) {
        $module_list = synved_plugout_get_module_list();
    } else {
        global $synved_plugout;
        $module_list = array_keys($synved_plugout['module-list']);
    }
    $plugins_dir = WP_PLUGIN_DIR;
    $plugins_dir = rtrim(str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, realpath($plugins_dir)), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    $plugin = $extra['plugin'];
    $plugin_dir = rtrim(str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, realpath(dirname($plugins_dir . $plugin))), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    $dir = get_temp_dir();
    $name = time();
    $dir = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . wp_unique_filename($dir, $name) . DIRECTORY_SEPARATOR;
    $list = array();
    foreach ($module_list as $module_id) {
        $addon_list = synved_plugout_module_addon_list($module_id);
        if ($addon_list != null) {
            foreach ($addon_list as $addon_name => $addon_file) {
                if (file_exists($addon_file)) {
                    $addon_dir = dirname($addon_file);
                    $parent_dir = dirname($addon_dir);
                    // clean names for comparison
                    $addon_dir = rtrim(str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, realpath($addon_dir)), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
                    $parent_dir = rtrim(str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, realpath($parent_dir)), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
                    if (strtolower($parent_dir) != strtolower($plugins_dir) && strpos(strtolower($addon_dir), strtolower($plugin_dir)) !== false) {
                        $path = $dir;
                        $diff = substr($addon_dir, strlen($plugins_dir));
                        $path .= $diff;
                        wp_mkdir_p($path);
                        copy_dir($addon_dir, $path);
                        $list[] = array('original' => $addon_dir, 'temporary' => $path);
                    }
                }
            }
        }
    }
    if ($list != null) {
        update_option('synved_option_wp_upgrade_addon_transfer', array('directory' => $dir, 'list' => $list));
        update_option('synved_option_wp_upgrade_addon_transfer_time', time());
    }
    return $perform;
}
Beispiel #25
0
 function handle_import_media_file($file, $post_id = 0)
 {
     // see if the attachment already exists
     $id = array_search($file, $this->filearr);
     if ($id === false) {
         set_time_limit(120);
         $post = get_post($post_id);
         $time = $post->post_date_gmt;
         // A writable uploads dir will pass this test. Again, there's no point overriding this one.
         if (!(($uploads = wp_upload_dir($time)) && false === $uploads['error'])) {
             return new WP_Error('upload_error', $uploads['error']);
         }
         // this security check is pointless. It gives false positives, and anyone running this importer can unfiltered_upload anyway.
         /*
         			$wp_filetype = wp_check_filetype( $file, null );
         
         			extract( $wp_filetype );
         	
         			if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
         				return new WP_Error( 'wrong_file_type', __( 'Sorry, this file type is not permitted for security reasons.' ) );
         /**/
         $filename = wp_unique_filename($uploads['path'], basename($file));
         // copy the file to the uploads dir
         $new_file = $uploads['path'] . '/' . $filename;
         if (false === @copy($file, $new_file)) {
             return new WP_Error('upload_error', sprintf(__('Could not find the right path to %s ( tried %s ). It could not be imported. Please upload it manually.', 'html-import-pages'), basename($file), $file));
         }
         //	else
         //	 	printf( __( '<br /><em>%s</em> is being copied to the uploads directory as <em>%s</em>.', 'html-import-pages' ), $file, $new_file );
         // Set correct file permissions
         $stat = stat(dirname($new_file));
         $perms = $stat['mode'] & 0666;
         @chmod($new_file, $perms);
         // Compute the URL
         $url = $uploads['url'] . '/' . $filename;
         //Apply upload filters
         $return = apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => wp_check_filetype($file, null)));
         $new_file = $return['file'];
         $url = $return['url'];
         $type = $return['type'];
         $title = preg_replace('!\\.[^.]+$!', '', basename($file));
         $content = '';
         // use image exif/iptc data for title and caption defaults if possible
         if ($image_meta = @wp_read_image_metadata($new_file)) {
             if ('' != trim($image_meta['title'])) {
                 $title = trim($image_meta['title']);
             }
             if ('' != trim($image_meta['caption'])) {
                 $content = trim($image_meta['caption']);
             }
         }
         if ($time) {
             $post_date_gmt = $time;
             $post_date = $time;
         } else {
             $post_date = current_time('mysql');
             $post_date_gmt = current_time('mysql', 1);
         }
         // Construct the attachment array
         $wp_filetype = wp_check_filetype(basename($filename), null);
         $attachment = array('post_mime_type' => $wp_filetype['type'], 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_name' => $title, 'post_content' => $content, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt);
         //Win32 fix:
         $new_file = str_replace(strtolower(str_replace('\\', '/', $uploads['basedir'])), $uploads['basedir'], $new_file);
         // Insert attachment
         $id = wp_insert_attachment($attachment, $new_file, $post_id);
         if (!is_wp_error($id)) {
             $data = wp_generate_attachment_metadata($id, $new_file);
             wp_update_attachment_metadata($id, $data);
             $this->filearr[$id] = $file;
             // $file contains the original, absolute path to the file
         }
     }
     // if attachment already exists
     return $id;
 }
function fcb_wp_upload_bits($name, $deprecated, $bits, $time = null)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.0');
    }
    if (empty($name)) {
        return array('error' => __('Empty filename'));
    }
    $wp_filetype = wp_check_filetype($name);
    if (!$wp_filetype['ext'] && !current_user_can('unfiltered_upload')) {
        return array('error' => __('Invalid file type'));
    }
    $upload = wp_upload_dir($time);
    $upload['path'] = $upload['basedir'] . '/formcraft_basic';
    $upload['url'] = $upload['baseurl'] . '/formcraft_basic';
    $upload['subdir'] = '/formcraft_basic';
    if ($upload['error'] !== false) {
        return $upload;
    }
    $upload_bits_error = apply_filters('wp_upload_bits', array('name' => $name, 'bits' => $bits, 'time' => $time));
    if (!is_array($upload_bits_error)) {
        $upload['error'] = $upload_bits_error;
        return $upload;
    }
    $filename = wp_unique_filename($upload['path'], $name);
    $new_file = $upload['path'] . "/{$filename}";
    if (!wp_mkdir_p(dirname($new_file))) {
        if (0 === strpos($upload['basedir'], ABSPATH)) {
            $error_path = str_replace(ABSPATH, '', $upload['basedir']) . $upload['subdir'];
        } else {
            $error_path = basename($upload['basedir']) . $upload['subdir'];
        }
        $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $error_path);
        return array('error' => $message);
    }
    $ifp = @fopen($new_file, 'wb');
    if (!$ifp) {
        return array('error' => sprintf(__('Could not write file %s'), $new_file));
    }
    @fwrite($ifp, $bits);
    fclose($ifp);
    clearstatcache();
    $stat = @stat(dirname($new_file));
    $perms = $stat['mode'] & 07777;
    $perms = $perms & 0666;
    @chmod($new_file, $perms);
    clearstatcache();
    $url = $upload['url'] . "/{$filename}";
    return array('file' => $new_file, 'url' => $url, 'name' => $filename, 'error' => false);
}
 /**
  * @param int     $post_id
  * @param WP_Post $post
  * @return void
  */
 public function save($post_id, WP_Post $post)
 {
     if (!$this->request_validator->is_valid($post)) {
         return;
     }
     $post_type = $this->get_real_post_type($post);
     $post_id = $this->get_real_post_id($post_id);
     if (!in_array($post_type, $this->allowed_post_types)) {
         return;
     }
     if (empty($this->post_request_data['mlp_to_translate'])) {
         return;
     }
     $to_translate = $this->post_request_data['mlp_to_translate'];
     $this->save_context = array('source_blog' => get_current_blog_id(), 'source_post' => $post, 'real_post_type' => $post_type, 'real_post_id' => $post_id);
     // Get the post
     $post_data = get_post($post_id, ARRAY_A);
     $post_meta = $this->get_post_meta_to_transfer($post_id);
     /**
      * Pre-Filter before Saving the Post
      * @param   Array $post_data
      * @param   Array $save_context
      */
     $post_data = apply_filters('mlp_pre_save_post', $post_data, $this->save_context);
     // When the filter returns FALSE, we'll stop here
     if (FALSE == $post_data || !is_array($post_data)) {
         return;
     }
     $file = $path = '';
     $fileinfo = array();
     // Check for thumbnail
     if (current_theme_supports('post-thumbnails')) {
         $thumb_id = get_post_thumbnail_id($post_id);
         if (0 < $thumb_id) {
             $path = wp_upload_dir();
             $file = get_post_meta($thumb_id, '_wp_attached_file', TRUE);
             $fileinfo = pathinfo($file);
             include_once ABSPATH . 'wp-admin/includes/image.php';
             //including the attachment function
         }
     }
     // Create the post array
     $new_post = array('post_title' => $post_data['post_title'], 'post_content' => $post_data['post_content'], 'post_status' => 'draft', 'post_author' => $post_data['post_author'], 'post_excerpt' => $post_data['post_excerpt'], 'post_date' => $post_data['post_date'], 'post_type' => $post_data['post_type']);
     $this->find_post_parents($post_data['post_type'], $post->post_parent);
     /**
      * Run before the first save_post action is called in other blogs.
      *
      * @param Array $save_context
      */
     do_action('mlp_before_post_synchronization', $this->save_context);
     // Create a copy of the item for every related blog
     foreach ($to_translate as $blog_id) {
         if ($blog_id == get_current_blog_id() or !blog_exists($blog_id)) {
             continue;
         }
         switch_to_blog($blog_id);
         // Set the linked parent post
         $new_post['post_parent'] = $this->get_post_parent($blog_id);
         $this->save_context['target_blog_id'] = $blog_id;
         /**
          * Filter post data before it is saved to the database.
          *
          * @param array $new_post
          * @param array $context
          */
         $new_post = apply_filters('mlp_pre_insert_post', $new_post, $this->save_context);
         // Insert remote blog post
         $remote_post_id = wp_insert_post($new_post);
         //echo $remote_post_id . '<br>';
         if (!empty($post_meta)) {
             $this->update_remote_post_meta($remote_post_id, $post_meta);
         }
         if ('' != $file) {
             // thumbfile exists
             if (0 < count($fileinfo)) {
                 $filedir = wp_upload_dir();
                 $filename = wp_unique_filename($filedir['path'], $fileinfo['basename']);
                 $copy = copy($path['basedir'] . '/' . $file, $filedir['path'] . '/' . $filename);
                 if ($copy) {
                     $wp_filetype = wp_check_filetype($filedir['url'] . '/' . $filename);
                     //get the file type
                     $attachment = array('post_mime_type' => $wp_filetype['type'], 'guid' => $filedir['url'] . '/' . $filename, 'post_parent' => $remote_post_id, 'post_title' => '', 'post_excerpt' => '', 'post_author' => $post_data['post_author'], 'post_content' => '');
                     //insert the image
                     $attach_id = wp_insert_attachment($attachment, $filedir['path'] . '/' . $filename);
                     if (!is_wp_error($attach_id)) {
                         wp_update_attachment_metadata($attach_id, wp_generate_attachment_metadata($attach_id, $filedir['path'] . '/' . $filename));
                         set_post_thumbnail($remote_post_id, $attach_id);
                     }
                     // update the image data
                 }
             }
         }
         $this->set_linked_element($post_id, $blog_id, $remote_post_id);
         restore_current_blog();
     }
     /**
      * Run after all save_post actions are called in other blogs.
      *
      * @param Array $save_context
      */
     do_action('mlp_after_post_synchronization', $this->save_context);
 }
function lpr_import_handle_upload($file, $overrides = array())
{
    // The default error handler.
    if (!function_exists('lpr_handle_upload_error')) {
        function lpr_handle_upload_error($file, $message)
        {
            return array('error' => $message);
        }
    }
    $action = 'lpr_import_handle_upload';
    /**
     * The dynamic portion of the hook name, $action, refers to the post action.
     *
     * @since 2.9.0 as 'wp_handle_upload_prefilter'
     * @since 4.0.0 Converted to a dynamic hook with $action
     *
     * @param array $file An array of data for a single file.
     */
    $file = apply_filters("lpr_import_handle_upload_prefilter", $file);
    // You may define your own function and pass the name in $overrides['upload_error_handler']
    $upload_error_handler = 'lpr_handle_upload_error';
    if (isset($overrides['upload_error_handler'])) {
        $upload_error_handler = $overrides['upload_error_handler'];
    }
    // You may have had one or more 'wp_handle_upload_prefilter' functions error out the file. Handle that gracefully.
    if (isset($file['error']) && !is_numeric($file['error']) && $file['error']) {
        return $upload_error_handler($file, $file['error']);
    }
    // Install user overrides. Did we mention that this voids your warranty?
    // You may define your own function and pass the name in $overrides['unique_filename_callback']
    $unique_filename_callback = null;
    if (isset($overrides['unique_filename_callback'])) {
        $unique_filename_callback = $overrides['unique_filename_callback'];
    }
    /*
     * This may not have orignially been intended to be overrideable,
     * but historically has been.
     */
    if (isset($overrides['upload_error_strings'])) {
        $upload_error_strings = $overrides['upload_error_strings'];
    } else {
        // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
        $upload_error_strings = array(false, __('The uploaded file exceeds the upload_max_filesize directive in php.ini.'), __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'), __('The uploaded file was only partially uploaded.'), __('No file was uploaded.'), '', __('Missing a temporary folder.'), __('Failed to write file to disk.'), __('File upload stopped by extension.'));
    }
    // All tests are on by default. Most can be turned off by $overrides[{test_name}] = false;
    $test_form = isset($overrides['test_form']) ? $overrides['test_form'] : true;
    $test_size = isset($overrides['test_size']) ? $overrides['test_size'] : true;
    // If you override this, you must provide $ext and $type!!
    $test_type = isset($overrides['test_type']) ? $overrides['test_type'] : true;
    $mimes = isset($overrides['mimes']) ? $overrides['mimes'] : false;
    $test_upload = isset($overrides['test_upload']) ? $overrides['test_upload'] : true;
    // A correct form post will pass this test.
    /*if ( $test_form && ( ! isset( $_POST['action'] ) || ( $_POST['action'] != $action ) ) ) {
    		return call_user_func( $upload_error_handler, $file, __( 'Invalid form submission.' ) );
    	}*/
    // A successful upload will pass this test. It makes no sense to override this one.
    if (isset($file['error']) && $file['error'] > 0) {
        return call_user_func($upload_error_handler, $file, $upload_error_strings[$file['error']]);
    }
    $test_file_size = 'wp_handle_upload' === $action ? $file['size'] : filesize($file['tmp_name']);
    // A non-empty file will pass this test.
    if ($test_size && !($test_file_size > 0)) {
        if (is_multisite()) {
            $error_msg = __('File is empty. Please upload something more substantial.');
        } else {
            $error_msg = __('File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.');
        }
        return call_user_func($upload_error_handler, $file, $error_msg);
    }
    // A properly uploaded file will pass this test. There should be no reason to override this one.
    $test_uploaded_file = 'wp_handle_upload' === $action ? @is_uploaded_file($file['tmp_name']) : @is_file($file['tmp_name']);
    if ($test_upload && !$test_uploaded_file) {
        return call_user_func($upload_error_handler, $file, __('Specified file failed upload test.'));
    }
    // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
    if ($test_type) {
        //print_r($file);
        $wp_filetype = wp_check_filetype_and_ext($file['tmp_name'], $file['name'], $mimes);
        $ext = empty($wp_filetype['ext']) ? '' : $wp_filetype['ext'];
        $type = empty($wp_filetype['type']) ? '' : $wp_filetype['type'];
        $proper_filename = empty($wp_filetype['proper_filename']) ? '' : $wp_filetype['proper_filename'];
        // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect
        if ($proper_filename) {
            $file['name'] = $proper_filename;
        }
        if ((!$type || !$ext) && !current_user_can('unfiltered_upload')) {
            return call_user_func($upload_error_handler, $file, __('Sorry, this file type is not permitted for security reasons.'));
        }
        if (!$type) {
            $type = $file['type'];
        }
    } else {
        $type = '';
    }
    /*
     * A writable uploads dir will pass this test. Again, there's no point
     * overriding this one.
     */
    if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
        return call_user_func($upload_error_handler, $file, $uploads['error']);
    }
    $filename = wp_unique_filename($uploads['path'], $file['name'], $unique_filename_callback);
    // Move the file to the uploads dir.
    $new_file = $uploads['path'] . "/{$filename}";
    if ('lpr_handle_upload' === $action) {
        $move_new_file = @move_uploaded_file($file['tmp_name'], $new_file);
    } else {
        $move_new_file = @rename($file['tmp_name'], $new_file);
    }
    if (false === $move_new_file) {
        return $upload_error_handler($file, sprintf(__('The uploaded file could not be moved')));
    }
    // Set correct file permissions.
    $stat = stat(dirname($new_file));
    $perms = $stat['mode'] & 0666;
    @chmod($new_file, $perms);
    // Compute the URL.
    $url = $uploads['url'] . "/{$filename}";
    if (is_multisite()) {
        delete_transient('dirsize_cache');
    }
    /**
     * Filter the data array for the uploaded file.
     *
     * @since 2.1.0
     *
     * @param array  $upload {
     *     Array of upload data.
     *
     *     @type string $file Filename of the newly-uploaded file.
     *     @type string $url  URL of the uploaded file.
     *     @type string $type File type.
     * }
     * @param string $context The type of upload action. Values include 'upload' or 'sideload'.
     */
    return apply_filters('lpr_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type), 'upload');
}
/**
 * Create a file in the upload folder with given content.
 *
 * If there is an error, then the key 'error' will exist with the error message.
 * If success, then the key 'file' will have the unique file path, the 'url' key
 * will have the link to the new file. and the 'error' key will be set to false.
 *
 * This function will not move an uploaded file to the upload folder. It will
 * create a new file with the content in $bits parameter. If you move the upload
 * file, read the content of the uploaded file, and then you can give the
 * filename and content to this function, which will add it to the upload
 * folder.
 *
 * The permissions will be set on the new file automatically by this function.
 *
 * @since 2.0.0
 *
 * @param string $name
 * @param null $deprecated Not used. Set to null.
 * @param mixed $bits File content
 * @param string $time Optional. Time formatted in 'yyyy/mm'.
 * @return array
 */
function wp_upload_bits($name, $deprecated, $bits, $time = null)
{
    if (empty($name)) {
        return array('error' => __('Empty filename'));
    }
    $wp_filetype = wp_check_filetype($name);
    if (!$wp_filetype['ext']) {
        return array('error' => __('Invalid file type'));
    }
    $upload = wp_upload_dir($time);
    if ($upload['error'] !== false) {
        return $upload;
    }
    /* WPMU check file before writing it */
    $upload_bits_error = apply_filters('wp_upload_bits', array('name' => $name, 'bits' => $bits, 'time' => $time));
    if (is_array($upload_bits_error) == false) {
        $upload['error'] = $upload_bits_error;
        return $upload;
    }
    $filename = wp_unique_filename($upload['path'], $name);
    $new_file = $upload['path'] . "/{$filename}";
    if (!wp_mkdir_p(dirname($new_file))) {
        $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
        return array('error' => $message);
    }
    $ifp = @fopen($new_file, 'wb');
    if (!$ifp) {
        return array('error' => sprintf(__('Could not write file %s'), $new_file));
    }
    @fwrite($ifp, $bits);
    fclose($ifp);
    // Set correct file permissions
    $stat = @stat(dirname($new_file));
    $perms = $stat['mode'] & 07777;
    $perms = $perms & 0666;
    @chmod($new_file, $perms);
    // Compute the URL
    $url = $upload['url'] . "/{$filename}";
    return array('file' => $new_file, 'url' => $url, 'error' => false);
}
Beispiel #30
0
 /**
  * Perform import operation
  * @param string $xml XML string to import
  * @param callback[optional] $logger Method where progress messages are submmitted
  * @return PMXI_Import_Record
  * @chainable
  */
 public function process($xml, $logger = NULL, $chunk = false, $is_cron = false, $xpath_prefix = '', $loop = 0)
 {
     add_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html'));
     kses_init();
     // do not perform special filtering for imported content
     kses_remove_filters();
     $cxpath = $xpath_prefix . $this->xpath;
     $this->options += PMXI_Plugin::get_default_import_options();
     // make sure all options are defined
     $avoid_pingbacks = PMXI_Plugin::getInstance()->getOption('pingbacks');
     $cron_sleep = (int) PMXI_Plugin::getInstance()->getOption('cron_sleep');
     if ($avoid_pingbacks and !defined('WP_IMPORTING')) {
         define('WP_IMPORTING', true);
     }
     $postRecord = new PMXI_Post_Record();
     $tmp_files = array();
     // compose records to import
     $records = array();
     $is_import_complete = false;
     try {
         $chunk == 1 and $logger and call_user_func($logger, __('Composing titles...', 'wp_all_import_plugin'));
         if (!empty($this->options['title'])) {
             $titles = XmlImportParser::factory($xml, $cxpath, $this->options['title'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             $loop and $titles = array_fill(0, $loop, '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing excerpts...', 'wp_all_import_plugin'));
         $post_excerpt = array();
         if (!empty($this->options['post_excerpt'])) {
             $post_excerpt = XmlImportParser::factory($xml, $cxpath, $this->options['post_excerpt'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $post_excerpt = array_fill(0, count($titles), '');
         }
         if ("xpath" == $this->options['status']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing statuses...', 'wp_all_import_plugin'));
             $post_status = array();
             if (!empty($this->options['status_xpath'])) {
                 $post_status = XmlImportParser::factory($xml, $cxpath, $this->options['status_xpath'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $post_status = array_fill(0, count($titles), '');
             }
         }
         if ("xpath" == $this->options['comment_status']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing comment statuses...', 'wp_all_import_plugin'));
             $comment_status = array();
             if (!empty($this->options['comment_status_xpath'])) {
                 $comment_status = XmlImportParser::factory($xml, $cxpath, $this->options['comment_status_xpath'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $comment_status = array_fill(0, count($titles), 'open');
             }
         }
         if ("xpath" == $this->options['ping_status']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing ping statuses...', 'wp_all_import_plugin'));
             $ping_status = array();
             if (!empty($this->options['ping_status_xpath'])) {
                 $ping_status = XmlImportParser::factory($xml, $cxpath, $this->options['ping_status_xpath'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $ping_status = array_fill(0, count($titles), 'open');
             }
         }
         if ("xpath" == $this->options['post_format']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing post formats...', 'wp_all_import_plugin'));
             $post_format = array();
             if (!empty($this->options['post_format_xpath'])) {
                 $post_format = XmlImportParser::factory($xml, $cxpath, $this->options['post_format_xpath'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $post_format = array_fill(0, count($titles), 'open');
             }
         }
         if ("no" == $this->options['is_multiple_page_template']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing page templates...', 'wp_all_import_plugin'));
             $page_template = array();
             if (!empty($this->options['single_page_template'])) {
                 $page_template = XmlImportParser::factory($xml, $cxpath, $this->options['single_page_template'], $file)->parse($records);
                 $tmp_files[] = $file;
             } else {
                 count($titles) and $page_template = array_fill(0, count($titles), 'default');
             }
         }
         if ($this->options['is_override_post_type'] and !empty($this->options['post_type_xpath'])) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing post types...', 'wp_all_import_plugin'));
             $post_type = array();
             $post_type = XmlImportParser::factory($xml, $cxpath, $this->options['post_type_xpath'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             if ('post' == $this->options['type'] and '' != $this->options['custom_type']) {
                 $pType = $this->options['custom_type'];
             } else {
                 $pType = $this->options['type'];
             }
             count($titles) and $post_type = array_fill(0, count($titles), $pType);
         }
         if ("no" == $this->options['is_multiple_page_parent']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing page parent...', 'wp_all_import_plugin'));
             $page_parent = array();
             if (!empty($this->options['single_page_parent'])) {
                 $page_parent = XmlImportParser::factory($xml, $cxpath, $this->options['single_page_parent'], $file)->parse($records);
                 $tmp_files[] = $file;
                 foreach ($page_parent as $key => $identity) {
                     $page = 0;
                     switch ($this->options['type']) {
                         case 'post':
                             if (!empty($identity)) {
                                 if (ctype_digit($identity)) {
                                     $page = get_post($identity);
                                 } else {
                                     $page = get_page_by_title($identity, OBJECT, $post_type[$key]);
                                     if (empty($page)) {
                                         $args = array('name' => $identity, 'post_type' => $post_type[$key], 'post_status' => 'any', 'numberposts' => 1);
                                         $my_posts = get_posts($args);
                                         if ($my_posts) {
                                             $page = $my_posts[0];
                                         }
                                     }
                                 }
                             }
                             break;
                         case 'page':
                             $page = get_page_by_title($identity) or $page = get_page_by_path($identity) or ctype_digit($identity) and $page = get_post($identity);
                             break;
                         default:
                             # code...
                             break;
                     }
                     $page_parent[$key] = !empty($page) ? $page->ID : 0;
                 }
             } else {
                 count($titles) and $page_parent = array_fill(0, count($titles), 0);
             }
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing authors...', 'wp_all_import_plugin'));
         $post_author = array();
         $current_user = wp_get_current_user();
         if (!empty($this->options['author'])) {
             $post_author = XmlImportParser::factory($xml, $cxpath, $this->options['author'], $file)->parse($records);
             $tmp_files[] = $file;
             foreach ($post_author as $key => $author) {
                 $user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author);
                 $post_author[$key] = !empty($user) ? $user->ID : $current_user->ID;
             }
         } else {
             count($titles) and $post_author = array_fill(0, count($titles), $current_user->ID);
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing slugs...', 'wp_all_import_plugin'));
         $post_slug = array();
         if (!empty($this->options['post_slug'])) {
             $post_slug = XmlImportParser::factory($xml, $cxpath, $this->options['post_slug'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $post_slug = array_fill(0, count($titles), '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing menu order...', 'wp_all_import_plugin'));
         $menu_order = array();
         if (!empty($this->options['order'])) {
             $menu_order = XmlImportParser::factory($xml, $cxpath, $this->options['order'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $menu_order = array_fill(0, count($titles), '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing contents...', 'wp_all_import_plugin'));
         if (!empty($this->options['content'])) {
             $contents = XmlImportParser::factory((!empty($this->options['is_keep_linebreaks']) and intval($this->options['is_keep_linebreaks'])) ? $xml : preg_replace('%\\r\\n?|\\n%', ' ', $xml), $cxpath, $this->options['content'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $contents = array_fill(0, count($titles), '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing dates...', 'wp_all_import_plugin'));
         if ('specific' == $this->options['date_type']) {
             $dates = XmlImportParser::factory($xml, $cxpath, $this->options['date'], $file)->parse($records);
             $tmp_files[] = $file;
             $warned = array();
             // used to prevent the same notice displaying several times
             foreach ($dates as $i => $d) {
                 if ($d == 'now') {
                     $d = current_time('mysql');
                 }
                 // Replace 'now' with the WordPress local time to account for timezone offsets (WordPress references its local time during publishing rather than the server’s time so it should use that)
                 $time = strtotime($d);
                 if (FALSE === $time) {
                     in_array($d, $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $d));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $time = time();
                 }
                 $dates[$i] = date('Y-m-d H:i:s', $time);
             }
         } else {
             $dates_start = XmlImportParser::factory($xml, $cxpath, $this->options['date_start'], $file)->parse($records);
             $tmp_files[] = $file;
             $dates_end = XmlImportParser::factory($xml, $cxpath, $this->options['date_end'], $file)->parse($records);
             $tmp_files[] = $file;
             $warned = array();
             // used to prevent the same notice displaying several times
             foreach ($dates_start as $i => $d) {
                 $time_start = strtotime($dates_start[$i]);
                 if (FALSE === $time_start) {
                     in_array($dates_start[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $dates_start[$i]));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $time_start = time();
                 }
                 $time_end = strtotime($dates_end[$i]);
                 if (FALSE === $time_end) {
                     in_array($dates_end[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $dates_end[$i]));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $time_end = time();
                 }
                 $dates[$i] = date('Y-m-d H:i:s', mt_rand($time_start, $time_end));
             }
         }
         // [custom taxonomies]
         require_once ABSPATH . 'wp-admin/includes/taxonomy.php';
         $taxonomies = array();
         $exclude_taxonomies = apply_filters('pmxi_exclude_taxonomies', class_exists('PMWI_Plugin') ? array('post_format', 'product_type', 'product_shipping_class') : array('post_format'));
         $post_taxonomies = array_diff_key(get_taxonomies_by_object_type(array($this->options['custom_type']), 'object'), array_flip($exclude_taxonomies));
         if (!empty($post_taxonomies)) {
             foreach ($post_taxonomies as $ctx) {
                 if ("" == $ctx->labels->name or class_exists('PMWI_Plugin') and strpos($ctx->name, "pa_") === 0 and $this->options['custom_type'] == "product") {
                     continue;
                 }
                 $chunk == 1 and $logger and call_user_func($logger, sprintf(__('Composing terms for `%s` taxonomy...', 'wp_all_import_plugin'), $ctx->labels->name));
                 $tx_name = $ctx->name;
                 $mapping_rules = !empty($this->options['tax_mapping'][$tx_name]) ? json_decode($this->options['tax_mapping'][$tx_name], true) : false;
                 $taxonomies[$tx_name] = array();
                 if (!empty($this->options['tax_logic'][$tx_name]) and !empty($this->options['tax_assing'][$tx_name])) {
                     switch ($this->options['tax_logic'][$tx_name]) {
                         case 'single':
                             if (!empty($this->options['tax_single_xpath'][$tx_name])) {
                                 $txes = XmlImportParser::factory($xml, $cxpath, $this->options['tax_single_xpath'][$tx_name], $file)->parse($records);
                                 $tmp_files[] = $file;
                                 foreach ($txes as $i => $tx) {
                                     $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => $tx, 'parent' => false, 'assign' => isset($this->options['term_assing'][$tx_name]) ? $this->options['term_assing'][$tx_name] : true, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]), 'hierarchy_level' => 1, 'max_hierarchy_level' => 1), $mapping_rules, $tx_name);
                                 }
                             }
                             break;
                         case 'multiple':
                             if (!empty($this->options['tax_multiple_xpath'][$tx_name])) {
                                 $txes = XmlImportParser::factory($xml, $cxpath, $this->options['tax_multiple_xpath'][$tx_name], $file)->parse($records);
                                 $tmp_files[] = $file;
                                 foreach ($txes as $i => $tx) {
                                     $_tx = $tx;
                                     // apply mapping rules before splitting via separator symbol
                                     if (!empty($this->options['tax_enable_mapping'][$tx_name]) and !empty($this->options['tax_logic_mapping'][$tx_name])) {
                                         if (!empty($mapping_rules)) {
                                             foreach ($mapping_rules as $rule) {
                                                 if (!empty($rule[trim($_tx)])) {
                                                     $_tx = trim($rule[trim($_tx)]);
                                                     break;
                                                 }
                                             }
                                         }
                                     }
                                     $delimeted_taxonomies = explode(!empty($this->options['tax_multiple_delim'][$tx_name]) ? $this->options['tax_multiple_delim'][$tx_name] : ',', $_tx);
                                     if (!empty($delimeted_taxonomies)) {
                                         foreach ($delimeted_taxonomies as $cc) {
                                             $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => $cc, 'parent' => false, 'assign' => isset($this->options['multiple_term_assing'][$tx_name]) ? $this->options['multiple_term_assing'][$tx_name] : true, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]) and empty($this->options['tax_logic_mapping'][$tx_name]), 'hierarchy_level' => 1, 'max_hierarchy_level' => 1), $mapping_rules, $tx_name);
                                         }
                                     }
                                 }
                             }
                             break;
                         case 'hierarchical':
                             if (!empty($this->options['tax_hierarchical_logic_entire'][$tx_name])) {
                                 if (!empty($this->options['tax_hierarchical_xpath'][$tx_name]) and is_array($this->options['tax_hierarchical_xpath'][$tx_name])) {
                                     count($titles) and $iterator = array_fill(0, count($titles), 0);
                                     $taxonomies_hierarchy_groups = array_fill(0, count($titles), array());
                                     // separate hierarchy groups via symbol
                                     if (!empty($this->options['is_tax_hierarchical_group_delim'][$tx_name]) and !empty($this->options['tax_hierarchical_group_delim'][$tx_name])) {
                                         foreach ($this->options['tax_hierarchical_xpath'][$tx_name] as $k => $tx_xpath) {
                                             if (empty($tx_xpath)) {
                                                 continue;
                                             }
                                             $txes = XmlImportParser::factory($xml, $cxpath, $tx_xpath, $file)->parse($records);
                                             $tmp_files[] = $file;
                                             foreach ($txes as $i => $tx) {
                                                 $_tx = $tx;
                                                 // apply mapping rules before splitting via separator symbol
                                                 if (!empty($this->options['tax_enable_mapping'][$tx_name]) and !empty($this->options['tax_logic_mapping'][$tx_name])) {
                                                     if (!empty($mapping_rules)) {
                                                         foreach ($mapping_rules as $rule) {
                                                             if (!empty($rule[trim($_tx)])) {
                                                                 $_tx = trim($rule[trim($_tx)]);
                                                                 break;
                                                             }
                                                         }
                                                     }
                                                 }
                                                 $delimeted_groups = explode($this->options['tax_hierarchical_group_delim'][$tx_name], $_tx);
                                                 if (!empty($delimeted_groups) and is_array($delimeted_groups)) {
                                                     foreach ($delimeted_groups as $group) {
                                                         if (!empty($group)) {
                                                             array_push($taxonomies_hierarchy_groups[$i], $group);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         foreach ($this->options['tax_hierarchical_xpath'][$tx_name] as $k => $tx_xpath) {
                                             if (empty($tx_xpath)) {
                                                 continue;
                                             }
                                             $txes = XmlImportParser::factory($xml, $cxpath, $tx_xpath, $file)->parse($records);
                                             $tmp_files[] = $file;
                                             foreach ($txes as $i => $tx) {
                                                 array_push($taxonomies_hierarchy_groups[$i], $tx);
                                             }
                                         }
                                     }
                                     foreach ($taxonomies_hierarchy_groups as $i => $groups) {
                                         if (empty($groups)) {
                                             continue;
                                         }
                                         foreach ($groups as $kk => $tx) {
                                             $_tx = $tx;
                                             // apply mapping rules before splitting via separator symbol
                                             if (!empty($this->options['tax_enable_mapping'][$tx_name]) and !empty($this->options['tax_logic_mapping'][$tx_name])) {
                                                 if (!empty($mapping_rules)) {
                                                     foreach ($mapping_rules as $rule) {
                                                         if (!empty($rule[trim($_tx)])) {
                                                             $_tx = trim($rule[trim($_tx)]);
                                                             break;
                                                         }
                                                     }
                                                 }
                                             }
                                             $delimeted_taxonomies = explode(!empty($this->options['tax_hierarchical_delim'][$tx_name]) ? $this->options['tax_hierarchical_delim'][$tx_name] : ',', $_tx);
                                             if (!empty($delimeted_taxonomies)) {
                                                 foreach ($delimeted_taxonomies as $j => $cc) {
                                                     $is_assign_term = isset($this->options['tax_hierarchical_assing'][$tx_name][$k]) ? $this->options['tax_hierarchical_assing'][$tx_name][$k] : true;
                                                     if (!empty($this->options['tax_hierarchical_last_level_assign'][$tx_name])) {
                                                         $is_assign_term = count($delimeted_taxonomies) == $j + 1 ? 1 : 0;
                                                     }
                                                     $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => $cc, 'parent' => (!empty($taxonomies[$tx_name][$i][$iterator[$i] - 1]) and $j) ? $taxonomies[$tx_name][$i][$iterator[$i] - 1] : false, 'assign' => $is_assign_term, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]) and empty($this->options['tax_logic_mapping'][$tx_name]), 'hierarchy_level' => $j + 1, 'max_hierarchy_level' => count($delimeted_taxonomies)), $mapping_rules, $tx_name);
                                                     $iterator[$i]++;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if (!empty($this->options['tax_hierarchical_logic_manual'][$tx_name])) {
                                 if (!empty($this->options['post_taxonomies'][$tx_name])) {
                                     $taxonomies_hierarchy = json_decode($this->options['post_taxonomies'][$tx_name], true);
                                     foreach ($taxonomies_hierarchy as $k => $taxonomy) {
                                         if ("" == $taxonomy['xpath']) {
                                             continue;
                                         }
                                         $txes_raw = XmlImportParser::factory($xml, $cxpath, $taxonomy['xpath'], $file)->parse($records);
                                         $tmp_files[] = $file;
                                         $warned = array();
                                         foreach ($txes_raw as $i => $cc) {
                                             $_tx = $cc;
                                             // apply mapping rules before splitting via separator symbol
                                             if (!empty($this->options['tax_enable_mapping'][$tx_name]) and !empty($this->options['tax_logic_mapping'][$tx_name])) {
                                                 if (!empty($mapping_rules)) {
                                                     foreach ($mapping_rules as $rule) {
                                                         if (!empty($rule[trim($_tx)])) {
                                                             $_tx = trim($rule[trim($_tx)]);
                                                             break;
                                                         }
                                                     }
                                                 }
                                             }
                                             if (!empty($this->options['tax_manualhierarchy_delim'][$tx_name])) {
                                                 $delimeted_taxonomies = explode($this->options['tax_manualhierarchy_delim'][$tx_name], $_tx);
                                             }
                                             if (empty($delimeted_taxonomies)) {
                                                 continue;
                                             }
                                             if (empty($taxonomies_hierarchy[$k]['txn_names'][$i])) {
                                                 $taxonomies_hierarchy[$k]['txn_names'][$i] = array();
                                             }
                                             if (empty($taxonomies[$tx_name][$i])) {
                                                 $taxonomies[$tx_name][$i] = array();
                                             }
                                             $count_cats = count($taxonomies[$tx_name][$i]);
                                             foreach ($delimeted_taxonomies as $j => $dc) {
                                                 if (!empty($taxonomy['parent_id'])) {
                                                     foreach ($taxonomies_hierarchy as $key => $value) {
                                                         if ($value['item_id'] == $taxonomy['parent_id'] and !empty($value['txn_names'][$i])) {
                                                             foreach ($value['txn_names'][$i] as $parent) {
                                                                 $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => trim($dc), 'parent' => $parent, 'assign' => isset($taxonomy['assign']) ? $taxonomy['assign'] : true, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]) and empty($this->options['tax_logic_mapping'][$tx_name]), 'hierarchy_level' => 1, 'max_hierarchy_level' => 1), $mapping_rules, $tx_name);
                                                             }
                                                         }
                                                     }
                                                 } else {
                                                     $taxonomies[$tx_name][$i][] = wp_all_import_ctx_mapping(array('name' => trim($dc), 'parent' => false, 'assign' => isset($taxonomy['assign']) ? $taxonomy['assign'] : true, 'is_mapping' => !empty($this->options['tax_enable_mapping'][$tx_name]) and empty($this->options['tax_logic_mapping'][$tx_name]), 'hierarchy_level' => 1, 'max_hierarchy_level' => 1), $mapping_rules, $tx_name);
                                                 }
                                                 if ($count_cats < count($taxonomies[$tx_name][$i])) {
                                                     $taxonomies_hierarchy[$k]['txn_names'][$i][] = $taxonomies[$tx_name][$i][count($taxonomies[$tx_name][$i]) - 1];
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             break;
                         default:
                             break;
                     }
                 }
             }
         }
         // [/custom taxonomies]
         // Composing featured images
         $image_sections = apply_filters('wp_all_import_image_sections', array(array('slug' => '', 'title' => __('Images', 'wp_all_import_plugin'), 'type' => 'images')));
         if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
             $logger and call_user_func($logger, __('<b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $uploads['error']);
             $logger and call_user_func($logger, __('<b>WARNING</b>: No featured images will be created. Uploads folder is not found.', 'wp_all_import_plugin'));
             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
         } else {
             $images_bundle = array();
             foreach ($image_sections as $section) {
                 $chunk == 1 and $logger and call_user_func($logger, __('Composing URLs for ' . strtolower($section['title']) . '...', 'wp_all_import_plugin'));
                 $featured_images = array();
                 if ("no" == $this->options[$section['slug'] . 'download_images']) {
                     if ($this->options[$section['slug'] . 'featured_image']) {
                         $featured_images = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'featured_image'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $featured_images = array_fill(0, count($titles), '');
                     }
                 } else {
                     if ($this->options[$section['slug'] . 'download_featured_image']) {
                         $featured_images = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'download_featured_image'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $featured_images = array_fill(0, count($titles), '');
                     }
                 }
                 $images_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = array('type' => $section['type'], 'files' => $featured_images);
                 // Composing images meta titles
                 $image_meta_titles_bundle = array();
                 if ($this->options[$section['slug'] . 'set_image_meta_title']) {
                     $chunk == 1 and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' meta data (titles)...', 'wp_all_import_plugin'));
                     $image_meta_titles = array();
                     if ($this->options[$section['slug'] . 'image_meta_title']) {
                         $image_meta_titles = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'image_meta_title'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $image_meta_titles = array_fill(0, count($titles), '');
                     }
                     $image_meta_titles_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $image_meta_titles;
                 }
                 // Composing images meta captions
                 $image_meta_captions_bundle = array();
                 if ($this->options[$section['slug'] . 'set_image_meta_caption']) {
                     $chunk == 1 and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' meta data (captions)...', 'wp_all_import_plugin'));
                     $image_meta_captions = array();
                     if ($this->options[$section['slug'] . 'image_meta_caption']) {
                         $image_meta_captions = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'image_meta_caption'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $image_meta_captions = array_fill(0, count($titles), '');
                     }
                     $image_meta_captions_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $image_meta_captions;
                 }
                 // Composing images meta alt text
                 $image_meta_alts_bundle = array();
                 if ($this->options[$section['slug'] . 'set_image_meta_alt']) {
                     $chunk == 1 and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' meta data (alt text)...', 'wp_all_import_plugin'));
                     $image_meta_alts = array();
                     if ($this->options[$section['slug'] . 'image_meta_alt']) {
                         $image_meta_alts = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'image_meta_alt'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $image_meta_alts = array_fill(0, count($titles), '');
                     }
                     $image_meta_alts_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $image_meta_alts;
                 }
                 // Composing images meta description
                 $image_meta_descriptions_bundle = array();
                 if ($this->options[$section['slug'] . 'set_image_meta_description']) {
                     $chunk == 1 and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' meta data (description)...', 'wp_all_import_plugin'));
                     $image_meta_descriptions = array();
                     if ($this->options[$section['slug'] . 'image_meta_description']) {
                         $image_meta_descriptions = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'image_meta_description'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $image_meta_descriptions = array_fill(0, count($titles), '');
                     }
                     $image_meta_descriptions_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $image_meta_descriptions;
                 }
                 $auto_rename_images_bundle = array();
                 $auto_extensions_bundle = array();
                 if ("yes" == $this->options[$section['slug'] . 'download_images']) {
                     // Composing images suffix
                     $chunk == 1 and $this->options[$section['slug'] . 'auto_rename_images'] and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' suffix...', 'wp_all_import_plugin'));
                     $auto_rename_images = array();
                     if ($this->options[$section['slug'] . 'auto_rename_images'] and !empty($this->options[$section['slug'] . 'auto_rename_images_suffix'])) {
                         $auto_rename_images = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'auto_rename_images_suffix'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $auto_rename_images = array_fill(0, count($titles), '');
                     }
                     $auto_rename_images_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $auto_rename_images;
                     // Composing images extensions
                     $chunk == 1 and $this->options[$section['slug'] . 'auto_set_extension'] and $logger and call_user_func($logger, __('Composing ' . strtolower($section['title']) . ' extensions...', 'wp_all_import_plugin'));
                     $auto_extensions = array();
                     if ($this->options[$section['slug'] . 'auto_set_extension'] and !empty($this->options[$section['slug'] . 'new_extension'])) {
                         $auto_extensions = XmlImportParser::factory($xml, $cxpath, $this->options[$section['slug'] . 'new_extension'], $file)->parse($records);
                         $tmp_files[] = $file;
                     } else {
                         count($titles) and $auto_extensions = array_fill(0, count($titles), '');
                     }
                     $auto_extensions_bundle[empty($section['slug']) ? 'pmxi_gallery_image' : $section['slug']] = $auto_extensions;
                 }
             }
         }
         // Composing attachments
         if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
             $logger and call_user_func($logger, __('<b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $uploads['error']);
             $logger and call_user_func($logger, __('<b>WARNING</b>: No attachments will be created', 'wp_all_import_plugin'));
             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
         } else {
             $chunk == 1 and $logger and call_user_func($logger, __('Composing URLs for attachments files...', 'wp_all_import_plugin'));
             $attachments = array();
             if ($this->options['attachments']) {
                 // Detect if attachments is separated by comma
                 $atchs = explode(',', $this->options['attachments']);
                 if (!empty($atchs)) {
                     $parse_multiple = true;
                     foreach ($atchs as $atch) {
                         if (!preg_match("/{.*}/", trim($atch))) {
                             $parse_multiple = false;
                         }
                     }
                     if ($parse_multiple) {
                         foreach ($atchs as $atch) {
                             $posts_attachments = XmlImportParser::factory($xml, $cxpath, trim($atch), $file)->parse($records);
                             $tmp_files[] = $file;
                             foreach ($posts_attachments as $i => $val) {
                                 $attachments[$i][] = $val;
                             }
                         }
                     } else {
                         $attachments = XmlImportParser::factory($xml, $cxpath, $this->options['attachments'], $file)->parse($records);
                         $tmp_files[] = $file;
                     }
                 }
             } else {
                 count($titles) and $attachments = array_fill(0, count($titles), '');
             }
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Composing unique keys...', 'wp_all_import_plugin'));
         if (!empty($this->options['unique_key'])) {
             $unique_keys = XmlImportParser::factory($xml, $cxpath, $this->options['unique_key'], $file)->parse($records);
             $tmp_files[] = $file;
         } else {
             count($titles) and $unique_keys = array_fill(0, count($titles), '');
         }
         $chunk == 1 and $logger and call_user_func($logger, __('Processing posts...', 'wp_all_import_plugin'));
         $addons = array();
         $addons_data = array();
         // data parsing for WP All Import add-ons
         $chunk == 1 and $logger and call_user_func($logger, __('Data parsing via add-ons...', 'wp_all_import_plugin'));
         $parsingData = array('import' => $this, 'count' => count($titles), 'xml' => $xml, 'logger' => $logger, 'chunk' => $chunk, 'xpath_prefix' => $xpath_prefix);
         $parse_functions = apply_filters('wp_all_import_addon_parse', array());
         foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
             $model_class = str_replace("_Plugin", "_Import_Record", $class);
             if (class_exists($model_class)) {
                 $addons[$class] = new $model_class();
                 $addons_data[$class] = method_exists($addons[$class], 'parse') ? $addons[$class]->parse($parsingData) : false;
             } else {
                 if (!empty($parse_functions[$class])) {
                     if (is_array($parse_functions[$class]) and is_callable($parse_functions[$class]) or !is_array($parse_functions[$class]) and function_exists($parse_functions[$class])) {
                         $addons_data[$class] = call_user_func($parse_functions[$class], $parsingData);
                     }
                 }
             }
         }
         // save current import state to variables before import
         $created = $this->created;
         $updated = $this->updated;
         $skipped = $this->skipped;
         $specified_records = array();
         if ($this->options['is_import_specified']) {
             $chunk == 1 and $logger and call_user_func($logger, __('Calculate specified records to import...', 'wp_all_import_plugin'));
             foreach (preg_split('% *, *%', $this->options['import_specified'], -1, PREG_SPLIT_NO_EMPTY) as $chank) {
                 if (preg_match('%^(\\d+)-(\\d+)$%', $chank, $mtch)) {
                     $specified_records = array_merge($specified_records, range(intval($mtch[1]), intval($mtch[2])));
                 } else {
                     $specified_records = array_merge($specified_records, array(intval($chank)));
                 }
             }
         }
         $simpleXml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
         $rootNodes = $simpleXml->xpath($cxpath);
         foreach ($titles as $i => $void) {
             $custom_type_details = get_post_type_object($post_type[$i]);
             if ($is_cron and $cron_sleep) {
                 sleep($cron_sleep);
             }
             $logger and call_user_func($logger, __('---', 'wp_all_import_plugin'));
             $logger and call_user_func($logger, sprintf(__('Record #%s', 'wp_all_import_plugin'), $this->imported + $this->skipped + $i + 1));
             wp_cache_flush();
             $logger and call_user_func($logger, __('<b>ACTION</b>: pmxi_before_post_import ...', 'wp_all_import_plugin'));
             do_action('pmxi_before_post_import', $this->id);
             if (empty($titles[$i])) {
                 if (!empty($addons_data['PMWI_Plugin']) and !empty($addons_data['PMWI_Plugin']['single_product_parent_ID'][$i])) {
                     $titles[$i] = $addons_data['PMWI_Plugin']['single_product_parent_ID'][$i] . ' Product Variation';
                 } else {
                     $logger and call_user_func($logger, __('<b>WARNING</b>: title is empty.', 'wp_all_import_plugin'));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                 }
             }
             if ($this->options['custom_type'] == 'import_users') {
                 $articleData = array('user_pass' => $addons_data['PMUI_Plugin']['pmui_pass'][$i], 'user_login' => $addons_data['PMUI_Plugin']['pmui_logins'][$i], 'user_nicename' => $addons_data['PMUI_Plugin']['pmui_nicename'][$i], 'user_url' => $addons_data['PMUI_Plugin']['pmui_url'][$i], 'user_email' => $addons_data['PMUI_Plugin']['pmui_email'][$i], 'display_name' => $addons_data['PMUI_Plugin']['pmui_display_name'][$i], 'user_registered' => $addons_data['PMUI_Plugin']['pmui_registered'][$i], 'first_name' => $addons_data['PMUI_Plugin']['pmui_first_name'][$i], 'last_name' => $addons_data['PMUI_Plugin']['pmui_last_name'][$i], 'description' => $addons_data['PMUI_Plugin']['pmui_description'][$i], 'nickname' => $addons_data['PMUI_Plugin']['pmui_nickname'][$i], 'role' => '' == $addons_data['PMUI_Plugin']['pmui_role'][$i] ? 'subscriber' : strtolower($addons_data['PMUI_Plugin']['pmui_role'][$i]));
                 $logger and call_user_func($logger, sprintf(__('Combine all data for user %s...', 'wp_all_import_plugin'), $articleData['user_login']));
             } else {
                 $articleData = array('post_type' => $post_type[$i], 'post_status' => "xpath" == $this->options['status'] ? $post_status[$i] : $this->options['status'], 'comment_status' => "xpath" == $this->options['comment_status'] ? $comment_status[$i] : $this->options['comment_status'], 'ping_status' => "xpath" == $this->options['ping_status'] ? $ping_status[$i] : $this->options['ping_status'], 'post_title' => !empty($this->options['is_leave_html']) ? html_entity_decode($titles[$i]) : $titles[$i], 'post_excerpt' => apply_filters('pmxi_the_excerpt', !empty($this->options['is_leave_html']) ? html_entity_decode($post_excerpt[$i]) : $post_excerpt[$i], $this->id), 'post_name' => $post_slug[$i], 'post_content' => apply_filters('pmxi_the_content', !empty($this->options['is_leave_html']) ? html_entity_decode($contents[$i]) : $contents[$i], $this->id), 'post_date' => $dates[$i], 'post_date_gmt' => get_gmt_from_date($dates[$i]), 'post_author' => $post_author[$i], 'menu_order' => (int) $menu_order[$i], 'post_parent' => "no" == $this->options['is_multiple_page_parent'] ? (int) $page_parent[$i] : (int) $this->options['parent']);
                 $logger and call_user_func($logger, sprintf(__('Combine all data for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
             }
             // Re-import Records Matching
             $post_to_update = false;
             $post_to_update_id = false;
             // if Auto Matching re-import option selected
             if ("manual" != $this->options['duplicate_matching']) {
                 // find corresponding article among previously imported
                 $logger and call_user_func($logger, sprintf(__('Find corresponding article among previously imported for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
                 $postRecord->clear();
                 $postRecord->getBy(array('unique_key' => $unique_keys[$i], 'import_id' => $this->id));
                 if (!$postRecord->isEmpty()) {
                     $logger and call_user_func($logger, sprintf(__('Duplicate post was founded for post %s with unique key `%s`...', 'wp_all_import_plugin'), $articleData['post_title'], $unique_keys[$i]));
                     if ($this->options['custom_type'] == 'import_users') {
                         $post_to_update = get_user_by('id', $post_to_update_id = $postRecord->post_id);
                     } else {
                         $post_to_update = get_post($post_to_update_id = $postRecord->post_id);
                     }
                 } else {
                     $logger and call_user_func($logger, sprintf(__('Duplicate post wasn\'t founded with unique key `%s`...', 'wp_all_import_plugin'), $unique_keys[$i]));
                 }
                 // if Manual Matching re-import option seleted
             } else {
                 if ('custom field' == $this->options['duplicate_indicator']) {
                     $custom_duplicate_value = XmlImportParser::factory($xml, $cxpath, $this->options['custom_duplicate_value'], $file)->parse($records);
                     $tmp_files[] = $file;
                     $custom_duplicate_name = XmlImportParser::factory($xml, $cxpath, $this->options['custom_duplicate_name'], $file)->parse($records);
                     $tmp_files[] = $file;
                 } else {
                     count($titles) and $custom_duplicate_name = $custom_duplicate_value = array_fill(0, count($titles), '');
                 }
                 $logger and call_user_func($logger, sprintf(__('Find corresponding article among database for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
                 // handle duplicates according to import settings
                 if ($duplicates = pmxi_findDuplicates($articleData, $custom_duplicate_name[$i], $custom_duplicate_value[$i], $this->options['duplicate_indicator'])) {
                     $duplicate_id = array_shift($duplicates);
                     if ($duplicate_id) {
                         $logger and call_user_func($logger, sprintf(__('Duplicate post was founded for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
                         if ($this->options['custom_type'] == 'import_users') {
                             $post_to_update = get_user_by('id', $post_to_update_id = $duplicate_id);
                         } else {
                             $post_to_update = get_post($post_to_update_id = $duplicate_id);
                         }
                     } else {
                         $logger and call_user_func($logger, sprintf(__('Duplicate post wasn\'n founded for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
                     }
                 }
             }
             if (!empty($specified_records)) {
                 if (!in_array($created + $updated + $skipped + 1, $specified_records)) {
                     if (!$postRecord->isEmpty()) {
                         $postRecord->set(array('iteration' => $this->iteration))->update();
                     }
                     $skipped++;
                     $logger and call_user_func($logger, __('<b>SKIPPED</b>: by specified records option', 'wp_all_import_plugin'));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
                     $logger and !$is_cron and PMXI_Plugin::$session->save_data();
                     continue;
                 }
             }
             // Duplicate record is founded
             if ($post_to_update) {
                 $continue_import = true;
                 $continue_import = apply_filters('wp_all_import_is_post_to_update', $post_to_update_id, wp_all_import_xml2array($rootNodes[$i]));
                 if (!$continue_import) {
                     if (!$postRecord->isEmpty()) {
                         $postRecord->set(array('iteration' => $this->iteration))->update();
                     }
                     $skipped++;
                     $logger and call_user_func($logger, sprintf(__('<b>SKIPPED</b>: By filter wp_all_import_is_post_to_update `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
                     $logger and !$is_cron and PMXI_Plugin::$session->save_data();
                     continue;
                 }
                 //$logger and call_user_func($logger, sprintf(__('Duplicate record is founded for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                 // Do not update already existing records option selected
                 if ("yes" == $this->options['is_keep_former_posts']) {
                     if (!$postRecord->isEmpty()) {
                         $postRecord->set(array('iteration' => $this->iteration))->update();
                     }
                     do_action('pmxi_do_not_update_existing', $post_to_update_id, $this->id, $this->iteration);
                     $skipped++;
                     $logger and call_user_func($logger, sprintf(__('<b>SKIPPED</b>: Previously imported record found for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                     $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
                     $logger and !$is_cron and PMXI_Plugin::$session->save_data();
                     continue;
                 }
                 $articleData['ID'] = $post_to_update_id;
                 // Choose which data to update
                 if ($this->options['update_all_data'] == 'no') {
                     if (!in_array($this->options['custom_type'], array('import_users'))) {
                         // preserve date of already existing article when duplicate is found
                         if (!$this->options['is_update_categories'] and (is_object_in_taxonomy($post_type[$i], 'category') or is_object_in_taxonomy($post_type[$i], 'post_tag')) or $this->options['is_update_categories'] and $this->options['update_categories_logic'] != "full_update") {
                             $logger and call_user_func($logger, sprintf(__('Preserve taxonomies of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                             $existing_taxonomies = array();
                             foreach (array_keys($taxonomies) as $tx_name) {
                                 $txes_list = get_the_terms($articleData['ID'], $tx_name);
                                 if (is_wp_error($txes_list)) {
                                     $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: Unable to get current taxonomies for article #%d, updating with those read from XML file', 'wp_all_import_plugin'), $articleData['ID']));
                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                 } else {
                                     $txes_new = array();
                                     if (!empty($txes_list)) {
                                         foreach ($txes_list as $t) {
                                             $txes_new[] = $t->term_taxonomy_id;
                                         }
                                     }
                                     $existing_taxonomies[$tx_name][$i] = $txes_new;
                                 }
                             }
                         }
                         if (!$this->options['is_update_dates']) {
                             // preserve date of already existing article when duplicate is found
                             $articleData['post_date'] = $post_to_update->post_date;
                             $articleData['post_date_gmt'] = $post_to_update->post_date_gmt;
                             $logger and call_user_func($logger, sprintf(__('Preserve date of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_status']) {
                             // preserve status and trashed flag
                             $articleData['post_status'] = $post_to_update->post_status;
                             $logger and call_user_func($logger, sprintf(__('Preserve status of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_content']) {
                             $articleData['post_content'] = $post_to_update->post_content;
                             $logger and call_user_func($logger, sprintf(__('Preserve content of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_title']) {
                             $articleData['post_title'] = $post_to_update->post_title;
                             $logger and call_user_func($logger, sprintf(__('Preserve title of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_slug']) {
                             $articleData['post_name'] = $post_to_update->post_name;
                             $logger and call_user_func($logger, sprintf(__('Preserve slug of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_excerpt']) {
                             $articleData['post_excerpt'] = $post_to_update->post_excerpt;
                             $logger and call_user_func($logger, sprintf(__('Preserve excerpt of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_menu_order']) {
                             $articleData['menu_order'] = $post_to_update->menu_order;
                             $logger and call_user_func($logger, sprintf(__('Preserve menu order of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_parent']) {
                             $articleData['post_parent'] = $post_to_update->post_parent;
                             $logger and call_user_func($logger, sprintf(__('Preserve post parent of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                         if (!$this->options['is_update_author']) {
                             $articleData['post_author'] = $post_to_update->post_author;
                             $logger and call_user_func($logger, sprintf(__('Preserve post author of already existing article for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         }
                     } else {
                         if (!$this->options['is_update_first_name']) {
                             $articleData['first_name'] = $post_to_update->first_name;
                         }
                         if (!$this->options['is_update_last_name']) {
                             $articleData['last_name'] = $post_to_update->last_name;
                         }
                         if (!$this->options['is_update_role']) {
                             unset($articleData['role']);
                         }
                         if (!$this->options['is_update_nickname']) {
                             $articleData['nickname'] = get_user_meta($post_to_update->ID, 'nickname', true);
                         }
                         if (!$this->options['is_update_description']) {
                             $articleData['description'] = get_user_meta($post_to_update->ID, 'description', true);
                         }
                         if (!$this->options['is_update_login']) {
                             $articleData['user_login'] = $post_to_update->user_login;
                         }
                         if (!$this->options['is_update_password']) {
                             unset($articleData['user_pass']);
                         }
                         if (!$this->options['is_update_nicename']) {
                             $articleData['user_nicename'] = $post_to_update->user_nicename;
                         }
                         if (!$this->options['is_update_email']) {
                             $articleData['user_email'] = $post_to_update->user_email;
                         }
                         if (!$this->options['is_update_registered']) {
                             $articleData['user_registered'] = $post_to_update->user_registered;
                         }
                         if (!$this->options['is_update_display_name']) {
                             $articleData['display_name'] = $post_to_update->display_name;
                         }
                         if (!$this->options['is_update_url']) {
                             $articleData['user_url'] = $post_to_update->user_url;
                         }
                     }
                     $logger and call_user_func($logger, sprintf(__('Applying filter `pmxi_article_data` for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                     $articleData = apply_filters('pmxi_article_data', $articleData, $this, $post_to_update);
                 }
                 if (!in_array($this->options['custom_type'], array('import_users'))) {
                     if ($this->options['update_all_data'] == 'yes' or $this->options['update_all_data'] == 'no' and $this->options['is_update_attachments']) {
                         $logger and call_user_func($logger, sprintf(__('Deleting attachments for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         wp_delete_attachments($articleData['ID'], true, 'files');
                     }
                     // handle obsolete attachments (i.e. delete or keep) according to import settings
                     if ($this->options['update_all_data'] == 'yes' or $this->options['update_all_data'] == 'no' and $this->options['is_update_images'] and $this->options['update_images_logic'] == "full_update") {
                         $logger and call_user_func($logger, sprintf(__('Deleting images for `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                         wp_delete_attachments($articleData['ID'], !$this->options['do_not_remove_images'], 'images');
                     }
                 }
             } elseif (!$postRecord->isEmpty()) {
                 // existing post not found though it's track was found... clear the leftover, plugin will continue to treat record as new
                 $postRecord->clear();
             }
             // no new records are created. it will only update posts it finds matching duplicates for
             if (!$this->options['create_new_records'] and empty($articleData['ID'])) {
                 if (!$postRecord->isEmpty()) {
                     $postRecord->set(array('iteration' => $this->iteration))->update();
                 }
                 $logger and call_user_func($logger, __('<b>SKIPPED</b>: by do not create new posts option.', 'wp_all_import_plugin'));
                 $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                 $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
                 $skipped++;
                 $logger and !$is_cron and PMXI_Plugin::$session->save_data();
                 continue;
             }
             // cloak urls with `WP Wizard Cloak` if corresponding option is set
             if (!empty($this->options['is_cloak']) and class_exists('PMLC_Plugin')) {
                 if (preg_match_all('%<a\\s[^>]*href=(?(?=")"([^"]*)"|(?(?=\')\'([^\']*)\'|([^\\s>]*)))%is', $articleData['post_content'], $matches, PREG_PATTERN_ORDER)) {
                     $hrefs = array_unique(array_merge(array_filter($matches[1]), array_filter($matches[2]), array_filter($matches[3])));
                     foreach ($hrefs as $url) {
                         if (preg_match('%^\\w+://%i', $url)) {
                             // mask only links having protocol
                             // try to find matching cloaked link among already registered ones
                             $list = new PMLC_Link_List();
                             $linkTable = $list->getTable();
                             $rule = new PMLC_Rule_Record();
                             $ruleTable = $rule->getTable();
                             $dest = new PMLC_Destination_Record();
                             $destTable = $dest->getTable();
                             $list->join($ruleTable, "{$ruleTable}.link_id = {$linkTable}.id")->join($destTable, "{$destTable}.rule_id = {$ruleTable}.id")->setColumns("{$linkTable}.*")->getBy(array("{$linkTable}.destination_type =" => 'ONE_SET', "{$linkTable}.is_trashed =" => 0, "{$linkTable}.preset =" => '', "{$linkTable}.expire_on =" => '0000-00-00', "{$ruleTable}.type =" => 'ONE_SET', "{$destTable}.weight =" => 100, "{$destTable}.url LIKE" => $url), NULL, 1, 1)->convertRecords();
                             if ($list->count()) {
                                 // matching link found
                                 $link = $list[0];
                             } else {
                                 // register new cloaked link
                                 global $wpdb;
                                 $slug = max(intval($wpdb->get_var("SELECT MAX(CONVERT(name, SIGNED)) FROM {$linkTable}")), intval($wpdb->get_var("SELECT MAX(CONVERT(slug, SIGNED)) FROM {$linkTable}")), 0);
                                 $i = 0;
                                 do {
                                     is_int(++$slug) and $slug > 0 or $slug = 1;
                                     $is_slug_found = !intval($wpdb->get_var("SELECT COUNT(*) FROM {$linkTable} WHERE name = '{$slug}' OR slug = '{$slug}'"));
                                 } while (!$is_slug_found and $i++ < 100000);
                                 if ($is_slug_found) {
                                     $link = new PMLC_Link_Record(array('name' => strval($slug), 'slug' => strval($slug), 'header_tracking_code' => '', 'footer_tracking_code' => '', 'redirect_type' => '301', 'destination_type' => 'ONE_SET', 'preset' => '', 'forward_url_params' => 1, 'no_global_tracking_code' => 0, 'expire_on' => '0000-00-00', 'created_on' => date('Y-m-d H:i:s'), 'is_trashed' => 0));
                                     $link->insert();
                                     $rule = new PMLC_Rule_Record(array('link_id' => $link->id, 'type' => 'ONE_SET', 'rule' => ''));
                                     $rule->insert();
                                     $dest = new PMLC_Destination_Record(array('rule_id' => $rule->id, 'url' => $url, 'weight' => 100));
                                     $dest->insert();
                                 } else {
                                     $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: Unable to create cloaked link for %s', 'wp_all_import_plugin'), $url));
                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                     $link = NULL;
                                 }
                             }
                             if ($link) {
                                 // cloaked link is found or created for url
                                 $articleData['post_content'] = preg_replace('%' . preg_quote($url, '%') . '(?=([\\s\'"]|$))%i', $link->getUrl(), $articleData['post_content']);
                             }
                         }
                     }
                 }
             }
             // insert article being imported
             if ($this->options['is_fast_mode']) {
                 foreach (array('transition_post_status', 'save_post', 'pre_post_update', 'add_attachment', 'edit_attachment', 'edit_post', 'post_updated', 'wp_insert_post', 'save_post_' . $post_type[$i]) as $act) {
                     remove_all_actions($act);
                 }
             }
             if (!in_array($this->options['custom_type'], array('import_users'))) {
                 if (empty($articleData['ID'])) {
                     $logger and call_user_func($logger, sprintf(__('<b>CREATING</b> `%s` `%s`', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name));
                 } else {
                     $logger and call_user_func($logger, sprintf(__('<b>UPDATING</b> `%s` `%s`', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name));
                 }
                 $pid = wp_insert_post($articleData, true);
             } else {
                 $pid = empty($articleData['ID']) ? wp_insert_user($articleData) : wp_update_user($articleData);
                 $articleData['post_title'] = $articleData['user_login'];
             }
             if (is_wp_error($pid)) {
                 $logger and call_user_func($logger, __('<b>ERROR</b>', 'wp_all_import_plugin') . ': ' . $pid->get_error_message());
                 $logger and !$is_cron and PMXI_Plugin::$session->errors++;
                 $skipped++;
             } else {
                 if ("manual" != $this->options['duplicate_matching'] or empty($articleData['ID'])) {
                     // associate post with import
                     $postRecord->isEmpty() and $postRecord->set(array('post_id' => $pid, 'import_id' => $this->id, 'unique_key' => $unique_keys[$i], 'product_key' => ($post_type[$i] == "product" and PMXI_Admin_Addons::get_addon('PMWI_Plugin')) ? $addons_data['PMWI_Plugin']['single_product_ID'][$i] : ''))->insert();
                     $postRecord->set(array('iteration' => $this->iteration))->update();
                     $logger and call_user_func($logger, sprintf(__('Associate post `%s` with current import ...', 'wp_all_import_plugin'), $articleData['post_title']));
                 }
                 // [post format]
                 if (current_theme_supports('post-formats') && post_type_supports($post_type[$i], 'post-formats')) {
                     set_post_format($pid, "xpath" == $this->options['post_format'] ? $post_format[$i] : $this->options['post_format']);
                     $logger and call_user_func($logger, sprintf(__('Associate post `%s` with post format %s ...', 'wp_all_import_plugin'), $articleData['post_title'], "xpath" == $this->options['post_format'] ? $post_format[$i] : $this->options['post_format']));
                 }
                 // [/post format]
                 // [addons import]
                 // prepare data for import
                 $importData = array('pid' => $pid, 'i' => $i, 'import' => $this, 'articleData' => $articleData, 'xml' => $xml, 'is_cron' => $is_cron, 'logger' => $logger, 'xpath_prefix' => $xpath_prefix, 'post_type' => $post_type[$i]);
                 $import_functions = apply_filters('wp_all_import_addon_import', array());
                 // deligate operation to addons
                 foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
                     if (class_exists($class)) {
                         if (method_exists($addons[$class], 'import')) {
                             $addons[$class]->import($importData);
                         }
                     } else {
                         if (!empty($import_functions[$class])) {
                             if (is_array($import_functions[$class]) and is_callable($import_functions[$class]) or !is_array($import_functions[$class]) and function_exists($import_functions[$class])) {
                                 call_user_func($import_functions[$class], $importData, $addons_data[$class]);
                             }
                         }
                     }
                 }
                 // [/addons import]
                 // Page Template
                 if ('page' == $articleData['post_type'] and wp_all_import_is_update_cf('_wp_page_template', $this->options) and (!empty($this->options['page_template']) or "no" == $this->options['is_multiple_page_template'])) {
                     update_post_meta($pid, '_wp_page_template', "no" == $this->options['is_multiple_page_template'] ? $page_template[$i] : $this->options['page_template']);
                 }
                 // [featured image]
                 $is_allow_import_images = apply_filters('wp_all_import_is_allow_import_images', false, $articleData['post_type']);
                 if (!empty($uploads) and false === $uploads['error'] and ($articleData['post_type'] == "product" and class_exists('PMWI_Plugin') or $is_allow_import_images) and (empty($articleData['ID']) or $this->options['update_all_data'] == "yes" or $this->options['update_all_data'] == "no" and $this->options['is_update_images'])) {
                     if (!empty($images_bundle)) {
                         $is_show_add_new_images = apply_filters('wp_all_import_is_show_add_new_images', true, $post_type[$i]);
                         foreach ($images_bundle as $slug => $bundle_data) {
                             $featured_images = $bundle_data['files'];
                             $option_slug = $slug == 'pmxi_gallery_image' ? '' : $slug;
                             if (!empty($featured_images[$i])) {
                                 $targetDir = $uploads['path'];
                                 $targetUrl = $uploads['url'];
                                 $logger and call_user_func($logger, __('<b>IMAGES:</b>', 'wp_all_import_plugin'));
                                 if (!@is_writable($targetDir)) {
                                     $logger and call_user_func($logger, sprintf(__('<b>ERROR</b>: Target directory %s is not writable', 'wp_all_import_plugin'), $targetDir));
                                 } else {
                                     require_once ABSPATH . 'wp-admin/includes/image.php';
                                     $success_images = false;
                                     $gallery_attachment_ids = array();
                                     $imgs = array();
                                     $featured_delim = "yes" == $this->options[$option_slug . 'download_images'] ? $this->options[$option_slug . 'download_featured_delim'] : $this->options[$option_slug . 'featured_delim'];
                                     $line_imgs = explode("\n", $featured_images[$i]);
                                     if (!empty($line_imgs)) {
                                         foreach ($line_imgs as $line_img) {
                                             $imgs = array_merge($imgs, !empty($featured_delim) ? str_getcsv($line_img, $featured_delim) : array($line_img));
                                         }
                                     }
                                     // keep existing and add newest images
                                     if (!empty($articleData['ID']) and $this->options['is_update_images'] and $this->options['update_images_logic'] == "add_new" and $this->options['update_all_data'] == "no" and $is_show_add_new_images) {
                                         $logger and call_user_func($logger, __('- Keep existing and add newest images ...', 'wp_all_import_plugin'));
                                         $attachment_imgs = get_attached_media('image', $pid);
                                         if ($post_type[$i] == "product") {
                                             $gallery_attachment_ids = array_filter(explode(",", get_post_meta($pid, '_product_image_gallery', true)));
                                         }
                                         if ($attachment_imgs) {
                                             foreach ($attachment_imgs as $attachment_img) {
                                                 $post_thumbnail_id = get_post_thumbnail_id($pid);
                                                 if (empty($post_thumbnail_id) and $this->options[$option_slug . 'is_featured']) {
                                                     set_post_thumbnail($pid, $attachment_img->ID);
                                                 } elseif (!in_array($attachment_img->ID, $gallery_attachment_ids) and $post_thumbnail_id != $attachment_img->ID) {
                                                     $gallery_attachment_ids[] = $attachment_img->ID;
                                                 }
                                             }
                                             $success_images = true;
                                         }
                                         if (!empty($gallery_attachment_ids)) {
                                             foreach ($gallery_attachment_ids as $aid) {
                                                 do_action($slug, $pid, $aid, wp_get_attachment_url($aid), 'update_images');
                                             }
                                         }
                                     }
                                     if (!empty($imgs)) {
                                         if ($this->options[$option_slug . 'set_image_meta_title'] and !empty($image_meta_titles_bundle[$slug])) {
                                             $img_titles = array();
                                             $line_img_titles = explode("\n", $image_meta_titles_bundle[$slug][$i]);
                                             if (!empty($line_img_titles)) {
                                                 foreach ($line_img_titles as $line_img_title) {
                                                     $img_titles = array_merge($img_titles, !empty($this->options[$option_slug . 'image_meta_title_delim']) ? str_getcsv($line_img_title, $this->options[$option_slug . 'image_meta_title_delim']) : array($line_img_title));
                                                 }
                                             }
                                         }
                                         if ($this->options[$option_slug . 'set_image_meta_caption'] and !empty($image_meta_captions_bundle[$slug])) {
                                             $img_captions = array();
                                             $line_img_captions = explode("\n", $image_meta_captions_bundle[$slug][$i]);
                                             if (!empty($line_img_captions)) {
                                                 foreach ($line_img_captions as $line_img_caption) {
                                                     $img_captions = array_merge($img_captions, !empty($this->options[$option_slug . 'image_meta_caption_delim']) ? str_getcsv($line_img_caption, $this->options[$option_slug . 'image_meta_caption_delim']) : array($line_img_caption));
                                                 }
                                             }
                                         }
                                         if ($this->options[$option_slug . 'set_image_meta_alt'] and !empty($image_meta_alts_bundle[$slug])) {
                                             $img_alts = array();
                                             $line_img_alts = explode("\n", $image_meta_alts_bundle[$slug][$i]);
                                             if (!empty($line_img_alts)) {
                                                 foreach ($line_img_alts as $line_img_alt) {
                                                     $img_alts = array_merge($img_alts, !empty($this->options[$option_slug . 'image_meta_alt_delim']) ? str_getcsv($line_img_alt, $this->options[$option_slug . 'image_meta_alt_delim']) : array($line_img_alt));
                                                 }
                                             }
                                         }
                                         if ($this->options[$option_slug . 'set_image_meta_description'] and !empty($image_meta_descriptions_bundle[$slug])) {
                                             $img_descriptions = array();
                                             $line_img_descriptions = explode("\n", $image_meta_descriptions_bundle[$slug][$i]);
                                             if (!empty($line_img_descriptions)) {
                                                 foreach ($line_img_descriptions as $line_img_description) {
                                                     $img_descriptions = array_merge($img_descriptions, !empty($this->options[$option_slug . 'image_meta_description_delim']) ? str_getcsv($line_img_description, $this->options[$option_slug . 'image_meta_description_delim']) : array($line_img_description));
                                                 }
                                             }
                                         }
                                         $is_keep_existing_images = (!empty($articleData['ID']) and $this->options['is_update_images'] and $this->options['update_images_logic'] == "add_new" and $this->options['update_all_data'] == "no" and $is_show_add_new_images);
                                         foreach ($imgs as $k => $img_url) {
                                             if (empty($img_url)) {
                                                 continue;
                                             }
                                             $attid = false;
                                             $attch = null;
                                             $url = str_replace(" ", "%20", trim($img_url));
                                             $bn = basename($url);
                                             if ("yes" == $this->options[$option_slug . 'download_images'] and !empty($auto_extensions_bundle[$slug][$i]) and preg_match('%^(jpg|jpeg|png|gif)$%i', $auto_extensions_bundle[$slug][$i])) {
                                                 $img_ext = $auto_extensions_bundle[$slug][$i];
                                             } else {
                                                 $img_ext = pmxi_getExtensionFromStr($url);
                                                 $default_extension = pmxi_getExtension($bn);
                                                 if ($img_ext == "") {
                                                     $img_ext = pmxi_get_remote_image_ext($url);
                                                 }
                                             }
                                             $logger and call_user_func($logger, sprintf(__('- Importing image `%s` for `%s` ...', 'wp_all_import_plugin'), $img_url, $articleData['post_title']));
                                             // generate local file name
                                             $image_name = urldecode(($this->options[$option_slug . 'auto_rename_images'] and !empty($auto_rename_images_bundle[$slug][$i])) ? sanitize_file_name($img_ext ? str_replace("." . $default_extension, "", $auto_rename_images_bundle[$slug][$i]) : $auto_rename_images_bundle[$slug][$i]) : sanitize_file_name($img_ext ? str_replace("." . $default_extension, "", $bn) : $bn)) . ("" != $img_ext ? '.' . $img_ext : '');
                                             // if wizard store image data to custom field
                                             $create_image = false;
                                             $download_image = true;
                                             $wp_filetype = false;
                                             if ($bundle_data['type'] == 'images' and base64_decode($url, true) !== false) {
                                                 $img = @imagecreatefromstring(base64_decode($url));
                                                 if ($img) {
                                                     $logger and call_user_func($logger, __('- Founded base64_encoded image', 'wp_all_import_plugin'));
                                                     $image_filename = md5(time()) . '.jpg';
                                                     $image_filepath = $targetDir . '/' . $image_filename;
                                                     imagejpeg($img, $image_filepath);
                                                     if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                                                         $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $image_filepath));
                                                         $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                     } else {
                                                         $create_image = true;
                                                     }
                                                 }
                                             } else {
                                                 $image_filename = wp_unique_filename($targetDir, $image_name);
                                                 $image_filepath = $targetDir . '/' . $image_filename;
                                                 // keep existing and add newest images
                                                 if ($is_keep_existing_images) {
                                                     $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_parent = %d;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", $pid));
                                                     if ($attch != null) {
                                                         $post_thumbnail_id = get_post_thumbnail_id($pid);
                                                         if ($post_thumbnail_id == $attch->ID or in_array($attch->ID, $gallery_attachment_ids)) {
                                                             continue;
                                                         }
                                                     } elseif (file_exists($targetDir . '/' . $image_name)) {
                                                         if ($bundle_data['type'] == 'images' and $img_meta = wp_read_image_metadata($targetDir . '/' . $image_name)) {
                                                             if (trim($img_meta['title']) && !is_numeric(sanitize_title($img_meta['title']))) {
                                                                 $img_title = $img_meta['title'];
                                                                 $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE post_title = %s AND post_type = %s AND post_parent = %d;", $img_title, "attachment", $pid));
                                                                 if ($attch != null) {
                                                                     $post_thumbnail_id = get_post_thumbnail_id($pid);
                                                                     if ($post_thumbnail_id == $attch->ID or in_array($attch->ID, $gallery_attachment_ids)) {
                                                                         continue;
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                                 // search existing attachment
                                                 if ($this->options[$option_slug . 'search_existing_images']) {
                                                     $image_filename = $image_name;
                                                     $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment"));
                                                     if ($attch != null) {
                                                         $download_image = false;
                                                         $attid = $attch->ID;
                                                     } elseif (@file_exists($targetDir . '/' . $image_name)) {
                                                         if ($bundle_data['type'] == 'images' and $img_meta = wp_read_image_metadata($targetDir . '/' . $image_name)) {
                                                             if (trim($img_meta['title']) && !is_numeric(sanitize_title($img_meta['title']))) {
                                                                 $img_title = $img_meta['title'];
                                                                 $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE post_title = %s AND post_type = %s AND post_parent = %d;", $img_title, "attachment", $pid));
                                                                 if ($attch != null) {
                                                                     $download_image = false;
                                                                     $attid = $attch->ID;
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                                 if ($download_image) {
                                                     // do not download images
                                                     if ("yes" != $this->options[$option_slug . 'download_images']) {
                                                         $image_filename = $image_name;
                                                         $image_filepath = $targetDir . '/' . $image_filename;
                                                         $wpai_uploads = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR;
                                                         $wpai_image_path = $wpai_uploads . str_replace('%20', ' ', $url);
                                                         $logger and call_user_func($logger, sprintf(__('- Searching for existing image `%s` in `%s` folder', 'wp_all_import_plugin'), $wpai_image_path, $wpai_uploads));
                                                         if (@file_exists($wpai_image_path) and @copy($wpai_image_path, $image_filepath)) {
                                                             $download_image = false;
                                                             // valdate import attachments
                                                             if ($bundle_data['type'] == 'files') {
                                                                 if (!($wp_filetype = wp_check_filetype(basename($image_filepath), null))) {
                                                                     $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($image_filepath)));
                                                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                     @unlink($image_filepath);
                                                                 } else {
                                                                     $create_image = true;
                                                                     $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully founded', 'wp_all_import_plugin'), $wpai_image_path));
                                                                 }
                                                             } elseif ($bundle_data['type'] == 'images') {
                                                                 if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                                                                     $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $image_filepath));
                                                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                     @unlink($image_filepath);
                                                                 } else {
                                                                     $create_image = true;
                                                                     $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully founded', 'wp_all_import_plugin'), $wpai_image_path));
                                                                 }
                                                             }
                                                         }
                                                     } else {
                                                         $logger and call_user_func($logger, sprintf(__('- Downloading image from `%s`', 'wp_all_import_plugin'), $url));
                                                         $request = get_file_curl($url, $image_filepath);
                                                         if ((is_wp_error($request) or $request === false) and !@file_put_contents($image_filepath, @file_get_contents($url))) {
                                                             @unlink($image_filepath);
                                                             // delete file since failed upload may result in empty file created
                                                         } else {
                                                             if ($bundle_data['type'] == 'images') {
                                                                 if ($image_info = @getimagesize($image_filepath) and in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                                                                     $create_image = true;
                                                                     $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                                                                 }
                                                             } elseif ($bundle_data['type'] == 'files') {
                                                                 if ($wp_filetype = wp_check_filetype(basename($image_filepath), null)) {
                                                                     $create_image = true;
                                                                     $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                                                                 }
                                                             }
                                                         }
                                                         if (!$create_image) {
                                                             $url = str_replace(" ", "%20", trim(pmxi_convert_encoding($img_url)));
                                                             $request = get_file_curl($url, $image_filepath);
                                                             if ((is_wp_error($request) or $request === false) and !@file_put_contents($image_filepath, @file_get_contents($url))) {
                                                                 $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s cannot be saved locally as %s', 'wp_all_import_plugin'), $url, $image_filepath));
                                                                 $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                 @unlink($image_filepath);
                                                                 // delete file since failed upload may result in empty file created
                                                             } else {
                                                                 if ($bundle_data['type'] == 'images') {
                                                                     if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
                                                                         $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $url));
                                                                         $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                         @unlink($image_filepath);
                                                                     } else {
                                                                         $create_image = true;
                                                                         $logger and call_user_func($logger, sprintf(__('- Image `%s` has been successfully downloaded', 'wp_all_import_plugin'), $url));
                                                                     }
                                                                 } elseif ($bundle_data['type'] == 'files') {
                                                                     if (!($wp_filetype = wp_check_filetype(basename($image_filepath), null))) {
                                                                         $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($url)));
                                                                         $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                                         @unlink($image_filepath);
                                                                     } else {
                                                                         $create_image = true;
                                                                         $logger and call_user_func($logger, sprintf(__('- File `%s` has been successfully founded', 'wp_all_import_plugin'), $url));
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                             if ($create_image) {
                                                 $logger and call_user_func($logger, sprintf(__('- Creating an attachment for image `%s`', 'wp_all_import_plugin'), $targetUrl . '/' . $image_filename));
                                                 $attachment = array('post_mime_type' => $bundle_data['type'] == 'images' ? image_type_to_mime_type($image_info[2]) : $wp_filetype['type'], 'guid' => $targetUrl . '/' . $image_filename, 'post_title' => $image_name, 'post_content' => '', 'post_author' => $post_author[$i]);
                                                 if ($bundle_data['type'] == 'images' and $image_meta = wp_read_image_metadata($image_filepath)) {
                                                     if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
                                                         $attachment['post_title'] = $image_meta['title'];
                                                     }
                                                     if (trim($image_meta['caption'])) {
                                                         $attachment['post_content'] = $image_meta['caption'];
                                                     }
                                                 }
                                                 $attid = wp_insert_attachment($attachment, $image_filepath, $pid);
                                                 if (is_wp_error($attid)) {
                                                     $logger and call_user_func($logger, __('- <b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $attid->get_error_message());
                                                     $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                                 } else {
                                                     // you must first include the image.php file
                                                     // for the function wp_generate_attachment_metadata() to work
                                                     require_once ABSPATH . 'wp-admin/includes/image.php';
                                                     wp_update_attachment_metadata($attid, wp_generate_attachment_metadata($attid, $image_filepath));
                                                     $update_attachment_meta = array();
                                                     if ($this->options[$option_slug . 'set_image_meta_title'] and !empty($img_titles[$k])) {
                                                         $update_attachment_meta['post_title'] = $img_titles[$k];
                                                     }
                                                     if ($this->options[$option_slug . 'set_image_meta_caption'] and !empty($img_captions[$k])) {
                                                         $update_attachment_meta['post_excerpt'] = $img_captions[$k];
                                                     }
                                                     if ($this->options[$option_slug . 'set_image_meta_description'] and !empty($img_descriptions[$k])) {
                                                         $update_attachment_meta['post_content'] = $img_descriptions[$k];
                                                     }
                                                     if ($this->options[$option_slug . 'set_image_meta_alt'] and !empty($img_alts[$k])) {
                                                         update_post_meta($attid, '_wp_attachment_image_alt', $img_alts[$k]);
                                                     }
                                                     if (!empty($update_attachment_meta)) {
                                                         $this->wpdb->update($this->wpdb->posts, $update_attachment_meta, array('ID' => $attid));
                                                     }
                                                 }
                                             }
                                             if ($attid) {
                                                 if ($attch != null and empty($attch->post_parent)) {
                                                     wp_update_post(array('ID' => $attch->ID, 'post_parent' => $pid));
                                                 }
                                                 $logger and call_user_func($logger, __('- <b>ACTION</b>: ' . $slug, 'wp_all_import_plugin'));
                                                 do_action($slug, $pid, $attid, $image_filepath, $is_keep_existing_images ? 'add_images' : 'update_images');
                                                 $success_images = true;
                                                 $post_thumbnail_id = get_post_thumbnail_id($pid);
                                                 if ($bundle_data['type'] == 'images' and empty($post_thumbnail_id) and $this->options[$option_slug . 'is_featured']) {
                                                     set_post_thumbnail($pid, $attid);
                                                 } elseif (!in_array($attid, $gallery_attachment_ids) and $post_thumbnail_id != $attid) {
                                                     $gallery_attachment_ids[] = $attid;
                                                 }
                                                 $logger and call_user_func($logger, sprintf(__('- Attachment has been successfully created for image `%s`', 'wp_all_import_plugin'), $targetUrl . '/' . $image_filename));
                                             }
                                         }
                                     }
                                     // Set product gallery images
                                     if ($post_type[$i] == "product") {
                                         update_post_meta($pid, '_product_image_gallery', !empty($gallery_attachment_ids) ? implode(',', $gallery_attachment_ids) : '');
                                     }
                                     // Create entry as Draft if no images are downloaded successfully
                                     if (!$success_images and "yes" == $this->options[$option_slug . 'create_draft']) {
                                         $this->wpdb->update($this->wpdb->posts, array('post_status' => 'draft'), array('ID' => $pid));
                                         $logger and call_user_func($logger, sprintf(__('- Post `%s` saved as Draft, because no images are downloaded successfully', 'wp_all_import_plugin'), $articleData['post_title']));
                                     }
                                 }
                             } else {
                                 // Create entry as Draft if no images are downloaded successfully
                                 if ("yes" == $this->options[$option_slug . 'create_draft']) {
                                     $this->wpdb->update($this->wpdb->posts, array('post_status' => 'draft'), array('ID' => $pid));
                                     $logger and call_user_func($logger, sprintf(__('Post `%s` saved as Draft, because no images are downloaded successfully', 'wp_all_import_plugin'), $articleData['post_title']));
                                 }
                             }
                         }
                     }
                 } else {
                     if (!empty($images_bundle)) {
                         foreach ($images_bundle as $slug => $bundle_data) {
                             if (!empty($bundle_data['images'][$i])) {
                                 $imgs = array();
                                 $featured_delim = "yes" == $this->options[$option_slug . 'download_images'] ? $this->options[$option_slug . 'download_featured_delim'] : $this->options[$option_slug . 'featured_delim'];
                                 $line_imgs = explode("\n", $bundle_data['images'][$i]);
                                 if (!empty($line_imgs)) {
                                     foreach ($line_imgs as $line_img) {
                                         $imgs = array_merge($imgs, !empty($featured_delim) ? str_getcsv($line_img, $featured_delim) : array($line_img));
                                     }
                                 }
                                 foreach ($imgs as $img) {
                                     do_action($slug, $pid, false, $img, false);
                                 }
                             }
                         }
                     }
                 }
                 // [/featured image]
                 // [attachments]
                 if (!empty($uploads) and false === $uploads['error'] and !empty($attachments[$i]) and (empty($articleData['ID']) or $this->options['update_all_data'] == "yes" or $this->options['update_all_data'] == "no" and $this->options['is_update_attachments'])) {
                     $targetDir = $uploads['path'];
                     $targetUrl = $uploads['url'];
                     $logger and call_user_func($logger, __('<b>ATTACHMENTS:</b>', 'wp_all_import_plugin'));
                     if (!@is_writable($targetDir)) {
                         $logger and call_user_func($logger, sprintf(__('- <b>ERROR</b>: Target directory %s is not writable', 'wp_all_import_plugin'), trim($targetDir)));
                     } else {
                         // you must first include the image.php file
                         // for the function wp_generate_attachment_metadata() to work
                         require_once ABSPATH . 'wp-admin/includes/image.php';
                         if (!is_array($attachments[$i])) {
                             $attachments[$i] = array($attachments[$i]);
                         }
                         $logger and call_user_func($logger, sprintf(__('- Importing attachments for `%s` ...', 'wp_all_import_plugin'), $articleData['post_title']));
                         foreach ($attachments[$i] as $attachment) {
                             if ("" == $attachment) {
                                 continue;
                             }
                             $atchs = str_getcsv($attachment, $this->options['atch_delim']);
                             if (!empty($atchs)) {
                                 foreach ($atchs as $atch_url) {
                                     if (empty($atch_url)) {
                                         continue;
                                     }
                                     $download_file = true;
                                     $atch_url = str_replace(" ", "%20", trim($atch_url));
                                     $attachment_filename = urldecode(basename(parse_url(trim($atch_url), PHP_URL_PATH)));
                                     $attachment_filepath = $targetDir . '/' . sanitize_file_name($attachment_filename);
                                     if ($this->options['is_search_existing_attach']) {
                                         // search existing attachment
                                         $attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s OR post_name = %s) AND post_type = %s;", $attachment_filename, preg_replace('/\\.[^.\\s]{3,4}$/', '', $attachment_filename), sanitize_title($attachment_filename), sanitize_title(preg_replace('/\\.[^.\\s]{3,4}$/', '', $attachment_filename)), "attachment"));
                                         if ($attch != null) {
                                             $download_file = false;
                                             $attach_id = $attch->ID;
                                         }
                                     }
                                     if ($download_file) {
                                         $attachment_filename = wp_unique_filename($targetDir, $attachment_filename);
                                         $attachment_filepath = $targetDir . '/' . sanitize_file_name($attachment_filename);
                                         $logger and call_user_func($logger, sprintf(__('- Filename for attachment was generated as %s', 'wp_all_import_plugin'), $attachment_filename));
                                         $request = get_file_curl(trim($atch_url), $attachment_filepath);
                                         if ((is_wp_error($request) or $request === false) and !@file_put_contents($attachment_filepath, @file_get_contents(trim($atch_url)))) {
                                             $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Attachment file %s cannot be saved locally as %s', 'wp_all_import_plugin'), trim($atch_url), $attachment_filepath));
                                             is_wp_error($request) and $logger and call_user_func($logger, sprintf(__('- <b>WP Error</b>: %s', 'wp_all_import_plugin'), $request->get_error_message()));
                                             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                             unlink($attachment_filepath);
                                             // delete file since failed upload may result in empty file created
                                         } elseif (!($wp_filetype = wp_check_filetype(basename($attachment_filename), null))) {
                                             $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($atch_url)));
                                             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                         } else {
                                             $logger and call_user_func($logger, sprintf(__('- File %s has been successfully downloaded', 'wp_all_import_plugin'), $atch_url));
                                             $attachment_data = array('guid' => $targetUrl . '/' . basename($attachment_filepath), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($attachment_filepath)), 'post_content' => '', 'post_status' => 'inherit', 'post_author' => $post_author[$i]);
                                             $attach_id = wp_insert_attachment($attachment_data, $attachment_filepath, $pid);
                                             if (is_wp_error($attach_id)) {
                                                 $logger and call_user_func($logger, __('- <b>WARNING</b>', 'wp_all_import_plugin') . ': ' . $pid->get_error_message());
                                                 $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                             } else {
                                                 wp_update_attachment_metadata($attach_id, wp_generate_attachment_metadata($attach_id, $attachment_filepath));
                                                 $logger and call_user_func($logger, sprintf(__('- Attachment has been successfully created for post `%s`', 'wp_all_import_plugin'), $articleData['post_title']));
                                                 $logger and call_user_func($logger, __('- <b>ACTION</b>: pmxi_attachment_uploaded', 'wp_all_import_plugin'));
                                                 do_action('pmxi_attachment_uploaded', $pid, $attach_id, $attachment_filepath);
                                             }
                                         }
                                     } else {
                                         $logger and call_user_func($logger, __('- <b>ACTION</b>: pmxi_attachment_uploaded', 'wp_all_import_plugin'));
                                         do_action('pmxi_attachment_uploaded', $pid, $attach_id, $attachment_filepath);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 // [/attachments]
                 // [custom taxonomies]
                 if (!empty($taxonomies)) {
                     $logger and call_user_func($logger, __('<b>TAXONOMIES:</b>', 'wp_all_import_plugin'));
                     foreach ($taxonomies as $tx_name => $txes) {
                         // Skip updating product attributes
                         if (PMXI_Admin_Addons::get_addon('PMWI_Plugin') and strpos($tx_name, "pa_") === 0) {
                             continue;
                         }
                         if (empty($articleData['ID']) or $this->options['update_all_data'] == "yes" or $this->options['update_all_data'] == "no" and $this->options['is_update_categories']) {
                             $logger and call_user_func($logger, sprintf(__('- Importing taxonomy `%s` ...', 'wp_all_import_plugin'), $tx_name));
                             if (!empty($this->options['tax_logic'][$tx_name]) and $this->options['tax_logic'][$tx_name] == 'hierarchical' and !empty($this->options['tax_hierarchical_logic'][$tx_name]) and $this->options['tax_hierarchical_logic'][$tx_name] == 'entire') {
                                 $logger and call_user_func($logger, sprintf(__('- Auto-nest enabled with separator `%s` ...', 'wp_all_import_plugin'), !empty($this->options['tax_hierarchical_delim'][$tx_name]) ? $this->options['tax_hierarchical_delim'][$tx_name] : ','));
                             }
                             if (!empty($articleData['ID'])) {
                                 if ($this->options['update_all_data'] == "no" and $this->options['update_categories_logic'] == "all_except" and !empty($this->options['taxonomies_list']) and is_array($this->options['taxonomies_list']) and in_array($tx_name, $this->options['taxonomies_list'])) {
                                     $logger and call_user_func($logger, sprintf(__('- %s %s `%s` has been skipped attempted to `Leave these taxonomies alone, update all others`...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name']));
                                     continue;
                                 }
                                 if ($this->options['update_all_data'] == "no" and $this->options['update_categories_logic'] == "only" and (!empty($this->options['taxonomies_list']) and is_array($this->options['taxonomies_list']) and !in_array($tx_name, $this->options['taxonomies_list']) or empty($this->options['taxonomies_list']))) {
                                     $logger and call_user_func($logger, sprintf(__('- %s %s `%s` has been skipped attempted to `Update only these taxonomies, leave the rest alone`...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name']));
                                     continue;
                                 }
                             }
                             $assign_taxes = array();
                             if ($this->options['update_categories_logic'] == "add_new" and !empty($existing_taxonomies[$tx_name][$i])) {
                                 $assign_taxes = $existing_taxonomies[$tx_name][$i];
                                 unset($existing_taxonomies[$tx_name][$i]);
                             } elseif (!empty($existing_taxonomies[$tx_name][$i])) {
                                 unset($existing_taxonomies[$tx_name][$i]);
                             }
                             // create term if not exists
                             if (!empty($txes[$i])) {
                                 foreach ($txes[$i] as $key => $single_tax) {
                                     $is_created_term = false;
                                     if (is_array($single_tax) and !empty($single_tax['name'])) {
                                         $parent_id = !empty($single_tax['parent']) ? pmxi_recursion_taxes($single_tax['parent'], $tx_name, $txes[$i], $key) : '';
                                         $term = empty($this->options['tax_is_full_search_' . $this->options['tax_logic'][$tx_name]][$tx_name]) ? term_exists($single_tax['name'], $tx_name, (int) $parent_id) : term_exists($single_tax['name'], $tx_name);
                                         if (empty($term) and !is_wp_error($term)) {
                                             $term = empty($this->options['tax_is_full_search_' . $this->options['tax_logic'][$tx_name]][$tx_name]) ? term_exists(htmlspecialchars($single_tax['name']), $tx_name, (int) $parent_id) : term_exists(htmlspecialchars($single_tax['name']), $tx_name);
                                             if (empty($term) and !is_wp_error($term)) {
                                                 $term_attr = array('parent' => !empty($parent_id) ? $parent_id : 0);
                                                 $term = wp_insert_term($single_tax['name'], $tx_name, $term_attr);
                                                 if (!is_wp_error($term)) {
                                                     $is_created_term = true;
                                                     if (empty($parent_id)) {
                                                         $logger and call_user_func($logger, sprintf(__('- Creating parent %s %s `%s` ...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name']));
                                                     } else {
                                                         $logger and call_user_func($logger, sprintf(__('- Creating child %s %s for %s named `%s` ...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, is_array($single_tax['parent']) ? $single_tax['parent']['name'] : $single_tax['parent'], $single_tax['name']));
                                                     }
                                                 }
                                             }
                                         }
                                         if (is_wp_error($term)) {
                                             $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: `%s`', 'wp_all_import_plugin'), $term->get_error_message()));
                                             $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
                                         } elseif (!empty($term)) {
                                             $cat_id = $term['term_id'];
                                             if ($cat_id and $single_tax['assign']) {
                                                 $term = get_term_by('id', $cat_id, $tx_name);
                                                 if ($term->parent != '0' and !empty($this->options['tax_is_full_search_' . $this->options['tax_logic'][$tx_name]][$tx_name]) and empty($this->options['tax_assign_to_one_term_' . $this->options['tax_logic'][$tx_name]][$tx_name])) {
                                                     $parent_ids = wp_all_import_get_parent_terms($cat_id, $tx_name);
                                                     if (!empty($parent_ids)) {
                                                         foreach ($parent_ids as $p) {
                                                             if (!in_array($p, $assign_taxes)) {
                                                                 $assign_taxes[] = $p;
                                                             }
                                                         }
                                                     }
                                                 }
                                                 if (!in_array($term->term_taxonomy_id, $assign_taxes)) {
                                                     $assign_taxes[] = $term->term_taxonomy_id;
                                                 }
                                                 if (!$is_created_term) {
                                                     if (empty($parent_id)) {
                                                         $logger and call_user_func($logger, sprintf(__('- Attempted to create parent %s %s `%s`, duplicate detected. Importing %s to existing `%s` %s, ID %d, slug `%s` ...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name'], $custom_type_details->labels->singular_name, $term->name, $tx_name, $term->term_id, $term->slug));
                                                     } else {
                                                         $logger and call_user_func($logger, sprintf(__('- Attempted to create child %s %s `%s`, duplicate detected. Importing %s to existing `%s` %s, ID %d, slug `%s` ...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name'], $custom_type_details->labels->singular_name, $term->name, $tx_name, $term->term_id, $term->slug));
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             // associate taxes with post
                             $this->associate_terms($pid, empty($assign_taxes) ? false : $assign_taxes, $tx_name, $logger, $is_cron);
                         } else {
                             $logger and call_user_func($logger, sprintf(__('- %s %s `%s` has been skipped attempted to `Do not update Taxonomies (incl. Categories and Tags)`...', 'wp_all_import_plugin'), $custom_type_details->labels->singular_name, $tx_name, $single_tax['name']));
                         }
                     }
                     if ($this->options['update_all_data'] == "no" and ($this->options['is_update_categories'] and $this->options['update_categories_logic'] != 'full_update' or !$this->options['is_update_categories'] and (is_object_in_taxonomy($post_type[$i], 'category') or is_object_in_taxonomy($post_type[$i], 'post_tag')))) {
                         if (!empty($existing_taxonomies)) {
                             foreach ($existing_taxonomies as $tx_name => $txes) {
                                 // Skip updating product attributes
                                 if (PMXI_Admin_Addons::get_addon('PMWI_Plugin') and strpos($tx_name, "pa_") === 0) {
                                     continue;
                                 }
                                 if (!empty($txes[$i])) {
                                     $this->associate_terms($pid, $txes[$i], $tx_name, $logger, $is_cron);
                                 }
                             }
                         }
                     }
                 }
                 // [/custom taxonomies]
                 if (empty($articleData['ID'])) {
                     $logger and call_user_func($logger, sprintf(__('<b>CREATED</b> `%s` `%s` (ID: %s)', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name, $pid));
                 } else {
                     $logger and call_user_func($logger, sprintf(__('<b>UPDATED</b> `%s` `%s` (ID: %s)', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name, $pid));
                 }
                 // fire important hooks after custom fields are added
                 if (!$this->options['is_fast_mode'] and $this->options['custom_type'] != 'import_users') {
                     $post_object = get_post($pid);
                     $is_update = !empty($articleData['ID']);
                     do_action("save_post_" . $articleData['post_type'], $pid, $post_object, $is_update);
                     do_action('save_post', $pid, $post_object, $is_update);
                     do_action('wp_insert_post', $pid, $post_object, $is_update);
                 }
                 // [addons import]
                 // prepare data for import
                 $importData = array('pid' => $pid, 'import' => $this, 'logger' => $logger);
                 $saved_functions = apply_filters('wp_all_import_addon_saved_post', array());
                 // deligate operation to addons
                 foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
                     if (class_exists($class)) {
                         if (method_exists($addons[$class], 'saved_post')) {
                             $addons[$class]->saved_post($importData);
                         }
                     } else {
                         if (!empty($saved_functions[$class])) {
                             if (is_array($saved_functions[$class]) and is_callable($saved_functions[$class]) or !is_array($saved_functions[$class]) and function_exists($saved_functions[$class])) {
                                 call_user_func($saved_functions[$class], $importData);
                             }
                         }
                     }
                 }
                 // [/addons import]
                 $logger and call_user_func($logger, __('<b>ACTION</b>: pmxi_saved_post', 'wp_all_import_plugin'));
                 do_action('pmxi_saved_post', $pid, $rootNodes[$i]);
                 // hook that was triggered immediately after post saved
                 if (empty($articleData['ID'])) {
                     $created++;
                 } else {
                     $updated++;
                 }
                 if (!$is_cron and "default" == $this->options['import_processing']) {
                     $processed_records = $created + $updated + $skipped;
                     $logger and call_user_func($logger, sprintf(__('<span class="processing_info"><span class="created_count">%s</span><span class="updated_count">%s</span><span class="percents_count">%s</span></span>', 'wp_all_import_plugin'), $created, $updated, ceil($processed_records / $this->count * 100)));
                 }
             }
             $logger and call_user_func($logger, __('<b>ACTION</b>: pmxi_after_post_import', 'wp_all_import_plugin'));
             do_action('pmxi_after_post_import', $this->id);
             $logger and !$is_cron and PMXI_Plugin::$session->chunk_number++;
         }
         wp_cache_flush();
         $this->set(array('imported' => $created + $updated, 'created' => $created, 'updated' => $updated, 'skipped' => $skipped, 'last_activity' => date('Y-m-d H:i:s')))->update();
         if (!$is_cron) {
             PMXI_Plugin::$session->save_data();
             $records_count = $this->created + $this->updated + $this->skipped;
             $is_import_complete = $records_count == $this->count;
             // Delete posts that are no longer present in your file
             if ($is_import_complete and !empty($this->options['is_delete_missing']) and $this->options['duplicate_matching'] == 'auto') {
                 $logger and call_user_func($logger, __('Removing previously imported posts which are no longer actual...', 'wp_all_import_plugin'));
                 $postList = new PMXI_Post_List();
                 $missing_ids = array();
                 $missingPosts = $postList->getBy(array('import_id' => $this->id, 'iteration !=' => $this->iteration));
                 if (!$missingPosts->isEmpty()) {
                     foreach ($missingPosts as $missingPost) {
                         $missing_ids[] = $missingPost['post_id'];
                     }
                 }
                 // Delete posts from database
                 if (!empty($missing_ids) && is_array($missing_ids)) {
                     $logger and call_user_func($logger, __('<b>ACTION</b>: pmxi_delete_post', 'wp_all_import_plugin'));
                     $logger and call_user_func($logger, __('Deleting posts from database', 'wp_all_import_plugin'));
                     $missing_ids_arr = array_chunk($missing_ids, 100);
                     foreach ($missing_ids_arr as $key => $ids) {
                         if (!empty($ids)) {
                             foreach ($ids as $k => $id) {
                                 $to_delete = true;
                                 // Instead of deletion, set Custom Field
                                 if ($this->options['is_update_missing_cf']) {
                                     update_post_meta($id, $this->options['update_missing_cf_name'], $this->options['update_missing_cf_value']);
                                     $to_delete = false;
                                     $logger and call_user_func($logger, sprintf(__('Instead of deletion post with ID `%s`, set Custom Field `%s` to value `%s`', 'wp_all_import_plugin'), $id, $this->options['update_missing_cf_name'], $this->options['update_missing_cf_value']));
                                 }
                                 // Instead of deletion, change post status to Draft
                                 if ($this->options['set_missing_to_draft']) {
                                     $this->wpdb->update($this->wpdb->posts, array('post_status' => 'draft'), array('ID' => $id));
                                     $to_delete = false;
                                     $logger and call_user_func($logger, sprintf(__('Instead of deletion, change post with ID `%s` status to Draft', 'wp_all_import_plugin'), $id));
                                 }
                                 if ($to_delete) {
                                     // Remove attachments
                                     empty($this->options['is_keep_attachments']) and wp_delete_attachments($id, true, 'files');
                                     // Remove images
                                     empty($this->options['is_keep_imgs']) and wp_delete_attachments($id, true, 'images');
                                     // Clear post's relationships
                                     if ($post_type[$i] != "import_users") {
                                         wp_delete_object_term_relationships($id, get_object_taxonomies('' != $this->options['custom_type'] ? $this->options['custom_type'] : 'post'));
                                     }
                                 } else {
                                     unset($ids[$k]);
                                 }
                             }
                             if (!empty($ids)) {
                                 do_action('pmxi_delete_post', $ids);
                                 if ($this->options['custom_type'] == "import_users") {
                                     $sql = "delete a,b\n\t\t\t\t\t\t\t\t\t\tFROM " . $this->wpdb->users . " a\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . $this->wpdb->usermeta . " b ON ( a.ID = b.user_id )\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tWHERE a.ID IN (" . implode(',', $ids) . ");";
                                 } else {
                                     $sql = "delete a,b,c\n\t\t\t\t\t\t\t\t\t\tFROM " . $this->wpdb->posts . " a\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . $this->wpdb->term_relationships . " b ON ( a.ID = b.object_id )\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . $this->wpdb->postmeta . " c ON ( a.ID = c.post_id )\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tWHERE a.ID IN (" . implode(',', $ids) . ");";
                                 }
                                 $this->wpdb->query($sql);
                                 // Delete record form pmxi_posts
                                 $sql = "DELETE FROM " . PMXI_Plugin::getInstance()->getTablePrefix() . "posts WHERE post_id IN (" . implode(',', $ids) . ") AND import_id = %d";
                                 $this->wpdb->query($this->wpdb->prepare($sql, $this->id));
                                 $this->set(array('deleted' => $this->deleted + count($ids)))->update();
                             }
                         }
                     }
                 }
             }
             // Set out of stock status for missing records [Woocommerce add-on option]
             if ($is_import_complete and empty($this->options['is_delete_missing']) and $post_type[$i] == "product" and class_exists('PMWI_Plugin') and !empty($this->options['missing_records_stock_status'])) {
                 $logger and call_user_func($logger, __('Update stock status previously imported posts which are no longer actual...', 'wp_all_import_plugin'));
                 $postList = new PMXI_Post_List();
                 $missingPosts = $postList->getBy(array('import_id' => $this->id, 'iteration !=' => $this->iteration));
                 if (!$missingPosts->isEmpty()) {
                     foreach ($missingPosts as $missingPost) {
                         update_post_meta($missingPost['post_id'], '_stock_status', 'outofstock');
                         update_post_meta($missingPost['post_id'], '_stock', 0);
                         $missingPostRecord = new PMXI_Post_Record();
                         $missingPostRecord->getBy('id', $missingPost['id']);
                         if (!$missingPostRecord->isEmpty()) {
                             $missingPostRecord->set(array('iteration' => $this->iteration))->update();
                         }
                         unset($missingPostRecord);
                     }
                 }
             }
         }
     } catch (XmlImportException $e) {
         $logger and call_user_func($logger, __('<b>ERROR</b>', 'wp_all_import_plugin') . ': ' . $e->getMessage());
         $logger and !$is_cron and PMXI_Plugin::$session->errors++;
     }
     $logger and $is_import_complete and call_user_func($logger, __('Cleaning temporary data...', 'wp_all_import_plugin'));
     foreach ($tmp_files as $file) {
         // remove all temporary files created
         @unlink($file);
     }
     if (($is_cron or $is_import_complete) and $this->options['is_delete_source']) {
         $logger and call_user_func($logger, __('Deleting source XML file...', 'wp_all_import_plugin'));
         // Delete chunks
         foreach (PMXI_Helper::safe_glob($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . 'pmxi_chunk_*', PMXI_Helper::GLOB_RECURSE | PMXI_Helper::GLOB_PATH) as $filePath) {
             $logger and call_user_func($logger, __('Deleting chunks files...', 'wp_all_import_plugin'));
             @file_exists($filePath) and wp_all_import_remove_source($filePath, false);
         }
         if ($this->type != "ftp") {
             if (!@unlink($this->path)) {
                 $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: Unable to remove %s', 'wp_all_import_plugin'), $this->path));
             }
         } else {
             $file_path_array = PMXI_Helper::safe_glob($this->path, PMXI_Helper::GLOB_NODIR | PMXI_Helper::GLOB_PATH);
             if (!empty($file_path_array)) {
                 foreach ($file_path_array as $path) {
                     if (!@unlink($path)) {
                         $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: Unable to remove %s', 'wp_all_import_plugin'), $path));
                     }
                 }
             }
         }
     }
     if (!$is_cron and $is_import_complete) {
         $this->set(array('processing' => 0, 'triggered' => 0, 'queue_chunk_number' => 0, 'registered_on' => date('Y-m-d H:i:s'), 'iteration' => ++$this->iteration))->update();
         $logger and call_user_func($logger, 'Done');
     }
     remove_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html'));
     kses_init();
     // return any filtering rules back if they has been disabled for import procedure
     return $this;
 }