diff --git a/app.php b/app.php index 03d756eb0..286e9ff07 100644 --- a/app.php +++ b/app.php @@ -4,18 +4,21 @@ * Original code by: Elias Torres, http://torrez.us/archives/2006/08/31/491/ * Modified by: Dougal Campbell, http://dougal.gunters.org/ * - * Version: 1.0.0-dc + * Version: 1.0.5-dc */ - + define('APP_REQUEST', true); require_once('wp-config.php'); +require_once('wp-includes/post-template.php'); -$use_querystring = 1; +// Attempt to automatically detect whether to use querystring +// or PATH_INFO, based on our environment: +$use_querystring = $wp_version == 'MU' ? 1 : 0; // If using querystring, we need to put the path together manually: if ($use_querystring) { - $_GLOBALS['use_querystring'] = $use_querystring; + $GLOBALS['use_querystring'] = $use_querystring; $action = $_GET['action']; $eid = (int) $_GET['eid']; @@ -28,7 +31,7 @@ if ($use_querystring) { $_SERVER['PATH_INFO'] = str_replace( '/app.php', '', $_SERVER['REQUEST_URI'] ); } -$app_logging = 1; +$app_logging = 0; function log_app($label,$msg) { global $app_logging; @@ -257,10 +260,11 @@ class AtomParser { class AtomServer { var $ATOM_CONTENT_TYPE = 'application/atom+xml'; - + var $CATEGORIES_CONTENT_TYPE = 'application/atomcat+xml'; var $INTROSPECTION_CONTENT_TYPE = 'application/atomserv+xml'; var $ENTRIES_PATH = "posts"; + var $CATEGORIES_PATH = "categories"; var $MEDIA_PATH = "attachments"; var $ENTRY_PATH = "post"; var $MEDIA_SINGLE_PATH = "attachment"; @@ -282,6 +286,8 @@ class AtomServer { $this->selectors = array( '@/service@' => array('GET' => 'get_service'), + '@/categories@' => + array('GET' => 'get_categories_xml'), '@/post/(\d+)@' => array('GET' => 'get_post', 'PUT' => 'put_post', @@ -348,31 +354,53 @@ class AtomServer { function get_service() { log_app('function','get_service()'); $entries_url = $this->get_entries_url(); + $categories_url = $this->get_categories_url(); $media_url = $this->get_attachments_url(); $accepted_content_types = join(',',$this->media_content_types); $introspection = << - - - entry - WordPress Posts - - - $accepted_content_types - WordPress Media - - + + + + WordPress Posts + entry + + + + WordPress Media + $accepted_content_types + + EOD; + $this->output($introspection, $this->INTROSPECTION_CONTENT_TYPE); } +function get_categories_xml() { + log_app('function','get_categories_xml()'); + $home = get_bloginfo_rss('home'); + + $categories = ""; + $cats = get_categories("hierarchical=0&hide_empty=0"); + foreach ((array) $cats as $cat) { + $categories .= " cat_name) . "\" />\n"; + } + $output = << + $categories + +EOD; + $this->output($output, $this->CATEGORIES_CONTENT_TYPE); +} + /* * Create Post (No arguments) */ function create_post() { - + global $current_blog; $this->get_accepted_content_type($this->atom_content_types); $parser = new AtomParser(); @@ -389,7 +417,7 @@ EOD; if(!current_user_can($cap)) $this->auth_required('Sorry, you do not have the right to edit/publish new posts.'); - $blog_ID = 1; + $blog_ID = $current_blog->blog_id; $post_status = ($publish) ? 'publish' : 'draft'; $post_author = $user->ID; $post_title = $entry->title; @@ -400,6 +428,8 @@ EOD; $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt'); + log_app('Inserting Post. Data:', print_r($post_data,true)); + $postID = wp_insert_post($post_data); if (!$postID) { @@ -437,8 +467,9 @@ EOD; // check for not found global $entry; + $entry = $GLOBALS['entry']; $this->set_current_entry($postID); - $this->escape($entry); + $this->escape($GLOBALS['entry']); if(!current_user_can('edit_post', $entry['ID'])) $this->auth_required('Sorry, you do not have the right to edit this post.'); @@ -507,6 +538,7 @@ EOD; } function create_attachment() { + global $wp, $wpdb, $wp_query, $blog_id; $type = $this->get_accepted_content_type(); @@ -531,6 +563,8 @@ EOD; $slug = "$slug.$ext"; $file = wp_upload_bits( $slug, NULL, $bits); + log_app('wp_upload_bits returns:',print_r($file,true)); + $url = $file['url']; $file = $file['file']; $filename = basename($file); @@ -695,7 +729,7 @@ EOD; if ($use_querystring) { $url .= '?action=/' . $this->ENTRIES_PATH; if(isset($page) && is_int($page)) { - $url .= "&eid=$page"; + $url .= "&eid=$page"; } } else { $url .= '/' . $this->ENTRIES_PATH; @@ -711,13 +745,29 @@ EOD; echo $url; } + function get_categories_url($page = NULL) { + global $use_querystring; + $url = get_bloginfo('url') . '/' . $this->script_name; + if ($use_querystring) { + $url .= '?action=/' . $this->CATEGORIES_PATH; + } else { + $url .= '/' . $this->CATEGORIES_PATH; + } + return $url; + } + + function the_categories_url() { + $url = $this->get_categories_url(); + echo $url; + } + function get_attachments_url($page = NULL) { global $use_querystring; $url = get_bloginfo('url') . '/' . $this->script_name; if ($use_querystring) { $url .= '?action=/' . $this->MEDIA_PATH; if(isset($page) && is_int($page)) { - $url .= "&eid=$page"; + $url .= "&eid=$page"; } } else { $url .= '/' . $this->MEDIA_PATH; @@ -738,11 +788,11 @@ EOD; global $use_querystring; if(!isset($postID)) { global $post; - $postID = $post->ID; + $postID = $GLOBALS['post']->ID; } if ($use_querystring) { - $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->ENTRY_PATH . "&eid=$postID"; + $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->ENTRY_PATH . "&eid=$postID"; } else { $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; } @@ -760,11 +810,11 @@ EOD; global $use_querystring; if(!isset($postID)) { global $post; - $postID = $post->ID; + $postID = $GLOBALS['post']->ID; } if ($use_querystring) { - $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->MEDIA_SINGLE_PATH ."&eid=$postID"; + $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->MEDIA_SINGLE_PATH ."&eid=$postID"; } else { $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/$postID"; } @@ -815,6 +865,7 @@ EOD; } function get_feed($page = 1, $post_type = 'post') { + global $post, $wp, $wp_query, $posts, $wpdb, $blog_id, $post_cache; log_app('function',"get_feed($page, '$post_type')"); ob_start(); @@ -829,7 +880,14 @@ EOD; $query .= "&post_type=$post_type"; } query_posts($query); - global $post; + $post = $GLOBALS['post']; + $posts = $GLOBALS['posts']; + $wp = $GLOBALS['wp']; + $wp_query = $GLOBALS['wp_query']; + $wpdb = $GLOBALS['wpdb']; + $blog_id = $GLOBALS['blog_id']; + $post_cache = $GLOBALS['post_cache']; + $total_count = $this->get_posts_count(); $last_page = (int) ceil($total_count / $count); @@ -851,15 +909,17 @@ EOD; Copyright -WordPress.com Atom API - +WordPress.com Atom API + - + ID); ?> <![CDATA[<?php the_title() ?>]]> - post_status == 'draft' ? 'yes' : 'no') ?> + post_status == 'draft' ? 'yes' : 'no') ?> @@ -868,7 +928,7 @@ EOD; - post_status == 'attachment') { ?> + post_status == 'attachment') { ?> @@ -878,8 +938,8 @@ EOD; ]]> - post_content ) ) : ?> - + post_content ) ) : ?> + ]]> + if ( have_posts() ) : while ( have_posts() ) : the_post(); + $post = $GLOBALS['post']; + ?> + - + ID); ?> <![CDATA[<?php the_title_rss() ?>]]> - post_status == 'draft' ? 'yes' : 'no') ?> + post_status == 'draft' ? 'yes' : 'no') ?> -post_type == 'attachment') { ?> +post_type == 'attachment') { ?> - + @@ -932,8 +995,8 @@ EOD; ]]> post_content ) ) : ?> - + if ( strlen( $GLOBALS['post']->post_content ) ) : ?> + ]]> script_name . "?action=/attachments&eid=$post_ID"; + $edit = get_bloginfo('url') . '/' . $this->script_name . "?action=/attachments&eid=$post_ID"; } else { $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; } @@ -1054,7 +1117,7 @@ EOD; function output($xml, $ctype = "application/atom+xml") { status_header('200'); - $xml = ''."\n".$xml; + $xml = ''."\n".$xml; header('Connection: close'); header('Content-Length: '. strlen($xml)); header('Content-Type: ' . $ctype); @@ -1194,4 +1257,4 @@ EOD; $server = new AtomServer(); $server->handle_request(); -?> \ No newline at end of file +?>