Changeset 8954
- Timestamp:
- 09/22/2008 08:06:48 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-app.php
r8952 r8954 47 47 48 48 /** 49 * log_app() -Writes logging info to a file.49 * Writes logging info to a file. 50 50 * 51 * @since 2.2.0 51 52 * @uses $app_logging 52 53 * @package WordPress … … 68 69 if ( !function_exists('wp_set_current_user') ) : 69 70 /** 70 * Sets the current WordPress User. 71 * 72 * Pluggable function which is also found in pluggable.php. 73 * 74 * @see wp-includes/pluggable.php Documentation for this function. 75 * @uses $current_user Global of current user to test whether $id is the same. 76 * 77 * @param int $id The user's ID. 78 * @param string $name Optional. The username of the user. 79 * @return WP_User Current user's User object 71 * @ignore 80 72 */ 81 73 function wp_set_current_user($id, $name = '') { … … 94 86 * Filter to add more post statuses. 95 87 * 96 * @param string $where SQL statement to filter 97 * @return string Filtered SQL statement with added post_status for where clause 88 * @since 2.2.0 89 * 90 * @param string $where SQL statement to filter. 91 * @return string Filtered SQL statement with added post_status for where clause. 98 92 */ 99 93 function wa_posts_where_include_drafts_filter($where) { … … 113 107 class AtomServer { 114 108 109 /** 110 * ATOM content type. 111 * 112 * @since 2.2.0 113 * @var string 114 */ 115 115 var $ATOM_CONTENT_TYPE = 'application/atom+xml'; 116 117 /** 118 * Categories ATOM content type. 119 * 120 * @since 2.2.0 121 * @var string 122 */ 116 123 var $CATEGORIES_CONTENT_TYPE = 'application/atomcat+xml'; 124 125 /** 126 * Service ATOM content type. 127 * 128 * @since 2.3.0 129 * @var string 130 */ 117 131 var $SERVICE_CONTENT_TYPE = 'application/atomsvc+xml'; 118 132 133 /** 134 * ATOM XML namespace. 135 * 136 * @since 2.3.0 137 * @var string 138 */ 119 139 var $ATOM_NS = 'http://www.w3.org/2005/Atom'; 140 141 /** 142 * ATOMPUB XML namespace. 143 * 144 * @since 2.3.0 145 * @var string 146 */ 120 147 var $ATOMPUB_NS = 'http://www.w3.org/2007/app'; 121 148 149 /** 150 * Entries path. 151 * 152 * @since 2.2.0 153 * @var string 154 */ 122 155 var $ENTRIES_PATH = "posts"; 156 157 /** 158 * Categories path. 159 * 160 * @since 2.2.0 161 * @var string 162 */ 123 163 var $CATEGORIES_PATH = "categories"; 164 165 /** 166 * Media path. 167 * 168 * @since 2.2.0 169 * @var string 170 */ 124 171 var $MEDIA_PATH = "attachments"; 172 173 /** 174 * Entry path. 175 * 176 * @since 2.2.0 177 * @var string 178 */ 125 179 var $ENTRY_PATH = "post"; 180 181 /** 182 * Service path. 183 * 184 * @since 2.2.0 185 * @var string 186 */ 126 187 var $SERVICE_PATH = "service"; 188 189 /** 190 * Media single path. 191 * 192 * @since 2.2.0 193 * @var string 194 */ 127 195 var $MEDIA_SINGLE_PATH = "attachment"; 128 196 197 /** 198 * ATOMPUB parameters. 199 * 200 * @since 2.2.0 201 * @var array 202 */ 129 203 var $params = array(); 204 205 /** 206 * Supported ATOMPUB media types. 207 * 208 * @since 2.3.0 209 * @var array 210 */ 130 211 var $media_content_types = array('image/*','audio/*','video/*'); 212 213 /** 214 * ATOMPUB content type(s). 215 * 216 * @since 2.2.0 217 * @var array 218 */ 131 219 var $atom_content_types = array('application/atom+xml'); 132 220 221 /** 222 * ATOMPUB methods. 223 * 224 * @since 2.2.0 225 * @var unknown_type 226 */ 133 227 var $selectors = array(); 134 228 135 // support for head 229 /** 230 * Whether to do output. 231 * 232 * Support for head. 233 * 234 * @since 2.2.0 235 * @var bool 236 */ 136 237 var $do_output = true; 137 238 239 /** 240 * PHP4 constructor - Sets up object properties. 241 * 242 * @since 2.2.0 243 * @return AtomServer 244 */ 138 245 function AtomServer() { 139 246 … … 170 277 } 171 278 279 /** 280 * Handle ATOMPUB request. 281 * 282 * @since 2.2.0 283 */ 172 284 function handle_request() { 173 285 global $always_authenticate; … … 227 339 } 228 340 341 /** 342 * Retrieve XML for ATOMPUB service. 343 * 344 * @since 2.2.0 345 */ 229 346 function get_service() { 230 347 log_app('function','get_service()'); … … 262 379 } 263 380 381 /** 382 * Retrieve categories list in XML format. 383 * 384 * @since 2.2.0 385 */ 264 386 function get_categories_xml() { 265 387 log_app('function','get_categories_xml()'); … … 285 407 } 286 408 287 /* 288 * Create Post (No arguments) 409 /** 410 * Create new post. 411 * 412 * @since 2.2.0 289 413 */ 290 414 function create_post() { … … 358 482 } 359 483 484 /** 485 * Retrieve post. 486 * 487 * @since 2.2.0 488 * 489 * @param int $postID Post ID. 490 */ 360 491 function get_post($postID) { 361 492 global $entry; … … 371 502 } 372 503 504 /** 505 * Update post. 506 * 507 * @since 2.2.0 508 * 509 * @param int $postID Post ID. 510 */ 373 511 function put_post($postID) { 374 512 // checked for valid content-types (atom+xml) … … 420 558 } 421 559 560 /** 561 * Remove post. 562 * 563 * @since 2.2.0 564 * 565 * @param int $postID Post ID. 566 */ 422 567 function delete_post($postID) { 423 568 … … 445 590 } 446 591 447 function get_attachment($postID = NULL) { 592 /** 593 * Retrieve attachment. 594 * 595 * @since 2.2.0 596 * 597 * @param int $postID Optional. Post ID. 598 */ 599 function get_attachment($postID = null) { 448 600 if( !current_user_can( 'upload_files' ) ) 449 601 $this->auth_required( __( 'Sorry, you do not have permission to upload files.' ) ); … … 459 611 } 460 612 613 /** 614 * Create new attachment. 615 * 616 * @since 2.2.0 617 */ 461 618 function create_attachment() { 462 619 … … 467 624 468 625 $fp = fopen("php://input", "rb"); 469 $bits = NULL;626 $bits = null; 470 627 while(!feof($fp)) { 471 628 $bits .= fread($fp, 4096); … … 513 670 } 514 671 672 /** 673 * Update attachment. 674 * 675 * @since 2.2.0 676 * 677 * @param int $postID Post ID. 678 */ 515 679 function put_attachment($postID) { 516 680 // checked for valid content-types (atom+xml) … … 553 717 } 554 718 719 /** 720 * Remove attachment. 721 * 722 * @since 2.2.0 723 * 724 * @param int $postID Post ID. 725 */ 555 726 function delete_attachment($postID) { 556 727 log_app('function',"delete_attachment($postID). File '$location' deleted."); … … 584 755 } 585 756 757 /** 758 * Retrieve attachment from post. 759 * 760 * @since 2.2.0 761 * 762 * @param int $postID Post ID. 763 */ 586 764 function get_file($postID) { 587 765 … … 615 793 } 616 794 795 /** 796 * Upload file to blog and add attachment to post. 797 * 798 * @since 2.2.0 799 * 800 * @param int $postID Post ID. 801 */ 617 802 function put_file($postID) { 618 803 … … 663 848 } 664 849 665 function get_entries_url($page = NULL) { 850 /** 851 * Retrieve entries URL. 852 * 853 * @since 2.2.0 854 * 855 * @param int $page Page ID. 856 * @return string 857 */ 858 function get_entries_url($page = null) { 666 859 if($GLOBALS['post_type'] == 'attachment') { 667 860 $path = $this->MEDIA_PATH; … … 676 869 } 677 870 678 function the_entries_url($page = NULL) { 871 /** 872 * Display entries URL. 873 * 874 * @since 2.2.0 875 * 876 * @param int $page Page ID. 877 */ 878 function the_entries_url($page = null) { 679 879 echo $this->get_entries_url($page); 680 880 } 681 881 882 /** 883 * Retrieve categories URL. 884 * 885 * @since 2.2.0 886 * 887 * @param mixed $deprecated Optional, not used. 888 * @return string 889 */ 682 890 function get_categories_url($deprecated = '') { 683 891 return $this->app_base . $this->CATEGORIES_PATH; 684 892 } 685 893 894 /** 895 * Display category URL. 896 * 897 * @since 2.2.0 898 */ 686 899 function the_categories_url() { 687 900 echo $this->get_categories_url(); 688 901 } 689 902 690 function get_attachments_url($page = NULL) { 903 /** 904 * Retrieve attachment URL. 905 * 906 * @since 2.2.0 907 * 908 * @param int $page Page ID. 909 * @return string 910 */ 911 function get_attachments_url($page = null) { 691 912 $url = $this->app_base . $this->MEDIA_PATH; 692 913 if(isset($page) && is_int($page)) { … … 696 917 } 697 918 698 function the_attachments_url($page = NULL) { 919 /** 920 * Display attachment URL. 921 * 922 * @since 2.2.0 923 * 924 * @param int $page Page ID. 925 */ 926 function the_attachments_url($page = null) { 699 927 echo $this->get_attachments_url($page); 700 928 } 701 929 930 /** 931 * Retrieve service URL. 932 * 933 * @since 2.3.0 934 * 935 * @return string 936 */ 702 937 function get_service_url() { 703 938 return $this->app_base . $this->SERVICE_PATH; 704 939 } 705 940 706 function get_entry_url($postID = NULL) { 941 /** 942 * Retrieve entry URL. 943 * 944 * @since 2.7.0 945 * 946 * @param int $postID Post ID. 947 * @return string 948 */ 949 function get_entry_url($postID = null) { 707 950 if(!isset($postID)) { 708 951 global $post; … … 716 959 } 717 960 718 function the_entry_url($postID = NULL) { 961 /** 962 * Display entry URL. 963 * 964 * @since 2.7.0 965 * 966 * @param int $postID Post ID. 967 */ 968 function the_entry_url($postID = null) { 719 969 echo $this->get_entry_url($postID); 720 970 } 721 971 722 function get_media_url($postID = NULL) { 972 /** 973 * Retrieve media URL. 974 * 975 * @since 2.2.0 976 * 977 * @param int $postID Post ID. 978 * @return string 979 */ 980 function get_media_url($postID = null) { 723 981 if(!isset($postID)) { 724 982 global $post; … … 732 990 } 733 991 734 function the_media_url($postID = NULL) { 992 /** 993 * Display the media URL. 994 * 995 * @since 2.2.0 996 * 997 * @param int $postID Post ID. 998 */ 999 function the_media_url($postID = null) { 735 1000 echo $this->get_media_url($postID); 736 1001 } 737 1002 1003 /** 1004 * Set the current entry to post ID. 1005 * 1006 * @since 2.2.0 1007 * 1008 * @param int $postID Post ID. 1009 */ 738 1010 function set_current_entry($postID) { 739 1011 global $entry; … … 753 1025 } 754 1026 1027 /** 1028 * Display posts XML. 1029 * 1030 * @since 2.2.0 1031 * 1032 * @param int $page Optional. Page ID. 1033 * @param string $post_type Optional, default is 'post'. Post Type. 1034 */ 755 1035 function get_posts($page = 1, $post_type = 'post') { 756 1036 log_app('function',"get_posts($page, '$post_type')"); … … 759 1039 } 760 1040 1041 /** 1042 * Display attachment XML. 1043 * 1044 * @since 2.2.0 1045 * 1046 * @param int $page Page ID. 1047 * @param string $post_type Optional, default is 'attachment'. Post type. 1048 */ 761 1049 function get_attachments($page = 1, $post_type = 'attachment') { 762 log_app('function',"get_attachments($page, '$post_type')"); 763 $GLOBALS['post_type'] = $post_type; 764 $feed = $this->get_feed($page, $post_type); 765 $this->output($feed); 766 } 767 1050 log_app('function',"get_attachments($page, '$post_type')"); 1051 $GLOBALS['post_type'] = $post_type; 1052 $feed = $this->get_feed($page, $post_type); 1053 $this->output($feed); 1054 } 1055 1056 /** 1057 * Retrieve feed XML. 1058 * 1059 * @since 2.2.0 1060 * 1061 * @param int $page Page ID. 1062 * @param string $post_type Optional, default is post. Post type. 1063 * @return string 1064 */ 768 1065 function get_feed($page = 1, $post_type = 'post') { 769 1066 global $post, $wp, $wp_query, $posts, $wpdb, $blog_id; … … 823 1120 } 824 1121 1122 /** 1123 * Display entry XML. 1124 * 1125 * @since 2.2.0 1126 * 1127 * @param int $postID Post ID. 1128 * @param string $post_type Optional, default is post. Post type. 1129 * @return string. 1130 */ 825 1131 function get_entry($postID, $post_type = 'post') { 826 1132 log_app('function',"get_entry($postID, '$post_type')"); … … 850 1156 } 851 1157 1158 /** 1159 * Display post content XML. 1160 * 1161 * @since 2.3.0 1162 */ 852 1163 function echo_entry() { ?> 853 1164 <entry xmlns="<?php echo $this->ATOM_NS ?>" … … 887 1198 <?php } 888 1199 1200 /** 1201 * Set 'OK' (200) status header. 1202 * 1203 * @since 2.2.0 1204 */ 889 1205 function ok() { 890 1206 log_app('Status','200: OK'); … … 894 1210 } 895 1211 1212 /** 1213 * Set 'No Content' (204) status header. 1214 * 1215 * @since 2.2.0 1216 */ 896 1217 function no_content() { 897 1218 log_app('Status','204: No Content'); … … 902 1223 } 903 1224 1225 /** 1226 * Display 'Internal Server Error' (500) status header. 1227 * 1228 * @since 2.2.0 1229 * 1230 * @param string $msg Optional. Status string. 1231 */ 904 1232 function internal_error($msg = 'Internal Server Error') { 905 1233 log_app('Status','500: Server Error'); … … 910 1238 } 911 1239 1240 /** 1241 * Set 'Bad Request' (400) status header. 1242 * 1243 * @since 2.2.0 1244 */ 912 1245 function bad_request() { 913 1246 log_app('Status','400: Bad Request'); … … 917 1250 } 918 1251 1252 /** 1253 * Set 'Length Required' (411) status header. 1254 * 1255 * @since 2.2.0 1256 */ 919 1257 function length_required() { 920 1258 log_app('Status','411: Length Required'); … … 925 1263 } 926 1264 1265 /** 1266 * Set 'Unsupported Media Type' (415) status header. 1267 * 1268 * @since 2.2.0 1269 */ 927 1270 function invalid_media() { 928 1271 log_app('Status','415: Unsupported Media Type'); … … 932 1275 } 933 1276 1277 /** 1278 * Set 'Forbidden' (403) status header. 1279 * 1280 * @since 2.6.0 1281 */ 934 1282 function forbidden($reason='') { 935 1283 log_app('Status','403: Forbidden'); … … 940 1288 } 941 1289 1290 /** 1291 * Set 'Not Found' (404) status header. 1292 * 1293 * @since 2.2.0 1294 */ 942 1295 function not_found() { 943 1296 log_app('Status','404: Not Found'); … … 947 1300 } 948 1301 1302 /** 1303 * Set 'Not Allowed' (405) status header. 1304 * 1305 * @since 2.2.0 1306 */ 949 1307 function not_allowed($allow) { 950 1308 log_app('Status','405: Not Allowed'); … … 954 1312 } 955 1313 1314 /** 1315 * Display Redirect (302) content and set status headers. 1316 * 1317 * @since 2.3.0 1318 */ 956 1319 function redirect($url) { 957 1320 … … 979 1342 } 980 1343 981 1344 /** 1345 * Set 'Client Error' (400) status header. 1346 * 1347 * @since 2.2.0 1348 */ 982 1349 function client_error($msg = 'Client Error') { 983 1350 log_app('Status','400: Client Error'); … … 987 1354 } 988 1355 1356 /** 1357 * Set created status headers (201). 1358 * 1359 * Sets the 'content-type', 'content-location', and 'location'. 1360 * 1361 * @since 2.2.0 1362 */ 989 1363 function created($post_ID, $content, $post_type = 'post') { 990 1364 log_app('created()::$post_ID',"$post_ID, $post_type"); … … 1007 1381 } 1008 1382 1383 /** 1384 * Set 'Auth Required' (401) headers. 1385 * 1386 * @since 2.2.0 1387 * 1388 * @param string $msg Status header content and HTML content. 1389 */ 1009 1390 function auth_required($msg) { 1010 1391 log_app('Status','401: Auth Required'); … … 1031 1412 } 1032 1413 1414 /** 1415 * Display XML and set headers with content type. 1416 * 1417 * @since 2.2.0 1418 * 1419 * @param string $xml Display feed content. 1420 * @param string $ctype Optional, default is 'atom+xml'. Feed content type. 1421 */ 1033 1422 function output($xml, $ctype = 'application/atom+xml') { 1034 1423 status_header('200'); … … 1045 1434 } 1046 1435 1436 /** 1437 * Sanitize content for database usage. 1438 * 1439 * @since 2.2.0 1440 * 1441 * @param array $array Sanitize array and multi-dimension array. 1442 */ 1047 1443 function escape(&$array) { 1048 1444 global $wpdb; … … 1059 1455 } 1060 1456 1061 /* 1062 * Access credential through various methods and perform login 1457 /** 1458 * Access credential through various methods and perform login. 1459 * 1460 * @since 2.2.0 1461 * 1462 * @return bool 1063 1463 */ 1064 1464 function authenticate() { … … 1086 1486 } 1087 1487 1088 function get_accepted_content_type($types = NULL) { 1488 /** 1489 * Retrieve accepted content types. 1490 * 1491 * @since 2.2.0 1492 * 1493 * @param array $types Optional. Content Types. 1494 * @return string 1495 */ 1496 function get_accepted_content_type($types = null) { 1089 1497 1090 1498 if(!isset($types)) { … … 1112 1520 } 1113 1521 1522 /** 1523 * Process conditionals for posts. 1524 * 1525 * @since 2.2.0 1526 */ 1114 1527 function process_conditionals() { 1115 1528 … … 1155 1568 } 1156 1569 1570 /** 1571 * Convert RFC3339 time string to timestamp. 1572 * 1573 * @since 2.3.0 1574 * 1575 * @param string $str String to time. 1576 * @return bool|int false if format is incorrect. 1577 */ 1157 1578 function rfc3339_str2time($str) { 1158 1579 1159 1160 1580 $match = false; 1581 if(!preg_match("/(\d{4}-\d{2}-\d{2})T(\d{2}\:\d{2}\:\d{2})\.?\d{0,3}(Z|[+-]+\d{2}\:\d{2})/", $str, $match)) 1161 1582 return false; 1162 1583 1163 1584 if($match[3] == 'Z') 1164 1585 $match[3] == '+0000'; 1165 1586 1166 return strtotime($match[1] . " " . $match[2] . " " . $match[3]); 1167 } 1168 1587 return strtotime($match[1] . " " . $match[2] . " " . $match[3]); 1588 } 1589 1590 /** 1591 * Retrieve published time to display in XML. 1592 * 1593 * @since 2.3.0 1594 * 1595 * @param string $published Time string. 1596 * @return string 1597 */ 1169 1598 function get_publish_time($published) { 1170 1599 1171 1172 1173 1600 $pubtime = $this->rfc3339_str2time($published); 1601 1602 if(!$pubtime) { 1174 1603 return array(current_time('mysql'),current_time('mysql',1)); 1175 1604 } else { 1176 1605 return array(date("Y-m-d H:i:s", $pubtime), gmdate("Y-m-d H:i:s", $pubtime)); 1177 1606 } 1178 1607 } 1179 1608 1180 1609 } 1181 1610 1611 /** 1612 * AtomServer 1613 * @var AtomServer 1614 * @global object $server 1615 */ 1182 1616 $server = new AtomServer(); 1183 1617 $server->handle_request();
Note: See TracChangeset
for help on using the changeset viewer.