/** * 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); } }
/** * Handles user Authentication actions Ex. login, register, logout etc. * * @since 1.0.0 * @since 1.5.7 It allows login by email also if site is using SSL. * @package GeoDirectory * @global object $errors WordPress Error object. */ function geodir_user_signup() { global $errors; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login'; $errors = new WP_Error(); if (isset($_GET['key'])) { $action = 'resetpass'; } // validate action so as to default to the login screen if (!in_array($action, array('logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login')) && false === has_filter('login_form_' . $action)) { $action = 'login'; } nocache_headers(); if (defined('RELOCATE')) { // Move flag is set if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) { $_SERVER['PHP_SELF'] = str_replace($_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF']); } $schema = isset($_SERVER['HTTPS']) && geodir_strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; if (dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != home_url()) { update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'])); } } //Set a cookie now to see if they are supported by the browser. //setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN); if (SITECOOKIEPATH != COOKIEPATH) { setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN); } /** * Allow plugins to override the default actions, and to add extra actions if they want on the register/signin page. * * Used dynamic hook login_form_$action * * @since 1.0.0 */ do_action('login_form_' . $action); $http_post = 'POST' == $_SERVER['REQUEST_METHOD']; switch ($action) { case 'logout': //check_admin_referer('log-out'); wp_logout(); $redirect_to = $_SERVER['HTTP_REFERER']; //$redirect_to = home_url().'/?ptype=login&loggedout=true'; if (isset($_REQUEST['redirect_to'])) { $redirect_to = $_REQUEST['redirect_to']; } $redirect_to = home_url(); wp_safe_redirect($redirect_to); exit; break; case 'lostpassword': case 'retrievepassword': if ($http_post) { $errors = geodir_retrieve_password(); $error_message = isset($errors->errors['invalid_email'][0]) ? $errors->errors['invalid_email'][0] : ''; if (!is_wp_error($errors)) { wp_redirect(geodir_login_url(array('checkemail' => 'confirm'))); exit; } else { wp_redirect(geodir_login_url(array('emsg' => 'fw'))); exit; } } if (isset($_GET['error']) && 'invalidkey' == $_GET['error']) { $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.', 'geodirectory')); } /** * Called in the geodir_user_signup() function during the lostpassword case. * * @since 1.0.0 */ do_action('lost_password'); $message = '<div class="sucess_msg">' . ENTER_USER_EMAIL_NEW_PW_MSG . '</div>'; $user_login = isset($_POST['user_login']) ? stripslashes($_POST['user_login']) : ''; break; case 'resetpass': case 'rp': $errors = reset_password($_GET['key'], $_GET['login']); if (!is_wp_error($errors)) { wp_redirect(geodir_login_url(array('checkemail' => 'newpass'))); exit; } wp_redirect(geodir_login_url(array('error' => 'invalidkey', 'action' => 'lostpassword'))); exit; break; case 'register': ############################### fix by Stiofan - HebTech.co.uk ### SECURITY FIX ############################## if (!get_option('users_can_register')) { wp_redirect(geodir_login_url(array('emsg' => 'regnewusr'))); exit; } ############################### fix by Stiofan - HebTech.co.uk ### SECURITY FIX ############################## global $user_email, $user_fname; $user_login = ''; $user_email = ''; if ($http_post) { $user_login = $_POST['user_email']; $user_email = $_POST['user_email']; $user_fname = $_POST['user_fname']; $errors = geodir_register_new_user($user_login, $user_email); /* display error in registration form */ if (is_wp_error($errors)) { $error_code = $errors->get_error_code(); $error_message = $errors->get_error_message($error_code); if (!isset($_POST['user_login']) && ($error_code == 'empty_username' || $error_code == 'invalid_username' || $error_code == 'username_exists')) { if ($error_code == 'empty_username') { $error_code = 'empty_email'; } else { if ($error_code == 'invalid_username') { $error_code = 'invalid_email'; } else { if ($error_code == 'username_exists') { $error_code = 'email_exists'; } } } $error_message = $errors->get_error_message($error_code); } global $geodir_signup_error; $geodir_signup_error = $error_message; } if (!is_wp_error($errors)) { $_POST['log'] = $user_login; $_POST['pwd'] = $errors[1]; $_POST['testcookie'] = 1; $secure_cookie = ''; // If the user wants ssl but the session is not ssl, force a secure cookie. if (!empty($_POST['log'])) { $user_name = sanitize_user($_POST['log']); if ($user = get_user_by('email', $user_name)) { if (get_user_option('use_ssl', $user->ID)) { $secure_cookie = true; force_ssl_admin(true); } } } $redirect_to = $_REQUEST['redirect_to']; if (!isset($_REQUEST['redirect_to']) || $_REQUEST['redirect_to'] == '') { if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], home_url())) { $redirect_to = $_SERVER['HTTP_REFERER']; } else { $redirect_to = home_url(); } } if (isset($_REQUEST['redirect_add_listing']) && $_REQUEST['redirect_add_listing'] != '') { $redirect_to = $_REQUEST['redirect_add_listing']; } if (!$secure_cookie && is_ssl() && force_ssl_login() && !force_ssl_admin() && 0 !== strpos($redirect_to, 'https') && 0 === strpos($redirect_to, 'http')) { $secure_cookie = false; } $user = wp_signon('', $secure_cookie); $requested_redirect_to = isset($_REQUEST['redirect_add_listing']) && $_REQUEST['redirect_add_listing'] != '' ? $_REQUEST['redirect_add_listing'] : (isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : ''); /** * Filter the login redirect URL. * * @since 1.4.9 * @param string $redirect_to The redirect destination URL. * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise. */ $redirect_to = apply_filters('login_redirect', $redirect_to, $requested_redirect_to, $user); if (!is_wp_error($user)) { wp_safe_redirect($redirect_to); exit; } exit; } } break; case 'login': default: $secure_cookie = ''; if (!empty($_POST['log'])) { $user_name = sanitize_user($_POST['log']); if ($user = get_user_by('login', $user_name)) { if (get_user_option('use_ssl', $user->ID)) { $secure_cookie = true; force_ssl_admin(true); } } elseif ($user = get_user_by('email', $user_name)) { $_POST['log'] = $user->user_login; // If signing in by email, set the username for normal WP login if (get_user_option('use_ssl', $user->ID)) { $secure_cookie = true; force_ssl_admin(true); } } } /////////////////////////// if (isset($_REQUEST['redirect_add_listing'])) { $_REQUEST['redirect_to'] = $_REQUEST['redirect_add_listing']; } if (!isset($_REQUEST['redirect_to']) || $_REQUEST['redirect_to'] == '') { if (is_user_logged_in()) { $user_ID = isset($user->ID) ? $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 the author link. * * @since 1.0.0 * * @param string $default_author_link Default author link. * @param int $user_ID The user ID. */ $default_author_link = apply_filters('geodir_dashboard_author_link', $default_author_link, $user_ID); $_REQUEST['redirect_to'] = $default_author_link; } else { $_REQUEST['redirect_to'] = home_url(); } } if (isset($_REQUEST['redirect_to'])) { $redirect_to = $_REQUEST['redirect_to']; // Redirect to https if user wants ssl if ($secure_cookie && false !== strpos($redirect_to, 'wp-admin')) { $redirect_to = preg_replace('|^http://|', 'https://', $redirect_to); } } else { $redirect_to = admin_url(); } if (!$secure_cookie && is_ssl() && force_ssl_login() && !force_ssl_admin() && 0 !== strpos($redirect_to, 'https') && 0 === strpos($redirect_to, 'http')) { $secure_cookie = false; } $user = wp_signon('', $secure_cookie); /** * Filter the login redirect URL. * * @since 1.4.9 * @param string $redirect_to The redirect destination URL. * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise. */ $redirect_to = apply_filters('login_redirect', $redirect_to, isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '', $user); if (is_wp_error($user)) { if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], 'ptype=property_submit') && $_POST['log'] != '' && $_POST['pwd'] != '') { wp_redirect($_SERVER['HTTP_REFERER'] . '&emsg=1'); } } if (!is_wp_error($user)) { // Some servers are not logging the user in properly after wp_signon, se we set the user here. //wp_set_current_user($user->ID); //echo '###';exit; if ($redirect_to) { wp_redirect($redirect_to); } else { wp_redirect(home_url()); } exit; } $errors = $user; // Clear errors if loggedout is set. if (!empty($_GET['loggedout'])) { $errors = new WP_Error(); } // If cookies are disabled we can't log in even with a valid user+pass if (isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE])) { $errors->add('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress.", 'geodirectory')); } // Some parts of this script use the main login form to display a message if (isset($_GET['loggedout']) && TRUE == $_GET['loggedout']) { $successmsg = '<div class="sucess_msg">' . YOU_ARE_LOGED_OUT_MSG . '</div>'; } elseif (isset($_GET['registration']) && 'disabled' == $_GET['registration']) { $successmsg = USER_REG_NOT_ALLOW_MSG; } elseif (isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail']) { $successmsg = EMAIL_CONFIRM_LINK_MSG; } elseif (isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail']) { $successmsg = NEW_PW_EMAIL_MSG; } elseif (isset($_GET['checkemail']) && 'registered' == $_GET['checkemail']) { $successmsg = REG_COMPLETE_MSG; } if (isset($_POST['log']) && $_POST['log'] != '' && $errors || (!isset($_POST['log']) || $_POST['log'] == '') && isset($_REQUEST['testcookie']) && $_REQUEST['testcookie']) { if (isset($_REQUEST['pagetype']) && $_REQUEST['pagetype'] != '') { wp_redirect($_REQUEST['pagetype'] . '&emsg=1'); } else { wp_redirect(geodir_login_url(array('logemsg' => '1', 'redirect_to' => urlencode($_REQUEST['redirect_to'])))); } exit; } break; } // end action switch }
if (postal_code.long_name) { getZip = postal_code.long_name; } <?php /** * Fires to add javascript variable to use in google map. * * @since 1.0.0 */ do_action('geodir_add_listing_geocode_js_vars'); ?> <?php if ($is_map_restrict) { ?> if (getCity.toLowerCase() != '<?php echo geodir_strtolower(addslashes_gpc($city)); ?> ') { alert('<?php echo addslashes_gpc(wp_sprintf(__('Please choose any address of the (%s) city only.', 'geodirectory'), $city)); ?> '); jQuery("#<?php echo $prefix . 'map'; ?> ").goMap(); jQuery.goMap.map.setCenter(new google.maps.LatLng('<?php echo $default_lat; ?> ', '<?php echo $default_lng;
/** * Imports data from CSV file using ajax. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @global object $current_user Current user object. */ function geodir_ajax_import_csv() { error_reporting(0); // hide error to get clean json response global $wpdb, $plugin_prefix, $current_user; $uploads = wp_upload_dir(); ini_set('auto_detect_line_endings', true); $wp_post_statuses = get_post_statuses(); // All of the WordPress supported post statuses. $task = isset($_POST['task']) ? $_POST['task'] : ''; $uploadedFile = isset($_POST['gddata']['uploadedFile']) ? $_POST['gddata']['uploadedFile'] : NULL; $filename = $uploadedFile; $uploads = wp_upload_dir(); $uploads_dir = $uploads['path']; $image_name_arr = explode('/', $filename); $filename = end($image_name_arr); $target_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $filename; $return = array(); $return['file'] = $uploadedFile; $return['error'] = __('The uploaded file is not a valid csv file. Please try again.', 'geodirectory'); if (is_file($target_path) && file_exists($target_path) && $uploadedFile) { $wp_filetype = wp_check_filetype_and_ext($target_path, $filename); if (!empty($wp_filetype) && isset($wp_filetype['ext']) && geodir_strtolower($wp_filetype['ext']) == 'csv') { $return['error'] = NULL; $return['rows'] = 0; if (($handle = fopen($target_path, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if (is_array($data) && !empty($data)) { $file[] = '"' . implode('","', $data) . '"'; } } fclose($handle); $file = $file; } $return['rows'] = !empty($file) && count($file) > 1 ? count($file) - 1 : 0; if (!$return['rows'] > 0) { $return['error'] = __('No data found in csv file.', 'geodirectory'); } } } if ($task == 'prepare' || !empty($return['error'])) { echo json_encode($return); exit; } $totRecords = isset($_POST['gddata']['totRecords']) ? $_POST['gddata']['totRecords'] : NULL; $importlimit = isset($_POST['gddata']['importlimit']) ? $_POST['gddata']['importlimit'] : 1; $count = $importlimit; $requested_limit = $importlimit; $tmpCnt = isset($_POST['gddata']['tmpcount']) ? $_POST['gddata']['tmpcount'] : 0; if ($count < $totRecords) { $count = $tmpCnt + $count; if ($count > $totRecords) { $count = $totRecords; } } else { $count = $totRecords; } $total_records = 0; $rowcount = 0; $address_invalid = 0; $blank_address = 0; $upload_files = 0; $invalid_post_type = 0; $invalid_title = 0; $customKeyarray = array(); $gd_post_info = array(); $post_location = array(); $countpost = 0; if (!empty($file)) { $columns = isset($file[0]) ? geodir_str_getcsv($file[0]) : NULL; $customKeyarray = $columns; if (empty($columns) || !empty($columns) && $columns[0] == '') { $return['error'] = CSV_INVAILD_FILE; echo json_encode($return); exit; } for ($i = 1; $i <= $importlimit; $i++) { $current_index = $tmpCnt + $i; if (isset($file[$current_index])) { $total_records++; $buffer = geodir_str_getcsv($file[$current_index]); $post_title = addslashes($buffer[0]); $current_post_author = $buffer[1]; $post_desc = addslashes($buffer[2]); $post_cat = array(); $catids_arr = array(); $post_cat = trim($buffer[3]); // comma seperated category name if ($post_cat) { $post_cat_arr = explode(',', $post_cat); for ($c = 0; $c < count($post_cat_arr); $c++) { $catid = wp_kses_normalize_entities(trim($post_cat_arr[$c])); if (!empty($buffer[5])) { if (in_array($buffer[5], geodir_get_posttypes())) { $p_taxonomy = geodir_get_taxonomies(addslashes($buffer[5])); if (get_term_by('name', $catid, $p_taxonomy[0])) { $cat = get_term_by('name', $catid, $p_taxonomy[0]); $catids_arr[] = $cat->slug; } else { if (get_term_by('slug', $catid, $p_taxonomy[0])) { $cat = get_term_by('slug', $catid, $p_taxonomy[0]); $catids_arr[] = $cat->slug; } else { $ret = wp_insert_term($catid, $p_taxonomy[0]); if ($ret && !is_wp_error($ret)) { if (get_term_by('name', $catid, $p_taxonomy[0])) { $cat = get_term_by('name', $catid, $p_taxonomy[0]); $catids_arr[] = $cat->slug; } elseif (get_term_by('slug', $catid, $p_taxonomy[0])) { $cat = get_term_by('slug', $catid, $p_taxonomy[0]); $catids_arr[] = $cat->slug; } } } } } } } } if (!$catids_arr) { $catids_arr[] = 1; } $post_tags = trim($buffer[4]); // comma seperated tags $tag_arr = ''; if ($post_tags) { $tag_arr = explode(',', $post_tags); } $table = $plugin_prefix . $buffer[5] . '_detail'; // check table in database $error = ''; if ($wpdb->get_var("SHOW TABLES LIKE '" . $table . "'") != $table) { $invalid_post_type++; continue; } if ($post_title != '') { $menu_order = 0; $image_folder_name = 'uplaod/'; $image_names = array(); for ($c = 5; $c < count($customKeyarray); $c++) { $gd_post_info[$customKeyarray[$c]] = addslashes($buffer[$c]); if ($customKeyarray[$c] == 'IMAGE') { $buffer[$c] = trim($buffer[$c]); if (!empty($buffer[$c])) { $image_names[] = $buffer[$c]; } } if ($customKeyarray[$c] == 'alive_days') { if ($buffer[$c] != '0' && $buffer[$c] != '') { $submitdata = date('Y-m-d'); $gd_post_info['expire_date'] = date('Y-m-d', strtotime($submitdata . "+" . addslashes($buffer[$c]) . " days")); } else { $gd_post_info['expire_date'] = 'Never'; } } if ($customKeyarray[$c] == 'post_city') { $post_city = addslashes($buffer[$c]); } if ($customKeyarray[$c] == 'post_region') { $post_region = addslashes($buffer[$c]); } if ($customKeyarray[$c] == 'post_country') { $post_country = addslashes($buffer[$c]); } if ($customKeyarray[$c] == 'post_latitude') { $post_latitude = addslashes($buffer[$c]); } if ($customKeyarray[$c] == 'post_longitude') { $post_longitude = addslashes($buffer[$c]); } // Post status if ($customKeyarray[$c] == 'post_status') { $post_status = sanitize_key($buffer[$c]); } } /* ================ before array create ============== */ $location_result = geodir_get_default_location(); if (!isset($gd_post_info['post_city']) || $gd_post_info['post_city'] == '' || (!isset($gd_post_info['post_region']) || $gd_post_info['post_region'] == '') || (!isset($gd_post_info['post_country']) || $gd_post_info['post_country'] == '') || (!isset($gd_post_info['post_address']) || $gd_post_info['post_address'] == '') || (!isset($gd_post_info['post_latitude']) || $gd_post_info['post_latitude'] == '') || (!isset($gd_post_info['post_longitude']) || $gd_post_info['post_longitude'] == '')) { $blank_address++; continue; } else { if ($location_result->location_id == 0) { if (geodir_strtolower($gd_post_info['post_city']) != geodir_strtolower($location_result->city) || geodir_strtolower($gd_post_info['post_region']) != geodir_strtolower($location_result->region) || geodir_strtolower($gd_post_info['post_country']) != geodir_strtolower($location_result->country)) { $address_invalid++; continue; } } } // Default post status $default_status = 'publish'; $post_status = !empty($post_status) ? sanitize_key($post_status) : $default_status; $post_status = !empty($wp_post_statuses) && !isset($wp_post_statuses[$post_status]) ? $default_status : $post_status; $my_post['post_title'] = $post_title; $my_post['post_content'] = $post_desc; $my_post['post_type'] = addslashes($buffer[5]); $my_post['post_author'] = $current_post_author; $my_post['post_status'] = $post_status; $my_post['post_category'] = $catids_arr; $my_post['post_tags'] = $tag_arr; $gd_post_info['post_tags'] = $tag_arr; $gd_post_info['post_title'] = $post_title; $gd_post_info['post_status'] = $post_status; $gd_post_info['submit_time'] = time(); $gd_post_info['submit_ip'] = $_SERVER['REMOTE_ADDR']; $last_postid = wp_insert_post($my_post); $countpost++; // Check if we need to save post location as new location if ($location_result->location_id > 0) { if (isset($post_city) && isset($post_region)) { $request_info['post_location'] = array('city' => $post_city, 'region' => $post_region, 'country' => $post_country, 'geo_lat' => $post_latitude, 'geo_lng' => $post_longitude); $post_location_info = $request_info['post_location']; if ($location_id = geodir_add_new_location($post_location_info)) { $post_location_id = $location_id; } } else { $post_location_id = 0; } } else { $post_location_id = 0; } /* ------- get default package info ----- */ $payment_info = array(); $package_info = array(); $package_info = (array) geodir_post_package_info($package_info, '', $buffer[5]); $package_id = ''; if (isset($gd_post_info['package_id']) && $gd_post_info['package_id'] != '') { $package_id = $gd_post_info['package_id']; } if (!empty($package_info)) { $payment_info['package_id'] = $package_info['pid']; if (isset($package_info['alive_days']) && $package_info['alive_days'] != 0) { $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['alive_days'] . " days")); } else { $payment_info['expire_date'] = 'Never'; } $gd_post_info = array_merge($gd_post_info, $payment_info); } $gd_post_info['post_location_id'] = $post_location_id; $post_type = get_post_type($last_postid); $table = $plugin_prefix . $post_type . '_detail'; geodir_save_post_info($last_postid, $gd_post_info); if (!empty($image_names)) { $upload_files++; $menu_order = 1; foreach ($image_names as $image_name) { $img_name_arr = explode('.', $image_name); $uploads = wp_upload_dir(); $sub_dir = $uploads['subdir']; $arr_file_type = wp_check_filetype($image_name); $uploaded_file_type = $arr_file_type['type']; $attachment = array(); $attachment['post_id'] = $last_postid; $attachment['title'] = $img_name_arr[0]; $attachment['content'] = ''; $attachment['file'] = $sub_dir . '/' . $image_name; $attachment['mime_type'] = $uploaded_file_type; $attachment['menu_order'] = $menu_order; $attachment['is_featured'] = 0; $attachment_set = ''; foreach ($attachment as $key => $val) { if ($val != '') { $attachment_set .= $key . " = '" . $val . "', "; } } $attachment_set = trim($attachment_set, ", "); $wpdb->query("INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set); if ($menu_order == 1) { $post_type = get_post_type($last_postid); $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s where post_id =%d", array($sub_dir . '/' . $image_name, $last_postid))); } $menu_order++; } } $gd_post_info['package_id'] = $package_id; /** This action is documented in geodirectory-functions/post-functions.php */ do_action('geodir_after_save_listing', $last_postid, $gd_post_info); if (!empty($buffer[5])) { if (in_array($buffer[5], geodir_get_posttypes())) { $taxonomies = geodir_get_posttype_info(addslashes($buffer[5])); wp_set_object_terms($last_postid, $my_post['post_tags'], $taxonomy = $taxonomies['taxonomies'][1]); wp_set_object_terms($last_postid, $my_post['post_category'], $taxonomy = $taxonomies['taxonomies'][0]); $post_default_category = isset($my_post['post_default_category']) ? $my_post['post_default_category'] : ''; $post_category_str = isset($my_post['post_category_str']) ? $my_post['post_category_str'] : ''; geodir_set_postcat_structure($last_postid, $taxonomy, $post_default_category, $post_category_str); } } } else { $invalid_title++; } } } } $return['rowcount'] = $countpost; $return['invalidcount'] = $address_invalid; $return['blank_address'] = $blank_address; $return['upload_files'] = $upload_files; $return['invalid_post_type'] = $invalid_post_type; $return['invalid_title'] = $invalid_title; $return['total_records'] = $total_records; echo json_encode($return); exit; }
/** * Calculates the distance radius. * * @since 1.0.0 * @package GeoDirectory * @param string $uom Measurement unit type. * @return float The mean radius. */ function geodir_getDistanceRadius($uom = 'km') { // Use Haversine formula to calculate the great circle distance between two points identified by longitude and latitude switch (geodir_strtolower($uom)) { case 'km': $earthMeanRadius = 6371.009; // km break; case 'm': case 'meters': $earthMeanRadius = 6371.009 * 1000; // km break; case 'miles': $earthMeanRadius = 3958.761; // miles break; case 'yards': case 'yds': $earthMeanRadius = 3958.761 * 1760; // yards break; case 'feet': case 'ft': $earthMeanRadius = 3958.761 * 1760 * 3; // feet break; case 'nm': $earthMeanRadius = 3440.069; // miles break; default: $earthMeanRadius = 3958.761; // miles break; } return $earthMeanRadius; }
/** * Set first image as post's featured image. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @param int $post_id The post ID. */ function geodir_set_wp_featured_image($post_id) { global $wpdb, $plugin_prefix; $uploads = wp_upload_dir(); // print_r($uploads ) ; $post_first_image = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id = %d and menu_order = 1 ", array($post_id))); $old_attachment_name = ''; $post_thumbnail_id = ''; if (has_post_thumbnail($post_id)) { if (has_post_thumbnail($post_id)) { $post_thumbnail_id = get_post_thumbnail_id($post_id); $old_attachment_name = basename(get_attached_file($post_thumbnail_id)); } } if (!empty($post_first_image)) { $post_type = get_post_type($post_id); $table_name = $plugin_prefix . $post_type . '_detail'; $wpdb->query("UPDATE " . $table_name . " SET featured_image='" . $post_first_image[0]->file . "' WHERE post_id =" . $post_id); $new_attachment_name = basename($post_first_image[0]->file); if (geodir_strtolower($new_attachment_name) != geodir_strtolower($old_attachment_name)) { if (has_post_thumbnail($post_id) && $post_thumbnail_id != '' && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'delete')) { add_filter('wp_delete_file', 'geodir_only_supportable_attachments_remove'); wp_delete_attachment($post_thumbnail_id); } $filename = $uploads['basedir'] . $post_first_image[0]->file; $attachment = array('post_mime_type' => $post_first_image[0]->mime_type, 'guid' => $uploads['baseurl'] . $post_first_image[0]->file, 'post_parent' => $post_id, 'post_title' => preg_replace('/\\.[^.]+$/', '', $post_first_image[0]->title), 'post_content' => ''); $id = wp_insert_attachment($attachment, $filename, $post_id); if (!is_wp_error($id)) { set_post_thumbnail($post_id, $id); require_once ABSPATH . 'wp-admin/includes/image.php'; wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $filename)); } } } else { //set_post_thumbnail($post_id,-1); if (has_post_thumbnail($post_id) && $post_thumbnail_id != '' && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'delete')) { wp_delete_attachment($post_thumbnail_id); } } }
/** * Get the listing layout name from layout parameter. * * @since 1.0.0 * * @param string $layout_choice Listing layout. * @return string Layout name. */ function gdsc_validate_layout_choice($layout_choice) { switch (geodir_strtolower($layout_choice)) { case 'list': case 'one': case 'one_column': case 'onecolumn': case '1': $layout_choice = 'list'; break; case 'gridview_onehalf': case 'two': case 'two_column': case 'two_columns': case 'twocolumn': case 'twocolumns': case '2': $layout_choice = 'gridview_onehalf'; break; case 'gridview_onethird': case 'three': case 'three_column': case 'three_columns': case 'threecolumn': case 'threecolumns': case '3': $layout_choice = 'gridview_onethird'; break; case 'gridview_onefourth': case 'four': case 'four_column': case 'four_columns': case 'fourcolumn': case 'fourcolumns': case '4': $layout_choice = 'gridview_onefourth'; break; case 'gridview_onefifth': case 'five': case 'five_column': case 'five_columns': case 'fivecolumn': case 'fivecolumns': case '5': $layout_choice = 'gridview_onefifth'; break; default: $layout_choice = 'gridview_onehalf'; break; } return $layout_choice; }
/** * 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 // Fix for WPML removing page_id query var: if (isset($wp->query_vars['page']) && !isset($wp->query_vars['page_id']) && isset($wp->query_vars['pagename']) && !is_home()) { global $wpdb; $page_for_posts = get_option('page_for_posts'); $real_page_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type='page' AND post_name=%s", $wp->query_vars['pagename'])); if (function_exists('icl_object_id')) { $real_page_id = icl_object_id($real_page_id, 'page', true, ICL_LANGUAGE_CODE); } if ($real_page_id && $real_page_id != $page_for_posts) { $wp->query_vars['page_id'] = $real_page_id; } } // 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 is GD homepage set the page ID if (geodir_is_page('home')) { $wp->query_vars['page_id'] = get_option('page_on_front'); } // The location url format (all or country_city or region_city or city). $geodir_show_location_url = get_option('geodir_show_location_url'); 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 ($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) { // do all these only when it is a geodirectory 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 ($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 (geodir_strtolower($default_location->country_slug) == geodir_strtolower($gd_country) && geodir_strtolower($default_location->region_slug) == geodir_strtolower($gd_region) && geodir_strtolower($default_location->city_slug) == geodir_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 (geodir_strtolower($default_location->country_slug) == geodir_strtolower($gd_country) && geodir_strtolower($default_location->region_slug) == geodir_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 (geodir_strtolower($default_location->country_slug) == geodir_strtolower($gd_country)) { $is_geodir_location_found = true; } } } else { if ($geodir_show_location_url == 'country_city') { if (count($geodir_terms) >= 2) { $gd_country = urldecode($geodir_terms[0]); $gd_city = urldecode($geodir_terms[1]); } else { if (count($geodir_terms) >= 1) { $gd_country = urldecode($geodir_terms[0]); } } if (geodir_strtolower($default_location->country_slug) == geodir_strtolower($gd_country) && geodir_strtolower($default_location->city_slug) == geodir_strtolower($gd_city)) { $is_geodir_location_found = true; } // if location has not been found for country and city then search for country only if (!$is_geodir_location_found) { $gd_city = ''; if (geodir_strtolower($default_location->country_slug) == geodir_strtolower($gd_country)) { $is_geodir_location_found = true; } } } else { if ($geodir_show_location_url == 'region_city') { if (count($geodir_terms) >= 2) { $gd_region = urldecode($geodir_terms[0]); $gd_city = urldecode($geodir_terms[1]); } else { if (count($geodir_terms) >= 1) { $gd_region = urldecode($geodir_terms[0]); } } if (geodir_strtolower($default_location->region_slug) == geodir_strtolower($gd_region) && geodir_strtolower($default_location->city_slug) == geodir_strtolower($gd_city)) { $is_geodir_location_found = true; } // if location has not been found for region and city then search for region only if (!$is_geodir_location_found) { $gd_city = ''; if (geodir_strtolower($default_location->region_slug) == geodir_strtolower($gd_region)) { $is_geodir_location_found = true; } } } else { $gd_city = $geodir_terms[0]; if (geodir_strtolower($default_location->city_slug) == geodir_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 ($geodir_show_location_url == 'all') { } else { if ($geodir_show_location_url == 'country_city') { $gd_region = ''; } else { if ($geodir_show_location_url == 'region_city') { $gd_country = ''; } else { $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'; } } } } } // Unset location session if gd page and location not set. if (isset($wp->query_vars['gd_is_geodir_page']) && !isset($wp->query_vars['gd_country'])) { unset($_SESSION['gd_multi_location'], $_SESSION['gd_city'], $_SESSION['gd_region'], $_SESSION['gd_country']); } 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 ($geodir_show_location_url == 'all') { } else { if ($geodir_show_location_url == 'country_city') { if (isset($wp->query_vars['gd_region'])) { $wp->query_vars['gd_region'] = ''; } } else { if ($geodir_show_location_url == 'region_city') { if (isset($wp->query_vars['gd_country'])) { $wp->query_vars['gd_country'] = ''; } } 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'] = ''; } } } } } 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'] = ''; } } }
/** * Validate the event data. * * @since 1.5.1 * @package GeoDirectory * * @param array $gd_post Post array. * @return array Event data array. */ function geodir_imex_process_event_data($gd_post) { $recurring_pkg = geodir_event_recurring_pkg((object) $gd_post); $is_recurring = isset($gd_post['is_recurring_event']) && (int) $gd_post['is_recurring_event'] == 0 ? false : true; $event_date = isset($gd_post['event_date']) && $gd_post['event_date'] != '' ? geodir_imex_get_date_ymd($gd_post['event_date']) : ''; $event_enddate = isset($gd_post['event_enddate']) && $gd_post['event_enddate'] != '' ? geodir_imex_get_date_ymd($gd_post['event_enddate']) : $event_date; $all_day = isset($gd_post['is_whole_day_event']) && !empty($gd_post['is_whole_day_event']) ? true : false; $starttime = isset($gd_post['starttime']) && !$all_day ? $gd_post['starttime'] : ''; $endtime = isset($gd_post['endtime']) && !$all_day ? $gd_post['endtime'] : ''; $repeat_type = ''; $different_times = ''; $starttimes = ''; $endtimes = ''; $repeat_days = ''; $repeat_weeks = ''; $event_recurring_dates = ''; $repeat_x = ''; $duration_x = ''; $repeat_end_type = ''; $max_repeat = ''; $repeat_end = ''; if ($recurring_pkg && $is_recurring) { $repeat_type = $gd_post['recurring_type']; if ($repeat_type == 'custom') { $starttimes = !$all_day && !empty($gd_post['event_starttimes']) ? explode(",", $gd_post['event_starttimes']) : array(); $endtimes = !$all_day && !empty($gd_post['event_endtimes']) ? explode(",", $gd_post['event_endtimes']) : array(); if (!empty($starttimes) || !empty($endtimes)) { $different_times = true; } $recurring_dates = isset($gd_post['recurring_dates']) && $gd_post['recurring_dates'] != '' ? explode(",", $gd_post['recurring_dates']) : array(); if (!empty($recurring_dates)) { $event_recurring_dates = array(); foreach ($recurring_dates as $recurring_date) { $recurring_date = trim($recurring_date); if ($recurring_date != '') { $event_recurring_dates[] = geodir_imex_get_date_ymd($recurring_date); } } $event_recurring_dates = array_unique($event_recurring_dates); $event_recurring_dates = implode(",", $event_recurring_dates); } } else { $duration_x = !empty($gd_post['event_duration_days']) ? (int) $gd_post['event_duration_days'] : 1; $repeat_x = !empty($gd_post['recurring_interval']) ? (int) $gd_post['recurring_interval'] : 1; $max_repeat = !empty($gd_post['max_recurring_count']) ? (int) $gd_post['max_recurring_count'] : 1; $repeat_end = !empty($gd_post['recurring_end_date']) ? geodir_imex_get_date_ymd($gd_post['recurring_end_date']) : ''; $repeat_end_type = $repeat_end != '' ? 1 : 0; $max_repeat = $repeat_end != '' ? '' : $max_repeat; $week_days = array_flip(array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')); $a_repeat_days = isset($gd_post['recurring_week_days']) && trim($gd_post['recurring_week_days']) != '' ? explode(',', trim($gd_post['recurring_week_days'])) : array(); $repeat_days = array(); if (!empty($a_repeat_days)) { foreach ($a_repeat_days as $repeat_day) { $repeat_day = geodir_strtolower(trim($repeat_day)); if ($repeat_day != '' && isset($week_days[$repeat_day])) { $repeat_days[] = $week_days[$repeat_day]; } } $repeat_days = array_unique($repeat_days); } $a_repeat_weeks = isset($gd_post['recurring_week_nos']) && trim($gd_post['recurring_week_nos']) != '' ? explode(",", trim($gd_post['recurring_week_nos'])) : array(); $repeat_weeks = array(); if (!empty($a_repeat_weeks)) { foreach ($a_repeat_weeks as $repeat_week) { $repeat_weeks[] = (int) $repeat_week; } $repeat_weeks = array_unique($repeat_weeks); } } } if (isset($gd_post['recurring_dates'])) { unset($gd_post['recurring_dates']); } $gd_post['is_recurring'] = $is_recurring; $gd_post['event_date'] = $event_date; $gd_post['event_start'] = $event_date; $gd_post['event_end'] = $event_enddate; $gd_post['all_day'] = $all_day; $gd_post['starttime'] = $starttime; $gd_post['endtime'] = $endtime; $gd_post['repeat_type'] = $repeat_type; $gd_post['different_times'] = $different_times; $gd_post['starttimes'] = $starttimes; $gd_post['endtimes'] = $endtimes; $gd_post['repeat_days'] = $repeat_days; $gd_post['repeat_weeks'] = $repeat_weeks; $gd_post['event_recurring_dates'] = $event_recurring_dates; $gd_post['repeat_x'] = $repeat_x; $gd_post['duration_x'] = $duration_x; $gd_post['repeat_end_type'] = $repeat_end_type; $gd_post['max_repeat'] = $max_repeat; $gd_post['repeat_end'] = $repeat_end; return $gd_post; }
/** * Outputs the listings template title. * * @since 1.0.0 * @package GeoDirectory * @global object $wp The WordPress object. * @global string $term Current term slug. */ function geodir_action_listings_title() { global $wp, $term; $gd_post_type = geodir_get_current_posttype(); $post_type_info = get_post_type_object($gd_post_type); $add_string_in_title = __('All', 'geodirectory') . ' '; if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') { $add_string_in_title = __('My Favorite', 'geodirectory') . ' '; } $list_title = $add_string_in_title . __(ucfirst($post_type_info->labels->name), 'geodirectory'); $single_name = $post_type_info->labels->singular_name; $taxonomy = geodir_get_taxonomies($gd_post_type, true); $gd_country = get_query_var('gd_country'); $gd_region = get_query_var('gd_region'); $gd_city = get_query_var('gd_city'); if (!empty($term)) { $location_name = ''; if ($gd_country != '' || $gd_region != '' || $gd_city != '') { if ($gd_country != '') { $location_name = geodir_sanitize_location_name('gd_country', $gd_country); } if ($gd_region != '') { $location_name = geodir_sanitize_location_name('gd_region', $gd_region); } if ($gd_city != '') { $location_name = geodir_sanitize_location_name('gd_city', $gd_city); } } $current_term = get_term_by('slug', $term, $taxonomy[0]); if (!empty($current_term)) { $current_term_name = __(ucfirst($current_term->name), 'geodirectory'); if ($current_term_name != '' && $location_name != '' && isset($current_term->taxonomy) && $current_term->taxonomy == $gd_post_type . 'category') { $location_last_char = substr($location_name, -1); $location_name_attach = geodir_strtolower($location_last_char) == 's' ? __("'", 'geodirectory') : __("'s", 'geodirectory'); $list_title .= __(' in', 'geodirectory') . ' ' . $location_name . $location_name_attach . ' ' . $current_term_name; } else { $list_title .= __(' in', 'geodirectory') . " '" . $current_term_name . "'"; } } else { if (count($taxonomy) > 1) { $current_term = get_term_by('slug', $term, $taxonomy[1]); if (!empty($current_term)) { $current_term_name = __(ucfirst($current_term->name), 'geodirectory'); if ($current_term_name != '' && $location_name != '' && isset($current_term->taxonomy) && $current_term->taxonomy == $gd_post_type . 'category') { $location_last_char = substr($location_name, -1); $location_name_attach = geodir_strtolower($location_last_char) == 's' ? __("'", 'geodirectory') : __("'s", 'geodirectory'); $list_title .= __(' in', 'geodirectory') . ' ' . $location_name . $location_name_attach . ' ' . $current_term_name; } else { $list_title .= __(' in', 'geodirectory') . " '" . $current_term_name . "'"; } } } } } else { $gd_country = isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] != '' ? $wp->query_vars['gd_country'] : ''; $gd_region = isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] != '' ? $wp->query_vars['gd_region'] : ''; $gd_city = isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] != '' ? $wp->query_vars['gd_city'] : ''; $gd_country_actual = $gd_region_actual = $gd_city_actual = ''; if (function_exists('get_actual_location_name')) { $gd_country_actual = $gd_country != '' ? get_actual_location_name('country', $gd_country, true) : $gd_country; $gd_region_actual = $gd_region != '' ? get_actual_location_name('region', $gd_region) : $gd_region; $gd_city_actual = $gd_city != '' ? get_actual_location_name('city', $gd_city) : $gd_city; } if ($gd_city != '') { if ($gd_city_actual != '') { $gd_city = $gd_city_actual; } else { $gd_city = preg_replace('/-(\\d+)$/', '', $gd_city); $gd_city = preg_replace('/[_-]/', ' ', $gd_city); $gd_city = __(geodir_ucwords($gd_city), 'geodirectory'); } $list_title .= __(' in', 'geodirectory') . " '" . $gd_city . "'"; } else { if ($gd_region != '') { if ($gd_region_actual != '') { $gd_region = $gd_region_actual; } else { $gd_region = preg_replace('/-(\\d+)$/', '', $gd_region); $gd_region = preg_replace('/[_-]/', ' ', $gd_region); $gd_region = __(geodir_ucwords($gd_region), 'geodirectory'); } $list_title .= __(' in', 'geodirectory') . " '" . $gd_region . "'"; } else { if ($gd_country != '') { if ($gd_country_actual != '') { $gd_country = $gd_country_actual; } else { $gd_country = preg_replace('/-(\\d+)$/', '', $gd_country); $gd_country = preg_replace('/[_-]/', ' ', $gd_country); $gd_country = __(geodir_ucwords($gd_country), 'geodirectory'); } $list_title .= __(' in', 'geodirectory') . " '" . $gd_country . "'"; } } } } if (is_search()) { $list_title = __('Search', 'geodirectory') . ' ' . __(ucfirst($post_type_info->labels->name), 'geodirectory') . __(' For :', 'geodirectory') . " '" . get_search_query() . "'"; } /** This action is documented in geodirectory_template_actions.php */ $class = apply_filters('geodir_page_title_class', 'entry-title fn'); /** This action is documented in geodirectory_template_actions.php */ $class_header = apply_filters('geodir_page_title_header_class', 'entry-header'); $title = $list_title; if (geodir_is_page('pt')) { $gd_page = 'pt'; $title = get_option('geodir_page_title_pt') ? get_option('geodir_page_title_pt') : $title; } elseif (geodir_is_page('listing')) { $gd_page = 'listing'; global $wp_query; $current_term = $wp_query->get_queried_object(); if (strpos($current_term->taxonomy, '_tags') !== false) { $title = get_option('geodir_page_title_tag-listing') ? get_option('geodir_page_title_tag-listing') : $title; } else { $title = get_option('geodir_page_title_cat-listing') ? get_option('geodir_page_title_cat-listing') : $title; } } elseif (geodir_is_page('author')) { $gd_page = 'author'; if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') { $title = get_option('geodir_page_title_favorite') ? get_option('geodir_page_title_favorite') : $title; } else { $title = get_option('geodir_page_title_author') ? get_option('geodir_page_title_author') : $title; } } /** * Filter page title to replace variables. * * @since 1.5.4 * @param string $title The page title including variables. * @param string $gd_page The GeoDirectory page type if any. */ $title = apply_filters('geodir_seo_page_title', __($title, 'geodirectory'), $gd_page); echo '<header class="' . $class_header . '"><h1 class="' . $class . '">' . apply_filters('geodir_listing_page_title', $title) . '</h1></header>'; }
/** * The geodirectory related listing widget shortcode. * * This implements the functionality of the shortcode for displaying related listing widget. * * @since 1.0.0 * @package GeoDirectory * @param array $atts { * Attributes of the shortcode. * * @type int $add_location_filter Filter listings using current location. Default 0. * @type string $before_title HTML content to prepend to the title when displayed. Default. <style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>. * @type int $character_count The excerpt length Default. 20. * @type int $is_widget Is this a widget? Default. 1. * @type string $layout Layout to display listing. Should be gridview_onehalf, gridview_onethird, * gridview_onefourth, gridview_onefifth, list. Default 'gridview_onehalf'. Default. gridview_onehalf. * @type string $list_sort Sort by. Default. latest. * @type string $listing_width Width of the listing in %. Default. Empty. * @type int $post_number No. of post to display. Default. 5. * @type string $relate_to Type to use for making relation. Can be tags or category. Default. category. * * } * @return string Related widget HTML. */ function geodir_sc_related_listings($atts) { ob_start(); $defaults = array('post_number' => 5, 'relate_to' => 'category', 'layout' => 'gridview_onehalf', 'add_location_filter' => 0, 'listing_width' => '', 'list_sort' => 'latest', 'character_count' => 20, 'is_widget' => 1, 'before_title' => '<style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>'); // The "before_title" code is an ugly & terrible hack. But it works for now. I should enqueue a new stylesheet. $params = shortcode_atts($defaults, $atts); /** * Begin validating parameters */ // Validate that post_number is a number and is 1 or higher $params['post_number'] = absint($params['post_number']); if (0 === $params['post_number']) { $params['post_number'] = 1; } // Validate relate_to - only category or tags $params['relate_to'] = geodir_strtolower($params['relate_to']); if ('category' != $params['relate_to'] && 'tags' != $params['relate_to']) { $params['relate_to'] = 'category'; } // Validate layout selection $params['layout'] = gdsc_validate_layout_choice($params['layout']); // Validate sorting option $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort']); // Validate add_location_filter $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); // Validate listing_width $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); // Validate character_count $params['character_count'] = absint($params['character_count']); if (20 > $params['character_count']) { $params['character_count'] = 20; } if ($related_display = geodir_related_posts_display($params)) { echo $related_display; } $output = ob_get_contents(); ob_end_clean(); return $output; }