From 419f125cb77af2469a34e744f01d2992977f26a8 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 22 May 2006 22:06:06 +0000 Subject: [PATCH] Handle robots.txt requests and obey blog_plubic setting. git-svn-id: http://svn.automattic.com/wordpress/trunk@3791 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/classes.php | 2 +- wp-includes/default-filters.php | 1 + wp-includes/functions.php | 10 ++++++++++ wp-includes/query.php | 13 +++++++++++++ wp-includes/rewrite.php | 5 ++++- wp-includes/template-loader.php | 10 ++++++++-- 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 65bf85a1f..79709dbf1 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -73,7 +73,7 @@ class retrospam_mgr { } class WP { - var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview'); + var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots'); var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type'); var $extra_query_vars = array(); diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index f45b3f4a7..0c5ad99d7 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -94,4 +94,5 @@ add_action('do_feed_rss', 'do_feed_rss', 10, 1); add_action('do_feed_rss2', 'do_feed_rss2', 10, 1); add_action('do_feed_atom', 'do_feed_atom', 10, 1); add_action('do_pings', 'do_all_pings', 10, 1); +add_action('do_robots', 'do_robots'); ?> diff --git a/wp-includes/functions.php b/wp-includes/functions.php index e003d8d8e..042dfa5be 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1655,6 +1655,16 @@ function do_feed_atom() { load_template(ABSPATH . 'wp-atom.php'); } +function do_robots() { + if ( '1' != get_option('blog_public') ) { + echo "User-agent: *\n"; + echo "Disallow: /\n"; + } else { + echo "User-agent: *\n"; + echo "Disallow:\n"; + } +} + function is_blog_installed() { global $wpdb; $wpdb->hide_errors(); diff --git a/wp-includes/query.php b/wp-includes/query.php index e6c82988a..79cd3d812 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -157,6 +157,12 @@ function is_preview() { return $wp_query->is_preview; } +function is_robots() { + global $wp_query; + + return $wp_query->is_robots; +} + function is_search () { global $wp_query; @@ -272,6 +278,7 @@ class WP_Query { var $is_comments_popup = false; var $is_admin = false; var $is_attachment = false; + var $is_robots = false; function init_query_flags() { $this->is_single = false; @@ -292,6 +299,7 @@ class WP_Query { $this->is_paged = false; $this->is_admin = false; $this->is_attachment = false; + $this->is_robots = false; } function init () { @@ -321,6 +329,11 @@ class WP_Query { $this->query_vars = $qv; } + if ( ! empty($qv['robots']) ) { + $this->is_robots = true; + return; + } + if ('404' == $qv['error']) { $this->is_404 = true; if ( !empty($query) ) { diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php index ffc5d55d6..48fa20b80 100644 --- a/wp-includes/rewrite.php +++ b/wp-includes/rewrite.php @@ -696,6 +696,9 @@ class WP_Rewrite { return $rewrite; } + // robots.txt + $robots_rewrite = array('robots.txt$' => $this->index . '?robots=1'); + // Post $post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, EP_PERMALINK); $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite); @@ -730,7 +733,7 @@ class WP_Rewrite { $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite); // Put them together. - $this->rules = array_merge($page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules); + $this->rules = array_merge($robots_rewrite, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules); do_action('generate_rewrite_rules', array(&$this)); $this->rules = apply_filters('rewrite_rules_array', $this->rules); diff --git a/wp-includes/template-loader.php b/wp-includes/template-loader.php index 3f8299f43..ea7ae82d2 100644 --- a/wp-includes/template-loader.php +++ b/wp-includes/template-loader.php @@ -1,7 +1,10 @@