/** * Get Current Post Type. * * @since 1.0.0 * @package GeoDirectory * @global object $wp_query WordPress Query object. * @global string $geodir_post_type The post type. * @return string The post type. */ function geodir_get_current_posttype() { global $wp_query, $geodir_post_type; $geodir_post_type = get_query_var('post_type'); if (geodir_is_page('add-listing') || geodir_is_page('preview')) { if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $geodir_post_type = get_post_type($_REQUEST['pid']); } elseif (isset($_REQUEST['listing_type'])) { $geodir_post_type = $_REQUEST['listing_type']; } } if ((geodir_is_page('search') || geodir_is_page('author')) && isset($_REQUEST['stype'])) { $geodir_post_type = $_REQUEST['stype']; } if (is_tax()) { $geodir_post_type = geodir_get_taxonomy_posttype(); } $all_postypes = geodir_get_posttypes(); $all_postypes = stripslashes_deep($all_postypes); if (is_array($all_postypes) && !in_array($geodir_post_type, $all_postypes)) { $geodir_post_type = ''; } return $geodir_post_type; }
/** * Check that page is. * * @since 1.0.0 * @package GeoDirectory * @global object $wp_query WordPress Query object. * @global object $post The current post object. * @param string $gdpage The page type. * @return bool If valid returns true. Otherwise false. */ function geodir_is_page($gdpage = '') { global $wp_query, $post; //if(!is_admin()): switch ($gdpage) { case 'add-listing': if (is_page() && get_query_var('page_id') == geodir_add_listing_page_id()) { return true; } elseif (is_page() && isset($post->post_content) && has_shortcode($post->post_content, 'gd_add_listing')) { return true; } break; case 'preview': if (is_page() && get_query_var('page_id') == geodir_preview_page_id() && isset($_REQUEST['listing_type']) && in_array($_REQUEST['listing_type'], geodir_get_posttypes())) { return true; } break; case 'listing-success': if (is_page() && get_query_var('page_id') == geodir_success_page_id()) { return true; } break; case 'detail': if (is_single() && in_array(get_query_var('post_type'), geodir_get_posttypes())) { return true; } break; case 'listing': if (is_tax() && geodir_get_taxonomy_posttype()) { global $current_term, $taxonomy, $term; return true; } if (is_post_type_archive() && in_array(get_query_var('post_type'), geodir_get_posttypes())) { return true; } break; case 'location': if (is_page() && get_query_var('page_id') == geodir_location_page_id()) { return true; } break; case 'author': if (is_author() && isset($_REQUEST['geodir_dashbord'])) { return true; } break; case 'search': if (is_search() && isset($_REQUEST['geodir_search'])) { return true; } break; default: return false; break; } //endif; return false; }
function geodir_get_request_param() { global $current_term, $wp_query; $request_param = array(); if (is_tax() && geodir_get_taxonomy_posttype() && is_object($current_term)) { $request_param['geo_url'] = 'is_term'; $request_param['geo_term_id'] = $current_term->term_id; $request_param['geo_taxonomy'] = $current_term->taxonomy; } elseif (is_post_type_archive() && in_array(get_query_var('post_type'), geodir_get_posttypes())) { $request_param['geo_url'] = 'is_archive'; $request_param['geo_posttype'] = get_query_var('post_type'); } elseif (is_author() && isset($_REQUEST['geodir_dashbord'])) { $request_param['geo_url'] = 'is_author'; $request_param['geo_posttype'] = $_REQUEST['stype']; } elseif (is_search() && isset($_REQUEST['geodir_search'])) { $request_param['geo_url'] = 'is_search'; $request_param['geo_request_uri'] = $_SERVER['QUERY_STRING']; } else { $request_param['geo_url'] = 'is_location'; } return json_encode($request_param); }
/** * Update markers on category Edit. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @param string $term_id The term ID as string. * @param int $tt_id The term taxonomy ID. * @param string $taxonomy The taxonomy slug. */ function geodir_update_markers_oncatedit($term_id, $tt_id, $taxonomy) { global $plugin_prefix, $wpdb; $gd_taxonomies = geodir_get_taxonomies(); if (is_array($gd_taxonomies) && in_array($taxonomy, $gd_taxonomies)) { $geodir_post_type = geodir_get_taxonomy_posttype($taxonomy); $table = $plugin_prefix . $geodir_post_type . '_detail'; $path_parts = pathinfo($_REQUEST['ct_cat_icon']['src']); $term_icon = $path_parts['dirname'] . '/cat_icon_' . $term_id . '.png'; $posts = $wpdb->get_results($wpdb->prepare("SELECT post_id,post_title,post_latitude,post_longitude,default_category FROM " . $table . " WHERE FIND_IN_SET(%s,%1\$s ) ", array($term_id, $taxonomy))); if (!empty($posts)) { foreach ($posts as $post_obj) { $lat = $post_obj->post_latitude; $lng = $post_obj->post_longitude; $json = '{'; $json .= '"id":"' . $post_obj->post_id . '",'; $json .= '"lat_pos": "' . $lat . '",'; $json .= '"long_pos": "' . $lng . '",'; $json .= '"marker_id":"' . $post_obj->post_id . '_' . $term_id . '",'; $json .= '"icon":"' . $term_icon . '",'; $json .= '"group":"catgroup' . $term_id . '"'; $json .= '}'; if ($post_obj->default_category == $term_id) { $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET marker_json = %s where post_id = %d", array($json, $post_obj->post_id))); } $wpdb->query($wpdb->prepare("UPDATE " . GEODIR_ICON_TABLE . " SET json = %s WHERE post_id = %d AND cat_id = %d", array($json, $post_obj->post_id, $term_id))); } } } }
/** * Locates template based on the template type. * * @since 1.0.0 * @package GeoDirectory * @global string $post_type The post type. * @global object $wp WordPress object. * @global object $post WordPress post object. * @param string $template The template type. * @return bool|string The template path. */ function geodir_locate_template($template = '') { global $post_type, $wp, $post; $fields = array(); switch ($template) { case 'signup': return $template = locate_template(array("geodirectory/geodir-signup.php")); break; case 'add-listing': $sc_post_type = ''; if (is_page() && isset($post->post_content) && has_shortcode($post->post_content, 'gd_add_listing')) { $listing_page_id = $post->ID; $regex_pattern = get_shortcode_regex(); preg_match('/' . $regex_pattern . '/s', $post->post_content, $regex_matches); if (!empty($regex_matches) && isset($regex_matches[2]) == 'gd_add_listing' && isset($regex_matches[3])) { $shortcode_atts = shortcode_parse_atts($regex_matches[3]); $sc_post_type = !empty($shortcode_atts) && isset($shortcode_atts['listing_type']) && !empty($shortcode_atts['listing_type']) ? $shortcode_atts['listing_type'] : ''; } } else { $listing_page_id = geodir_add_listing_page_id(); } $is_wpml = function_exists('icl_object_id') ? true : false; if ($listing_page_id != '' && (is_page($listing_page_id) || $is_wpml && !empty($wp->query_vars['page_id'])) && isset($_REQUEST['listing_type']) && in_array($_REQUEST['listing_type'], geodir_get_posttypes())) { $post_type = $_REQUEST['listing_type']; } if (empty($post_type) && !isset($_REQUEST['pid'])) { $pagename = $wp->query_vars['pagename']; $post_types = geodir_get_posttypes(); if (!empty($post_types)) { $post_type = $post_types[0]; } if ($sc_post_type != '') { $post_type = $sc_post_type; } if ($is_wpml && !empty($wp->query_vars['page_id'])) { wp_redirect(geodir_getlink(get_permalink($wp->query_vars['page_id']), array('listing_type' => $post_type))); } else { wp_redirect(trailingslashit(get_site_url()) . $pagename . '/?listing_type=' . $post_type); } exit; } return $template = locate_template(array("geodirectory/add-{$post_type}.php", "geodirectory/add-listing.php")); break; case 'success': $success_page_id = geodir_success_page_id(); if ($success_page_id != '' && is_page($success_page_id) && isset($_REQUEST['listing_type']) && in_array($_REQUEST['listing_type'], geodir_get_posttypes())) { $post_type = $_REQUEST['listing_type']; } return $template = locate_template(array("geodirectory/{$post_type}-success.php", "geodirectory/listing-success.php")); break; case 'detail': case 'preview': if (in_array(get_post_type(), geodir_get_posttypes())) { $post_type = get_post_type(); } return $template = locate_template(array("geodirectory/single-{$post_type}.php", "geodirectory/listing-detail.php")); break; case 'listing': $templates = array(); if (is_post_type_archive() && in_array(get_post_type(), geodir_get_posttypes())) { $post_type = get_post_type(); $templates[] = "geodirectory/archive-{$post_type}.php"; } if (is_tax() && geodir_get_taxonomy_posttype()) { $query_obj = get_queried_object(); $curr_taxonomy = isset($query_obj->taxonomy) ? $query_obj->taxonomy : ''; $curr_term = isset($query_obj->slug) ? $query_obj->slug : ''; $templates[] = "geodirectory/taxonomy-{$curr_taxonomy}-{$curr_term}.php"; $templates[] = "geodirectory/taxonomy-{$curr_taxonomy}.php"; } $templates[] = "geodirectory/geodir-listing.php"; return $template = locate_template($templates); break; case 'information': return $template = locate_template(array("geodirectory/geodir-information.php")); break; case 'author': return $template = locate_template(array("geodirectory/geodir-author.php")); break; case 'search': return $template = locate_template(array("geodirectory/geodir-search.php")); break; case 'location': return $template = locate_template(array("geodirectory/geodir-location.php")); break; case 'geodir-home': return $template = locate_template(array("geodirectory/geodir-home.php")); break; case 'listing-listview': $template = locate_template(array("geodirectory/listing-listview.php")); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/listing-listview.php'; } return $template; break; case 'widget-listing-listview': $template = locate_template(array("geodirectory/widget-listing-listview.php")); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/widget-listing-listview.php'; } return $template; break; } return false; }
/** * Check that page is. * * @since 1.0.0 * @since 1.5.6 Added to check GD invoices and GD checkout pages. * @since 1.5.7 Updated to validate buddypress dashboard listings page as a author page. * @package GeoDirectory * @global object $wp_query WordPress Query object. * @global object $post The current post object. * @param string $gdpage The page type. * @return bool If valid returns true. Otherwise false. */ function geodir_is_page($gdpage = '') { global $wp_query, $post, $wp; //if(!is_admin()): switch ($gdpage) { case 'add-listing': if (is_page() && get_query_var('page_id') == geodir_add_listing_page_id()) { return true; } elseif (is_page() && isset($post->post_content) && has_shortcode($post->post_content, 'gd_add_listing')) { return true; } break; case 'preview': if (is_page() && get_query_var('page_id') == geodir_preview_page_id() && isset($_REQUEST['listing_type']) && in_array($_REQUEST['listing_type'], geodir_get_posttypes())) { return true; } break; case 'listing-success': if (is_page() && get_query_var('page_id') == geodir_success_page_id()) { return true; } break; case 'detail': if (is_single() && in_array(get_query_var('post_type'), geodir_get_posttypes())) { return true; } break; case 'pt': if (is_post_type_archive() && in_array(get_query_var('post_type'), geodir_get_posttypes()) && !is_tax()) { return true; } break; case 'listing': if (is_tax() && geodir_get_taxonomy_posttype()) { global $current_term, $taxonomy, $term; return true; } if (is_post_type_archive() && in_array(get_query_var('post_type'), geodir_get_posttypes())) { return true; } break; case 'home': if (is_page() && get_query_var('page_id') == geodir_home_page_id() || is_page_geodir_home()) { return true; } break; case 'location': if (is_page() && get_query_var('page_id') == geodir_location_page_id()) { return true; } break; case 'author': if (is_author() && isset($_REQUEST['geodir_dashbord'])) { return true; } if (function_exists('bp_loggedin_user_id') && function_exists('bp_displayed_user_id') && ($my_id = (int) bp_loggedin_user_id())) { if (((bool) bp_is_current_component('listings') || (bool) bp_is_current_component('favorites')) && $my_id > 0 && $my_id == (int) bp_displayed_user_id()) { return true; } } break; case 'search': if (is_search() && isset($_REQUEST['geodir_search'])) { return true; } break; case 'info': if (is_page() && get_query_var('page_id') == geodir_info_page_id()) { return true; } break; case 'login': if (is_page() && get_query_var('page_id') == geodir_login_page_id()) { return true; } break; case 'checkout': if (is_page() && function_exists('geodir_payment_checkout_page_id') && get_query_var('page_id') == geodir_payment_checkout_page_id()) { return true; } break; case 'invoices': if (is_page() && function_exists('geodir_payment_invoices_page_id') && get_query_var('page_id') == geodir_payment_invoices_page_id()) { return true; } break; default: return false; break; } //endif; return false; }