1 | <?php |
---|
2 | |
---|
3 | if (! isset($wp_did_header)): |
---|
4 | if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) |
---|
5 | 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."); |
---|
6 | |
---|
7 | require_once( dirname(__FILE__) . '/wp-config.php'); |
---|
8 | |
---|
9 | require_once( dirname(__FILE__) . '/wp-includes/wp-l10n.php'); |
---|
10 | |
---|
11 | $query_vars = array(); |
---|
12 | |
---|
13 | // Process PATH_INFO and 404. |
---|
14 | if ((isset($_GET['error']) && $_GET['error'] == '404') || |
---|
15 | (! empty( $_SERVER['PATH_INFO']))) { |
---|
16 | |
---|
17 | // Fetch the rewrite rules. |
---|
18 | $rewrite = rewrite_rules('matches'); |
---|
19 | |
---|
20 | if (! empty($rewrite)) { |
---|
21 | $pathinfo = $_SERVER['PATH_INFO']; |
---|
22 | $req_uri = $_SERVER['REQUEST_URI']; |
---|
23 | $home_path = parse_url(get_settings('home')); |
---|
24 | $home_path = $home_path['path']; |
---|
25 | |
---|
26 | // Trim path info from the end and the leading home path from the |
---|
27 | // front. For path info requests, this leaves us with the requesting |
---|
28 | // filename, if any. For 404 requests, this leaves us with the |
---|
29 | // requested permalink. |
---|
30 | $req_uri = str_replace($pathinfo, '', $req_uri); |
---|
31 | $req_uri = str_replace($home_path, '', $req_uri); |
---|
32 | $req_uri = trim($req_uri, '/'); |
---|
33 | $pathinfo = trim($pathinfo, '/'); |
---|
34 | |
---|
35 | // The requested permalink is in $pathinfo for path info requests and |
---|
36 | // $req_uri for other requests. |
---|
37 | if (! empty($pathinfo)) { |
---|
38 | $request = $pathinfo; |
---|
39 | } else { |
---|
40 | $request = $req_uri; |
---|
41 | } |
---|
42 | |
---|
43 | // Look for matches. |
---|
44 | $request_match = $request; |
---|
45 | foreach ($rewrite as $match => $query) { |
---|
46 | // If the requesting file is the anchor of the match, prepend it |
---|
47 | // to the path info. |
---|
48 | if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) { |
---|
49 | $request_match = $req_uri . '/' . $request; |
---|
50 | } |
---|
51 | |
---|
52 | if (preg_match("!^$match!", $request_match, $matches)) { |
---|
53 | // Got a match. |
---|
54 | // Trim the query of everything up to the '?'. |
---|
55 | $query = preg_replace("!^.+\?!", '', $query); |
---|
56 | |
---|
57 | // Substitute the substring matches into the query. |
---|
58 | eval("\$query = \"$query\";"); |
---|
59 | |
---|
60 | // Parse the query. |
---|
61 | parse_str($query, $query_vars); |
---|
62 | |
---|
63 | // If we're processing a 404 request, clear the error var |
---|
64 | // since we found something. |
---|
65 | if (isset($_GET['error'])) { |
---|
66 | unset($_GET['error']); |
---|
67 | } |
---|
68 | |
---|
69 | break; |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | $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', 'error'); |
---|
76 | |
---|
77 | for ($i=0; $i<count($wpvarstoreset); $i += 1) { |
---|
78 | $wpvar = $wpvarstoreset[$i]; |
---|
79 | if (!isset($$wpvar)) { |
---|
80 | if (empty($_POST[$wpvar])) { |
---|
81 | if (empty($_GET[$wpvar]) && empty($query_vars[$wpvar])) { |
---|
82 | $$wpvar = ''; |
---|
83 | } elseif (!empty($_GET[$wpvar])) { |
---|
84 | $$wpvar = $_GET[$wpvar]; |
---|
85 | } else { |
---|
86 | $$wpvar = $query_vars[$wpvar]; |
---|
87 | } |
---|
88 | } else { |
---|
89 | $$wpvar = $_POST[$wpvar]; |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | if ('' != $feed) { |
---|
95 | $doing_rss = true; |
---|
96 | } |
---|
97 | |
---|
98 | if (1 == $tb) { |
---|
99 | $doing_trackback = true; |
---|
100 | } |
---|
101 | |
---|
102 | // Sending HTTP headers |
---|
103 | |
---|
104 | if ( !isset($doing_rss) || !$doing_rss ) { |
---|
105 | @header ('X-Pingback: '. get_settings('siteurl') . '/xmlrpc.php'); |
---|
106 | } else { |
---|
107 | // We're showing a feed, so WP is indeed the only thing that last changed |
---|
108 | $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; |
---|
109 | $wp_etag = '"' . md5($wp_last_modified) . '"'; |
---|
110 | @header('Last-Modified: '.$wp_last_modified); |
---|
111 | @header('ETag: '.$wp_etag); |
---|
112 | @header ('X-Pingback: ' . get_settings('siteurl') . '/xmlrpc.php'); |
---|
113 | |
---|
114 | // Support for Conditional GET |
---|
115 | if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) $client_last_modified = $_SERVER['HTTP_IF_MODIFIED_SINCE']; |
---|
116 | else $client_last_modified = false; |
---|
117 | if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); |
---|
118 | else $client_etag = false; |
---|
119 | |
---|
120 | if ( ($client_last_modified && $client_etag) ? |
---|
121 | (($client_last_modified == $wp_last_modified) && ($client_etag == $wp_etag)) : |
---|
122 | (($client_last_modified == $wp_last_modified) || ($client_etag == $wp_etag)) ) { |
---|
123 | if ( preg_match('/cgi/',php_sapi_name()) ) { |
---|
124 | header('HTTP/1.1 304 Not Modified'); |
---|
125 | echo "\r\n\r\n"; |
---|
126 | exit; |
---|
127 | } else { |
---|
128 | if (version_compare(phpversion(),'4.3.0','>=')) { |
---|
129 | header('Not Modified', TRUE, 304); |
---|
130 | } else { |
---|
131 | header('HTTP/1.x 304 Not Modified'); |
---|
132 | } |
---|
133 | exit; |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | // Getting settings from DB |
---|
139 | if ( isset($doing_rss) && $doing_rss == 1 ) |
---|
140 | $posts_per_page = get_settings('posts_per_rss'); |
---|
141 | if ( !isset($posts_per_page) || $posts_per_page == 0 ) |
---|
142 | $posts_per_page = get_settings('posts_per_page'); |
---|
143 | if ( !isset($what_to_show) ) |
---|
144 | $what_to_show = get_settings('what_to_show'); |
---|
145 | if ( isset($showposts) && $showposts ) { |
---|
146 | $showposts = (int) $showposts; |
---|
147 | $posts_per_page = $showposts; |
---|
148 | } |
---|
149 | if ( !isset($nopaging) ) { |
---|
150 | $nopaging = ''; |
---|
151 | } |
---|
152 | |
---|
153 | $use_gzipcompression = get_settings('gzipcompression'); |
---|
154 | |
---|
155 | $more_wpvars = array('posts_per_page', 'what_to_show', 'showposts', 'nopaging'); |
---|
156 | |
---|
157 | // Construct the query string. |
---|
158 | $query_string = ''; |
---|
159 | foreach (array_merge($wpvarstoreset, $more_wpvars) as $wpvar) { |
---|
160 | if ($$wpvar != '') { |
---|
161 | $query_string .= (strlen($query_string) < 1) ? '' : '&'; |
---|
162 | $query_string .= $wpvar . '=' . rawurlencode($$wpvar); |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | $query_string = apply_filters('query_string', $query_string); |
---|
167 | |
---|
168 | update_category_cache(); |
---|
169 | |
---|
170 | // Call query posts to do the work. |
---|
171 | $posts = query_posts($query_string); |
---|
172 | |
---|
173 | if (1 == count($posts)) { |
---|
174 | if (is_single()) { |
---|
175 | $more = 1; |
---|
176 | $single = 1; |
---|
177 | } |
---|
178 | if ( $s && empty($paged) && !strstr($_SERVER['PHP_SELF'], 'wp-admin/')) { // If they were doing a search and got one result |
---|
179 | header('Location: ' . get_permalink($posts[0]->ID)); |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | $wp_did_header = true; |
---|
184 | endif; |
---|
185 | |
---|
186 | // Template redirection |
---|
187 | if (is_single() && (! isset($wp_did_single)) && |
---|
188 | file_exists(ABSPATH . 'wp-content/single.php')) { |
---|
189 | $wp_did_single = true; |
---|
190 | include(ABSPATH . 'wp-content/single.php'); |
---|
191 | exit; |
---|
192 | } else if (is_page() && (! isset($wp_did_page)) && |
---|
193 | file_exists(ABSPATH . 'wp-content/page.php')) { |
---|
194 | $wp_did_page = true; |
---|
195 | include(ABSPATH . 'wp-content/page.php'); |
---|
196 | exit; |
---|
197 | } else if (is_category() && (! isset($wp_did_category)) && |
---|
198 | file_exists(ABSPATH . 'wp-content/category.php')) { |
---|
199 | $wp_did_category = true; |
---|
200 | include(ABSPATH . 'wp-content/category.php'); |
---|
201 | exit; |
---|
202 | } else if (is_author() && (! isset($wp_did_author)) && |
---|
203 | file_exists(ABSPATH . 'wp-content/author.php')) { |
---|
204 | $wp_did_author = true; |
---|
205 | include(ABSPATH . 'wp-content/author.php'); |
---|
206 | exit; |
---|
207 | } else if (is_date() && (! isset($wp_did_date)) && |
---|
208 | file_exists(ABSPATH . 'wp-content/date.php')) { |
---|
209 | $wp_did_date = true; |
---|
210 | include(ABSPATH . 'wp-content/date.php'); |
---|
211 | exit; |
---|
212 | } else if (is_archive() && (! isset($wp_did_archive)) && |
---|
213 | file_exists(ABSPATH . 'wp-content/archive.php')) { |
---|
214 | $wp_did_archive = true; |
---|
215 | include(ABSPATH . 'wp-content/archive.php'); |
---|
216 | exit; |
---|
217 | } else if (is_search() && (! isset($wp_did_search)) && |
---|
218 | file_exists(ABSPATH . 'wp-content/search.php')) { |
---|
219 | $wp_did_search = true; |
---|
220 | include(ABSPATH . 'wp-content/search.php'); |
---|
221 | exit; |
---|
222 | } else if (is_404() && (! isset($wp_did_404)) && |
---|
223 | file_exists(ABSPATH . 'wp-content/404.php')) { |
---|
224 | $wp_did_404 = true; |
---|
225 | include(ABSPATH . 'wp-content/404.php'); |
---|
226 | exit; |
---|
227 | } else if (is_feed() && $pagenow != 'wp-feed.php') { |
---|
228 | include(dirname(__FILE__) . '/wp-feed.php'); |
---|
229 | exit; |
---|
230 | } else if ($pagenow != 'wp-trackback.php' && $tb == 1) { |
---|
231 | include(dirname(__FILE__) . '/wp-trackback.php'); |
---|
232 | exit; |
---|
233 | } |
---|
234 | |
---|
235 | if ($pagenow != 'post.php' && $pagenow != 'edit.php') { |
---|
236 | if ( get_settings('gzipcompression') ) |
---|
237 | gzip_compression(); |
---|
238 | } |
---|
239 | |
---|
240 | ?> |
---|