From 8b44ee9d93148bca4f73df48eb2906c8b66d15e3 Mon Sep 17 00:00:00 2001 From: rboren Date: Wed, 30 Jun 2004 15:31:49 +0000 Subject: [PATCH] Add WP_Query_State class. Introduce is_single(), is_archive(), and friends. git-svn-id: http://svn.automattic.com/wordpress/trunk@1449 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-blog-header.php | 2 + wp-includes/classes.php | 129 ++++++++++++++++++++++++++++++++++++++ wp-includes/functions.php | 48 ++++++++++++++ wp-settings.php | 1 + 4 files changed, 180 insertions(+) create mode 100644 wp-includes/classes.php diff --git a/wp-blog-header.php b/wp-blog-header.php index 18f80f02d1..ddb4c646c4 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -147,6 +147,8 @@ foreach (array_merge($wpvarstoreset, $more_wpvars) as $wpvar) { $query_string = apply_filters('query_string', $query_string); +$wp_query_state->parse_query($query_string); + // Update some caches. update_category_cache(); diff --git a/wp-includes/classes.php b/wp-includes/classes.php new file mode 100644 index 0000000000..0e2652fb7f --- /dev/null +++ b/wp-includes/classes.php @@ -0,0 +1,129 @@ +single = false; + $this->archive = false; + $this->date = false; + $this->author = false; + $this->category = false; + $this->search = false; + $this->feed = false; + $this->home = false; + } + + function parse_query ($query) { + parse_str($query); + $this->init(); + + if ('' != $m) { + $this->date = true; + } + + if ('' != $hour) { + $this->date = true; + } + + if ('' != $minute) { + $this->date = true; + } + + if ('' != $second) { + $this->date = true; + } + + if ('' != $year) { + $this->date = true; + } + + if ('' != $monthnum) { + $this->date = true; + } + + if ('' != $day) { + $this->date = true; + } + + if ('' != $w) { + $this->date = true; + } + + if ('' != $name) { + $this->single = true; + } + + if (($p != '') && ($p != 'all')) { + $this->single = true; + } + + if (!empty($s)) { + $this->search = true; + } + + if ((empty($cat)) || ($cat == 'all') || ($cat == '0') || + // Bypass cat checks if fetching specific posts + ( + intval($year) || intval($monthnum) || intval($day) || intval($w) || + intval($p) || !empty($name) || !empty($s) + ) + ) { + $this->category = false; + } else { + if (stristr($cat,'-')) { + $this->category = false; + } else { + $this->category = true; + } + } + + if ('' != $category_name) { + $this->category = true; + } + + if ((empty($author)) || ($author == 'all') || ($author == '0')) { + $this->author = false; + } else { + $this->author = true; + } + + if ('' != $author_name) { + $this->author = true; + } + + if ('' != $feed) { + $this->feed = true; + } + + if ( ($this->date || $this->author || $this->category) + && (! $this->single)) { + $this->archive = true; + } + + if ( ! ($this->archive || $this->single || $this->search || $this->feed)) { + $this->home = true; + } + + } + + function WP_Query_State ($query = '') { + if (! empty($query)) { + $this->parse_query($query); + } + } +} + +// Make a global instance. +if (! isset($wp_query_state)) { + $wp_query_state = new WP_Query_State(); +} + +?> diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 527bdfbd9a..70460d865f 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1805,4 +1805,52 @@ function wp_head() { do_action('wp_head', ''); } +function is_single () { + global $wp_query_state; + + return $wp_query_state->single; +} + +function is_archive () { + global $wp_query_state; + + return $wp_query_state->archive; +} + +function is_date () { + global $wp_query_state; + + return $wp_query_state->date; +} + +function is_author () { + global $wp_query_state; + + return $wp_query_state->author; +} + +function is_category () { + global $wp_query_state; + + return $wp_query_state->category; +} + +function is_search () { + global $wp_query_state; + + return $wp_query_state->search; +} + +function is_feed () { + global $wp_query_state; + + return $wp_query_state->search; +} + +function is_home () { + global $wp_query_state; + + return $wp_query_state->home; +} + ?> \ No newline at end of file diff --git a/wp-settings.php b/wp-settings.php index 26a44ae12f..a2c4353b46 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -47,6 +47,7 @@ if ( !(phpversion() >= '4.1') ) die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.1' ); +require (ABSPATH . WPINC . '/classes.php'); require (ABSPATH . WPINC . '/functions.php'); timer_start(); require (ABSPATH . WPINC . '/functions-formatting.php');