Changeset 4916

Show
Ignore:
Timestamp:
02/22/07 19:44:16 (1 year ago)
Author:
ryan
Message:

APP updates from dougal and eliast. fixes #3741

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app.php

    r4880 r4916  
    55 * Modified by: Dougal Campbell, http://dougal.gunters.org/ 
    66 * 
    7  * Version: 1.0.0-dc 
     7 * Version: 1.0.5-dc 
    88 */ 
    9      
     9 
    1010define('APP_REQUEST', true); 
    1111 
    1212require_once('wp-config.php'); 
    13  
    14 $use_querystring = 1; 
     13require_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; 
    1518 
    1619// If using querystring, we need to put the path together manually: 
    1720if ($use_querystring) { 
    18     $_GLOBALS['use_querystring'] = $use_querystring; 
     21    $GLOBALS['use_querystring'] = $use_querystring; 
    1922    $action = $_GET['action']; 
    2023    $eid = (int) $_GET['eid']; 
     
    2932} 
    3033 
    31 $app_logging = 1
     34$app_logging = 0
    3235 
    3336function log_app($label,$msg) { 
     
    258261 
    259262    var $ATOM_CONTENT_TYPE = 'application/atom+xml'; 
    260  
     263    var $CATEGORIES_CONTENT_TYPE = 'application/atomcat+xml'; 
    261264    var $INTROSPECTION_CONTENT_TYPE = 'application/atomserv+xml'; 
    262265 
    263266    var $ENTRIES_PATH = "posts"; 
     267    var $CATEGORIES_PATH = "categories"; 
    264268    var $MEDIA_PATH = "attachments"; 
    265269    var $ENTRY_PATH = "post"; 
     
    283287            '@/service@' =>  
    284288                array('GET' => 'get_service'), 
     289            '@/categories@' => 
     290                array('GET' => 'get_categories_xml'), 
    285291            '@/post/(\d+)@' =>  
    286292                array('GET' => 'get_post',  
     
    349355        log_app('function','get_service()'); 
    350356        $entries_url = $this->get_entries_url(); 
     357        $categories_url = $this->get_categories_url();  
    351358        $media_url = $this->get_attachments_url(); 
    352359        $accepted_content_types = join(',',$this->media_content_types); 
    353360        $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>  
    365373</service> 
    366374 
    367375EOD; 
     376 
    368377        $this->output($introspection, $this->INTROSPECTION_CONTENT_TYPE);  
    369378    } 
     379 
     380function 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> 
     395EOD; 
     396    $this->output($output, $this->CATEGORIES_CONTENT_TYPE);  
     397} 
    370398 
    371399    /* 
     
    373401     */ 
    374402    function create_post() { 
    375  
     403        global $current_blog; 
    376404        $this->get_accepted_content_type($this->atom_content_types); 
    377405 
     
    390418            $this->auth_required('Sorry, you do not have the right to edit/publish new posts.'); 
    391419 
    392         $blog_ID = 1
     420        $blog_ID = $current_blog->blog_id
    393421        $post_status = ($publish) ? 'publish' : 'draft'; 
    394422        $post_author = $user->ID; 
     
    401429        $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt'); 
    402430 
     431        log_app('Inserting Post. Data:', print_r($post_data,true)); 
     432 
    403433        $postID = wp_insert_post($post_data); 
    404434 
     
    438468        // check for not found 
    439469        global $entry; 
     470        $entry = $GLOBALS['entry']; 
    440471        $this->set_current_entry($postID); 
    441         $this->escape($entry); 
     472        $this->escape($GLOBALS['entry']); 
    442473 
    443474        if(!current_user_can('edit_post', $entry['ID'])) 
     
    508539 
    509540    function create_attachment() { 
     541        global $wp, $wpdb, $wp_query, $blog_id; 
    510542 
    511543        $type = $this->get_accepted_content_type(); 
     
    532564        $file = wp_upload_bits( $slug, NULL, $bits); 
    533565 
     566        log_app('wp_upload_bits returns:',print_r($file,true)); 
     567         
    534568        $url = $file['url']; 
    535569        $file = $file['file']; 
     
    696730            $url .= '?action=/' . $this->ENTRIES_PATH; 
    697731            if(isset($page) && is_int($page)) { 
    698                 $url .= "&eid=$page"; 
     732                $url .= "&amp;eid=$page"; 
    699733            } 
    700734        } else { 
     
    712746    } 
    713747 
     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     
    714764    function get_attachments_url($page = NULL) { 
    715765        global $use_querystring; 
     
    718768            $url .= '?action=/' . $this->MEDIA_PATH; 
    719769            if(isset($page) && is_int($page)) { 
    720                 $url .= "&eid=$page"; 
     770                $url .= "&amp;eid=$page"; 
    721771            } 
    722772        } else { 
     
    739789        if(!isset($postID)) { 
    740790            global $post; 
    741             $postID = $post->ID; 
     791            $postID = $GLOBALS['post']->ID; 
    742792        } 
    743793         
    744794        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 . "&amp;eid=$postID"; 
    746796        } else { 
    747797            $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; 
     
    761811        if(!isset($postID)) { 
    762812            global $post; 
    763             $postID = $post->ID; 
     813            $postID = $GLOBALS['post']->ID; 
    764814        } 
    765815         
    766816        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 ."&amp;eid=$postID"; 
    768818        } else { 
    769819            $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/$postID"; 
     
    816866 
    817867    function get_feed($page = 1, $post_type = 'post') { 
     868        global $post, $wp, $wp_query, $posts, $wpdb, $blog_id, $post_cache; 
    818869        log_app('function',"get_feed($page, '$post_type')"); 
    819870        ob_start(); 
     
    830881        } 
    831882        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         
    833891 
    834892        $total_count = $this->get_posts_count(); 
     
    852910<link rel="self" type="application/atom+xml" href="<?php $this->the_entries_url() ?>" /> 
    853911<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?> 
    856916<entry> 
    857         <id><?php the_guid(); ?></id> 
     917        <id><?php the_guid($post->ID); ?></id> 
    858918        <title type="html"><![CDATA[<?php the_title() ?>]]></title> 
    859919        <updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated> 
    860920        <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> 
    861921        <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> 
    863923        </app:control> 
    864924        <author> 
     
    869929    <?php } ?> 
    870930        </author> 
    871     <?php if($post->post_status == 'attachment') { ?> 
     931    <?php if($GLOBALS['post']->post_status == 'attachment') { ?> 
    872932        <link rel="edit" href="<?php $this->the_entry_url() ?>" /> 
    873933        <link rel="edit-media" href="<?php $this->the_media_url() ?>" /> 
     
    879939     <category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->cat_name?>" /> 
    880940    <?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> 
    883943<?php endif; ?> 
    884944    </entry> 
     
    896956        log_app('function',"get_entry($postID, '$post_type')"); 
    897957        ob_start(); 
    898         global $posts, $post, $wp_query
     958        global $posts, $post, $wp_query, $wp, $wpdb, $blog_id, $post_cache
    899959        switch($post_type) { 
    900960            case 'post': 
     
    906966        } 
    907967        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)); ?> 
    909972<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> 
    911974    <title type="html"><![CDATA[<?php the_title_rss() ?>]]></title> 
    912975 
     
    914977    <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> 
    915978    <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> 
    917980    </app:control> 
    918981    <author> 
     
    921984        <uri><?php the_author_url()?></uri> 
    922985    </author> 
    923 <?php if($post->post_type == 'attachment') { ?> 
     986<?php if($GLOBALS['post']->post_type == 'attachment') { ?> 
    924987    <link rel="edit" href="<?php $this->the_entry_url() ?>" /> 
    925988    <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(); ?>"/> 
    927990<?php } else { ?> 
    928991    <link href="<?php permalink_single_rss() ?>" /> 
     
    933996    <summary type="html"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> 
    934997<?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> 
    9371000<?php endif; ?> 
    9381001</entry> 
     
    10261089            case 'attachment': 
    10271090                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&amp;eid=$post_ID"; 
    10291092                } else { 
    10301093                    $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; 
     
    10551118    function output($xml, $ctype = "application/atom+xml") { 
    10561119            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; 
    10581121            header('Connection: close'); 
    10591122            header('Content-Length: '. strlen($xml));