コード例 #1
0
/**
 * Set custom page title.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wp WordPress object.
 * @param string $title Old title.
 * @param string $sep Title separator.
 * @return string Modified title.
 */
function geodir_custom_page_title($title = '', $sep = '')
{
    global $wp;
    if ($sep == '') {
        /**
         * Filter the pae title separator.
         *
         * @since 1.0.0
         * @package GeoDirectory
         * @param string $sep The separator, default: `|`.
         */
        $sep = apply_filters('geodir_page_title_separator', '|');
    }
    if ($title == '') {
        $sitename = get_bloginfo('name');
        $site_description = get_bloginfo('description');
        $title = $sitename . ' ' . $sep . ' ' . $site_description;
    }
    if (is_search() && isset($_REQUEST['geodir_search'])) {
        $all_postypes = geodir_get_posttypes();
        $keyword = esc_sql(strip_tags(get_query_var('s')));
        $stype = esc_sql(strip_tags(esc_attr($_REQUEST['stype'])));
        $snear = esc_sql(strip_tags(esc_attr($_REQUEST['snear'])));
        if ($stype && in_array($stype, $all_postypes)) {
            $title = $keyword;
            if (!empty($stype)) {
                $posttype_obj = get_post_type_object($stype);
                $title = $title . ' ' . $sep . ' ' . ucfirst($posttype_obj->labels->name);
            }
            if (!empty($snear)) {
                $title = $title . ' ' . $sep . ' ' . __('Near', 'geodirectory') . ' ' . $snear;
            }
            $sitename = get_bloginfo('name');
            $title = $title . ' ' . $sep . ' ' . __('Search Results', 'geodirectory') . ' ' . $sep . ' ' . $sitename;
        }
    }
    //print_r($wp->query_vars) ;
    if (isset($wp->query_vars['pagename']) && $wp->query_vars['pagename'] != '') {
        $page = get_page_by_path($wp->query_vars['pagename']);
    }
    if (!empty($page)) {
        $listing_page_id = geodir_add_listing_page_id();
        if ($listing_page_id != '' && $page->ID == $listing_page_id) {
            if (isset($_REQUEST['listing_type']) && $_REQUEST['listing_type'] != '') {
                $listing_type = esc_attr($_REQUEST['listing_type']);
                $post_type_info = geodir_get_posttype_info($listing_type);
                if (!empty($title)) {
                    $title_array = explode($sep, $title);
                    $title_array[0] = ucwords(__('Add', 'geodirectory') . ' ' . __($post_type_info['labels']['singular_name'], 'geodirectory')) . ' ';
                    $title = implode($sep, $title_array);
                } else {
                    $title = ucwords(__('Add', 'geodirectory') . ' ' . __($post_type_info['labels']['singular_name'], 'geodirectory'));
                }
                //$title .= " " . $gd_country . $gd_region . $gd_city  . "$sep ";
            }
        }
    }
    return $title;
}
コード例 #2
0
/**
 * Outputs the add listings page title with HTML wrappers of which most can be filtered.
 *
 * @since 1.0.0
 * @package GeoDirectory
 */
function geodir_action_add_listing_page_title()
{
    if (isset($_REQUEST['listing_type']) && $_REQUEST['listing_type'] != '') {
        $listing_type = $_REQUEST['listing_type'];
    }
    /** This action is documented in geodirectory_template_actions.php */
    $class = apply_filters('geodir_page_title_class', 'entry-title fn');
    /** This action is documented in geodirectory_template_actions.php */
    $class_header = apply_filters('geodir_page_title_header_class', 'entry-header');
    echo '<header class="' . $class_header . '"><h1 class="' . $class . '">';
    if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
        $post_type_info = geodir_get_posttype_info(get_post_type($_REQUEST['pid']));
        /**
         * Filter the add listing page title.
         *
         * @since 1.0.0
         * @param string $title The page title. This is usually Edit/Add followed by the post type name.
         */
        echo apply_filters('geodir_add_listing_page_title_text', ucwords(__('Edit', GEODIRECTORY_TEXTDOMAIN) . ' ' . __($post_type_info['labels']['singular_name'], GEODIRECTORY_TEXTDOMAIN)));
    } elseif (isset($listing_type)) {
        $post_type_info = geodir_get_posttype_info($listing_type);
        /** This action is documented in geodirectory_template_actions.php */
        echo apply_filters('geodir_add_listing_page_title_text', ucwords(__('Add', GEODIRECTORY_TEXTDOMAIN) . ' ' . __($post_type_info['labels']['singular_name'], GEODIRECTORY_TEXTDOMAIN)));
    } else {
        /** This action is documented in geodirectory_template_actions.php */
        apply_filters('geodir_add_listing_page_title_text', the_title());
    }
    echo '</h1></header>';
}
コード例 #3
0
/**
 * Imports data from CSV file using ajax.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @global object $current_user Current user object.
 */
function geodir_ajax_import_csv()
{
    error_reporting(0);
    // hide error to get clean json response
    global $wpdb, $plugin_prefix, $current_user;
    $uploads = wp_upload_dir();
    ini_set('auto_detect_line_endings', true);
    $wp_post_statuses = get_post_statuses();
    // All of the WordPress supported post statuses.
    $task = isset($_POST['task']) ? $_POST['task'] : '';
    $uploadedFile = isset($_POST['gddata']['uploadedFile']) ? $_POST['gddata']['uploadedFile'] : NULL;
    $filename = $uploadedFile;
    $uploads = wp_upload_dir();
    $uploads_dir = $uploads['path'];
    $image_name_arr = explode('/', $filename);
    $filename = end($image_name_arr);
    $target_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $filename;
    $return = array();
    $return['file'] = $uploadedFile;
    $return['error'] = __('The uploaded file is not a valid csv file. Please try again.', 'geodirectory');
    if (is_file($target_path) && file_exists($target_path) && $uploadedFile) {
        $wp_filetype = wp_check_filetype_and_ext($target_path, $filename);
        if (!empty($wp_filetype) && isset($wp_filetype['ext']) && geodir_strtolower($wp_filetype['ext']) == 'csv') {
            $return['error'] = NULL;
            $return['rows'] = 0;
            if (($handle = fopen($target_path, "r")) !== FALSE) {
                while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                    if (is_array($data) && !empty($data)) {
                        $file[] = '"' . implode('","', $data) . '"';
                    }
                }
                fclose($handle);
                $file = $file;
            }
            $return['rows'] = !empty($file) && count($file) > 1 ? count($file) - 1 : 0;
            if (!$return['rows'] > 0) {
                $return['error'] = __('No data found in csv file.', 'geodirectory');
            }
        }
    }
    if ($task == 'prepare' || !empty($return['error'])) {
        echo json_encode($return);
        exit;
    }
    $totRecords = isset($_POST['gddata']['totRecords']) ? $_POST['gddata']['totRecords'] : NULL;
    $importlimit = isset($_POST['gddata']['importlimit']) ? $_POST['gddata']['importlimit'] : 1;
    $count = $importlimit;
    $requested_limit = $importlimit;
    $tmpCnt = isset($_POST['gddata']['tmpcount']) ? $_POST['gddata']['tmpcount'] : 0;
    if ($count < $totRecords) {
        $count = $tmpCnt + $count;
        if ($count > $totRecords) {
            $count = $totRecords;
        }
    } else {
        $count = $totRecords;
    }
    $total_records = 0;
    $rowcount = 0;
    $address_invalid = 0;
    $blank_address = 0;
    $upload_files = 0;
    $invalid_post_type = 0;
    $invalid_title = 0;
    $customKeyarray = array();
    $gd_post_info = array();
    $post_location = array();
    $countpost = 0;
    if (!empty($file)) {
        $columns = isset($file[0]) ? geodir_str_getcsv($file[0]) : NULL;
        $customKeyarray = $columns;
        if (empty($columns) || !empty($columns) && $columns[0] == '') {
            $return['error'] = CSV_INVAILD_FILE;
            echo json_encode($return);
            exit;
        }
        for ($i = 1; $i <= $importlimit; $i++) {
            $current_index = $tmpCnt + $i;
            if (isset($file[$current_index])) {
                $total_records++;
                $buffer = geodir_str_getcsv($file[$current_index]);
                $post_title = addslashes($buffer[0]);
                $current_post_author = $buffer[1];
                $post_desc = addslashes($buffer[2]);
                $post_cat = array();
                $catids_arr = array();
                $post_cat = trim($buffer[3]);
                // comma seperated category name
                if ($post_cat) {
                    $post_cat_arr = explode(',', $post_cat);
                    for ($c = 0; $c < count($post_cat_arr); $c++) {
                        $catid = wp_kses_normalize_entities(trim($post_cat_arr[$c]));
                        if (!empty($buffer[5])) {
                            if (in_array($buffer[5], geodir_get_posttypes())) {
                                $p_taxonomy = geodir_get_taxonomies(addslashes($buffer[5]));
                                if (get_term_by('name', $catid, $p_taxonomy[0])) {
                                    $cat = get_term_by('name', $catid, $p_taxonomy[0]);
                                    $catids_arr[] = $cat->slug;
                                } else {
                                    if (get_term_by('slug', $catid, $p_taxonomy[0])) {
                                        $cat = get_term_by('slug', $catid, $p_taxonomy[0]);
                                        $catids_arr[] = $cat->slug;
                                    } else {
                                        $ret = wp_insert_term($catid, $p_taxonomy[0]);
                                        if ($ret && !is_wp_error($ret)) {
                                            if (get_term_by('name', $catid, $p_taxonomy[0])) {
                                                $cat = get_term_by('name', $catid, $p_taxonomy[0]);
                                                $catids_arr[] = $cat->slug;
                                            } elseif (get_term_by('slug', $catid, $p_taxonomy[0])) {
                                                $cat = get_term_by('slug', $catid, $p_taxonomy[0]);
                                                $catids_arr[] = $cat->slug;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (!$catids_arr) {
                    $catids_arr[] = 1;
                }
                $post_tags = trim($buffer[4]);
                // comma seperated tags
                $tag_arr = '';
                if ($post_tags) {
                    $tag_arr = explode(',', $post_tags);
                }
                $table = $plugin_prefix . $buffer[5] . '_detail';
                // check table in database
                $error = '';
                if ($wpdb->get_var("SHOW TABLES LIKE '" . $table . "'") != $table) {
                    $invalid_post_type++;
                    continue;
                }
                if ($post_title != '') {
                    $menu_order = 0;
                    $image_folder_name = 'uplaod/';
                    $image_names = array();
                    for ($c = 5; $c < count($customKeyarray); $c++) {
                        $gd_post_info[$customKeyarray[$c]] = addslashes($buffer[$c]);
                        if ($customKeyarray[$c] == 'IMAGE') {
                            $buffer[$c] = trim($buffer[$c]);
                            if (!empty($buffer[$c])) {
                                $image_names[] = $buffer[$c];
                            }
                        }
                        if ($customKeyarray[$c] == 'alive_days') {
                            if ($buffer[$c] != '0' && $buffer[$c] != '') {
                                $submitdata = date('Y-m-d');
                                $gd_post_info['expire_date'] = date('Y-m-d', strtotime($submitdata . "+" . addslashes($buffer[$c]) . " days"));
                            } else {
                                $gd_post_info['expire_date'] = 'Never';
                            }
                        }
                        if ($customKeyarray[$c] == 'post_city') {
                            $post_city = addslashes($buffer[$c]);
                        }
                        if ($customKeyarray[$c] == 'post_region') {
                            $post_region = addslashes($buffer[$c]);
                        }
                        if ($customKeyarray[$c] == 'post_country') {
                            $post_country = addslashes($buffer[$c]);
                        }
                        if ($customKeyarray[$c] == 'post_latitude') {
                            $post_latitude = addslashes($buffer[$c]);
                        }
                        if ($customKeyarray[$c] == 'post_longitude') {
                            $post_longitude = addslashes($buffer[$c]);
                        }
                        // Post status
                        if ($customKeyarray[$c] == 'post_status') {
                            $post_status = sanitize_key($buffer[$c]);
                        }
                    }
                    /* ================ before array create ============== */
                    $location_result = geodir_get_default_location();
                    if (!isset($gd_post_info['post_city']) || $gd_post_info['post_city'] == '' || (!isset($gd_post_info['post_region']) || $gd_post_info['post_region'] == '') || (!isset($gd_post_info['post_country']) || $gd_post_info['post_country'] == '') || (!isset($gd_post_info['post_address']) || $gd_post_info['post_address'] == '') || (!isset($gd_post_info['post_latitude']) || $gd_post_info['post_latitude'] == '') || (!isset($gd_post_info['post_longitude']) || $gd_post_info['post_longitude'] == '')) {
                        $blank_address++;
                        continue;
                    } else {
                        if ($location_result->location_id == 0) {
                            if (geodir_strtolower($gd_post_info['post_city']) != geodir_strtolower($location_result->city) || geodir_strtolower($gd_post_info['post_region']) != geodir_strtolower($location_result->region) || geodir_strtolower($gd_post_info['post_country']) != geodir_strtolower($location_result->country)) {
                                $address_invalid++;
                                continue;
                            }
                        }
                    }
                    // Default post status
                    $default_status = 'publish';
                    $post_status = !empty($post_status) ? sanitize_key($post_status) : $default_status;
                    $post_status = !empty($wp_post_statuses) && !isset($wp_post_statuses[$post_status]) ? $default_status : $post_status;
                    $my_post['post_title'] = $post_title;
                    $my_post['post_content'] = $post_desc;
                    $my_post['post_type'] = addslashes($buffer[5]);
                    $my_post['post_author'] = $current_post_author;
                    $my_post['post_status'] = $post_status;
                    $my_post['post_category'] = $catids_arr;
                    $my_post['post_tags'] = $tag_arr;
                    $gd_post_info['post_tags'] = $tag_arr;
                    $gd_post_info['post_title'] = $post_title;
                    $gd_post_info['post_status'] = $post_status;
                    $gd_post_info['submit_time'] = time();
                    $gd_post_info['submit_ip'] = $_SERVER['REMOTE_ADDR'];
                    $last_postid = wp_insert_post($my_post);
                    $countpost++;
                    // Check if we need to save post location as new location
                    if ($location_result->location_id > 0) {
                        if (isset($post_city) && isset($post_region)) {
                            $request_info['post_location'] = array('city' => $post_city, 'region' => $post_region, 'country' => $post_country, 'geo_lat' => $post_latitude, 'geo_lng' => $post_longitude);
                            $post_location_info = $request_info['post_location'];
                            if ($location_id = geodir_add_new_location($post_location_info)) {
                                $post_location_id = $location_id;
                            }
                        } else {
                            $post_location_id = 0;
                        }
                    } else {
                        $post_location_id = 0;
                    }
                    /* ------- get default package info ----- */
                    $payment_info = array();
                    $package_info = array();
                    $package_info = (array) geodir_post_package_info($package_info, '', $buffer[5]);
                    $package_id = '';
                    if (isset($gd_post_info['package_id']) && $gd_post_info['package_id'] != '') {
                        $package_id = $gd_post_info['package_id'];
                    }
                    if (!empty($package_info)) {
                        $payment_info['package_id'] = $package_info['pid'];
                        if (isset($package_info['alive_days']) && $package_info['alive_days'] != 0) {
                            $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['alive_days'] . " days"));
                        } else {
                            $payment_info['expire_date'] = 'Never';
                        }
                        $gd_post_info = array_merge($gd_post_info, $payment_info);
                    }
                    $gd_post_info['post_location_id'] = $post_location_id;
                    $post_type = get_post_type($last_postid);
                    $table = $plugin_prefix . $post_type . '_detail';
                    geodir_save_post_info($last_postid, $gd_post_info);
                    if (!empty($image_names)) {
                        $upload_files++;
                        $menu_order = 1;
                        foreach ($image_names as $image_name) {
                            $img_name_arr = explode('.', $image_name);
                            $uploads = wp_upload_dir();
                            $sub_dir = $uploads['subdir'];
                            $arr_file_type = wp_check_filetype($image_name);
                            $uploaded_file_type = $arr_file_type['type'];
                            $attachment = array();
                            $attachment['post_id'] = $last_postid;
                            $attachment['title'] = $img_name_arr[0];
                            $attachment['content'] = '';
                            $attachment['file'] = $sub_dir . '/' . $image_name;
                            $attachment['mime_type'] = $uploaded_file_type;
                            $attachment['menu_order'] = $menu_order;
                            $attachment['is_featured'] = 0;
                            $attachment_set = '';
                            foreach ($attachment as $key => $val) {
                                if ($val != '') {
                                    $attachment_set .= $key . " = '" . $val . "', ";
                                }
                            }
                            $attachment_set = trim($attachment_set, ", ");
                            $wpdb->query("INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set);
                            if ($menu_order == 1) {
                                $post_type = get_post_type($last_postid);
                                $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s where post_id =%d", array($sub_dir . '/' . $image_name, $last_postid)));
                            }
                            $menu_order++;
                        }
                    }
                    $gd_post_info['package_id'] = $package_id;
                    /** This action is documented in geodirectory-functions/post-functions.php */
                    do_action('geodir_after_save_listing', $last_postid, $gd_post_info);
                    if (!empty($buffer[5])) {
                        if (in_array($buffer[5], geodir_get_posttypes())) {
                            $taxonomies = geodir_get_posttype_info(addslashes($buffer[5]));
                            wp_set_object_terms($last_postid, $my_post['post_tags'], $taxonomy = $taxonomies['taxonomies'][1]);
                            wp_set_object_terms($last_postid, $my_post['post_category'], $taxonomy = $taxonomies['taxonomies'][0]);
                            $post_default_category = isset($my_post['post_default_category']) ? $my_post['post_default_category'] : '';
                            $post_category_str = isset($my_post['post_category_str']) ? $my_post['post_category_str'] : '';
                            geodir_set_postcat_structure($last_postid, $taxonomy, $post_default_category, $post_category_str);
                        }
                    }
                } else {
                    $invalid_title++;
                }
            }
        }
    }
    $return['rowcount'] = $countpost;
    $return['invalidcount'] = $address_invalid;
    $return['blank_address'] = $blank_address;
    $return['upload_files'] = $upload_files;
    $return['invalid_post_type'] = $invalid_post_type;
    $return['invalid_title'] = $invalid_title;
    $return['total_records'] = $total_records;
    echo json_encode($return);
    exit;
}
コード例 #4
0
 /**
  * Imports data from csv file.
  *
  * @since 1.0.0
  * @package GeoDirectory
  * @global object $wpdb WordPress Database object.
  * @global string $plugin_prefix Geodirectory plugin table prefix.
  * @global object $current_user Current user object.
  */
 function geodir_import_data()
 {
     global $wpdb, $plugin_prefix, $current_user;
     if (isset($_REQUEST['geodir_import_data']) && !empty($_REQUEST['geodir_import_data'])) {
         $uploads = wp_upload_dir();
         $uploads_dir = $uploads['path'];
         $curr_img_url = $_REQUEST['filename'];
         $image_name_arr = explode('/', $curr_img_url);
         $filename = end($image_name_arr);
         $target_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $filename;
         $destination_path = $uploads_dir . '/temp_' . $current_user->data->ID;
         $csv_target_path = $target_path;
         ini_set('auto_detect_line_endings', true);
         $fd = fopen($target_path, "rt");
         $total_records = 0;
         $rowcount = 0;
         $address_invalid = 0;
         $blank_address = 0;
         $upload_files = 0;
         $invalid_post_type = 0;
         $invalid_title = 0;
         $customKeyarray = array();
         $gd_post_info = array();
         $post_location = array();
         $countpost = 0;
         $uploaded_file_type = pathinfo($filename, PATHINFO_EXTENSION);
         $extensionarr = array('csv', 'CSV');
         if (in_array($uploaded_file_type, $extensionarr)) {
             while (!feof($fd)) {
                 $buffer = fgetcsv($fd, 40960);
                 if ($rowcount == 0) {
                     for ($k = 0; $k < count($buffer); $k++) {
                         $customKeyarray[$k] = $buffer[$k];
                     }
                     if ($customKeyarray[0] == '') {
                         echo $geodir_url = admin_url() . 'admin.php?page=geodirectory&tab=general_settings&active_tab=csv_upload_settings&emsg=wrong';
                         exit;
                     }
                 } elseif (!empty($buffer)) {
                     $total_records++;
                     $post_title = addslashes($buffer[0]);
                     $current_post_author = $buffer[1];
                     $post_desc = addslashes($buffer[2]);
                     $post_cat = array();
                     $catids_arr = array();
                     $post_cat = trim($buffer[3]);
                     // comma seperated category name
                     if ($post_cat) {
                         $post_cat_arr = explode(',', $post_cat);
                         for ($c = 0; $c < count($post_cat_arr); $c++) {
                             $catid = wp_kses_normalize_entities(trim($post_cat_arr[$c]));
                             if (!empty($buffer[5])) {
                                 if (in_array($buffer[5], geodir_get_posttypes())) {
                                     $p_taxonomy = geodir_get_taxonomies(addslashes($buffer[5]));
                                     if (get_term_by('name', $catid, $p_taxonomy[0])) {
                                         $cat = get_term_by('name', $catid, $p_taxonomy[0]);
                                         $catids_arr[] = $cat->slug;
                                     } elseif (get_term_by('slug', $catid, $p_taxonomy[0])) {
                                         $cat = get_term_by('slug', $catid, $p_taxonomy[0]);
                                         $catids_arr[] = $cat->slug;
                                     }
                                 }
                             }
                         }
                     }
                     if (!$catids_arr) {
                         $catids_arr[] = 1;
                     }
                     $post_tags = trim($buffer[4]);
                     // comma seperated tags
                     $tag_arr = '';
                     if ($post_tags) {
                         $tag_arr = explode(',', $post_tags);
                     }
                     $table = $plugin_prefix . $buffer[5] . '_detail';
                     // check table in database
                     $error = '';
                     if ($wpdb->get_var("SHOW TABLES LIKE '" . $table . "'") != $table) {
                         $invalid_post_type++;
                         continue;
                     }
                     if ($post_title != '') {
                         $menu_order = 0;
                         $image_folder_name = 'uplaod/';
                         $image_names = array();
                         for ($c = 5; $c < count($customKeyarray); $c++) {
                             $gd_post_info[$customKeyarray[$c]] = addslashes($buffer[$c]);
                             if ($customKeyarray[$c] == 'IMAGE') {
                                 $buffer[$c] = trim($buffer[$c]);
                                 if (!empty($buffer[$c])) {
                                     $image_names[] = $buffer[$c];
                                 }
                             }
                             if ($customKeyarray[$c] == 'alive_days') {
                                 if ($buffer[$c] != '0' && $buffer[$c] != '') {
                                     $submitdata = date('Y-m-d');
                                     $gd_post_info['expire_date'] = date('Y-m-d', strtotime($submitdata . "+" . addslashes($buffer[$c]) . " days"));
                                 } else {
                                     $gd_post_info['expire_date'] = 'Never';
                                 }
                             }
                             if ($customKeyarray[$c] == 'post_city') {
                                 $post_city = addslashes($buffer[$c]);
                             }
                             if ($customKeyarray[$c] == 'post_region') {
                                 $post_region = addslashes($buffer[$c]);
                             }
                             if ($customKeyarray[$c] == 'post_country') {
                                 $post_country = addslashes($buffer[$c]);
                             }
                             if ($customKeyarray[$c] == 'post_latitude') {
                                 $post_latitude = addslashes($buffer[$c]);
                             }
                             if ($customKeyarray[$c] == 'post_longitude') {
                                 $post_longitude = addslashes($buffer[$c]);
                             }
                         }
                         /* ================ before array create ============== */
                         $location_result = geodir_get_default_location();
                         if (!isset($gd_post_info['post_city']) || $gd_post_info['post_city'] == '' || (!isset($gd_post_info['post_region']) || $gd_post_info['post_region'] == '') || (!isset($gd_post_info['post_country']) || $gd_post_info['post_country'] == '') || (!isset($gd_post_info['post_address']) || $gd_post_info['post_address'] == '') || (!isset($gd_post_info['post_latitude']) || $gd_post_info['post_latitude'] == '') || (!isset($gd_post_info['post_longitude']) || $gd_post_info['post_longitude'] == '')) {
                             $blank_address++;
                             continue;
                         } elseif ($location_result->location_id == 0) {
                             if (strtolower($gd_post_info['post_city']) != strtolower($location_result->city) || strtolower($gd_post_info['post_region']) != strtolower($location_result->region) || strtolower($gd_post_info['post_country']) != strtolower($location_result->country)) {
                                 $address_invalid++;
                                 continue;
                             }
                         }
                         $my_post['post_title'] = $post_title;
                         $my_post['post_content'] = $post_desc;
                         $my_post['post_type'] = addslashes($buffer[5]);
                         $my_post['post_author'] = $current_post_author;
                         $my_post['post_status'] = 'publish';
                         $my_post['post_category'] = $catids_arr;
                         $my_post['post_tags'] = $tag_arr;
                         $gd_post_info['post_tags'] = $tag_arr;
                         $gd_post_info['post_title'] = $post_title;
                         $gd_post_info['post_status'] = 'publish';
                         $gd_post_info['submit_time'] = time();
                         $gd_post_info['submit_ip'] = $_SERVER['REMOTE_ADDR'];
                         $last_postid = wp_insert_post($my_post);
                         $countpost++;
                         // Check if we need to save post location as new location
                         if ($location_result->location_id > 0) {
                             if (isset($post_city) && isset($post_region)) {
                                 $request_info['post_location'] = array('city' => $post_city, 'region' => $post_region, 'country' => $post_country, 'geo_lat' => $post_latitude, 'geo_lng' => $post_longitude);
                                 $post_location_info = $request_info['post_location'];
                                 if ($location_id = geodir_add_new_location($post_location_info)) {
                                     $post_location_id = $location_id;
                                 }
                             } else {
                                 $post_location_id = 0;
                             }
                         } else {
                             $post_location_id = 0;
                         }
                         /* ------- get default package info ----- */
                         $payment_info = array();
                         $package_info = array();
                         $package_info = (array) geodir_post_package_info($package_info, '', $buffer[5]);
                         $package_id = '';
                         if (isset($gd_post_info['package_id']) && $gd_post_info['package_id'] != '') {
                             $package_id = $gd_post_info['package_id'];
                         }
                         if (!empty($package_info)) {
                             $payment_info['package_id'] = $package_info['pid'];
                             if (isset($package_info['alive_days']) && $package_info['alive_days'] != 0) {
                                 $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['alive_days'] . " days"));
                             } else {
                                 $payment_info['expire_date'] = 'Never';
                             }
                             $gd_post_info = array_merge($gd_post_info, $payment_info);
                         }
                         $gd_post_info['post_location_id'] = $post_location_id;
                         $post_type = get_post_type($last_postid);
                         $table = $plugin_prefix . $post_type . '_detail';
                         geodir_save_post_info($last_postid, $gd_post_info);
                         if (!empty($image_names)) {
                             $upload_files++;
                             $menu_order = 1;
                             foreach ($image_names as $image_name) {
                                 $img_name_arr = explode('.', $image_name);
                                 $uploads = wp_upload_dir();
                                 $sub_dir = $uploads['subdir'];
                                 $arr_file_type = wp_check_filetype($image_name);
                                 $uploaded_file_type = $arr_file_type['type'];
                                 $attachment = array();
                                 $attachment['post_id'] = $last_postid;
                                 $attachment['title'] = $img_name_arr[0];
                                 $attachment['content'] = '';
                                 $attachment['file'] = $sub_dir . '/' . $image_name;
                                 $attachment['mime_type'] = $uploaded_file_type;
                                 $attachment['menu_order'] = $menu_order;
                                 $attachment['is_featured'] = 0;
                                 $attachment_set = '';
                                 foreach ($attachment as $key => $val) {
                                     if ($val != '') {
                                         $attachment_set .= $key . " = '" . $val . "', ";
                                     }
                                 }
                                 $attachment_set = trim($attachment_set, ", ");
                                 $wpdb->query("INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set);
                                 if ($menu_order == 1) {
                                     $post_type = get_post_type($last_postid);
                                     $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s where post_id =%d", array($sub_dir . '/' . $image_name, $last_postid)));
                                 }
                                 $menu_order++;
                             }
                         }
                         $gd_post_info['package_id'] = $package_id;
                         /** This action is documented in geodirectory-functions/post-functions.php */
                         do_action('geodir_after_save_listing', $last_postid, $gd_post_info);
                         if (!empty($buffer[5])) {
                             if (in_array($buffer[5], geodir_get_posttypes())) {
                                 $taxonomies = geodir_get_posttype_info(addslashes($buffer[5]));
                                 wp_set_object_terms($last_postid, $my_post['post_tags'], $taxonomy = $taxonomies['taxonomies'][1]);
                                 wp_set_object_terms($last_postid, $my_post['post_category'], $taxonomy = $taxonomies['taxonomies'][0]);
                                 $post_default_category = isset($my_post['post_default_category']) ? $my_post['post_default_category'] : '';
                                 $post_category_str = isset($my_post['post_category_str']) ? $my_post['post_category_str'] : '';
                                 geodir_set_postcat_structure($last_postid, $taxonomy, $post_default_category, $post_category_str);
                             }
                         }
                     } else {
                         $invalid_title++;
                     }
                 }
                 $rowcount++;
             }
             fclose($fd);
             //unlink($csv_target_path);
             //rmdir($destination_path);
             if (!empty($filename)) {
                 geodir_remove_temp_images();
             }
             echo $geodir_url = admin_url() . 'admin.php?page=geodirectory&tab=general_settings&active_tab=csv_upload_settings&msg=success&rowcount=' . $countpost . '&invalidcount=' . $address_invalid . '&blank_address=' . $blank_address . '&upload_files=' . $upload_files . '&invalid_post_type=' . $invalid_post_type . '&invalid_title=' . $invalid_title . '&total_records=' . $total_records;
             exit;
         } else {
             echo $geodir_url = admin_url() . 'admin.php?page=geodirectory&tab=general_settings&active_tab=csv_upload_settings&emsg=csvonly';
             exit;
         }
     }
 }