Handle robots.txt requests and obey blog_plubic setting.

git-svn-id: http://svn.automattic.com/wordpress/trunk@3791 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-05-22 22:06:06 +00:00
parent e5e2b93053
commit 419f125cb7
6 changed files with 37 additions and 4 deletions

View File

@ -73,7 +73,7 @@ class retrospam_mgr {
} }
class WP { 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 $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type');
var $extra_query_vars = array(); var $extra_query_vars = array();

View File

@ -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_rss2', 'do_feed_rss2', 10, 1);
add_action('do_feed_atom', 'do_feed_atom', 10, 1); add_action('do_feed_atom', 'do_feed_atom', 10, 1);
add_action('do_pings', 'do_all_pings', 10, 1); add_action('do_pings', 'do_all_pings', 10, 1);
add_action('do_robots', 'do_robots');
?> ?>

View File

@ -1655,6 +1655,16 @@ function do_feed_atom() {
load_template(ABSPATH . 'wp-atom.php'); 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() { function is_blog_installed() {
global $wpdb; global $wpdb;
$wpdb->hide_errors(); $wpdb->hide_errors();

View File

@ -157,6 +157,12 @@ function is_preview() {
return $wp_query->is_preview; return $wp_query->is_preview;
} }
function is_robots() {
global $wp_query;
return $wp_query->is_robots;
}
function is_search () { function is_search () {
global $wp_query; global $wp_query;
@ -272,6 +278,7 @@ class WP_Query {
var $is_comments_popup = false; var $is_comments_popup = false;
var $is_admin = false; var $is_admin = false;
var $is_attachment = false; var $is_attachment = false;
var $is_robots = false;
function init_query_flags() { function init_query_flags() {
$this->is_single = false; $this->is_single = false;
@ -292,6 +299,7 @@ class WP_Query {
$this->is_paged = false; $this->is_paged = false;
$this->is_admin = false; $this->is_admin = false;
$this->is_attachment = false; $this->is_attachment = false;
$this->is_robots = false;
} }
function init () { function init () {
@ -321,6 +329,11 @@ class WP_Query {
$this->query_vars = $qv; $this->query_vars = $qv;
} }
if ( ! empty($qv['robots']) ) {
$this->is_robots = true;
return;
}
if ('404' == $qv['error']) { if ('404' == $qv['error']) {
$this->is_404 = true; $this->is_404 = true;
if ( !empty($query) ) { if ( !empty($query) ) {

View File

@ -696,6 +696,9 @@ class WP_Rewrite {
return $rewrite; return $rewrite;
} }
// robots.txt
$robots_rewrite = array('robots.txt$' => $this->index . '?robots=1');
// Post // Post
$post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, EP_PERMALINK); $post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, EP_PERMALINK);
$post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite); $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); $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
// Put them together. // 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)); do_action('generate_rewrite_rules', array(&$this));
$this->rules = apply_filters('rewrite_rules_array', $this->rules); $this->rules = apply_filters('rewrite_rules_array', $this->rules);

View File

@ -1,7 +1,10 @@
<?php <?php
if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) { if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
do_action('template_redirect'); do_action('template_redirect');
if ( is_feed() ) { if ( is_robots() ) {
do_action('do_robots');
exit;
} else if ( is_feed() ) {
do_feed(); do_feed();
exit; exit;
} else if ( is_trackback() ) { } else if ( is_trackback() ) {
@ -55,7 +58,10 @@ if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
} }
} else { } else {
// Process feeds and trackbacks even if not using themes. // Process feeds and trackbacks even if not using themes.
if ( is_feed() ) { if ( is_robots() ) {
do_action('do_robots');
exit;
} else if ( is_feed() ) {
do_feed(); do_feed();
exit; exit;
} else if ( is_trackback() ) { } else if ( is_trackback() ) {