/**
  * 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();
     $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('coremapping' . $i, $ret_array)) {
             if ($ret_array['coretextbox' . $i] != '-- Select --' && $ret_array['coremapping' . $i] != '') {
                 $mappedindex = str_replace('textbox', '', $ret_array['coretextbox' . $i]);
                 $new_post[$ret_array['coremapping' . $i]] = $data_rows[$mappedindex];
                 $custom_array[$ret_array['coremapping' . $i]] = $data_rows[$mappedindex];
             }
         } else {
             if (array_key_exists('mapping' . $i, $ret_array)) {
                 if ($ret_array['mapping' . $i] != '-- Select --') {
                     if ($ret_array['mapping' . $i] != 'add_custom' . $i) {
                         $strip_CF = strpos($ret_array['mapping' . $i], 'CF: ');
                         $strip_SEO = strpos($ret_array['mapping' . $i], 'SEO: ');
                         if ($strip_CF === 0) {
                             $custom_key = substr($ret_array['mapping' . $i], 4);
                             $custom_array[$custom_key] = $data_rows[$i];
                         } elseif ($strip_SEO === 0) {
                             $seo_key = substr($ret_array['mapping' . $i], 5);
                             $seo_custom_array[$seo_key] = $data_rows[$i];
                         } else {
                             $new_post[$ret_array['mapping' . $i]] = $data_rows[$i];
                         }
                     } else {
                         $new_post[$ret_array['textbox' . $i]] = $data_rows[$i];
                         $custom_array[$ret_array['textbox' . $i]] = $data_rows[$i];
                     }
                 }
             }
         }
     }
     /*		for($j = 0; $j< $ret_array['corecustomcount'];j++){	
     			if(array_key_exists('coremapping' . $i,$ret_array)){
                                     echo '<pre>';print_r($ret_array['coretextbox' . $i]);echo '</pre>';
                                     if($ret_array['coretextbox' . $i] != '-- Select --'){
                                             $mappedindex = str_replace('textbox','',$ret_array['coretextbox'.$i]);
                                             echo '<pre>';print_r($mappedindex);echo '</pre>';die;
                                             //$new_post[$ret_array['coretextbox'.$i]] = $data_rows[];
                                             //$custom_array[$ret_array['coremapping'.$i]] = $data_rows[$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);
                         $featured_image = $fimg_name;
                         $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';
                         }
                         //else
                         //	$fimg_name = $fimg_name.'.'.$path_parts['extension'];
                         $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);
                         if (array_key_exists('extension', $path_parts)) {
                             //$fimg_name = wp_unique_filename($fimg_path, $fimg_name, $path_parts['extension']);
                         }
                         $this->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);
                             /*if (!is_wp_error($img)) {
                             			$sizes_array = array(
                             					// #1 - resizes to 1024x768 pixel, square-cropped image
                             					array('width' => 1024, 'height' => 768, 'crop' => true),
                             					// #2 - resizes to 100px max width/height, non-cropped image
                             					array('width' => 100, 'height' => 100, 'crop' => false),
                             					// #3 - resizes to 100 pixel max height, non-cropped image
                             					array('width' => 300, 'height' => 100, 'crop' => false),
                             					// #3 - resizes to 624x468 pixel max width, non-cropped image
                             					array('width' => 624, 'height' => 468, 'crop' => false)
                             					);
                             			$resize = $img->multi_resize($sizes_array);
                             		}*/
                             $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;
         }
         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', 'wp-ultimate-csv-importer') . " - </b>" . __('publish', 'wp-ultimate-csv-importer');
                 break;
             case 2:
                 $data_array['post_status'] = 'publish';
                 $sticky = true;
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('sticky', 'wp-ultimate-csv-importer');
                 break;
             case 3:
                 $data_array['post_status'] = 'publish';
                 $data_array['post_password'] = $_POST['postsPassword'];
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('protected with password', 'wp-ultimate-csv-importer') . $data_array['post_password'];
                 break;
             case 4:
                 $data_array['post_status'] = 'private';
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('private', 'wp-ultimate-csv-importer');
                 break;
             case 5:
                 $data_array['post_status'] = 'draft';
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('draft', 'wp-ultimate-csv-importer');
                 break;
             case 6:
                 $data_array['post_status'] = 'pending';
                 $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('pending', 'wp-ultimate-csv-importer');
                 break;
             default:
                 $poststatus = $data_array['post_status'] = strtolower($data_array['post_status']);
                 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($data_array['post_status'], 1);
                         $stripPSL = substr($poststatus, -1);
                         if ($stripPSL == '}') {
                             $postpwd = substr($poststatus, 0, -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') . $data_array['post_password'];
                         } else {
                             $data_array['post_status'] = 'publish';
                             $data_array['post_password'] = $poststatus;
                             $this->detailedLog[$currentLimit]['poststatus'] = "<b>" . __('Status', 'wp-ultimate-csv-importer') . " - </b>" . __('protected with password', 'wp-ultimate-csv-importer') . $data_array['post_password'];
                         }
                     } 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'];
                 }
         }
         // Post Format Options
         if (isset($data_array['post_format'])) {
             $post_format = 0;
             switch ($data_array['post_format']) {
                 case 1:
                     $post_format = 'post-format-aside';
                     break;
                 case 2:
                     $post_format = 'post-format-image';
                     break;
                 case 3:
                     $post_format = 'post-format-video';
                     break;
                 case 4:
                     $post_format = 'post-format-audio';
                     break;
                 case 5:
                     $post_format = 'post-format-quote';
                     break;
                 case 6:
                     $post_format = 'post-format-link';
                     break;
                 case 7:
                     $post_format = 'post-format-gallery';
                     break;
                 default:
                     if ($data_array['post_format'] == 'post-format-aside') {
                         $post_format = 'post-format-aside';
                         break;
                     }
                     if ($data_array['post_format'] == 'post-format-image') {
                         $post_format = 'post-format-image';
                         break;
                     }
                     if ($data_array['post_format'] == 'post-format-video') {
                         $post_format = 'post-format-video';
                         break;
                     }
                     if ($data_array['post_format'] == 'post-format-audio') {
                         $post_format = 'post-format-audio';
                         break;
                     }
                     if ($data_array['post_format'] == 'post-format-quote') {
                         $post_format = 'post-format-quote';
                         break;
                     }
                     if ($data_array['post_format'] == 'post-format-link') {
                         $post_format = 'post-format-link';
                         break;
                     }
                     if ($data_array['post_format'] == 'post-format-gallery') {
                         $post_format = 'post-format-gallery';
                         break;
                     }
                     $post_format = 0;
             }
         }
         // 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', 'wp-ultimate-csv-importer') . " </b>" . $admindet[0]->user_login . ")";
                 $this->noPostAuthCount++;
             } else {
                 $data_array['post_author'] = $postauthor[0]->ID;
                 $this->detailedLog[$currentLimit]['assigned_author'] = "<b>" . __('Author', 'wp-ultimate-csv-importer') . " - </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', 'wp-ultimate-csv-importer') . " </b>" . $admindet[0]->user_login . ")";
             $this->noPostAuthCount++;
         }
         // Date format post
         $data_array['post_date'] = str_replace('/', '-', $data_array['post_date']);
         if (!isset($data_array['post_date'])) {
             $data_array['post_date'] = date('Y-m-d H:i:s');
             $this->detailedLog[$currentLimit]['postdate'] = "<b>" . __('Date', 'wp-ultimate-csv-importer') . " - </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', 'wp-ultimate-csv-importer') . " - </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', 'wp-ultimate-csv-importer') . " - </b>" . __('protected with password', 'wp-ultimate-csv-importer') . $ret_array['globalpassword_txt'];
             }
         }
         if ($data_array) {
             if ($this->MultiImages == 'true') {
                 // Inline image import feature by fredrick marks
                 $inlineImagesObj = new WPImporter_inlineImages();
                 $postid = wp_insert_post($data_array);
                 $post_id = $inlineImagesObj->importwithInlineImages($postid, $currentLimit, $data_array, $this, $importinlineimageoption, $extractedimagelocation, $sample_inlineimage_url);
                 //	$inline_shortcode = $inlineImagesObj->capture_all_shortcodes($data_array['post_content']);
             } else {
                 $post_id = wp_insert_post($data_array);
                 $this->detailedLog[$currentLimit]['post_id'] = "<b>" . __('Created Post_ID', 'wp-ultimate-csv-importer') . " - </b>" . $post_id . " - success";
             }
         }
         unset($postauthor);
         if ($post_id) {
             $uploaded_file_name = $session_arr['uploadedFile'];
             $real_file_name = $session_arr['uploaded_csv_name'];
             //                                $version = $session_arr['currentfileversion'];
             $action = $data_array['post_type'];
             /*				$version_arr=array();
             						$version_arr=explode("(",$uploaded_file_name);
             						$version_arr=explode(")",$version_arr[1]);
             						$version=$version_arr[0]; */
             $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 == 'post') {
                 $imported_as = 'Post';
             }
             if ($action == 'page') {
                 $imported_as = 'Page';
             }
             if ($action != 'post' && $action != 'page') {
                 $imported_as = 'Custom Post';
             }
             $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 post formats added by fredrick marks
             if (isset($post_format)) {
                 wp_set_object_terms($post_id, $post_format, 'post_format');
             }
             //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', 'wp-ultimate-csv-importer') . " - </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', 'wp-ultimate-csv-importer') . " - </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;
                 /*$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);*/
                 $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', 'wp-ultimate-csv-importer') . "</a> | <a href='" . get_edit_post_link($post_id, true) . "' title='" . esc_attr(__('Edit this item', 'wp-ultimate-csv-importer')) . "' target='_blank'>" . __('Admin View', 'wp-ultimate-csv-importer') . "</a>";
     }
     unset($data_array);
 }
 /**
  * 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);
 }