/**
  * @global object $wpdb WordPress Database object.
  *
  * @param array $args
  * @param array $instance
  * @return null
  */
 public function widget($args, $instance)
 {
     global $wpdb, $wp;
     extract($args, EXTR_SKIP);
     $gd_country = isset($wp->query_vars['gd_country']) ? $wp->query_vars['gd_country'] : '';
     $gd_region = isset($wp->query_vars['gd_region']) ? $wp->query_vars['gd_region'] : '';
     $gd_city = isset($wp->query_vars['gd_city']) ? $wp->query_vars['gd_city'] : '';
     $location_title = '';
     //$seo_title = '';
     $seo_desc = '';
     if ($gd_city) {
         $info = geodir_city_info_by_slug($gd_city, $gd_country, $gd_region);
         if (!empty($info)) {
             $location_title = $info->city;
             $seo_title = $info->city_meta;
             $seo_desc = $info->city_desc;
         }
     } else {
         if (!$gd_city && $gd_region) {
             $info = geodir_location_seo_by_slug($gd_region, 'region', $gd_country);
             if (!empty($info)) {
                 //$seo_title = $info->seo_title;
                 $seo_desc = $info->seo_desc;
                 $location_title = $wpdb->get_var($wpdb->prepare("SELECT region FROM " . POST_LOCATION_TABLE . " WHERE region_slug!='' AND region_slug=%s ORDER BY location_id ASC", array($gd_region)));
             }
         } else {
             if (!$gd_city && !$gd_region && $gd_country) {
                 $info = geodir_location_seo_by_slug($gd_country, 'country');
                 if (!empty($info)) {
                     //$seo_title = $info->seo_title;
                     $seo_desc = $info->seo_desc;
                     $location_title = $wpdb->get_var($wpdb->prepare("SELECT country FROM " . POST_LOCATION_TABLE . " WHERE country_slug!='' AND country_slug=%s ORDER BY location_id ASC", array($gd_country)));
                 }
             }
         }
     }
     $location_desc = $seo_desc;
     if ($location_desc == '') {
         return NULL;
     }
     $title = empty($instance['title']) ? __('Location Description', GEODIRECTORY_TEXTDOMAIN) : apply_filters('geodir_location_description_widget_title', __($instance['title'], GEODIRECTORY_TEXTDOMAIN));
     $title = str_replace('%s', $location_title, $title);
     $title = str_replace('%location%', $location_title, $title);
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . __($title) . $after_title;
     }
     $location_desc = stripslashes_deep($location_desc);
     echo '<div class="geodir-category-list-in clearfix geodir-location-desc">' . $location_desc . '</div>';
     echo $after_widget;
 }
/**
 *
 * @global object $wpdb WordPress Database object.
 *
 * @param $atts
 * @return null|string
 *
 * @global object $wp WordPress object.
 */
function geodir_sc_location_description($atts)
{
    global $wpdb, $wp;
    ob_start();
    $gd_country = isset($wp->query_vars['gd_country']) ? $wp->query_vars['gd_country'] : '';
    $gd_region = isset($wp->query_vars['gd_region']) ? $wp->query_vars['gd_region'] : '';
    $gd_city = isset($wp->query_vars['gd_city']) ? $wp->query_vars['gd_city'] : '';
    $location_title = '';
    $seo_title = '';
    $seo_desc = '';
    if ($gd_city) {
        $info = geodir_city_info_by_slug($gd_city, $gd_country, $gd_region);
        if (!empty($info)) {
            $location_title = $info->city;
            $seo_title = $info->city_meta;
            $seo_desc = $info->city_desc;
        }
    } else {
        if (!$gd_city && $gd_region) {
            $info = geodir_location_seo_by_slug($gd_region, 'region', $gd_country);
            if (!empty($info)) {
                $seo_title = $info->seo_title;
                $seo_desc = $info->seo_desc;
                $location_title = $wpdb->get_var($wpdb->prepare("SELECT region FROM " . POST_LOCATION_TABLE . " WHERE region_slug!='' AND region_slug=%s ORDER BY location_id ASC", array($gd_region)));
            }
        } else {
            if (!$gd_city && !$gd_region && $gd_country) {
                $info = geodir_location_seo_by_slug($gd_country, 'country');
                if (!empty($info)) {
                    $seo_title = $info->seo_title;
                    $seo_desc = $info->seo_desc;
                    $location_title = $wpdb->get_var($wpdb->prepare("SELECT country FROM " . POST_LOCATION_TABLE . " WHERE country_slug!='' AND country_slug=%s ORDER BY location_id ASC", array($gd_country)));
                }
            }
        }
    }
    $location_desc = $seo_desc;
    if ($location_desc == '') {
        return null;
    }
    $location_desc = stripslashes_deep($location_desc);
    echo '<div class="geodir-category-list-in clearfix geodir-location-desc">' . $location_desc . '</div>';
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
/**
 * Add location information to the meta description.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @global object $wpdb WordPress Database object.
 * @global object $wp WordPress object.
 *
 * @param string $seo_desc Meta description text.
 * @return null|string Altered meta desc.
 */
function geodir_set_location_meta_desc($seo_desc = '')
{
    global $wpdb, $wp;
    $gd_country = get_query_var('gd_country');
    $gd_region = get_query_var('gd_region');
    $gd_city = get_query_var('gd_city');
    if ($gd_city) {
        $info = geodir_city_info_by_slug($gd_city, $gd_country, $gd_region);
        if (!empty($info)) {
            $seo_desc .= $info->city_meta != '' ? $info->city_meta : $info->city_meta;
        }
    } else {
        if (!$gd_city && $gd_region) {
            $info = geodir_location_seo_by_slug($gd_region, 'region', $gd_country);
            if (!empty($info)) {
                $seo_desc .= $info->seo_desc != '' ? $info->seo_desc : $info->seo_title;
            }
        } else {
            if (!$gd_city && !$gd_region && $gd_country) {
                $info = geodir_location_seo_by_slug($gd_country, 'country');
                if (!empty($info)) {
                    $seo_desc .= $info->seo_desc != '' ? $info->seo_desc : $info->seo_title;
                }
            }
        }
    }
    $location_desc = $seo_desc;
    if ($location_desc == '') {
        return NULL;
    } else {
        return $location_desc;
    }
}