Changeset 4916
- Timestamp:
- 02/22/2007 07:44:16 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/app.php
r4880 r4916 5 5 * Modified by: Dougal Campbell, http://dougal.gunters.org/ 6 6 * 7 * Version: 1.0. 0-dc7 * Version: 1.0.5-dc 8 8 */ 9 9 10 10 define('APP_REQUEST', true); 11 11 12 12 require_once('wp-config.php'); 13 14 $use_querystring = 1; 13 require_once('wp-includes/post-template.php'); 14 15 // Attempt to automatically detect whether to use querystring 16 // or PATH_INFO, based on our environment: 17 $use_querystring = $wp_version == 'MU' ? 1 : 0; 15 18 16 19 // If using querystring, we need to put the path together manually: 17 20 if ($use_querystring) { 18 $ _GLOBALS['use_querystring'] = $use_querystring;21 $GLOBALS['use_querystring'] = $use_querystring; 19 22 $action = $_GET['action']; 20 23 $eid = (int) $_GET['eid']; … … 29 32 } 30 33 31 $app_logging = 1;34 $app_logging = 0; 32 35 33 36 function log_app($label,$msg) { … … 258 261 259 262 var $ATOM_CONTENT_TYPE = 'application/atom+xml'; 260 263 var $CATEGORIES_CONTENT_TYPE = 'application/atomcat+xml'; 261 264 var $INTROSPECTION_CONTENT_TYPE = 'application/atomserv+xml'; 262 265 263 266 var $ENTRIES_PATH = "posts"; 267 var $CATEGORIES_PATH = "categories"; 264 268 var $MEDIA_PATH = "attachments"; 265 269 var $ENTRY_PATH = "post"; … … 283 287 '@/service@' => 284 288 array('GET' => 'get_service'), 289 '@/categories@' => 290 array('GET' => 'get_categories_xml'), 285 291 '@/post/(\d+)@' => 286 292 array('GET' => 'get_post', … … 349 355 log_app('function','get_service()'); 350 356 $entries_url = $this->get_entries_url(); 357 $categories_url = $this->get_categories_url(); 351 358 $media_url = $this->get_attachments_url(); 352 359 $accepted_content_types = join(',',$this->media_content_types); 353 360 $introspection = <<<EOD 354 <service xmlns="http://purl.org/atom/app#" xmlns:atom="http://www.w3.org/2005/Atom"> 355 <workspace title="WordPress Experimental Workspace"> 356 <collection href="$entries_url" title="WordPress Posts"> 357 <accept>entry</accept> 358 <atom:title>WordPress Posts</atom:title> 359 </collection> 360 <collection href="$media_url" title="WordPress Media"> 361 <accept>$accepted_content_types</accept> 362 <atom:title>WordPress Media</atom:title> 363 </collection> 364 </workspace> 361 <service xmlns="http://purl.org/atom/app#" xmlns:atom="http://www.w3.org/2005/Atom"> 362 <workspace title="WordPress Workspace"> 363 <collection href="$entries_url" title="Posts"> 364 <atom:title>WordPress Posts</atom:title> 365 <accept>entry</accept> 366 <categories href="$categories_url" /> 367 </collection> 368 <collection href="$media_url" title="Media"> 369 <atom:title>WordPress Media</atom:title> 370 <accept>$accepted_content_types</accept> 371 </collection> 372 </workspace> 365 373 </service> 366 374 367 375 EOD; 376 368 377 $this->output($introspection, $this->INTROSPECTION_CONTENT_TYPE); 369 378 } 379 380 function get_categories_xml() { 381 log_app('function','get_categories_xml()'); 382 $home = get_bloginfo_rss('home'); 383 384 $categories = ""; 385 $cats = get_categories("hierarchical=0&hide_empty=0"); 386 foreach ((array) $cats as $cat) { 387 $categories .= " <category term=\"" . attribute_escape($cat->cat_name) . "\" />\n"; 388 } 389 $output = <<<EOD 390 <app:categories xmlns:app="http://purl.org/atom/app#" 391 xmlns="http://www.w3.org/2005/Atom" 392 fixed="yes" scheme="$home"> 393 $categories 394 </app:categories> 395 EOD; 396 $this->output($output, $this->CATEGORIES_CONTENT_TYPE); 397 } 370 398 371 399 /* … … 373 401 */ 374 402 function create_post() { 375 403 global $current_blog; 376 404 $this->get_accepted_content_type($this->atom_content_types); 377 405 … … 390 418 $this->auth_required('Sorry, you do not have the right to edit/publish new posts.'); 391 419 392 $blog_ID = 1;420 $blog_ID = $current_blog->blog_id; 393 421 $post_status = ($publish) ? 'publish' : 'draft'; 394 422 $post_author = $user->ID; … … 401 429 $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt'); 402 430 431 log_app('Inserting Post. Data:', print_r($post_data,true)); 432 403 433 $postID = wp_insert_post($post_data); 404 434 … … 438 468 // check for not found 439 469 global $entry; 470 $entry = $GLOBALS['entry']; 440 471 $this->set_current_entry($postID); 441 $this->escape($ entry);472 $this->escape($GLOBALS['entry']); 442 473 443 474 if(!current_user_can('edit_post', $entry['ID'])) … … 508 539 509 540 function create_attachment() { 541 global $wp, $wpdb, $wp_query, $blog_id; 510 542 511 543 $type = $this->get_accepted_content_type(); … … 532 564 $file = wp_upload_bits( $slug, NULL, $bits); 533 565 566 log_app('wp_upload_bits returns:',print_r($file,true)); 567 534 568 $url = $file['url']; 535 569 $file = $file['file']; … … 696 730 $url .= '?action=/' . $this->ENTRIES_PATH; 697 731 if(isset($page) && is_int($page)) { 698 $url .= "& eid=$page";732 $url .= "&eid=$page"; 699 733 } 700 734 } else { … … 712 746 } 713 747 748 function get_categories_url($page = NULL) { 749 global $use_querystring; 750 $url = get_bloginfo('url') . '/' . $this->script_name; 751 if ($use_querystring) { 752 $url .= '?action=/' . $this->CATEGORIES_PATH; 753 } else { 754 $url .= '/' . $this->CATEGORIES_PATH; 755 } 756 return $url; 757 } 758 759 function the_categories_url() { 760 $url = $this->get_categories_url(); 761 echo $url; 762 } 763 714 764 function get_attachments_url($page = NULL) { 715 765 global $use_querystring; … … 718 768 $url .= '?action=/' . $this->MEDIA_PATH; 719 769 if(isset($page) && is_int($page)) { 720 $url .= "& eid=$page";770 $url .= "&eid=$page"; 721 771 } 722 772 } else { … … 739 789 if(!isset($postID)) { 740 790 global $post; 741 $postID = $ post->ID;791 $postID = $GLOBALS['post']->ID; 742 792 } 743 793 744 794 if ($use_querystring) { 745 $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->ENTRY_PATH . "& eid=$postID";795 $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->ENTRY_PATH . "&eid=$postID"; 746 796 } else { 747 797 $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; … … 761 811 if(!isset($postID)) { 762 812 global $post; 763 $postID = $ post->ID;813 $postID = $GLOBALS['post']->ID; 764 814 } 765 815 766 816 if ($use_querystring) { 767 $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->MEDIA_SINGLE_PATH ."& eid=$postID";817 $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->MEDIA_SINGLE_PATH ."&eid=$postID"; 768 818 } else { 769 819 $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/$postID"; … … 816 866 817 867 function get_feed($page = 1, $post_type = 'post') { 868 global $post, $wp, $wp_query, $posts, $wpdb, $blog_id, $post_cache; 818 869 log_app('function',"get_feed($page, '$post_type')"); 819 870 ob_start(); … … 830 881 } 831 882 query_posts($query); 832 global $post; 883 $post = $GLOBALS['post']; 884 $posts = $GLOBALS['posts']; 885 $wp = $GLOBALS['wp']; 886 $wp_query = $GLOBALS['wp_query']; 887 $wpdb = $GLOBALS['wpdb']; 888 $blog_id = $GLOBALS['blog_id']; 889 $post_cache = $GLOBALS['post_cache']; 890 833 891 834 892 $total_count = $this->get_posts_count(); … … 852 910 <link rel="self" type="application/atom+xml" href="<?php $this->the_entries_url() ?>" /> 853 911 <rights type="text">Copyright <?php echo mysql2date('Y', get_lastpostdate('blog')); ?></rights> 854 <generator uri="http://wordpress.com/" version="1.0.0-dc">WordPress.com Atom API</generator> 855 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 912 <generator uri="http://wordpress.com/" version="1.0.5-dc">WordPress.com Atom API</generator> 913 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 914 $post = $GLOBALS['post']; 915 ?> 856 916 <entry> 857 <id><?php the_guid( ); ?></id>917 <id><?php the_guid($post->ID); ?></id> 858 918 <title type="html"><![CDATA[<?php the_title() ?>]]></title> 859 919 <updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated> 860 920 <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> 861 921 <app:control> 862 <app:draft><?php echo ($ post->post_status == 'draft' ? 'yes' : 'no') ?></app:draft>922 <app:draft><?php echo ($GLOBALS['post']->post_status == 'draft' ? 'yes' : 'no') ?></app:draft> 863 923 </app:control> 864 924 <author> … … 869 929 <?php } ?> 870 930 </author> 871 <?php if($ post->post_status == 'attachment') { ?>931 <?php if($GLOBALS['post']->post_status == 'attachment') { ?> 872 932 <link rel="edit" href="<?php $this->the_entry_url() ?>" /> 873 933 <link rel="edit-media" href="<?php $this->the_media_url() ?>" /> … … 879 939 <category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->cat_name?>" /> 880 940 <?php } ?> <summary type="html"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> 881 <?php if ( strlen( $ post->post_content ) ) : ?>882 <content type="html">< ?php echo get_the_content('', 0, '') ?></content>941 <?php if ( strlen( $GLOBALS['post']->post_content ) ) : ?> 942 <content type="html"><![CDATA[<?php echo get_the_content('', 0, '') ?>]]></content> 883 943 <?php endif; ?> 884 944 </entry> … … 896 956 log_app('function',"get_entry($postID, '$post_type')"); 897 957 ob_start(); 898 global $posts, $post, $wp_query ;958 global $posts, $post, $wp_query, $wp, $wpdb, $blog_id, $post_cache; 899 959 switch($post_type) { 900 960 case 'post': … … 906 966 } 907 967 query_posts($varname . '=' . $postID); 908 if ( have_posts() ) : while ( have_posts() ) : the_post();?> 968 if ( have_posts() ) : while ( have_posts() ) : the_post(); 969 $post = $GLOBALS['post']; 970 ?> 971 <?php log_app('$post',print_r($GLOBALS['post'],true)); ?> 909 972 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#" xml:lang="<?php echo get_option('rss_language'); ?>"> 910 <id><?php the_guid( ); ?></id>973 <id><?php the_guid($post->ID); ?></id> 911 974 <title type="html"><![CDATA[<?php the_title_rss() ?>]]></title> 912 975 … … 914 977 <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> 915 978 <app:control> 916 <app:draft><?php echo ($ post->post_status == 'draft' ? 'yes' : 'no') ?></app:draft>979 <app:draft><?php echo ($GLOBALS['post']->post_status == 'draft' ? 'yes' : 'no') ?></app:draft> 917 980 </app:control> 918 981 <author> … … 921 984 <uri><?php the_author_url()?></uri> 922 985 </author> 923 <?php if($ post->post_type == 'attachment') { ?>986 <?php if($GLOBALS['post']->post_type == 'attachment') { ?> 924 987 <link rel="edit" href="<?php $this->the_entry_url() ?>" /> 925 988 <link rel="edit-media" href="<?php $this->the_media_url() ?>" /> 926 <content type="<?php echo $ post->post_mime_type ?>" src="<?php the_guid(); ?>"/>989 <content type="<?php echo $GLOBALS['post']->post_mime_type ?>" src="<?php the_guid(); ?>"/> 927 990 <?php } else { ?> 928 991 <link href="<?php permalink_single_rss() ?>" /> … … 933 996 <summary type="html"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> 934 997 <?php } 935 if ( strlen( $ post->post_content ) ) : ?>936 <content type="html">< ?php echo get_the_content('', 0, '') ?></content>998 if ( strlen( $GLOBALS['post']->post_content ) ) : ?> 999 <content type="html"><![CDATA[<?php echo get_the_content('', 0, '') ?>]]></content> 937 1000 <?php endif; ?> 938 1001 </entry> … … 1026 1089 case 'attachment': 1027 1090 if ($use_querystring) { 1028 $edit = get_bloginfo('url') . '/' . $this->script_name . "?action=/attachments& eid=$post_ID";1091 $edit = get_bloginfo('url') . '/' . $this->script_name . "?action=/attachments&eid=$post_ID"; 1029 1092 } else { 1030 1093 $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; … … 1055 1118 function output($xml, $ctype = "application/atom+xml") { 1056 1119 status_header('200'); 1057 $xml = '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?>'."\n".$xml;1120 $xml = '<?xml version="1.0" encoding="' . strtolower(get_option('blog_charset')) . '"?>'."\n".$xml; 1058 1121 header('Connection: close'); 1059 1122 header('Content-Length: '. strlen($xml));
Note: See TracChangeset
for help on using the changeset viewer.