示例#1
0
 /**
  * @param $post_content
  * @param $postID
  * @return array
  */
 public function capture_all_shortcodes($post_content, $postID)
 {
     $result = array();
     $pattern = "/([WPIMPINLINE:([\\w]+)(.*?)(])/";
     $shortcode_prefix = "[WPIMPINLINE:";
     $post_content = str_replace("\n", "<br />", $post_content);
     preg_match_all($pattern, $post_content, $results, PREG_PATTERN_ORDER);
     $inlineimg_shortcodes = array();
     $inline_shortcode_count = 0;
     for ($i = 0; $i < count($results[0]); $i++) {
         $get_shortcode_pos = strpos($results[0][$i], $shortcode_prefix);
         $inlineimg_shortcodes[] = substr($results[0][$i], $get_shortcode_pos);
     }
     $inline_shortcode_count = count($inlineimg_shortcodes);
     if (!empty($inlineimg_shortcodes) && is_array($inlineimg_shortcodes)) {
         foreach ($inlineimg_shortcodes as $shortkey => $shortcode) {
             $get_inlineimage_val = substr($shortcode, "13", -1);
             $image_attribute = explode('|', $get_inlineimage_val);
             $get_inlineimage_val = $image_attribute[0];
             $uploadDir = wp_upload_dir();
             $inlineimageDir = $uploadDir['basedir'] . '/smack_inline_images';
             $inlineimageURL = $uploadDir['baseurl'] . '/smack_inline_images';
             $wp_media_url = $uploadDir['baseurl'];
             $get_media_settings = get_option('uploads_use_yearmonth_folders');
             if ($get_media_settings == 1) {
                 $dirname = date('Y') . '/' . date('m');
                 $full_path = $uploadDir['basedir'] . '/' . $dirname;
                 $baseurl = $uploadDir['baseurl'] . '/' . $dirname;
             } else {
                 $full_path = $uploadDir['basedir'];
                 $baseurl = $uploadDir['baseurl'];
             }
             $wp_media_path = $full_path;
             $eventKey = sanitize_text_field($_POST['postdata']['uploadedFile']);
             $inlineimageDirpath = $inlineimageDir . '/' . $eventKey;
             $imagelist = scanDirectories($inlineimageDirpath);
             $currentLoc = '';
             if (!$imagelist) {
                 $noimage = WP_CONST_ULTIMATE_CSV_IMP_DIR . "images/noimage.png";
                 $oldWord = $shortcode;
                 $newWord = '<img src="' . $noimage . '" />';
                 $post_content = str_replace($oldWord, $newWord, $post_content);
                 $result['post_content'] = $post_content;
                 $result['inlineimage_shortcode'] = "No-Image-count:" . $inline_shortcode_count;
             } else {
                 if (!empty($imagelist)) {
                     foreach ($imagelist as $imgwithloc) {
                         if (strpos($imgwithloc, $get_inlineimage_val)) {
                             $currentLoc = $imgwithloc;
                         }
                     }
                 }
                 $exploded_currentLoc = explode("{$eventKey}", $currentLoc);
                 if (!empty($exploded_currentLoc) && isset($exploded_currentLoc[1])) {
                     $inlimg_curr_loc = $exploded_currentLoc[1];
                 } else {
                     $inlimg_curr_loc = '';
                 }
                 $inlineimageURL = $inlineimageURL . '/' . $eventKey . $inlimg_curr_loc;
                 $helperObj = new WPImporter_includes_helper();
                 $helperObj->get_fimg_from_URL($inlineimageURL, $wp_media_path, $get_inlineimage_val, '', '', '');
                 $wp_media_path = $wp_media_path . "/" . $get_inlineimage_val;
                 if (@getimagesize($wp_media_path)) {
                     $img = wp_get_image_editor($wp_media_path);
                     if (!is_wp_error($img)) {
                         $sizes_array = array(array('width' => 1024, 'height' => 768, 'crop' => true), array('width' => 100, 'height' => 100, 'crop' => false), array('width' => 300, 'height' => 100, 'crop' => false), array('width' => 624, 'height' => 468, 'crop' => false));
                         $resize = $img->multi_resize($sizes_array);
                     }
                     $get_inline_guid = str_replace(' ', '-', $get_inlineimage_val);
                     $inline_file['guid'] = $baseurl . "/" . $get_inlineimage_val;
                     $inline_file['post_title'] = $get_inlineimage_val;
                     $inline_file['post_content'] = '';
                     $inline_file['post_status'] = 'attachment';
                     $wp_upload_dir = wp_upload_dir();
                     $attachment = array('guid' => $inline_file['guid'], 'post_mime_type' => 'image/jpeg', 'post_title' => preg_replace('/\\.[^.]+$/', '', @basename($inline_file['guid'])), 'post_content' => '', 'post_status' => 'inherit');
                     if ($get_media_settings == 1) {
                         $generate_attachment = $dirname . '/' . $get_inline_guid;
                     } else {
                         $generate_attachment = $get_inline_guid;
                     }
                     $uploadedImage = $wp_upload_dir['path'] . '/' . $get_inlineimage_val;
                     //duplicate check
                     global $wpdb;
                     $existing_attachment = array();
                     //$query = $wpdb->get_results("select post_title from $wpdb->posts where post_type = 'attachment' and post_mime_type = 'image/jpeg'");
                     $query = $wpdb->get_results($wpdb->prepare("select post_title from {$wpdb->posts} where post_type = %s and post_mime_type = %s", 'attachment', 'image/jpeg'));
                     if (!empty($query)) {
                         foreach ($query as $key) {
                             $existing_attachment[] = $key->post_title;
                         }
                     }
                     //duplicate check
                     if (!in_array($attachment['post_title'], $existing_attachment)) {
                         $attach_id = wp_insert_attachment($attachment, $generate_attachment, $postID);
                         $attach_data = wp_generate_attachment_metadata($attach_id, $uploadedImage);
                         wp_update_attachment_metadata($attach_id, $attach_data);
                         //set_post_thumbnail($postID, $attach_id);
                     }
                     // if($shortcode_mode == 'Inline') {
                     $oldWord = $shortcode;
                     $image_attribute[1] = isset($image_attribute[1]) ? $image_attribute[1] : '';
                     $image_attribute[2] = isset($image_attribute[2]) ? $image_attribute[2] : '';
                     $image_attribute[3] = isset($image_attribute[3]) ? $image_attribute[3] : '';
                     $newWord = '<img src="' . $inline_file['guid'] . '" ' . $image_attribute[1] . ' ' . $image_attribute[2] . ' ' . $image_attribute[3] . ' />';
                     $post_content = str_replace($oldWord, $newWord, $post_content);
                     $result['post_content'] = $post_content;
                     $result['inlineimage_shortcode'] = $inline_shortcode_count;
                     // }
                 }
             }
         }
     }
     return $result;
 }
 /**
  * function to map the csv file and process it
  *
  * @return boolean
  */
 function processDataInWP($data_rows, $ret_array, $session_arr, $currentLimit, $extractedimagelocation, $importinlineimageoption, $sample_inlineimage_url = null)
 {
     global $wpdb;
     $post_id = '';
     $new_post = array();
     $smack_taxo = array();
     $custom_array = array();
     $corecustom_arr = array();
     $seo_custom_array = array();
     $imported_feature_img = array();
     $headr_count = $ret_array['h2'];
     //for ($i = 0; $i < count($data_rows); $i++) {
     for ($i = 0; $i <= $ret_array['basic_count']; $i++) {
         if (array_key_exists('corefieldname' . $i, $ret_array)) {
             if ($ret_array['coremapping' . $i] != '-- Select --' && $ret_array['coremapping' . $i] != '') {
                 $mappedindex = str_replace('CF: ', '', $ret_array['corefieldname' . $i]);
                 if (array_key_exists($ret_array['coremapping' . $i], $data_rows)) {
                     $new_post[$mappedindex] = $data_rows[$ret_array['coremapping' . $i]];
                     $corecustom_arr[$mappedindex] = $data_rows[$ret_array['coremapping' . $i]];
                 }
             }
         } else {
             if (array_key_exists('seofieldname' . $i, $ret_array)) {
                 if ($ret_array['seomapping' . $i] != '-- Select --' && $ret_array['seomapping' . $i] != '') {
                     $mappedindex = str_replace('SEO: ', '', $ret_array['seofieldname' . $i]);
                     if (array_key_exists($ret_array['seomapping' . $i], $data_rows)) {
                         //$new_post[$mappedindex] = $data_rows[$ret_array['seomapping'.$i]];
                         $seo_custom_array[$mappedindex] = $data_rows[$ret_array['seomapping' . $i]];
                     }
                 }
             } else {
                 if (array_key_exists('addcorefieldname' . $i, $ret_array)) {
                     if ($ret_array['addcoremapping' . $i] != '-- Select --' && $ret_array['addcoremapping' . $i] != '') {
                         if (array_key_exists($ret_array['addcoremapping' . $i], $data_rows)) {
                             $corecustom_arr[$ret_array['addcorefieldname' . $i]] = $data_rows[$ret_array['addcoremapping' . $i]];
                         }
                     }
                 } else {
                     if (array_key_exists('mapping' . $i, $ret_array)) {
                         if ($ret_array['mapping' . $i] != '-- Select --') {
                             if (array_key_exists($ret_array['mapping' . $i], $data_rows)) {
                                 $new_post[$ret_array['fieldname' . $i]] = $data_rows[$ret_array['mapping' . $i]];
                             }
                         }
                     }
                 }
             }
         }
     }
     for ($inc = 0; $inc < count($data_rows); $inc++) {
         foreach ($this->keys as $k => $v) {
             if (array_key_exists($v, $new_post)) {
                 $custom_array[$v] = $new_post[$v];
             }
         }
     }
     if (is_array($new_post)) {
         foreach ($new_post as $ckey => $cval) {
             $this->postFlag = true;
             $taxo = get_taxonomies();
             foreach ($taxo as $taxokey => $taxovalue) {
                 if ($taxokey != 'category' && $taxokey != 'link_category' && $taxokey != 'post_tag' && $taxokey != 'nav_menu' && $taxokey != 'post_format') {
                     if ($taxokey == $ckey) {
                         $smack_taxo[$ckey] = $new_post[$ckey];
                     }
                 }
             }
             $taxo_check = 0;
             if (!isset($smack_taxo[$ckey])) {
                 $smack_taxo[$ckey] = null;
                 $taxo_check = 1;
             }
             if ($ckey != 'post_category' && $ckey != 'post_tag' && $ckey != 'featured_image' && $ckey != $smack_taxo[$ckey] && $ckey != 'wp_page_template') {
                 if ($taxo_check == 1) {
                     unset($smack_taxo[$ckey]);
                     $taxo_check = 0;
                 }
                 if (array_key_exists($ckey, $custom_array)) {
                     $darray[$ckey] = $new_post[$ckey];
                 } else {
                     if (array_key_exists($ckey, $smack_taxo)) {
                         $data_array[$ckey] = null;
                     } else {
                         $data_array[$ckey] = $new_post[$ckey];
                     }
                 }
             } else {
                 switch ($ckey) {
                     case 'post_tag':
                         $tags[$ckey] = $new_post[$ckey];
                         break;
                     case 'post_category':
                         $categories[$ckey] = $new_post[$ckey];
                         break;
                     case 'wp_page_template':
                         $custom_array['_wp_page_template'] = $new_post[$ckey];
                         break;
                     case 'featured_image':
                         require_once ABSPATH . "wp-includes/pluggable.php";
                         require_once ABSPATH . 'wp-admin/includes/image.php';
                         $dir = wp_upload_dir();
                         $get_media_settings = get_option('uploads_use_yearmonth_folders');
                         if ($get_media_settings == 1) {
                             $dirname = date('Y') . '/' . date('m');
                             $full_path = $dir['basedir'] . '/' . $dirname;
                             $baseurl = $dir['baseurl'] . '/' . $dirname;
                         } else {
                             $full_path = $dir['basedir'];
                             $baseurl = $dir['baseurl'];
                         }
                         $f_img = $new_post[$ckey];
                         $fimg_path = $full_path;
                         $fimg_name = @basename($f_img);
                         $fimg_name = strtolower(str_replace(' ', '-', $fimg_name));
                         $fimg_name = preg_replace('/[^a-zA-Z0-9._\\s]/', '', $fimg_name);
                         $fimg_name = urlencode($fimg_name);
                         $parseURL = parse_url($f_img);
                         $path_parts = pathinfo($f_img);
                         if (!isset($path_parts['extension'])) {
                             $fimg_name = $fimg_name . '.jpg';
                         }
                         $f_img_slug = '';
                         $f_img_slug = strtolower(str_replace('', '-', $f_img_slug));
                         $f_img_slug = preg_replace('/[^a-zA-Z0-9._\\s]/', '', $f_img_slug);
                         $post_slug_value = strtolower($f_img_slug);
                         require_once WP_CONST_ULTIMATE_CSV_IMP_DIRECTORY . '/includes/WPImporter_includes_helper.php';
                         $impCE = new WPImporter_includes_helper();
                         $path_parts['extension'] = isset($path_parts['extension']) ? $path_parts['extension'] : '';
                         //$fimg_name = wp_unique_filename($fimg_path, $fimg_name, $path_parts['extension']);
                         //$fimg_name = $fimg_name.'.'.$path_parts['extension'];
                         $impCE->get_fimg_from_URL($f_img, $fimg_path, $fimg_name, $post_slug_value, $currentLimit, $this);
                         $filepath = $fimg_path . "/" . $fimg_name;
                         if (@getimagesize($filepath)) {
                             $img = wp_get_image_editor($filepath);
                             $file['guid'] = $baseurl . "/" . $fimg_name;
                             $file['post_title'] = $fimg_name;
                             $file['post_content'] = '';
                             $file['post_status'] = 'attachment';
                         } else {
                             $file = false;
                         }
                         break;
                 }
             }
         }
     }
     if ($_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['selectedImporter'] != 'custompost') {
         $data_array['post_type'] = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['selectedImporter'];
     } else {
         $data_array['post_type'] = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['custompostlist'];
     }
     if ($this->titleDupCheck == 'true') {
         $this->postFlag = $this->duplicateChecks('title', $data_array['post_title'], $data_array['post_type'], $currentLimit, $data_array['post_title']);
     }
     if ($this->conDupCheck == 'true' && $this->postFlag) {
         $this->postFlag = $this->duplicateChecks('content', $data_array['post_content'], $data_array['post_type'], $currentLimit, $data_array['post_title']);
     }
     if ($this->titleDupCheck == 'true' && $this->conDupCheck == 'true') {
         $this->postFlag = $this->duplicateChecks('title && content', $data_array['post_content'], $data_array['post_type'], $currentLimit, $data_array['post_title']);
     }
     if ($this->postFlag) {
         unset($sticky);
         if (empty($data_array['post_status'])) {
             $data_array['post_status'] = null;
         }
         $data_array['post_type'] = "post";
         if ($_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['importallwithps'] != 0) {
             $data_array['post_status'] = $_SESSION['SMACK_MAPPING_SETTINGS_VALUES']['importallwithps'];
         }
         switch ($data_array['post_status']) {
             case 1:
                 $data_array['post_status'] = 'publish';
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>publish";
                 break;
             case 2:
                 $data_array['post_status'] = 'publish';
                 $sticky = true;
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>sticky";
                 break;
             case 3:
                 $data_array['post_status'] = 'private';
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>private";
                 break;
             case 4:
                 $data_array['post_status'] = 'draft';
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>draft";
                 break;
             case 5:
                 $data_array['post_status'] = 'pending';
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>pending";
                 break;
             default:
                 $poststatus_pwd = $data_array['post_status'];
                 $poststatus = $data_array['post_status'] = strtolower($data_array['post_status']);
                 if ($data_array['post_status'] == 'pending') {
                     $data_array['post_status'] = 'pending';
                     $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('pending', 'wp-ultimate-csv-importer');
                 }
                 if ($data_array['post_status'] == 'draft') {
                     $data_array['post_status'] = 'draft';
                     $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('draft', 'wp-ultimate-csv-importer');
                 }
                 if ($data_array['post_status'] == 'publish') {
                     $data_array['post_status'] = 'publish';
                     $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('publish', 'wp-ultimate-csv-importer');
                 }
                 if ($data_array['post_status'] == 'private') {
                     $data_array['post_status'] = 'private';
                     $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('private', 'wp-ultimate-csv-importer');
                 }
                 if ($data_array['post_status'] != 'publish' && $data_array['post_status'] != 'private' && $data_array['post_status'] != 'draft' && $data_array['post_status'] != 'pending' && $data_array['post_status'] != 'sticky') {
                     $stripPSF = strpos($data_array['post_status'], '{');
                     if ($stripPSF === 0) {
                         $poststatus = substr($poststatus_pwd, 1);
                         $stripPSL = substr($poststatus, -1);
                         if ($stripPSL == '}') {
                             $postpwd = substr($poststatus, 1, -1);
                             $data_array['post_status'] = 'publish';
                             $data_array['post_password'] = $postpwd;
                             $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('protected with password', 'wp-ultimate-csv-importer');
                         } else {
                             $data_array['post_status'] = 'publish';
                             $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('publish', 'wp-ultimate-csv-importer');
                         }
                     } else {
                         $data_array['post_status'] = 'publish';
                         $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('publish', 'wp-ultimate-csv-importer');
                     }
                 }
                 if ($data_array['post_status'] == 'sticky') {
                     $data_array['post_status'] = 'publish';
                     $sticky = true;
                     $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('sticky', 'wp-ultimate-csv-importer');
                 }
                 /*      else {
                 							   $this->detailedLog[$currentLimit]['poststatus'] = "<b>".__('Status','wp-ultimate-csv-importer')." - </b>" . $data_array['post_status'];
                 					   }*/
         }
         // Author name/id update
         if (isset($data_array['post_author'])) {
             $authorLen = strlen($data_array['post_author']);
             $postuserid = $data_array['post_author'];
             $checkpostuserid = intval($data_array['post_author']);
             $postAuthorLen = strlen($checkpostuserid);
             $postauthor = array();
             if ($authorLen == $postAuthorLen) {
                 $postauthor = $wpdb->get_results("select ID,user_login from {$wpdb->users} where ID = \"{$postuserid}\"");
                 if (empty($postauthor) || !$postauthor[0]->ID) {
                     // If user name are numeric Ex: 1300001
                     $postauthor = $wpdb->get_results("select ID,user_login from {$wpdb->users} where user_login = \"{$postuserid}\"");
                 }
             } else {
                 $postauthor = $wpdb->get_results("select ID,user_login from {$wpdb->users} where user_login = \"{$postuserid}\"");
             }
             if (empty($postauthor) || !$postauthor[0]->ID) {
                 $data_array['post_author'] = 1;
                 $admindet = $wpdb->get_results("select ID,user_login from {$wpdb->users} where ID = 1");
                 $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - not found (assigned to </b>" . $admindet[0]->user_login . ")";
                 $this->noPostAuthCount++;
             } else {
                 $data_array['post_author'] = $postauthor[0]->ID;
                 $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - </b>" . $postauthor[0]->user_login;
             }
         } else {
             $data_array['post_author'] = 1;
             $admindet = $wpdb->get_results("select ID,user_login from {$wpdb->users} where ID = 1");
             $this->detailedLog[$currentLimit]['assigned_author'] = "<b>Author - not found (assigned to </b>" . $admindet[0]->user_login . ")";
             $this->noPostAuthCount++;
         }
         // Date format post
         if (isset($data_array['post_date'])) {
             $data_array['post_date'] = str_replace('/', '-', $data_array['post_date']);
         } else {
             $data_array['post_date'] = date('Y-m-d');
         }
         if ($data_array['post_date'] == null) {
             $data_array['post_date'] = date('Y-m-d');
             $this->detailedLog[$currentLimit]['postdate'] = "<b>Date - </b>" . $data_array['post_date'];
         } else {
             $data_array['post_date'] = date('Y-m-d H:i:s', strtotime($data_array['post_date']));
             $this->detailedLog[$currentLimit]['postdate'] = "<b>Date - </b>" . $data_array['post_date'];
         }
         if (isset($data_array['post_slug'])) {
             $data_array['post_name'] = $data_array['post_slug'];
         }
         //add global password
         if ($data_array) {
             if ($ret_array['importallwithps'] == 3) {
                 $data_array['post_password'] = $ret_array['globalpassword_txt'];
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>Status - </b>protected with password " . $ret_array['globalpassword_txt'];
             }
         }
         if ($data_array) {
             if ($this->MultiImages == 'true') {
                 $inlineImagesObj = new WPImporter_inlineImages();
                 $postid = wp_insert_post($data_array);
                 $post_id = $inlineImagesObj->importwithInlineImages($postid, $currentLimit, $data_array, $this, $importinlineimageoption, $extractedimagelocation, $sample_inlineimage_url);
             } else {
                 $post_id = wp_insert_post($data_array);
                 $this->detailedLog[$currentLimit]['post_id'] = "<b>Created Post_ID - </b>" . $post_id . " - success";
             }
         }
         unset($postauthor);
         if ($post_id) {
             if (!empty($corecustom_arr)) {
                 foreach ($corecustom_arr as $corecustom_key => $corecustom_value) {
                     update_post_meta($post_id, $corecustom_key, $corecustom_value);
                 }
             }
             $custom_array = $this->eshopMetaData($new_post, $post_id, $currentLimit);
             $uploaded_file_name = $session_arr['uploadedFile'];
             $real_file_name = $session_arr['uploaded_csv_name'];
             $action = $data_array['post_type'];
             $get_imported_feature_image = array();
             $get_imported_feature_image = get_option('IMPORTED_FEATURE_IMAGES');
             if (is_array($get_imported_feature_image)) {
                 $imported_feature_img = array_merge($get_imported_feature_image, $imported_feature_img);
             } else {
                 $imported_feature_img = $imported_feature_img;
             }
             update_option('IMPORTED_FEATURE_IMAGES', $imported_feature_img);
             $created_records[$action][] = $post_id;
             if ($action == 'eshop') {
                 $imported_as = 'eshop-product';
             }
             $keyword = $action;
             $this->insPostCount++;
             if (isset($sticky) && $sticky) {
                 stick_post($post_id);
             }
             if (!empty($custom_array)) {
                 foreach ($custom_array as $custom_key => $custom_value) {
                     //update_post_meta($post_id, $custom_key, $custom_value);
                 }
             }
             //Import SEO Values
             if (!empty($seo_custom_array)) {
                 $this->importSEOfields($seo_custom_array, $post_id);
             }
             // Create custom taxonomy to post
             if (!empty($smack_taxo)) {
                 foreach ($smack_taxo as $taxo_key => $taxo_value) {
                     if (!empty($taxo_value)) {
                         $split_line = explode('|', $taxo_value);
                         wp_set_object_terms($post_id, $split_line, $taxo_key);
                     }
                 }
             }
             // Create/Add tags to post
             if (!empty($tags)) {
                 $this->detailedLog[$currentLimit]['tags'] = "";
                 foreach ($tags as $tag_key => $tag_value) {
                     $this->detailedLog[$currentLimit]['tags'] .= $tag_value . "|";
                     wp_set_post_tags($post_id, $tag_value);
                 }
                 $this->detailedLog[$currentLimit]['tags'] = "<b>Tags - </b>" . substr($this->detailedLog[$currentLimit]['tags'], 0, -1);
             }
             // Create/Add category to post
             if (!empty($categories)) {
                 $this->detailedLog[$currentLimit]['category'] = "";
                 $assigned_categories = array();
                 $split_cate = explode('|', $categories['post_category']);
                 foreach ($split_cate as $key => $val) {
                     if (is_numeric($val)) {
                         $split_cate[$key] = 'uncategorized';
                         $assigned_categories['uncategorized'] = 'uncategorized';
                     }
                     $assigned_categories[$val] = $val;
                 }
                 foreach ($assigned_categories as $cateKey => $cateVal) {
                     $this->detailedLog[$currentLimit]['category'] .= $cateKey . "|";
                 }
                 $this->detailedLog[$currentLimit]['category'] = "<b>Category - </b>" . substr($this->detailedLog[$currentLimit]['category'], 0, -1);
                 wp_set_object_terms($post_id, $split_cate, 'category');
             }
             // Add featured image
             if (!empty($file)) {
                 //$wp_filetype = wp_check_filetype(@basename($file ['guid']), null);
                 $wp_upload_dir = wp_upload_dir();
                 $attachment = array('guid' => $file['guid'], 'post_mime_type' => 'image/jpeg', 'post_title' => preg_replace('/[^a-zA-Z0-9._\\s]/', '', @basename($file['guid'])), 'post_content' => '', 'post_status' => 'inherit');
                 if ($get_media_settings == 1) {
                     $generate_attachment = $dirname . '/' . $fimg_name;
                 } else {
                     $generate_attachment = $fimg_name;
                 }
                 $uploadedImage = $wp_upload_dir['path'] . '/' . $fimg_name;
                 $existing_attachment = array();
                 $query = $wpdb->get_results("select post_title from {$wpdb->posts} where post_type = 'attachment' and post_mime_type = 'image/jpeg'");
                 foreach ($query as $key) {
                     $existing_attachment[] = $key->post_title;
                 }
                 if (!in_array($fimg_name, $existing_attachment)) {
                     $attach_id = wp_insert_attachment($attachment, $generate_attachment, $post_id);
                     $attach_data = wp_generate_attachment_metadata($attach_id, $uploadedImage);
                     wp_update_attachment_metadata($attach_id, $attach_data);
                 } else {
                     $query2 = $wpdb->get_results("select ID from {$wpdb->posts} where post_title = '{$fimg_name}' and post_type = 'attachment'");
                     foreach ($query2 as $key2) {
                         $attach_id = $key2->ID;
                     }
                 }
                 set_post_thumbnail($post_id, $attach_id);
             }
         } else {
             $skippedRecords[] = $_SESSION['SMACK_SKIPPED_RECORDS'];
         }
         $this->detailedLog[$currentLimit]['verify_here'] = "<b>Verify Here -</b> <a href='" . get_permalink($post_id) . "' title='" . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $data_array['post_title'])) . "' rel='permalink' target='_blank'>" . __('Web View') . "</a> | <a href='" . get_edit_post_link($post_id, true) . "' title='" . esc_attr(__('Edit this item')) . "' target='_blank'>" . __('Admin View') . "</a>";
     }
     unset($data_array);
 }