summaryrefslogtreecommitdiffstats
path: root/wp-app.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-04-04 16:44:15 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-04-04 16:44:15 +0000
commit7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc (patch)
treec6fd23b598f3994eddb18cb1c0f2e8d95ff054fa /wp-app.php
parentf650f48c048bfbbb2ae702b6425d87e39358d748 (diff)
downloadwordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.tar.gz
wordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.tar.xz
wordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.zip
Merged with WordPress 2.5, unstable, only for testing
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1218 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-app.php')
-rw-r--r--wp-app.php148
1 files changed, 58 insertions, 90 deletions
diff --git a/wp-app.php b/wp-app.php
index e0fdaf3..52ce7b7 100644
--- a/wp-app.php
+++ b/wp-app.php
@@ -12,6 +12,7 @@ define('APP_REQUEST', true);
require_once('./wp-config.php');
require_once(ABSPATH . WPINC . '/post-template.php');
require_once(ABSPATH . WPINC . '/atomlib.php');
+require_once(ABSPATH . WPINC . '/feed.php');
$_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );
@@ -67,7 +68,6 @@ class AtomServer {
var $MEDIA_SINGLE_PATH = "attachment";
var $params = array();
- var $script_name = "wp-app.php";
var $media_content_types = array('image/*','audio/*','video/*');
var $atom_content_types = array('application/atom+xml');
@@ -79,6 +79,10 @@ class AtomServer {
function AtomServer() {
$this->script_name = array_pop(explode('/',$_SERVER['SCRIPT_NAME']));
+ $this->app_base = get_bloginfo('url') . '/' . $this->script_name . '/';
+ if ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) {
+ $this->app_base = preg_replace( '/^http:\/\//', 'https://', $this->app_base );
+ }
$this->selectors = array(
'@/service$@' =>
@@ -160,7 +164,7 @@ class AtomServer {
function get_service() {
log_app('function','get_service()');
- if( !current_user_can( 'edit_posts' ) )
+ if( !current_user_can( 'edit_posts' ) )
$this->auth_required( __( 'Sorry, you do not have the right to access this blog.' ) );
$entries_url = attribute_escape($this->get_entries_url());
@@ -170,17 +174,18 @@ class AtomServer {
$accepted_media_types = $accepted_media_types . "<accept>" . $med . "</accept>";
}
$atom_prefix="atom";
+ $atom_blogname=get_bloginfo('name');
$service_doc = <<<EOD
<service xmlns="$this->ATOMPUB_NS" xmlns:$atom_prefix="$this->ATOM_NS">
<workspace>
- <$atom_prefix:title>WordPress Workspace</$atom_prefix:title>
+ <$atom_prefix:title>$atom_blogname Workspace</$atom_prefix:title>
<collection href="$entries_url">
- <$atom_prefix:title>WordPress Posts</$atom_prefix:title>
+ <$atom_prefix:title>$atom_blogname Posts</$atom_prefix:title>
<accept>$this->ATOM_CONTENT_TYPE;type=entry</accept>
<categories href="$categories_url" />
</collection>
<collection href="$media_url">
- <$atom_prefix:title>WordPress Media</$atom_prefix:title>
+ <$atom_prefix:title>$atom_blogname Media</$atom_prefix:title>
$accepted_media_types
</collection>
</workspace>
@@ -194,7 +199,7 @@ EOD;
function get_categories_xml() {
log_app('function','get_categories_xml()');
- if( !current_user_can( 'edit_posts' ) )
+ if( !current_user_can( 'edit_posts' ) )
$this->auth_required( __( 'Sorry, you do not have the right to access this blog.' ) );
$home = attribute_escape(get_bloginfo_rss('home'));
@@ -218,7 +223,7 @@ EOD;
* Create Post (No arguments)
*/
function create_post() {
- global $blog_id, $wpdb;
+ global $blog_id, $user_ID;
$this->get_accepted_content_type($this->atom_content_types);
$parser = new AtomParser();
@@ -252,11 +257,11 @@ EOD;
$blog_ID = (int ) $blog_id;
$post_status = ($publish) ? 'publish' : 'draft';
- $post_author = (int) $user->ID;
+ $post_author = (int) $user_ID;
$post_title = $entry->title[1];
$post_content = $entry->content[1];
$post_excerpt = $entry->summary[1];
- $pubtimes = $this->get_publish_time($entry);
+ $pubtimes = $this->get_publish_time($entry->published);
$post_date = $pubtimes[0];
$post_date_gmt = $pubtimes[1];
@@ -272,9 +277,8 @@ EOD;
if ( is_wp_error( $postID ) )
$this->internal_error($postID->get_error_message());
- if (!$postID) {
+ if (!$postID)
$this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.'));
- }
// getting warning here about unable to set headers
// because something in the cache is printing to the buffer
@@ -292,7 +296,7 @@ EOD;
global $entry;
if( !current_user_can( 'edit_post', $postID ) )
- $this->auth_required( __( 'Sorry, you do not have the right to access this post.' ) );
+ $this->auth_required( __( 'Sorry, you do not have the right to access this post.' ) );
$this->set_current_entry($postID);
$output = $this->get_entry($postID);
@@ -302,8 +306,6 @@ EOD;
}
function put_post($postID) {
- global $wpdb;
-
// checked for valid content-types (atom+xml)
// quick check and exit
$this->get_accepted_content_type($this->atom_content_types);
@@ -319,7 +321,6 @@ EOD;
// check for not found
global $entry;
- $entry = $GLOBALS['entry'];
$this->set_current_entry($postID);
if(!current_user_can('edit_post', $entry['ID']))
@@ -332,9 +333,12 @@ EOD;
$post_title = $parsed->title[1];
$post_content = $parsed->content[1];
$post_excerpt = $parsed->summary[1];
- $pubtimes = $this->get_publish_time($entry);
+ $pubtimes = $this->get_publish_time($entry->published);
$post_date = $pubtimes[0];
$post_date_gmt = $pubtimes[1];
+ $pubtimes = $this->get_publish_time($parsed->updated);
+ $post_modified = $pubtimes[0];
+ $post_modified_gmt = $pubtimes[1];
// let's not go backwards and make something draft again.
if(!$publish && $post_status == 'draft') {
@@ -343,7 +347,7 @@ EOD;
$post_status = 'publish';
}
- $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt');
+ $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt');
$this->escape($postdata);
$result = wp_update_post($postdata);
@@ -383,7 +387,7 @@ EOD;
function get_attachment($postID = NULL) {
if( !current_user_can( 'upload_files' ) )
- $this->auth_required( __( 'Sorry, you do not have the right to file uploads on this blog.' ) );
+ $this->auth_required( __( 'Sorry, you do not have permission to upload files.' ) );
if (!isset($postID)) {
$this->get_attachments();
@@ -396,7 +400,6 @@ EOD;
}
function create_attachment() {
- global $wp, $wpdb, $wp_query, $blog_id;
$type = $this->get_accepted_content_type();
@@ -417,7 +420,7 @@ EOD;
$slug = sanitize_file_name( $_SERVER['HTTP_TITLE'] );
elseif ( empty( $slug ) ) // just make a random name
$slug = substr( md5( uniqid( microtime() ) ), 0, 7);
- $ext = preg_replace( '|.*/([a-z]+)|', '$1', $_SERVER['CONTENT_TYPE'] );
+ $ext = preg_replace( '|.*/([a-z0-9]+)|', '$1', $_SERVER['CONTENT_TYPE'] );
$slug = "$slug.$ext";
$file = wp_upload_bits( $slug, NULL, $bits);
@@ -425,9 +428,8 @@ EOD;
$url = $file['url'];
$file = $file['file'];
- $filename = basename($file);
- $header = apply_filters('wp_create_file_in_uploads', $file); // replicate
+ do_action('wp_create_file_in_uploads', $file); // replicate
// Construct the attachment array
$attachment = array(
@@ -440,11 +442,10 @@ EOD;
);
// Save the data
- $postID = wp_insert_attachment($attachment, $file, $post);
+ $postID = wp_insert_attachment($attachment, $file);
- if (!$postID) {
+ if (!$postID)
$this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.'));
- }
$output = $this->get_entry($postID, 'attachment');
@@ -453,8 +454,6 @@ EOD;
}
function put_attachment($postID) {
- global $wpdb;
-
// checked for valid content-types (atom+xml)
// quick check and exit
$this->get_accepted_content_type($this->atom_content_types);
@@ -473,14 +472,15 @@ EOD;
if(!current_user_can('edit_post', $entry['ID']))
$this->auth_required(__('Sorry, you do not have the right to edit this post.'));
- $publish = (isset($parsed->draft) && trim($parsed->draft) == 'yes') ? false : true;
-
extract($entry);
$post_title = $parsed->title[1];
$post_content = $parsed->content[1];
+ $pubtimes = $this->get_publish_time($parsed->updated);
+ $post_modified = $pubtimes[0];
+ $post_modified_gmt = $pubtimes[1];
- $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt');
+ $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_modified', 'post_modified_gmt');
$this->escape($postdata);
$result = wp_update_post($postdata);
@@ -557,8 +557,6 @@ EOD;
function put_file($postID) {
- $type = $this->get_accepted_content_type();
-
// first check if user can upload
if(!current_user_can('upload_files'))
$this->auth_required(__('You do not have permission to upload files.'));
@@ -587,11 +585,14 @@ EOD;
fclose($localfp);
$ID = $entry['ID'];
- $pubtimes = $this->get_publish_time($entry);
+ $pubtimes = $this->get_publish_time($entry->published);
$post_date = $pubtimes[0];
$post_date_gmt = $pubtimes[1];
+ $pubtimes = $this->get_publish_time($parsed->updated);
+ $post_modified = $pubtimes[0];
+ $post_modified_gmt = $pubtimes[1];
- $post_data = compact('ID', 'post_date', 'post_date_gmt');
+ $post_data = compact('ID', 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt');
$result = wp_update_post($post_data);
if (!$result) {
@@ -608,7 +609,7 @@ EOD;
} else {
$path = $this->ENTRIES_PATH;
}
- $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $path;
+ $url = $this->app_base . $path;
if(isset($page) && is_int($page)) {
$url .= "/$page";
}
@@ -616,21 +617,19 @@ EOD;
}
function the_entries_url($page = NULL) {
- $url = $this->get_entries_url($page);
- echo $url;
+ echo $this->get_entries_url($page);
}
- function get_categories_url($page = NULL) {
- return get_bloginfo('url') . '/' . $this->script_name . '/' . $this->CATEGORIES_PATH;
+ function get_categories_url($deprecated = '') {
+ return $this->app_base . $this->CATEGORIES_PATH;
}
function the_categories_url() {
- $url = $this->get_categories_url();
- echo $url;
+ echo $this->get_categories_url();
}
function get_attachments_url($page = NULL) {
- $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_PATH;
+ $url = $this->app_base . $this->MEDIA_PATH;
if(isset($page) && is_int($page)) {
$url .= "/$page";
}
@@ -638,46 +637,43 @@ EOD;
}
function the_attachments_url($page = NULL) {
- $url = $this->get_attachments_url($page);
- echo $url;
+ echo $this->get_attachments_url($page);
}
function get_service_url() {
- return get_bloginfo('url') . '/' . $this->script_name . '/' . $this->SERVICE_PATH;
+ return $this->app_base . $this->SERVICE_PATH;
}
function get_entry_url($postID = NULL) {
if(!isset($postID)) {
global $post;
- $postID = (int) $GLOBALS['post']->ID;
+ $postID = (int) $post->ID;
}
- $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID";
+ $url = $this->app_base . $this->ENTRY_PATH . "/$postID";
log_app('function',"get_entry_url() = $url");
return $url;
}
function the_entry_url($postID = NULL) {
- $url = $this->get_entry_url($postID);
- echo $url;
+ echo $this->get_entry_url($postID);
}
function get_media_url($postID = NULL) {
if(!isset($postID)) {
global $post;
- $postID = (int) $GLOBALS['post']->ID;
+ $postID = (int) $post->ID;
}
- $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/file/$postID";
+ $url = $this->app_base . $this->MEDIA_SINGLE_PATH ."/file/$postID";
log_app('function',"get_media_url() = $url");
return $url;
}
function the_media_url($postID = NULL) {
- $url = $this->get_media_url($postID);
- echo $url;
+ echo $this->get_media_url($postID);
}
function set_current_entry($postID) {
@@ -711,7 +707,7 @@ EOD;
}
function get_feed($page = 1, $post_type = 'post') {
- global $post, $wp, $wp_query, $posts, $wpdb, $blog_id, $post_cache;
+ global $post, $wp, $wp_query, $posts, $wpdb, $blog_id;
log_app('function',"get_feed($page, '$post_type')");
ob_start();
@@ -722,7 +718,7 @@ EOD;
$count = get_option('posts_per_rss');
- wp('what_to_show=posts&posts_per_page=' . $count . '&offset=' . ($count * ($page-1) ));
+ wp('what_to_show=posts&posts_per_page=' . $count . '&offset=' . ($count * ($page-1) . '&orderby=modified'));
$post = $GLOBALS['post'];
$posts = $GLOBALS['posts'];
@@ -730,7 +726,6 @@ EOD;
$wp_query = $GLOBALS['wp_query'];
$wpdb = $GLOBALS['wpdb'];
$blog_id = (int) $GLOBALS['blog_id'];
- $post_cache = $GLOBALS['post_cache'];
log_app('function',"query_posts(# " . print_r($wp_query, true) . "#)");
log_app('function',"total_count(# $wp_query->max_num_pages #)");
@@ -754,7 +749,7 @@ EOD;
<link rel="last" type="<?php echo $this->ATOM_CONTENT_TYPE ?>" href="<?php $this->the_entries_url($last_page) ?>" />
<link rel="self" type="<?php echo $this->ATOM_CONTENT_TYPE ?>" href="<?php $this->the_entries_url($self_page) ?>" />
<rights type="text">Copyright <?php echo mysql2date('Y', get_lastpostdate('blog')); ?></rights>
-<generator uri="http://wordpress.com/" version="1.0.5-dc">WordPress.com Atom API</generator>
+<?php the_generator( 'atom' ); ?>
<?php if ( have_posts() ) {
while ( have_posts() ) {
the_post();
@@ -771,7 +766,6 @@ EOD;
function get_entry($postID, $post_type = 'post') {
log_app('function',"get_entry($postID, '$post_type')");
ob_start();
- global $posts, $post, $wp_query, $wp, $wpdb, $blog_id, $post_cache;
switch($post_type) {
case 'post':
$varname = 'p';
@@ -800,7 +794,7 @@ EOD;
<entry xmlns="<?php echo $this->ATOM_NS ?>"
xmlns:app="<?php echo $this->ATOMPUB_NS ?>" xml:lang="<?php echo get_option('rss_language'); ?>">
<id><?php the_guid($GLOBALS['post']->ID); ?></id>
-<?php list($content_type, $content) = $this->prep_content(get_the_title()); ?>
+<?php list($content_type, $content) = prep_atom_text_construct(get_the_title()); ?>
<title type="<?php echo $content_type ?>"><?php echo $content ?></title>
<updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated>
<published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published>
@@ -820,7 +814,7 @@ EOD;
<?php } else { ?>
<link href="<?php the_permalink_rss() ?>" />
<?php if ( strlen( $GLOBALS['post']->post_content ) ) :
-list($content_type, $content) = $this->prep_content(get_the_content()); ?>
+list($content_type, $content) = prep_atom_text_construct(get_the_content()); ?>
<content type="<?php echo $content_type ?>"><?php echo $content ?></content>
<?php endif; ?>
<?php } ?>
@@ -828,37 +822,11 @@ list($content_type, $content) = $this->prep_content(get_the_content()); ?>
<?php foreach(get_the_category() as $category) { ?>
<category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->name?>" />
<?php } ?>
-<?php list($content_type, $content) = $this->prep_content(get_the_excerpt()); ?>
+<?php list($content_type, $content) = prep_atom_text_construct(get_the_excerpt()); ?>
<summary type="<?php echo $content_type ?>"><?php echo $content ?></summary>
</entry>
<?php }
- function prep_content($data) {
- if (strpos($data, '<') === false && strpos($data, '&') === false) {
- return array('text', $data);
- }
-
- $parser = xml_parser_create();
- xml_parse($parser, '<div>' . $data . '</div>', true);
- $code = xml_get_error_code($parser);
- xml_parser_free($parser);
-
- if (!$code) {
- if (strpos($data, '<') === false) {
- return array('text', $data);
- } else {
- $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
- return array('xhtml', $data);
- }
- }
-
- if (strpos($data, ']]>') == false) {
- return array('html', "<![CDATA[$data]]>");
- } else {
- return array('html', htmlspecialchars($data));
- }
- }
-
function ok() {
log_app('Status','200: OK');
header('Content-Type: text/plain');
@@ -959,7 +927,7 @@ EOD;
$ctloc = $this->get_entry_url($post_ID);
break;
case 'attachment':
- $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID";
+ $edit = $this->app_base . "attachments/$post_ID";
break;
}
header("Content-Type: $this->ATOM_CONTENT_TYPE");
@@ -1140,9 +1108,9 @@ EOD;
return strtotime($match[1] . " " . $match[2] . " " . $match[3]);
}
- function get_publish_time($entry) {
+ function get_publish_time($published) {
- $pubtime = $this->rfc3339_str2time($entry->published);
+ $pubtime = $this->rfc3339_str2time($published);
if(!$pubtime) {
return array(current_time('mysql'),current_time('mysql',1));