/** Set up WordPress environment */
require_once('./wp-load.php');
-/** Post Template API */
-require_once(ABSPATH . WPINC . '/post-template.php');
-
/** Atom Publishing Protocol Class */
require_once(ABSPATH . WPINC . '/atomlib.php');
-/** Feed Handling API */
-require_once(ABSPATH . WPINC . '/feed.php');
+/** Admin Image API for metadata updating */
+require_once(ABSPATH . '/wp-admin/includes/image.php');
$_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );
}
}
-if ( !function_exists('wp_set_current_user') ) :
-/**
- * @ignore
- */
-function wp_set_current_user($id, $name = '') {
- global $current_user;
-
- if ( isset($current_user) && ($id == $current_user->ID) )
- return $current_user;
-
- $current_user = new WP_User($id, $name);
-
- return $current_user;
-}
-endif;
-
/**
* Filter to add more post statuses.
*
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());
- $categories_url = attribute_escape($this->get_categories_url());
- $media_url = attribute_escape($this->get_attachments_url());
+ $entries_url = esc_attr($this->get_entries_url());
+ $categories_url = esc_attr($this->get_categories_url());
+ $media_url = esc_attr($this->get_attachments_url());
+ $accepted_media_types = '';
foreach ($this->media_content_types as $med) {
$accepted_media_types = $accepted_media_types . "<accept>" . $med . "</accept>";
}
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'));
+ $home = esc_attr(get_bloginfo_rss('home'));
$categories = "";
$cats = get_categories("hierarchical=0&hide_empty=0");
foreach ((array) $cats as $cat) {
- $categories .= " <category term=\"" . attribute_escape($cat->name) . "\" />\n";
+ $categories .= " <category term=\"" . esc_attr($cat->name) . "\" />\n";
}
$output = <<<EOD
<app:categories xmlns:app="$this->ATOMPUB_NS"
// this could affect our ability to send back the right headers
@wp_set_post_categories($postID, $post_category);
+ do_action( 'atompub_create_post', $postID, $entry );
+
$output = $this->get_entry($postID);
log_app('function',"create_post($postID)");
$this->internal_error(__('For some strange yet very annoying reason, this post could not be edited.'));
}
+ do_action( 'atompub_put_post', $ID, $parsed );
+
log_app('function',"put_post($postID)");
$this->ok();
}
extract($entry);
$post_title = $parsed->title[1];
- $post_content = $parsed->content[1];
+ $post_content = $parsed->summary[1];
$pubtimes = $this->get_publish_time($parsed->updated);
$post_modified = $pubtimes[0];
$post_modified_gmt = $pubtimes[1];
}
$location = get_post_meta($entry['ID'], '_wp_attached_file', true);
+ $location = get_option ('upload_path') . '/' . $location;
$filetype = wp_check_filetype($location);
if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']))
header('Content-Type: ' . $entry['post_mime_type']);
header('Connection: close');
- $fp = fopen($location, "rb");
- while(!feof($fp)) {
- echo fread($fp, 4096);
+ if ($fp = fopen($location, "rb")) {
+ status_header('200');
+ header('Content-Type: ' . $entry['post_mime_type']);
+ header('Connection: close');
+
+ while(!feof($fp)) {
+ echo fread($fp, 4096);
+ }
+
+ fclose($fp);
+ } else {
+ status_header ('404');
}
- fclose($fp);
log_app('function',"get_file($postID)");
exit;
$this->auth_required(__('Sorry, you do not have the right to edit this post.'));
}
+ $upload_dir = wp_upload_dir( );
$location = get_post_meta($entry['ID'], '_wp_attached_file', true);
$filetype = wp_check_filetype($location);
+ $location = "{$upload_dir['basedir']}/{$location}";
+
if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']))
$this->internal_error(__('Error ocurred while accessing post metadata for file location.'));
$this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.'));
}
+ wp_update_attachment_metadata( $postID, wp_generate_attachment_metadata( $postID, $location ) );
+
log_app('function',"put_file($postID)");
$this->ok();
}
* @return string
*/
function get_entries_url($page = null) {
- if($GLOBALS['post_type'] == 'attachment') {
+ if ( isset($GLOBALS['post_type']) && ( $GLOBALS['post_type'] == 'attachment' ) ) {
$path = $this->MEDIA_PATH;
} else {
$path = $this->ENTRIES_PATH;
log_app('function',"get_feed($page, '$post_type')");
ob_start();
+ $this->ENTRY_PATH = $post_type;
+
if(!isset($page)) {
$page = 1;
}
$count = get_option('posts_per_rss');
- wp('what_to_show=posts&posts_per_page=' . $count . '&offset=' . ($count * ($page-1) . '&orderby=modified'));
+ wp('posts_per_page=' . $count . '&offset=' . ($count * ($page-1) . '&orderby=modified'));
$post = $GLOBALS['post'];
$posts = $GLOBALS['posts'];
$self_page = $page > 1 ? $page : NULL;
?><feed xmlns="<?php echo $this->ATOM_NS ?>" xmlns:app="<?php echo $this->ATOMPUB_NS ?>" xml:lang="<?php echo get_option('rss_language'); ?>">
<id><?php $this->the_entries_url() ?></id>
-<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT')); ?></updated>
+<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></updated>
<title type="text"><?php bloginfo_rss('name') ?></title>
<subtitle type="text"><?php bloginfo_rss("description") ?></subtitle>
<link rel="first" type="<?php echo $this->ATOM_CONTENT_TYPE ?>" href="<?php $this->the_entries_url() ?>" />
<?php endif; ?>
<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>
+<rights type="text">Copyright <?php echo date('Y'); ?></rights>
<?php the_generator( 'atom' ); ?>
<?php if ( have_posts() ) {
while ( have_posts() ) {
$varname = 'p';
break;
case 'attachment':
+ $this->ENTRY_PATH = 'attachment';
$varname = 'attachment_id';
break;
}
</app:control>
<author>
<name><?php the_author()?></name>
-<?php if (get_the_author_url() && get_the_author_url() != 'http://') { ?>
- <uri><?php the_author_url()?></uri>
+<?php if ( get_the_author_meta('url') && get_the_author_meta('url') != 'http://' ) { ?>
+ <uri><?php the_author_meta('url') ?></uri>
<?php } ?>
</author>
<?php if($GLOBALS['post']->post_type == 'attachment') { ?>
<?php endif; ?>
<?php } ?>
<link rel="edit" href="<?php $this->the_entry_url() ?>" />
-<?php foreach(get_the_category() as $category) { ?>
- <category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->name?>" />
-<?php } ?>
+ <?php the_category_rss( 'atom' ); ?>
<?php list($content_type, $content) = prep_atom_text_construct(get_the_excerpt()); ?>
<summary type="<?php echo $content_type ?>"><?php echo $content ?></summary>
</entry>
log_app('Status','204: No Content');
header('Content-Type: text/plain');
status_header('204');
- echo "Deleted.";
+ echo "Moved to Trash.";
exit;
}
function redirect($url) {
log_app('Status','302: Redirect');
- $escaped_url = attribute_escape($url);
+ $escaped_url = esc_attr($url);
$content = <<<EOD
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
// If Basic Auth is working...
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
log_app("Basic Auth",$_SERVER['PHP_AUTH_USER']);
+
$user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
if ( $user && !is_wp_error($user) ) {
wp_set_current_user($user->ID);
- log_app("authenticate()", $_SERVER['PHP_AUTH_USER']);
+ log_app("authenticate()", $user->user_login);
return true;
}
}