/**
 * Returns permalink structure using post link.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @global object $wp_query WordPress Query object.
 * @global object $post WordPress Post object.
 * @param string $post_link The post link.
 * @param object $post_obj The post object.
 * @param string $leavename Not yet implemented.
 * @param bool $sample Is this a sample post?.
 * @return string The post link.
 */
function geodir_listing_permalink_structure($post_link, $post_obj, $leavename, $sample)
{
    //echo $post_link."<br />".$sample ;
    global $wpdb, $wp_query, $plugin_prefix, $post, $comment_post_cache, $gd_permalink_cache;
    if (isset($post_obj->ID) && isset($post->ID) && $post_obj->ID == $post->ID) {
    } elseif (isset($post_obj->post_status) && $post_obj->post_status == 'auto-draft') {
        return $post_link;
    } else {
        $orig_post = $post;
        $post = $post_obj;
    }
    if (in_array($post->post_type, geodir_get_posttypes())) {
        $post_types = get_option('geodir_post_types');
        $slug = $post_types[$post->post_type]['rewrite']['slug'];
        // Alter the CPT slug if WPML is set to do so
        if (function_exists('icl_object_id')) {
            if (gd_wpml_slug_translation_turned_on($post->post_type) && ($language_code = gd_wpml_get_lang_from_url($post_link))) {
                $org_slug = $slug;
                $slug = apply_filters('wpml_translate_single_string', $slug, 'WordPress', 'URL slug: ' . $slug, $language_code);
                if (!$slug) {
                    $slug = $org_slug;
                }
            }
        }
        // Fix slug problem when slug matches part of host or base url/ Ex: url -> www.abcxyz.com & slug -> xyz.
        $site_url = trailingslashit(get_bloginfo('url'));
        $fix_url = strpos($post_link, $site_url) === 0 ? true : false;
        if ($fix_url) {
            $post_link = str_replace($site_url, '', $post_link);
        }
        $post_link = trailingslashit(preg_replace("/" . preg_quote($slug, "/") . "/", $slug . "/%gd_taxonomy%", $post_link, 1));
        if ($fix_url) {
            $post_link = $site_url . $post_link;
        }
        if (isset($comment_post_cache[$post->ID])) {
            $post = $comment_post_cache[$post->ID];
        }
        if (isset($gd_permalink_cache[$post->ID]) && $gd_permalink_cache[$post->ID] && !$sample) {
            $post_id = $post->ID;
            if (isset($orig_post)) {
                $post = $orig_post;
            }
            return $gd_permalink_cache[$post_id];
        }
        if (!isset($post->post_locations)) {
            $post_type = $post->post_type;
            $ID = $post->ID;
            $post2 = $wpdb->get_row($wpdb->prepare("SELECT * from " . $plugin_prefix . $post->post_type . "_detail WHERE post_id = %d ", array($post->ID)));
            $post = (object) array_merge((array) $post, (array) $post2);
            $comment_post_cache[$post->ID] = $post;
        }
        if (false !== strpos($post_link, '%gd_taxonomy%')) {
            if (apply_filters("geodir_add_location_url_to_url", get_option('geodir_add_location_url'), $post->post_type, $post)) {
                $location_request = '';
                if (!empty($post->post_locations)) {
                    $geodir_arr_locations = explode(',', $post->post_locations);
                    if (count($geodir_arr_locations) == 3) {
                        $post->city_slug = str_replace('[', '', $geodir_arr_locations[0]);
                        $post->city_slug = str_replace(']', '', $post->city_slug);
                        $post->region_slug = str_replace('[', '', $geodir_arr_locations[1]);
                        $post->region_slug = str_replace(']', '', $post->region_slug);
                        $post->country_slug = str_replace('[', '', $geodir_arr_locations[2]);
                        $post->country_slug = str_replace(']', '', $post->country_slug);
                        $post_location = (object) array('country_slug' => $post->country_slug, 'region_slug' => $post->region_slug, 'city_slug' => $post->city_slug);
                    } else {
                        $post_location = geodir_get_location();
                    }
                } else {
                    $post_location_sql = $wpdb->get_results($wpdb->prepare("SELECT post_locations from " . $plugin_prefix . $post->post_type . "_detail WHERE post_id = %d ", array($post->ID)));
                    if (!empty($post_location_sql) && is_array($post_location_sql) && !empty($post_location_sql[0]->post_locations)) {
                        $geodir_arr_locations = explode(',', $post_location_sql[0]->post_locations);
                        if (count($geodir_arr_locations) == 3) {
                            $post->city_slug = str_replace('[', '', $geodir_arr_locations[0]);
                            $post->city_slug = str_replace(']', '', $post->city_slug);
                            $post->region_slug = str_replace('[', '', $geodir_arr_locations[1]);
                            $post->region_slug = str_replace(']', '', $post->region_slug);
                            $post->country_slug = str_replace('[', '', $geodir_arr_locations[2]);
                            $post->country_slug = str_replace(']', '', $post->country_slug);
                            $post_location = (object) array('country_slug' => $post->country_slug, 'region_slug' => $post->region_slug, 'city_slug' => $post->city_slug);
                        }
                    } else {
                        $post_location = geodir_get_location();
                    }
                }
                if (!empty($post_location)) {
                    $country_slug = isset($post_location->country_slug) ? $post_location->country_slug : '';
                    $region_slug = isset($post_location->region_slug) ? $post_location->region_slug : '';
                    $city_slug = isset($post_location->city_slug) ? $post_location->city_slug : '';
                    $geodir_show_location_url = get_option('geodir_show_location_url');
                    $location_slug = array();
                    if ($geodir_show_location_url == 'all') {
                        $location_slug[] = $country_slug;
                        $location_slug[] = $region_slug;
                    } else {
                        if ($geodir_show_location_url == 'country_city') {
                            $location_slug[] = $country_slug;
                        } else {
                            if ($geodir_show_location_url == 'region_city') {
                                $location_slug[] = $region_slug;
                            }
                        }
                    }
                    $location_slug[] = $city_slug;
                    $location_request .= implode('/', $location_slug) . '/';
                }
            }
            if (get_option('geodir_add_categories_url')) {
                $term_request = '';
                $taxonomies = geodir_get_taxonomies($post->post_type);
                $taxonomies = end($taxonomies);
                if (!empty($post->default_category)) {
                    $post_terms = $post->default_category;
                } else {
                    $post_terms = '';
                    if (isset($post->{$taxonomies})) {
                        $post_terms = explode(",", trim($post->{$taxonomies}, ","));
                        $post_terms = $post_terms[0];
                    }
                    if (!$post_terms) {
                        $post_terms = geodir_get_post_meta($post->ID, 'default_category', true);
                    }
                    if (!$post_terms) {
                        $post_terms = geodir_get_post_meta($post->ID, $taxonomies, true);
                        if ($post_terms) {
                            $post_terms = explode(",", trim($post_terms, ","));
                            $post_terms = $post_terms[0];
                        }
                    }
                }
                $term = get_term_by('id', $post_terms, $taxonomies);
                if (!empty($term)) {
                    $term_request = $term->slug;
                }
                //$term_request = $term->slug.'/';
            }
            $request_term = '';
            $listingurl_separator = '';
            //$detailurl_separator = get_option('geodir_detailurl_separator');
            $detailurl_separator = '';
            if (isset($location_request) && $location_request != '' && isset($term_request) && $term_request != '') {
                $request_term = $location_request;
                //$listingurl_separator = get_option('geodir_listingurl_separator');
                //$request_term .= $listingurl_separator.'/'.$term_request;
                $request_term .= $term_request;
            } else {
                if (isset($location_request) && $location_request != '') {
                    $request_term = $location_request;
                }
                if (isset($term_request) && $term_request != '') {
                    $request_term .= $term_request;
                }
            }
            $request_term = trim($request_term, '/');
            if (!empty($request_term)) {
                $post_link = str_replace('%gd_taxonomy%', $request_term . $detailurl_separator, $post_link);
            } else {
                $post_link = str_replace('/%gd_taxonomy%', $request_term . $detailurl_separator, $post_link);
            }
            //echo $post_link ;
        }
        // temp cache the permalink
        if (!$sample && (!isset($_REQUEST['geodir_ajax']) || isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] != 'add_listing')) {
            $gd_permalink_cache[$post->ID] = $post_link;
        }
    }
    if (isset($orig_post)) {
        $post = $orig_post;
    }
    //echo $post_link ;
    return $post_link;
}
Пример #2
0
/**
 * Main function that generates breadcrumb for all pages.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wp_query WordPress Query object.
 * @global object $post The current post object.
 */
function geodir_breadcrumb()
{
    global $wp_query, $geodir_add_location_url;
    /**
     * Filter breadcrumb separator.
     *
     * @since 1.0.0
     */
    $separator = apply_filters('geodir_breadcrumb_separator', ' > ');
    if (!is_home()) {
        $breadcrumb = '';
        $url_categoris = '';
        $breadcrumb .= '<div class="geodir-breadcrumb clearfix"><ul id="breadcrumbs">';
        /**
         * Filter breadcrumb's first link.
         *
         * @since 1.0.0
         */
        $breadcrumb .= '<li>' . apply_filters('geodir_breadcrumb_first_link', '<a href="' . get_option('home') . '">' . __('Home', 'geodirectory') . '</a>') . '</li>';
        $gd_post_type = geodir_get_current_posttype();
        $post_type_info = get_post_type_object($gd_post_type);
        remove_filter('post_type_archive_link', 'geodir_get_posttype_link');
        $listing_link = get_post_type_archive_link($gd_post_type);
        add_filter('post_type_archive_link', 'geodir_get_posttype_link', 10, 2);
        $listing_link = rtrim($listing_link, '/');
        $listing_link .= '/';
        $post_type_for_location_link = $listing_link;
        $location_terms = geodir_get_current_location_terms('query_vars', $gd_post_type);
        $location_link = $post_type_for_location_link;
        if (geodir_is_page('detail') || geodir_is_page('listing')) {
            global $post;
            $is_location_last = '';
            $is_taxonomy_last = '';
            $breadcrumb .= '<li>';
            if (get_query_var($gd_post_type . 'category')) {
                $gd_taxonomy = $gd_post_type . 'category';
            } elseif (get_query_var($gd_post_type . '_tags')) {
                $gd_taxonomy = $gd_post_type . '_tags';
            }
            $breadcrumb .= $separator . '<a href="' . $listing_link . '">' . __(ucfirst($post_type_info->label), 'geodirectory') . '</a>';
            if (!empty($gd_taxonomy) || geodir_is_page('detail')) {
                $is_location_last = false;
            } else {
                $is_location_last = true;
            }
            if (!empty($gd_taxonomy) && geodir_is_page('listing')) {
                $is_taxonomy_last = true;
            } else {
                $is_taxonomy_last = false;
            }
            if (!empty($location_terms)) {
                $geodir_get_locations = function_exists('get_actual_location_name') ? true : false;
                foreach ($location_terms as $key => $location_term) {
                    if ($location_term != '') {
                        $gd_location_link_text = preg_replace('/-(\\d+)$/', '', $location_term);
                        $gd_location_link_text = preg_replace('/[_-]/', ' ', $gd_location_link_text);
                        $gd_location_link_text = ucfirst($gd_location_link_text);
                        $location_term_actual_country = '';
                        $location_term_actual_region = '';
                        $location_term_actual_city = '';
                        if ($geodir_get_locations) {
                            if ($key == 'gd_country') {
                                $location_term_actual_country = get_actual_location_name('country', $location_term, true);
                            } else {
                                if ($key == 'gd_region') {
                                    $location_term_actual_region = get_actual_location_name('region', $location_term, true);
                                } else {
                                    if ($key == 'gd_city') {
                                        $location_term_actual_city = get_actual_location_name('city', $location_term, true);
                                    }
                                }
                            }
                        } else {
                            $location_info = geodir_get_location();
                            if (!empty($location_info) && isset($location_info->location_id)) {
                                if ($key == 'gd_country') {
                                    $location_term_actual_country = __($location_info->country, 'geodirectory');
                                } else {
                                    if ($key == 'gd_region') {
                                        $location_term_actual_region = __($location_info->region, 'geodirectory');
                                    } else {
                                        if ($key == 'gd_city') {
                                            $location_term_actual_city = __($location_info->city, 'geodirectory');
                                        }
                                    }
                                }
                            }
                        }
                        if ($is_location_last && $key == 'gd_country' && !(isset($location_terms['gd_region']) && $location_terms['gd_region'] != '') && !(isset($location_terms['gd_city']) && $location_terms['gd_city'] != '')) {
                            $breadcrumb .= $location_term_actual_country != '' ? $separator . $location_term_actual_country : $separator . $gd_location_link_text;
                        } else {
                            if ($is_location_last && $key == 'gd_region' && !(isset($location_terms['gd_city']) && $location_terms['gd_city'] != '')) {
                                $breadcrumb .= $location_term_actual_region != '' ? $separator . $location_term_actual_region : $separator . $gd_location_link_text;
                            } else {
                                if ($is_location_last && $key == 'gd_city') {
                                    $breadcrumb .= $location_term_actual_city != '' ? $separator . $location_term_actual_city : $separator . $gd_location_link_text;
                                } else {
                                    if (get_option('permalink_structure') != '') {
                                        $location_link .= $location_term . '/';
                                    } else {
                                        $location_link .= "&{$key}=" . $location_term;
                                    }
                                    if ($key == 'gd_country' && $location_term_actual_country != '') {
                                        $gd_location_link_text = $location_term_actual_country;
                                    } else {
                                        if ($key == 'gd_region' && $location_term_actual_region != '') {
                                            $gd_location_link_text = $location_term_actual_region;
                                        } else {
                                            if ($key == 'gd_city' && $location_term_actual_city != '') {
                                                $gd_location_link_text = $location_term_actual_city;
                                            }
                                        }
                                    }
                                    $breadcrumb .= $separator . '<a href="' . $location_link . '">' . $gd_location_link_text . '</a>';
                                }
                            }
                        }
                    }
                }
            }
            if (!empty($gd_taxonomy)) {
                $term_index = 1;
                if (get_query_var($gd_post_type . '_tags')) {
                    $cat_link = $listing_link . 'tags/';
                } else {
                    $cat_link = $listing_link;
                }
                foreach ($location_terms as $key => $location_term) {
                    if ($location_term != '') {
                        if (get_option('permalink_structure') != '') {
                            $cat_link .= $location_term . '/';
                        }
                    }
                }
                $term_array = explode("/", trim($wp_query->query[$gd_taxonomy], "/"));
                foreach ($term_array as $term) {
                    $term_link_text = preg_replace('/-(\\d+)$/', '', $term);
                    $term_link_text = preg_replace('/[_-]/', ' ', $term_link_text);
                    // get term actual name
                    $term_info = get_term_by('slug', $term, $gd_taxonomy, 'ARRAY_A');
                    if (!empty($term_info) && isset($term_info['name']) && $term_info['name'] != '') {
                        $term_link_text = urldecode($term_info['name']);
                    } else {
                        $term_link_text = ucwords(urldecode($term_link_text));
                    }
                    if ($term_index == count($term_array) && $is_taxonomy_last) {
                        $breadcrumb .= $separator . $term_link_text;
                    } else {
                        $cat_link .= $term . '/';
                        $breadcrumb .= $separator . '<a href="' . $cat_link . '">' . $term_link_text . '</a>';
                    }
                    $term_index++;
                }
            }
            if (geodir_is_page('detail')) {
                $breadcrumb .= $separator . get_the_title();
            }
            $breadcrumb .= '</li>';
        } elseif (geodir_is_page('author')) {
            $user_id = get_current_user_id();
            $author_link = get_author_posts_url($user_id);
            $default_author_link = geodir_getlink($author_link, array('geodir_dashbord' => 'true', 'stype' => 'gd_place'), false);
            /**
             * Filter author page link.
             *
             * @since 1.0.0
             * @param string $default_author_link Default author link.
             * @param int $user_id Author ID.
             */
            $default_author_link = apply_filters('geodir_dashboard_author_link', $default_author_link, $user_id);
            $breadcrumb .= '<li>';
            $breadcrumb .= $separator . '<a href="' . $default_author_link . '">' . __('My Dashboard', 'geodirectory') . '</a>';
            if (isset($_REQUEST['list'])) {
                $author_link = geodir_getlink($author_link, array('geodir_dashbord' => 'true', 'stype' => $_REQUEST['stype']), false);
                /**
                 * Filter author page link.
                 *
                 * @since 1.0.0
                 * @param string $author_link Author page link.
                 * @param int $user_id Author ID.
                 * @param string $_REQUEST['stype'] Post type.
                 */
                $author_link = apply_filters('geodir_dashboard_author_link', $author_link, $user_id, $_REQUEST['stype']);
                $breadcrumb .= $separator . '<a href="' . $author_link . '">' . __(ucfirst($post_type_info->label), 'geodirectory') . '</a>';
                $breadcrumb .= $separator . ucfirst(__('My', 'geodirectory') . ' ' . $_REQUEST['list']);
            } else {
                $breadcrumb .= $separator . __(ucfirst($post_type_info->label), 'geodirectory');
            }
            $breadcrumb .= '</li>';
        } elseif (is_category() || is_single()) {
            $category = get_the_category();
            if (is_category()) {
                $breadcrumb .= '<li>' . $separator . $category[0]->cat_name . '</li>';
            }
            if (is_single()) {
                $breadcrumb .= '<li>' . $separator . '<a href="' . get_category_link($category[0]->term_id) . '">' . $category[0]->cat_name . '</a></li>';
                $breadcrumb .= '<li>' . $separator . get_the_title() . '</li>';
            }
            /* End of my version ##################################################### */
        } else {
            if (is_page()) {
                $page_title = get_the_title();
                if (geodir_is_page('location')) {
                    $page_title = defined('GD_LOCATION') ? GD_LOCATION : __('Location', 'geodirectory');
                }
                $breadcrumb .= '<li>' . $separator;
                $breadcrumb .= stripslashes_deep($page_title);
                $breadcrumb .= '</li>';
            } else {
                if (is_tag()) {
                    $breadcrumb .= "<li> " . $separator . single_tag_title('', false) . '</li>';
                } else {
                    if (is_day()) {
                        $breadcrumb .= "<li> " . $separator . __(" Archive for", 'geodirectory') . " ";
                        the_time('F jS, Y');
                        $breadcrumb .= '</li>';
                    } else {
                        if (is_month()) {
                            $breadcrumb .= "<li> " . $separator . __(" Archive for", 'geodirectory') . " ";
                            the_time('F, Y');
                            $breadcrumb .= '</li>';
                        } else {
                            if (is_year()) {
                                $breadcrumb .= "<li> " . $separator . __(" Archive for", 'geodirectory') . " ";
                                the_time('Y');
                                $breadcrumb .= '</li>';
                            } else {
                                if (is_author()) {
                                    $breadcrumb .= "<li> " . $separator . __(" Author Archive", 'geodirectory');
                                    $breadcrumb .= '</li>';
                                } else {
                                    if (isset($_GET['paged']) && !empty($_GET['paged'])) {
                                        $breadcrumb .= "<li>" . $separator . __("Blog Archives", 'geodirectory');
                                        $breadcrumb .= '</li>';
                                    } else {
                                        if (is_search()) {
                                            $breadcrumb .= "<li> " . $separator . __(" Search Results", 'geodirectory');
                                            $breadcrumb .= '</li>';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        $breadcrumb .= '</ul></div>';
        /**
         * Filter breadcrumb html output.
         *
         * @since 1.0.0
         * @param string $breadcrumb Breadcrumb HTML.
         * @param string $separator Breadcrumb separator.
         */
        echo $breadcrumb = apply_filters('geodir_breadcrumb', $breadcrumb, $separator);
    }
}
Пример #3
0
 /**
  * Adds content to our custom post listing page columns.
  *
  * @since 1.0.0
  * @package GeoDirectory
  * @global object $wpdb WordPress Database object.
  * @global object $post WordPress Post object.
  * @param string $column The column name.
  * @param int $post_id The post ID.
  */
 function geodir_manage_post_columns($column, $post_id)
 {
     global $post, $wpdb;
     switch ($column) {
         /* If displaying the 'city' column. */
         case 'location':
             $location_id = geodir_get_post_meta($post->ID, 'post_location_id', true);
             $location = geodir_get_location($location_id);
             /* If no city is found, output a default message. */
             if (empty($location)) {
                 _e('Unknown', GEODIRECTORY_TEXTDOMAIN);
             } else {
                 /* If there is a city id, append 'city name' to the text string. */
                 $add_location_id = $location_id > 0 ? ' (' . $location_id . ')' : '';
                 echo __($location->country, GEODIRECTORY_TEXTDOMAIN) . '-' . $location->region . '-' . $location->city . $add_location_id;
             }
             break;
             /* If displaying the 'expire' column. */
         /* If displaying the 'expire' column. */
         case 'expire':
             $expire_date = geodir_get_post_meta($post->ID, 'expire_date', true);
             $d1 = $expire_date;
             // get expire_date
             $d2 = date('Y-m-d');
             // get current date
             $state = __('days left', GEODIRECTORY_TEXTDOMAIN);
             $date_diff_text = '';
             $expire_class = 'expire_left';
             if ($expire_date != 'Never') {
                 if (strtotime($d1) < strtotime($d2)) {
                     $state = __('days overdue', GEODIRECTORY_TEXTDOMAIN);
                     $expire_class = 'expire_over';
                 }
                 $date_diff = round(abs(strtotime($d1) - strtotime($d2)) / 86400);
                 // get the differance in days
                 $date_diff_text = '<br /><span class="' . $expire_class . '">(' . $date_diff . ' ' . $state . ')</span>';
             }
             /* If no expire_date is found, output a default message. */
             if (empty($expire_date)) {
                 echo __('Unknown', GEODIRECTORY_TEXTDOMAIN);
             } else {
                 echo $expire_date . $date_diff_text;
             }
             break;
             /* If displaying the 'categorys' column. */
         /* If displaying the 'categorys' column. */
         case 'categorys':
             /* Get the categorys for the post. */
             $terms = wp_get_object_terms($post_id, get_object_taxonomies($post));
             /* If terms were found. */
             if (!empty($terms)) {
                 $out = array();
                 /* Loop through each term, linking to the 'edit posts' page for the specific term. */
                 foreach ($terms as $term) {
                     if (!strstr($term->taxonomy, 'tag')) {
                         $out[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, $term->taxonomy => $term->slug), 'edit.php')), esc_html(sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, 'display')));
                     }
                 }
                 /* Join the terms, separating them with a comma. */
                 echo join(', ', $out);
             } else {
                 _e('No Categories', GEODIRECTORY_TEXTDOMAIN);
             }
             break;
     }
 }
/**
 * 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);
            }
        }
    }
}
Пример #5
0
/**
 * Filter the permalink for a post with a custom post type.
 *
 * @since 1.1.6
 *
 * @global object $wpdb WordPress Database object.
 * @global WP_Query $wp_query WordPress Query object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @global array $comment_post_cache Array of cached post links.
 * @global array $gd_permalink_cache Array of cached post permalinks.
 *
 * @param string $post_link The post permalink.
 * @param WP_Post $post_obj Post object. Default current post.
 * @param bool $leavename Whether to keep post name or page name.
 * @param bool $sample Is it a sample permalink.
 * @return string The post permalink.
 */
function geodir_cpt_post_type_link($post_link, $post_obj, $leavename, $sample)
{
    if (empty($post_obj->post_type)) {
        return $post_link;
    }
    $gd_postypes = geodir_get_posttypes();
    if (!in_array($post_obj->post_type, $gd_postypes)) {
        return $post_link;
    }
    if (geodir_cpt_no_location($post_obj->post_type)) {
        $post = $post_obj;
        global $wpdb, $wp_query, $plugin_prefix, $comment_post_cache, $gd_permalink_cache;
        if (!empty($post->post_locations)) {
            $geodir_arr_locations = explode(',', $post->post_locations);
            if (count($geodir_arr_locations) == 3) {
                $post->city_slug = str_replace('[', '', $geodir_arr_locations[0]);
                $post->city_slug = str_replace(']', '', $post->city_slug);
                $post->region_slug = str_replace('[', '', $geodir_arr_locations[1]);
                $post->region_slug = str_replace(']', '', $post->region_slug);
                $post->country_slug = str_replace('[', '', $geodir_arr_locations[2]);
                $post->country_slug = str_replace(']', '', $post->country_slug);
                $post_location = (object) array('country_slug' => $post->country_slug, 'region_slug' => $post->region_slug, 'city_slug' => $post->city_slug);
            } else {
                $post_location = geodir_get_location();
            }
        } else {
            $post_location_sql = $wpdb->get_results($wpdb->prepare("SELECT post_locations from " . $plugin_prefix . $post->post_type . "_detail WHERE post_id = %d ", array($post->ID)));
            if (!empty($post_location_sql) && is_array($post_location_sql) && !empty($post_location_sql[0]->post_locations)) {
                $geodir_arr_locations = explode(',', $post_location_sql[0]->post_locations);
                if (count($geodir_arr_locations) == 3) {
                    $post->city_slug = str_replace('[', '', $geodir_arr_locations[0]);
                    $post->city_slug = str_replace(']', '', $post->city_slug);
                    $post->region_slug = str_replace('[', '', $geodir_arr_locations[1]);
                    $post->region_slug = str_replace(']', '', $post->region_slug);
                    $post->country_slug = str_replace('[', '', $geodir_arr_locations[2]);
                    $post->country_slug = str_replace(']', '', $post->country_slug);
                    $post_location = (object) array('country_slug' => $post->country_slug, 'region_slug' => $post->region_slug, 'city_slug' => $post->city_slug);
                }
            } else {
                $post_location = geodir_get_location();
            }
        }
        $location_vars = '';
        if (!empty($post_location)) {
            if (get_option('geodir_show_location_url') == 'all') {
                $location_vars .= $post_location->country_slug . '/';
                $location_vars .= $post_location->region_slug . '/';
                $location_vars .= $post_location->city_slug . '/';
            } else {
                $location_vars .= $post_location->city_slug . '/';
            }
        }
        $search = $location_vars;
        $replace = '';
        $post_link = str_replace($search, $replace, $post_link);
    }
    return $post_link;
}