/**
 * Redirect url after sharing location.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @global object $wp_query WordPress Query object.
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 *
 * @param string $redirect_url Old redirect url
 * @return bool|null|string Filtered redirect url.
 */
function geodir_location_manager_share_location($redirect_url)
{
    global $wp_query, $plugin_prefix;
    if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'share_location') {
        if (isset($_REQUEST['error']) && $_REQUEST['error']) {
            $_SESSION['gd_location_shared'] = true;
            return;
        }
        global $wpdb;
        // ask user to share his location only one time.
        $_SESSION['gd_location_shared'] = true;
        $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
        if (get_option('geodir_search_dist') != '') {
            $dist = get_option('geodir_search_dist');
        } else {
            $dist = '25000';
        }
        if (get_option('geodir_near_me_dist') != '') {
            $dist2 = get_option('geodir_near_me_dist');
        } else {
            $dist2 = '200';
        }
        if (isset($_REQUEST['lat']) && isset($_REQUEST['long'])) {
            $mylat = (double) stripslashes(ucfirst($_REQUEST['lat']));
            $mylon = (double) stripslashes(ucfirst($_REQUEST['long']));
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
            $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip));
            $mylat = stripslashes(ucfirst($addr_details['geoplugin_latitude']));
            $mylon = stripslashes(ucfirst($addr_details['geoplugin_longitude']));
        }
        $_SESSION['user_lat'] = $mylat;
        $_SESSION['user_lon'] = $mylon;
        $lon1 = $mylon - $dist2 / abs(cos(deg2rad($mylat)) * 69);
        $lon2 = $mylon + $dist2 / abs(cos(deg2rad($mylat)) * 69);
        $lat1 = $mylat - $dist2 / 69;
        $lat2 = $mylat + $dist2 / 69;
        $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : '';
        $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : '';
        $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : '';
        $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : '';
        $near_location_info = $wpdb->get_results($wpdb->prepare("SELECT *,CONVERT((%s * 2 * ASIN(SQRT( POWER(SIN((%s - (" . $plugin_prefix . "gd_place_detail.post_latitude)) * pi()/180 / 2), 2) +COS(%s * pi()/180) * COS( (" . $plugin_prefix . "gd_place_detail.post_latitude) * pi()/180) *POWER(SIN((%s - " . $plugin_prefix . "gd_place_detail.post_longitude) * pi()/180 / 2), 2) ))),UNSIGNED INTEGER) as distance FROM " . $plugin_prefix . "gd_place_detail WHERE (" . $plugin_prefix . "gd_place_detail.post_latitude IS NOT NULL AND " . $plugin_prefix . "gd_place_detail.post_latitude!='') AND " . $plugin_prefix . "gd_place_detail.post_latitude between {$rlat1} and {$rlat2}  AND " . $plugin_prefix . "gd_place_detail.post_longitude between {$rlon1} and {$rlon2} ORDER BY distance ASC LIMIT 1", $DistanceRadius, $mylat, $mylat, $mylon));
        if (!empty($near_location_info)) {
            $redirect_url = geodir_get_location_link('base') . 'me';
            return $redirect_url;
            die;
        }
        $location_info = $wpdb->get_results($wpdb->prepare("SELECT *,CONVERT((%s * 2 * ASIN(SQRT( POWER(SIN((%s - (" . POST_LOCATION_TABLE . ".city_latitude)) * pi()/180 / 2), 2) +COS(%s * pi()/180) * COS( (" . POST_LOCATION_TABLE . ".city_latitude) * pi()/180) *POWER(SIN((%s - " . POST_LOCATION_TABLE . ".city_longitude) * pi()/180 / 2), 2) ))),UNSIGNED INTEGER) as distance FROM " . POST_LOCATION_TABLE . " ORDER BY distance ASC LIMIT 1", $DistanceRadius, $mylat, $mylat, $mylon));
        if (!empty($location_info)) {
            $location_info = end($location_info);
            $location_array = array();
            $location_array['gd_country'] = $location_info->country_slug;
            $location_array['gd_region'] = $location_info->region_slug;
            $location_array['gd_city'] = $location_info->city_slug;
            $base = rtrim(geodir_get_location_link('base'), '/');
            $redirect_url = $base . '/' . $location_info->country_slug . '/' . $location_info->region_slug . '/' . $location_info->city_slug;
            $redirect_url = geodir_location_permalink_url($redirect_url);
        } else {
            $redirect_url = geodir_get_location_link('base');
        }
        return $redirect_url;
        die;
    }
}
Ejemplo n.º 2
0
 /**
  * Calculate the great circle distance between two points identified by longitude and latitude.
  *
  * @since 1.0.0
  * @package GeoDirectory
  * @param array $point1 Latitude and Longitude of point 1.
  * @param array $point2 Latitude and Longitude of point 2.
  * @param string $uom Unit of measurement.
  * @return float The distance.
  */
 function geodir_calculateDistanceFromLatLong($point1, $point2, $uom = 'km')
 {
     //	Use Haversine formula to calculate the great circle distance between two points identified by longitude and latitude
     $earthMeanRadius = geodir_getDistanceRadius($uom);
     $deltaLatitude = deg2rad($point2['latitude'] - $point1['latitude']);
     $deltaLongitude = deg2rad($point2['longitude'] - $point1['longitude']);
     $a = sin($deltaLatitude / 2) * sin($deltaLatitude / 2) + cos(deg2rad($point1['latitude'])) * cos(deg2rad($point2['latitude'])) * sin($deltaLongitude / 2) * sin($deltaLongitude / 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     $distance = $earthMeanRadius * $c;
     return $distance;
 }
Ejemplo n.º 3
0
/**
 * Listing search where filter.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @global string $table Listing table name.
 * @param string $where The where query string.
 * @return string Modified where query string.
 */
function searching_filter_where($where)
{
    global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s, $s_A, $s_SA;
    global $search_term;
    $search_term = 'OR';
    $search_term = 'AND';
    $geodir_custom_search = '';
    $category_search_range = '';
    if (is_single() && get_query_var('post_type')) {
        return $where;
    }
    if (is_tax()) {
        return $where;
    }
    $s = trim($s);
    $where = '';
    $better_search_terms = '';
    $better_search = array();
    if (!empty($s_SA)) {
        foreach ($s_SA as $s_term) {
            //$s_term = esc_attr($s_term);
            //$better_search[] = " OR $wpdb->posts.post_title LIKE\"%$s_term%\" ";
            $better_search[] = " OR ( {$wpdb->posts}.post_title LIKE \"{$s_term}\" OR {$wpdb->posts}.post_title LIKE \"{$s_term}%\" OR {$wpdb->posts}.post_title LIKE \"% {$s_term}%\" ) ";
        }
    }
    if (is_array($better_search)) {
        $better_search_terms = implode(' ', $better_search);
    }
    $better_search_terms = '';
    if (isset($_REQUEST['stype'])) {
        $post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype']));
    } else {
        $post_types = 'gd_place';
    }
    if ($s != '') {
        $keywords = explode(" ", $s);
        if (is_array($keywords) && ($klimit = get_option('geodir_search_word_limit'))) {
            foreach ($keywords as $kkey => $kword) {
                if (mb_strlen($kword, 'UTF-8') <= $klimit) {
                    unset($keywords[$kkey]);
                }
            }
        }
        if (!empty($keywords)) {
            foreach ($keywords as $keyword) {
                $keyword = trim($keyword);
                if ($keyword != '') {
                    //$better_search_terms .= ' OR ' . $wpdb->posts . '.post_title LIKE "%' . $adv_search_val . '%"';
                    $better_search_terms .= ' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )';
                }
            }
        }
    }
    /* get taxonomy */
    $taxonomies = geodir_get_taxonomies($post_types, true);
    if ($taxonomies) {
        $taxonomies = implode("','", $taxonomies);
        $taxonomies = "'" . $taxonomies . "'";
    } else {
        $taxonomies = '';
    }
    $content_where = $terms_where = '';
    if ($s != '') {
        /**
         * Filter the search query content where values.
         *
         * @since 1.5.0
         * @package GeoDirectory
         * @param string $content_where The query values, default: `" OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\") "`.
         */
        $content_where = apply_filters("geodir_search_content_where", " OR ({$wpdb->posts}.post_content LIKE \"{$s}\" OR {$wpdb->posts}.post_content LIKE \"{$s}%\" OR {$wpdb->posts}.post_content LIKE \"% {$s}%\") ");
        /**
         * Filter the search query term values.
         *
         * @since 1.5.0
         * @package GeoDirectory
         * @param string $terms_where The separator, default: `" AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "`.
         */
        $terms_where = apply_filters("geodir_search_terms_where", " AND ({$wpdb->terms}.name LIKE \"{$s}\" OR {$wpdb->terms}.name LIKE \"{$s}%\" OR {$wpdb->terms}.name LIKE \"% {$s}%\" OR {$wpdb->terms}.name IN ({$s_A})) ");
    }
    if ($snear != '') {
        if (isset($_SESSION['near_me_range']) && is_numeric($_SESSION['near_me_range']) && !isset($_REQUEST['sdist'])) {
            $dist = $_SESSION['near_me_range'];
        }
        $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69);
        $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69);
        $lat1 = $mylat - $dist / 69;
        $lat2 = $mylat + $dist / 69;
        $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : '';
        $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : '';
        $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : '';
        $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : '';
        $where .= " AND ( ( {$wpdb->posts}.post_title LIKE \"{$s}\" {$better_search_terms})\n\t\t\t                    {$content_where} \n\t\t\t\t\t\t\t\tOR ({$wpdb->posts}.ID IN( \n\t\t\t\t\t\t\t\t\t\tSELECT {$wpdb->term_relationships}.object_id as post_id \n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->term_taxonomy},  {$wpdb->terms}, {$wpdb->term_relationships} \n\t\t\t\t\t\t\t\t\t\tWHERE {$wpdb->term_taxonomy}.term_id =  {$wpdb->terms}.term_id\n\t\t\t\t\t\t\t\t\t\tAND {$wpdb->term_relationships}.term_taxonomy_id =  {$wpdb->term_taxonomy}.term_taxonomy_id\n\t\t\t\t\t\t\t\t\t\tAND {$wpdb->term_taxonomy}.taxonomy in ({$taxonomies})\n\t\t\t\t\t\t\t\t\t\t{$terms_where} \n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\t)\n\t\t\t\t\t\tAND {$wpdb->posts}.post_type in ('{$post_types}')\n\t\t\t\t\t\tAND ({$wpdb->posts}.post_status = 'publish')\n\t\t\t\t\t\tAND ( " . $table . ".post_latitude between {$rlat1} and {$rlat2} )\n\t\t\t\t\t\tAND ( " . $table . ".post_longitude between {$rlon1} and {$rlon2} ) ";
        if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') {
            $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1'));
            $where .= " AND CONVERT((" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS({$mylat}) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS({$mylat}) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(({$mylon} - " . $table . ".post_longitude) * pi()/180 / 2), 2) ))),DECIMAL(64,4)) <= " . $dist;
        }
    } else {
        $where .= " AND (\t( {$wpdb->posts}.post_title LIKE \"{$s}\" {$better_search_terms})\n                            {$content_where}  \n\t\t\t\t\t\t\tOR ( {$wpdb->posts}.ID IN(\t\n\t\t\t\t\t\t\t\t\tSELECT {$wpdb->term_relationships}.object_id as post_id                     \n\t\t\t\t\t\t\t\t\tFROM {$wpdb->term_taxonomy},  {$wpdb->terms}, {$wpdb->term_relationships}\n\t\t\t\t\t\t\t\tWHERE {$wpdb->term_taxonomy}.term_id =  {$wpdb->terms}.term_id\n\t\t\t\t\t\t\t\tAND {$wpdb->term_relationships}.term_taxonomy_id =  {$wpdb->term_taxonomy}.term_taxonomy_id\n\t\t\t\t\t\t\t\tAND {$wpdb->term_taxonomy}.taxonomy in ( {$taxonomies} )\n\t\t\t\t\t\t\t\t{$terms_where} \n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) \n\t\t\t\t\t) \n\t\t\t\tAND {$wpdb->posts}.post_type in ('{$post_types}') \n\t\t\t\tAND ({$wpdb->posts}.post_status = 'publish') ";
    }
    ########### WPML ###########
    if (function_exists('icl_object_id')) {
        $lang_code = ICL_LANGUAGE_CODE;
        if ($lang_code && $post_types) {
            $where .= " AND icl_t.language_code = '" . $lang_code . "' AND icl_t.element_type IN('post_" . $post_types . "') ";
        }
    }
    ########### WPML ###########
    return $where;
}