/** * 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>'; } } }
/** * Adds meta keywords and description for SEO. * * @since 1.0.0 * @since 1.5.4 Modified to replace %location% from meta when Yoast SEO plugin active. * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global object $post The current post object. * @global object $wp_query WordPress Query object. * @global array $geodir_addon_list List of active GeoDirectory extensions. */ function geodir_add_meta_keywords() { global $wp, $post, $wp_query, $wpdb, $geodir_addon_list; $is_geodir_page = geodir_is_geodir_page(); if (!$is_geodir_page) { return; } // if non GD page, bail $use_gd_meta = true; if (class_exists('WPSEO_Frontend') || class_exists('All_in_One_SEO_Pack')) { $use_gd_meta = false; if (geodir_is_page('search')) { $use_gd_meta = true; } } if (!$use_gd_meta) { return; } // bail if Yoast Wordpress SEO or All_in_One_SEO_Pack active. $current_term = $wp_query->get_queried_object(); $all_postypes = geodir_get_posttypes(); $geodir_taxonomies = geodir_get_taxonomies('', true); $meta_desc = ''; $meta_key = ''; if (isset($current_term->ID) && $current_term->ID == geodir_location_page_id()) { /** * Filter SEO meta location description. * * @since 1.0.0 */ $meta_desc = apply_filters('geodir_seo_meta_location_description', ''); $meta_desc .= ''; } if (have_posts() && is_single() or is_page()) { while (have_posts()) { the_post(); if (has_excerpt()) { $out_excerpt = strip_tags(strip_shortcodes(get_the_excerpt())); if (empty($out_excerpt)) { $out_excerpt = strip_tags(do_shortcode(get_the_excerpt())); } $out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", $out_excerpt); } else { $out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", $post->post_content); $out_excerpt = strip_tags(strip_shortcodes($out_excerpt)); if (empty($out_excerpt)) { $out_excerpt = strip_tags(do_shortcode($out_excerpt)); // parse short code from content } $out_excerpt = trim(wp_trim_words($out_excerpt, 35, ''), '.!?,;:-'); } $meta_desc .= $out_excerpt; } } elseif ((is_category() || is_tag()) && isset($current_term->taxonomy) && in_array($current_term->taxonomy, $geodir_taxonomies)) { if (is_category()) { $meta_desc .= __("Posts related to Category:", 'geodirectory') . " " . ucfirst(single_cat_title("", FALSE)); } elseif (is_tag()) { $meta_desc .= __("Posts related to Tag:", 'geodirectory') . " " . ucfirst(single_tag_title("", FALSE)); } } elseif (isset($current_term->taxonomy) && in_array($current_term->taxonomy, $geodir_taxonomies)) { $meta_desc .= isset($current_term->description) ? $current_term->description : ''; } $geodir_post_type = geodir_get_current_posttype(); $geodir_post_type_info = get_post_type_object($geodir_post_type); $geodir_is_page_listing = geodir_is_page('listing') ? true : false; $category_taxonomy = geodir_get_taxonomies($geodir_post_type); $tag_taxonomy = geodir_get_taxonomies($geodir_post_type, true); $geodir_is_category = isset($category_taxonomy[0]) && get_query_var($category_taxonomy[0]) ? get_query_var($category_taxonomy[0]) : false; $geodir_is_tag = isset($tag_taxonomy[0]) && get_query_var($tag_taxonomy[0]) ? true : false; $geodir_is_search = geodir_is_page('search') ? true : false; $geodir_is_location = geodir_is_page('location') ? true : false; $geodir_location_manager = isset($geodir_addon_list['geodir_location_manager']) && ($geodir_addon_list['geodir_location_manager'] = 'yes' ? true : false); $godir_location_terms = geodir_get_current_location_terms('query_vars'); $gd_city = $geodir_location_manager && isset($godir_location_terms['gd_city']) ? $godir_location_terms['gd_city'] : NULL; $gd_region = $geodir_location_manager && isset($godir_location_terms['gd_region']) ? $godir_location_terms['gd_region'] : NULL; $gd_country = $geodir_location_manager && isset($godir_location_terms['gd_country']) ? $godir_location_terms['gd_country'] : NULL; $replace_location = __('Everywhere', 'geodirectory'); $location_id = NULL; if ($geodir_location_manager) { $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 = (int) $wpdb->get_var($sql); $location_type = geodir_what_is_current_location(); if ($location_type == 'city') { $replace_location = geodir_get_current_location(array('what' => 'city', 'echo' => false)); } elseif ($location_type == 'region') { $replace_location = geodir_get_current_location(array('what' => 'region', 'echo' => false)); } elseif ($location_type == 'country') { $replace_location = geodir_get_current_location(array('what' => 'country', 'echo' => false)); $replace_location = __($replace_location, 'geodirectory'); } $country = get_query_var('gd_country'); $region = get_query_var('gd_region'); $city = get_query_var('gd_city'); $current_location = ''; if ($country != '') { $current_location = get_actual_location_name('country', $country, true); } if ($region != '') { $current_location = get_actual_location_name('region', $region); } if ($city != '') { $current_location = get_actual_location_name('city', $city); } $replace_location = $current_location != '' ? $current_location : $replace_location; } $geodir_meta_keys = ''; $geodir_meta_desc = ''; if ($is_geodir_page && !empty($geodir_post_type_info)) { if ($geodir_is_page_listing || $geodir_is_search || geodir_is_page('add-listing')) { $geodir_meta_keys = isset($geodir_post_type_info->seo['meta_keyword']) && $geodir_post_type_info->seo['meta_keyword'] != '' ? $geodir_post_type_info->seo['meta_keyword'] : $geodir_meta_keys; $geodir_meta_desc = isset($geodir_post_type_info->description) ? $geodir_post_type_info->description : $geodir_meta_desc; $geodir_meta_desc = isset($geodir_post_type_info->seo['meta_description']) && $geodir_post_type_info->seo['meta_description'] != '' ? $geodir_post_type_info->seo['meta_description'] : $geodir_meta_desc; if ($geodir_is_category) { $category = $geodir_is_category ? get_term_by('slug', $geodir_is_category, $category_taxonomy[0]) : NULL; if (isset($category->term_id) && !empty($category->term_id)) { $category_id = $category->term_id; $category_desc = trim($category->description) != '' ? trim($category->description) : get_tax_meta($category_id, 'ct_cat_top_desc', false, $geodir_post_type); if ($location_id) { $option_name = 'geodir_cat_loc_' . $geodir_post_type . '_' . $category_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) { $option_name = 'geodir_cat_loc_' . $geodir_post_type . '_' . $category_id . '_' . $location_id; $option = get_option($option_name); $category_desc = isset($option['gd_cat_loc_desc']) && trim($option['gd_cat_loc_desc']) != '' ? trim($option['gd_cat_loc_desc']) : $category_desc; } } $geodir_meta_desc = __("Posts related to Category:", 'geodirectory') . " " . ucfirst(single_cat_title("", FALSE)) . '. ' . $category_desc; } } else { if ($geodir_is_tag) { $geodir_meta_desc = __("Posts related to Tag:", 'geodirectory') . " " . ucfirst(single_tag_title("", FALSE)) . '. ' . $geodir_meta_desc; } } } } $gd_page = ''; if (geodir_is_page('home')) { $gd_page = 'home'; $meta_desc = get_option('geodir_meta_desc_homepage') ? get_option('geodir_meta_desc_homepage') : $meta_desc; } elseif (geodir_is_page('detail')) { $gd_page = 'detail'; $meta_desc = get_option('geodir_meta_desc_detail') ? get_option('geodir_meta_desc_detail') : $meta_desc; } elseif (geodir_is_page('pt')) { $gd_page = 'pt'; $meta_desc = get_option('geodir_meta_desc_pt') ? get_option('geodir_meta_desc_pt') : $meta_desc; } elseif (geodir_is_page('listing')) { $gd_page = 'listing'; $meta_desc = get_option('geodir_meta_desc_listing') ? get_option('geodir_meta_desc_listing') : $meta_desc; } elseif (geodir_is_page('location')) { $gd_page = 'location'; $meta_desc = get_option('geodir_meta_desc_location') ? get_option('geodir_meta_desc_location') : $meta_desc; $meta_desc = apply_filters('geodir_seo_meta_location_description', $meta_desc); } elseif (geodir_is_page('search')) { $gd_page = 'search'; $meta_desc = get_option('geodir_meta_desc_search') ? get_option('geodir_meta_desc_search') : $meta_desc; } elseif (geodir_is_page('add-listing')) { $gd_page = 'add-listing'; $meta_desc = get_option('geodir_meta_desc_add-listing') ? get_option('geodir_meta_desc_add-listing') : $meta_desc; } elseif (geodir_is_page('author')) { $gd_page = 'author'; $meta_desc = get_option('geodir_meta_desc_author') ? get_option('geodir_meta_desc_author') : $meta_desc; } elseif (geodir_is_page('login')) { $gd_page = 'login'; $meta_desc = get_option('geodir_meta_desc_login') ? get_option('geodir_meta_desc_login') : $meta_desc; } elseif (geodir_is_page('listing-success')) { $gd_page = 'listing-success'; $meta_desc = get_option('geodir_meta_desc_listing-success') ? get_option('geodir_meta_desc_listing-success') : $meta_desc; } /* $geodir_meta_desc = $geodir_meta_desc != '' ? $geodir_meta_desc : $meta_desc; if ($geodir_meta_desc != '') { $geodir_meta_desc = strip_tags($geodir_meta_desc); $geodir_meta_desc = esc_html($geodir_meta_desc); $geodir_meta_desc = wp_html_excerpt($geodir_meta_desc, 1000, '.'); $geodir_meta_desc = isset($replace_location) ? str_replace('%location%', $replace_location, $geodir_meta_desc) : $geodir_meta_desc; $meta_desc = $geodir_meta_desc != '' ? $geodir_meta_desc : $meta_desc; } */ if ($meta_desc) { $meta_desc = stripslashes_deep($meta_desc); /** * Filter page description to replace variables. * * @since 1.5.4 * @param string $title The page description including variables. * @param string $gd_page The GeoDirectory page type if any. */ $meta_desc = apply_filters('geodir_seo_meta_description_pre', __($meta_desc, 'geodirectory'), $gd_page, ''); /** * Filter SEO meta description. * * @since 1.0.0 * @param string $meta_desc Meta description content. */ echo apply_filters('geodir_seo_meta_description', '<meta name="description" content="' . $meta_desc . '" />', $meta_desc); } // meta keywords if (isset($post->post_type) && in_array($post->post_type, $all_postypes)) { $place_tags = wp_get_post_terms($post->ID, $post->post_type . '_tags', array("fields" => "names")); $place_cats = wp_get_post_terms($post->ID, $post->post_type . 'category', array("fields" => "names")); $meta_key .= implode(", ", array_merge((array) $place_cats, (array) $place_tags)); } else { $posttags = get_the_tags(); if ($posttags) { foreach ($posttags as $tag) { $meta_key .= $tag->name . ' '; } } else { $tags = get_tags(array('orderby' => 'count', 'order' => 'DESC')); $xt = 1; foreach ($tags as $tag) { if ($xt <= 20) { $meta_key .= $tag->name . ", "; } $xt++; } } } $meta_key = $meta_key != '' ? rtrim(trim($meta_key), ",") : $meta_key; $geodir_meta_keys = $geodir_meta_keys != '' ? $meta_key != '' ? $meta_key . ', ' . $geodir_meta_keys : $geodir_meta_keys : $meta_key; if ($geodir_meta_keys != '') { $geodir_meta_keys = strip_tags($geodir_meta_keys); $geodir_meta_keys = esc_html($geodir_meta_keys); $geodir_meta_keys = geodir_strtolower($geodir_meta_keys); $geodir_meta_keys = wp_html_excerpt($geodir_meta_keys, 1000, ''); $geodir_meta_keys = str_replace('%location%', $replace_location, $geodir_meta_keys); $meta_key = rtrim(trim($geodir_meta_keys), ","); } if ($meta_key) { $meta_key = stripslashes_deep($meta_key); /** * Filter SEO meta keywords. * * @since 1.0.0 * @param string $meta_desc Meta keywords. */ echo apply_filters('geodir_seo_meta_keywords', '<meta name="keywords" content="' . $meta_key . '" />', $meta_key); } }
/** * * @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; } } }