2003-12-11 01:22:36 +01:00
< ? php
2004-08-24 10:43:01 +02:00
if ( ! isset ( $wp_did_header )) :
2005-02-14 01:49:03 +01:00
if ( ! file_exists ( dirname ( __FILE__ ) . '/wp-config.php' ) ) {
if ( strstr ( $_SERVER [ 'PHP_SELF' ], 'wp-admin' ) ) $path = '' ;
else $path = 'wp-admin/' ;
die ( " There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href=' { $path } setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file. " );
}
2003-12-11 01:22:36 +01:00
2005-02-13 22:20:00 +01:00
$wp_did_header = true ;
2004-07-06 19:58:48 +02:00
require_once ( dirname ( __FILE__ ) . '/wp-config.php' );
2003-12-11 01:22:36 +01:00
2004-08-27 22:59:38 +02:00
$query_vars = array ();
// Process PATH_INFO and 404.
if (( isset ( $_GET [ 'error' ]) && $_GET [ 'error' ] == '404' ) ||
2004-12-04 01:09:40 +01:00
(( ! empty ( $_SERVER [ 'PATH_INFO' ])) &&
( '/' != $_SERVER [ 'PATH_INFO' ]) &&
2005-02-18 02:43:48 +01:00
( false === strpos ( $_SERVER [ 'PATH_INFO' ], '.php' ))
2004-12-04 01:09:40 +01:00
)) {
2004-08-27 22:59:38 +02:00
2004-09-19 06:19:16 +02:00
// If we match a rewrite rule, this will be cleared.
$error = '404' ;
// Fetch the rewrite rules.
2004-12-03 03:38:11 +01:00
$rewrite = $wp_rewrite -> wp_rewrite_rules ();
2004-09-19 06:19:16 +02:00
if ( ! empty ( $rewrite )) {
$pathinfo = $_SERVER [ 'PATH_INFO' ];
$req_uri = $_SERVER [ 'REQUEST_URI' ];
$home_path = parse_url ( get_settings ( 'home' ));
$home_path = $home_path [ 'path' ];
// Trim path info from the end and the leading home path from the
// front. For path info requests, this leaves us with the requesting
// filename, if any. For 404 requests, this leaves us with the
// requested permalink.
$req_uri = str_replace ( $pathinfo , '' , $req_uri );
$req_uri = str_replace ( $home_path , '' , $req_uri );
$req_uri = trim ( $req_uri , '/' );
$pathinfo = trim ( $pathinfo , '/' );
// The requested permalink is in $pathinfo for path info requests and
// $req_uri for other requests.
if ( ! empty ( $pathinfo )) {
$request = $pathinfo ;
} else {
$request = $req_uri ;
}
2004-02-17 03:50:57 +01:00
2004-09-19 06:19:16 +02:00
// Look for matches.
$request_match = $request ;
foreach ( $rewrite as $match => $query ) {
// If the requesting file is the anchor of the match, prepend it
// to the path info.
2004-08-27 22:59:38 +02:00
if (( ! empty ( $req_uri )) && ( strpos ( $match , $req_uri ) === 0 )) {
$request_match = $req_uri . '/' . $request ;
}
2004-02-17 03:50:57 +01:00
2004-09-19 06:19:16 +02:00
if ( preg_match ( " !^ $match ! " , $request_match , $matches )) {
// Got a match.
// Trim the query of everything up to the '?'.
$query = preg_replace ( " !^.+ \ ?! " , '' , $query );
2004-02-17 03:50:57 +01:00
2004-09-19 06:19:16 +02:00
// Substitute the substring matches into the query.
eval ( " \$ query = \" $query\ " ; " );
2004-02-17 03:50:57 +01:00
2004-09-19 06:19:16 +02:00
// Parse the query.
parse_str ( $query , $query_vars );
2004-08-27 22:59:38 +02:00
2004-09-19 06:19:16 +02:00
// If we're processing a 404 request, clear the error var
// since we found something.
if ( isset ( $_GET [ 'error' ])) {
unset ( $_GET [ 'error' ]);
}
2004-08-27 22:59:38 +02:00
2004-09-19 06:19:16 +02:00
if ( isset ( $error )) {
unset ( $error );
}
2004-09-11 18:12:40 +02:00
2004-09-19 06:19:16 +02:00
break ;
}
}
}
}
2004-02-17 03:50:57 +01:00
2005-04-09 19:12:36 +02:00
$wpvarstoreset = 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' );
2003-12-11 01:22:36 +01:00
2004-12-04 01:09:40 +01:00
$wpvarstoreset = apply_filters ( 'query_vars' , $wpvarstoreset );
2004-07-06 19:58:48 +02:00
for ( $i = 0 ; $i < count ( $wpvarstoreset ); $i += 1 ) {
$wpvar = $wpvarstoreset [ $i ];
if ( ! isset ( $$wpvar )) {
if ( empty ( $_POST [ $wpvar ])) {
2004-08-27 22:59:38 +02:00
if ( empty ( $_GET [ $wpvar ]) && empty ( $query_vars [ $wpvar ])) {
2004-07-06 19:58:48 +02:00
$$wpvar = '' ;
} elseif ( ! empty ( $_GET [ $wpvar ])) {
$$wpvar = $_GET [ $wpvar ];
} else {
2004-08-27 22:59:38 +02:00
$$wpvar = $query_vars [ $wpvar ];
2004-07-06 19:58:48 +02:00
}
} else {
$$wpvar = $_POST [ $wpvar ];
}
}
}
2003-12-11 01:22:36 +01:00
2004-05-09 07:54:17 +02:00
// Sending HTTP headers
2005-06-09 02:17:43 +02:00
@ header ( 'X-Pingback: ' . get_bloginfo ( 'pingback_url' ));
2004-02-22 04:29:54 +01:00
2005-02-13 21:01:41 +01:00
if ( ! empty ( $error ) && '404' == $error ) {
2005-06-09 02:17:43 +02:00
status_header ( 404 );
2005-02-13 21:01:41 +01:00
} else if ( empty ( $feed ) ) {
2005-02-14 05:36:57 +01:00
@ header ( 'Content-type: ' . get_option ( 'html_type' ) . '; charset=' . get_option ( 'blog_charset' ));
2004-02-22 04:29:54 +01:00
} else {
// We're showing a feed, so WP is indeed the only thing that last changed
2004-10-14 10:27:56 +02:00
if ( $withcomments )
$wp_last_modified = mysql2date ( 'D, d M Y H:i:s' , get_lastcommentmodified ( 'GMT' ), 0 ) . ' GMT' ;
else
$wp_last_modified = mysql2date ( 'D, d M Y H:i:s' , get_lastpostmodified ( 'GMT' ), 0 ) . ' GMT' ;
2004-07-06 19:58:48 +02:00
$wp_etag = '"' . md5 ( $wp_last_modified ) . '"' ;
2004-10-14 10:27:56 +02:00
@ header ( " Last-Modified: $wp_last_modified " );
@ header ( " ETag: $wp_etag " );
2004-03-31 05:54:58 +02:00
2004-03-31 23:19:58 +02:00
// Support for Conditional GET
2004-05-10 09:51:50 +02:00
if ( isset ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ])) $client_etag = stripslashes ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ]);
else $client_etag = false ;
2004-03-31 23:19:58 +02:00
2005-05-13 23:07:21 +02:00
$client_last_modified = trim ( $_SERVER [ 'HTTP_IF_MODIFIED_SINCE' ]);
// If string is empty, return 0. If not, attempt to parse into a timestamp
$client_modified_timestamp = $client_last_modified ? strtotime ( $client_last_modified ) : 0 ;
// Make a timestamp for our most recent modification...
$wp_modified_timestamp = strtotime ( $wp_last_modified );
2005-05-06 01:05:51 +02:00
if ( ( $client_last_modified && $client_etag ) ?
2005-05-13 23:07:21 +02:00
(( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag == $wp_etag )) :
(( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag == $wp_etag )) ) {
2005-06-09 02:17:43 +02:00
status_header ( 304 );
exit ;
2004-03-31 05:54:58 +02:00
}
2004-02-22 04:29:54 +01:00
}
2003-12-11 01:22:36 +01:00
2004-05-24 04:55:39 +02:00
$use_gzipcompression = get_settings ( 'gzipcompression' );
2004-02-25 05:08:54 +01:00
2004-10-28 01:58:40 +02:00
$more_wpvars = array ( 'posts_per_page' , 'posts_per_archive_page' , 'what_to_show' , 'showposts' , 'nopaging' );
2004-02-11 05:51:19 +01:00
2004-05-24 04:55:39 +02:00
// Construct the query string.
$query_string = '' ;
foreach ( array_merge ( $wpvarstoreset , $more_wpvars ) as $wpvar ) {
2004-07-06 19:58:48 +02:00
if ( $$wpvar != '' ) {
$query_string .= ( strlen ( $query_string ) < 1 ) ? '' : '&' ;
$query_string .= $wpvar . '=' . rawurlencode ( $$wpvar );
}
2004-02-11 05:51:19 +01:00
}
2004-06-21 00:36:45 +02:00
$query_string = apply_filters ( 'query_string' , $query_string );
2004-05-24 04:55:39 +02:00
update_category_cache ();
2005-04-09 19:12:36 +02:00
get_currentuserinfo ();
2003-12-11 01:22:36 +01:00
2004-05-24 04:55:39 +02:00
// Call query posts to do the work.
2005-03-27 22:45:01 +02:00
$posts = & query_posts ( $query_string );
2003-12-11 01:22:36 +01:00
2004-10-28 00:07:58 +02:00
// Extract updated query vars back into global namespace.
extract ( $wp_query -> query_vars );
2005-02-25 03:07:08 +01:00
if ( is_single () || is_page () ) {
2005-02-13 21:32:24 +01:00
$more = 1 ;
$single = 1 ;
2003-12-11 01:22:36 +01:00
}
2004-11-10 05:01:46 +01:00
// Issue a 404 if a permalink request doesn't match any posts. Don't issue a
// 404 if one was already issued, if the request was a search, or if the
// request was a regular query string request rather than a permalink request.
if ( ( 0 == count ( $posts )) && ! is_404 () && ! is_search ()
2005-04-03 07:43:42 +02:00
&& ( isset ( $rewrite ) || ( ! empty ( $_SERVER [ 'QUERY_STRING' ]) &&
( false === strpos ( $_SERVER [ 'REQUEST_URI' ], '?' ))) ) ) {
2004-11-10 05:01:46 +01:00
$wp_query -> is_404 = true ;
2005-06-09 02:17:43 +02:00
status_header ( 404 );
} else {
status_header ( 200 );
2004-11-10 05:01:46 +01:00
}
2005-02-14 06:50:46 +01:00
if ( $pagenow != 'post.php' && $pagenow != 'edit.php' ) {
if ( get_settings ( 'gzipcompression' ) )
gzip_compression ();
}
2004-08-24 10:43:01 +02:00
// Template redirection
2005-02-13 21:38:28 +01:00
if ( defined ( 'WP_USE_THEMES' ) && constant ( 'WP_USE_THEMES' ) ) {
do_action ( 'template_redirect' );
if ( is_feed () && empty ( $doing_rss ) ) {
include ( ABSPATH . '/wp-feed.php' );
exit ;
2005-02-13 22:25:08 +01:00
} else if ( is_trackback () && empty ( $doing_trackback ) ) {
2005-02-13 21:38:28 +01:00
include ( ABSPATH . '/wp-trackback.php' );
exit ;
} else if ( is_404 () && get_404_template () ) {
include ( get_404_template ());
exit ;
} else if ( is_search () && get_search_template () ) {
include ( get_search_template ());
exit ;
} else if ( is_home () && get_home_template () ) {
include ( get_home_template ());
exit ;
} else if ( is_single () && get_single_template () ) {
include ( get_single_template ());
exit ;
} else if ( is_page () && get_page_template () ) {
include ( get_page_template ());
exit ;
} else if ( is_category () && get_category_template ()) {
include ( get_category_template ());
exit ;
} else if ( is_author () && get_author_template () ) {
include ( get_author_template ());
exit ;
} else if ( is_date () && get_date_template () ) {
include ( get_date_template ());
exit ;
} else if ( is_archive () && get_archive_template () ) {
include ( get_archive_template ());
exit ;
2005-02-14 10:17:23 +01:00
} else if ( is_comments_popup () && get_comments_popup_template () ) {
include ( get_comments_popup_template ());
exit ;
2005-02-13 21:38:28 +01:00
} else if ( is_paged () && get_paged_template () ) {
include ( get_paged_template ());
exit ;
} else if ( file_exists ( TEMPLATEPATH . " /index.php " ) ) {
include ( TEMPLATEPATH . " /index.php " );
exit ;
2004-09-13 10:05:30 +02:00
}
2005-02-13 22:20:00 +01:00
} else {
// Process feeds and trackbacks even if not using themes.
if ( is_feed () && empty ( $doing_rss ) ) {
include ( ABSPATH . '/wp-feed.php' );
exit ;
2005-02-13 22:25:08 +01:00
} else if ( is_trackback () && empty ( $doing_trackback ) ) {
2005-02-13 22:20:00 +01:00
include ( ABSPATH . '/wp-trackback.php' );
exit ;
}
2004-06-01 01:35:32 +02:00
}
2005-02-13 22:20:00 +01:00
endif ;
2005-02-25 03:07:08 +01:00
?>