2003-12-10 19:22:36 -05:00
< ? php
2004-08-24 04:43:01 -04:00
if ( ! isset ( $wp_did_header )) :
2004-07-06 13:58:48 -04:00
if ( ! file_exists ( dirname ( __FILE__ ) . '/wp-config.php' ) )
2004-05-18 16:05:40 -04:00
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='wp-admin/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-10 19:22:36 -05:00
2004-07-06 13:58:48 -04:00
require_once ( dirname ( __FILE__ ) . '/wp-config.php' );
2003-12-10 19:22:36 -05:00
2004-07-06 13:58:48 -04:00
require_once ( dirname ( __FILE__ ) . '/wp-includes/wp-l10n.php' );
2004-05-14 16:46:05 -04:00
2004-08-27 16:59:38 -04:00
$query_vars = array ();
// Process PATH_INFO and 404.
if (( isset ( $_GET [ 'error' ]) && $_GET [ 'error' ] == '404' ) ||
2004-12-03 19:09:40 -05:00
(( ! empty ( $_SERVER [ 'PATH_INFO' ])) &&
( '/' != $_SERVER [ 'PATH_INFO' ]) &&
( false === strpos ( $_SERVER [ 'PATH_INFO' ], $_SERVER [ 'SCRIPT_NAME' ]))
)) {
2004-08-27 16:59:38 -04:00
2004-09-19 00:19:16 -04:00
// If we match a rewrite rule, this will be cleared.
$error = '404' ;
// Fetch the rewrite rules.
2004-12-02 21:38:11 -05:00
$rewrite = $wp_rewrite -> wp_rewrite_rules ();
2004-09-19 00:19:16 -04: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-16 21:50:57 -05:00
2004-09-19 00:19:16 -04: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 16:59:38 -04:00
if (( ! empty ( $req_uri )) && ( strpos ( $match , $req_uri ) === 0 )) {
$request_match = $req_uri . '/' . $request ;
}
2004-02-16 21:50:57 -05:00
2004-09-19 00:19:16 -04: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-16 21:50:57 -05:00
2004-09-19 00:19:16 -04:00
// Substitute the substring matches into the query.
eval ( " \$ query = \" $query\ " ; " );
2004-02-16 21:50:57 -05:00
2004-09-19 00:19:16 -04:00
// Parse the query.
parse_str ( $query , $query_vars );
2004-08-27 16:59:38 -04:00
2004-09-19 00:19:16 -04: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 16:59:38 -04:00
2004-09-19 00:19:16 -04:00
if ( isset ( $error )) {
unset ( $error );
}
2004-09-11 12:12:40 -04:00
2004-09-19 00:19:16 -04:00
break ;
}
}
}
}
2004-02-16 21:50:57 -05:00
2004-10-08 04:06:21 -04:00
$wpvarstoreset = array ( 'm' , 'p' , 'posts' , 'w' , 'cat' , 'withcomments' , 's' , 'search' , 'exact' , 'sentence' , 'poststart' , 'postend' , 'preview' , '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' );
2003-12-10 19:22:36 -05:00
2004-12-03 19:09:40 -05:00
$wpvarstoreset = apply_filters ( 'query_vars' , $wpvarstoreset );
2004-07-06 13:58:48 -04:00
for ( $i = 0 ; $i < count ( $wpvarstoreset ); $i += 1 ) {
$wpvar = $wpvarstoreset [ $i ];
if ( ! isset ( $$wpvar )) {
if ( empty ( $_POST [ $wpvar ])) {
2004-08-27 16:59:38 -04:00
if ( empty ( $_GET [ $wpvar ]) && empty ( $query_vars [ $wpvar ])) {
2004-07-06 13:58:48 -04:00
$$wpvar = '' ;
} elseif ( ! empty ( $_GET [ $wpvar ])) {
$$wpvar = $_GET [ $wpvar ];
} else {
2004-08-27 16:59:38 -04:00
$$wpvar = $query_vars [ $wpvar ];
2004-07-06 13:58:48 -04:00
}
} else {
$$wpvar = $_POST [ $wpvar ];
}
}
}
2003-12-10 19:22:36 -05:00
2004-07-06 13:58:48 -04:00
if ( '' != $feed ) {
$doing_rss = true ;
2004-05-31 19:35:32 -04:00
}
2004-07-06 13:58:48 -04:00
if ( 1 == $tb ) {
$doing_trackback = true ;
2004-05-31 19:35:32 -04:00
}
2003-12-10 19:22:36 -05:00
2004-05-09 01:54:17 -04:00
// Sending HTTP headers
2004-02-21 22:29:54 -05:00
2004-09-11 12:12:40 -04:00
if ( is_404 ()) {
header ( " HTTP/1.x 404 Not Found " );
} else if ( ! isset ( $doing_rss ) || ! $doing_rss ) {
2004-09-17 10:57:15 -04:00
@ header ( 'X-Pingback: ' . get_bloginfo ( 'pingback_url' ));
2004-02-21 22:29:54 -05:00
} else {
// We're showing a feed, so WP is indeed the only thing that last changed
2004-10-14 04:27:56 -04: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 13:58:48 -04:00
$wp_etag = '"' . md5 ( $wp_last_modified ) . '"' ;
2004-10-14 04:27:56 -04:00
@ header ( " Last-Modified: $wp_last_modified " );
@ header ( " ETag: $wp_etag " );
2004-09-17 10:57:15 -04:00
@ header ( 'X-Pingback: ' . get_bloginfo ( 'pingback_url' ));
2004-03-30 22:54:58 -05:00
2004-03-31 16:19:58 -05:00
// Support for Conditional GET
2004-05-10 03:51:50 -04:00
if ( isset ( $_SERVER [ 'HTTP_IF_MODIFIED_SINCE' ])) $client_last_modified = $_SERVER [ 'HTTP_IF_MODIFIED_SINCE' ];
else $client_last_modified = false ;
if ( isset ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ])) $client_etag = stripslashes ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ]);
else $client_etag = false ;
2004-03-31 16:19:58 -05:00
if ( ( $client_last_modified && $client_etag ) ?
(( $client_last_modified == $wp_last_modified ) && ( $client_etag == $wp_etag )) :
(( $client_last_modified == $wp_last_modified ) || ( $client_etag == $wp_etag )) ) {
2004-05-21 18:33:47 -04:00
if ( preg_match ( '/cgi/' , php_sapi_name ()) ) {
header ( 'HTTP/1.1 304 Not Modified' );
echo " \r \n \r \n " ;
exit ;
} else {
if ( version_compare ( phpversion (), '4.3.0' , '>=' )) {
header ( 'Not Modified' , TRUE , 304 );
} else {
header ( 'HTTP/1.x 304 Not Modified' );
}
2004-07-06 14:20:11 -04:00
exit ;
2004-05-21 18:33:47 -04:00
}
2004-03-30 22:54:58 -05:00
}
2004-02-21 22:29:54 -05:00
}
2003-12-10 19:22:36 -05:00
2004-05-09 01:54:17 -04:00
// Getting settings from DB
2004-07-06 13:58:48 -04:00
if ( isset ( $doing_rss ) && $doing_rss == 1 )
$posts_per_page = get_settings ( 'posts_per_rss' );
2004-05-23 22:55:39 -04:00
$use_gzipcompression = get_settings ( 'gzipcompression' );
2004-02-24 23:08:54 -05:00
2004-10-27 19:58:40 -04:00
$more_wpvars = array ( 'posts_per_page' , 'posts_per_archive_page' , 'what_to_show' , 'showposts' , 'nopaging' );
2004-02-10 23:51:19 -05:00
2004-05-23 22:55:39 -04:00
// Construct the query string.
$query_string = '' ;
foreach ( array_merge ( $wpvarstoreset , $more_wpvars ) as $wpvar ) {
2004-07-06 13:58:48 -04:00
if ( $$wpvar != '' ) {
$query_string .= ( strlen ( $query_string ) < 1 ) ? '' : '&' ;
$query_string .= $wpvar . '=' . rawurlencode ( $$wpvar );
}
2004-02-10 23:51:19 -05:00
}
2004-06-20 18:36:45 -04:00
$query_string = apply_filters ( 'query_string' , $query_string );
2004-05-23 22:55:39 -04:00
update_category_cache ();
2003-12-10 19:22:36 -05:00
2004-05-23 22:55:39 -04:00
// Call query posts to do the work.
$posts = query_posts ( $query_string );
2003-12-10 19:22:36 -05:00
2004-10-27 18:07:58 -04:00
// Extract updated query vars back into global namespace.
extract ( $wp_query -> query_vars );
2004-05-23 22:55:39 -04:00
if ( 1 == count ( $posts )) {
2004-07-27 22:43:54 -04:00
if ( is_single ()) {
2004-07-06 13:58:48 -04:00
$more = 1 ;
$single = 1 ;
}
if ( $s && empty ( $paged ) && ! strstr ( $_SERVER [ 'PHP_SELF' ], 'wp-admin/' )) { // If they were doing a search and got one result
header ( 'Location: ' . get_permalink ( $posts [ 0 ] -> ID ));
}
2003-12-10 19:22:36 -05:00
}
2004-11-09 23:01:46 -05: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 ()
&& ! empty ( $_SERVER [ 'QUERY_STRING' ]) &&
( false === strpos ( $_SERVER [ 'REQUEST_URI' ], '?' )) ) {
$wp_query -> is_404 = true ;
header ( " HTTP/1.x 404 Not Found " );
}
2004-08-24 04:43:01 -04:00
$wp_did_header = true ;
endif ;
2004-09-30 13:56:16 -04:00
$wp_template_dir = get_template_directory ();
2004-09-11 12:12:40 -04:00
2004-08-24 04:43:01 -04:00
// Template redirection
2004-09-15 03:37:43 -04:00
if ( $pagenow == 'index.php' ) {
2004-09-13 04:05:30 -04:00
if ( ! isset ( $wp_did_template_redirect )) {
2004-12-03 19:12:08 -05:00
$wp_did_template_redirect = true ;
do_action ( 'template_redirect' , '' );
2004-09-18 15:01:18 -04:00
if ( is_feed ()) {
$wp_did_template_redirect = true ;
include ( dirname ( __FILE__ ) . '/wp-feed.php' );
exit ;
} else if ( $tb == 1 ) {
$wp_did_template_redirect = true ;
include ( dirname ( __FILE__ ) . '/wp-trackback.php' );
exit ;
2004-11-23 16:16:04 -05:00
} else if ( is_404 () &&
file_exists ( " $wp_template_dir /404.php " )) {
$wp_did_template_redirect = true ;
include ( " $wp_template_dir /404.php " );
exit ;
2004-09-18 15:01:18 -04:00
} else if ( is_home () &&
2004-09-30 13:56:16 -04:00
file_exists ( " $wp_template_dir /index.php " )) {
2004-09-13 04:05:30 -04:00
$wp_did_template_redirect = true ;
2004-09-30 13:56:16 -04:00
include ( " $wp_template_dir /index.php " );
2004-09-13 04:05:30 -04:00
exit ;
} else if ( is_single () &&
2004-09-30 13:56:16 -04:00
file_exists ( " $wp_template_dir /single.php " )) {
2004-09-13 04:05:30 -04:00
$wp_did_template_redirect = true ;
2004-09-30 13:56:16 -04:00
include ( " $wp_template_dir /single.php " );
2004-09-13 04:05:30 -04:00
exit ;
2004-10-06 01:11:11 -04:00
} else if ( is_page () && file_exists ( get_page_template ())) {
2004-09-13 04:05:30 -04:00
$wp_did_template_redirect = true ;
2004-10-06 01:11:11 -04:00
include ( get_page_template ());
2004-09-13 04:05:30 -04:00
exit ;
} else if ( is_category () &&
2004-09-30 13:56:16 -04:00
file_exists ( " $wp_template_dir /category.php " )) {
2004-09-13 04:05:30 -04:00
$wp_did_template_redirect = true ;
2004-09-30 13:56:16 -04:00
include ( " $wp_template_dir /category.php " );
2004-09-13 04:05:30 -04:00
exit ;
} else if ( is_author () &&
2004-09-30 13:56:16 -04:00
file_exists ( " $wp_template_dir /author.php " )) {
2004-09-13 04:05:30 -04:00
$wp_did_template_redirect = true ;
2004-09-30 13:56:16 -04:00
include ( " $wp_template_dir /author.php " );
2004-09-13 04:05:30 -04:00
exit ;
} else if ( is_date () &&
2004-09-30 13:56:16 -04:00
file_exists ( " $wp_template_dir /date.php " )) {
2004-09-13 04:05:30 -04:00
$wp_did_date = true ;
$wp_did_template_redirect = true ;
2004-09-30 13:56:16 -04:00
include ( " $wp_template_dir /date.php " );
2004-09-13 04:05:30 -04:00
exit ;
} else if ( is_archive () &&
2004-09-30 13:56:16 -04:00
file_exists ( " $wp_template_dir /archive.php " )) {
2004-09-13 04:05:30 -04:00
$wp_did_template_redirect = true ;
2004-09-30 13:56:16 -04:00
include ( " $wp_template_dir /archive.php " );
2004-09-13 04:05:30 -04:00
exit ;
} else if ( is_search () &&
2004-09-30 13:56:16 -04:00
file_exists ( " $wp_template_dir /search.php " )) {
2004-09-13 04:05:30 -04:00
$wp_did_template_redirect = true ;
2004-09-30 13:56:16 -04:00
include ( " $wp_template_dir /search.php " );
2004-09-13 04:05:30 -04:00
exit ;
2004-11-29 18:37:29 -05:00
} else if ( is_paged () &&
file_exists ( " $wp_template_dir /paged.php " )) {
$wp_did_template_redirect = true ;
include ( " $wp_template_dir /paged.php " );
exit ;
2004-09-30 13:56:16 -04:00
} else if ( file_exists ( " $wp_template_dir /index.php " ))
2004-09-13 04:05:30 -04:00
{
$wp_did_template_redirect = true ;
2004-09-30 13:56:16 -04:00
include ( " $wp_template_dir /index.php " );
2004-09-13 04:05:30 -04:00
exit ;
}
}
2004-05-31 19:35:32 -04:00
}
2004-01-07 12:36:54 -05:00
if ( $pagenow != 'post.php' && $pagenow != 'edit.php' ) {
2004-07-06 13:58:48 -04:00
if ( get_settings ( 'gzipcompression' ) )
gzip_compression ();
2003-12-10 19:22:36 -05:00
}
2004-05-24 04:22:18 -04:00
?>