Make WordPress Core

source: trunk/wp-blog-header.php @ 1405

Last change on this file since 1405 was 1404, checked in by saxmatt, 21 years ago

Gzip cleanup, debugged wacky options problem, some cleanup and reorg. We need to split up functions.php more logically, and kill some of the useless functions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1<?php
2
3if (!file_exists(dirname(__FILE__).'/' . 'wp-config.php'))
4    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.");
5
6require_once(dirname(__FILE__).'/' . '/wp-config.php');
7
8require_once(dirname(__FILE__).'/' . 'wp-includes/wp-l10n.php');
9
10// Process PATH_INFO, if set.
11$path_info = array();
12if (! empty($_SERVER['PATH_INFO'])) {
13    // Fetch the rewrite rules.
14    $rewrite = rewrite_rules('matches');
15
16    $pathinfo = $_SERVER['PATH_INFO'];
17    // Trim leading '/'.
18    $pathinfo = preg_replace("!^/!", '', $pathinfo);
19
20    if (! empty($rewrite)) {
21        // Get the name of the file requesting path info.
22        $req_uri = $_SERVER['REQUEST_URI'];
23        $req_uri = str_replace($pathinfo, '', $req_uri);
24        $req_uri = preg_replace("!/+$!", '', $req_uri);
25        $req_uri = explode('/', $req_uri);
26        $req_uri = $req_uri[count($req_uri)-1];
27
28        // Look for matches.
29        $pathinfomatch = $pathinfo;
30        foreach ($rewrite as $match => $query) {
31            // If the request URI is the anchor of the match, prepend it
32            // to the path info.
33            if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) {
34                $pathinfomatch = $req_uri . '/' . $pathinfo;
35            }
36
37            if (preg_match("!^$match!", $pathinfomatch, $matches)) {
38                // Got a match.
39                // Trim the query of everything up to the '?'.
40                $query = preg_replace("!^.+\?!", '', $query);
41
42                // Substitute the substring matches into the query.
43                eval("\$query = \"$query\";");
44
45                // Parse the query.
46                parse_str($query, $path_info);
47                break;
48            }
49        }
50    }   
51}
52
53$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');
54
55    for ($i=0; $i<count($wpvarstoreset); $i += 1) {
56        $wpvar = $wpvarstoreset[$i];
57        if (!isset($$wpvar)) {
58            if (empty($_POST[$wpvar])) {
59                if (empty($_GET[$wpvar]) && empty($path_info[$wpvar])) {
60                    $$wpvar = '';
61                } elseif (!empty($_GET[$wpvar])) {
62                    $$wpvar = $_GET[$wpvar];
63                } else {
64                    $$wpvar = $path_info[$wpvar];
65                }
66            } else {
67                $$wpvar = $_POST[$wpvar];
68            }
69        }
70    }
71
72if ($feed != '') {
73    $doing_rss = 1;
74}
75
76if ($tb == 1) {
77    $doing_trackback = 1;
78}
79
80// Sending HTTP headers
81
82if (!isset($doing_rss) || !$doing_rss) {
83        // It is presumptious to think that WP is the only thing that might change on the page.
84        @header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                 // Date in the past
85        @header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
86        @header("Cache-Control: no-store, no-cache, must-revalidate");     // HTTP/1.1
87        @header("Cache-Control: post-check=0, pre-check=0", false);
88        @header("Pragma: no-cache");                                     // HTTP/1.0
89        @header ('X-Pingback: '. get_settings('siteurl') . '/xmlrpc.php');
90} else {
91
92        // We're showing a feed, so WP is indeed the only thing that last changed
93        $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
94        $wp_etag = '"'.md5($wp_last_modified).'"';
95        @header('Last Modified: '.$wp_last_modified);
96        @header('ETag: '.$wp_etag);
97        @header ('X-Pingback: ' . get_settings('siteurl') . '/xmlrpc.php');
98
99        // Support for Conditional GET
100        if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) $client_last_modified = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
101        else $client_last_modified = false;
102        if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
103        else $client_etag = false;
104
105        if ( ($client_last_modified && $client_etag) ?
106            (($client_last_modified == $wp_last_modified) && ($client_etag == $wp_etag)) :
107            (($client_last_modified == $wp_last_modified) || ($client_etag == $wp_etag)) ) {
108                if ( preg_match('/cgi/',php_sapi_name()) ) {
109                    header('HTTP/1.1 304 Not Modified');
110                    echo "\r\n\r\n";
111                    exit;
112                } else {
113                    if (version_compare(phpversion(),'4.3.0','>=')) {
114                        header('Not Modified', TRUE, 304);
115                    } else {
116                        header('HTTP/1.x 304 Not Modified');
117                    }
118                }
119        }
120
121}
122
123// Getting settings from DB
124if (isset($doing_rss) && $doing_rss == 1)
125    $posts_per_page=get_settings('posts_per_rss');
126if (!isset($posts_per_page) || $posts_per_page == 0)
127    $posts_per_page = get_settings('posts_per_page');
128if (!isset($what_to_show))
129    $what_to_show = get_settings('what_to_show');
130if (isset($showposts) && $showposts) {
131    $showposts = (int)$showposts;
132    $posts_per_page = $showposts;
133}
134$archive_mode = get_settings('archive_mode');
135$use_gzipcompression = get_settings('gzipcompression');
136
137$more_wpvars = array('posts_per_page', 'what_to_show', 'showposts');
138
139// Construct the query string.
140$query_string = '';
141foreach (array_merge($wpvarstoreset, $more_wpvars) as $wpvar) {
142    if ($$wpvar != '') {
143        $query_string .= (strlen($query_string) < 1) ? '' : '&';
144        $query_string .= $wpvar . '=' . rawurlencode($$wpvar);
145    }
146}
147
148if ($pagenow != 'post.php') { timer_start(); }
149
150// Update some caches.
151update_category_cache();
152
153// Call query posts to do the work.
154$posts = query_posts($query_string);
155
156// Update per post caches.
157update_post_caches($posts);
158
159if (1 == count($posts)) {
160    if ($p || $name) {
161        $more = 1;
162        $single = 1;
163    }
164    if ($s && empty($paged)) { // If they were doing a search and got one result
165        if (!strstr($_SERVER['PHP_SELF'], 'wp-admin')) // And not in admin section
166            header('Location: ' . get_permalink($posts[0]->ID));
167    }
168}
169
170if ($pagenow != 'wp-feed.php' && $feed != '') {
171    require(dirname(__FILE__) . '/wp-feed.php');
172    exit;
173}
174
175if ($pagenow != 'wp-trackback.php' && $tb == 1) {
176    require(dirname(__FILE__) . '/wp-trackback.php');
177    exit;
178}
179
180if ($pagenow != 'post.php' && $pagenow != 'edit.php') {
181    if ( get_settings('gzipcompression') ) 
182        gzip_compression();
183}
184
185?>
Note: See TracBrowser for help on using the repository browser.