From 9fb2ddc65ff64b8177088aa7a17e93319245004a Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sat, 1 Sep 2007 19:32:54 +0000 Subject: [PATCH] AtomPub fixes from Pete Lacey. fixes #4887 git-svn-id: https://develop.svn.wordpress.org/trunk@6004 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-app.php | 240 +++++++++++++++++++---------------------------------- 1 file changed, 85 insertions(+), 155 deletions(-) diff --git a/wp-app.php b/wp-app.php index 74789443bb..911d5aa3fe 100644 --- a/wp-app.php +++ b/wp-app.php @@ -13,24 +13,7 @@ require_once('./wp-config.php'); require_once(ABSPATH . WPINC . '/post-template.php'); require_once(ABSPATH . WPINC . '/atomlib.php'); -// 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; - $action = $_GET['action']; - $eid = (int) $_GET['eid']; - - $_SERVER['PATH_INFO'] = $action; - - if ($eid) { - $_SERVER['PATH_INFO'] .= "/$eid"; - } -} else { - $_SERVER['PATH_INFO'] = str_replace( '.*/wp-app.php', '', $_SERVER['REQUEST_URI'] ); -} +$_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] ); $app_logging = 0; @@ -142,7 +125,7 @@ class AtomServer { // redirect to /service in case no path is found. if(strlen($path) == 0 || $path == '/') { - $this->redirect($this->get_service_url()); + $this->redirect($this->get_service_url()); } // dispatch @@ -150,22 +133,22 @@ class AtomServer { if(preg_match($regex, $path, $matches)) { if(isset($funcs[$method])) { - // authenticate regardless of the operation and set the current - // user. each handler will decide if auth is required or not. - $this->authenticate(); - $u = wp_get_current_user(); - if(!isset($u) || $u->ID == 0) { - if ($always_authenticate) { - $this->auth_required('Credentials required.'); - } - } + // authenticate regardless of the operation and set the current + // user. each handler will decide if auth is required or not. + $this->authenticate(); + $u = wp_get_current_user(); + if(!isset($u) || $u->ID == 0) { + if ($always_authenticate) { + $this->auth_required('Credentials required.'); + } + } - array_shift($matches); - call_user_func_array(array(&$this,$funcs[$method]), $matches); - exit(); + array_shift($matches); + call_user_func_array(array(&$this,$funcs[$method]), $matches); + exit(); } else { - // only allow what we have handlers for... - $this->not_allowed(array_keys($funcs)); + // only allow what we have handlers for... + $this->not_allowed(array_keys($funcs)); } } } @@ -245,7 +228,6 @@ EOD; array_push($catnames, $cat["term"]); $wp_cats = get_categories(array('hide_empty' => false)); - log_app('CATEGORIES :', print_r($wp_cats,true)); $post_category = array(); @@ -352,8 +334,6 @@ EOD; $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt'); $this->escape($postdata); - log_app('UPDATING ENTRY WITH:', print_r($postdata,true)); - $result = wp_update_post($postdata); if (!$result) { @@ -606,23 +586,14 @@ EOD; } function get_entries_url($page = NULL) { - global $use_querystring; if($GLOBALS['post_type'] == 'attachment') { $path = $this->MEDIA_PATH; } else { $path = $this->ENTRIES_PATH; } - $url = get_bloginfo('url') . '/' . $this->script_name; - if ($use_querystring) { - $url .= '?action=/' . $path; - if(isset($page) && is_int($page)) { - $url .= "&eid=$page"; - } - } else { - $url .= '/' . $path; - if(isset($page) && is_int($page)) { - $url .= "/$page"; - } + $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $path; + if(isset($page) && is_int($page)) { + $url .= "/$page"; } return $url; } @@ -633,14 +604,7 @@ EOD; } 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; + return get_bloginfo('url') . '/' . $this->script_name . '/' . $this->CATEGORIES_PATH; } function the_categories_url() { @@ -649,18 +613,9 @@ EOD; } 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"; - } - } else { - $url .= '/' . $this->MEDIA_PATH; - if(isset($page) && is_int($page)) { - $url .= "/$page"; - } + $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_PATH; + if(isset($page) && is_int($page)) { + $url .= "/$page"; } return $url; } @@ -671,28 +626,16 @@ EOD; } function get_service_url() { - global $use_querystring; - $url = get_bloginfo('url') . '/' . $this->script_name; - if ($use_querystring) { - $url .= '?action=/' . $this->SERVICE_PATH; - } else { - $url .= '/' . $this->SERVICE_PATH; - } - return $url; + return get_bloginfo('url') . '/' . $this->script_name . '/' . $this->SERVICE_PATH; } function get_entry_url($postID = NULL) { - global $use_querystring; if(!isset($postID)) { global $post; $postID = (int) $GLOBALS['post']->ID; } - if ($use_querystring) { - $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"; - } + $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; log_app('function',"get_entry_url() = $url"); return $url; @@ -704,17 +647,12 @@ EOD; } function get_media_url($postID = NULL) { - global $use_querystring; if(!isset($postID)) { global $post; $postID = (int) $GLOBALS['post']->ID; } - if ($use_querystring) { - $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->MEDIA_SINGLE_PATH ."/file&eid=$postID"; - } else { - $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/file/$postID"; - } + $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/file/$postID"; log_app('function',"get_media_url() = $url"); return $url; @@ -767,7 +705,7 @@ EOD; $count = get_option('posts_per_rss'); - wp('what_to_show=posts&posts_per_page=' . $count . '&offset=' . ($page-1)); + wp('what_to_show=posts&posts_per_page=' . $count . '&offset=' . ($count * ($page-1) )); $post = $GLOBALS['post']; $posts = $GLOBALS['posts']; @@ -783,6 +721,7 @@ EOD; $next_page = (($page + 1) > $last_page) ? NULL : $page + 1; $prev_page = ($page - 1) < 1 ? NULL : $page - 1; $last_page = ((int)$last_page == 1 || (int)$last_page == 0) ? NULL : (int) $last_page; + $self_page = $page > 1 ? $page : NULL; ?> the_entries_url() ?> @@ -796,46 +735,15 @@ EOD; - + Copyright WordPress.com Atom API - - - ID); ?> - <![CDATA[<?php the_title_rss() ?>]]> - - - - - post_status == 'draft' ? 'yes' : 'no') ?> - - - - - - - - - post_type == 'attachment') { ?> - - - - - post_content ) ) : ?> - ]]> - - - - - - - ]]> - -echo_entry(); + } + } ?> - + if ( have_posts() ) { + while ( have_posts() ) { + the_post(); + $this->echo_entry(); + log_app('$post',print_r($GLOBALS['post'],true)); + $entry = ob_get_contents(); + break; + } + } + ob_end_clean(); + + log_app('get_entry returning:',$entry); + return $entry; + } + + function echo_entry() { ?> - ID); ?> - <![CDATA[<?php the_title_rss() ?>]]> - + ID); ?> +prep_content(get_the_title()); ?> + <?php echo $content ?> @@ -874,34 +794,49 @@ $post = $GLOBALS['post']; - + - + post_type == 'attachment') { ?> - post_content ) ) : ?> - ]]> - +post_content ) ) : +list($content_type, $content) = $this->prep_content(get_the_content()); ?> + + - ]]> - -prep_content(get_the_excerpt()); ?> + + +' . $data . '', true); + $code = xml_get_error_code($parser); + xml_parser_free($parser); + + if (!$code) { + $data = "
$data
"; + return array('xhtml', $data); + } + + if (strpos($data, ']]>') == false) { + return array('html', ""); + } else { + return array('html', htmlspecialchars($data)); + } } function ok() { @@ -997,7 +932,6 @@ EOD; } function created($post_ID, $content, $post_type = 'post') { - global $use_querystring; log_app('created()::$post_ID',"$post_ID, $post_type"); $edit = $this->get_entry_url($post_ID); switch($post_type) { @@ -1005,11 +939,7 @@ EOD; $ctloc = $this->get_entry_url($post_ID); break; case 'attachment': - if ($use_querystring) { - $edit = get_bloginfo('url') . '/' . $this->script_name . "?action=/attachments&eid=$post_ID"; - } else { - $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; - } + $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; break; } header("Content-Type: $this->ATOM_CONTENT_TYPE");