/** * * @global object $wp WordPress object. * * @param array $args * @param array $instance */ public function widget($args, $instance) { global $wp; extract($args, EXTR_SKIP); $title = empty($instance['title']) ? __('Popular Locations', GEODIRLOCATION_TEXTDOMAIN) : apply_filters('geodir_popular_location_widget_title', __($instance['title'], GEODIRLOCATION_TEXTDOMAIN)); echo $before_widget; ?> <div class="geodir-category-list-in clearfix"> <div class="geodir-cat-list clearfix"> <?php echo $before_title . __($title) . $after_title; ?> <?php $location_terms = geodir_get_current_location_terms(); //locations in sessions // get all the cities in current region $args = 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_slug', 'region_column_name' => 'region_slug', 'city_column_name' => 'city_slug', 'location_link_part' => true, 'order_by' => ' asc ', 'no_of_records' => '', 'format' => array('type' => 'list', 'container_wrapper' => 'ul', 'container_wrapper_attr' => '', 'item_wrapper' => 'li', 'item_wrapper_attr' => '')); if (!empty($location_terms)) { if (isset($location_terms['gd_region']) && $location_terms['gd_region'] != '') { $args['region_val'] = $location_terms['gd_region']; $args['country_val'] = $location_terms['gd_country']; } else { if (isset($location_terms['gd_country']) && $location_terms['gd_country'] != '') { $args['country_val'] = $location_terms['gd_country']; } } } echo $geodir_cities_list = geodir_get_location_array($args, false); ?> </div> </div> <?php echo $after_widget; }
/** * * @global object $wp WordPress object. * * @param $atts * @return string */ function geodir_sc_popular_location($atts) { global $wp; $location_terms = geodir_get_current_location_terms(); //locations in sessions // get all the cities in current region $args = 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_slug', 'region_column_name' => 'region_slug', 'city_column_name' => 'city_slug', 'location_link_part' => true, 'order_by' => ' asc ', 'no_of_records' => '', 'format' => array('type' => 'list', 'container_wrapper' => 'ul', 'container_wrapper_attr' => '', 'item_wrapper' => 'li', 'item_wrapper_attr' => '')); if (!empty($location_terms)) { if (isset($location_terms['gd_region']) && $location_terms['gd_region'] != '') { $args['region_val'] = $location_terms['gd_region']; $args['country_val'] = $location_terms['gd_country']; } else { if (isset($location_terms['gd_country']) && $location_terms['gd_country'] != '') { $args['country_val'] = $location_terms['gd_country']; } } } ob_start(); echo '<div class="geodir-sc-popular-location">'; echo $geodir_cities_list = geodir_get_location_array($args, false); echo '</div>'; $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * This is used to put country , region , city and neighbour dropdown on add/edit listing page. * * @since 1.0.0 * @package GeoDirectory_Location_Manager * * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * * @param array $val The array of setting for the custom field. */ function geodir_location_address_extra_listing_fields($val) { $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']); $prefix = $name . '_'; $extra_fields['city_lable'] != '' ? $city_title = $extra_fields['city_lable'] : ($city_title = ucwords($prefix . ' city')); $extra_fields['region_lable'] != '' ? $region_title = $extra_fields['region_lable'] : ($region_title = ucwords($prefix . ' region')); $extra_fields['country_lable'] != '' ? $country_title = $extra_fields['country_lable'] : ($country_title = ucwords($prefix . ' country')); $city = ''; $region = ''; $country = ''; $neighbourhood = ''; if (isset($_REQUEST['backandedit']) && $_REQUEST['backandedit'] && isset($_SESSION['listing'])) { $post = unserialize($_SESSION['listing']); $city = $post[$prefix . 'city']; $region = $post[$prefix . 'region']; $country = $post[$prefix . 'country']; $neighbourhood = isset($post[$prefix . 'neighbourhood']) ? $post[$prefix . 'neighbourhood'] : ''; } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '' && ($post_info = geodir_get_post_info($_REQUEST['pid']))) { $post_info = (array) $post_info; $city = $post_info[$prefix . 'city']; $region = $post_info[$prefix . 'region']; $country = $post_info[$prefix . 'country']; if (isset($post_info[$prefix . 'neighbourhood'])) { $neighbourhood = $post_info[$prefix . 'neighbourhood']; } } elseif (isset($_SESSION['gd_multi_location'])) { if (isset($_SESSION['gd_city']) && $_SESSION['gd_city'] != '') { $location = geodir_get_locations('city', $_SESSION['gd_city']); } elseif (isset($_SESSION['gd_region']) && $_SESSION['gd_region'] != '') { $location = geodir_get_locations('region', $_SESSION['gd_region']); } elseif (isset($_SESSION['gd_country']) && $_SESSION['gd_country'] != '') { $location = geodir_get_locations('country', $_SESSION['gd_country']); } if (isset($location) && $location) { $location = end($location); } $city = isset($location->city) ? $location->city : ''; $region = isset($location->region) ? $location->region : ''; $country = isset($location->country) ? $location->country : ''; } $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 : ''; } ?> <div id="geodir_add_listing_all_chosen_container_row" class="geodir_location_add_listing_all_chosen_container" > <?php if (get_option('geodir_enable_country') == 'default') { global $wpdb; $countries_ISO2 = $wpdb->get_var($wpdb->prepare("SELECT ISO2 FROM " . GEODIR_COUNTRIES_TABLE . " WHERE Country=%s", $country)); ?> <input type="hidden" name="geodir_location_add_listing_country_val" value="<?php echo $country; ?> " /> <input type="hidden" id="<?php echo $prefix; ?> country" data-country_code="<?php echo $countries_ISO2; ?> " name="<?php echo $prefix; ?> country" value="<?php echo $country; ?> " /> <?php } else { if ($extra_fields['show_country']) { ?> <div id="geodir_<?php echo $prefix . 'country'; ?> _row" class="<?php if ($is_required) { echo 'required_field'; } ?> geodir_form_row geodir_location_add_listing_country_chosen_container clearfix"> <label> <?php _e($country_title, GEODIRLOCATION_TEXTDOMAIN); ?> <?php if ($is_required) { echo '<span>*</span>'; } ?> </label> <div class="geodir_location_add_listing_country_chosen_div" style="width:57%; float:left;"> <input type="hidden" name="geodir_location_add_listing_country_val" value="<?php echo $country; ?> " /> <select id="<?php echo $prefix; ?> country" class="geodir_location_add_listing_chosen" data-location_type="country" name="<?php echo $prefix; ?> country" data-placeholder="<?php _e('Choose a country.', GEODIRLOCATION_TEXTDOMAIN); ?> " data-addsearchtermonnorecord="1" data-ajaxchosen="0" data-autoredirect="0" data-showeverywhere="0" > <?php if (get_option('geodir_enable_country') == 'multi') { geodir_get_country_dl($country, $prefix); } else { if (get_option('geodir_enable_country') == 'selected') { geodir_get_limited_country_dl($country, $prefix); } } ?> </select> </div> <span class="geodir_message_note"><?php _e('Click on above field and type to filter list', GEODIRLOCATION_TEXTDOMAIN); ?> </span> <?php if ($is_required) { ?> <span class="geodir_message_error"><?php echo $required_msg; ?> </span> <?php } ?> </div> <?php } } // end of show country if if (get_option('geodir_enable_region') == 'default') { ?> <input type="hidden" name="geodir_location_add_listing_region_val" value="<?php echo $region; ?> " /> <input type="hidden" id="<?php echo $prefix; ?> region" name="<?php echo $prefix; ?> region" value="<?php echo $region; ?> " /> <?php } else { if ($extra_fields['show_region']) { ?> <div id="geodir_<?php echo $prefix . 'region'; ?> _row" class="<?php if ($is_required) { echo 'required_field'; } ?> geodir_form_row geodir_location_add_listing_region_chosen_container clearfix"> <label> <?php _e($region_title, GEODIRLOCATION_TEXTDOMAIN); ?> <?php if ($is_required) { echo '<span>*</span>'; } ?> </label> <div class="geodir_location_add_listing_region_chosen_div" style="width:57%; float:left;"> <input type="hidden" name="geodir_location_add_listing_region_val" value="<?php echo $region; ?> " /> <select id="<?php echo $prefix; ?> region" class="geodir_location_add_listing_chosen" data-location_type="region" name="<?php echo $prefix; ?> region" data-placeholder="<?php _e('Please wait..…', GEODIRLOCATION_TEXTDOMAIN); ?> " <?php if (get_option('geodir_enable_region') == 'selected') { ?> data-ajaxchosen="0" <?php } else { ?> data-ajaxchosen="1" <?php } ?> data-addsearchtermonnorecord="1" data-autoredirect="0" > <?php $selected = ''; $args = array('what' => 'region', 'country_val' => $country, 'region_val' => '', 'echo' => false, 'format' => array('type' => 'array')); if (get_option('location_dropdown_all')) { $args['no_of_records'] = '10000'; } // set limit to 10 thouseand as this is most browsers limit $location_array = geodir_get_location_array($args); // get country val in case of country search to get selected option ?> <option value='' ><?php _e('Select State', GEODIRLOCATION_TEXTDOMAIN); ?> </option> <?php if (!empty($location_array)) { foreach ($location_array as $locations) { $selected = ''; if (strtolower($region) == strtolower($locations->region)) { $selected = " selected='selected' "; } ?> <option <?php echo $selected; ?> value="<?php echo $locations->region; ?> " ><?php echo ucwords($locations->region); ?> </option> <?php } } ?> </select> </div> <span class="geodir_message_note"><?php _e('Click on above field and type to filter list or add a new region', GEODIRLOCATION_TEXTDOMAIN); ?> </span> <?php if ($is_required) { ?> <span class="geodir_message_error"><?php echo $required_msg; ?> </span> <?php } ?> </div> <?php } } //end of show region if (get_option('geodir_enable_city') == 'default') { ?> <input type="hidden" name="geodir_location_add_listing_city_val" value="<?php echo $city; ?> " /> <input type="hidden" id="<?php echo $prefix; ?> city" name="<?php echo $prefix; ?> city" value="<?php echo $city; ?> " /> <?php } else { if ($extra_fields['show_city']) { ?> <div id="geodir_<?php echo $prefix . 'city'; ?> _row" class="<?php if ($is_required) { echo 'required_field'; } ?> geodir_form_row geodir_location_add_listing_city_chosen_container clearfix"> <label> <?php _e($city_title, GEODIRLOCATION_TEXTDOMAIN); ?> <?php if ($is_required) { echo '<span>*</span>'; } ?> </label> <div class="geodir_location_add_listing_city_chosen_div" style="width:57%; float:left;"> <input type="hidden" name="geodir_location_add_listing_city_val" value="<?php echo $city; ?> " /> <select id="<?php echo $prefix; ?> city" class="geodir_location_add_listing_chosen" data-location_type="city" name="<?php echo $prefix; ?> city" data-placeholder="<?php _e('Please wait..…', GEODIRLOCATION_TEXTDOMAIN); ?> " <?php if (get_option('geodir_enable_city') == 'selected') { ?> data-ajaxchosen="0" <?php } else { ?> data-ajaxchosen="1" <?php } ?> data-addsearchtermonnorecord="1" data-autoredirect="0" > <?php $selected = ''; $args = array('what' => 'city', 'country_val' => $country, 'region_val' => $region, 'echo' => false, 'format' => array('type' => 'array')); if (get_option('location_dropdown_all')) { $args['no_of_records'] = '10000'; } // set limit to 10 thouseand as this is most browsers limit $location_array = geodir_get_location_array($args); // get country val in case of country search to get selected option ?> <option value='' ><?php _e('Select City', GEODIRLOCATION_TEXTDOMAIN); ?> </option> <?php if (!empty($location_array)) { foreach ($location_array as $locations) { $selected = ''; if (strtolower($city) == strtolower($locations->city)) { $selected = " selected='selected' "; } ?> <option <?php echo $selected; ?> value="<?php echo $locations->city; ?> " ><?php echo ucwords($locations->city); ?> </option> <?php } } ?> </select> </div> <span class="geodir_message_note"><?php _e('Click on above field and type to filter list or add a new city', GEODIRLOCATION_TEXTDOMAIN); ?> </span> <?php if ($is_required) { ?> <span class="geodir_message_error"><?php echo $required_msg; ?> </span> <?php } ?> </div> <?php } } // end of show city if if (get_option('location_neighbourhoods') && $is_admin == '1') { global $plugin_prefix; $neighbourhood_options = geodir_get_neighbourhoods_dl(esc_attr(stripslashes($city)), $neighbourhood, false); $neighbourhood_display = ''; if (trim($neighbourhood_options) == '') { $neighbourhood_display = 'style="display:none;"'; } ?> <div id="geodir_<?php echo $prefix . 'neighbourhood'; ?> _row" class="geodir_form_row geodir_location_add_listing_neighbourhood_chosen_container clearfix" <?php echo $neighbourhood_display; ?> > <label><?php _e('Neighbourhood', GEODIRLOCATION_TEXTDOMAIN); ?> </label> <div class="geodir_location_add_listing_neighbourhood_chosen_div" style="width:57%; float:left;"> <select name="<?php echo $prefix . 'neighbourhood'; ?> " class="chosen_select" option-ajaxChosen="false" > <?php echo $neighbourhood_options; ?> </select> </div> <span class="geodir_message_note"><?php _e('Click on above field and type to filter list', GEODIRLOCATION_TEXTDOMAIN); ?> </span> </div> <?php } ?> </div ><!-- end of geodir_location_add_listing_all_chosen_container --> <?php }
/** * 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'] = ''; } } }
/** * Default settings for location manager. * * @since 1.0.0 * @package GeoDirectory_Location_Manager * * @param array $arr * @return array */ function geodir_location_default_options($arr = array()) { $country_array = geodir_get_countries_array(); $args = array('what' => 'region', 'echo' => false, 'filter_by_non_restricted' => false, 'format' => array('type' => 'array')); $region_obj = (array) geodir_get_location_array($args); $region_array = ''; foreach ($region_obj as $region) { $region_array[$region->region] = $region->region; } $args = array('what' => 'city', 'echo' => false, 'filter_by_non_restricted' => false, 'format' => array('type' => 'array')); $city_obj = (array) geodir_get_location_array($args); $city_array = ''; foreach ($city_obj as $city) { $city_array[$city->city] = $city->city; } $arr[] = array('name' => __('Location Settings', GEODIRLOCATION_TEXTDOMAIN), 'type' => 'no_tabs', 'desc' => '', 'id' => 'location_setting_options'); $arr[] = array('name' => __('Main Navigation Settings', GEODIRLOCATION_TEXTDOMAIN), 'type' => 'sectionstart', 'id' => 'location_setting_switcher_options'); $arr[] = array('name' => __('Show location switcher in menu', GEODIRLOCATION_TEXTDOMAIN), 'desc' => sprintf(__('Show change location navigation in main menu? (untick to disable) If you disable this option, none of the change location link will appear in main navigation.', GEODIRLOCATION_TEXTDOMAIN)), 'id' => 'geodir_show_changelocation_nave', 'std' => '', 'type' => 'checkbox', 'value' => '1'); $arr[] = array('name' => '', 'desc' => __('List drilled-down Regions, Cities.', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_location_switcher_list_mode', 'std' => '', 'type' => 'radio', 'value' => 'drill', 'radiogroup' => 'start'); $arr[] = array('name' => '', 'desc' => __('List all Countries, Regions, Cities.', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_location_switcher_list_mode', 'std' => '', 'type' => 'radio', 'value' => 'all', 'radiogroup' => 'end'); $arr[] = array('type' => 'sectionend', 'id' => 'location_setting_switcher_options'); /*$arr[] = array( 'name' => GD_LOCATION_SETTINGS, 'type' => 'sectionstart', 'id' => 'location_setting_default_options'); $arr[] = array( 'name' => GD_LOCATION_MULTICITY, 'desc' => GD_LOCATION_MULTICITY_DESC, 'id' => 'location_multicity', 'std' => '', 'type' => 'checkbox', 'std' => 'yes' ); $arr[] = array( 'name' => GD_LOCATION_EVERYWHERE, 'desc' => GD_LOCATION_EVERYWHERE_DESC, 'id' => 'location_everywhere', 'std' => '', 'type' => 'checkbox', 'std' => 'yes' ); $arr[] = array( 'type' => 'sectionend', 'id' => 'location_setting_default_options');*/ /* -------- start location settings ----- */ $arr[] = array('name' => GD_LOCATION_SETTINGS, 'type' => 'sectionstart', 'id' => 'geodir_location_setting'); $arr[] = array('name' => __('Home Page Results', GEODIRLOCATION_TEXTDOMAIN), 'desc' => __('Show default location results on home page (First time only, if geodirectory home page is your site home page and user comes to home page).', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_result_by_location', 'std' => 'everywhere', 'type' => 'radio', 'value' => 'default', 'radiogroup' => 'start'); $arr[] = array('name' => '', 'desc' => __('Show everywhere location results on home page (First time only, if geodirectory home page is your site home page and user comes to home page).', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_result_by_location', 'std' => 'everywhere', 'type' => 'radio', 'value' => 'everywhere', 'radiogroup' => 'end'); $arr[] = array('name' => '', 'id' => '', 'type' => 'field_seperator'); $arr[] = array('name' => __('Country', GEODIRLOCATION_TEXTDOMAIN), 'desc' => __('Enable default country (country drop-down will not appear on add listing and location switcher).', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_country', 'std' => 'multi', 'type' => 'radio', 'value' => 'default', 'radiogroup' => 'start'); $arr[] = array('name' => '', 'desc' => __('Enable Multi Countries', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_country', 'std' => 'multi', 'type' => 'radio', 'value' => 'multi', 'radiogroup' => ''); $arr[] = array('name' => '', 'desc' => __('Enable Selected Countries', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_country', 'std' => 'multi', 'type' => 'radio', 'value' => 'selected', 'radiogroup' => 'end'); $arr[] = array('name' => '', 'desc' => __('Only select countries will appear in country drop-down on add listing page and location switcher. Make sure to have default country in your selected countries list for proper site functioning.', GEODIRLOCATION_TEXTDOMAIN), 'tip' => '', 'id' => 'geodir_selected_countries', 'css' => 'min-width:300px;', 'std' => array(), 'type' => 'multiselect', 'placeholder_text' => __('Select Countries', GEODIRLOCATION_TEXTDOMAIN), 'class' => 'chosen_select', 'options' => $country_array); $arr[] = array('name' => '', 'desc' => __('Add everywhere option in location switcher country drop-down.', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_everywhere_in_country_dropdown', 'std' => '1', 'type' => 'checkbox', 'value' => '1'); $arr[] = array('name' => '', 'id' => '', 'type' => 'field_seperator'); /*state*/ $arr[] = array('name' => __('Region', GEODIRLOCATION_TEXTDOMAIN), 'desc' => __('Enable default region (region drop-down will not appear on add listing and location switcher).', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_region', 'std' => 'multi', 'type' => 'radio', 'value' => 'default', 'radiogroup' => 'start'); $arr[] = array('name' => '', 'desc' => __('Enable Multi Regions', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_region', 'std' => 'multi', 'type' => 'radio', 'value' => 'multi', 'radiogroup' => ''); $arr[] = array('name' => '', 'desc' => __('Enable Selected Regions', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_region', 'std' => 'multi', 'type' => 'radio', 'value' => 'selected', 'radiogroup' => 'end'); $arr[] = array('name' => '', 'desc' => __('Only select regions will appear in region drop-down on add listing page and location switcher. Make sure to have default region in your selected regions list for proper site functioning', GEODIRLOCATION_TEXTDOMAIN), 'tip' => '', 'id' => 'geodir_selected_regions', 'css' => 'min-width:300px;', 'std' => array(), 'type' => 'multiselect', 'placeholder_text' => __('Select Regions', GEODIRLOCATION_TEXTDOMAIN), 'class' => 'chosen_select', 'options' => $region_array); $arr[] = array('name' => '', 'desc' => __('Add everywhere option in location switcher region drop-down.', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_everywhere_in_region_dropdown', 'std' => '1', 'type' => 'checkbox', 'value' => '1'); $arr[] = array('name' => '', 'id' => '', 'type' => 'field_seperator'); /*city*/ $arr[] = array('name' => __('City', GEODIRLOCATION_TEXTDOMAIN), 'desc' => __('Enable default city (City drop-down will not appear on add listing and location switcher).', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_city', 'std' => 'multi', 'type' => 'radio', 'value' => 'default', 'radiogroup' => 'start'); $arr[] = array('name' => '', 'desc' => __('Enable Multicity', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_city', 'std' => 'multi', 'type' => 'radio', 'value' => 'multi', 'radiogroup' => ''); $arr[] = array('name' => '', 'desc' => __('Enable Selected City', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_enable_city', 'std' => 'multi', 'type' => 'radio', 'value' => 'selected', 'radiogroup' => 'end'); $arr[] = array('name' => '', 'desc' => __('Only select cities will appear in city drop-down on add listing page and location switcher. Make sure to have default city in your selected cities list for proper site functioning', GEODIRLOCATION_TEXTDOMAIN), 'tip' => '', 'id' => 'geodir_selected_cities', 'css' => 'min-width:300px;', 'std' => array(), 'type' => 'multiselect', 'placeholder_text' => __('Select Cities', GEODIRLOCATION_TEXTDOMAIN), 'class' => 'chosen_select', 'options' => $city_array); $arr[] = array('name' => '', 'desc' => __('Add everywhere option in location switcher city drop-down.', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'geodir_everywhere_in_city_dropdown', 'std' => '1', 'type' => 'checkbox', 'value' => '1'); $arr[] = array('name' => '', 'id' => '', 'type' => 'field_seperator'); $arr[] = array('name' => GD_LOCATION_NEIGHBOURHOODS, 'desc' => GD_LOCATION_NEIGHBOURHOODS_DESC, 'id' => 'location_neighbourhoods', 'std' => '', 'type' => 'checkbox', 'std' => 'yes'); $arr[] = array('type' => 'sectionend', 'id' => 'geodir_location_setting'); $arr[] = array('name' => __('Add listing form settings', GEODIRLOCATION_TEXTDOMAIN), 'type' => 'sectionstart', 'id' => 'geodir_location_setting_add_listing'); $arr[] = array('name' => __('Disable Google address autocomplete?', GEODIRLOCATION_TEXTDOMAIN), 'desc' => __('This will stop the address sugestions when typing in address box on add listing page.', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'location_address_fill', 'std' => '', 'type' => 'checkbox'); $arr[] = array('name' => __('Show all locations in dropdown?', GEODIRLOCATION_TEXTDOMAIN), 'desc' => __('This is usefull if you have a small directory but can break your site if you have many locations', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'location_dropdown_all', 'std' => '', 'type' => 'checkbox'); $arr[] = array('name' => __('Disable set address on map from changing address fields', GEODIRLOCATION_TEXTDOMAIN), 'desc' => __('This is usefull if you have a small directory and you have custom locations or your locations are not known by the Google API and they break the address. (highly recommended not to enable this)', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'location_set_address_disable', 'std' => '', 'type' => 'checkbox'); $arr[] = array('name' => __('Disable move map pin from changing address fields', GEODIRLOCATION_TEXTDOMAIN), 'desc' => __('This is usefull if you have a small directory and you have custom locations or your locations are not known by the Google API and they break the address. (highly recommended not to enable this)', GEODIRLOCATION_TEXTDOMAIN), 'id' => 'location_set_pin_disable', 'std' => '', 'type' => 'checkbox'); $arr[] = array('type' => 'sectionend', 'id' => 'geodir_location_setting_add_listing'); /* -------- end location settings ----- */ $arr = apply_filters('geodir_location_default_options', $arr); return $arr; }
/** * * @global object $wpdb WordPress Database object. * * @param null $args * @return string */ function geodir_location_tab_switcher($args = null) { $switcher = !empty($args) && isset($args['addSearchTermOnNorecord']) ? true : false; if (get_option('geodir_enable_country') != 'default' || get_option('geodir_enable_region') != 'default' || get_option('geodir_enable_city') != 'default') { $defaults = array('echo' => true, 'addSearchTermOnNorecord' => 0, 'autoredirect' => false); $args = wp_parse_args($args, $defaults); global $wpdb; // Options $echo = $args['echo']; $addSearchTermOnNorecord = $args['addSearchTermOnNorecord']; $autoredirect = $args['autoredirect']; $output = ''; $selected = ''; $location_list = ''; $country_div = ''; $region_div = ''; $city_div = ''; $onchange = ''; $what_is_current_location = geodir_what_is_current_location(); $what_is_current_location_div = $what_is_current_location . '_div'; if ($what_is_current_location != '') { ${$what_is_current_location_div} = 'gd-tab-active'; } else { $what_is_current_location = apply_filters('geodir_location_switcher_default_tab', 'city'); $what_is_current_location_div = $what_is_current_location . '_div'; ${$what_is_current_location_div} = 'gd-tab-active'; } $location_value = ''; if ($autoredirect === '0') { } else { $location_value = geodir_get_location_link('base'); $onchange = ' onchange="window.location.href=this.value" '; $autoredirect = '1'; } $base_location = geodir_get_location_link('base'); $current_location_array = array(); $selected = ''; $country_val = ''; $region_val = ''; $city_val = ''; $country_val = geodir_get_current_location(array('what' => 'country', 'echo' => false)); $region_val = geodir_get_current_location(array('what' => 'region', 'echo' => false)); $city_val = geodir_get_current_location(array('what' => 'city', 'echo' => false)); $item_set_selected = false; $output .= '<div class="geodir_location_tab_container" >'; $output .= '<dl class="geodir_location_tabs_head">'; if (get_option('geodir_enable_country') != 'default') { $output .= '<dd data-location="country" class="geodir_location_tabs ' . $country_div . '" ><a href="javascript:void(0)">' . __('Country', GEODIRLOCATION_TEXTDOMAIN) . '</a></dd>'; } if (get_option('geodir_enable_region') != 'default') { $output .= '<dd data-location="region" class="geodir_location_tabs ' . $region_div . '" ><a href="javascript:void(0)">' . __('Region', GEODIRLOCATION_TEXTDOMAIN) . '</a></dd>'; } if (get_option('geodir_enable_city') != 'default') { $output .= '<dd data-location="city" class="geodir_location_tabs ' . $city_div . ' " ><a href="javascript:void(0)">' . __('City', GEODIRLOCATION_TEXTDOMAIN) . '</a></dd>'; } $output .= '</dl>'; $output .= '<input type="hidden" class="selected_location" value="city" /><div style="clear:both;"></div>'; $output .= '<div class="geodir_location_sugestion">'; $output .= '<select class="geodir_location_switcher_chosen" name="gd_location" data-placeholder="' . __('Please wait..…', GEODIRLOCATION_TEXTDOMAIN) . '" data-addSearchTermOnNorecord="' . $addSearchTermOnNorecord . '" data-autoredirect="' . $autoredirect . '" ' . $onchange . ' data-showeverywhere="1" >'; $location_switcher_list_mode = get_option('geodir_location_switcher_list_mode'); if (empty($location_switcher_list_mode)) { $location_switcher_list_mode = 'drill'; } if ($location_switcher_list_mode == 'drill') { $args = array('what' => $what_is_current_location, 'country_val' => strtolower($what_is_current_location) == 'region' || strtolower($what_is_current_location) == 'city' ? $country_val : '', 'region_val' => strtolower($what_is_current_location) == 'city' ? $region_val : '', 'echo' => false, 'no_of_records' => '5', 'format' => array('type' => 'array')); } else { $args = array('what' => $what_is_current_location, 'echo' => false, 'no_of_records' => '5', 'format' => array('type' => 'array')); } if ($what_is_current_location == 'country' && $country_val != '') { $args_current_location = array('what' => $what_is_current_location, 'country_val' => $country_val, 'compare_operator' => '=', 'no_of_records' => '1', 'echo' => false, 'format' => array('type' => 'array')); $current_location_array = geodir_get_location_array($args_current_location, $switcher); } if ($what_is_current_location == 'region' && $region_val != '') { $args_current_location = array('what' => $what_is_current_location, 'country_val' => $country_val, 'region_val' => $region_val, 'compare_operator' => '=', 'no_of_records' => '1', 'echo' => false, 'format' => array('type' => 'array')); $current_location_array = geodir_get_location_array($args_current_location, $switcher); } if ($what_is_current_location == 'city' && $city_val != '') { $args_current_location = array('what' => $what_is_current_location, 'country_val' => $country_val, 'region_val' => $region_val, 'city_val' => $city_val, 'compare_operator' => '=', 'no_of_records' => '1', 'echo' => false, 'format' => array('type' => 'array')); $current_location_array = geodir_get_location_array($args_current_location, $switcher); } $location_array = geodir_get_location_array($args, $switcher); // get country val in case of country search to get selected option if (get_option('geodir_everywhere_in_' . $what_is_current_location . '_dropdown')) { $output .= '<option value="' . $base_location . '">' . __('Everywhere', GEODIRLOCATION_TEXTDOMAIN) . '</option>'; } $selected = ''; if (!empty($location_array)) { foreach ($location_array as $locations) { $selected = ''; $with_parent = isset($locations->label) ? true : false; switch ($what_is_current_location) { case 'country': if (strtolower($country_val) == strtolower($locations->country)) { $selected = 'selected="selected"'; } $locations->country = __($locations->country, GEODIRECTORY_TEXTDOMAIN); break; case 'region': $country_iso2 = geodir_location_get_iso2($country_val); $country_iso2 = $country_iso2 != '' ? $country_iso2 : $country_val; $with_parent = $with_parent && strtolower($region_val . ', ' . $country_iso2) == strtolower($locations->label) ? true : false; if (strtolower($region_val) == strtolower($locations->region) || $with_parent) { $selected = 'selected="selected"'; } break; case 'city': $with_parent = $with_parent && strtolower($city_val . ', ' . $region_val) == strtolower($locations->label) ? true : false; if (strtolower($city_val) == strtolower($locations->city) || $with_parent) { $selected = 'selected="selected"'; } break; } $output .= '<option value="' . geodir_location_permalink_url($base_location . $locations->location_link) . '" ' . $selected . '>' . ucwords($locations->{$what_is_current_location}) . '</option>'; if (!$item_set_selected && $selected != '') { $item_set_selected = true; } } } if (!empty($current_location_array) && !$item_set_selected) { foreach ($current_location_array as $current_location) { $selected = ''; $with_parent = isset($current_location->label) ? true : false; switch ($what_is_current_location) { case 'country': if (strtolower($country_val) == strtolower($current_location->country)) { $selected = 'selected="selected"'; } $current_location->country = __($current_location->country, GEODIRECTORY_TEXTDOMAIN); break; case 'region': $country_iso2 = geodir_location_get_iso2($country_val); $country_iso2 = $country_iso2 != '' ? $country_iso2 : $country_val; $with_parent = $with_parent && strtolower($region_val . ', ' . $country_iso2) == strtolower($current_location->label) ? true : false; if (strtolower($region_val) == strtolower($current_location->region) || $with_parent) { $selected = 'selected="selected"'; } break; case 'city': $with_parent = $with_parent && strtolower($city_val . ', ' . $region_val) == strtolower($current_location->label) ? true : false; if (strtolower($city_val) == strtolower($current_location->city) || $with_parent) { $selected = 'selected="selected"'; } break; } $output .= '<option value="' . geodir_location_permalink_url($base_location . $current_location->location_link) . '" ' . $selected . '>' . ucwords($current_location->{$what_is_current_location}) . '</option>'; } } $output .= '</select>'; $output .= "</div>"; $output .= '</div>'; if ($echo) { echo $output; } else { return $output; } } }