/**
 * Adds listing description to the page.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @global object $wpdb WordPress Database object.
 * @global object $wp_query WordPress Query object.
 */
function geodir_location_action_listings_description()
{
    global $wpdb, $wp_query;
    $current_term = $wp_query->get_queried_object();
    $gd_post_type = geodir_get_current_posttype();
    if (isset($current_term->term_id) && $current_term->term_id != '') {
        $term_desc = term_description($current_term->term_id, $gd_post_type . '_tags');
        $saved_data = stripslashes(get_tax_meta($current_term->term_id, 'ct_cat_top_desc', false, $gd_post_type));
        if ($term_desc && !$saved_data) {
            $saved_data = $term_desc;
        }
        $default_location = geodir_get_default_location();
        $location_type = geodir_what_is_current_location();
        $replace_location = __('Everywhere', GEODIRLOCATION_TEXTDOMAIN);
        $gd_country = get_query_var('gd_country');
        $gd_region = get_query_var('gd_region');
        $gd_city = get_query_var('gd_city');
        $current_location = '';
        if ($gd_country != '') {
            $location_type = 'country';
            $current_location = get_actual_location_name('country', $gd_country, true);
        }
        if ($gd_region != '') {
            $location_type = 'region';
            $current_location = get_actual_location_name('region', $gd_region);
        }
        if ($gd_city != '') {
            $location_type = 'city';
            $current_location = get_actual_location_name('city', $gd_city);
        }
        if ($location_type == 'city') {
            $replace_location = geodir_get_current_location(array('what' => 'city', 'echo' => false));
            $option_name = 'geodir_cat_loc_' . $gd_post_type . '_' . $current_term->term_id;
            $cat_loc_option = get_option($option_name);
            $gd_cat_loc_default = !empty($cat_loc_option) && isset($cat_loc_option['gd_cat_loc_default']) && $cat_loc_option['gd_cat_loc_default'] > 0 ? true : false;
            if (!$gd_cat_loc_default && $gd_city != '') {
                $post_type = $gd_post_type;
                $term_id = $current_term->term_id;
                $sql = $wpdb->prepare("SELECT location_id FROM " . POST_LOCATION_TABLE . " WHERE city_slug=%s ORDER BY location_id ASC LIMIT 1", array($gd_city));
                $location_id = $wpdb->get_var($sql);
                if ($location_id > 0) {
                    $option_name = 'geodir_cat_loc_' . $post_type . '_' . $term_id . '_' . $location_id;
                    $option = get_option($option_name);
                    $gd_cat_loc_desc = !empty($option) && isset($option['gd_cat_loc_desc']) ? trim($option['gd_cat_loc_desc']) : '';
                    if ($gd_cat_loc_desc != '') {
                        $saved_data = stripslashes_deep($gd_cat_loc_desc);
                    }
                }
            }
        } else {
            if ($location_type == 'region') {
                $replace_location = geodir_get_current_location(array('what' => 'region', 'echo' => false));
            } else {
                if ($location_type == 'country') {
                    $replace_location = geodir_get_current_location(array('what' => 'country', 'echo' => false));
                    $replace_location = __($replace_location, GEODIRECTORY_TEXTDOMAIN);
                }
            }
        }
        $replace_location = $current_location != '' ? $current_location : $replace_location;
        $saved_data = str_replace('%location%', $replace_location, $saved_data);
        $cat_description = apply_filters('the_content', $saved_data);
        if ($cat_description) {
            echo '<div class="term_description">' . $cat_description . '</div>';
        }
    }
}
Exemplo n.º 2
0
 * Filter the map restriction for specific address only
 *
 * @since 1.0.0
 *
 * @param bool $var Whether to ristrict the map for specific address only.
 */
$is_map_restrict = apply_filters('geodir_add_listing_map_restrict', true);
/**
 * Filter the auto change address fields values when moving the map pin
 *
 * @since 1.4.8
 *
 * @param bool $var Whether to change the country, state, city values in fields.
 */
$auto_change_address_fields_pin_move = apply_filters('geodir_auto_change_address_fields_pin_move', true);
$default_location = geodir_get_default_location();
$defaultcity = isset($default_location->city) ? $default_location->city : '';
$lat_lng_blank = false;
if ($lat == '' && $lng == '') {
    $lat_lng_blank = true;
    $city = $defaultcity;
    $region = isset($default_location->region) ? $default_location->region : '';
    $country = isset($default_location->country) ? $default_location->country : '';
    $lng = isset($default_location->city_longitude) ? $default_location->city_longitude : '';
    $lat = isset($default_location->city_latitude) ? $default_location->city_latitude : '';
}
$default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : '';
$default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : '';
if (is_admin() && isset($_REQUEST['tab']) && $mapzoom == '') {
    $mapzoom = 4;
    if (isset($_REQUEST['add_hood'])) {
/**
 * 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;
}
Exemplo n.º 4
0
        /**
         *
         * @global object $wpdb WordPress Database object.
         *
         * @param array $args
         * @param array $instance
         */
        public function widget($args, $instance)
        {
            extract($args, EXTR_SKIP);
            echo $before_widget;
            $title = empty($instance['title']) ? $instance['category_title'] : apply_filters('widget_title', $instance['title']);
            $hood_post_type = empty($instance['hood_post_type']) ? 'gd_place' : apply_filters('widget_hood_post_type', $instance['hood_post_type']);
            $hood_category = empty($instance['hood_category']) ? '0' : apply_filters('widget_hood_category', $instance['hood_category']);
            $post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
            $layout = empty($instance['layout']) ? 'gridview_onehalf' : apply_filters('widget_layout', $instance['layout']);
            $add_location_filter = empty($instance['add_location_filter']) ? '0' : apply_filters('widget_layout', $instance['add_location_filter']);
            $list_sort = empty($instance['list_sort']) ? 'latest' : apply_filters('widget_list_sort', $instance['list_sort']);
            $character_count = empty($instance['character_count']) ? 20 : apply_filters('widget_list_sort', $instance['character_count']);
            if (empty($title) || $title == 'All') {
                $title .= ' Neighbourhood ' . get_post_type_plural_label($hood_post_type);
            }
            global $wpdb, $post, $geodir_post_type;
            if ($geodir_post_type == '') {
                $geodir_post_type = 'gd_place';
            }
            $all_postypes = geodir_get_posttypes();
            $location_id = '';
            $not_in_array = array();
            if (geodir_is_page('detail') || geodir_is_page('preview') || geodir_is_page('add-listing')) {
                if (isset($post->post_type) && $post->post_type == $hood_post_type && isset($post->post_location_id)) {
                    $not_in_array[] = $post->ID;
                    $location_id = $post->post_location_id;
                }
            } elseif (in_array($geodir_post_type, $all_postypes) && $geodir_post_type == $hood_post_type) {
                if (isset($_SESSION['gd_city']) && $_SESSION['gd_city'] != '') {
                    $location_id = $wpdb->get_var($wpdb->prepare("SELECT location_id FROM " . POST_LOCATION_TABLE . " WHERE city_slug = %s", array($_SESSION['gd_city'])));
                } else {
                    $default_location = geodir_get_default_location();
                    $location_id = $default_location->location_id;
                }
            }
            $gd_neighbourhoods = geodir_get_neighbourhoods($location_id);
            if ($gd_neighbourhoods) {
                ?>
			
			<div class="geodir_locations geodir_location_listing">
						<div class="locatin_list_heading clearfix">
							<h3><?php 
                _e(ucfirst($title), GEODIRLOCATION_TEXTDOMAIN);
                ?>
</h3>
						</div>
						
						<?php 
                $hood_slug_arr = array();
                if (!empty($gd_neighbourhoods)) {
                    foreach ($gd_neighbourhoods as $hoodslug) {
                        $hood_slug_arr[] = $hoodslug->hood_slug;
                    }
                }
                $query_args = array('posts_per_page' => $post_number, 'is_geodir_loop' => true, 'post__not_in' => $not_in_array, 'gd_neighbourhood' => $hood_slug_arr, 'gd_location' => $add_location_filter ? true : false, 'post_type' => $hood_post_type, 'order_by' => $list_sort, 'excerpt_length' => $character_count);
                if ($hood_category != 0 || $hood_category != '') {
                    $category_taxonomy = geodir_get_taxonomies($hood_post_type);
                    $tax_query = array('taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $hood_category);
                    $query_args['tax_query'] = array($tax_query);
                }
                global $gridview_columns;
                query_posts($query_args);
                if (strstr($layout, 'gridview')) {
                    $listing_view_exp = explode('_', $layout);
                    $gridview_columns = $layout;
                    $layout = $listing_view_exp[0];
                }
                $template = apply_filters("geodir_template_part-listing-listview", geodir_plugin_path() . '/geodirectory-templates/listing-listview.php');
                include $template;
                wp_reset_query();
                ?>
				
						 
					</div>
			
			<?php 
            }
            echo $after_widget;
        }
Exemplo n.º 5
0
function dt_geodir_dummy_content_generator($post_infos = array())
{
    global $city_bound_lat1, $city_bound_lng1, $city_bound_lat2, $city_bound_lng2;
    if (empty($post_infos)) {
        return;
    }
    foreach ($post_infos as $post_info) {
        $default_location = geodir_get_default_location();
        if ($city_bound_lat1 > $city_bound_lat2) {
            $dummy_post_latitude = geodir_random_float(geodir_random_float($city_bound_lat1, $city_bound_lat2), geodir_random_float($city_bound_lat2, $city_bound_lat1));
        } else {
            $dummy_post_latitude = geodir_random_float(geodir_random_float($city_bound_lat2, $city_bound_lat1), geodir_random_float($city_bound_lat1, $city_bound_lat2));
        }
        if ($city_bound_lng1 > $city_bound_lng2) {
            $dummy_post_longitude = geodir_random_float(geodir_random_float($city_bound_lng1, $city_bound_lng2), geodir_random_float($city_bound_lng2, $city_bound_lng1));
        } else {
            $dummy_post_longitude = geodir_random_float(geodir_random_float($city_bound_lng2, $city_bound_lng1), geodir_random_float($city_bound_lng1, $city_bound_lng2));
        }
        $postal_code = '';
        $address = '';
        $post_address = geodir_get_address_by_lat_lan($dummy_post_latitude, $dummy_post_longitude);
        if (!empty($post_address)) {
            foreach ($post_address as $add_key => $add_value) {
                if ($add_value->types[0] == 'postal_code') {
                    $postal_code = $add_value->long_name;
                }
                if ($add_value->types[0] == 'street_number') {
                    if ($address != '') {
                        $address .= ',' . $add_value->long_name;
                    } else {
                        $address .= $add_value->long_name;
                    }
                }
                if ($add_value->types[0] == 'route') {
                    if ($address != '') {
                        $address .= ',' . $add_value->long_name;
                    } else {
                        $address .= $add_value->long_name;
                    }
                }
                if ($add_value->types[0] == 'neighborhood') {
                    if ($address != '') {
                        $address .= ',' . $add_value->long_name;
                    } else {
                        $address .= $add_value->long_name;
                    }
                }
                if ($add_value->types[0] == 'sublocality') {
                    if ($address != '') {
                        $address .= ',' . $add_value->long_name;
                    } else {
                        $address .= $add_value->long_name;
                    }
                }
            }
            $post_info['post_address'] = $address;
            $post_info['post_city'] = $default_location->city;
            $post_info['post_region'] = $default_location->region;
            $post_info['post_country'] = $default_location->country;
            $post_info['post_zip'] = $postal_code;
            $post_info['post_latitude'] = $dummy_post_latitude;
            $post_info['post_longitude'] = $dummy_post_longitude;
        }
        geodir_save_listing($post_info, true);
    }
}
Exemplo n.º 6
0
/**
 * The geodirectory listing map shortcode.
 *
 * This implements the functionality of the shortcode for displaying listing map.
 *
 * @since 1.0.0
 * @since 1.5.2 Added TERRAIN for $maptype attribute.
 * @package GeoDirectory
 * @global object $post The current post object.
 * @param array $atts {
 *     Attributes of the shortcode.
 *
 *     @type string $width           Map width in pixels. Default 294.
 *     @type string $height          Map height in pixels. Default 370.
 *     @type string $maptype         Map type. Default ROADMAP. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN.
 *     @type string $zoom            The zoom level of the map. Between 1-19. Default 13.
 *     @type string $autozoom        True if the map should autozoom, false if not.
 *     @type bool   $sticky          True if should be sticky, false if not
 *     @type string $showall         Show all listings on map? (not just page list). Default 0.
 *     @type string $child_collapse  True if the map should collapse the categories, false if not.
 *     @type string $scrollwheel     True to allow scroll wheel to scroll map or false if not.
 *     @type bool   $marker_cluster  Enable marker cluster? Default: false.
 *
 * }
 * @return string Map HTML.
 */
function geodir_sc_listing_map($atts)
{
    ob_start();
    add_action('wp_head', 'init_listing_map_script');
    // Initialize the map object and marker array
    add_action('the_post', 'create_list_jsondata');
    // Add marker in json array
    add_action('wp_footer', 'show_listing_widget_map');
    // Show map for listings with markers
    $defaults = array('width' => '294', 'height' => '370', 'zoom' => '13', 'autozoom' => '', 'sticky' => '', 'showall' => '0', 'scrollwheel' => '0', 'maptype' => 'ROADMAP', 'child_collapse' => 0, 'marker_cluster' => false);
    $params = shortcode_atts($defaults, $atts);
    $params = gdsc_validate_map_args($params);
    $map_args = array('map_canvas_name' => 'gd_listing_map', 'width' => $params['width'], 'height' => $params['height'], 'zoom' => $params['zoom'], 'autozoom' => $params['autozoom'], 'sticky' => $params['sticky'], 'showall' => $params['showall'], 'scrollwheel' => $params['scrollwheel'], 'child_collapse' => 0, 'enable_cat_filters' => false, 'enable_text_search' => false, 'enable_post_type_filters' => false, 'enable_location_filters' => false, 'enable_jason_on_load' => true);
    if (is_single()) {
        global $post;
        $map_default_lat = $address_latitude = $post->post_latitude;
        $map_default_lng = $address_longitude = $post->post_longitude;
        $mapview = $post->post_mapview;
        $map_args['zoom'] = $post->post_mapzoom;
        $map_args['map_class_name'] = 'geodir-map-listing-page-single';
    } else {
        $default_location = geodir_get_default_location();
        $map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : '';
        $map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : '';
        $map_args['map_class_name'] = 'geodir-map-listing-page';
    }
    if (empty($mapview)) {
        $mapview = 'ROADMAP';
    }
    // Set default map options
    $map_args['ajax_url'] = geodir_get_ajax_url();
    $map_args['latitude'] = $map_default_lat;
    $map_args['longitude'] = $map_default_lng;
    $map_args['streetViewControl'] = true;
    $map_args['maptype'] = $mapview;
    $map_args['showPreview'] = '0';
    $map_args['maxZoom'] = 21;
    $map_args['bubble_size'] = 'small';
    // Add marker cluster
    if (isset($params['marker_cluster']) && gdsc_to_bool_val($params['marker_cluster']) && defined('GDCLUSTER_VERSION')) {
        $map_args['enable_marker_cluster'] = true;
    } else {
        $map_args['enable_marker_cluster'] = false;
    }
    geodir_draw_map($map_args);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
/**
 * Displays setting form for the given tab.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global array $geodir_settings Geodirectory settings array.
 * @global object $wpdb WordPress Database object.
 * @param string $tab_name Tab name.
 */
function geodir_admin_option_form($tab_name)
{
    //echo $tab_name.'_array.php' ;
    global $geodir_settings, $is_default, $mapzoom;
    if (file_exists(dirname(__FILE__) . '/option-pages/' . $tab_name . '_array.php')) {
        /**
         * Contains settings array for given tab.
         *
         * @since 1.0.0
         * @package GeoDirectory
         */
        include_once 'option-pages/' . $tab_name . '_array.php';
    }
    $listing_type = isset($_REQUEST['listing_type']) ? $_REQUEST['listing_type'] : '';
    switch ($tab_name) {
        case 'general_settings':
            geodir_admin_fields($geodir_settings['general_settings']);
            /**
             *
             * Update Taxonomy Options *
             *
             **/
            /*add_action('updated_option_place_prefix','update_listing_prefix');
              function update_listing_prefix(){
                  geodir_register_defaults();
              }*/
            if (isset($_REQUEST['active_tab']) && ($_REQUEST['active_tab'] == 'dummy_data_settings' || $_REQUEST['active_tab'] == 'csv_upload_settings')) {
                $hide_save_button = "style='display:none;'";
            } else {
                $hide_save_button = '';
            }
            /**
             * Filter weather the default save button in the GD admin settings pages should be shown.
             *
             * @since 1.0.0
             * @param string $hide_save_button The style element, either blank or: style='display:none;'.
             */
            $hide_save_button = apply_filters('geodir_hide_save_button', $hide_save_button);
            ?>

            <p class="submit">
            <input <?php 
            echo $hide_save_button;
            ?>
 name="save" class="button-primary" type="submit" value="<?php 
            _e('Save changes', 'geodirectory');
            ?>
" />
            <input type="hidden" name="subtab" id="last_tab" />
            </p>
            
            </div>
            
		<?php 
            break;
        case 'design_settings':
            geodir_admin_fields($geodir_settings['design_settings']);
            ?>
			<p class="submit">
			<input name="save" class="button-primary" type="submit" value="<?php 
            _e('Save changes', 'geodirectory');
            ?>
" />
			<input type="hidden" name="subtab" id="last_tab" />
			</p>
			</div>
        <?php 
            break;
        case 'permalink_settings':
            geodir_admin_fields($geodir_settings['permalink_settings']);
            ?>
            <p class="submit">
            <input name="save" class="button-primary" type="submit" value="<?php 
            _e('Save changes', 'geodirectory');
            ?>
" />
            <input type="hidden" name="subtab" id="last_tab" />
            </p>
            </div>	
		<?php 
            break;
        case 'title_meta_settings':
            geodir_admin_fields($geodir_settings['title_meta_settings']);
            ?>
            <p class="submit">
            <input name="save" class="button-primary" type="submit" value="<?php 
            _e('Save changes', 'geodirectory');
            ?>
" />
            <input type="hidden" name="subtab" id="last_tab" />
            </p>
            </div>
		<?php 
            break;
        case 'notifications_settings':
            geodir_admin_fields($geodir_settings['notifications_settings']);
            ?>
			
			<p class="submit">
				
			<input name="save" class="button-primary" type="submit" value="<?php 
            _e('Save changes', 'geodirectory');
            ?>
" />
			<input type="hidden" name="subtab" id="last_tab" />
			</p>
			</div>
			
		<?php 
            break;
        case 'default_location_settings':
            ?>
            <div class="inner_content_tab_main">
                <div class="gd-content-heading">
                    <?php 
            global $wpdb;
            $location_result = geodir_get_default_location();
            $prefix = '';
            $lat = isset($location_result->city_latitude) ? $location_result->city_latitude : '';
            $lng = isset($location_result->city_longitude) ? $location_result->city_longitude : '';
            $city = isset($location_result->city) ? $location_result->city : '';
            $region = isset($location_result->region) ? $location_result->region : '';
            $country = isset($location_result->country) ? $location_result->country : '';
            $map_title = __("Set Address On Map", 'geodirectory');
            ?>

                    <h3><?php 
            _e('Set Default Location', 'geodirectory');
            ?>
</h3>

                    <input type="hidden" name="add_location" value="location">

                    <input type="hidden" name="update_city" value="<?php 
            if (isset($location_result->location_id)) {
                echo $location_result->location_id;
            }
            ?>
">

                    <input type="hidden" name="address" id="<?php 
            echo $prefix;
            ?>
address" value="">

                    <table class="form-table default_location_form">
                        <tbody>
                        <tr valign="top" class="single_select_page">
                            <th class="titledesc" scope="row"><?php 
            _e('City', 'geodirectory');
            ?>
</th>
                            <td class="forminp">
                                <div class="gtd-formfeild required">
                                    <input class="require" type="text" size="80" style="width:440px"
                                           id="<?php 
            echo $prefix;
            ?>
city" name="city"
                                           value="<?php 
            if (isset($location_result->city)) {
                echo $location_result->city;
            }
            ?>
"/>

                                    <div
                                        class="gd-location_message_error"> <?php 
            _e('This field is required.', 'geodirectory');
            ?>
</div>
                                </div>
                                <span class="description"></span>
                            </td>
                        </tr>
                        <tr valign="top" class="single_select_page">
                            <th class="titledesc" scope="row"><?php 
            _e('Region', 'geodirectory');
            ?>
</th>
                            <td class="forminp">
                                <div class="gtd-formfeild required">
                                    <input class="require" type="text" size="80" style="width:440px"
                                           id="<?php 
            echo $prefix;
            ?>
region" name="region"
                                           value="<?php 
            if (isset($location_result->region)) {
                echo $location_result->region;
            }
            ?>
"/>

                                    <div
                                        class="gd-location_message_error"> <?php 
            _e('This field is required.', 'geodirectory');
            ?>
</div>
                                </div>
                                <span class="description"></span>
                            </td>
                        </tr>
                        <tr valign="top" class="single_select_page">
                            <th class="titledesc" scope="row"><?php 
            _e('Country', 'geodirectory');
            ?>
</th>
                            <td class="forminp">
                                <div class="gtd-formfeild required" style="padding-top:10px;">
                                    <?php 
            $country_result = isset($location_result->country) ? $location_result->country : '';
            ?>
                                    <select id="<?php 
            echo $prefix;
            ?>
country" class="chosen_select"
                                            data-location_type="country" name="<?php 
            echo $prefix;
            ?>
country"
                                            data-placeholder="<?php 
            _e('Choose a country.', 'geodirectory');
            ?>
"
                                            data-addsearchtermonnorecord="1" data-ajaxchosen="0" data-autoredirect="0"
                                            data-showeverywhere="0">
                                        <?php 
            geodir_get_country_dl($country, $prefix);
            ?>
                                    </select>

                                    <div
                                        class="gd-location_message_error"><?php 
            _e('This field is required.', 'geodirectory');
            ?>
</div>

                                </div>


                                <span class="description"></span>
                            </td>
                        </tr>
                        <tr valign="top" class="single_select_page">
                            <th class="titledesc"
                                scope="row"><?php 
            _e('Set Location on Map', 'geodirectory');
            ?>
</th>
                            <td class="forminp">
                                <?php 
            /**
             * Contains add listing page map functions.
             *
             * @since 1.0.0
             */
            include geodir_plugin_path() . "/geodirectory-functions/map-functions/map_on_add_listing_page.php";
            ?>
                            </td>
                        </tr>
                        <tr valign="top" class="single_select_page">
                            <th class="titledesc" scope="row"><?php 
            _e('City Latitude', 'geodirectory');
            ?>
</th>
                            <td class="forminp">
                                <div class="gtd-formfeild required" style="padding-top:10px;">
                                    <input type="text" class="require" size="80" style="width:440px"
                                           id="<?php 
            echo $prefix;
            ?>
latitude" name="latitude"
                                           value="<?php 
            if (isset($location_result->city_latitude)) {
                echo $location_result->city_latitude;
            }
            ?>
"/>

                                    <div
                                        class="gd-location_message_error"><?php 
            _e('This field is required.', 'geodirectory');
            ?>
</div>
                                </div>
                                <span class="description"></span>
                            </td>
                        </tr>
                        <tr valign="top" class="single_select_page">
                            <th class="titledesc"
                                scope="row"><?php 
            _e('City Longitude', 'geodirectory');
            ?>
</th>
                            <td class="forminp">
                                <div class="gtd-formfeild required" style="padding-top:10px;">
                                    <input type="text" class="require" size="80" style="width:440px"
                                           id="<?php 
            echo $prefix;
            ?>
longitude" name="longitude"
                                           value="<?php 
            if (isset($location_result->city_longitude)) {
                echo $location_result->city_longitude;
            }
            ?>
"/>

                                    <div
                                        class="gd-location_message_error"><?php 
            _e('This field is required.', 'geodirectory');
            ?>
</div>
                                </div>
                                <span class="description"></span>
                            </td>
                        </tr>
                        <?php 
            if (isset($location_result->location_id) && $location_result->location_id >= 0) {
                ?>
                            <tr valign="top" class="single_select_page">
                                <th class="titledesc"
                                    scope="row"><?php 
                _e('Action For Listing', 'geodirectory');
                ?>
</th>
                                <td class="forminp">
                                    <div class="gtd-formfeild" style="padding-top:10px;">
                                        <input style="display:none;" type="radio" name="listing_action"
                                               checked="checked" value="delete"/>
                                        <label><?php 
                _e('Post will be updated if both city and map marker position has been changed.', 'geodirectory');
                ?>
</label>
                                    </div>
                                </td>
                            </tr>
                        <?php 
            }
            ?>
                        </tbody>
                    </table>

                    <p class="submit">
                        <input type="hidden" name="is_default" value="1"/>
                        <input id="location_save" type="submit" value="Save changes" class="button-primary" name="save">
                    </p>

                </div>
            </div>
            <?php 
            break;
        case $listing_type . '_fields_settings':
            geodir_custom_post_type_form();
            break;
        case 'tools_settings':
            geodir_diagnostic_tools_setting_page();
            break;
        case 'compatibility_settings':
            geodir_theme_compatibility_setting_page();
            break;
        case 'import_export':
            geodir_import_export_page();
            break;
    }
    // end of switch
}
/**
 *
 * @global object $wpdb WordPress Database object.
 *
 * @param $atts
 * @return string
 */
function geodir_sc_popular_in_neighbourhood($atts)
{
    ob_start();
    $defaults = array('post_type' => 'gd_place', 'category' => '0', 'list_sort' => 'latest', 'post_number' => 5, 'layout' => 'gridview_onehalf', 'character_count' => 20, 'add_location_filter' => 1);
    $params = shortcode_atts($defaults, $atts);
    /**
     * Being validating $params
     */
    // Check we have a valid post_type
    if (!gdsc_is_post_type_valid($params['post_type'])) {
        $params['post_type'] = 'gd_place';
    }
    // Manage the entered categories
    if (0 != $params['category'] || '' != $params['category']) {
        $params['category'] = gdsc_manage_category_choice($params['post_type'], $params['category']);
    }
    // Validate our sorting choice
    $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort']);
    // Post_number needs to be a positive integer
    $params['post_number'] = absint($params['post_number']);
    if (0 == $params['post_number']) {
        $params['post_number'] = 1;
    }
    // Validate our layout choice
    // Outside of the norm, I added some more simple terms to match the existing
    // So now I just run the switch to set it properly.
    $params['layout'] = gdsc_validate_layout_choice($params['layout']);
    // Validate character_count
    $params['character_count'] = absint($params['character_count']);
    if (20 > $params['character_count']) {
        $params['character_count'] = 20;
    }
    /**
     * End validation
     */
    global $wpdb, $post, $geodir_post_type;
    if ($geodir_post_type == '') {
        $geodir_post_type = 'gd_place';
    }
    $all_postypes = geodir_get_posttypes();
    $location_id = '';
    $not_in_array = array();
    if (geodir_is_page('detail') || geodir_is_page('preview') || geodir_is_page('add-listing')) {
        if (isset($post->post_type) && $post->post_type == $params['post_type'] && isset($post->post_location_id)) {
            $not_in_array[] = $post->ID;
            $location_id = $post->post_location_id;
        }
    } elseif (in_array($geodir_post_type, $all_postypes) && $geodir_post_type == $params['post_type']) {
        if (isset($_SESSION['gd_city']) && $_SESSION['gd_city'] != '') {
            $location_id = $wpdb->get_var($wpdb->prepare("SELECT location_id FROM " . POST_LOCATION_TABLE . " WHERE city_slug = %s", array($_SESSION['gd_city'])));
        } else {
            $default_location = geodir_get_default_location();
            $location_id = $default_location->location_id;
        }
    }
    $gd_neighbourhoods = geodir_get_neighbourhoods($location_id);
    if ($gd_neighbourhoods) {
        ?>

		<div class="geodir_locations geodir_location_listing">
			<?php 
        $hood_slug_arr = array();
        if (!empty($gd_neighbourhoods)) {
            foreach ($gd_neighbourhoods as $hoodslug) {
                $hood_slug_arr[] = $hoodslug->hood_slug;
            }
        }
        $query_args = array('posts_per_page' => $params['post_number'], 'is_geodir_loop' => true, 'post__not_in' => $not_in_array, 'gd_neighbourhood' => $hood_slug_arr, 'gd_location' => $params['add_location_filter'] ? true : false, 'post_type' => $params['post_type'], 'order_by' => $params['list_sort'], 'excerpt_length' => $params['character_count']);
        if ($params['category'] != 0 || $params['category'] != '') {
            $category_taxonomy = geodir_get_taxonomies($params['post_type']);
            $tax_query = array('taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $params['category']);
            $query_args['tax_query'] = array($tax_query);
        }
        global $gridview_columns;
        query_posts($query_args);
        if (strstr($params['layout'], 'gridview')) {
            $listing_view_exp = explode('_', $params['layout']);
            $gridview_columns = $params['layout'];
            $layout = $listing_view_exp[0];
        }
        $template = apply_filters("geodir_template_part-listing-listview", geodir_plugin_path() . '/geodirectory-templates/listing-listview.php');
        include $template;
        wp_reset_query();
        ?>

		</div>

	<?php 
    }
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
/**
 * Get location array using arguments.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @global object $wpdb WordPress Database object.
 *
 * @param null|array $args {
 *    Attributes of args.
 *
 *    @type string $what What do you want to query. Possible values: city, region, country. Default: 'city'.
 *    @type string $city_val City value.
 *    @type string $region_val Region value.
 *    @type string $country_val Country value.
 *    @type string $country_non_restricted Non restricted countries.
 *    @type string $region_non_restricted Non restricted regions.
 *    @type string $city_non_restricted Non restricted cities.
 *    @type bool $filter_by_non_restricted Filter by non restricted?.
 *    @type string $compare_operator Comparison operator.
 *    @type string $country_column_name Country column name.
 *    @type string $region_column_name Region column name.
 *    @type string $city_column_name City column name.
 *    @type bool $location_link_part Location link part.
 *    @type string $order_by Order by value.
 *    @type string $no_of_records No of records to return.
 *    @type string $spage Current page number.
 *    @type array $format {
 *        Attributes of format.
 *
 *        @type string $type Type. Default: 'list'.
 *        @type string $container_wrapper Container wrapper. Default: 'ul'.
 *        @type string $container_wrapper_attr Container wrapper attr.
 *        @type string $item_wrapper Item wrapper. Default: 'li'.
 *        @type string $item_wrapper_attr Item wrapper attr.
 *
 *    }
 *
 * }
 * @param bool $switcher Todo: describe this part.
 * @return array|mixed|string
 */
function geodir_get_location_array($args = null, $switcher = false)
{
    global $wpdb;
    $defaults = array('what' => 'city', 'city_val' => '', 'region_val' => '', 'country_val' => '', 'country_non_restricted' => '', 'region_non_restricted' => '', 'city_non_restricted' => '', 'filter_by_non_restricted' => true, 'compare_operator' => 'like', 'country_column_name' => 'country', 'region_column_name' => 'region', 'city_column_name' => 'city', 'location_link_part' => true, 'order_by' => 'asc', 'no_of_records' => '', 'spage' => '', 'format' => array('type' => 'list', 'container_wrapper' => 'ul', 'container_wrapper_attr' => '', 'item_wrapper' => 'li', 'item_wrapper_attr' => ''));
    $location_args = wp_parse_args($args, $defaults);
    $search_query = '';
    $location_link_column = '';
    $location_default = geodir_get_default_location();
    if ($location_args['filter_by_non_restricted']) {
        // Non restricted countries
        if ($location_args['country_non_restricted'] == '') {
            if (get_option('geodir_enable_country') == 'default') {
                $country_non_retsricted = isset($location_default->country) ? $location_default->country : '';
                $location_args['country_non_restricted'] = $country_non_retsricted;
            } else {
                if (get_option('geodir_enable_country') == 'selected') {
                    $country_non_retsricted = get_option('geodir_selected_countries');
                    if (!empty($country_non_retsricted) && is_array($country_non_retsricted)) {
                        $country_non_retsricted = implode(',', $country_non_retsricted);
                    }
                    $location_args['country_non_restricted'] = $country_non_retsricted;
                }
            }
            $location_args['country_non_restricted'] = geodir_parse_location_list($location_args['country_non_restricted']);
        }
        //Non restricted Regions
        if ($location_args['region_non_restricted'] == '') {
            if (get_option('geodir_enable_region') == 'default') {
                $regoin_non_restricted = isset($location_default->region) ? $location_default->region : '';
                $location_args['region_non_restricted'] = $regoin_non_restricted;
            } else {
                if (get_option('geodir_enable_region') == 'selected') {
                    $regoin_non_restricted = get_option('geodir_selected_regions');
                    if (!empty($regoin_non_restricted) && is_array($regoin_non_restricted)) {
                        $regoin_non_restricted = implode(',', $regoin_non_restricted);
                    }
                    $location_args['region_non_restricted'] = $regoin_non_restricted;
                }
            }
            $location_args['region_non_restricted'] = geodir_parse_location_list($location_args['region_non_restricted']);
        }
        //Non restricted cities
        if ($location_args['city_non_restricted'] == '') {
            if (get_option('geodir_enable_city') == 'default') {
                $city_non_retsricted = isset($location_default->city) ? $location_default->city : '';
                $location_args['city_non_restricted'] = $city_non_retsricted;
            } else {
                if (get_option('geodir_enable_city') == 'selected') {
                    $city_non_restricted = get_option('geodir_selected_cities');
                    if (!empty($city_non_restricted) && is_array($city_non_restricted)) {
                        $city_non_restricted = implode(',', $city_non_restricted);
                    }
                    $location_args['city_non_restricted'] = $city_non_restricted;
                }
            }
            $location_args['city_non_restricted'] = geodir_parse_location_list($location_args['city_non_restricted']);
        }
    }
    if ($location_args['what'] == '') {
        $location_args['what'] = 'city';
    }
    if ($location_args['location_link_part']) {
        switch ($location_args['what']) {
            case 'country':
                if (get_option('permalink_structure') != '') {
                    $location_link_column = ", CONCAT_WS('/', country_slug) AS location_link ";
                } else {
                    $location_link_column = ", CONCAT_WS('&gd_country=', '', country_slug) AS location_link ";
                }
                break;
            case 'region':
                if (get_option('permalink_structure') != '') {
                    $location_link_column = ", CONCAT_WS('/', country_slug, region_slug) AS location_link ";
                } else {
                    $location_link_column = ", CONCAT_WS('&', CONCAT('&gd_country=', country_slug), CONCAT('gd_region=', region_slug) ) AS location_link ";
                }
                break;
            case 'city':
                if (get_option('permalink_structure') != '') {
                    $location_link_column = ", CONCAT_WS('/', country_slug, region_slug, city_slug) AS location_link ";
                } else {
                    $location_link_column = ", CONCAT_WS('&', CONCAT('&gd_country=', country_slug), CONCAT('gd_region=', region_slug) ,CONCAT('gd_city=' , city_slug)) AS location_link ";
                }
                /*else
                				{
                					if ( get_option('permalink_structure') != '' )
                						$location_link_column = " ,   city_slug as location_link ";
                					else
                						$location_link_column = " , CONCAT_WS('&gd_city=', '',city_slug) as location_link ";
                
                				}*/
                break;
                /*default:
                				if(get_option('geodir_show_location_url')=='all')
                				{
                					if ( get_option('permalink_structure') != '' )
                						$location_link_column = " , CONCAT_WS('/', country_slug, region_slug, city_slug) as location_link ";
                					else
                						$location_link_column = " , CONCAT_WS('&', CONCAT('&gd_country=' ,country_slug) ,CONCAT('gd_region=' , region_slug) ,CONCAT('gd_city=' , city_slug)) as location_link ";
                				}
                				else
                				{
                					if ( get_option('permalink_structure') != '' )
                						$location_link_column = " ,   city_slug as location_link ";
                					else
                						$location_link_column = " , CONCAT_WS('&gd_city=', '',city_slug) as location_link ";
                
                				}
                				break;*/
        }
    }
    switch ($location_args['compare_operator']) {
        case 'like':
            if (isset($location_args['country_val']) && $location_args['country_val'] != '') {
                //$search_query .= " AND lower(".$location_args['country_column_name'].") like  '". mb_strtolower( $location_args['country_val'] )."%' ";
                $countries_search_sql = geodir_countries_search_sql($location_args['country_val']);
                $countries_search_sql = $countries_search_sql != '' ? " OR FIND_IN_SET(country, '" . $countries_search_sql . "')" : '';
                $translated_country_val = sanitize_title(trim(wp_unslash($location_args['country_val'])));
                $search_query .= " AND ( lower(" . $location_args['country_column_name'] . ") like  '%" . mb_strtolower($location_args['country_val']) . "%' OR  lower(country_slug) LIKE '" . $translated_country_val . "%' " . $countries_search_sql . " ) ";
            }
            if (isset($location_args['region_val']) && $location_args['region_val'] != '') {
                $search_query .= " AND lower(" . $location_args['region_column_name'] . ") like  '%" . mb_strtolower($location_args['region_val']) . "%' ";
            }
            if (isset($location_args['city_val']) && $location_args['city_val'] != '') {
                $search_query .= " AND lower(" . $location_args['city_column_name'] . ") like  '%" . mb_strtolower($location_args['city_val']) . "%' ";
            }
            break;
        case 'in':
            if (isset($location_args['country_val']) && $location_args['country_val'] != '') {
                $location_args['country_val'] = geodir_parse_location_list($location_args['country_val']);
                $search_query .= " AND lower(" . $location_args['country_column_name'] . ") in({$location_args['country_val']}) ";
            }
            if (isset($location_args['region_val']) && $location_args['region_val'] != '') {
                $location_args['region_val'] = geodir_parse_location_list($location_args['region_val']);
                $search_query .= " AND lower(" . $location_args['region_column_name'] . ") in({$location_args['region_val']}) ";
            }
            if (isset($location_args['city_val']) && $location_args['city_val'] != '') {
                $location_args['city_val'] = geodir_parse_location_list($location_args['city_val']);
                $search_query .= " AND lower(" . $location_args['city_column_name'] . ") in({$location_args['city_val']}) ";
            }
            break;
        default:
            if (isset($location_args['country_val']) && $location_args['country_val'] != '') {
                //$search_query .= " AND lower(".$location_args['country_column_name'].") =  '". mb_strtolower($location_args['country_val'])."' ";
                $countries_search_sql = geodir_countries_search_sql($location_args['country_val']);
                $countries_search_sql = $countries_search_sql != '' ? " OR FIND_IN_SET(country, '" . $countries_search_sql . "')" : '';
                $translated_country_val = sanitize_title(trim(wp_unslash($location_args['country_val'])));
                $search_query .= " AND ( lower(" . $location_args['country_column_name'] . ") =  '" . mb_strtolower($location_args['country_val']) . "' OR  lower(country_slug) LIKE '" . $translated_country_val . "%' " . $countries_search_sql . " ) ";
            }
            if (isset($location_args['region_val']) && $location_args['region_val'] != '') {
                $search_query .= " AND lower(" . $location_args['region_column_name'] . ") =  '" . mb_strtolower($location_args['region_val']) . "' ";
            }
            if (isset($location_args['city_val']) && $location_args['city_val'] != '') {
                $search_query .= " AND lower(" . $location_args['city_column_name'] . ") =  '" . mb_strtolower($location_args['city_val']) . "' ";
            }
            break;
    }
    // end of switch
    if ($location_args['country_non_restricted'] != '') {
        $search_query .= " AND LOWER(country) IN ({$location_args['country_non_restricted']}) ";
    }
    if ($location_args['region_non_restricted'] != '') {
        if ($location_args['what'] == 'region' || $location_args['what'] == 'city') {
            $search_query .= " AND LOWER(region) IN ({$location_args['region_non_restricted']}) ";
        }
    }
    if ($location_args['city_non_restricted'] != '') {
        if ($location_args['what'] == 'city') {
            $search_query .= " AND LOWER(city) IN ({$location_args['city_non_restricted']}) ";
        }
    }
    //page
    if ($location_args['no_of_records']) {
        $spage = $location_args['no_of_records'] * $location_args['spage'];
    } else {
        $spage = "0";
    }
    // limit
    $limit = $location_args['no_of_records'] != '' ? ' LIMIT ' . $spage . ', ' . (int) $location_args['no_of_records'] . ' ' : '';
    // display all locations with same name also
    $search_field = $location_args['what'];
    if ($switcher) {
        $select = $search_field . $location_link_column;
        $group_by = $search_field;
        $order_by = $search_field;
        if ($search_field == 'city') {
            $select .= ', country, region, city, country_slug, region_slug, city_slug';
            $group_by = 'country, region, city';
            $order_by = 'city, region, country';
        } else {
            if ($search_field == 'region') {
                $select .= ', country, region, country_slug, region_slug';
                $group_by = 'country, region';
                $order_by = 'region, country';
            } else {
                if ($search_field == 'country') {
                    $select .= ', country, country_slug';
                    $group_by = 'country';
                    $order_by = 'country';
                }
            }
        }
        $main_location_query = "SELECT " . $select . " FROM " . POST_LOCATION_TABLE . " WHERE 1=1 " . $search_query . " GROUP BY " . $group_by . " ORDER BY " . $order_by . " " . $location_args['order_by'] . " " . $limit;
    } else {
        $main_location_query = "SELECT {$location_args['what']} {$location_link_column} FROM " . POST_LOCATION_TABLE . " WHERE 1=1 " . $search_query . " GROUP BY {$location_args['what']} ORDER BY {$location_args['what']} {$location_args['order_by']} {$limit}";
    }
    $locations = $wpdb->get_results($main_location_query);
    if ($switcher && !empty($locations)) {
        $new_locations = array();
        foreach ($locations as $location) {
            //print_r($location);
            //echo '###'.$search_field;
            $new_location = $location;
            $label = $location->{$search_field};
            if (($search_field == 'city' || $search_field == 'region') && (int) geodir_location_check_duplicate($search_field, $label) > 1) {
                if ($search_field == 'city') {
                    $label .= ', ' . $location->region;
                } else {
                    if ($search_field == 'region') {
                        $country_iso2 = geodir_location_get_iso2($location->country);
                        $country_iso2 = $country_iso2 != '' ? $country_iso2 : $location->country;
                        $label .= $country_iso2 != '' ? ', ' . $country_iso2 : '';
                    }
                }
            }
            $new_location->title = $location->{$search_field};
            $new_location->{$search_field} = $label;
            $new_location->label = $label;
            $new_locations[] = $new_location;
        }
        $locations = $new_locations;
    }
    $location_as_formated_list = "";
    if (!empty($location_args['format'])) {
        if ($location_args['format']['type'] == 'array') {
            return $locations;
        } elseif ($location_args['format']['type'] == 'jason') {
            return json_encode($locations);
        } else {
            $base_location_link = geodir_get_location_link('base');
            $container_wrapper = '';
            $container_wrapper_attr = '';
            $item_wrapper = '';
            $item_wrapper_attr = '';
            if (isset($location_args['format']['container_wrapper']) && !empty($location_args['format']['container_wrapper'])) {
                $container_wrapper = $location_args['format']['container_wrapper'];
            }
            if (isset($location_args['format']['container_wrapper_attr']) && !empty($location_args['format']['container_wrapper_attr'])) {
                $container_wrapper_attr = $location_args['format']['container_wrapper_attr'];
            }
            if (isset($location_args['format']['item_wrapper']) && !empty($location_args['format']['item_wrapper'])) {
                $item_wrapper = $location_args['format']['item_wrapper'];
            }
            if (isset($location_args['format']['item_wrapper_attr']) && !empty($location_args['format']['item_wrapper_attr'])) {
                $item_wrapper_attr = $location_args['format']['item_wrapper_attr'];
            }
            if (!empty($container_wrapper)) {
                $location_as_formated_list = "<" . $container_wrapper . " " . $container_wrapper_attr . " >";
            }
            if (!empty($locations)) {
                foreach ($locations as $location) {
                    if (!empty($item_wrapper)) {
                        $location_as_formated_list .= "<" . $item_wrapper . " " . $item_wrapper_attr . " >";
                    }
                    if (isset($location->location_link)) {
                        $location_as_formated_list .= "<a href='" . geodir_location_permalink_url($base_location_link . $location->location_link) . "' ><i class='fa fa-caret-right'></i> ";
                    }
                    $location_as_formated_list .= $location->{$location_args}['what'];
                    if (isset($location->location_link)) {
                        $location_as_formated_list .= "</a>";
                    }
                    if (!empty($item_wrapper)) {
                        $location_as_formated_list .= "</" . $item_wrapper . ">";
                    }
                }
            }
            return $location_as_formated_list;
        }
    }
    return $locations;
}
/**
 * Add the location variables in session.
 *
 * @since 1.0.0
 *
 * @param object $wp The WordPress object.
 */
function geodir_set_location_var_in_session_in_core($wp)
{
    //$wp->geodir_query_vars = $wp->query_vars ;
    // this code will determine when a user wants to switch location
    // Query Vars will have page_id parameter
    // check if query var has page_id and that page id is location page
    geodir_set_is_geodir_page($wp);
    if (!get_option('geodir_set_as_home')) {
        if (empty($wp->query_vars) || !array_diff(array_keys($wp->query_vars), array('preview', 'page', 'paged', 'cpage'))) {
            if ('page' == get_option('show_on_front')) {
                $wp->query_vars['page_id'] = get_option('page_on_front');
            }
        }
    }
    if (isset($wp->query_vars['page_id']) && $wp->query_vars['page_id'] == geodir_location_page_id()) {
        $gd_country = '';
        $gd_region = '';
        $gd_city = '';
        if (isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] != '') {
            $gd_country = urldecode($wp->query_vars['gd_country']);
        }
        if (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] != '') {
            $gd_region = urldecode($wp->query_vars['gd_region']);
        }
        if (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] != '') {
            $gd_city = urldecode($wp->query_vars['gd_city']);
        }
        if (!($gd_country == '' && $gd_region == '' && $gd_city == '')) {
            $default_location = geodir_get_default_location();
            if (get_option('geodir_add_location_url')) {
                if (get_option('geodir_show_location_url') != 'all') {
                    if ($gd_region == '') {
                        if (isset($_SESSION['gd_region'])) {
                            $gd_region = $_SESSION['gd_region'];
                        } else {
                            $gd_region = $default_location->region_slug;
                        }
                    }
                    if ($gd_city == '') {
                        if (isset($_SESSION['gd_city'])) {
                            $gd_city = $_SESSION['gd_city'];
                        } else {
                            $gd_city = $default_location->city_slug;
                        }
                        $base_location_link = geodir_get_location_link('base');
                        wp_redirect($base_location_link . '/' . $gd_country . '/' . $gd_region . '/' . $gd_city);
                        exit;
                    }
                }
            }
            $args = array('what' => 'city', 'city_val' => $gd_city, 'region_val' => $gd_region, 'country_val' => $gd_country, 'country_column_name' => 'country_slug', 'region_column_name' => 'region_slug', 'city_column_name' => 'city_slug', 'location_link_part' => false, 'compare_operator' => '');
            $location_array = function_exists('geodir_get_location_array') ? geodir_get_location_array($args) : array();
            if (!empty($location_array)) {
                $_SESSION['gd_multi_location'] = 1;
                $_SESSION['gd_country'] = $gd_country;
                $_SESSION['gd_region'] = $gd_region;
                $_SESSION['gd_city'] = $gd_city;
                $wp->query_vars['gd_country'] = $gd_country;
                $wp->query_vars['gd_region'] = $gd_region;
                $wp->query_vars['gd_city'] = $gd_city;
            } else {
                unset($_SESSION['gd_multi_location'], $_SESSION['gd_city'], $_SESSION['gd_region'], $_SESSION['gd_country']);
            }
        } else {
            unset($_SESSION['gd_multi_location'], $_SESSION['gd_city'], $_SESSION['gd_region'], $_SESSION['gd_country']);
        }
    } else {
        if (isset($wp->query_vars['post_type']) && $wp->query_vars['post_type'] != '') {
            if (!is_admin()) {
                $requested_post_type = $wp->query_vars['post_type'];
                // check if this post type is geodirectory post types
                $post_type_array = geodir_get_posttypes();
                if (in_array($requested_post_type, $post_type_array)) {
                    // now u can apply geodirectory related manipulation.
                }
            }
        } else {
            // check if a geodirectory taxonomy is set
            $gd_country = '';
            $gd_region = '';
            $gd_city = '';
            $is_geodir_taxonomy = false;
            $is_geodir_taxonomy_term = false;
            // the last term is real geodirectory taxonomy term or not
            $is_geodir_location_found = false;
            $geodir_taxonomy = '';
            $geodir_post_type = '';
            $geodir_term = '';
            $geodir_set_location_session = true;
            $geodir_taxonomis = geodir_get_taxonomies('', true);
            foreach ($geodir_taxonomis as $taxonomy) {
                if (array_key_exists($taxonomy, $wp->query_vars)) {
                    $is_geodir_taxonomy = true;
                    $geodir_taxonomy = $taxonomy;
                    $geodir_post_type = str_replace('category', '', $taxonomy);
                    $geodir_post_type = str_replace('_tags', '', $geodir_post_type);
                    $geodir_term = $wp->query_vars[$geodir_taxonomy];
                    break;
                }
            }
            // now get an array of all terms seperated by '/'
            $geodir_terms = explode('/', $geodir_term);
            $geodir_last_term = end($geodir_terms);
            if ($is_geodir_taxonomy) {
                $wp->query_vars['post_type'] = $geodir_post_type;
                // now check if last term is a post of geodirectory post types
                $geodir_post = get_posts(array('name' => $geodir_last_term, 'posts_per_page' => 1, 'post_type' => $geodir_post_type));
                if (empty($geodir_post)) {
                    $geodir_post = get_posts(array('name' => $geodir_last_term, 'posts_per_page' => 1, 'post_type' => $geodir_post_type, 'post_status' => 'draft', 'suppress_filters' => false));
                }
                if (!empty($geodir_post)) {
                    if ($geodir_post[0]->post_status != 'publish') {
                        foreach ($wp->query_vars as $key => $vars) {
                            unset($wp->query_vars[$key]);
                        }
                        $wp->query_vars['error'] = '404';
                        // set it as 404 if post exists but its status is not published yet
                    } else {
                        //$wp->query_vars[$geodir_taxonomy] = str_replace( '/'.$geodir_last_term , ''  , $geodir_term);
                        $wp->query_vars[$geodir_post_type] = $geodir_last_term;
                        $wp->query_vars['name'] = $geodir_last_term;
                    }
                    $geodir_term = str_replace('/' . $geodir_last_term, '', $geodir_term, $post_title_replace_count);
                    if (!$post_title_replace_count) {
                        $geodir_term = str_replace($geodir_last_term, '', $geodir_term, $post_title_replace_count);
                    }
                    $geodir_terms = explode('/', $geodir_term);
                    $geodir_last_term = end($geodir_terms);
                    $geodir_set_location_session = false;
                    //return ;
                }
                $geodir_location_terms = '';
                // if last term is not a post then check if last term is a term of the specific texonomy or not
                if (geodir_term_exists($geodir_last_term, $geodir_taxonomy)) {
                    $is_geodir_taxonomy_term = true;
                    $geodir_set_location_session = false;
                }
                // now check if there is location parts in the url or not
                if (get_option('geodir_add_location_url')) {
                    $default_location = geodir_get_default_location();
                    if (get_option('geodir_show_location_url') == 'all') {
                        if (count($geodir_terms) >= 3) {
                            $gd_country = urldecode($geodir_terms[0]);
                            $gd_region = urldecode($geodir_terms[1]);
                            $gd_city = urldecode($geodir_terms[2]);
                        } else {
                            if (count($geodir_terms) >= 2) {
                                $gd_country = urldecode($geodir_terms[0]);
                                $gd_region = urldecode($geodir_terms[1]);
                            } else {
                                if (count($geodir_terms) >= 1) {
                                    $gd_country = urldecode($geodir_terms[0]);
                                }
                            }
                        }
                        if (strtolower($default_location->country_slug) == strtolower($gd_country) && strtolower($default_location->region_slug) == strtolower($gd_region) && strtolower($default_location->city_slug) == strtolower($gd_city)) {
                            $is_geodir_location_found = true;
                        }
                        // if location has not been found for country , region and city then search for country and region only
                        if (!$is_geodir_location_found) {
                            $gd_city = '';
                            if (strtolower($default_location->country_slug) == strtolower($gd_country) && strtolower($default_location->region_slug) == strtolower($gd_region)) {
                                $is_geodir_location_found = true;
                            }
                        }
                        // if location has not been found for country , region  then search for country only
                        if (!$is_geodir_location_found) {
                            $gd_city = '';
                            $gd_region = '';
                            if (strtolower($default_location->country_slug) == strtolower($gd_country)) {
                                $is_geodir_location_found = true;
                            }
                        }
                    } else {
                        $gd_city = $geodir_terms[0];
                        if (strtolower($default_location->city_slug) == strtolower($gd_city)) {
                            $is_geodir_location_found = true;
                            $gd_region = $default_location->region_slug;
                            $gd_country = $default_location->country_slug;
                        }
                    }
                    // if locaton still not found then clear location related session variables
                    if ($is_geodir_location_found && $geodir_set_location_session) {
                        $_SESSION['gd_multi_location'] = 1;
                        $_SESSION['gd_country'] = $gd_country;
                        $_SESSION['gd_region'] = $gd_region;
                        $_SESSION['gd_city'] = $gd_city;
                    }
                    if (get_option('geodir_show_location_url') != 'all') {
                        $gd_country = '';
                        $gd_region = '';
                    }
                    if ($is_geodir_location_found) {
                        $wp->query_vars['gd_country'] = $gd_country;
                        $wp->query_vars['gd_region'] = $gd_region;
                        $wp->query_vars['gd_city'] = $gd_city;
                    } else {
                        $gd_country = '';
                        $gd_region = '';
                        $gd_city = '';
                    }
                }
                $wp->query_vars[$geodir_taxonomy] = $geodir_term;
                // eliminate location related terms from taxonomy term
                if ($gd_country != '') {
                    $wp->query_vars[$geodir_taxonomy] = preg_replace('/' . urlencode($gd_country) . '/', '', $wp->query_vars[$geodir_taxonomy], 1);
                }
                if ($gd_region != '') {
                    $wp->query_vars[$geodir_taxonomy] = preg_replace('/' . urlencode($gd_region) . '/', '', $wp->query_vars[$geodir_taxonomy], 1);
                }
                if ($gd_city != '') {
                    $wp->query_vars[$geodir_taxonomy] = preg_replace('/' . urlencode($gd_city) . '/', '', $wp->query_vars[$geodir_taxonomy], 1);
                }
                $wp->query_vars[$geodir_taxonomy] = str_replace('///', '', $wp->query_vars[$geodir_taxonomy]);
                $wp->query_vars[$geodir_taxonomy] = str_replace('//', '', $wp->query_vars[$geodir_taxonomy]);
                $wp->query_vars[$geodir_taxonomy] = trim($wp->query_vars[$geodir_taxonomy], '/');
                if ($wp->query_vars[$geodir_taxonomy] == '') {
                    unset($wp->query_vars[$geodir_taxonomy]);
                } else {
                    if (!$is_geodir_taxonomy_term) {
                        foreach ($wp->query_vars as $key => $vars) {
                            unset($wp->query_vars[$key]);
                        }
                        $wp->query_vars['error'] = '404';
                    }
                }
            }
        }
    }
    if (isset($_SESSION['gd_multi_location']) && $_SESSION['gd_multi_location'] == 1) {
        $wp->query_vars['gd_country'] = $_SESSION['gd_country'];
        $wp->query_vars['gd_region'] = $_SESSION['gd_region'];
        $wp->query_vars['gd_city'] = $_SESSION['gd_city'];
    }
    // now check if there is location parts in the url or not
    if (get_option('geodir_add_location_url')) {
        if (get_option('geodir_show_location_url') != 'all') {
            if (isset($wp->query_vars['gd_country'])) {
                $wp->query_vars['gd_country'] = '';
            }
            if (isset($wp->query_vars['gd_region'])) {
                $wp->query_vars['gd_region'] = '';
            }
        }
    } else {
        if (isset($wp->query_vars['gd_country'])) {
            $wp->query_vars['gd_country'] = '';
        }
        if (isset($wp->query_vars['gd_region'])) {
            $wp->query_vars['gd_region'] = '';
        }
        if (isset($wp->query_vars['gd_city'])) {
            $wp->query_vars['gd_city'] = '';
        }
    }
}
Exemplo n.º 11
0
 /**
  * Front-end display content for listing page map widget.
  *
  * @since 1.0.0
  * @since 1.5.1 Declare function public.
  *
  * @global object $post The current post object.
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     if (geodir_is_page('listing') || geodir_is_page('author') || geodir_is_page('search') || geodir_is_page('detail')) {
         extract($args, EXTR_SKIP);
         /** This action is documented in geodirectory_shortcodes.php */
         $width = empty($instance['width']) ? '294' : apply_filters('widget_width', $instance['width']);
         /** This action is documented in geodirectory_shortcodes.php */
         $height = empty($instance['heigh']) ? '370' : apply_filters('widget_heigh', $instance['heigh']);
         /** This action is documented in geodirectory_shortcodes.php */
         $maptype = empty($instance['maptype']) ? 'ROADMAP' : apply_filters('widget_maptype', $instance['maptype']);
         /** This action is documented in geodirectory_shortcodes.php */
         $zoom = empty($instance['zoom']) ? '13' : apply_filters('widget_zoom', $instance['zoom']);
         /** This action is documented in geodirectory_shortcodes.php */
         $autozoom = empty($instance['autozoom']) ? '' : apply_filters('widget_autozoom', $instance['autozoom']);
         /**
          * Filter the listing map value widget_sticky, to set if the map should be sticky or not (scroll with page).
          *
          * @since 1.0.0
          * @param bool $sticky True if should be sticky, false if not
          */
         $sticky = empty($instance['sticky']) ? '' : apply_filters('widget_sticky', $instance['sticky']);
         /** This action is documented in geodirectory_shortcodes.php */
         $scrollwheel = empty($instance['scrollwheel']) ? '0' : apply_filters('widget_scrollwheel', $instance['scrollwheel']);
         $showall = empty($instance['showall']) ? '0' : apply_filters('widget_showall', $instance['showall']);
         /**
          * Filter the listing map should to be displayed or not.
          *
          * @since 1.4.6
          *
          * @param bool $display true if map should be displayed, false if not.
          */
         $show_map = apply_filters('geodir_show_map_listing', $display = true);
         if (!$show_map) {
             return;
         }
         $map_args = array();
         $map_args['map_canvas_name'] = str_replace('-', '_', $args['widget_id']);
         $map_args['width'] = $width;
         $map_args['height'] = $height;
         $map_args['scrollwheel'] = $scrollwheel;
         $map_args['showall'] = $showall;
         $map_args['child_collapse'] = '0';
         $map_args['sticky'] = $sticky;
         $map_args['enable_cat_filters'] = false;
         $map_args['enable_text_search'] = false;
         $map_args['enable_post_type_filters'] = false;
         $map_args['enable_location_filters'] = false;
         $map_args['enable_jason_on_load'] = true;
         if (is_single()) {
             global $post;
             $map_default_lat = $address_latitude = $post->post_latitude;
             $map_default_lng = $address_longitude = $post->post_longitude;
             $mapview = $post->post_mapview;
             $mapzoom = $post->post_mapzoom;
             $map_args['map_class_name'] = 'geodir-map-listing-page-single';
         } else {
             $default_location = geodir_get_default_location();
             $map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : '';
             $map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : '';
             $map_args['map_class_name'] = 'geodir-map-listing-page';
             $mapview = $maptype;
         }
         if (empty($mapview)) {
             $mapview = 'ROADMAP';
         }
         if (empty($mapzoom)) {
             $mapzoom = $zoom;
         }
         // Set default map options
         $map_args['ajax_url'] = geodir_get_ajax_url();
         $map_args['latitude'] = $map_default_lat;
         $map_args['longitude'] = $map_default_lng;
         $map_args['zoom'] = $zoom;
         //$map_args['scrollwheel'] = true;
         $map_args['scrollwheel'] = $scrollwheel;
         $map_args['showall'] = $showall;
         $map_args['streetViewControl'] = true;
         $map_args['maptype'] = $mapview;
         $map_args['showPreview'] = '0';
         $map_args['maxZoom'] = 21;
         $map_args['autozoom'] = $autozoom;
         $map_args['bubble_size'] = 'small';
         echo $before_widget;
         geodir_draw_map($map_args);
         echo $after_widget;
     }
 }
Exemplo n.º 12
0
/**
 * Displays custom fields html.
 *
 * @since 1.0.0
 * @since 1.5.2 Added TERRAIN map type.
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global object $post The current post object.
 * @global array $geodir_addon_list List of active GeoDirectory extensions.
 * @param int|string $package_id The package ID.
 * @param string $default Optional. When set to "default" it will display only default fields.
 * @param string $post_type Optional. The wordpress post type.
 */
function geodir_get_custom_fields_html($package_id = '', $default = 'custom', $post_type = 'gd_place')
{
    global $is_default, $mapzoom;
    $show_editors = array();
    $listing_type = $post_type;
    $custom_fields = geodir_post_custom_fields($package_id, $default, $post_type);
    foreach ($custom_fields as $key => $val) {
        $val = stripslashes_deep($val);
        // strip slashes from labels
        $name = $val['name'];
        $site_title = $val['site_title'];
        $type = $val['type'];
        $admin_desc = $val['desc'];
        $option_values = $val['option_values'];
        $is_required = $val['is_required'];
        $is_default = $val['is_default'];
        $is_admin = $val['is_admin'];
        $required_msg = $val['required_msg'];
        $extra_fields = unserialize($val['extra_fields']);
        $value = '';
        /* field available to site admin only for edit */
        $for_admin_use = isset($val['for_admin_use']) && (int) $val['for_admin_use'] == 1 ? true : false;
        if ($for_admin_use && !is_super_admin()) {
            continue;
        }
        if (is_admin()) {
            global $post;
            if (isset($_REQUEST['post'])) {
                $_REQUEST['pid'] = $_REQUEST['post'];
            }
        }
        if (isset($_REQUEST['backandedit']) && $_REQUEST['backandedit'] && isset($_SESSION['listing'])) {
            $post = unserialize($_SESSION['listing']);
            $value = isset($post[$name]) ? $post[$name] : '';
        } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
            $value = geodir_get_post_meta($_REQUEST['pid'], $name, true);
        } else {
            if ($value == '') {
                $value = $val['default'];
            }
        }
        /**
         * Called before the custom fields info is output for submitting a post.
         *
         * Used dynamic hook type geodir_before_custom_form_field_$name.
         *
         * @since 1.0.0
         * @param string $listing_type The post post type.
         * @param int $package_id The price package ID for the post.
         * @param array $val The settings array for the field. {@see geodir_custom_field_save()}.
         * @see 'geodir_after_custom_form_field_$name'
         */
        do_action('geodir_before_custom_form_field_' . $name, $listing_type, $package_id, $val);
        if ($type == 'fieldset') {
            ?>
<h5><?php 
            echo $site_title;
            ?>
            <?php 
            if ($admin_desc != '') {
                echo '<small>( ' . $admin_desc . ' )</small>';
            }
            ?>
            </h5><?php 
        } elseif ($type == 'address') {
            $prefix = $name . '_';
            $site_title != '' ? $address_title = $site_title : ($address_title = ucwords($prefix . ' address'));
            $extra_fields['zip_lable'] != '' ? $zip_title = $extra_fields['zip_lable'] : ($zip_title = ucwords($prefix . ' zip/post code '));
            $extra_fields['map_lable'] != '' ? $map_title = $extra_fields['map_lable'] : ($map_title = ucwords('set address on map'));
            $extra_fields['mapview_lable'] != '' ? $mapview_title = $extra_fields['mapview_lable'] : ($mapview_title = ucwords($prefix . ' mapview'));
            $address = '';
            $zip = '';
            $mapview = '';
            $mapzoom = '';
            $lat = '';
            $lng = '';
            if (isset($_REQUEST['backandedit']) && $_REQUEST['backandedit'] && isset($_SESSION['listing'])) {
                $post = unserialize($_SESSION['listing']);
                $address = $post[$prefix . 'address'];
                $zip = isset($post[$prefix . 'zip']) ? $post[$prefix . 'zip'] : '';
                $lat = isset($post[$prefix . 'latitude']) ? $post[$prefix . 'latitude'] : '';
                $lng = isset($post[$prefix . 'longitude']) ? $post[$prefix . 'longitude'] : '';
                $mapview = isset($post[$prefix . 'mapview']) ? $post[$prefix . 'mapview'] : '';
                $mapzoom = isset($post[$prefix . 'mapzoom']) ? $post[$prefix . 'mapzoom'] : '';
            } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '' && ($post_info = geodir_get_post_info($_REQUEST['pid']))) {
                $post_info = (array) $post_info;
                $address = $post_info[$prefix . 'address'];
                $zip = isset($post_info[$prefix . 'zip']) ? $post_info[$prefix . 'zip'] : '';
                $lat = isset($post_info[$prefix . 'latitude']) ? $post_info[$prefix . 'latitude'] : '';
                $lng = isset($post_info[$prefix . 'longitude']) ? $post_info[$prefix . 'longitude'] : '';
                $mapview = isset($post_info[$prefix . 'mapview']) ? $post_info[$prefix . 'mapview'] : '';
                $mapzoom = isset($post_info[$prefix . 'mapzoom']) ? $post_info[$prefix . 'mapzoom'] : '';
            }
            $location = geodir_get_default_location();
            if (empty($city)) {
                $city = isset($location->city) ? $location->city : '';
            }
            if (empty($region)) {
                $region = isset($location->region) ? $location->region : '';
            }
            if (empty($country)) {
                $country = isset($location->country) ? $location->country : '';
            }
            $lat_lng_blank = false;
            if (empty($lat) && empty($lng)) {
                $lat_lng_blank = true;
            }
            if (empty($lat)) {
                $lat = isset($location->city_latitude) ? $location->city_latitude : '';
            }
            if (empty($lng)) {
                $lng = isset($location->city_longitude) ? $location->city_longitude : '';
            }
            /**
             * Filter the default latitude.
             *
             * @since 1.0.0
             *
             * @param float $lat Default latitude.
             * @param bool $is_admin For admin use only?.
             */
            $lat = apply_filters('geodir_default_latitude', $lat, $is_admin);
            /**
             * Filter the default longitude.
             *
             * @since 1.0.0
             *
             * @param float $lat Default longitude.
             * @param bool $is_admin For admin use only?.
             */
            $lng = apply_filters('geodir_default_longitude', $lng, $is_admin);
            ?>

            <div id="geodir_<?php 
            echo $prefix . 'address';
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
            _e($address_title, 'geodirectory');
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label>
                <input type="text" field_type="<?php 
            echo $type;
            ?>
" name="<?php 
            echo $prefix . 'address';
            ?>
"
                       id="<?php 
            echo $prefix . 'address';
            ?>
" class="geodir_textfield"
                       value="<?php 
            echo esc_attr(stripslashes($address));
            ?>
"/>
                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>


            <?php 
            /**
             * Called after the address input on the add listings.
             *
             * This is used by the location manage to add further locations info etc.
             *
             * @since 1.0.0
             * @param array $val The array of setting for the custom field. {@see geodir_custom_field_save()}.
             */
            do_action('geodir_address_extra_listing_fields', $val);
            if (isset($extra_fields['show_zip']) && $extra_fields['show_zip']) {
                ?>

                <div id="geodir_<?php 
                echo $prefix . 'zip';
                ?>
_row"
                     class="<?php 
                /*if($is_required) echo 'required_field';*/
                ?>
 geodir_form_row clearfix">
                    <label>
                        <?php 
                _e($zip_title, 'geodirectory');
                ?>
                        <?php 
                /*if($is_required) echo '<span>*</span>';*/
                ?>
                    </label>
                    <input type="text" field_type="<?php 
                echo $type;
                ?>
" name="<?php 
                echo $prefix . 'zip';
                ?>
"
                           id="<?php 
                echo $prefix . 'zip';
                ?>
" class="geodir_textfield autofill"
                           value="<?php 
                echo esc_attr(stripslashes($zip));
                ?>
"/>
                    <?php 
                /*if($is_required) {?>
                		<span class="geodir_message_error"><?php echo _e($required_msg,'geodirectory');?></span>
                		<?php }*/
                ?>
                </div>
            <?php 
            }
            ?>

            <?php 
            if (isset($extra_fields['show_map']) && $extra_fields['show_map']) {
                ?>

                <div id="geodir_<?php 
                echo $prefix . 'map';
                ?>
_row" class="geodir_form_row clearfix">
                    <?php 
                /**
                 * Contains add listing page map functions.
                 *
                 * @since 1.0.0
                 */
                include geodir_plugin_path() . "/geodirectory-functions/map-functions/map_on_add_listing_page.php";
                if ($lat_lng_blank) {
                    $lat = '';
                    $lng = '';
                }
                ?>
                    <span class="geodir_message_note"><?php 
                echo GET_MAP_MSG;
                ?>
</span>
                </div>
                <?php 
                /* show lat lng */
                $style_latlng = isset($extra_fields['show_latlng']) && $extra_fields['show_latlng'] || is_admin() ? '' : 'style="display:none"';
                ?>
                <div id="geodir_<?php 
                echo $prefix . 'latitude';
                ?>
_row"
                     class="<?php 
                if ($is_required) {
                    echo 'required_field';
                }
                ?>
 geodir_form_row clearfix" <?php 
                echo $style_latlng;
                ?>
>
                    <label>
                        <?php 
                echo PLACE_ADDRESS_LAT;
                ?>
                        <?php 
                if ($is_required) {
                    echo '<span>*</span>';
                }
                ?>
                    </label>
                    <input type="text" field_type="<?php 
                echo $type;
                ?>
" name="<?php 
                echo $prefix . 'latitude';
                ?>
"
                           id="<?php 
                echo $prefix . 'latitude';
                ?>
" class="geodir_textfield"
                           value="<?php 
                echo esc_attr(stripslashes($lat));
                ?>
" size="25"/>
                    <span class="geodir_message_note"><?php 
                echo GET_LATITUDE_MSG;
                ?>
</span>
                    <?php 
                if ($is_required) {
                    ?>
                        <span class="geodir_message_error"><?php 
                    _e($required_msg, 'geodirectory');
                    ?>
</span>
                    <?php 
                }
                ?>
                </div>

                <div id="geodir_<?php 
                echo $prefix . 'longitude';
                ?>
_row"
                     class="<?php 
                if ($is_required) {
                    echo 'required_field';
                }
                ?>
 geodir_form_row clearfix" <?php 
                echo $style_latlng;
                ?>
>
                    <label>
                        <?php 
                echo PLACE_ADDRESS_LNG;
                ?>
                        <?php 
                if ($is_required) {
                    echo '<span>*</span>';
                }
                ?>
                    </label>
                    <input type="text" field_type="<?php 
                echo $type;
                ?>
" name="<?php 
                echo $prefix . 'longitude';
                ?>
"
                           id="<?php 
                echo $prefix . 'longitude';
                ?>
" class="geodir_textfield"
                           value="<?php 
                echo esc_attr(stripslashes($lng));
                ?>
" size="25"/>
                    <span class="geodir_message_note"><?php 
                echo GET_LOGNGITUDE_MSG;
                ?>
</span>
                    <?php 
                if ($is_required) {
                    ?>
                        <span class="geodir_message_error"><?php 
                    _e($required_msg, 'geodirectory');
                    ?>
</span>
                    <?php 
                }
                ?>
                </div>
            <?php 
            }
            ?>

            <?php 
            if (isset($extra_fields['show_mapview']) && $extra_fields['show_mapview']) {
                ?>
                <div id="geodir_<?php 
                echo $prefix . 'mapview';
                ?>
_row" class="geodir_form_row clearfix ">
                    <label><?php 
                _e($mapview_title, 'geodirectory');
                ?>
</label>


                    <span class="geodir_user_define"><input field_type="<?php 
                echo $type;
                ?>
" type="radio"
                                                            class="gd-checkbox"
                                                            name="<?php 
                echo $prefix . 'mapview';
                ?>
"
                                                            id="<?php 
                echo $prefix . 'mapview';
                ?>
" <?php 
                if ($mapview == 'ROADMAP' || $mapview == '') {
                    echo 'checked="checked"';
                }
                ?>
  value="ROADMAP" size="25"/> <?php 
                _e('Default Map', 'geodirectory');
                ?>
</span>
                    <span class="geodir_user_define"> <input field_type="<?php 
                echo $type;
                ?>
" type="radio"
                                                             class="gd-checkbox"
                                                             name="<?php 
                echo $prefix . 'mapview';
                ?>
"
                                                             id="map_view1" <?php 
                if ($mapview == 'SATELLITE') {
                    echo 'checked="checked"';
                }
                ?>
 value="SATELLITE" size="25"/> <?php 
                _e('Satellite Map', 'geodirectory');
                ?>
</span>

                    <span class="geodir_user_define"><input field_type="<?php 
                echo $type;
                ?>
" type="radio"
                                                            class="gd-checkbox"
                                                            name="<?php 
                echo $prefix . 'mapview';
                ?>
"
                                                            id="map_view2" <?php 
                if ($mapview == 'HYBRID') {
                    echo 'checked="checked"';
                }
                ?>
  value="HYBRID" size="25"/> <?php 
                _e('Hybrid Map', 'geodirectory');
                ?>
</span>
					<span class="geodir_user_define"><input field_type="<?php 
                echo $type;
                ?>
" type="radio"
                                                            class="gd-checkbox"
                                                            name="<?php 
                echo $prefix . 'mapview';
                ?>
"
                                                            id="map_view3" <?php 
                if ($mapview == 'TERRAIN') {
                    echo 'checked="checked"';
                }
                ?>
  value="TERRAIN" size="25"/> <?php 
                _e('Terrain Map', 'geodirectory');
                ?>
</span>


                </div>
            <?php 
            }
            ?>

            <?php 
            if (isset($extra_fields['show_mapzoom']) && $extra_fields['show_mapzoom']) {
                ?>
                <input type="hidden" value="<?php 
                if (isset($mapzoom)) {
                    echo esc_attr($mapzoom);
                }
                ?>
" name="<?php 
                echo $prefix . 'mapzoom';
                ?>
" id="<?php 
                echo $prefix . 'mapzoom';
                ?>
"/>
            <?php 
            }
            ?>
        <?php 
        } elseif ($type == 'text') {
            ?>

            <div id="<?php 
            echo $name;
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
            $site_title = __($site_title, 'geodirectory');
            echo trim($site_title) ? $site_title : '&nbsp;';
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label>
                <input field_type="<?php 
            echo $type;
            ?>
" name="<?php 
            echo $name;
            ?>
" id="<?php 
            echo $name;
            ?>
"
                       value="<?php 
            echo esc_attr(stripslashes($value));
            ?>
" type="text" class="geodir_textfield"/>
                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>

        <?php 
        } elseif ($type == 'email') {
            if ($value == $val['default']) {
                $value = '';
            }
            ?>

            <div id="<?php 
            echo $name;
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
            $site_title = __($site_title, 'geodirectory');
            echo trim($site_title) ? $site_title : '&nbsp;';
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label>
                <input field_type="<?php 
            echo $type;
            ?>
" name="<?php 
            echo $name;
            ?>
" id="<?php 
            echo $name;
            ?>
"
                       value="<?php 
            echo esc_attr(stripslashes($value));
            ?>
" type="text" class="geodir_textfield"/>
                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>

        <?php 
        } elseif ($type == 'phone') {
            if ($value == $val['default']) {
                $value = '';
            }
            ?>

            <div id="<?php 
            echo $name;
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
            $site_title = __($site_title, 'geodirectory');
            echo trim($site_title) ? $site_title : '&nbsp;';
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label>
                <input field_type="<?php 
            echo $type;
            ?>
" name="<?php 
            echo $name;
            ?>
" id="<?php 
            echo $name;
            ?>
"
                       value="<?php 
            echo esc_attr(stripslashes($value));
            ?>
" type="text" class="geodir_textfield"/>
                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>

        <?php 
        } elseif ($type == 'url') {
            if ($value == $val['default']) {
                $value = '';
            }
            ?>

            <div id="<?php 
            echo $name;
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
            $site_title = __($site_title, 'geodirectory');
            echo trim($site_title) ? $site_title : '&nbsp;';
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label>
                <input field_type="<?php 
            echo $type;
            ?>
" name="<?php 
            echo $name;
            ?>
" id="<?php 
            echo $name;
            ?>
"
                       value="<?php 
            echo esc_attr(stripslashes($value));
            ?>
" type="text" class="geodir_textfield"/>
                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>

        <?php 
        } elseif ($type == 'radio') {
            ?>
            <div id="<?php 
            echo $name;
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
            $site_title = __($site_title, 'geodirectory');
            echo trim($site_title) ? $site_title : '&nbsp;';
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label>

                <?php 
            if ($option_values) {
                $option_values_arr = explode(',', $option_values);
                for ($i = 0; $i < count($option_values_arr); $i++) {
                    if (strstr($option_values_arr[$i], "/")) {
                        $radio_attr = explode("/", $option_values_arr[$i]);
                        $radio_lable = ucfirst($radio_attr[0]);
                        $radio_value = $radio_attr[1];
                    } else {
                        $radio_lable = ucfirst($option_values_arr[$i]);
                        $radio_value = $option_values_arr[$i];
                    }
                    ?>

                        <input name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" <?php 
                    if ($radio_value == $value) {
                        echo 'checked="checked"';
                    }
                    ?>
  value="<?php 
                    echo $radio_value;
                    ?>
" class="gd-checkbox" field_type="<?php 
                    echo $type;
                    ?>
"
                               type="radio"  /><?php 
                    _e($radio_lable);
                    ?>

                    <?php 
                }
            }
            ?>
                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>

        <?php 
        } elseif ($type == 'checkbox') {
            ?>

            <div id="<?php 
            echo $name;
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
            $site_title = __($site_title, 'geodirectory');
            echo trim($site_title) ? $site_title : '&nbsp;';
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label>
                <?php 
            if ($value != '1') {
                $value = '0';
            }
            ?>
                <input type="hidden" name="<?php 
            echo $name;
            ?>
" id="<?php 
            echo $name;
            ?>
" value="<?php 
            echo esc_attr($value);
            ?>
"/>
                <input  <?php 
            if ($value == '1') {
                echo 'checked="checked"';
            }
            ?>
  value="1" class="gd-checkbox" field_type="<?php 
            echo $type;
            ?>
" type="checkbox"
                     onchange="if(this.checked){jQuery('#<?php 
            echo $name;
            ?>
').val('1');} else{ jQuery('#<?php 
            echo $name;
            ?>
').val('0');}"/>
                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>

        <?php 
        } elseif ($type == 'textarea') {
            ?>

            <div id="<?php 
            echo $name;
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
            $site_title = __($site_title, 'geodirectory');
            echo trim($site_title) ? $site_title : '&nbsp;';
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label><?php 
            if (is_array($extra_fields) && in_array('1', $extra_fields)) {
                $editor_settings = array('media_buttons' => false, 'textarea_rows' => 10);
                ?>

                <div class="editor" field_id="<?php 
                echo $name;
                ?>
" field_type="editor">
                    <?php 
                wp_editor(stripslashes($value), $name, $editor_settings);
                ?>
                    </div><?php 
            } else {
                ?>
<textarea field_type="<?php 
                echo $type;
                ?>
" class="geodir_textarea" name="<?php 
                echo $name;
                ?>
"
                                id="<?php 
                echo $name;
                ?>
"><?php 
                echo stripslashes($value);
                ?>
</textarea><?php 
            }
            ?>


                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>

        <?php 
        } elseif ($type == 'select') {
            ?>
            <div id="<?php 
            echo $name;
            ?>
_row"
                 class="<?php 
            if ($is_required) {
                echo 'required_field';
            }
            ?>
 geodir_form_row geodir_custom_fields clearfix">
                <label>
                    <?php 
            $site_title = __($site_title, 'geodirectory');
            echo trim($site_title) ? $site_title : '&nbsp;';
            ?>
                    <?php 
            if ($is_required) {
                echo '<span>*</span>';
            }
            ?>
                </label>
                <?php 
            $option_values_arr = geodir_string_values_to_options($option_values);
            $select_options = '';
            if (!empty($option_values_arr)) {
                foreach ($option_values_arr as $option_row) {
                    if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) {
                        $option_label = isset($option_row['label']) ? $option_row['label'] : '';
                        $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
                    } else {
                        $option_label = isset($option_row['label']) ? $option_row['label'] : '';
                        $option_value = isset($option_row['value']) ? $option_row['value'] : '';
                        $selected = $option_value == $value ? 'selected="selected"' : '';
                        $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
                    }
                }
            }
            ?>
                <select field_type="<?php 
            echo $type;
            ?>
" name="<?php 
            echo $name;
            ?>
" id="<?php 
            echo $name;
            ?>
"
                        class="geodir_textfield textfield_x chosen_select"
                        data-placeholder="<?php 
            echo __('Choose', 'geodirectory') . ' ' . $site_title . '&hellip;';
            ?>
"
                        option-ajaxchosen="false"><?php 
            echo $select_options;
            ?>
</select>
                <span class="geodir_message_note"><?php 
            _e($admin_desc, 'geodirectory');
            ?>
</span>
                <?php 
            if ($is_required) {
                ?>
                    <span class="geodir_message_error"><?php 
                _e($required_msg, 'geodirectory');
                ?>
</span>
                <?php 
            }
            ?>
            </div>

        <?php 
        } else {
            if ($type == 'multiselect') {
                $multi_display = 'select';
                if (!empty($val['extra_fields'])) {
                    $multi_display = unserialize($val['extra_fields']);
                }
                ?>
            <div id="<?php 
                echo $name;
                ?>
_row"
                 class="<?php 
                if ($is_required) {
                    echo 'required_field';
                }
                ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
                $site_title = __($site_title, 'geodirectory');
                echo trim($site_title) ? $site_title : '&nbsp;';
                ?>
                    <?php 
                if ($is_required) {
                    echo '<span>*</span>';
                }
                ?>
                </label>
                <input type="hidden" name="gd_field_<?php 
                echo $name;
                ?>
" value="1"/>
                <?php 
                if ($multi_display == 'select') {
                    ?>
                <div class="geodir_multiselect_list">
                    <select field_type="<?php 
                    echo $type;
                    ?>
" name="<?php 
                    echo $name;
                    ?>
[]" id="<?php 
                    echo $name;
                    ?>
"
                            multiple="multiple" class="geodir_textfield textfield_x chosen_select"
                            data-placeholder="<?php 
                    _e('Select', 'geodirectory');
                    ?>
"
                            option-ajaxchosen="false">
                        <?php 
                } else {
                    echo '<ul class="gd_multi_choice">';
                }
                $option_values_arr = geodir_string_values_to_options($option_values);
                $select_options = '';
                if (!empty($option_values_arr)) {
                    foreach ($option_values_arr as $option_row) {
                        if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) {
                            $option_label = isset($option_row['label']) ? $option_row['label'] : '';
                            if ($multi_display == 'select') {
                                $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
                            } else {
                                $select_options .= $option_row['optgroup'] == 'start' ? '<li>' . $option_label . '</li>' : '';
                            }
                        } else {
                            $option_label = isset($option_row['label']) ? $option_row['label'] : '';
                            $option_value = isset($option_row['value']) ? $option_row['value'] : '';
                            $selected = $option_value == $value ? 'selected="selected"' : '';
                            $selected = '';
                            $checked = '';
                            if (!is_array($value) && trim($value) != '' || is_array($value) && !empty($value)) {
                                if (!is_array($value)) {
                                    $value_array = explode(',', $value);
                                } else {
                                    $value_array = $value;
                                }
                                if (is_array($value_array)) {
                                    if (in_array($option_value, $value_array)) {
                                        $selected = 'selected="selected"';
                                        $checked = 'checked="checked"';
                                    }
                                }
                            }
                            if ($multi_display == 'select') {
                                $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
                            } else {
                                $select_options .= '<li><input name="' . $name . '[]" ' . $checked . ' value="' . esc_attr($option_value) . '" class="gd-' . $multi_display . '" field_type="' . $multi_display . '" type="' . $multi_display . '" />&nbsp;' . $option_label . ' </li>';
                            }
                        }
                    }
                }
                echo $select_options;
                if ($multi_display == 'select') {
                    ?>
</select></div>
            <?php 
                } else {
                    ?>
</ul><?php 
                }
                ?>
                <span class="geodir_message_note"><?php 
                _e($admin_desc, 'geodirectory');
                ?>
</span>
                <?php 
                if ($is_required) {
                    ?>
                    <span class="geodir_message_error"><?php 
                    _e($required_msg, 'geodirectory');
                    ?>
</span>
                <?php 
                }
                ?>
            </div>
        <?php 
            } else {
                if ($type == 'html') {
                    ?>

            <div id="<?php 
                    echo $name;
                    ?>
_row"
                 class="<?php 
                    if ($is_required) {
                        echo 'required_field';
                    }
                    ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
                    $site_title = __($site_title, 'geodirectory');
                    echo trim($site_title) ? $site_title : '&nbsp;';
                    ?>
                    <?php 
                    if ($is_required) {
                        echo '<span>*</span>';
                    }
                    ?>
                </label>

                <?php 
                    $editor_settings = array('media_buttons' => false, 'textarea_rows' => 10);
                    ?>

                <div class="editor" field_id="<?php 
                    echo $name;
                    ?>
" field_type="editor">
                    <?php 
                    wp_editor(stripslashes($value), $name, $editor_settings);
                    ?>
                </div>

                <span class="geodir_message_note"><?php 
                    _e($admin_desc, 'geodirectory');
                    ?>
</span>
                <?php 
                    if ($is_required) {
                        ?>
                    <span class="geodir_message_error"><?php 
                        _e($required_msg, 'geodirectory');
                        ?>
</span>
                <?php 
                    }
                    ?>

            </div>
        <?php 
                } elseif ($type == 'datepicker') {
                    if ($extra_fields['date_format'] == '') {
                        $extra_fields['date_format'] = 'yy-mm-dd';
                    }
                    $search = array('dd', 'mm', 'yy');
                    $replace = array('d', 'm', 'Y');
                    $date_format = str_replace($search, $replace, $extra_fields['date_format']);
                    if ($value && !isset($_REQUEST['backandedit'])) {
                        $time = strtotime($value);
                        $value = date($date_format, $time);
                    }
                    ?>
            <script type="text/javascript">

                jQuery(function () {

                    jQuery("#<?php 
                    echo $name;
                    ?>
").datepicker({changeMonth: true, changeYear: true,});

                    jQuery("#<?php 
                    echo $name;
                    ?>
").datepicker("option", "dateFormat", '<?php 
                    echo $extra_fields['date_format'];
                    ?>
');

                    <?php 
                    if (!empty($value)) {
                        ?>
                    jQuery("#<?php 
                        echo $name;
                        ?>
").datepicker("setDate", "<?php 
                        echo $value;
                        ?>
");
                    <?php 
                    }
                    ?>

                });

            </script>
            <div id="<?php 
                    echo $name;
                    ?>
_row"
                 class="<?php 
                    if ($is_required) {
                        echo 'required_field';
                    }
                    ?>
 geodir_form_row clearfix">
                <label>

                    <?php 
                    $site_title = __($site_title, 'geodirectory');
                    echo trim($site_title) ? $site_title : '&nbsp;';
                    ?>
                    <?php 
                    if ($is_required) {
                        echo '<span>*</span>';
                    }
                    ?>
                </label>

                <input field_type="<?php 
                    echo $type;
                    ?>
" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
"
                       value="<?php 
                    echo esc_attr($value);
                    ?>
" type="text" class="geodir_textfield"/>

                <span class="geodir_message_note"><?php 
                    _e($admin_desc, 'geodirectory');
                    ?>
</span>
                <?php 
                    if ($is_required) {
                        ?>
                    <span class="geodir_message_error"><?php 
                        _e($required_msg, 'geodirectory');
                        ?>
</span>
                <?php 
                    }
                    ?>
            </div>

        <?php 
                } elseif ($type == 'time') {
                    if ($value != '') {
                        $value = date('H:i', strtotime($value));
                    }
                    ?>
            <script type="text/javascript">
                jQuery(document).ready(function () {

                    jQuery('#<?php 
                    echo $name;
                    ?>
').timepicker({
                        showPeriod: true,
                        showLeadingZero: true,
                        showPeriod: true,
                    });
                });
            </script>
            <div id="<?php 
                    echo $name;
                    ?>
_row"
                 class="<?php 
                    if ($is_required) {
                        echo 'required_field';
                    }
                    ?>
 geodir_form_row clearfix">
                <label>

                    <?php 
                    $site_title = __($site_title, 'geodirectory');
                    echo trim($site_title) ? $site_title : '&nbsp;';
                    ?>
                    <?php 
                    if ($is_required) {
                        echo '<span>*</span>';
                    }
                    ?>
                </label>
                <input readonly="readonly" field_type="<?php 
                    echo $type;
                    ?>
" name="<?php 
                    echo $name;
                    ?>
"
                       id="<?php 
                    echo $name;
                    ?>
" value="<?php 
                    echo esc_attr($value);
                    ?>
" type="text" class="geodir_textfield"/>

                <span class="geodir_message_note"><?php 
                    _e($admin_desc, 'geodirectory');
                    ?>
</span>
                <?php 
                    if ($is_required) {
                        ?>
                    <span class="geodir_message_error"><?php 
                        _e($required_msg, 'geodirectory');
                        ?>
</span>
                <?php 
                    }
                    ?>
            </div>

        <?php 
                } elseif ($type == 'taxonomy') {
                    if ($value == $val['default']) {
                        $value = '';
                    }
                    ?>
            <div id="<?php 
                    echo $name;
                    ?>
_row"
                 class="<?php 
                    if ($is_required) {
                        echo 'required_field';
                    }
                    ?>
 geodir_form_row clearfix">
                <label>
                    <?php 
                    $site_title = __($site_title, 'geodirectory');
                    echo trim($site_title) ? $site_title : '&nbsp;';
                    ?>
                    <?php 
                    if ($is_required) {
                        echo '<span>*</span>';
                    }
                    ?>
                </label>

                <div id="<?php 
                    echo $name;
                    ?>
" class="geodir_taxonomy_field" style="float:left; width:70%;">
                    <?php 
                    global $wpdb, $post, $cat_display, $post_cat, $package_id, $exclude_cats;
                    $exclude_cats = array();
                    if ($is_admin == '1') {
                        $post_type = get_post_type();
                        $package_info = array();
                        $package_info = (array) geodir_post_package_info($package_info, $post, $post_type);
                        if (!empty($package_info)) {
                            if (isset($package_info['cat']) && $package_info['cat'] != '') {
                                $exclude_cats = explode(',', $package_info['cat']);
                            }
                        }
                    }
                    $cat_display = unserialize($val['extra_fields']);
                    if (isset($_REQUEST['backandedit']) && (is_array($post_cat[$name]) && !empty($post_cat[$name]))) {
                        $post_cat = implode(",", $post_cat[$name]);
                    } else {
                        if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
                            $post_cat = geodir_get_post_meta($_REQUEST['pid'], $name, true);
                        }
                    }
                    global $geodir_addon_list;
                    if (!empty($geodir_addon_list) && array_key_exists('geodir_payment_manager', $geodir_addon_list) && $geodir_addon_list['geodir_payment_manager'] == 'yes') {
                        $catadd_limit = $wpdb->get_var($wpdb->prepare("SELECT cat_limit FROM " . GEODIR_PRICE_TABLE . " WHERE pid = %d", array($package_id)));
                    } else {
                        $catadd_limit = 0;
                    }
                    if ($cat_display != '' && $cat_display != 'ajax_chained') {
                        $required_limit_msg = '';
                        if ($catadd_limit > 0 && $cat_display != 'select' && $cat_display != 'radio') {
                            $required_limit_msg = __('Only select', 'geodirectory') . ' ' . $catadd_limit . __(' categories for this package.', 'geodirectory');
                        } else {
                            $required_limit_msg = $required_msg;
                        }
                        echo '<input type="hidden" cat_limit="' . $catadd_limit . '" id="cat_limit" value="' . esc_attr($required_limit_msg) . '" name="cat_limit[' . $name . ']"  />';
                        if ($cat_display == 'select' || $cat_display == 'multiselect') {
                            $cat_display == '';
                            $multiple = '';
                            if ($cat_display == 'multiselect') {
                                $multiple = 'multiple="multiple"';
                            }
                            echo '<select id="' . $name . '" ' . $multiple . ' type="' . $name . '" name="post_category[' . $name . '][]" alt="' . $name . '" field_type="' . $cat_display . '" class="geodir_textfield textfield_x chosen_select" data-placeholder="' . __('Select Category', 'geodirectory') . '">';
                            if ($cat_display == 'select') {
                                echo '<option value="">' . __('Select Category', 'geodirectory') . '</option>';
                            }
                        }
                        echo geodir_custom_taxonomy_walker($name, $catadd_limit = 0);
                        if ($cat_display == 'select' || $cat_display == 'multiselect') {
                            echo '</select>';
                        }
                    } else {
                        echo geodir_custom_taxonomy_walker2($name, $catadd_limit);
                    }
                    ?>
                </div>

                <span class="geodir_message_note"><?php 
                    _e($admin_desc, 'geodirectory');
                    ?>
</span>
                <?php 
                    if ($is_required) {
                        ?>
                    <span class="geodir_message_error"><?php 
                        _e($required_msg, 'geodirectory');
                        ?>
</span>
                <?php 
                    }
                    ?>
            </div>

        <?php 
                } elseif ($type == 'file') {
                    ?>

            <?php 
                    // adjust values here
                    $file_id = $name;
                    // this will be the name of form field. Image url(s) will be submitted in $_POST using this key. So if $id == �img1� then $_POST[�img1�] will have all the image urls
                    if ($value != '') {
                        $file_value = trim($value, ",");
                        // this will be initial value of the above form field. Image urls.
                    } else {
                        $file_value = '';
                    }
                    if (isset($extra_fields['file_multiple']) && $extra_fields['file_multiple']) {
                        $file_multiple = true;
                    } else {
                        $file_multiple = false;
                    }
                    if (isset($extra_fields['image_limit']) && $extra_fields['image_limit']) {
                        $file_image_limit = $extra_fields['image_limit'];
                    } else {
                        $file_image_limit = 1;
                    }
                    $file_width = geodir_media_image_large_width();
                    // If you want to automatically resize all uploaded images then provide width here (in pixels)
                    $file_height = geodir_media_image_large_height();
                    // If you want to automatically resize all uploaded images then provide height here (in pixels)
                    if (!empty($file_value)) {
                        $curImages = explode(',', $file_value);
                        if (!empty($curImages)) {
                            $file_totImg = count($curImages);
                        }
                    }
                    $allowed_file_types = !empty($extra_fields['gd_file_types']) && is_array($extra_fields['gd_file_types']) && !in_array("*", $extra_fields['gd_file_types']) ? implode(",", $extra_fields['gd_file_types']) : '';
                    $display_file_types = $allowed_file_types != '' ? '.' . implode(", .", $extra_fields['gd_file_types']) : '';
                    ?>
            <?php 
                    /*?> <h5 class="geodir-form_title"> <?php echo $site_title; ?>
                    			 <?php if($file_image_limit!=0 && $file_image_limit==1 ){echo '<br /><small>('.__('You can upload').' '.$file_image_limit.' '.__('image with this package').')</small>';} ?>
                    			 <?php if($file_image_limit!=0 && $file_image_limit>1 ){echo '<br /><small>('.__('You can upload').' '.$file_image_limit.' '.__('images with this package').')</small>';} ?>
                    			 <?php if($file_image_limit==0){echo '<br /><small>('.__('You can upload unlimited images with this package').')</small>';} ?>
                    		</h5>   <?php */
                    ?>

            <div id="<?php 
                    echo $name;
                    ?>
_row"
                 class="<?php 
                    if ($is_required) {
                        echo 'required_field';
                    }
                    ?>
 geodir_form_row clearfix">

                <div id="<?php 
                    echo $file_id;
                    ?>
dropbox" align="center" style="">
                    <label
                        style="text-align:left; padding-top:10px;"><?php 
                    $site_title = __($site_title, 'geodirectory');
                    echo $site_title;
                    if ($is_required) {
                        echo '<span>*</span>';
                    }
                    ?>
</label>
                    <input class="geodir-custom-file-upload" field_type="file" type="hidden"
                           name="<?php 
                    echo $file_id;
                    ?>
" id="<?php 
                    echo $file_id;
                    ?>
"
                           value="<?php 
                    echo esc_attr($file_value);
                    ?>
"/>
                    <input type="hidden" name="<?php 
                    echo $file_id;
                    ?>
image_limit"
                           id="<?php 
                    echo $file_id;
                    ?>
image_limit" value="<?php 
                    echo $file_image_limit;
                    ?>
"/>
					<?php 
                    if ($allowed_file_types != '') {
                        ?>
					<input type="hidden" name="<?php 
                        echo $file_id;
                        ?>
_allowed_types"
                           id="<?php 
                        echo $file_id;
                        ?>
_allowed_types" value="<?php 
                        echo esc_attr($allowed_file_types);
                        ?>
" data-exts="<?php 
                        echo esc_attr($display_file_types);
                        ?>
"/>
					<?php 
                    }
                    ?>
                    <input type="hidden" name="<?php 
                    echo $file_id;
                    ?>
totImg" id="<?php 
                    echo $file_id;
                    ?>
totImg"
                           value="<?php 
                    if (isset($file_totImg)) {
                        echo esc_attr($file_totImg);
                    } else {
                        echo '0';
                    }
                    ?>
"/>

                    <div style="float:left; width:55%;">
                        <div
                            class="plupload-upload-uic hide-if-no-js <?php 
                    if ($file_multiple) {
                        ?>
plupload-upload-uic-multiple<?php 
                    }
                    ?>
"
                            id="<?php 
                    echo $file_id;
                    ?>
plupload-upload-ui" style="float:left; width:30%;">
                            <?php 
                    /*?><h4><?php _e('Drop files to upload');?></h4><br/><?php */
                    ?>
                            <input id="<?php 
                    echo $file_id;
                    ?>
plupload-browse-button" type="button"
                                   value="<?php 
                    $file_image_limit > 1 ? esc_attr_e('Select Files', 'geodirectory') : esc_attr_e('Select File', 'geodirectory');
                    ?>
"
                                   class="geodir_button" style="margin-top:10px;"/>
                            <span class="ajaxnonceplu"
                                  id="ajaxnonceplu<?php 
                    echo wp_create_nonce($file_id . 'pluploadan');
                    ?>
"></span>
                            <?php 
                    if ($file_width && $file_height) {
                        ?>
                                <span class="plupload-resize"></span>
                                <span class="plupload-width" id="plupload-width<?php 
                        echo $file_width;
                        ?>
"></span>
                                <span class="plupload-height" id="plupload-height<?php 
                        echo $file_height;
                        ?>
"></span>
                            <?php 
                    }
                    ?>
                            <div class="filelist"></div>
                        </div>
                        <div
                            class="plupload-thumbs <?php 
                    if ($file_multiple) {
                        ?>
plupload-thumbs-multiple<?php 
                    }
                    ?>
 "
                            id="<?php 
                    echo $file_id;
                    ?>
plupload-thumbs"
                            style=" clear:inherit; margin-top:0; margin-left:15px; padding-top:10px; float:left; width:50%;">
                        </div>
                        <?php 
                    /*?><span id="upload-msg" ><?php _e('Please drag &amp; drop the images to rearrange the order');?></span><?php */
                    ?>

                        <span id="<?php 
                    echo $file_id;
                    ?>
upload-error" style="display:none"></span>

                    </div>
                </div>
                <span class="geodir_message_note"><?php 
                    _e($admin_desc, 'geodirectory');
                    ?>
 <?php 
                    echo $display_file_types != '' ? __('Allowed file types:', 'geodirectory') . ' ' . $display_file_types : '';
                    ?>
</span>
                <?php 
                    if ($is_required) {
                        ?>
                    <span class="geodir_message_error"><?php 
                        _e($required_msg, 'geodirectory');
                        ?>
</span>
                <?php 
                    }
                    ?>
            </div>


        <?php 
                }
            }
        }
        /**
         * Called after the custom fields info is output for submitting a post.
         *
         * Used dynamic hook type geodir_after_custom_form_field_$name.
         *
         * @since 1.0.0
         * @param string $listing_type The post post type.
         * @param int $package_id The price package ID for the post.
         * @param array $val The settings array for the field. {@see geodir_custom_field_save()}.
         * @see 'geodir_before_custom_form_field_$name'
         */
        do_action('geodir_after_custom_form_field_' . $name, $listing_type, $package_id, $val);
    }
}
Exemplo n.º 13
0
/**
 * Handle import/export for categories & listings.
 *
 * @since 1.4.6
 * @package GeoDirectory
 *
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @global object $current_user Current user object.
 * @global null|object $wp_filesystem WP_Filesystem object.
 * @return string Json data.
 */
function geodir_ajax_import_export()
{
    global $wpdb, $plugin_prefix, $current_user, $wp_filesystem;
    // try to set higher limits for import
    @ini_set('max_input_time', 3000);
    @ini_set('max_execution_time', 3000);
    @ini_set('memory_limit', '256M');
    error_reporting(0);
    $json = array();
    if (!current_user_can('manage_options')) {
        wp_send_json($json);
    }
    $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : NULL;
    $nonce = isset($_REQUEST['_nonce']) ? $_REQUEST['_nonce'] : NULL;
    $stat = isset($_REQUEST['_st']) ? $_REQUEST['_st'] : false;
    if (!wp_verify_nonce($nonce, 'geodir_import_export_nonce')) {
        wp_send_json($json);
    }
    $post_type = isset($_REQUEST['_pt']) ? $_REQUEST['_pt'] : NULL;
    /*if( empty( $wp_filesystem ) ) {
    		require_once( ABSPATH . '/wp-admin/includes/file.php' );
    		WP_Filesystem();
    		global $wp_filesystem;
    	}*/
    $wp_filesystem = geodir_init_filesystem();
    if (!$wp_filesystem) {
        $json['error'] = __('Fail, something wrong to create csv file.', GEODIRECTORY_TEXTDOMAIN);
        wp_send_json($json);
        exit;
    }
    $csv_file_dir = geodir_path_import_export(false);
    if (!$wp_filesystem->is_dir($csv_file_dir)) {
        $wp_filesystem->mkdir($csv_file_dir, FS_CHMOD_DIR);
    }
    switch ($task) {
        case 'export_posts':
            // WPML
            $is_wpml = geodir_is_wpml();
            if ($is_wpml) {
                global $sitepress;
                $active_lang = ICL_LANGUAGE_CODE;
                $sitepress->switch_lang('all', true);
            }
            // WPML
            if ($post_type == 'gd_event') {
                //add_filter( 'geodir_imex_count_posts', 'geodir_imex_count_events', 10, 2 );
                add_filter('geodir_imex_export_posts_query', 'geodir_imex_get_events_query', 10, 2);
            }
            $file_name = $post_type . '_' . date('j_n_y');
            $posts_count = geodir_get_posts_count($post_type);
            $file_url = geodir_path_import_export() . '/' . $file_name . '.csv';
            $file_path = $csv_file_dir . '/' . $file_name . '.csv';
            $file_path_temp = $csv_file_dir . '/' . $post_type . '_' . $nonce . '.csv';
            if (isset($_REQUEST['_st'])) {
                $line_count = (int) geodir_import_export_line_count($file_path_temp);
                $percentage = count($posts_count) > 0 && $line_count > 0 ? ceil($line_count / $posts_count) * 100 : 0;
                $percentage = min($percentage, 100);
                $json['percentage'] = $percentage;
                // WPML
                if ($is_wpml) {
                    $sitepress->switch_lang($active_lang, true);
                }
                // WPML
                wp_send_json($json);
            } else {
                if ($wp_filesystem->exists($file_path)) {
                    $wp_filesystem->delete($file_path);
                }
                if (!$posts_count > 0) {
                    $json['error'] = __('No records to export.', GEODIRECTORY_TEXTDOMAIN);
                } else {
                    $args = array('hide_empty' => 0);
                    $posts = geodir_imex_get_posts($post_type);
                    if (!empty($posts)) {
                        $total_posts = count($posts);
                        $per_page = 100;
                        $total_pages = ceil($total_posts / $per_page);
                        for ($i = 0; $i <= $total_pages; $i++) {
                            $save_posts = array_slice($posts, $i * $per_page, $per_page);
                            $clear = $i == 0 ? true : false;
                            geodir_save_csv_data($file_path_temp, $save_posts, $clear);
                        }
                        if ($wp_filesystem->exists($file_path_temp)) {
                            $wp_filesystem->move($file_path_temp, $file_path, true);
                        }
                        if ($wp_filesystem->exists($file_path)) {
                            $json['total'] = $posts_count;
                            $json['csv_file'] = $file_url;
                        } else {
                            $json['error'] = __('Fail, something wrong to create csv file.', GEODIRECTORY_TEXTDOMAIN);
                        }
                    } else {
                        $json['error'] = __('No records to export.', GEODIRECTORY_TEXTDOMAIN);
                    }
                }
                // WPML
                if ($is_wpml) {
                    $sitepress->switch_lang($active_lang, true);
                }
                // WPML
                wp_send_json($json);
            }
            break;
        case 'export_cats':
            // WPML
            $is_wpml = geodir_is_wpml();
            if ($is_wpml) {
                global $sitepress;
                $active_lang = ICL_LANGUAGE_CODE;
                $sitepress->switch_lang('all', true);
            }
            // WPML
            $file_name = $post_type . 'category_' . date('j_n_y');
            $terms_count = geodir_get_terms_count($post_type);
            $file_url = geodir_path_import_export() . '/' . $file_name . '.csv';
            $file_path = $csv_file_dir . '/' . $file_name . '.csv';
            $file_path_temp = $csv_file_dir . '/' . $post_type . 'category_' . $nonce . '.csv';
            if (isset($_REQUEST['_st'])) {
                $line_count = (int) geodir_import_export_line_count($file_path_temp);
                $percentage = count($terms_count) > 0 && $line_count > 0 ? ceil($line_count / $terms_count) * 100 : 0;
                $percentage = min($percentage, 100);
                $json['percentage'] = $percentage;
                // WPML
                if ($is_wpml) {
                    $sitepress->switch_lang($active_lang, true);
                }
                // WPML
                wp_send_json($json);
            } else {
                if ($wp_filesystem->exists($file_path)) {
                    $wp_filesystem->delete($file_path);
                }
                if (!$terms_count > 0) {
                    $json['error'] = __('No records to export.', GEODIRECTORY_TEXTDOMAIN);
                } else {
                    $args = array('hide_empty' => 0);
                    $terms = geodir_imex_get_terms($post_type);
                    if (!empty($terms)) {
                        $total_terms = count($terms);
                        $per_page = 50;
                        $total_pages = ceil($total_terms / $per_page);
                        for ($i = 0; $i <= $total_pages; $i++) {
                            $save_terms = array_slice($terms, $i * $per_page, $per_page);
                            $clear = $i == 0 ? true : false;
                            geodir_save_csv_data($file_path_temp, $save_terms, $clear);
                        }
                        if ($wp_filesystem->exists($file_path_temp)) {
                            $wp_filesystem->move($file_path_temp, $file_path, true);
                        }
                        if ($wp_filesystem->exists($file_path)) {
                            $json['total'] = $terms_count;
                            $json['csv_file'] = $file_url;
                        } else {
                            $json['error'] = __('Fail, something wrong to create csv file.', GEODIRECTORY_TEXTDOMAIN);
                        }
                    } else {
                        $json['error'] = __('No records to export.', GEODIRECTORY_TEXTDOMAIN);
                    }
                }
                // WPML
                if ($is_wpml) {
                    $sitepress->switch_lang($active_lang, true);
                }
                // WPML
                wp_send_json($json);
            }
            break;
        case 'prepare_import':
        case 'import_cat':
        case 'import_post':
            // WPML
            $is_wpml = geodir_is_wpml();
            if ($is_wpml) {
                global $sitepress;
                $active_lang = ICL_LANGUAGE_CODE;
            }
            // WPML
            ini_set('auto_detect_line_endings', true);
            $uploads = wp_upload_dir();
            $uploads_dir = $uploads['path'];
            $uploads_subdir = $uploads['subdir'];
            $csv_file = isset($_POST['_file']) ? $_POST['_file'] : NULL;
            $import_choice = isset($_REQUEST['_ch']) ? $_REQUEST['_ch'] : 'skip';
            $csv_file_arr = explode('/', $csv_file);
            $csv_filename = end($csv_file_arr);
            $target_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $csv_filename;
            $json['file'] = $csv_file;
            $json['error'] = __('The uploaded file is not a valid csv file. Please try again.', GEODIRECTORY_TEXTDOMAIN);
            if ($csv_file && $wp_filesystem->is_file($target_path) && $wp_filesystem->exists($target_path)) {
                $wp_filetype = wp_check_filetype_and_ext($target_path, $csv_filename);
                if (!empty($wp_filetype) && isset($wp_filetype['ext']) && strtolower($wp_filetype['ext']) == 'csv') {
                    $json['error'] = NULL;
                    $json['rows'] = 0;
                    if (($handle = fopen($target_path, "r")) !== FALSE) {
                        while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) {
                            if (!empty($data)) {
                                $file[] = $data;
                            }
                        }
                        fclose($handle);
                    }
                    $json['rows'] = !empty($file) && count($file) > 1 ? count($file) - 1 : 0;
                    if (!$json['rows'] > 0) {
                        $json['error'] = __('No data found in csv file.', GEODIRECTORY_TEXTDOMAIN);
                    }
                } else {
                    wp_send_json($json);
                }
            } else {
                wp_send_json($json);
            }
            if ($task == 'prepare_import' || !empty($json['error'])) {
                wp_send_json($json);
            }
            $total = $json['rows'];
            $limit = isset($_POST['limit']) ? (int) $_POST['limit'] : 1;
            $processed = isset($_POST['processed']) ? (int) $_POST['processed'] : 0;
            $count = $limit;
            $requested_limit = $limit;
            if ($count < $total) {
                $count = $processed + $count;
                if ($count > $total) {
                    $count = $total;
                }
            } else {
                $count = $total;
            }
            $created = 0;
            $updated = 0;
            $skipped = 0;
            $invalid = 0;
            $invalid_addr = 0;
            $images = 0;
            $invalid_title = 0;
            $customKeyarray = array();
            $gd_post_info = array();
            $post_location = array();
            $countpost = 0;
            $post_types = geodir_get_posttypes();
            if ($task == 'import_cat') {
                if (!empty($file)) {
                    $columns = isset($file[0]) ? $file[0] : NULL;
                    if (empty($columns) || !empty($columns) && $columns[0] == '') {
                        $json['error'] = CSV_INVAILD_FILE;
                        wp_send_json($json);
                    }
                    for ($i = 1; $i <= $limit; $i++) {
                        $index = $processed + $i;
                        if (isset($file[$index])) {
                            $row = $file[$index];
                            $row = array_map('trim', $row);
                            $row = array_map('utf8_encode', $row);
                            $cat_id = '';
                            $cat_name = '';
                            $cat_slug = '';
                            $cat_posttype = '';
                            $cat_parent = '';
                            $cat_description = '';
                            $cat_top_description = '';
                            $cat_image = '';
                            $cat_icon = '';
                            $cat_language = '';
                            $c = 0;
                            foreach ($columns as $column) {
                                if ($column == 'cat_id') {
                                    $cat_id = (int) $row[$c];
                                } else {
                                    if ($column == 'cat_name') {
                                        $cat_name = $row[$c];
                                    } else {
                                        if ($column == 'cat_slug') {
                                            $cat_slug = $row[$c];
                                        } else {
                                            if ($column == 'cat_posttype') {
                                                $cat_posttype = $row[$c];
                                            } else {
                                                if ($column == 'cat_parent') {
                                                    $cat_parent = trim($row[$c]);
                                                } else {
                                                    if ($column == 'cat_description') {
                                                        $cat_description = $row[$c];
                                                    } else {
                                                        if ($column == 'cat_top_description') {
                                                            $cat_top_description = $row[$c];
                                                        } else {
                                                            if ($column == 'cat_image') {
                                                                $cat_image = $row[$c];
                                                            } else {
                                                                if ($column == 'cat_icon') {
                                                                    $cat_icon = $row[$c];
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                // WPML
                                if ($is_wpml && $column == 'cat_language') {
                                    $cat_language = strtolower(trim($row[$c]));
                                }
                                // WPML
                                $c++;
                            }
                            if ($cat_name == '' || !in_array($cat_posttype, $post_types)) {
                                $invalid++;
                                continue;
                            }
                            // WPML
                            if ($is_wpml && $cat_language != '') {
                                $sitepress->switch_lang($cat_language, true);
                            }
                            // WPML
                            $term_data = array();
                            $term_data['name'] = $cat_name;
                            $term_data['slug'] = $cat_slug;
                            $term_data['description'] = $cat_description;
                            $term_data['top_description'] = $cat_top_description;
                            $term_data['image'] = $cat_image != '' ? basename($cat_image) : '';
                            $term_data['icon'] = $cat_icon != '' ? basename($cat_icon) : '';
                            $term_data = array_map('utf8_encode', $term_data);
                            $taxonomy = $cat_posttype . 'category';
                            $term_data['taxonomy'] = $taxonomy;
                            $term_parent_id = 0;
                            if ($cat_parent != "" || (int) $cat_parent > 0) {
                                $term_parent = '';
                                if ($term_parent = get_term_by('name', $cat_parent, $taxonomy)) {
                                    $term_parent = $term_parent;
                                } else {
                                    if ($term_parent = get_term_by('slug', $cat_parent, $taxonomy)) {
                                        $term_parent = $term_parent;
                                    } else {
                                        if ($term_parent = get_term_by('id', $cat_parent, $taxonomy)) {
                                            $term_parent = $term_parent;
                                        } else {
                                            $term_parent_data = array();
                                            $term_parent_data['name'] = $cat_parent;
                                            $term_parent_data = array_map('utf8_encode', $term_parent_data);
                                            $term_parent_data['taxonomy'] = $taxonomy;
                                            $term_parent_id = (int) geodir_imex_insert_term($taxonomy, $term_parent_data);
                                        }
                                    }
                                }
                                if (!empty($term_parent) && !is_wp_error($term_parent)) {
                                    $term_parent_id = (int) $term_parent->term_id;
                                }
                            }
                            $term_data['parent'] = (int) $term_parent_id;
                            $term_id = NULL;
                            if ($import_choice == 'update') {
                                if ($cat_id > 0 && ($term = (array) term_exists($cat_id, $taxonomy))) {
                                    $term_data['term_id'] = $term['term_id'];
                                    if ($term_id = geodir_imex_update_term($taxonomy, $term_data)) {
                                        $updated++;
                                    } else {
                                        $invalid++;
                                    }
                                } else {
                                    if ($term_data['slug'] != '' && ($term = (array) term_exists($term_data['slug'], $taxonomy))) {
                                        $term_data['term_id'] = $term['term_id'];
                                        if ($term_id = geodir_imex_update_term($taxonomy, $term_data)) {
                                            $updated++;
                                        } else {
                                            $invalid++;
                                        }
                                    } else {
                                        if ($term_id = geodir_imex_insert_term($taxonomy, $term_data)) {
                                            $created++;
                                        } else {
                                            $invalid++;
                                        }
                                    }
                                }
                            } else {
                                if ($import_choice == 'skip') {
                                    if ($cat_id > 0 && ($term = (array) term_exists($cat_id, $taxonomy))) {
                                        $skipped++;
                                    } else {
                                        if ($term_data['slug'] != '' && ($term = (array) term_exists($term_data['slug'], $taxonomy))) {
                                            $skipped++;
                                        } else {
                                            if ($term_id = geodir_imex_insert_term($taxonomy, $term_data)) {
                                                $created++;
                                            } else {
                                                $invalid++;
                                            }
                                        }
                                    }
                                } else {
                                    $invalid++;
                                }
                            }
                            if ($term_id) {
                                if (isset($term_data['top_description'])) {
                                    update_tax_meta($term_id, 'ct_cat_top_desc', $term_data['top_description'], $cat_posttype);
                                }
                                $attachment = false;
                                if (isset($term_data['image']) && $term_data['image'] != '') {
                                    $cat_image = geodir_get_default_catimage($term_id, $cat_posttype);
                                    $cat_image = !empty($cat_image) && isset($cat_image['src']) ? $cat_image['src'] : '';
                                    if (basename($cat_image) != $term_data['image']) {
                                        $attachment = true;
                                        update_tax_meta($term_id, 'ct_cat_default_img', array('id' => 'image', 'src' => $uploads['url'] . '/' . $term_data['image']), $cat_posttype);
                                    }
                                }
                                if (isset($term_data['icon']) && $term_data['icon'] != '') {
                                    $cat_icon = get_tax_meta($term_id, 'ct_cat_icon', false, $cat_posttype);
                                    $cat_icon = !empty($cat_icon) && isset($cat_icon['src']) ? $cat_icon['src'] : '';
                                    if (basename($cat_icon) != $term_data['icon']) {
                                        $attachment = true;
                                        update_tax_meta($term_id, 'ct_cat_icon', array('id' => 'icon', 'src' => $uploads['url'] . '/' . $term_data['icon']), $cat_posttype);
                                    }
                                }
                                if ($attachment) {
                                    $images++;
                                }
                            }
                            // WPML
                            if ($is_wpml && $cat_language != '') {
                                $sitepress->switch_lang($active_lang, true);
                            }
                            // WPML
                        }
                    }
                }
                $json = array();
                $json['processed'] = $limit;
                $json['created'] = $created;
                $json['updated'] = $updated;
                $json['skipped'] = $skipped;
                $json['invalid'] = $invalid;
                $json['images'] = $images;
                wp_send_json($json);
            } else {
                if ($task == 'import_post') {
                    if (!empty($file)) {
                        $wp_post_statuses = get_post_statuses();
                        // All of the WordPress supported post statuses.
                        $default_status = 'publish';
                        $current_date = date_i18n('Y-m-d', time());
                        $columns = isset($file[0]) ? $file[0] : NULL;
                        if (empty($columns) || !empty($columns) && $columns[0] == '') {
                            $json['error'] = CSV_INVAILD_FILE;
                            wp_send_json($json);
                        }
                        for ($i = 1; $i <= $limit; $i++) {
                            $index = $processed + $i;
                            $gd_post = array();
                            if (isset($file[$index])) {
                                $row = $file[$index];
                                $row = array_map('trim', $row);
                                $row = array_map('utf8_encode', $row);
                                $row = array_map('addslashes_gpc', $row);
                                $post_id = '';
                                $post_title = '';
                                $post_author = '';
                                $post_content = '';
                                $post_category_arr = array();
                                $post_tags = array();
                                $post_type = '';
                                $post_status = '';
                                $geodir_video = '';
                                $post_address = '';
                                $post_city = '';
                                $post_region = '';
                                $post_country = '';
                                $post_zip = '';
                                $post_latitude = '';
                                $post_longitude = '';
                                $geodir_timing = '';
                                $geodir_contact = '';
                                $geodir_email = '';
                                $geodir_website = '';
                                $geodir_twitter = '';
                                $geodir_facebook = '';
                                $geodir_twitter = '';
                                $post_images = array();
                                $expire_date = 'Never';
                                $language = '';
                                $original_post_id = '';
                                $c = 0;
                                foreach ($columns as $column) {
                                    $gd_post[$column] = $row[$c];
                                    if ($column == 'post_id') {
                                        $post_id = $row[$c];
                                    } else {
                                        if ($column == 'post_title') {
                                            $post_title = $row[$c];
                                        } else {
                                            if ($column == 'post_author') {
                                                $post_author = $row[$c];
                                            } else {
                                                if ($column == 'post_content') {
                                                    $post_content = $row[$c];
                                                } else {
                                                    if ($column == 'post_category' && $row[$c] != '') {
                                                        $post_category_arr = explode(',', $row[$c]);
                                                    } else {
                                                        if ($column == 'post_tags' && $row[$c] != '') {
                                                            $post_tags = explode(',', $row[$c]);
                                                        } else {
                                                            if ($column == 'post_type') {
                                                                $post_type = $row[$c];
                                                            } else {
                                                                if ($column == 'post_status') {
                                                                    $post_status = sanitize_key($row[$c]);
                                                                } else {
                                                                    if ($column == 'is_featured') {
                                                                        $is_featured = (int) $row[$c];
                                                                    } else {
                                                                        if ($column == 'geodir_video') {
                                                                            $geodir_video = $row[$c];
                                                                        } else {
                                                                            if ($column == 'post_address') {
                                                                                $post_address = $row[$c];
                                                                            } else {
                                                                                if ($column == 'post_city') {
                                                                                    $post_city = $row[$c];
                                                                                } else {
                                                                                    if ($column == 'post_region') {
                                                                                        $post_region = $row[$c];
                                                                                    } else {
                                                                                        if ($column == 'post_country') {
                                                                                            $post_country = $row[$c];
                                                                                        } else {
                                                                                            if ($column == 'post_zip') {
                                                                                                $post_zip = $row[$c];
                                                                                            } else {
                                                                                                if ($column == 'post_latitude') {
                                                                                                    $post_latitude = $row[$c];
                                                                                                } else {
                                                                                                    if ($column == 'post_longitude') {
                                                                                                        $post_longitude = $row[$c];
                                                                                                    } else {
                                                                                                        if ($column == 'geodir_timing') {
                                                                                                            $geodir_timing = $row[$c];
                                                                                                        } else {
                                                                                                            if ($column == 'geodir_contact') {
                                                                                                                $geodir_contact = $row[$c];
                                                                                                            } else {
                                                                                                                if ($column == 'geodir_email') {
                                                                                                                    $geodir_email = $row[$c];
                                                                                                                } else {
                                                                                                                    if ($column == 'geodir_website') {
                                                                                                                        $geodir_website = $row[$c];
                                                                                                                    } else {
                                                                                                                        if ($column == 'geodir_twitter') {
                                                                                                                            $geodir_twitter = $row[$c];
                                                                                                                        } else {
                                                                                                                            if ($column == 'geodir_facebook') {
                                                                                                                                $geodir_facebook = $row[$c];
                                                                                                                            } else {
                                                                                                                                if ($column == 'geodir_twitter') {
                                                                                                                                    $geodir_twitter = $row[$c];
                                                                                                                                } else {
                                                                                                                                    if ($column == 'IMAGE' && !empty($row[$c]) && $row[$c] != '') {
                                                                                                                                        $post_images[] = $row[$c];
                                                                                                                                    } else {
                                                                                                                                        if ($column == 'alive_days' && (int) $row[$c] > 0) {
                                                                                                                                            $expire_date = date_i18n('Y-m-d', strtotime($current_date . '+' . (int) $row[$c] . ' days'));
                                                                                                                                        } else {
                                                                                                                                            if ($column == 'expire_date' && $row[$c] != '' && strtolower($row[$c]) != 'never') {
                                                                                                                                                $row[$c] = str_replace('/', '-', $row[$c]);
                                                                                                                                                $expire_date = date_i18n('Y-m-d', strtotime($row[$c]));
                                                                                                                                            }
                                                                                                                                        }
                                                                                                                                    }
                                                                                                                                }
                                                                                                                            }
                                                                                                                        }
                                                                                                                    }
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // WPML
                                    if ($is_wpml) {
                                        if ($column == 'language') {
                                            $language = strtolower(trim($row[$c]));
                                        } else {
                                            if ($column == 'original_post_id') {
                                                $original_post_id = (int) $row[$c];
                                            }
                                        }
                                    }
                                    // WPML
                                    $c++;
                                }
                                // WPML
                                if ($is_wpml && $language != '') {
                                    $sitepress->switch_lang($language, true);
                                }
                                // WPML
                                $gd_post['IMAGE'] = $post_images;
                                $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;
                                $valid = true;
                                if ($post_title == '' || !in_array($post_type, $post_types)) {
                                    $invalid++;
                                    $valid = false;
                                }
                                $location_allowed = function_exists('geodir_cpt_no_location') && geodir_cpt_no_location($post_type) ? false : true;
                                if ($location_allowed) {
                                    $location_result = geodir_get_default_location();
                                    if ($post_address == '' || $post_city == '' || $post_region == '' || $post_country == '' || $post_latitude == '' || $post_longitude == '') {
                                        $invalid_addr++;
                                        $valid = false;
                                    } else {
                                        if (!empty($location_result) && $location_result->location_id == 0) {
                                            if (strtolower($post_city) != strtolower($location_result->city) || strtolower($post_region) != strtolower($location_result->region) || strtolower($post_country) != strtolower($location_result->country)) {
                                                $invalid_addr++;
                                                $valid = false;
                                            } else {
                                                if (!function_exists('geodir_location_plugin_activated')) {
                                                    $gd_post['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']';
                                                    // Set the default location when location manager not activated.
                                                }
                                            }
                                        }
                                    }
                                }
                                if (!$valid) {
                                    continue;
                                }
                                $cat_taxonomy = $post_type . 'category';
                                $tags_taxonomy = $post_type . '_tags';
                                $post_category = array();
                                if (!empty($post_category_arr)) {
                                    foreach ($post_category_arr as $value) {
                                        $category_name = wp_kses_normalize_entities(trim($value));
                                        if ($category_name != '') {
                                            $term_category = array();
                                            if ($term = get_term_by('name', $category_name, $cat_taxonomy)) {
                                                $term_category = $term;
                                            } else {
                                                if ($term = get_term_by('slug', $category_name, $cat_taxonomy)) {
                                                    $term_category = $term;
                                                } else {
                                                    $term_data = array();
                                                    $term_data['name'] = $category_name;
                                                    $term_data = array_map('utf8_encode', $term_data);
                                                    $term_data['taxonomy'] = $cat_taxonomy;
                                                    $term_id = geodir_imex_insert_term($cat_taxonomy, $term_data);
                                                    if ($term_id) {
                                                        $term_category = get_term($term_id, $cat_taxonomy);
                                                    }
                                                }
                                            }
                                            if (!empty($term_category) && !is_wp_error($term_category)) {
                                                //$post_category[] = $term_category->slug;
                                                $post_category[] = intval($term_category->term_id);
                                            }
                                        }
                                    }
                                }
                                $save_post = array();
                                $save_post['post_title'] = $post_title;
                                $save_post['post_content'] = $post_content;
                                $save_post['post_type'] = $post_type;
                                $save_post['post_author'] = $post_author;
                                $save_post['post_status'] = $post_status;
                                $save_post['post_category'] = $post_category;
                                $save_post['post_tags'] = $post_tags;
                                $saved_post_id = NULL;
                                if ($import_choice == 'update') {
                                    if ($post_id > 0 && get_post($post_id)) {
                                        $save_post['ID'] = $post_id;
                                        if (wp_update_post($save_post)) {
                                            $saved_post_id = $post_id;
                                            $updated++;
                                        }
                                    } else {
                                        if ($saved_post_id = wp_insert_post($save_post)) {
                                            $created++;
                                        }
                                    }
                                    if (!$saved_post_id > 0) {
                                        $invalid++;
                                    }
                                } else {
                                    if ($import_choice == 'skip') {
                                        if ($post_id > 0 && get_post($post_id)) {
                                            $skipped++;
                                        } else {
                                            if ($saved_post_id = wp_insert_post($save_post)) {
                                                $created++;
                                            } else {
                                                $invalid++;
                                            }
                                        }
                                    } else {
                                        $invalid++;
                                    }
                                }
                                if ((int) $saved_post_id > 0) {
                                    // WPML
                                    if ($is_wpml && $original_post_id > 0 && $language != '') {
                                        $wpml_post_type = 'post_' . $post_type;
                                        $source_language = geodir_get_language_for_element($original_post_id, $wpml_post_type);
                                        $source_language = $source_language != '' ? $source_language : $sitepress->get_default_language();
                                        $trid = $sitepress->get_element_trid($original_post_id, $wpml_post_type);
                                        $sitepress->set_element_language_details($saved_post_id, $wpml_post_type, $trid, $language, $source_language);
                                    }
                                    // WPML
                                    $gd_post_info = geodir_get_post_info($saved_post_id);
                                    $gd_post['post_id'] = $saved_post_id;
                                    $gd_post['ID'] = $saved_post_id;
                                    $gd_post['post_tags'] = $post_tags;
                                    $gd_post['post_title'] = $post_title;
                                    $gd_post['post_status'] = $post_status;
                                    $gd_post['submit_time'] = time();
                                    $gd_post['submit_ip'] = $_SERVER['REMOTE_ADDR'];
                                    // post location
                                    $post_location_id = 0;
                                    if ($location_allowed && !empty($location_result) && $location_result->location_id > 0) {
                                        $post_location_info = array('city' => $post_city, 'region' => $post_region, 'country' => $post_country, 'geo_lat' => $post_latitude, 'geo_lng' => $post_longitude);
                                        if ($location_id = (int) geodir_add_new_location($post_location_info)) {
                                            $post_location_id = $location_id;
                                        }
                                    }
                                    $gd_post['post_location_id'] = $post_location_id;
                                    // post package info
                                    $package_id = isset($gd_post['package_id']) && !empty($gd_post['package_id']) ? (int) $gd_post['package_id'] : 0;
                                    if (!$package_id && !empty($gd_post_info) && isset($gd_post_info->package_id) && $gd_post_info->package_id) {
                                        $package_id = $gd_post_info->package_id;
                                    }
                                    $package_info = array();
                                    if ($package_id && function_exists('geodir_get_package_info_by_id')) {
                                        $package_info = (array) geodir_get_package_info_by_id($package_id);
                                        if (!(!empty($package_info) && isset($package_info['post_type']) && $package_info['post_type'] == $post_type)) {
                                            $package_info = array();
                                        }
                                    }
                                    if (empty($package_info)) {
                                        $package_info = (array) geodir_post_package_info(array(), '', $post_type);
                                    }
                                    if (!empty($package_info)) {
                                        $package_id = $package_info['pid'];
                                        if (isset($gd_post['alive_days']) || isset($gd_post['expire_date'])) {
                                            $gd_post['expire_date'] = $expire_date;
                                        } else {
                                            if (isset($package_info['days']) && (int) $package_info['days'] > 0) {
                                                $gd_post['alive_days'] = (int) $package_info['days'];
                                                $gd_post['expire_date'] = date_i18n('Y-m-d', strtotime($current_date . '+' . (int) $package_info['days'] . ' days'));
                                            } else {
                                                $gd_post['expire_date'] = 'Never';
                                            }
                                        }
                                        $gd_post['package_id'] = $package_id;
                                    }
                                    $table = $plugin_prefix . $post_type . '_detail';
                                    if ($post_type == 'gd_event') {
                                        $gd_post = geodir_imex_process_event_data($gd_post);
                                    }
                                    if (isset($gd_post['post_id'])) {
                                        unset($gd_post['post_id']);
                                    }
                                    // Export franchise fields
                                    $is_franchise_active = is_plugin_active('geodir_franchise/geodir_franchise.php') && geodir_franchise_enabled($post_type) ? true : false;
                                    if ($is_franchise_active) {
                                        if (isset($gd_post['gd_is_franchise']) && (int) $gd_post['gd_is_franchise'] == 1) {
                                            $gd_franchise_lock = array();
                                            if (isset($gd_post['gd_franchise_lock'])) {
                                                $gd_franchise_lock = str_replace(" ", "", $gd_post['gd_franchise_lock']);
                                                $gd_franchise_lock = trim($gd_franchise_lock);
                                                $gd_franchise_lock = explode(",", $gd_franchise_lock);
                                            }
                                            update_post_meta($saved_post_id, 'gd_is_franchise', 1);
                                            update_post_meta($saved_post_id, 'gd_franchise_lock', $gd_franchise_lock);
                                        } else {
                                            if (isset($gd_post['franchise']) && (int) $gd_post['franchise'] > 0 && geodir_franchise_check((int) $gd_post['franchise'])) {
                                                geodir_save_post_meta($saved_post_id, 'franchise', (int) $gd_post['franchise']);
                                            }
                                        }
                                    }
                                    if (!empty($save_post['post_category']) && is_array($save_post['post_category'])) {
                                        $save_post['post_category'] = array_unique(array_map('intval', $save_post['post_category']));
                                        $gd_post[$cat_taxonomy] = $save_post['post_category'];
                                    }
                                    // Save post info
                                    geodir_save_post_info($saved_post_id, $gd_post);
                                    // post taxonomies
                                    if (!empty($save_post['post_category'])) {
                                        wp_set_object_terms($saved_post_id, $save_post['post_category'], $cat_taxonomy);
                                        $post_default_category = isset($save_post['post_default_category']) ? $save_post['post_default_category'] : '';
                                        $post_category_str = isset($save_post['post_category_str']) ? $save_post['post_category_str'] : '';
                                        geodir_set_postcat_structure($saved_post_id, $cat_taxonomy, $post_default_category, $post_category_str);
                                    }
                                    if (!empty($save_post['post_tags'])) {
                                        wp_set_object_terms($saved_post_id, $save_post['post_tags'], $tags_taxonomy);
                                    }
                                    // Post images
                                    if (!empty($post_images)) {
                                        $post_images = array_unique($post_images);
                                        $old_post_images_arr = array();
                                        $saved_post_images_arr = array();
                                        $order = 1;
                                        $old_post_images = geodir_get_images($saved_post_id);
                                        if (!empty($old_post_images)) {
                                            foreach ($old_post_images as $old_post_image) {
                                                if (!empty($old_post_image) && isset($old_post_image->file) && $old_post_image->file != '') {
                                                    $old_post_images_arr[] = $old_post_image->file;
                                                }
                                            }
                                        }
                                        foreach ($post_images as $post_image) {
                                            $image_name = basename($post_image);
                                            $saved_post_images_arr[] = $image_name;
                                            if (!empty($old_post_images_arr) && in_array($image_name, $old_post_images_arr)) {
                                                continue;
                                                // Skip if image already exists.
                                            }
                                            $image_name_parts = explode('.', $image_name);
                                            array_pop($image_name_parts);
                                            $proper_image_name = implode('.', $image_name_parts);
                                            $arr_file_type = wp_check_filetype($image_name);
                                            if (!empty($arr_file_type)) {
                                                $uploaded_file_type = $arr_file_type['type'];
                                                $attachment = array();
                                                $attachment['post_id'] = $saved_post_id;
                                                $attachment['title'] = $proper_image_name;
                                                $attachment['content'] = '';
                                                $attachment['file'] = $uploads_subdir . '/' . $image_name;
                                                $attachment['mime_type'] = $uploaded_file_type;
                                                $attachment['menu_order'] = $order;
                                                $attachment['is_featured'] = 0;
                                                $attachment_set = '';
                                                foreach ($attachment as $key => $val) {
                                                    if ($val != '') {
                                                        $attachment_set .= $key . " = '" . $val . "', ";
                                                    }
                                                }
                                                $attachment_set = trim($attachment_set, ", ");
                                                // Add new attachment
                                                $wpdb->query("INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set);
                                                $order++;
                                            }
                                        }
                                        $saved_post_images_sql = !empty($saved_post_images_arr) ? " AND ( file NOT LIKE '%/" . implode("' AND file NOT LIKE '%/", $saved_post_images_arr) . "' )" : '';
                                        // Remove previous attachment
                                        $wpdb->query("DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id = " . (int) $saved_post_id . " " . $saved_post_images_sql);
                                        if (!empty($saved_post_images_arr)) {
                                            $menu_order = 1;
                                            foreach ($saved_post_images_arr as $img_name) {
                                                $wpdb->query($wpdb->prepare("UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET menu_order = %d WHERE post_id =%d AND file LIKE %s", array($menu_order, $saved_post_id, '%/' . $img_name)));
                                                if ($menu_order == 1) {
                                                    if ($featured_image = $wpdb->get_var($wpdb->prepare("SELECT file FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id =%d AND file LIKE %s", array($saved_post_id, '%/' . $img_name)))) {
                                                        $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s WHERE post_id =%d", array($featured_image, $saved_post_id)));
                                                    }
                                                }
                                                $menu_order++;
                                            }
                                        }
                                        if ($order > 1) {
                                            $images++;
                                        }
                                    }
                                    /** This action is documented in geodirectory-functions/post-functions.php */
                                    do_action('geodir_after_save_listing', $saved_post_id, $gd_post);
                                    if (isset($is_featured)) {
                                        geodir_save_post_meta($saved_post_id, 'is_featured', $is_featured);
                                    }
                                    if (isset($gd_post['expire_date'])) {
                                        geodir_save_post_meta($saved_post_id, 'expire_date', $gd_post['expire_date']);
                                    }
                                }
                                // WPML
                                if ($is_wpml && $language != '') {
                                    $sitepress->switch_lang($active_lang, true);
                                }
                                // WPML
                            }
                        }
                    }
                    $json = array();
                    $json['processed'] = $limit;
                    $json['created'] = $created;
                    $json['updated'] = $updated;
                    $json['skipped'] = $skipped;
                    $json['invalid'] = $invalid;
                    $json['invalid_addr'] = $invalid_addr;
                    $json['images'] = $images;
                    wp_send_json($json);
                }
            }
            break;
    }
    echo '0';
    wp_die();
}
/**
 * Prints location related javascript.
 *
 * @since 1.0.0
 * @package GeoDirectory
 */
function geodir_add_sharelocation_scripts()
{
    $default_search_for_text = SEARCH_FOR_TEXT;
    if (get_option('geodir_search_field_default_text')) {
        $default_search_for_text = __(get_option('geodir_search_field_default_text'), 'geodirectory');
    }
    $default_near_text = NEAR_TEXT;
    if (get_option('geodir_near_field_default_text')) {
        $default_near_text = __(get_option('geodir_near_field_default_text'), 'geodirectory');
    }
    ?>


    <script type="text/javascript">
        var default_location = '<?php 
    if ($search_location = geodir_get_default_location()) {
        echo $search_location->city;
    }
    ?>
';
        var latlng;
        var Sgeocoder;
        var address;
        var dist = 0;
        var Sgeocoder = new google.maps.Geocoder();

		function geodir_setup_submit_search() {
			jQuery('.geodir_submit_search').click(function() {
				var s = ' ';
				var $form = jQuery(this).closest('form');
				
				if (jQuery("#sdist input[type='radio']:checked").length != 0) dist = jQuery("#sdist input[type='radio']:checked").val();
				if (jQuery('.search_text', $form).val() == '' || jQuery('.search_text', $form).val() == '<?php 
    echo $default_search_for_text;
    ?>
') jQuery('.search_text', $form).val(s);
				
				// Disable location based search for disabled location post type.
				if (jQuery('.search_by_post', $form).val() != '' && typeof gd_cpt_no_location == 'function') {
					if (gd_cpt_no_location(jQuery('.search_by_post', $form).val())) {
						jQuery('.snear', $form).remove();
						jQuery('.sgeo_lat', $form).remove();
						jQuery('.sgeo_lon', $form).remove();
						jQuery('select[name="sort_by"]', $form).remove();
						jQuery($form).submit();
						return;
					}
				}
				
				if (dist > 0 || (jQuery('select[name="sort_by"]').val() == 'nearest' || jQuery('select[name="sort_by"]', $form).val() == 'farthest') || (jQuery(".snear", $form).val() != '' && jQuery(".snear", $form).val() != '<?php 
    echo $default_near_text;
    ?>
')) {
					geodir_setsearch($form);
				} else {
					jQuery(".snear", $form).val('');
					jQuery($form).submit();
				}
			});
		}

        jQuery(document).ready(function() {
			/*
			jQuery('#sort_by').change(function() {
				jQuery('.geodir_submit_search:first').click();
			});
			*/
			
			geodir_setup_submit_search();
		});
        
		function geodir_setsearch($form) {
			if ((dist > 0 || (jQuery('select[name="sort_by"]', $form).val() == 'nearest' || jQuery('select[name="sort_by"]', $form).val() == 'farthest')) && (jQuery(".snear", $form).val() == '' || jQuery(".snear", $form).val() == '<?php 
    echo $default_near_text;
    ?>
')) jQuery(".snear", $form).val(default_location);
			geocodeAddress($form);
		}

        function updateSearchPosition(latLng, $form) {
            jQuery('.sgeo_lat').val(latLng.lat());
            jQuery('.sgeo_lon').val(latLng.lng());
            jQuery($form).submit(); // submit form after insering the lat long positions
        }

        function geocodeAddress($form) {
            Sgeocoder = new google.maps.Geocoder(); // Call the geocode function

            if (jQuery('.snear', $form).val() == '' || ( jQuery('.sgeo_lat').val() != '' && jQuery('.sgeo_lon').val() != ''  ) || jQuery('.snear', $form).val().match("^<?php 
    _e('In:', 'geodirectory');
    ?>
")) {
                if (jQuery('.snear', $form).val().match("^<?php 
    _e('In:', 'geodirectory');
    ?>
")) {
                    jQuery(".snear", $form).val('');
                }
                jQuery($form).submit();
            } else {

                var address = jQuery(".snear", $form).val();

                if (jQuery('.snear', $form).val() == '<?php 
    echo $default_near_text;
    ?>
') {
                    initialise2();
                } else {

                    Sgeocoder.geocode({'address': address<?php 
    if ($near_add = get_option('geodir_search_near_addition')) {
        echo '+", ' . $near_add . '"';
    }
    if ($near_add2 = apply_filters('geodir_search_near_addition', '')) {
        echo $near_add2;
    }
    //gt_advanced_near_search();
    ?>
},
                        function (results, status) {
                            if (status == google.maps.GeocoderStatus.OK) {
                                updateSearchPosition(results[0].geometry.location, $form);
                            } else {
                                alert("<?php 
    _e('Search was not successful for the following reason:', 'geodirectory');
    ?>
" + status);
                            }
                        });
                }
            }
        }

        function initialise2() {
            var latlng = new google.maps.LatLng(56.494343, -4.205446);
            var myOptions = {
                zoom: 4,
                mapTypeId: google.maps.MapTypeId.TERRAIN,
                disableDefaultUI: true
            }
            //alert(latLng);
            prepareGeolocation();
            doGeolocation();
        }

        function doGeolocation() {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(positionSuccess, positionError);
            } else {
                positionError(-1);
            }
        }

        function positionError(err) {
            var msg;
            switch (err.code) {
                case err.UNKNOWN_ERROR:
                    msg = "<?php 
    _e('Unable to find your location', 'geodirectory');
    ?>
";
                    break;
                case err.PERMISSION_DENINED:
                    msg = "<?php 
    _e('Permission denied in finding your location', 'geodirectory');
    ?>
";
                    break;
                case err.POSITION_UNAVAILABLE:
                    msg = "<?php 
    _e('Your location is currently unknown', 'geodirectory');
    ?>
";
                    break;
                case err.BREAK:
                    msg = "<?php 
    _e('Attempt to find location took too long', 'geodirectory');
    ?>
";
                    break;
                default:
                    msg = "<?php 
    _e('Location detection not supported in browser', 'geodirectory');
    ?>
";
            }
            jQuery('#info').html(msg);
        }

        function positionSuccess(position) {
            var coords = position.coords || position.coordinate || position;
            jQuery('.sgeo_lat').val(coords.latitude);
            jQuery('.sgeo_lon').val(coords.longitude);

            jQuery($form).submit();
        }


    </script>
<?php 
}
/**
 * Handles location form submitted data.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 */
function geodir_location_form_submit()
{
    global $wpdb, $plugin_prefix;
    if (isset($_REQUEST['add_location'])) {
        $location_info = array('city' => $_REQUEST['city'], 'region' => $_REQUEST['region'], 'country' => $_REQUEST['country'], 'geo_lat' => $_REQUEST['latitude'], 'geo_lng' => $_REQUEST['longitude'], 'is_default' => $_REQUEST['is_default'], 'update_city' => $_REQUEST['update_city']);
        $old_location = geodir_get_default_location();
        $locationid = geodir_add_new_location($location_info);
        $default_location = geodir_get_location($locationid);
        //UPDATE AND DELETE LISTING
        $posttype = geodir_get_posttypes();
        if (isset($_REQUEST['listing_action']) && $_REQUEST['listing_action'] == 'delete') {
            foreach ($posttype as $posttypeobj) {
                /* do not update latitude and longitude otrherwise all listings will be spotted on one point on map
                                if ($old_location->city_latitude != $_REQUEST['latitude'] || $old_location->city_longitude != $_REQUEST['longitude']) {
                
                                    $del_post_sql = $wpdb->get_results(
                                        $wpdb->prepare(
                                            "SELECT post_id from ".$plugin_prefix.$posttypeobj."_detail WHERE post_location_id = %d AND (post_city != %s OR post_region != %s)",
                                            array($locationid,$_REQUEST['city'],$_REQUEST['region'])
                                        )
                                    );
                                    $sql = $wpdb->prepare(
                                            "SELECT post_id from ".$plugin_prefix.$posttypeobj."_detail WHERE post_location_id = %d AND (post_city != %s OR post_region != %s)",
                                            array($locationid,$_REQUEST['city'],$_REQUEST['region'])
                                        );
                                    if (!empty($del_post_sql)) {
                                        foreach ($del_post_sql as $del_post_info) {
                                            $postid = (int)$del_post_info->post_id;
                                            //wp_delete_post($postid); // update post location instead of delete post
                                            $sql = $wpdb->prepare(
                                                "UPDATE ".$plugin_prefix.$posttypeobj."_detail SET post_latitude=%s, post_longitude=%s WHERE post_location_id=%d AND post_id=%d",
                                                array( $_REQUEST['latitude'], $_REQUEST['longitude'], $locationid, $postid )
                                            );
                                            $wpdb->query($sql);
                                        }
                                    }
                                }
                                */
                $post_locations = '[' . $default_location->city_slug . '],[' . $default_location->region_slug . '],[' . $default_location->country_slug . ']';
                // set all overall post location
                $sql = $wpdb->prepare("UPDATE " . $plugin_prefix . $posttypeobj . "_detail SET post_city=%s, post_region=%s, post_country=%s, post_locations=%s\r\n\t\t\t\t\t\tWHERE post_location_id=%d AND ( post_city!=%s OR post_region!=%s OR post_country!=%s OR post_locations!=%s OR post_locations IS NULL)", array($_REQUEST['city'], $_REQUEST['region'], $_REQUEST['country'], $post_locations, $locationid, $_REQUEST['city'], $_REQUEST['region'], $_REQUEST['country'], $post_locations));
                $wpdb->query($sql);
            }
        }
    }
}
Exemplo n.º 16
0
/**
 * Returns related listings of a listing.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @param array $request Related posts request array.
 * @global object $wpdb WordPress Database object.
 * @global object $post The current post object.
 * @global string $gridview_columns The girdview style of the listings.
 * @return string Returns related posts html.
 */
function geodir_related_posts_display($request)
{
    if (!empty($request)) {
        $before_title = isset($request['before_title']) && !empty($request['before_title']) ? $request['before_title'] : '';
        $after_title = isset($request['after_title']) && !empty($request['after_title']) ? $request['after_title'] : '';
        $title = isset($request['title']) && !empty($request['title']) ? $request['title'] : __('Related Listings', 'geodirectory');
        $post_number = isset($request['post_number']) && !empty($request['post_number']) ? $request['post_number'] : '5';
        $relate_to = isset($request['relate_to']) && !empty($request['relate_to']) ? $request['relate_to'] : 'category';
        $layout = isset($request['layout']) && !empty($request['layout']) ? $request['layout'] : 'gridview_onehalf';
        $add_location_filter = isset($request['add_location_filter']) && !empty($request['add_location_filter']) ? $request['add_location_filter'] : '0';
        $listing_width = isset($request['listing_width']) && !empty($request['listing_width']) ? $request['listing_width'] : '';
        $list_sort = isset($request['list_sort']) && !empty($request['list_sort']) ? $request['list_sort'] : 'latest';
        $character_count = isset($request['character_count']) && !empty($request['character_count']) ? $request['character_count'] : '';
        global $wpdb, $post;
        $origi_post = $post;
        $post_type = '';
        $post_id = '';
        $category_taxonomy = '';
        $tax_field = 'id';
        $category = array();
        if (isset($_REQUEST['backandedit'])) {
            $post = (object) unserialize($_SESSION['listing']);
            $post_type = $post->listing_type;
            if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
                $post_id = $_REQUEST['pid'];
            }
        } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
            $post = geodir_get_post_info($_REQUEST['pid']);
            $post_type = $post->post_type;
            $post_id = $_REQUEST['pid'];
        } elseif (isset($post->post_type) && $post->post_type != '') {
            $post_type = $post->post_type;
            $post_id = $post->ID;
        }
        if ($relate_to == 'category') {
            $category_taxonomy = $post_type . $relate_to;
            if (isset($post->{$category_taxonomy}) && $post->{$category_taxonomy} != '') {
                $category = explode(',', trim($post->{$category_taxonomy}, ','));
            }
        } elseif ($relate_to == 'tags') {
            $category_taxonomy = $post_type . '_' . $relate_to;
            if ($post->post_tags != '') {
                $category = explode(',', trim($post->post_tags, ','));
            }
            $tax_field = 'name';
        }
        /* --- return false in invalid request --- */
        if (empty($category)) {
            return false;
        }
        $all_postypes = geodir_get_posttypes();
        if (!in_array($post_type, $all_postypes)) {
            return false;
        }
        /* --- return false in invalid request --- */
        $location_url = '';
        if ($add_location_filter != '0') {
            $location_url = array();
            $geodir_show_location_url = get_option('geodir_show_location_url');
            $gd_city = get_query_var('gd_city');
            if ($gd_city) {
                $gd_country = get_query_var('gd_country');
                $gd_region = get_query_var('gd_region');
            } else {
                $location = geodir_get_default_location();
                $gd_country = isset($location->country_slug) ? $location->country_slug : '';
                $gd_region = isset($location->region_slug) ? $location->region_slug : '';
                $gd_city = isset($location->city_slug) ? $location->city_slug : '';
            }
            if ($geodir_show_location_url == 'all') {
                $location_url[] = $gd_country;
                $location_url[] = $gd_region;
            } else {
                if ($geodir_show_location_url == 'country_city') {
                    $location_url[] = $gd_country;
                } else {
                    if ($geodir_show_location_url == 'region_city') {
                        $location_url[] = $gd_region;
                    }
                }
            }
            $location_url[] = $gd_city;
            $location_url = implode('/', $location_url);
        }
        if (!empty($category)) {
            global $geodir_add_location_url;
            $geodir_add_location_url = '0';
            if ($add_location_filter != '0') {
                $geodir_add_location_url = '1';
            }
            $viewall_url = get_term_link((int) $category[0], $post_type . $category_taxonomy);
            $geodir_add_location_url = NULL;
        }
        ob_start();
        ?>


        <div class="geodir_locations geodir_location_listing">

            <?php 
        if (isset($request['is_widget']) && $request['is_widget'] == '1') {
            /** geodir_before_title filter Documented in geodirectory_widgets.php */
            $before_title = isset($before_title) ? $before_title : apply_filters('geodir_before_title', '<h3 class="widget-title">');
            /** geodir_after_title filter Documented in geodirectory_widgets.php */
            $after_title = isset($after_title) ? $after_title : apply_filters('geodir_after_title', '</h3>');
            ?>
                <div class="location_list_heading clearfix">
                    <?php 
            echo $before_title . $title . $after_title;
            ?>
                </div>
            <?php 
        }
        $query_args = array('posts_per_page' => $post_number, 'is_geodir_loop' => true, 'gd_location' => $add_location_filter ? true : false, 'post_type' => $post_type, 'order_by' => $list_sort, 'post__not_in' => array($post_id), 'excerpt_length' => $character_count);
        $tax_query = array('taxonomy' => $category_taxonomy, 'field' => $tax_field, 'terms' => $category);
        $query_args['tax_query'] = array($tax_query);
        global $gridview_columns, $post;
        query_posts($query_args);
        if (strstr($layout, 'gridview')) {
            $listing_view_exp = explode('_', $layout);
            $gridview_columns = $layout;
            $layout = $listing_view_exp[0];
        } else {
            if ($layout == 'list') {
                $gridview_columns = '';
            }
        }
        $related_posts = true;
        /**
         * Filters related listing listview template.
         *
         * @since 1.0.0
         */
        $template = apply_filters("geodir_template_part-related-listing-listview", geodir_locate_template('listing-listview'));
        /**
         * Includes related listing listview template.
         *
         * @since 1.0.0
         */
        include $template;
        wp_reset_query();
        $post = $origi_post;
        ?>

        </div>
        <?php 
        return $html = ob_get_clean();
    }
}
Exemplo n.º 17
0
 /**
  * Saves listing in the database using given information.
  *
  * @since 1.0.0
  * @package GeoDirectory
  * @global object $wpdb WordPress Database object.
  * @global object $post The current post object.
  * @global object $current_user Current user object.
  * @param array $request_info {
  *    Array of request info arguments.
  *
  *    @type string $action                                  Ajax action name.
  *    @type string $geodir_ajax                             Ajax type.
  *    @type string $ajax_action                             Ajax action.
  *    @type string $listing_type                            Listing type.
  *    @type string $pid                                     Default Post ID.
  *    @type string $preview                                 Todo Desc needed.
  *    @type string $add_listing_page_id                     Add listing page ID.
  *    @type string $post_title                              Listing title.
  *    @type string $post_desc                               Listing Description.
  *    @type string $post_tags                               Listing tags.
  *    @type array  $cat_limit                               Category limit.
  *    @type array  $post_category                           Category IDs.
  *    @type array  $post_category_str                       Category string.
  *    @type string $post_default_category                   Default category ID.
  *    @type string $post_address                            Listing address.
  *    @type string $geodir_location_add_listing_country_val Add listing country value.
  *    @type string $post_country                            Listing country.
  *    @type string $geodir_location_add_listing_region_val  Add listing region value.
  *    @type string $post_region                             Listing region.
  *    @type string $geodir_location_add_listing_city_val    Add listing city value.
  *    @type string $post_city                               Listing city.
  *    @type string $post_zip                                Listing zip.
  *    @type string $post_latitude                           Listing latitude.
  *    @type string $post_longitude                          Listing longitude.
  *    @type string $post_mapview                            Listing mapview. Default "ROADMAP".
  *    @type string $post_mapzoom                            Listing mapzoom Default "9".
  *    @type string $geodir_timing                           Business timing info.
  *    @type string $geodir_contact                          Contact number.
  *    @type string $geodir_email                            Business contact email.
  *    @type string $geodir_website                          Business website.
  *    @type string $geodir_twitter                          Twitter link.
  *    @type string $geodir_facebook                         Facebook link.
  *    @type string $geodir_video                            Video link.
  *    @type string $geodir_special_offers                   Speacial offers.
  *    @type string $post_images                             Post image urls.
  *    @type string $post_imagesimage_limit                  Post images limit.
  *    @type string $post_imagestotImg                       Todo Desc needed.
  *    @type string $geodir_accept_term_condition            Has accepted terms and conditions?.
  *    @type string $geodir_spamblocker                      Todo Desc needed.
  *    @type string $geodir_filled_by_spam_bot               Todo Desc needed.
  *
  * }
  * @param bool $dummy Optional. Is this a dummy listing? Default false.
  * @return int|string|WP_Error Created post id.
  */
 function geodir_save_listing($request_info = array(), $dummy = false)
 {
     global $wpdb, $current_user;
     $last_post_id = '';
     if (isset($_SESSION['listing']) && !$dummy) {
         $request_info = array();
         $request_session = unserialize($_SESSION['listing']);
         $request_info = array_merge($_REQUEST, $request_session);
     } else {
         if (!isset($_SESSION['listing']) && !$dummy) {
             global $post;
             $request_info['pid'] = $post->ID;
             $request_info['post_title'] = $request_info['post_title'];
             $request_info['listing_type'] = $post->post_type;
             $request_info['post_desc'] = $request_info['content'];
         } else {
             if (!$dummy) {
                 return false;
             }
         }
     }
     /**
      * Filter the request_info array.
      *
      * You can use this filter to modify request_info array.
      *
      * @since 1.0.0
      * @package GeoDirectory
      * @param array $request_info See {@see geodir_save_listing()} for accepted args.
      */
     $request_info = apply_filters('geodir_action_get_request_info', $request_info);
     // Check if we need to save post location as new location
     $location_result = geodir_get_default_location();
     if ($location_result->location_id > 0) {
         if (isset($request_info['post_city']) && isset($request_info['post_region'])) {
             $request_info['post_location'] = array('city' => $request_info['post_city'], 'region' => isset($request_info['post_region']) ? $request_info['post_region'] : '', 'country' => isset($request_info['post_country']) ? $request_info['post_country'] : '', 'geo_lat' => isset($request_info['post_latitude']) ? $request_info['post_latitude'] : '', 'geo_lng' => isset($request_info['post_longitude']) ? $request_info['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 = $location_result->location_id;
         }
     } else {
         $post_location_id = $location_result->location_id;
     }
     if ($dummy) {
         $post_status = 'publish';
     } else {
         $post_status = geodir_new_post_default_status();
     }
     if (isset($request_info['pid']) && $request_info['pid'] != '') {
         $post_status = get_post_status($request_info['pid']);
     }
     /* fix change of slug on every title edit */
     if (!isset($request_info['post_name'])) {
         $request_info['post_name'] = $request_info['post_title'];
         if (!empty($request_info['pid'])) {
             $post_info = get_post($request_info['pid']);
             if (!empty($post_info) && isset($post_info->post_name)) {
                 $request_info['post_name'] = $post_info->post_name;
             }
         }
     }
     $post = array('post_content' => $request_info['post_desc'], 'post_status' => $post_status, 'post_title' => $request_info['post_title'], 'post_name' => $request_info['post_name'], 'post_type' => $request_info['listing_type']);
     /**
      * Called before a listing is saved to the database.
      *
      * @since 1.0.0
      * @param object $post The post object.
      */
     do_action_ref_array('geodir_before_save_listing', $post);
     $send_post_submit_mail = false;
     // unhook this function so it doesn't loop infinitely
     remove_action('save_post', 'geodir_post_information_save', 10, 2);
     if (isset($request_info['pid']) && $request_info['pid'] != '') {
         $post['ID'] = $request_info['pid'];
         $last_post_id = wp_update_post($post);
     } else {
         $last_post_id = wp_insert_post($post);
         if (!$dummy && $last_post_id) {
             $send_post_submit_mail = true;
             // we move post_submit email from here so the rest of the variables are added to the db first(was breaking permalink in email)
             //geodir_sendEmail('','',$current_user->user_email,$current_user->display_name,'','',$request_info,'post_submit',$last_post_id,$current_user->ID);
         }
     }
     // re-hook this function
     add_action('save_post', 'geodir_post_information_save', 10, 2);
     $post_tags = '';
     if (!isset($request_info['post_tags'])) {
         $post_type = $request_info['listing_type'];
         $post_tags = implode(",", wp_get_object_terms($last_post_id, $post_type . '_tags', array('fields' => 'names')));
     }
     $gd_post_info = array("post_title" => $request_info['post_title'], "post_tags" => isset($request_info['post_tags']) ? $request_info['post_tags'] : $post_tags, "post_status" => $post_status, "post_location_id" => $post_location_id, "claimed" => isset($request_info['claimed']) ? $request_info['claimed'] : '', "businesses" => isset($request_info['a_businesses']) ? $request_info['a_businesses'] : '', "submit_time" => time(), "submit_ip" => $_SERVER['REMOTE_ADDR']);
     $payment_info = array();
     $package_info = array();
     $package_info = (array) geodir_post_package_info($package_info, $post);
     $post_package_id = geodir_get_post_meta($last_post_id, 'package_id');
     if (!empty($package_info) && !$post_package_id) {
         if (isset($package_info['days']) && $package_info['days'] != 0) {
             $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['days'] . " days"));
         } else {
             $payment_info['expire_date'] = 'Never';
         }
         $payment_info['package_id'] = $package_info['pid'];
         $payment_info['alive_days'] = $package_info['days'];
         $payment_info['is_featured'] = $package_info['is_featured'];
         $gd_post_info = array_merge($gd_post_info, $payment_info);
     }
     $custom_metaboxes = geodir_post_custom_fields('', 'all', $request_info['listing_type']);
     foreach ($custom_metaboxes as $key => $val) {
         $name = $val['name'];
         $type = $val['type'];
         $extrafields = $val['extra_fields'];
         if (trim($type) == 'address') {
             $prefix = $name . '_';
             $address = $prefix . 'address';
             if (isset($request_info[$address]) && $request_info[$address] != '') {
                 $gd_post_info[$address] = $request_info[$address];
             }
             if ($extrafields != '') {
                 $extrafields = unserialize($extrafields);
                 if (!isset($request_info[$prefix . 'city']) || $request_info[$prefix . 'city'] == '') {
                     $location_result = geodir_get_default_location();
                     $gd_post_info[$prefix . 'city'] = $location_result->city;
                     $gd_post_info[$prefix . 'region'] = $location_result->region;
                     $gd_post_info[$prefix . 'country'] = $location_result->country;
                     $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']';
                     // set all overall post location
                 } else {
                     $gd_post_info[$prefix . 'city'] = $request_info[$prefix . 'city'];
                     $gd_post_info[$prefix . 'region'] = $request_info[$prefix . 'region'];
                     $gd_post_info[$prefix . 'country'] = $request_info[$prefix . 'country'];
                     //----------set post locations when import dummy data-------
                     $location_result = geodir_get_default_location();
                     $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']';
                     // set all overall post location
                     //-----------------------------------------------------------------
                 }
                 if (isset($extrafields['show_zip']) && $extrafields['show_zip'] && isset($request_info[$prefix . 'zip'])) {
                     $gd_post_info[$prefix . 'zip'] = $request_info[$prefix . 'zip'];
                 }
                 if (isset($extrafields['show_map']) && $extrafields['show_map']) {
                     if (isset($request_info[$prefix . 'latitude']) && $request_info[$prefix . 'latitude'] != '') {
                         $gd_post_info[$prefix . 'latitude'] = $request_info[$prefix . 'latitude'];
                     }
                     if (isset($request_info[$prefix . 'longitude']) && $request_info[$prefix . 'longitude'] != '') {
                         $gd_post_info[$prefix . 'longitude'] = $request_info[$prefix . 'longitude'];
                     }
                     if (isset($request_info[$prefix . 'mapview']) && $request_info[$prefix . 'mapview'] != '') {
                         $gd_post_info[$prefix . 'mapview'] = $request_info[$prefix . 'mapview'];
                     }
                     if (isset($request_info[$prefix . 'mapzoom']) && $request_info[$prefix . 'mapzoom'] != '') {
                         $gd_post_info[$prefix . 'mapzoom'] = $request_info[$prefix . 'mapzoom'];
                     }
                 }
                 // show lat lng
                 if (isset($extrafields['show_latlng']) && $extrafields['show_latlng'] && isset($request_info[$prefix . 'latlng'])) {
                     $gd_post_info[$prefix . 'latlng'] = $request_info[$prefix . 'latlng'];
                 }
             }
         } elseif (trim($type) == 'file') {
             if (isset($request_info[$name])) {
                 $request_files = array();
                 if ($request_info[$name] != '') {
                     $request_files = explode(",", $request_info[$name]);
                 }
                 $extrafields = $extrafields != '' ? maybe_unserialize($extrafields) : NULL;
                 geodir_save_post_file_fields($last_post_id, $name, $request_files, $extrafields);
             }
         } elseif (trim($type) == 'datepicker') {
             $datetime = '';
             if ($request_info[$name] != '') {
                 $date_format = geodir_default_date_format();
                 if (isset($val['extra_fields']) && $val['extra_fields'] != '') {
                     $extra_fields = unserialize($val['extra_fields']);
                     $date_format = isset($extra_fields['date_format']) && $extra_fields['date_format'] != '' ? $extra_fields['date_format'] : $date_format;
                 }
                 $search = array('dd', 'mm', 'yy');
                 $replace = array('d', 'm', 'Y');
                 $date_format = str_replace($search, $replace, $date_format);
                 $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $request_info[$name]) : $request_info[$name];
                 // PHP doesn't work well with dd/mm/yyyy format
                 $datetime = date("Y-m-d", strtotime($post_htmlvar_value));
             }
             $gd_post_info[$name] = $datetime;
         } else {
             if ($type == 'multiselect') {
                 if (isset($request_info[$name])) {
                     $gd_post_info[$name] = $request_info[$name];
                 } else {
                     if (isset($request_info['gd_field_' . $name])) {
                         $gd_post_info[$name] = '';
                         /* fix de-select for multiselect */
                     }
                 }
             } else {
                 if (isset($request_info[$name])) {
                     $gd_post_info[$name] = $request_info[$name];
                 }
             }
         }
     }
     if (isset($request_info['post_dummy']) && $request_info['post_dummy'] != '') {
         $gd_post_info['post_dummy'] = $request_info['post_dummy'];
     }
     // Save post detail info in detail table
     if (!empty($gd_post_info)) {
         geodir_save_post_info($last_post_id, $gd_post_info);
     }
     // Set categories to the listing
     if (isset($request_info['post_category']) && !empty($request_info['post_category'])) {
         $post_category = array();
         foreach ($request_info['post_category'] as $taxonomy => $cat) {
             if ($dummy) {
                 $post_category = $cat;
             } else {
                 if (!is_array($cat) && strstr($cat, ',')) {
                     $cat = explode(',', $cat);
                 }
                 if (!empty($cat) && is_array($cat)) {
                     $post_category = array_map('intval', $cat);
                 }
             }
             wp_set_object_terms($last_post_id, $post_category, $taxonomy);
         }
         $post_default_category = isset($request_info['post_default_category']) ? $request_info['post_default_category'] : '';
         $post_category_str = isset($request_info['post_category_str']) ? $request_info['post_category_str'] : '';
         geodir_set_postcat_structure($last_post_id, $taxonomy, $post_default_category, $post_category_str);
     }
     $post_tags = '';
     // Set tags to the listing
     if (isset($request_info['post_tags']) && !is_array($request_info['post_tags']) && !empty($request_info['post_tags'])) {
         $post_tags = explode(",", $request_info['post_tags']);
     } elseif (isset($request_info['post_tags']) && is_array($request_info['post_tags'])) {
         if ($dummy) {
             $post_tags = $request_info['post_tags'];
         }
     } else {
         if ($dummy) {
             $post_tags = array($request_info['post_title']);
         }
     }
     if (is_array($post_tags)) {
         $taxonomy = $request_info['listing_type'] . '_tags';
         wp_set_object_terms($last_post_id, $post_tags, $taxonomy);
     }
     // Insert attechment
     if (isset($request_info['post_images']) && !is_wp_error($last_post_id)) {
         if (!$dummy) {
             $tmpimgArr = trim($request_info['post_images'], ",");
             $tmpimgArr = explode(",", $tmpimgArr);
             geodir_save_post_images($last_post_id, $tmpimgArr, $dummy);
         } else {
             geodir_save_post_images($last_post_id, $request_info['post_images'], $dummy);
         }
     } elseif (!isset($request_info['post_images']) || $request_info['post_images'] == '') {
         /* Delete Attachments
         			$postcurr_images = geodir_get_images($last_post_id);
         			
         			$wpdb->query(
         				$wpdb->prepare(
         					"DELETE FROM ".GEODIR_ATTACHMENT_TABLE." WHERE `post_id` = %d",
         					array($last_post_id)
         				)
         			);
         			geodir_remove_attachments($postcurr_images);
         			
         			$gd_post_featured_img = array();
         			$gd_post_featured_img['featured_image'] = '';
         			geodir_save_post_info($last_post_id, $gd_post_featured_img); 
         			*/
     }
     geodir_remove_temp_images();
     geodir_set_wp_featured_image($last_post_id);
     /**
      * Called after a listing is saved to the database and before any email have been sent.
      *
      * @since 1.0.0
      * @param int $last_post_id The saved post ID.
      * @param array $request_info The post details in an array.
      * @see 'geodir_after_save_listinginfo'
      */
     do_action('geodir_after_save_listing', $last_post_id, $request_info);
     //die;
     if ($send_post_submit_mail) {
         // if new post send out email
         $to_name = geodir_get_client_name($current_user->ID);
         geodir_sendEmail('', '', $current_user->user_email, $to_name, '', '', $request_info, 'post_submit', $last_post_id, $current_user->ID);
     }
     /*
      * Unset the session so we don't loop.
      */
     if (isset($_SESSION['listing'])) {
         unset($_SESSION['listing']);
     }
     return $last_post_id;
 }
Exemplo n.º 18
0
/**
 * Check whether a term slug exists or not.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $table_prefix WordPress Database Table prefix.
 * @param bool $slug_exists Default: false.
 * @param string $slug Term slug.
 * @param int $term_id The term ID.
 * @return bool true when exists. false when not exists.
 */
function geodir_term_slug_is_exists($slug_exists, $slug, $term_id)
{
    global $wpdb, $table_prefix;
    $default_location = geodir_get_default_location();
    $country_slug = $default_location->country_slug;
    $region_slug = $default_location->region_slug;
    $city_slug = $default_location->city_slug;
    if ($country_slug == $slug || $region_slug == $slug || $city_slug == $slug) {
        return $slug_exists = true;
    }
    if ($wpdb->get_var($wpdb->prepare("SELECT slug FROM " . $table_prefix . "terms WHERE slug=%s AND term_id != %d", array($slug, $term_id)))) {
        return $slug_exists = true;
    }
    return $slug_exists;
}
Exemplo n.º 19
0
/**
 * Display the google map html.
 *
 * @since 1.0.0
 *
 * @global array $map_canvas_arr Array of map canvas data.
 *
 * @param array $map_args {
 *    Array of map arguments to use in map options.
 *
 *    @type string $width Map width.
 *    @type string $height Map height.
 *    @type string $child_collapse Collapse filter div?.
 *    @type string $sticky Todo: desc needed.
 *    @type bool $enable_map_resize_button Do you want to enable map resize button?.
 *    @type bool $enable_cat_filters Do you want to enable category filters?.
 *    @type bool $enable_text_search Do you want to enable text search?.
 *    @type bool $enable_post_type_filters Do you want to enable post type filters?.
 *    @type bool $enable_location_filters Do you want to enable location filters?.
 *    @type bool $enable_jason_on_load Do you want to enable json on load?.
 *    @type bool $enable_map_direction Do you want to enable map directions?.
 *    @type bool $enable_marker_cluster Do you want to enable marker cluster?.
 *    @type string $ajax_url Map ajax url.
 *    @type string $map_canvas_name Map canvas name.
 *    @type string $inputText Text search placeholder.
 *    @type string $latitude Map default latitude.
 *    @type string $longitude Map default longitude.
 *    @type string $zoom Map default zoom.
 *    @type string $scrollwheel Map default scroll wheel level.
 *    @type bool $streetViewControl Display street view control?.
 *    @type string $maptype Map type.
 *    @type string $showPreview Show preview?.
 *    @type int $maxZoom Map maximum zoom level.
 *    @type int $autozoom Map auto zoom level.
 *    @type string $bubble_size Map bubble size.
 *    @type string $token Map token.
 *    @type array $navigationControlOptions {
 *        Options of navigation control.
 *
 *        @type string $position Navigation position.
 *        @type string $style Navigation style.
 *
 *    }
 *    @type string $map_class_name Map class name.
 *    @type bool $is_geodir_home_map_widget Is this a home page map? True if the current page is home.
 *
 * }
 * @return string|void Html content for google map.
 */
function geodir_draw_map($map_args = array())
{
    global $map_canvas_arr;
    $map_canvas_name = !empty($map_args) && $map_args['map_canvas_name'] != '' ? $map_args['map_canvas_name'] : 'home_map_canvas';
    $map_class_name = !empty($map_args) && isset($map_args['map_class_name']) ? $map_args['map_class_name'] : '';
    $default_location = geodir_get_default_location();
    $map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : '';
    $map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : '';
    $map_default_zoom = 12;
    // map options default values
    $width = 950;
    $height = 450;
    $child_collapse = '0';
    $sticky = '';
    $enable_cat_filters = false;
    $enable_text_search = false;
    $enable_post_type_filters = false;
    $enable_location_filters = false;
    $enable_jason_on_load = false;
    $enable_map_direction = false;
    $enable_marker_cluster = false;
    $enable_map_resize_button = false;
    $maptype = 'ROADMAP';
    $geodir_map_options = array('width' => $width, 'height' => $height, 'child_collapse' => $child_collapse, 'sticky' => $sticky, 'enable_map_resize_button' => $enable_map_resize_button, 'enable_cat_filters' => $enable_cat_filters, 'enable_text_search' => $enable_text_search, 'enable_post_type_filters' => $enable_post_type_filters, 'enable_location_filters' => $enable_location_filters, 'enable_jason_on_load' => $enable_jason_on_load, 'enable_map_direction' => $enable_map_direction, 'enable_marker_cluster' => $enable_marker_cluster, 'ajax_url' => geodir_get_ajax_url(), 'map_canvas_name' => $map_canvas_name, 'inputText' => __('Title or Keyword', 'geodirectory'), 'latitude' => $map_default_lat, 'longitude' => $map_default_lng, 'zoom' => $map_default_zoom, 'scrollwheel' => true, 'streetViewControl' => true, 'maptype' => $maptype, 'showPreview' => '0', 'maxZoom' => 21, 'autozoom' => true, 'bubble_size' => 'small', 'token' => '68f48005e256696074e1da9bf9f67f06', 'navigationControlOptions' => array('position' => 'TOP_LEFT', 'style' => 'ZOOM_PAN'));
    if (!empty($map_args)) {
        foreach ($map_args as $map_option_key => $map_option_value) {
            $geodir_map_options[$map_option_key] = $map_option_value;
        }
    }
    if (strpos($geodir_map_options['height'], '%') !== false || strpos($geodir_map_options['height'], 'px') !== false || strpos($geodir_map_options['height'], 'vh') !== false) {
    } else {
        $geodir_map_options['height'] = $geodir_map_options['height'] . 'px';
    }
    if (strpos($geodir_map_options['width'], '%') !== false || strpos($geodir_map_options['width'], 'px') !== false) {
    } else {
        $geodir_map_options['width'] = $geodir_map_options['width'] . 'px';
    }
    /**
     * Filter the options to use in google map.
     *
     * @since 1.0.0
     *
     * @param array $geodir_map_options {@see geodir_draw_map()} docblock.
     */
    $geodir_map_options = apply_filters("geodir_map_options_{$map_canvas_name}", $geodir_map_options);
    $map_canvas_arr[$map_canvas_name] = array();
    /**
     * Filter the post types to display data on map.
     *
     * @since 1.0.0
     *
     * @param object $object Objects of post types.
     */
    $post_types = apply_filters("geodir_map_post_type_list_{$map_canvas_name}", geodir_get_posttypes('object'));
    /**
     * Filter the post types to exclude to display data on map.
     *
     * @since 1.0.0
     *
     * @param array Array of post types to exclude to display data on map.
     */
    $exclude_post_types = apply_filters("geodir_exclude_post_type_on_map_{$map_canvas_name}", get_option('geodir_exclude_post_type_on_map'));
    if (count((array) $post_types) != count($exclude_post_types) || $enable_jason_on_load) {
        // Set default map options
        wp_enqueue_script('geodir-map-widget', geodir_plugin_url() . '/geodirectory-functions/map-functions/js/map.min.js');
        wp_localize_script('geodir-map-widget', $map_canvas_name, $geodir_map_options);
        if ($map_canvas_name == 'detail_page_map_canvas' || $map_canvas_name == 'preview_map_canvas') {
            $map_width = '100%';
        } else {
            $map_width = $geodir_map_options['width'];
        }
        /**
         * Filter the width of map.
         *
         * @since 1.0.0
         *
         * @param int $map_width Width of map box, eg: gd_place.
         */
        $map_width = apply_filters('geodir_change_map_width', $map_width);
        ?>
        <div id="catcher_<?php 
        echo $map_canvas_name;
        ?>
"></div>
        <div class="stick_trigger_container">
            <div class="trigger_sticky triggeroff_sticky"></div>
            <div class="top_banner_section geodir_map_container <?php 
        echo $map_class_name;
        ?>
"
                 id="sticky_map_<?php 
        echo $map_canvas_name;
        ?>
"
                 style="min-height:<?php 
        echo $geodir_map_options['height'];
        ?>
;width:<?php 
        echo $map_width;
        ?>
;">

                <div class="map_background">
                    <div class="top_banner_section_in clearfix">
                        <div class="<?php 
        echo $map_canvas_name;
        ?>
_TopLeft TopLeft"><span class="triggermap" id="<?php 
        echo $map_canvas_name;
        ?>
_triggermap" <?php 
        if (!$geodir_map_options['enable_map_resize_button']) {
            ?>
 <?php 
        }
        ?>
><i class="fa fa-arrows-alt"></i></span></div>
                        <div class="<?php 
        echo $map_canvas_name;
        ?>
_TopRight TopRight"></div>
                        <div id="<?php 
        echo $map_canvas_name;
        ?>
_wrapper" class="main_map_wrapper"
                             style="height:<?php 
        echo $geodir_map_options['height'];
        ?>
;width:<?php 
        echo $map_width;
        ?>
;">
                            <!-- new map start -->
                            <div class="iprelative">
                                <div class="geodir_marker_cluster" id="<?php 
        echo $map_canvas_name;
        ?>
"
                                     style="height:<?php 
        echo $geodir_map_options['height'];
        ?>
;width:<?php 
        echo $map_width;
        ?>
;"></div>
                                <div id="<?php 
        echo $map_canvas_name;
        ?>
_loading_div" class="loading_div"
                                     style=" height:<?php 
        echo $geodir_map_options['height'];
        ?>
;width:<?php 
        echo $map_width;
        ?>
;"></div>
                                <!--<div id="home_map_counter"></div>        -->
                                <div id="<?php 
        echo $map_canvas_name;
        ?>
_map_nofound"
                                     class="advmap_nofound"><?php 
        echo MAP_NO_RESULTS;
        ?>
</div>
                            </div>
                            <!-- new map end -->
                        </div>
                        <div class="<?php 
        echo $map_canvas_name;
        ?>
_BottomLeft BottomLeft"></div>
                    </div>
                </div>
                <?php 
        if ($geodir_map_options['enable_jason_on_load']) {
            ?>
                    <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_jason_enabled" value="1"/>
                <?php 
        } else {
            ?>
                    <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_jason_enabled" value="0"/>
                <?php 
        }
        if (!$geodir_map_options['enable_text_search'] && !$geodir_map_options['enable_cat_filters']) {
            $show_entire_cat_panel = "none";
        } else {
            $show_entire_cat_panel = "''";
        }
        ?>

                <?php 
        if ($geodir_map_options['enable_map_direction']) {
            ?>

                    <input type="text" id="<?php 
            echo $map_canvas_name;
            ?>
_fromAddress" name="from" class="textfield"
                           value="<?php 
            echo ENTER_LOCATION_TEXT;
            ?>
"
                           onblur="if (this.value == '') {this.value = '<?php 
            echo ENTER_LOCATION_TEXT;
            ?>
';}"
                           onfocus="if (this.value == '<?php 
            echo ENTER_LOCATION_TEXT;
            ?>
') {this.value = '';}"/>
                    <input type="button" value="<?php 
            _e('Get Directions', 'geodirectory');
            ?>
"
                           class="<?php 
            echo $map_canvas_name;
            ?>
_getdirection" id="directions"
                           onclick="calcRoute('<?php 
            echo $map_canvas_name;
            ?>
')"/>

                    <script>
                        <?php 
            if (geodir_is_page('detail')) {
                ?>
                        jQuery(function () {
                            gd_initialize_ac();
                        });
                        <?php 
            }
            ?>

                        function gd_initialize_ac() {
                            // Create the autocomplete object, restricting the search
                            // to geographical location types.
                            autocomplete = new google.maps.places.Autocomplete(
                                /** @type {HTMLInputElement} */(document.getElementById('<?php 
            echo $map_canvas_name;
            ?>
_fromAddress')),
                                {types: ['geocode']});
                            // When the user selects an address from the dropdown,
                            // populate the address fields in the form.
                            google.maps.event.addListener(autocomplete, 'place_changed', function () {
                                gd_fillInAddress_ac();
                            });
                        }

                        function gd_fillInAddress_ac() {
                            //submit the form
                            jQuery('#directions').trigger('click');
                        }

                    </script>


                    <div id='directions-options' class="hidden">
                        <select id="travel-mode" onchange="calcRoute('<?php 
            echo $map_canvas_name;
            ?>
')">
                            <option value="driving"><?php 
            _e('Driving', 'geodirectory');
            ?>
</option>
                            <option value="walking"><?php 
            _e('Walking', 'geodirectory');
            ?>
</option>
                            <option value="bicycling"><?php 
            _e('Bicycling', 'geodirectory');
            ?>
</option>
                            <option value="transit"><?php 
            _e('Public Transport', 'geodirectory');
            ?>
</option>
                        </select>

                        <select id="travel-units" onchange="calcRoute('<?php 
            echo $map_canvas_name;
            ?>
')">
                            <option value="miles"><?php 
            _e('Miles', 'geodirectory');
            ?>
</option>
                            <option <?php 
            if (get_option('geodir_search_dist_1') == 'km') {
                echo 'selected="selected"';
            }
            ?>
 value="kilometers"><?php 
            _e('Kilometers', 'geodirectory');
            ?>
</option>
                        </select>
                    </div>

                    <div id="<?php 
            echo $map_canvas_name;
            ?>
_directionsPanel" style="width:auto;"></div>
                <?php 
        }
        $geodir_default_map_search_pt = get_option('geodir_default_map_search_pt');
        if (empty($geodir_default_map_search_pt)) {
            $geodir_default_map_search_pt = 'gd_place';
        }
        /**
         * Filter the post type to retrive data for map
         *
         * @since 1.0.0
         *
         * @param string $geodir_default_map_search_pt Post type, eg: gd_place.
         */
        $map_search_pt = apply_filters('geodir_default_map_search_pt', $geodir_default_map_search_pt);
        ?>
                <div class="map-category-listing-main" style="display:<?php 
        echo $show_entire_cat_panel;
        ?>
">
                    <?php 
        $exclude_post_types = get_option('geodir_exclude_post_type_on_map');
        $geodir_available_pt_on_map = count(geodir_get_posttypes('array')) - count($exclude_post_types);
        $map_cat_class = '';
        if ($geodir_map_options['enable_post_type_filters']) {
            $map_cat_class = $geodir_available_pt_on_map > 1 ? ' map-cat-ptypes' : ' map-cat-floor';
        }
        ?>
                    <div
                        class="map-category-listing<?php 
        echo $map_cat_class;
        ?>
">
                        <div class="trigger triggeroff"><i class="fa fa-compress"></i><i class="fa fa-expand"></i></div>
                        <div id="<?php 
        echo $map_canvas_name;
        ?>
_cat"
                             class="<?php 
        echo $map_canvas_name;
        ?>
_map_category  map_category"
                             <?php 
        if ($child_collapse) {
            ?>
checked="checked" <?php 
        }
        ?>
                             style="max-height:<?php 
        echo $geodir_map_options['height'];
        ?>
;">
                            <input
                                onkeydown="if(event.keyCode == 13){build_map_ajax_search_param('<?php 
        echo $map_canvas_name;
        ?>
', false)}"
                                type="text"
                                class="inputbox <?php 
        echo $geodir_map_options['enable_text_search'] ? '' : 'geodir-hide';
        ?>
"
                                id="<?php 
        echo $map_canvas_name;
        ?>
_search_string" name="search"
                                placeholder="<?php 
        _e('Title', 'geodirectory');
        ?>
"/>
                            <?php 
        if ($geodir_map_options['enable_cat_filters']) {
            ?>
                                <?php 
            if ($geodir_map_options['child_collapse']) {
                $child_collapse = "1";
                ?>
                                    <input type="hidden" id="<?php 
                echo $map_canvas_name;
                ?>
_child_collapse" value="1"/>
                                <?php 
            } else {
                $child_collapse = "0";
                ?>
                                    <input type="hidden" id="<?php 
                echo $map_canvas_name;
                ?>
_child_collapse" value="0"/>
                                <?php 
            }
            ?>
                                <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_cat_enabled" value="1"/>
                                <div class="toggle">
                                    <?php 
            echo home_map_taxonomy_walker(array($map_search_pt . 'category'), 0, true, 0, $map_canvas_name, $child_collapse, true);
            ?>
                                    <script>jQuery( document ).ready(function() {
                                            geodir_show_sub_cat_collapse_button();
                                        });</script>
                                </div>
                            <?php 
        } else {
            // end of cat filter
            ?>
                                <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_cat_enabled" value="0"/>
                                <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_child_collapse" value="0"/>
                            <?php 
        }
        ?>
                            <div class="BottomRight"></div>
                            <br/>

                        </div>
                    </div>
                </div>
                <!-- map-category-listings-->

                <?php 
        if ($geodir_map_options['enable_location_filters']) {
            $country = get_query_var('gd_country');
            $region = get_query_var('gd_region');
            $city = get_query_var('gd_city');
            //fix for location/me page
            $country = $country != 'me' ? $country : '';
            $region = $region != 'me' ? $region : '';
            $city = $country != 'me' ? $city : '';
            ?>
                    <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_location_enabled" value="1"/>
                    <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_country" name="gd_country"
                           value="<?php 
            echo $country;
            ?>
"/>
                    <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_region" name="gd_region"
                           value="<?php 
            echo $region;
            ?>
"/>
                    <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_city" name="gd_city"
                           value="<?php 
            echo $city;
            ?>
"/>
                    <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_neighbourhood" name="gd_neighbourhood"
                           value="<?php 
            if (isset($_REQUEST['gd_neighbourhood'])) {
                echo $_REQUEST['gd_neighbourhood'];
            }
            ?>
"/>
                <?php 
        } else {
            //end of location filter
            ?>
                    <input type="hidden" id="<?php 
            echo $map_canvas_name;
            ?>
_location_enabled" value="0"/>
                <?php 
        }
        ?>

                <input type="hidden" id="<?php 
        echo $map_canvas_name;
        ?>
_posttype" name="gd_posttype" value="<?php 
        echo $map_search_pt;
        ?>
"/>

                <input type="hidden" name="limitstart" value=""/>



                <?php 
        if ($geodir_map_options['enable_post_type_filters']) {
            $post_types = geodir_get_posttypes('object');
            if (count((array) $post_types) > 1) {
                ?>
                        <div class="map-places-listing" id="<?php 
                echo $map_canvas_name;
                ?>
_posttype_menu"
                             style="max-width:<?php 
                echo $map_width;
                ?>
!important;">

                            <?php 
                if (isset($geodir_map_options['is_geodir_home_map_widget']) && $map_args['is_geodir_home_map_widget']) {
                    ?>
                            <div class="geodir-map-posttype-list"><?php 
                }
                ?>
                                <ul class="clearfix place-list">
                                    <?php 
                $exclude_post_types = get_option('geodir_exclude_post_type_on_map');
                foreach ($post_types as $post_type => $args) {
                    if (!in_array($post_type, $exclude_post_types)) {
                        $class = $map_search_pt == $post_type ? 'class="gd-map-search-pt"' : '';
                        echo '<li id="' . $post_type . '" ' . $class . '><a href="javascript:void(0);" onclick="jQuery(\'#' . $map_canvas_name . '_posttype\').val(\'' . $post_type . '\');build_map_ajax_search_param(\'' . $map_canvas_name . '\', true)">' . __(ucfirst($args->labels->name), 'geodirectory') . '</a></li>';
                    }
                }
                ?>
                                </ul>
                                <?php 
                if (isset($geodir_map_options['is_geodir_home_map_widget']) && $map_args['is_geodir_home_map_widget']) {
                    ?>
                            </div><?php 
                }
                ?>
                            <div class="geodir-map-navigation">
                                <ul>
                                    <li class="geodir-leftarrow"><a href="#"><i class="fa fa-chevron-left"></i></a></li>
                                    <li class="geodir-rightarrow"><a href="#"><i class="fa fa-chevron-right"></i></a>
                                    </li>
                                </ul>
                            </div>

                        </div> <!-- map-places-listings-->
                    <?php 
            }
        }
        // end of post type filter if
        ?>

            </div>
        </div> <!--end of stick trigger container-->
        <script type="text/javascript">

            jQuery(document).ready(function () {
                //initMap('<?php 
        echo $map_canvas_name;
        ?>
'); // depreciated, no need to load this twice
                build_map_ajax_search_param('<?php 
        echo $map_canvas_name;
        ?>
', false);
                map_sticky('<?php 
        echo $map_canvas_name;
        ?>
');
            });

        </script>
        <?php 
        if (strpos($geodir_map_options['height'], 'vh')) {
            ?>
            <script>
                (function () {
                    var screenH = jQuery(window).height();
                    var heightVH = "<?php 
            echo str_replace("vh", "", $geodir_map_options['height']);
            ?>
";

                    var ptypeH = '';
                    if (jQuery("#<?php 
            echo $map_canvas_name;
            ?>
_posttype_menu").length) {
                        ptypeH = jQuery("#<?php 
            echo $map_canvas_name;
            ?>
_posttype_menu").outerHeight();
                    }

                    jQuery("#sticky_map_<?php 
            echo $map_canvas_name;
            ?>
").css("min-height", screenH * (heightVH / 100) + 'px');
                    jQuery("#<?php 
            echo $map_canvas_name;
            ?>
_wrapper").height(screenH * (heightVH / 100) + 'px');
                    jQuery("#<?php 
            echo $map_canvas_name;
            ?>
").height(screenH * (heightVH / 100) + 'px');
                    jQuery("#<?php 
            echo $map_canvas_name;
            ?>
_loading_div").height(screenH * (heightVH / 100) + 'px');
                    jQuery("#<?php 
            echo $map_canvas_name;
            ?>
_cat").css("max-height", (screenH * (heightVH / 100)) - ptypeH + 'px');

                }());
            </script>

        <?php 
        } elseif (strpos($geodir_map_options['height'], 'px')) {
            ?>
            <script>
                (function () {
                    var screenH = jQuery(window).height();
                    var heightVH = "<?php 
            echo str_replace("px", "", $geodir_map_options['height']);
            ?>
";
                    var ptypeH = '';
                    if (jQuery("#<?php 
            echo $map_canvas_name;
            ?>
_posttype_menu").length) {
                        ptypeH = jQuery("#<?php 
            echo $map_canvas_name;
            ?>
_posttype_menu").outerHeight();
                    }

                    jQuery("#<?php 
            echo $map_canvas_name;
            ?>
_cat").css("max-height", heightVH - ptypeH + 'px');

                }());
            </script>
        <?php 
        }
        /**
         * Action that runs after all the map code has been output;
         *
         * @since 1.5.3
         *
         * @param array $geodir_map_options Array of map settings.
         * @param string $map_canvas_name The canvas name and ID for the map.
         */
        do_action('geodir_map_after_render', $geodir_map_options, $map_canvas_name);
    }
    // Exclude posttypes if end
}