/** * Performs front-end pre-header functionality * * - This function is not called on admin side. * - Loads conditional CSS styles. * - Determines if page is single property or property overview. * * @since 1.11 */ public function template_redirect() { global $post, $property, $wp_query, $wp_properties, $wp_styles, $wpp_query; /** * HACK. * @see self::parse_request(); * @author peshkov@UD */ if (get_query_var('_fix_to_page_template')) { $wp_query->is_single = false; $wp_query->is_page = true; } wp_localize_script('wpp-localization', 'wpp', array('instance' => $this->get_instance())); //** Load global wp-property script on all frontend pages */ wp_enqueue_script('wp-property-global'); if (apply_filters('wpp::custom_styles', false) === false) { //** Possibly load essential styles that are used in widgets */ wp_enqueue_style('wp-property-frontend'); //** Possibly load theme specific styles */ wp_enqueue_style('wp-property-theme-specific'); } if (!isset($wp_properties['configuration']['do_not_enable_text_widget_shortcodes']) || $wp_properties['configuration']['do_not_enable_text_widget_shortcodes'] != 'true') { add_filter('widget_text', 'do_shortcode'); } do_action('wpp_template_redirect'); //** Handle single property page previews */ if (!empty($wp_query->query_vars['preview']) && $post->post_type == "property" && $post->post_status == "publish") { wp_redirect(get_permalink($post->ID)); die; } /* (count($wp_query->posts) < 2) added post 1.31.1 release */ /* to avoid taxonomy archives from being broken by single property pages */ if (isset($post) && count($wp_query->posts) < 2 && ($post->post_type == "property" || isset($wp_query->is_child_property))) { $wp_query->single_property_page = true; //** This is a hack and should be done better */ if (!$post) { $post = get_post($wp_query->queried_object_id); $wp_query->posts[0] = $post; $wp_query->post = $post; } } //** If viewing root property page that is the default dynamic page. */ if (isset($wp_query->wpp_default_property_page)) { $wp_query->is_property_overview = true; } //** If this is the root page with a manually inserted shortcode, or any page with a PO shortcode */ if (isset($post) && strpos($post->post_content, "property_overview")) { $wp_query->is_property_overview = true; } //** If this is the root page and the shortcode is automatically inserted */ if (isset($wp_query->wpp_root_property_page) && $wp_properties['configuration']['automatically_insert_overview'] == 'true') { $wp_query->is_property_overview = true; } //** If search result page, and system not explicitly configured to not include PO on search result page automatically */ if (isset($wp_query->wpp_search_page) && (!isset($wp_properties['configuration']['do_not_override_search_result_page']) || $wp_properties['configuration']['do_not_override_search_result_page'] != 'true')) { $wp_query->is_property_overview = true; } //** Scripts and styles to load on all overview and single listing pages */ if (isset($wp_query->single_property_page) || isset($wp_query->is_property_overview)) { // Check for and load conditional browser styles $conditional_styles = apply_filters('wpp_conditional_style_slugs', array('IE', 'IE 7', 'msie')); foreach ($conditional_styles as $type) { // Fix slug for URL $url_slug = strtolower(str_replace(" ", "_", $type)); if (file_exists(STYLESHEETPATH . "/wp_properties-{$url_slug}.css")) { wp_register_style('wp-property-frontend-' . $url_slug, get_bloginfo('stylesheet_directory') . "/wp_properties-{$url_slug}.css", array('wp-property-frontend'), '1.13'); } elseif (file_exists(TEMPLATEPATH . "/wp_properties-{$url_slug}.css")) { wp_register_style('wp-property-frontend-' . $url_slug, get_bloginfo('template_url') . "/wp_properties-{$url_slug}.css", array('wp-property-frontend'), '1.13'); } elseif (file_exists(WPP_URL . "styles/wp_properties-{$url_slug}.css") && $wp_properties['configuration']['autoload_css'] == 'true') { wp_register_style('wp-property-frontend-' . $url_slug, WPP_URL . "styles/wp_properties-{$url_slug}.css", array('wp-property-frontend'), WPP_Version); } // Mark every style as conditional $wp_styles->add_data('wp-property-frontend-' . $url_slug, 'conditional', $type); wp_enqueue_style('wp-property-frontend-' . $url_slug); } } //** Scripts loaded only on single property pages */ if (isset($wp_query->single_property_page)) { WPP_F::console_log('Including scripts for all single property pages.'); WPP_F::load_assets(array('single')); do_action('template_redirect_single_property'); add_action('wp_head', create_function('', "do_action('wp_head_single_property'); ")); $property = (array) WPP_F::get_property($post->ID, "load_gallery=true"); $property_type = !empty($property['property_type']) ? $property['property_type'] : false; // Redirect to parent if property type is non-public. if (isset($wp_properties['redirect_to_parent']) && is_array($wp_properties['redirect_to_parent']) && in_array($property_type, $wp_properties['redirect_to_parent']) && $property['post_parent']) { die(wp_redirect(get_permalink($property['post_parent']))); } $property = prepare_property_for_display($property); //** Make certain variables available to be used within the single listing page */ $single_page_vars = apply_filters('wpp_property_page_vars', array('property' => $property, 'wp_properties' => $wp_properties)); //** By merging our extra variables into $wp_query->query_vars they will be extracted in load_template() */ if (is_array($single_page_vars)) { $wp_query->query_vars = array_merge($wp_query->query_vars, $single_page_vars); } } //** Current requests includes a property overview. PO may be via shortcode, search result, or due to this being the Default Dynamic Property page */ if (isset($wp_query->is_property_overview)) { WPP_F::console_log('Including scripts for all property overview pages.'); WPP_F::load_assets(array('overview')); if (isset($wp_query->wpp_default_property_page)) { WPP_F::console_log('Dynamic Default Property page detected, will load custom template.'); } else { WPP_F::console_log('Custom Default Property page detected, property overview content may be rendered via shortcode.'); } //** Make certain variables available to be used within the single listing page */ $overview_page_vars = apply_filters('wpp_overview_page_vars', array('wp_properties' => $wp_properties, 'wpp_query' => $wpp_query)); //** By merging our extra variables into $wp_query->query_vars they will be extracted in load_template() */ if (is_array($overview_page_vars)) { $wp_query->query_vars = array_merge($wp_query->query_vars, $overview_page_vars); } do_action('template_redirect_property_overview'); add_action('wp_head', create_function('', "do_action('wp_head_property_overview'); ")); } do_action('wpp_template_redirect_post_scripts'); }