The document has moved here.
EOD; header('HTTP/1.1 302 Moved'); header('Content-Type: text/html'); header('Location: ' . $url); echo $content; exit; } function client_error($msg = 'Client Error') { log_app('Status','400: Client Error'); header('Content-Type: text/plain'); status_header('400'); exit; } function created($post_ID, $content, $post_type = 'post') { log_app('created()::$post_ID',"$post_ID, $post_type"); $edit = $this->get_entry_url($post_ID); switch($post_type) { case 'post': $ctloc = $this->get_entry_url($post_ID); break; case 'attachment': $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; break; } header("Content-Type: $this->ATOM_CONTENT_TYPE"); if(isset($ctloc)) header('Content-Location: ' . $ctloc); header('Location: ' . $edit); status_header('201'); echo $content; exit; } function auth_required($msg) { log_app('Status','401: Auth Required'); nocache_headers(); header('WWW-Authenticate: Basic realm="WordPress Atom Protocol"'); header("HTTP/1.1 401 $msg"); header('Status: ' . $msg); header('Content-Type: text/html'); $content = <<$msg
EOD; echo $content; exit; } function output($xml, $ctype = 'application/atom+xml') { status_header('200'); $xml = ''."\n".$xml; header('Connection: close'); header('Content-Length: '. strlen($xml)); header('Content-Type: ' . $ctype); header('Content-Disposition: attachment; filename=atom.xml'); header('Date: '. date('r')); if($this->do_output) echo $xml; log_app('function', "output:\n$xml"); exit; } function escape(&$array) { global $wpdb; foreach ($array as $k => $v) { if (is_array($v)) { $this->escape($array[$k]); } else if (is_object($v)) { //skip } else { $array[$k] = $wpdb->escape($v); } } } /* * Access credential through various methods and perform login */ function authenticate() { $login_data = array(); $already_md5 = false; log_app("authenticate()",print_r($_ENV, true)); // if using mod_rewrite/ENV hack // http://www.besthostratings.com/articles/http-auth-php-cgi.html if(isset($_SERVER['HTTP_AUTHORIZATION'])) { list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); } // If Basic Auth is working... if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $login_data = array('login' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']); log_app("Basic Auth",$login_data['login']); } else { // else, do cookie-based authentication if (function_exists('wp_get_cookie_login')) { $login_data = wp_get_cookie_login(); $already_md5 = true; } } // call wp_login and set current user if (!empty($login_data) && wp_login($login_data['login'], $login_data['password'], $already_md5)) { $current_user = new WP_User(0, $login_data['login']); wp_set_current_user($current_user->ID); log_app("authenticate()",$login_data['login']); } } function get_accepted_content_type($types = NULL) { if(!isset($types)) { $types = $this->media_content_types; } if(!isset($_SERVER['CONTENT_LENGTH']) || !isset($_SERVER['CONTENT_TYPE'])) { $this->length_required(); } $type = $_SERVER['CONTENT_TYPE']; list($type,$subtype) = explode('/',$type); list($subtype) = explode(";",$subtype); // strip MIME parameters log_app("get_accepted_content_type", "type=$type, subtype=$subtype"); foreach($types as $t) { list($acceptedType,$acceptedSubtype) = explode('/',$t); if($acceptedType == '*' || $acceptedType == $type) { if($acceptedSubtype == '*' || $acceptedSubtype == $subtype) return $type . "/" . $subtype; } } $this->invalid_media(); } function process_conditionals() { if(empty($this->params)) return; if($_SERVER['REQUEST_METHOD'] == 'DELETE') return; switch($this->params[0]) { case $this->ENTRY_PATH: global $post; $post = wp_get_single_post($this->params[1]); $wp_last_modified = get_post_modified_time('D, d M Y H:i:s', true); $post = NULL; break; case $this->ENTRIES_PATH: $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; break; default: return; } $wp_etag = md5($wp_last_modified); @header("Last-Modified: $wp_last_modified"); @header("ETag: $wp_etag"); // Support for Conditional GET if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); else $client_etag = false; $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']); // If string is empty, return 0. If not, attempt to parse into a timestamp $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; // Make a timestamp for our most recent modification... $wp_modified_timestamp = strtotime($wp_last_modified); if ( ($client_last_modified && $client_etag) ? (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) : (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) { status_header( 304 ); exit; } } function rfc3339_str2time($str) { $match = false; if(!preg_match("/(\d{4}-\d{2}-\d{2})T(\d{2}\:\d{2}\:\d{2})\.?\d{0,3}(Z|[+-]+\d{2}\:\d{2})/", $str, $match)) return false; if($match[3] == 'Z') $match[3] == '+0000'; return strtotime($match[1] . " " . $match[2] . " " . $match[3]); } function get_publish_time($entry) { $pubtime = $this->rfc3339_str2time($entry->published); if(!$pubtime) { return array(current_time('mysql'),current_time('mysql',1)); } else { return array(date("Y-m-d H:i:s", $pubtime), gmdate("Y-m-d H:i:s", $pubtime)); } } } $server = new AtomServer(); $server->handle_request(); ?>