Changeset 20062 for trunk/wp-includes/class-wp-atom-server.php
- Timestamp:
- 03/01/2012 09:15:44 PM (14 years ago)
- File:
-
- 1 copied
-
trunk/wp-includes/class-wp-atom-server.php (copied) (copied from trunk/wp-app.php) (31 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-atom-server.php
r20059 r20062 1 1 <?php 2 /**3 * Atom Publishing Protocol support for WordPress4 *5 * @version 1.0.5-dc6 */7 8 /**9 * WordPress is handling an Atom Publishing Protocol request.10 *11 * @var bool12 */13 define('APP_REQUEST', true);14 15 /** Set up WordPress environment */16 require_once('./wp-load.php');17 18 /** Atom Publishing Protocol Class */19 require_once(ABSPATH . WPINC . '/atomlib.php');20 21 /** Admin Image API for metadata updating */22 require_once(ABSPATH . '/wp-admin/includes/image.php');23 24 $_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );25 26 /**27 * Whether to always authenticate user. Permanently set to true.28 *29 * @name always_authenticate30 * @var int|bool31 * @todo Should be an option somewhere32 */33 $always_authenticate = 1;34 35 /**36 * Writes logging info to a file.37 *38 * @since 2.2.039 * @deprecated 3.4.040 * @deprecated Use error_log()41 * @link http://www.php.net/manual/en/function.error-log.php42 *43 * @param string $label Type of logging44 * @param string $msg Information describing logging reason.45 */46 function log_app( $label, $msg ) {47 _deprecated_function( __FUNCTION__, '3.4', 'error_log()' );48 if ( ! empty( $GLOBALS['app_logging'] ) )49 error_log( $label . ' - ' . $message );50 }51 52 /**53 * Filter to add more post statuses.54 *55 * @since 2.2.056 *57 * @param string $where SQL statement to filter.58 * @return string Filtered SQL statement with added post_status for where clause.59 */60 function wa_posts_where_include_drafts_filter($where) {61 $where = str_replace("post_status = 'publish'","post_status = 'publish' OR post_status = 'future' OR post_status = 'draft' OR post_status = 'inherit'", $where);62 return $where;63 64 }65 add_filter('posts_where', 'wa_posts_where_include_drafts_filter');66 2 67 3 /** … … 72 8 * @since 2.2.0 73 9 */ 74 class AtomServer {10 class wp_atom_server { 75 11 76 12 /** … … 240 176 'DELETE' => 'delete_attachment'), 241 177 ); 178 179 add_filter( 'wp_die_handler', array( $this, 'return_atom_die_handler' ) ); 180 } 181 182 /** 183 * Override die handler 184 * @return callback 185 */ 186 public function return_atom_die_handler() { 187 return array( $this, 'atom_die_handler' ); 188 } 189 190 /** 191 * Die with a message. Only accept strings, no WP_Error objects yet 192 * @param string $message 193 * @return void 194 */ 195 public function atom_die_handler( $message ) { 196 if ( is_scalar( $message ) ) 197 die( (string) $message ); 198 die(); 242 199 } 243 200 … … 248 205 */ 249 206 function handle_request() { 250 global $always_authenticate;251 207 252 208 if ( !empty( $_SERVER['ORIG_PATH_INFO'] ) ) … … 282 238 // user. each handler will decide if auth is required or not. 283 239 if ( !$this->authenticate() ) { 284 if ( $always_authenticate ) 285 $this->auth_required('Credentials required.'); 240 $this->auth_required('Credentials required.'); 286 241 } 287 242 288 243 array_shift($matches); 289 call_user_func_array(array( &$this,$funcs[$method]), $matches);290 exit();244 call_user_func_array(array($this,$funcs[$method]), $matches); 245 wp_die(); 291 246 } else { 292 247 // only allow what we have handlers for... … … 306 261 */ 307 262 function get_service() { 263 308 264 if ( !current_user_can( 'edit_posts' ) ) 309 265 $this->auth_required( __( 'Sorry, you do not have the right to access this site.' ) ); … … 345 301 */ 346 302 function get_categories_xml() { 303 347 304 if ( !current_user_can( 'edit_posts' ) ) 348 305 $this->auth_required( __( 'Sorry, you do not have the right to access this site.' ) ); … … 411 368 $post_excerpt = ''; 412 369 $pubtimes = ''; 413 370 414 371 if ( isset( $entry->title ) && is_array( $entry->title ) && !empty( $entry->title[1] ) ) 415 372 $post_title = (string) $entry->title[1]; … … 420 377 if ( !empty( $entry->published ) ) 421 378 $pubtimes = (string) $entry->published; 422 379 423 380 $pubtimes = $this->get_publish_time( $pubtimes ); 424 381 … … 684 641 */ 685 642 function delete_attachment($postID) { 643 686 644 // check for not found 687 645 global $entry; … … 751 709 } 752 710 753 exit;711 wp_die(); 754 712 } 755 713 … … 994 952 */ 995 953 function get_posts($page = 1, $post_type = 'post') { 996 $feed = $this->get_feed($page, $post_type);997 $this->output($feed);954 $feed = $this->get_feed($page, $post_type); 955 $this->output($feed); 998 956 } 999 957 … … 1034 992 $count = get_option('posts_per_rss'); 1035 993 1036 wp('posts_per_page=' . $count . '&offset=' . ($count * ($page-1) . '&orderby=modified'));994 wp('posts_per_page=' . $count . '&offset=' . ($count * ($page-1)) . '&orderby=modified&post_status=any'); 1037 995 1038 996 $post = $GLOBALS['post']; … … 1160 1118 header('Content-Type: text/plain'); 1161 1119 status_header('200'); 1162 exit;1120 wp_die(); 1163 1121 } 1164 1122 … … 1172 1130 status_header('204'); 1173 1131 echo "Moved to Trash."; 1174 exit;1132 wp_die(); 1175 1133 } 1176 1134 … … 1186 1144 status_header('500'); 1187 1145 echo $msg; 1188 exit;1146 wp_die(); 1189 1147 } 1190 1148 … … 1197 1155 header('Content-Type: text/plain'); 1198 1156 status_header('400'); 1199 exit;1157 wp_die(); 1200 1158 } 1201 1159 … … 1209 1167 header('Content-Type: text/plain'); 1210 1168 status_header('411'); 1211 exit;1169 wp_die(); 1212 1170 } 1213 1171 … … 1220 1178 header("HTTP/1.1 415 Unsupported Media Type"); 1221 1179 header('Content-Type: text/plain'); 1222 exit;1180 wp_die(); 1223 1181 } 1224 1182 … … 1232 1190 status_header('403'); 1233 1191 echo $reason; 1234 exit;1192 wp_die(); 1235 1193 } 1236 1194 … … 1243 1201 header('Content-Type: text/plain'); 1244 1202 status_header('404'); 1245 exit;1203 wp_die(); 1246 1204 } 1247 1205 … … 1254 1212 header('Allow: ' . join(',', $allow)); 1255 1213 status_header('405'); 1256 exit;1214 wp_die(); 1257 1215 } 1258 1216 … … 1281 1239 header('Location: ' . $url); 1282 1240 echo $content; 1283 exit;1241 wp_die(); 1284 1242 1285 1243 } … … 1293 1251 header('Content-Type: text/plain'); 1294 1252 status_header('400'); 1295 exit;1253 wp_die(); 1296 1254 } 1297 1255 … … 1319 1277 status_header('201'); 1320 1278 echo $content; 1321 exit;1279 wp_die(); 1322 1280 } 1323 1281 … … 1349 1307 EOD; 1350 1308 echo $content; 1351 exit;1309 wp_die(); 1352 1310 } 1353 1311 … … 1361 1319 */ 1362 1320 function output($xml, $ctype = 'application/atom+xml') { 1363 status_header('200');1364 $xml = '<?xml version="1.0" encoding="' . strtolower(get_option('blog_charset')) . '"?>'."\n".$xml;1365 header('Connection: close');1366 header('Content-Length: '. strlen($xml));1367 header('Content-Type: ' . $ctype);1368 header('Content-Disposition: attachment; filename=atom.xml');1369 header('Date: '. date('r'));1370 if ($this->do_output)1371 echo $xml;1372 exit;1321 status_header('200'); 1322 $xml = '<?xml version="1.0" encoding="' . strtolower(get_option('blog_charset')) . '"?>'."\n".$xml; 1323 header('Connection: close'); 1324 header('Content-Length: '. strlen($xml)); 1325 header('Content-Type: ' . $ctype); 1326 header('Content-Disposition: attachment; filename=atom.xml'); 1327 header('Date: '. date('r')); 1328 if ($this->do_output) 1329 echo $xml; 1330 wp_die(); 1373 1331 } 1374 1332 … … 1402 1360 */ 1403 1361 function authenticate() { 1362 1404 1363 // if using mod_rewrite/ENV hack 1405 1364 // http://www.besthostratings.com/articles/http-auth-php-cgi.html … … 1416 1375 // If Basic Auth is working... 1417 1376 if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { 1377 1418 1378 $user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); 1419 1379 if ( $user && !is_wp_error($user) ) { … … 1503 1463 (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) { 1504 1464 status_header( 304 ); 1505 exit;1465 wp_die(); 1506 1466 } 1507 1467 } … … 1547 1507 1548 1508 } 1549 1550 /**1551 * AtomServer1552 * @var AtomServer1553 * @global object $server1554 */1555 $server = new AtomServer();1556 $server->handle_request();
Note: See TracChangeset
for help on using the changeset viewer.