Changeset 19935 for trunk/wp-app.php
- Timestamp:
- 02/17/2012 12:02:42 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-app.php
r19926 r19935 23 23 24 24 $_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] ); 25 26 /**27 * Whether to enable Atom Publishing Protocol Logging.28 *29 * @name app_logging30 * @var int|bool31 */32 $app_logging = 0;33 25 34 26 /** … … 45 37 * 46 38 * @since 2.2.0 47 * @ uses $app_logging48 * @ package WordPress49 * @ subpackage Logging39 * @deprecated 3.4.0 40 * @deprecated Use error_log() 41 * @link http://www.php.net/manual/en/function.error-log.php 50 42 * 51 43 * @param string $label Type of logging 52 44 * @param string $msg Information describing logging reason. 53 45 */ 54 function log_app($label,$msg) { 55 global $app_logging; 56 if ($app_logging) { 57 $fp = fopen( 'wp-app.log', 'a+'); 58 $date = gmdate( 'Y-m-d H:i:s' ); 59 fwrite($fp, "\n\n$date - $label\n$msg\n"); 60 fclose($fp); 61 } 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 ); 62 50 } 63 51 … … 269 257 $method = $_SERVER['REQUEST_METHOD']; 270 258 271 log_app('REQUEST',"$method $path\n================");272 273 259 $this->process_conditionals(); 274 260 //$this->process_conditionals(); … … 320 306 */ 321 307 function get_service() { 322 log_app('function','get_service()');323 324 308 if ( !current_user_can( 'edit_posts' ) ) 325 309 $this->auth_required( __( 'Sorry, you do not have the right to access this site.' ) ); … … 361 345 */ 362 346 function get_categories_xml() { 363 log_app('function','get_categories_xml()');364 365 347 if ( !current_user_can( 'edit_posts' ) ) 366 348 $this->auth_required( __( 'Sorry, you do not have the right to access this site.' ) ); … … 397 379 398 380 $entry = array_pop($parser->feed->entries); 399 400 log_app('Received entry:', print_r($entry,true));401 381 402 382 $catnames = array(); … … 452 432 453 433 $this->escape($post_data); 454 log_app('Inserting Post. Data:', print_r($post_data,true));455 434 456 435 $postID = wp_insert_post($post_data); … … 471 450 $output = $this->get_entry($postID); 472 451 473 log_app('function',"create_post($postID)");474 452 $this->created($postID, $output); 475 453 } … … 490 468 $this->set_current_entry($postID); 491 469 $output = $this->get_entry($postID); 492 log_app('function',"get_post($postID)");493 470 $this->output($output); 494 471 … … 512 489 513 490 $parsed = array_pop($parser->feed->entries); 514 515 log_app('Received UPDATED entry:', print_r($parsed,true));516 491 517 492 // check for not found … … 547 522 do_action( 'atompub_put_post', $ID, $parsed ); 548 523 549 log_app('function',"put_post($postID)");550 524 $this->ok(); 551 525 } … … 576 550 } 577 551 578 log_app('function',"delete_post($postID)");579 552 $this->ok(); 580 553 } … … 598 571 $this->set_current_entry($postID); 599 572 $output = $this->get_entry($postID, 'attachment'); 600 log_app('function',"get_attachment($postID)");601 573 $this->output($output); 602 574 } … … 633 605 $file = wp_upload_bits( $slug, null, $bits); 634 606 635 log_app('wp_upload_bits returns:',print_r($file,true));636 637 607 $url = $file['url']; 638 608 $file = $file['file']; … … 659 629 660 630 $this->created($postID, $output, 'attachment'); 661 log_app('function',"create_attachment($postID)");662 631 } 663 632 … … 704 673 $this->internal_error(__('For some strange yet very annoying reason, this post could not be edited.')); 705 674 706 log_app('function',"put_attachment($postID)");707 675 $this->ok(); 708 676 } … … 716 684 */ 717 685 function delete_attachment($postID) { 718 log_app('function',"delete_attachment($postID). File '$location' deleted.");719 720 686 // check for not found 721 687 global $entry; … … 740 706 $this->internal_error(__('For some strange yet very annoying reason, this post could not be deleted.')); 741 707 742 log_app('function',"delete_attachment($postID). File '$location' deleted.");743 708 $this->ok(); 744 709 } … … 786 751 } 787 752 788 log_app('function',"get_file($postID)");789 753 exit; 790 754 } … … 844 808 wp_update_attachment_metadata( $postID, wp_generate_attachment_metadata( $postID, $location ) ); 845 809 846 log_app('function',"put_file($postID)");847 810 $this->ok(); 848 811 } … … 955 918 $url = $this->app_base . $this->ENTRY_PATH . "/$postID"; 956 919 957 log_app('function',"get_entry_url() = $url");958 920 return $url; 959 921 } … … 986 948 $url = $this->app_base . $this->MEDIA_SINGLE_PATH ."/file/$postID"; 987 949 988 log_app('function',"get_media_url() = $url");989 950 return $url; 990 951 } … … 1010 971 function set_current_entry($postID) { 1011 972 global $entry; 1012 log_app('function',"set_current_entry($postID)");1013 973 1014 974 if (!isset($postID)) { … … 1034 994 */ 1035 995 function get_posts($page = 1, $post_type = 'post') { 1036 log_app('function',"get_posts($page, '$post_type')");1037 996 $feed = $this->get_feed($page, $post_type); 1038 997 $this->output($feed); … … 1048 1007 */ 1049 1008 function get_attachments($page = 1, $post_type = 'attachment') { 1050 log_app('function',"get_attachments($page, '$post_type')");1051 1009 $GLOBALS['post_type'] = $post_type; 1052 1010 $feed = $this->get_feed($page, $post_type); … … 1065 1023 function get_feed($page = 1, $post_type = 'post') { 1066 1024 global $post, $wp, $wp_query, $posts, $wpdb, $blog_id; 1067 log_app('function',"get_feed($page, '$post_type')");1068 1025 ob_start(); 1069 1026 … … 1085 1042 $wpdb = $GLOBALS['wpdb']; 1086 1043 $blog_id = (int) $GLOBALS['blog_id']; 1087 log_app('function',"query_posts(# " . print_r($wp_query, true) . "#)"); 1088 1089 log_app('function',"total_count(# $wp_query->max_num_pages #)"); 1044 1090 1045 $last_page = $wp_query->max_num_pages; 1091 1046 $next_page = (($page + 1) > $last_page) ? null : $page + 1; … … 1132 1087 */ 1133 1088 function get_entry($postID, $post_type = 'post') { 1134 log_app('function',"get_entry($postID, '$post_type')");1135 1089 ob_start(); 1136 1090 switch($post_type) { … … 1148 1102 the_post(); 1149 1103 $this->echo_entry(); 1150 log_app('$post',print_r($GLOBALS['post'],true));1151 1104 $entry = ob_get_contents(); 1152 1105 break; … … 1155 1108 ob_end_clean(); 1156 1109 1157 log_app('get_entry returning:',$entry);1158 1110 return $entry; 1159 1111 } … … 1206 1158 */ 1207 1159 function ok() { 1208 log_app('Status','200: OK');1209 1160 header('Content-Type: text/plain'); 1210 1161 status_header('200'); … … 1218 1169 */ 1219 1170 function no_content() { 1220 log_app('Status','204: No Content');1221 1171 header('Content-Type: text/plain'); 1222 1172 status_header('204'); … … 1233 1183 */ 1234 1184 function internal_error($msg = 'Internal Server Error') { 1235 log_app('Status','500: Server Error');1236 1185 header('Content-Type: text/plain'); 1237 1186 status_header('500'); … … 1246 1195 */ 1247 1196 function bad_request() { 1248 log_app('Status','400: Bad Request');1249 1197 header('Content-Type: text/plain'); 1250 1198 status_header('400'); … … 1258 1206 */ 1259 1207 function length_required() { 1260 log_app('Status','411: Length Required');1261 1208 header("HTTP/1.1 411 Length Required"); 1262 1209 header('Content-Type: text/plain'); … … 1271 1218 */ 1272 1219 function invalid_media() { 1273 log_app('Status','415: Unsupported Media Type');1274 1220 header("HTTP/1.1 415 Unsupported Media Type"); 1275 1221 header('Content-Type: text/plain'); … … 1283 1229 */ 1284 1230 function forbidden($reason='') { 1285 log_app('Status','403: Forbidden');1286 1231 header('Content-Type: text/plain'); 1287 1232 status_header('403'); … … 1296 1241 */ 1297 1242 function not_found() { 1298 log_app('Status','404: Not Found');1299 1243 header('Content-Type: text/plain'); 1300 1244 status_header('404'); … … 1308 1252 */ 1309 1253 function not_allowed($allow) { 1310 log_app('Status','405: Not Allowed');1311 1254 header('Allow: ' . join(',', $allow)); 1312 1255 status_header('405'); … … 1320 1263 */ 1321 1264 function redirect($url) { 1322 1323 log_app('Status','302: Redirect');1324 1265 $escaped_url = esc_attr($url); 1325 1266 $content = <<<EOD … … 1350 1291 */ 1351 1292 function client_error($msg = 'Client Error') { 1352 log_app('Status','400: Client Error');1353 1293 header('Content-Type: text/plain'); 1354 1294 status_header('400'); … … 1364 1304 */ 1365 1305 function created($post_ID, $content, $post_type = 'post') { 1366 log_app('created()::$post_ID',"$post_ID, $post_type");1367 1306 $edit = $this->get_entry_url($post_ID); 1368 1307 switch($post_type) { … … 1391 1330 */ 1392 1331 function auth_required($msg) { 1393 log_app('Status','401: Auth Required');1394 1332 nocache_headers(); 1395 1333 header('WWW-Authenticate: Basic realm="WordPress Atom Protocol"'); … … 1432 1370 if ($this->do_output) 1433 1371 echo $xml; 1434 log_app('function', "output:\n$xml");1435 1372 exit; 1436 1373 } … … 1465 1402 */ 1466 1403 function authenticate() { 1467 log_app("authenticate()",print_r($_ENV, true));1468 1469 1404 // if using mod_rewrite/ENV hack 1470 1405 // http://www.besthostratings.com/articles/http-auth-php-cgi.html … … 1481 1416 // If Basic Auth is working... 1482 1417 if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { 1483 log_app("Basic Auth",$_SERVER['PHP_AUTH_USER']);1484 1485 1418 $user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); 1486 1419 if ( $user && !is_wp_error($user) ) { 1487 1420 wp_set_current_user($user->ID); 1488 log_app("authenticate()", $user->user_login);1489 1421 return true; 1490 1422 } … … 1515 1447 list($type,$subtype) = explode('/',$type); 1516 1448 list($subtype) = explode(";",$subtype); // strip MIME parameters 1517 log_app("get_accepted_content_type", "type=$type, subtype=$subtype");1518 1449 1519 1450 foreach($types as $t) {
Note: See TracChangeset
for help on using the changeset viewer.