web/wp-includes/class-wp-xmlrpc-server.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    46 			'wp.deleteTerm'			=> 'this:wp_deleteTerm',
    46 			'wp.deleteTerm'			=> 'this:wp_deleteTerm',
    47 			'wp.getTerm'			=> 'this:wp_getTerm',
    47 			'wp.getTerm'			=> 'this:wp_getTerm',
    48 			'wp.getTerms'			=> 'this:wp_getTerms',
    48 			'wp.getTerms'			=> 'this:wp_getTerms',
    49 			'wp.getTaxonomy'		=> 'this:wp_getTaxonomy',
    49 			'wp.getTaxonomy'		=> 'this:wp_getTaxonomy',
    50 			'wp.getTaxonomies'		=> 'this:wp_getTaxonomies',
    50 			'wp.getTaxonomies'		=> 'this:wp_getTaxonomies',
       
    51 			'wp.getUser'			=> 'this:wp_getUser',
       
    52 			'wp.getUsers'			=> 'this:wp_getUsers',
       
    53 			'wp.getProfile'			=> 'this:wp_getProfile',
       
    54 			'wp.editProfile'		=> 'this:wp_editProfile',
    51 			'wp.getPage'			=> 'this:wp_getPage',
    55 			'wp.getPage'			=> 'this:wp_getPage',
    52 			'wp.getPages'			=> 'this:wp_getPages',
    56 			'wp.getPages'			=> 'this:wp_getPages',
    53 			'wp.newPage'			=> 'this:wp_newPage',
    57 			'wp.newPage'			=> 'this:wp_newPage',
    54 			'wp.deletePage'			=> 'this:wp_deletePage',
    58 			'wp.deletePage'			=> 'this:wp_deletePage',
    55 			'wp.editPage'			=> 'this:wp_editPage',
    59 			'wp.editPage'			=> 'this:wp_editPage',
    76 			'wp.getMediaItem'		=> 'this:wp_getMediaItem',
    80 			'wp.getMediaItem'		=> 'this:wp_getMediaItem',
    77 			'wp.getMediaLibrary'	=> 'this:wp_getMediaLibrary',
    81 			'wp.getMediaLibrary'	=> 'this:wp_getMediaLibrary',
    78 			'wp.getPostFormats'     => 'this:wp_getPostFormats',
    82 			'wp.getPostFormats'     => 'this:wp_getPostFormats',
    79 			'wp.getPostType'		=> 'this:wp_getPostType',
    83 			'wp.getPostType'		=> 'this:wp_getPostType',
    80 			'wp.getPostTypes'		=> 'this:wp_getPostTypes',
    84 			'wp.getPostTypes'		=> 'this:wp_getPostTypes',
       
    85 			'wp.getRevisions'		=> 'this:wp_getRevisions',
       
    86 			'wp.restoreRevision'	=> 'this:wp_restoreRevision',
    81 
    87 
    82 			// Blogger API
    88 			// Blogger API
    83 			'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
    89 			'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
    84 			'blogger.getUserInfo' => 'this:blogger_getUserInfo',
    90 			'blogger.getUserInfo' => 'this:blogger_getUserInfo',
    85 			'blogger.getPost' => 'this:blogger_getPost',
    91 			'blogger.getPost' => 'this:blogger_getPost',
    86 			'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
    92 			'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
    87 			'blogger.getTemplate' => 'this:blogger_getTemplate',
       
    88 			'blogger.setTemplate' => 'this:blogger_setTemplate',
       
    89 			'blogger.newPost' => 'this:blogger_newPost',
    93 			'blogger.newPost' => 'this:blogger_newPost',
    90 			'blogger.editPost' => 'this:blogger_editPost',
    94 			'blogger.editPost' => 'this:blogger_editPost',
    91 			'blogger.deletePost' => 'this:blogger_deletePost',
    95 			'blogger.deletePost' => 'this:blogger_deletePost',
    92 
    96 
    93 			// MetaWeblog API (with MT extensions to structs)
    97 			// MetaWeblog API (with MT extensions to structs)
    99 			'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
   103 			'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
   100 
   104 
   101 			// MetaWeblog API aliases for Blogger API
   105 			// MetaWeblog API aliases for Blogger API
   102 			// see http://www.xmlrpc.com/stories/storyReader$2460
   106 			// see http://www.xmlrpc.com/stories/storyReader$2460
   103 			'metaWeblog.deletePost' => 'this:blogger_deletePost',
   107 			'metaWeblog.deletePost' => 'this:blogger_deletePost',
   104 			'metaWeblog.getTemplate' => 'this:blogger_getTemplate',
       
   105 			'metaWeblog.setTemplate' => 'this:blogger_setTemplate',
       
   106 			'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
   108 			'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
   107 
   109 
   108 			// MovableType API
   110 			// MovableType API
   109 			'mt.getCategoryList' => 'this:mt_getCategoryList',
   111 			'mt.getCategoryList' => 'this:mt_getCategoryList',
   110 			'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
   112 			'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
   156 		$number2 = $args[1];
   158 		$number2 = $args[1];
   157 		return $number1 + $number2;
   159 		return $number1 + $number2;
   158 	}
   160 	}
   159 
   161 
   160 	/**
   162 	/**
   161 	 * Check user's credentials.
       
   162 	 *
       
   163 	 * @since 1.5.0
       
   164 	 *
       
   165 	 * @param string $user_login User's username.
       
   166 	 * @param string $user_pass User's password.
       
   167 	 * @return bool Whether authentication passed.
       
   168 	 * @deprecated use wp_xmlrpc_server::login
       
   169 	 * @see wp_xmlrpc_server::login
       
   170 	 */
       
   171 	function login_pass_ok($user_login, $user_pass) {
       
   172 		if ( !get_option( 'enable_xmlrpc' ) ) {
       
   173 			$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site. An admin user can enable them at %s'),  admin_url('options-writing.php') ) );
       
   174 			return false;
       
   175 		}
       
   176 
       
   177 		if (!user_pass_ok($user_login, $user_pass)) {
       
   178 			$this->error = new IXR_Error(403, __('Bad login/pass combination.'));
       
   179 			return false;
       
   180 		}
       
   181 		return true;
       
   182 	}
       
   183 
       
   184 	/**
       
   185 	 * Log user in.
   163 	 * Log user in.
   186 	 *
   164 	 *
   187 	 * @since 2.8
   165 	 * @since 2.8.0
   188 	 *
   166 	 *
   189 	 * @param string $username User's username.
   167 	 * @param string $username User's username.
   190 	 * @param string $password User's password.
   168 	 * @param string $password User's password.
   191 	 * @return mixed WP_User object if authentication passed, false otherwise
   169 	 * @return mixed WP_User object if authentication passed, false otherwise
   192 	 */
   170 	 */
   193 	function login($username, $password) {
   171 	function login( $username, $password ) {
   194 		if ( !get_option( 'enable_xmlrpc' ) ) {
   172 		// Respect any old filters against get_option() for 'enable_xmlrpc'.
   195 			$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site. An admin user can enable them at %s'),  admin_url('options-writing.php') ) );
   173 		$enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); // Deprecated
       
   174 		if ( false === $enabled )
       
   175 			$enabled = apply_filters( 'option_enable_xmlrpc', true ); // Deprecated
       
   176 
       
   177 		// Proper filter for turning off XML-RPC. It is on by default.
       
   178 		$enabled = apply_filters( 'xmlrpc_enabled', $enabled );
       
   179 
       
   180 		if ( ! $enabled ) {
       
   181 			$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) );
   196 			return false;
   182 			return false;
   197 		}
   183 		}
   198 
   184 
   199 		$user = wp_authenticate($username, $password);
   185 		$user = wp_authenticate($username, $password);
   200 
   186 
   201 		if (is_wp_error($user)) {
   187 		if (is_wp_error($user)) {
   202 			$this->error = new IXR_Error(403, __('Bad login/pass combination.'));
   188 			$this->error = new IXR_Error( 403, __( 'Incorrect username or password.' ) );
       
   189 			$this->error = apply_filters( 'xmlrpc_login_error', $this->error, $user );
   203 			return false;
   190 			return false;
   204 		}
   191 		}
   205 
   192 
   206 		wp_set_current_user( $user->ID );
   193 		wp_set_current_user( $user->ID );
   207 		return $user;
   194 		return $user;
       
   195 	}
       
   196 
       
   197 	/**
       
   198 	 * Check user's credentials. Deprecated.
       
   199 	 *
       
   200 	 * @since 1.5.0
       
   201 	 * @deprecated 2.8.0
       
   202 	 * @deprecated use wp_xmlrpc_server::login
       
   203 	 * @see wp_xmlrpc_server::login
       
   204 	 *
       
   205 	 * @param string $username User's username.
       
   206 	 * @param string $password User's password.
       
   207 	 * @return bool Whether authentication passed.
       
   208 	 */
       
   209 	function login_pass_ok( $username, $password ) {
       
   210 		return (bool) $this->login( $username, $password );
   208 	}
   211 	}
   209 
   212 
   210 	/**
   213 	/**
   211 	 * Sanitize string or array of strings for database.
   214 	 * Sanitize string or array of strings for database.
   212 	 *
   215 	 *
   316 			),
   319 			),
   317 			'blog_url'          => array(
   320 			'blog_url'          => array(
   318 				'desc'          => __( 'Site URL' ),
   321 				'desc'          => __( 'Site URL' ),
   319 				'readonly'      => true,
   322 				'readonly'      => true,
   320 				'option'        => 'siteurl'
   323 				'option'        => 'siteurl'
       
   324 			),
       
   325 			'home_url'          => array(
       
   326 				'desc'          => __( 'Home URL' ),
       
   327 				'readonly'      => true,
       
   328 				'option'        => 'home'
   321 			),
   329 			),
   322 			'image_default_link_type' => array(
   330 			'image_default_link_type' => array(
   323 				'desc'          => __( 'Image default link type' ),
   331 				'desc'          => __( 'Image default link type' ),
   324 				'readonly'      => true,
   332 				'readonly'      => true,
   325 				'option'        => 'image_default_link_type'
   333 				'option'        => 'image_default_link_type'
   471 			// Don't include blogs that aren't hosted at this site
   479 			// Don't include blogs that aren't hosted at this site
   472 			if ( $blog->site_id != $current_site->id )
   480 			if ( $blog->site_id != $current_site->id )
   473 				continue;
   481 				continue;
   474 
   482 
   475 			$blog_id = $blog->userblog_id;
   483 			$blog_id = $blog->userblog_id;
   476 			switch_to_blog($blog_id);
   484 
   477 			$is_admin = current_user_can('manage_options');
   485 			switch_to_blog( $blog_id );
       
   486 
       
   487 			$is_admin = current_user_can( 'manage_options' );
   478 
   488 
   479 			$struct[] = array(
   489 			$struct[] = array(
   480 				'isAdmin'		=> $is_admin,
   490 				'isAdmin'		=> $is_admin,
   481 				'url'			=> get_option( 'home' ) . '/',
   491 				'url'			=> home_url( '/' ),
   482 				'blogid'		=> (string) $blog_id,
   492 				'blogid'		=> (string) $blog_id,
   483 				'blogName'		=> get_option( 'blogname' ),
   493 				'blogName'		=> get_option( 'blogname' ),
   484 				'xmlrpc'		=> site_url( 'xmlrpc.php' )
   494 				'xmlrpc'		=> site_url( 'xmlrpc.php', 'rpc' ),
   485 			);
   495 			);
   486 
   496 
   487 			restore_current_blog();
   497 			restore_current_blog();
   488 		}
   498 		}
   489 
   499 
   771 		$link = post_permalink( $page->ID );
   781 		$link = post_permalink( $page->ID );
   772 
   782 
   773 		// Get info the page parent if there is one.
   783 		// Get info the page parent if there is one.
   774 		$parent_title = "";
   784 		$parent_title = "";
   775 		if ( ! empty( $page->post_parent ) ) {
   785 		if ( ! empty( $page->post_parent ) ) {
   776 			$parent = get_page( $page->post_parent );
   786 			$parent = get_post( $page->post_parent );
   777 			$parent_title = $parent->post_title;
   787 			$parent_title = $parent->post_title;
   778 		}
   788 		}
   779 
   789 
   780 		// Determine comment and ping settings.
   790 		// Determine comment and ping settings.
   781 		$allow_comments = comments_open( $page->ID ) ? 1 : 0;
   791 		$allow_comments = comments_open( $page->ID ) ? 1 : 0;
   869 
   879 
   870 		return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment );
   880 		return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment );
   871 	}
   881 	}
   872 
   882 
   873 	/**
   883 	/**
       
   884 	 * Prepares user data for return in an XML-RPC object.
       
   885 	 *
       
   886 	 * @access protected
       
   887 	 *
       
   888 	 * @param WP_User $user The unprepared user object
       
   889 	 * @param array $fields The subset of user fields to return
       
   890 	 * @return array The prepared user data
       
   891 	 */
       
   892 	protected function _prepare_user( $user, $fields ) {
       
   893 		$_user = array( 'user_id' => strval( $user->ID ) );
       
   894 
       
   895 		$user_fields = array(
       
   896 			'username'          => $user->user_login,
       
   897 			'first_name'        => $user->user_firstname,
       
   898 			'last_name'         => $user->user_lastname,
       
   899 			'registered'        => $this->_convert_date( $user->user_registered ),
       
   900 			'bio'               => $user->user_description,
       
   901 			'email'             => $user->user_email,
       
   902 			'nickname'          => $user->nickname,
       
   903 			'nicename'          => $user->user_nicename,
       
   904 			'url'               => $user->user_url,
       
   905 			'display_name'      => $user->display_name,
       
   906 			'roles'             => $user->roles,
       
   907 		);
       
   908 
       
   909 		if ( in_array( 'all', $fields ) ) {
       
   910 			$_user = array_merge( $_user, $user_fields );
       
   911 		} else {
       
   912 			if ( in_array( 'basic', $fields ) ) {
       
   913 				$basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' );
       
   914 				$fields = array_merge( $fields, $basic_fields );
       
   915 			}
       
   916 			$requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) );
       
   917 			$_user = array_merge( $_user, $requested_fields );
       
   918 		}
       
   919 
       
   920 		return apply_filters( 'xmlrpc_prepare_user', $_user, $user, $fields );
       
   921 	}
       
   922 
       
   923 	/**
   874 	 * Create a new post for any registered post type.
   924 	 * Create a new post for any registered post type.
   875 	 *
   925 	 *
   876 	 * @since 3.4.0
   926 	 * @since 3.4.0
   877 	 *
   927 	 *
   878 	 * @param array $args Method parameters. Contains:
   928 	 * @param array $args Method parameters. Contains:
   883 	 *      $content_struct can contain:
   933 	 *      $content_struct can contain:
   884 	 *      - post_type (default: 'post')
   934 	 *      - post_type (default: 'post')
   885 	 *      - post_status (default: 'draft')
   935 	 *      - post_status (default: 'draft')
   886 	 *      - post_title
   936 	 *      - post_title
   887 	 *      - post_author
   937 	 *      - post_author
   888 	 *      - post_exerpt
   938 	 *      - post_excerpt
   889 	 *      - post_content
   939 	 *      - post_content
   890 	 *      - post_date_gmt | post_date
   940 	 *      - post_date_gmt | post_date
   891 	 *      - post_format
   941 	 *      - post_format
   892 	 *      - post_password
   942 	 *      - post_password
   893 	 *      - comment_status - can be 'open' | 'closed'
   943 	 *      - comment_status - can be 'open' | 'closed'
   960 			if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) )
  1010 			if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) )
   961 				return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
  1011 				return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
   962 			if ( $post_data['post_type'] != get_post_type( $post_data['ID'] ) )
  1012 			if ( $post_data['post_type'] != get_post_type( $post_data['ID'] ) )
   963 				return new IXR_Error( 401, __( 'The post type may not be changed.' ) );
  1013 				return new IXR_Error( 401, __( 'The post type may not be changed.' ) );
   964 		} else {
  1014 		} else {
   965 			if ( ! current_user_can( $post_type->cap->edit_posts ) )
  1015 			if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) )
   966 				return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) );
  1016 				return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) );
   967 		}
  1017 		}
   968 
  1018 
   969 		switch ( $post_data['post_status'] ) {
  1019 		switch ( $post_data['post_status'] ) {
   970 			case 'draft':
  1020 			case 'draft':
   978 			case 'future':
  1028 			case 'future':
   979 				if ( ! current_user_can( $post_type->cap->publish_posts ) )
  1029 				if ( ! current_user_can( $post_type->cap->publish_posts ) )
   980 					return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type' ) );
  1030 					return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type' ) );
   981 				break;
  1031 				break;
   982 			default:
  1032 			default:
   983 				$post_data['post_status'] = 'draft';
  1033 				if ( ! get_post_status_object( $post_data['post_status'] ) )
       
  1034 					$post_data['post_status'] = 'draft';
   984 			break;
  1035 			break;
   985 		}
  1036 		}
   986 
  1037 
   987 		if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) )
  1038 		if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) )
   988 			return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type' ) );
  1039 			return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type' ) );
  1043 
  1094 
  1044 		if ( isset( $post_data['post_thumbnail'] ) ) {
  1095 		if ( isset( $post_data['post_thumbnail'] ) ) {
  1045 			// empty value deletes, non-empty value adds/updates
  1096 			// empty value deletes, non-empty value adds/updates
  1046 			if ( ! $post_data['post_thumbnail'] )
  1097 			if ( ! $post_data['post_thumbnail'] )
  1047 				delete_post_thumbnail( $post_ID );
  1098 				delete_post_thumbnail( $post_ID );
  1048 			elseif ( ! set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ) )
  1099 			elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) )
  1049 					return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
  1100 				return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
       
  1101 			set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] );
  1050 			unset( $content_struct['post_thumbnail'] );
  1102 			unset( $content_struct['post_thumbnail'] );
  1051 		}
  1103 		}
  1052 
  1104 
  1053 		if ( isset( $post_data['custom_fields'] ) )
  1105 		if ( isset( $post_data['custom_fields'] ) )
  1054 			$this->set_custom_fields( $post_ID, $post_data['custom_fields'] );
  1106 			$this->set_custom_fields( $post_ID, $post_data['custom_fields'] );
  1155 
  1207 
  1156 		$this->attach_uploads( $post_ID, $post_data['post_content'] );
  1208 		$this->attach_uploads( $post_ID, $post_data['post_content'] );
  1157 
  1209 
  1158 		$post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct );
  1210 		$post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct );
  1159 
  1211 
  1160 		$post_ID = wp_insert_post( $post_data, true );
  1212 		$post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true );
  1161 		if ( is_wp_error( $post_ID ) )
  1213 		if ( is_wp_error( $post_ID ) )
  1162 			return new IXR_Error( 500, $post_ID->get_error_message() );
  1214 			return new IXR_Error( 500, $post_ID->get_error_message() );
  1163 
  1215 
  1164 		if ( ! $post_ID )
  1216 		if ( ! $post_ID )
  1165 			return new IXR_Error( 401, __( 'Sorry, your entry could not be posted. Something wrong happened.' ) );
  1217 			return new IXR_Error( 401, __( 'Sorry, your entry could not be posted. Something wrong happened.' ) );
  1203 		$post = get_post( $post_id, ARRAY_A );
  1255 		$post = get_post( $post_id, ARRAY_A );
  1204 
  1256 
  1205 		if ( empty( $post['ID'] ) )
  1257 		if ( empty( $post['ID'] ) )
  1206 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  1258 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  1207 
  1259 
       
  1260 		if ( isset( $content_struct['if_not_modified_since'] ) ) {
       
  1261 			// If the post has been modified since the date provided, return an error.
       
  1262 			if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) {
       
  1263 				return new IXR_Error( 409, __( 'There is a revision of this post that is more recent.' ) );
       
  1264 			}
       
  1265 		}
       
  1266 
  1208 		// convert the date field back to IXR form
  1267 		// convert the date field back to IXR form
  1209 		$post['post_date'] = $this->_convert_date( $post['post_date'] );
  1268 		$post['post_date'] = $this->_convert_date( $post['post_date'] );
  1210 
  1269 
  1211 		// ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
  1270 		// ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
  1212 		// since _insert_post will ignore the non-GMT date if the GMT date is set
  1271 		// since _insert_post will ignore the non-GMT date if the GMT date is set
  1252 		if ( ! $user = $this->login( $username, $password ) )
  1311 		if ( ! $user = $this->login( $username, $password ) )
  1253 			return $this->error;
  1312 			return $this->error;
  1254 
  1313 
  1255 		do_action( 'xmlrpc_call', 'wp.deletePost' );
  1314 		do_action( 'xmlrpc_call', 'wp.deletePost' );
  1256 
  1315 
  1257 		$post = wp_get_single_post( $post_id, ARRAY_A );
  1316 		$post = get_post( $post_id, ARRAY_A );
  1258 		if ( empty( $post['ID'] ) )
  1317 		if ( empty( $post['ID'] ) )
  1259 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  1318 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  1260 
  1319 
  1261 		$post_type = get_post_type_object( $post['post_type'] );
  1320 		$post_type = get_post_type_object( $post['post_type'] );
  1262 		if ( ! current_user_can( $post_type->cap->delete_post, $post_id ) )
  1321 		if ( ! current_user_can( $post_type->cap->delete_post, $post_id ) )
  1282 	 * Instead of, or in addition to, individual field names, conceptual group
  1341 	 * Instead of, or in addition to, individual field names, conceptual group
  1283 	 * names can be used to specify multiple fields. The available conceptual
  1342 	 * names can be used to specify multiple fields. The available conceptual
  1284 	 * groups are 'post' (all basic fields), 'taxonomies', 'custom_fields',
  1343 	 * groups are 'post' (all basic fields), 'taxonomies', 'custom_fields',
  1285 	 * and 'enclosure'.
  1344 	 * and 'enclosure'.
  1286 	 *
  1345 	 *
  1287 	 * @uses wp_get_single_post()
  1346 	 * @uses get_post()
  1288 	 * @param array $args Method parameters. Contains:
  1347 	 * @param array $args Method parameters. Contains:
  1289 	 *  - int     $post_id
  1348 	 *  - int     $post_id
  1290 	 *  - string  $username
  1349 	 *  - string  $username
  1291 	 *  - string  $password
  1350 	 *  - string  $password
  1292 	 *  - array   $fields optional
  1351 	 *  - array   $fields optional
  1333 		if ( ! $user = $this->login( $username, $password ) )
  1392 		if ( ! $user = $this->login( $username, $password ) )
  1334 			return $this->error;
  1393 			return $this->error;
  1335 
  1394 
  1336 		do_action( 'xmlrpc_call', 'wp.getPost' );
  1395 		do_action( 'xmlrpc_call', 'wp.getPost' );
  1337 
  1396 
  1338 		$post = wp_get_single_post( $post_id, ARRAY_A );
  1397 		$post = get_post( $post_id, ARRAY_A );
  1339 
  1398 
  1340 		if ( empty( $post['ID'] ) )
  1399 		if ( empty( $post['ID'] ) )
  1341 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  1400 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  1342 
  1401 
  1343 		$post_type = get_post_type_object( $post['post_type'] );
  1402 		$post_type = get_post_type_object( $post['post_type'] );
  1419 		if ( isset( $filter['orderby'] ) ) {
  1478 		if ( isset( $filter['orderby'] ) ) {
  1420 			$query['orderby'] = $filter['orderby'];
  1479 			$query['orderby'] = $filter['orderby'];
  1421 
  1480 
  1422 			if ( isset( $filter['order'] ) )
  1481 			if ( isset( $filter['order'] ) )
  1423 				$query['order'] = $filter['order'];
  1482 				$query['order'] = $filter['order'];
       
  1483 		}
       
  1484 
       
  1485 		if ( isset( $filter['s'] ) ) {
       
  1486 			$query['s'] = $filter['s'];
  1424 		}
  1487 		}
  1425 
  1488 
  1426 		$posts_list = wp_get_recent_posts( $query );
  1489 		$posts_list = wp_get_recent_posts( $query );
  1427 
  1490 
  1428 		if ( ! $posts_list )
  1491 		if ( ! $posts_list )
  1916 
  1979 
  1917 		return $struct;
  1980 		return $struct;
  1918 	}
  1981 	}
  1919 
  1982 
  1920 	/**
  1983 	/**
       
  1984 	 * Retrieve a user.
       
  1985 	 *
       
  1986 	 * The optional $fields parameter specifies what fields will be included
       
  1987 	 * in the response array. This should be a list of field names. 'user_id' will
       
  1988 	 * always be included in the response regardless of the value of $fields.
       
  1989 	 *
       
  1990 	 * Instead of, or in addition to, individual field names, conceptual group
       
  1991 	 * names can be used to specify multiple fields. The available conceptual
       
  1992 	 * groups are 'basic' and 'all'.
       
  1993 	 *
       
  1994 	 * @uses get_userdata()
       
  1995 	 * @param array $args Method parameters. Contains:
       
  1996 	 *  - int     $blog_id
       
  1997 	 *  - string  $username
       
  1998 	 *  - string  $password
       
  1999 	 *  - int     $user_id
       
  2000 	 *  - array   $fields optional
       
  2001 	 * @return array contains (based on $fields parameter):
       
  2002 	 *  - 'user_id'
       
  2003 	 *  - 'username'
       
  2004 	 *  - 'first_name'
       
  2005 	 *  - 'last_name'
       
  2006 	 *  - 'registered'
       
  2007 	 *  - 'bio'
       
  2008 	 *  - 'email'
       
  2009 	 *  - 'nickname'
       
  2010 	 *  - 'nicename'
       
  2011 	 *  - 'url'
       
  2012 	 *  - 'display_name'
       
  2013 	 *  - 'roles'
       
  2014 	 */
       
  2015 	function wp_getUser( $args ) {
       
  2016 		if ( ! $this->minimum_args( $args, 4 ) )
       
  2017 			return $this->error;
       
  2018 
       
  2019 		$this->escape( $args );
       
  2020 
       
  2021 		$blog_id    = (int) $args[0];
       
  2022 		$username   = $args[1];
       
  2023 		$password   = $args[2];
       
  2024 		$user_id    = (int) $args[3];
       
  2025 
       
  2026 		if ( isset( $args[4] ) )
       
  2027 			$fields = $args[4];
       
  2028 		else
       
  2029 			$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' );
       
  2030 
       
  2031 		if ( ! $user = $this->login( $username, $password ) )
       
  2032 			return $this->error;
       
  2033 
       
  2034 		do_action( 'xmlrpc_call', 'wp.getUser' );
       
  2035 
       
  2036 		if ( ! current_user_can( 'edit_user', $user_id ) )
       
  2037 			return new IXR_Error( 401, __( 'Sorry, you cannot edit users.' ) );
       
  2038 
       
  2039 		$user_data = get_userdata( $user_id );
       
  2040 
       
  2041 		if ( ! $user_data )
       
  2042 			return new IXR_Error( 404, __( 'Invalid user ID' ) );
       
  2043 
       
  2044 		return $this->_prepare_user( $user_data, $fields );
       
  2045 	}
       
  2046 
       
  2047 	/**
       
  2048 	 * Retrieve users.
       
  2049 	 *
       
  2050 	 * The optional $filter parameter modifies the query used to retrieve users.
       
  2051 	 * Accepted keys are 'number' (default: 50), 'offset' (default: 0), 'role',
       
  2052 	 * 'who', 'orderby', and 'order'.
       
  2053 	 *
       
  2054 	 * The optional $fields parameter specifies what fields will be included
       
  2055 	 * in the response array.
       
  2056 	 *
       
  2057 	 * @uses get_users()
       
  2058 	 * @see wp_getUser() for more on $fields and return values
       
  2059 	 *
       
  2060 	 * @param array $args Method parameters. Contains:
       
  2061 	 *  - int     $blog_id
       
  2062 	 *  - string  $username
       
  2063 	 *  - string  $password
       
  2064 	 *  - array   $filter optional
       
  2065 	 *  - array   $fields optional
       
  2066 	 * @return array users data
       
  2067 	 */
       
  2068 	function wp_getUsers( $args ) {
       
  2069 		if ( ! $this->minimum_args( $args, 3 ) )
       
  2070 			return $this->error;
       
  2071 
       
  2072 		$this->escape( $args );
       
  2073 
       
  2074 		$blog_id    = (int) $args[0];
       
  2075 		$username   = $args[1];
       
  2076 		$password   = $args[2];
       
  2077 		$filter     = isset( $args[3] ) ? $args[3] : array();
       
  2078 
       
  2079 		if ( isset( $args[4] ) )
       
  2080 			$fields = $args[4];
       
  2081 		else
       
  2082 			$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' );
       
  2083 
       
  2084 		if ( ! $user = $this->login( $username, $password ) )
       
  2085 			return $this->error;
       
  2086 
       
  2087 		do_action( 'xmlrpc_call', 'wp.getUsers' );
       
  2088 
       
  2089 		if ( ! current_user_can( 'list_users' ) )
       
  2090 			return new IXR_Error( 401, __( 'Sorry, you cannot list users.' ) );
       
  2091 
       
  2092 		$query = array( 'fields' => 'all_with_meta' );
       
  2093 
       
  2094 		$query['number'] = ( isset( $filter['number'] ) ) ? absint( $filter['number'] ) : 50;
       
  2095 		$query['offset'] = ( isset( $filter['offset'] ) ) ? absint( $filter['offset'] ) : 0;
       
  2096 
       
  2097 		if ( isset( $filter['orderby'] ) ) {
       
  2098 			$query['orderby'] = $filter['orderby'];
       
  2099 
       
  2100 			if ( isset( $filter['order'] ) )
       
  2101 				$query['order'] = $filter['order'];
       
  2102 		}
       
  2103 
       
  2104 		if ( isset( $filter['role'] ) ) {
       
  2105 			if ( get_role( $filter['role'] ) === null )
       
  2106 				return new IXR_Error( 403, __( 'The role specified is not valid' ) );
       
  2107 
       
  2108 			$query['role'] = $filter['role'];
       
  2109 		}
       
  2110 
       
  2111 		if ( isset( $filter['who'] ) ) {
       
  2112 			$query['who'] = $filter['who'];
       
  2113 		}
       
  2114 
       
  2115 		$users = get_users( $query );
       
  2116 
       
  2117 		$_users = array();
       
  2118 		foreach ( $users as $user_data ) {
       
  2119 			if ( current_user_can( 'edit_user', $user_data->ID ) )
       
  2120 				$_users[] = $this->_prepare_user( $user_data, $fields );
       
  2121 		}
       
  2122 		return $_users;
       
  2123 	}
       
  2124 
       
  2125 	/**
       
  2126 	 * Retrieve information about the requesting user.
       
  2127 	 *
       
  2128 	 * @uses get_userdata()
       
  2129 	 * @param array $args Method parameters. Contains:
       
  2130 	 *  - int     $blog_id
       
  2131 	 *  - string  $username
       
  2132 	 *  - string  $password
       
  2133 	 *  - array   $fields optional
       
  2134 	 * @return array (@see wp_getUser)
       
  2135 	 */
       
  2136 	function wp_getProfile( $args ) {
       
  2137 		if ( ! $this->minimum_args( $args, 3 ) )
       
  2138 			return $this->error;
       
  2139 
       
  2140 		$this->escape( $args );
       
  2141 
       
  2142 		$blog_id    = (int) $args[0];
       
  2143 		$username   = $args[1];
       
  2144 		$password   = $args[2];
       
  2145 
       
  2146 		if ( isset( $args[3] ) )
       
  2147 			$fields = $args[3];
       
  2148 		else
       
  2149 			$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' );
       
  2150 
       
  2151 		if ( ! $user = $this->login( $username, $password ) )
       
  2152 			return $this->error;
       
  2153 
       
  2154 		do_action( 'xmlrpc_call', 'wp.getProfile' );
       
  2155 
       
  2156 		if ( ! current_user_can( 'edit_user', $user->ID ) )
       
  2157 			return new IXR_Error( 401, __( 'Sorry, you cannot edit your profile.' ) );
       
  2158 
       
  2159 		$user_data = get_userdata( $user->ID );
       
  2160 
       
  2161 		return $this->_prepare_user( $user_data, $fields );
       
  2162 	}
       
  2163 
       
  2164 	/**
       
  2165 	 * Edit user's profile.
       
  2166 	 *
       
  2167 	 * @uses wp_update_user()
       
  2168 	 * @param array $args Method parameters. Contains:
       
  2169 	 *  - int     $blog_id
       
  2170 	 *  - string  $username
       
  2171 	 *  - string  $password
       
  2172 	 *  - array   $content_struct
       
  2173 	 *      It can optionally contain:
       
  2174 	 *      - 'first_name'
       
  2175 	 *      - 'last_name'
       
  2176 	 *      - 'website'
       
  2177 	 *      - 'display_name'
       
  2178 	 *      - 'nickname'
       
  2179 	 *      - 'nicename'
       
  2180 	 *      - 'bio'
       
  2181 	 * @return bool True, on success.
       
  2182 	 */
       
  2183 	function wp_editProfile( $args ) {
       
  2184 		if ( ! $this->minimum_args( $args, 4 ) )
       
  2185 			return $this->error;
       
  2186 
       
  2187 		$this->escape( $args );
       
  2188 
       
  2189 		$blog_id        = (int) $args[0];
       
  2190 		$username       = $args[1];
       
  2191 		$password       = $args[2];
       
  2192 		$content_struct = $args[3];
       
  2193 
       
  2194 		if ( ! $user = $this->login( $username, $password ) )
       
  2195 			return $this->error;
       
  2196 
       
  2197 		do_action( 'xmlrpc_call', 'wp.editProfile' );
       
  2198 
       
  2199 		if ( ! current_user_can( 'edit_user', $user->ID ) )
       
  2200 			return new IXR_Error( 401, __( 'Sorry, you cannot edit your profile.' ) );
       
  2201 
       
  2202 		// holds data of the user
       
  2203 		$user_data = array();
       
  2204 		$user_data['ID'] = $user->ID;
       
  2205 
       
  2206 		// only set the user details if it was given
       
  2207 		if ( isset( $content_struct['first_name'] ) )
       
  2208 			$user_data['first_name'] = $content_struct['first_name'];
       
  2209 
       
  2210 		if ( isset( $content_struct['last_name'] ) )
       
  2211 			$user_data['last_name'] = $content_struct['last_name'];
       
  2212 
       
  2213 		if ( isset( $content_struct['url'] ) )
       
  2214 			$user_data['user_url'] = $content_struct['url'];
       
  2215 
       
  2216 		if ( isset( $content_struct['display_name'] ) )
       
  2217 			$user_data['display_name'] = $content_struct['display_name'];
       
  2218 
       
  2219 		if ( isset( $content_struct['nickname'] ) )
       
  2220 			$user_data['nickname'] = $content_struct['nickname'];
       
  2221 
       
  2222 		if ( isset( $content_struct['nicename'] ) )
       
  2223 			$user_data['user_nicename'] = $content_struct['nicename'];
       
  2224 
       
  2225 		if ( isset( $content_struct['bio'] ) )
       
  2226 			$user_data['description'] = $content_struct['bio'];
       
  2227 
       
  2228 		$result = wp_update_user( $user_data );
       
  2229 
       
  2230 		if ( is_wp_error( $result ) )
       
  2231 			return new IXR_Error( 500, $result->get_error_message() );
       
  2232 
       
  2233 		if ( ! $result )
       
  2234 			return new IXR_Error( 500, __( 'Sorry, the user cannot be updated.' ) );
       
  2235 
       
  2236 		return true;
       
  2237 	}
       
  2238 
       
  2239 	/**
  1921 	 * Retrieve page.
  2240 	 * Retrieve page.
  1922 	 *
  2241 	 *
  1923 	 * @since 2.2.0
  2242 	 * @since 2.2.0
  1924 	 *
  2243 	 *
  1925 	 * @param array $args Method parameters. Contains:
  2244 	 * @param array $args Method parameters. Contains:
  1939 
  2258 
  1940 		if ( !$user = $this->login($username, $password) ) {
  2259 		if ( !$user = $this->login($username, $password) ) {
  1941 			return $this->error;
  2260 			return $this->error;
  1942 		}
  2261 		}
  1943 
  2262 
  1944 		$page = get_page($page_id);
  2263 		$page = get_post($page_id);
  1945 		if ( ! $page )
  2264 		if ( ! $page )
  1946 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  2265 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  1947 
  2266 
  1948 		if ( !current_user_can( 'edit_page', $page_id ) )
  2267 		if ( !current_user_can( 'edit_page', $page_id ) )
  1949 			return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) );
  2268 			return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) );
  2056 
  2375 
  2057 		do_action('xmlrpc_call', 'wp.deletePage');
  2376 		do_action('xmlrpc_call', 'wp.deletePage');
  2058 
  2377 
  2059 		// Get the current page based on the page_id and
  2378 		// Get the current page based on the page_id and
  2060 		// make sure it is a page and not a post.
  2379 		// make sure it is a page and not a post.
  2061 		$actual_page = wp_get_single_post($page_id, ARRAY_A);
  2380 		$actual_page = get_post($page_id, ARRAY_A);
  2062 		if ( !$actual_page || ($actual_page['post_type'] != 'page') )
  2381 		if ( !$actual_page || ($actual_page['post_type'] != 'page') )
  2063 			return(new IXR_Error(404, __('Sorry, no such page.')));
  2382 			return(new IXR_Error(404, __('Sorry, no such page.')));
  2064 
  2383 
  2065 		// Make sure the user can delete pages.
  2384 		// Make sure the user can delete pages.
  2066 		if ( !current_user_can('delete_page', $page_id) )
  2385 		if ( !current_user_can('delete_page', $page_id) )
  2097 			return $this->error;
  2416 			return $this->error;
  2098 
  2417 
  2099 		do_action('xmlrpc_call', 'wp.editPage');
  2418 		do_action('xmlrpc_call', 'wp.editPage');
  2100 
  2419 
  2101 		// Get the page data and make sure it is a page.
  2420 		// Get the page data and make sure it is a page.
  2102 		$actual_page = wp_get_single_post($page_id, ARRAY_A);
  2421 		$actual_page = get_post($page_id, ARRAY_A);
  2103 		if ( !$actual_page || ($actual_page['post_type'] != 'page') )
  2422 		if ( !$actual_page || ($actual_page['post_type'] != 'page') )
  2104 			return(new IXR_Error(404, __('Sorry, no such page.')));
  2423 			return(new IXR_Error(404, __('Sorry, no such page.')));
  2105 
  2424 
  2106 		// Make sure the user is allowed to edit pages.
  2425 		// Make sure the user is allowed to edit pages.
  2107 		if ( !current_user_can('edit_page', $page_id) )
  2426 		if ( !current_user_can('edit_page', $page_id) )
  3167 		}
  3486 		}
  3168 
  3487 
  3169 		return $struct;
  3488 		return $struct;
  3170 	}
  3489 	}
  3171 
  3490 
       
  3491 	/**
       
  3492 	 * Retrieve revisions for a specific post.
       
  3493 	 *
       
  3494 	 * @since 3.5.0
       
  3495 	 *
       
  3496 	 * The optional $fields parameter specifies what fields will be included
       
  3497 	 * in the response array.
       
  3498 	 *
       
  3499 	 * @uses wp_get_post_revisions()
       
  3500 	 * @see wp_getPost() for more on $fields
       
  3501 	 *
       
  3502 	 * @param array $args Method parameters. Contains:
       
  3503 	 *  - int     $blog_id
       
  3504 	 *  - string  $username
       
  3505 	 *  - string  $password
       
  3506 	 *  - int     $post_id
       
  3507 	 *  - array   $fields
       
  3508 	 * @return array contains a collection of posts.
       
  3509 	 */
       
  3510 	function wp_getRevisions( $args ) {
       
  3511 		if ( ! $this->minimum_args( $args, 4 ) )
       
  3512 			return $this->error;
       
  3513 
       
  3514 		$this->escape( $args );
       
  3515 
       
  3516 		$blog_id    = (int) $args[0];
       
  3517 		$username   = $args[1];
       
  3518 		$password   = $args[2];
       
  3519 		$post_id    = (int) $args[3];
       
  3520 
       
  3521 		if ( isset( $args[4] ) )
       
  3522 			$fields = $args[4];
       
  3523 		else
       
  3524 			$fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' );
       
  3525 
       
  3526 		if ( ! $user = $this->login( $username, $password ) )
       
  3527 			return $this->error;
       
  3528 
       
  3529 		do_action( 'xmlrpc_call', 'wp.getRevisions' );
       
  3530 
       
  3531 		if ( ! $post = get_post( $post_id ) )
       
  3532 			return new IXR_Error( 404, __( 'Invalid post ID' ) );
       
  3533 
       
  3534 		if ( ! current_user_can( 'edit_post', $post_id ) )
       
  3535 			return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
       
  3536 
       
  3537 		// Check if revisions are enabled.
       
  3538 		if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
       
  3539 			return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
       
  3540 
       
  3541 		$revisions = wp_get_post_revisions( $post_id );
       
  3542 
       
  3543 		if ( ! $revisions )
       
  3544 			return array();
       
  3545 
       
  3546 		$struct = array();
       
  3547 
       
  3548 		foreach ( $revisions as $revision ) {
       
  3549 			if ( ! current_user_can( 'read_post', $revision->ID ) )
       
  3550 				continue;
       
  3551 
       
  3552 			// Skip autosaves
       
  3553 			if ( wp_is_post_autosave( $revision ) )
       
  3554 				continue;
       
  3555 
       
  3556 			$struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields );
       
  3557 		}
       
  3558 
       
  3559 		return $struct;
       
  3560 	}
       
  3561 
       
  3562 	/**
       
  3563 	 * Restore a post revision
       
  3564 	 *
       
  3565 	 * @since 3.5.0
       
  3566 	 *
       
  3567 	 * @uses wp_restore_post_revision()
       
  3568 	 *
       
  3569 	 * @param array $args Method parameters. Contains:
       
  3570 	 *  - int     $blog_id
       
  3571 	 *  - string  $username
       
  3572 	 *  - string  $password
       
  3573 	 *  - int     $post_id
       
  3574 	 * @return bool false if there was an error restoring, true if success.
       
  3575 	 */
       
  3576 	function wp_restoreRevision( $args ) {
       
  3577 		if ( ! $this->minimum_args( $args, 3 ) )
       
  3578 			return $this->error;
       
  3579 
       
  3580 		$this->escape( $args );
       
  3581 
       
  3582 		$blog_id     = (int) $args[0];
       
  3583 		$username    = $args[1];
       
  3584 		$password    = $args[2];
       
  3585 		$revision_id = (int) $args[3];
       
  3586 
       
  3587 		if ( ! $user = $this->login( $username, $password ) )
       
  3588 			return $this->error;
       
  3589 
       
  3590 		do_action( 'xmlrpc_call', 'wp.restoreRevision' );
       
  3591 
       
  3592 		if ( ! $revision = wp_get_post_revision( $revision_id ) )
       
  3593 			return new IXR_Error( 404, __( 'Invalid post ID' ) );
       
  3594 
       
  3595 		if ( wp_is_post_autosave( $revision ) )
       
  3596 			return new IXR_Error( 404, __( 'Invalid post ID' ) );
       
  3597 
       
  3598 		if ( ! $post = get_post( $revision->post_parent ) )
       
  3599 			return new IXR_Error( 404, __( 'Invalid post ID' ) );
       
  3600 
       
  3601 		if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
       
  3602 			return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
       
  3603 
       
  3604 		// Check if revisions are disabled.
       
  3605 		if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
       
  3606 			return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
       
  3607 
       
  3608 		$post = wp_restore_post_revision( $revision_id );
       
  3609 
       
  3610 		return (bool) $post;
       
  3611 	}
       
  3612 
  3172 	/* Blogger API functions.
  3613 	/* Blogger API functions.
  3173 	 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
  3614 	 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
  3174 	 */
  3615 	 */
  3175 
  3616 
  3176 	/**
  3617 	/**
  3202 		$struct = array(
  3643 		$struct = array(
  3203 			'isAdmin'  => $is_admin,
  3644 			'isAdmin'  => $is_admin,
  3204 			'url'      => get_option('home') . '/',
  3645 			'url'      => get_option('home') . '/',
  3205 			'blogid'   => '1',
  3646 			'blogid'   => '1',
  3206 			'blogName' => get_option('blogname'),
  3647 			'blogName' => get_option('blogname'),
  3207 			'xmlrpc'   => site_url( 'xmlrpc.php' )
  3648 			'xmlrpc'   => site_url( 'xmlrpc.php', 'rpc' ),
  3208 		);
  3649 		);
  3209 
  3650 
  3210 		return array($struct);
  3651 		return array($struct);
  3211 	}
  3652 	}
  3212 
  3653 
  3214 	 * Private function for retrieving a users blogs for multisite setups
  3655 	 * Private function for retrieving a users blogs for multisite setups
  3215 	 *
  3656 	 *
  3216 	 * @access protected
  3657 	 * @access protected
  3217 	 */
  3658 	 */
  3218 	function _multisite_getUsersBlogs($args) {
  3659 	function _multisite_getUsersBlogs($args) {
  3219 		global $current_blog;
  3660 		$current_blog = get_blog_details();
       
  3661 
  3220 		$domain = $current_blog->domain;
  3662 		$domain = $current_blog->domain;
  3221 		$path = $current_blog->path . 'xmlrpc.php';
  3663 		$path = $current_blog->path . 'xmlrpc.php';
  3222 		$protocol = is_ssl() ? 'https' : 'http';
  3664 
  3223 
  3665 		$rpc = new IXR_Client( set_url_scheme( "http://{$domain}{$path}" ) );
  3224 		$rpc = new IXR_Client("$protocol://{$domain}{$path}");
       
  3225 		$rpc->query('wp.getUsersBlogs', $args[1], $args[2]);
  3666 		$rpc->query('wp.getUsersBlogs', $args[1], $args[2]);
  3226 		$blogs = $rpc->getResponse();
  3667 		$blogs = $rpc->getResponse();
  3227 
  3668 
  3228 		if ( isset($blogs['faultCode']) )
  3669 		if ( isset($blogs['faultCode']) )
  3229 			return new IXR_Error($blogs['faultCode'], $blogs['faultString']);
  3670 			return new IXR_Error($blogs['faultCode'], $blogs['faultString']);
  3292 		$password  = $args[3];
  3733 		$password  = $args[3];
  3293 
  3734 
  3294 		if ( !$user = $this->login($username, $password) )
  3735 		if ( !$user = $this->login($username, $password) )
  3295 			return $this->error;
  3736 			return $this->error;
  3296 
  3737 
  3297 		$post_data = wp_get_single_post($post_ID, ARRAY_A);
  3738 		$post_data = get_post($post_ID, ARRAY_A);
  3298 		if ( ! $post_data )
  3739 		if ( ! $post_data )
  3299 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  3740 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  3300 
  3741 
  3301 		if ( !current_user_can( 'edit_post', $post_ID ) )
  3742 		if ( !current_user_can( 'edit_post', $post_ID ) )
  3302 			return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
  3743 			return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
  3379 
  3820 
  3380 		return $recent_posts;
  3821 		return $recent_posts;
  3381 	}
  3822 	}
  3382 
  3823 
  3383 	/**
  3824 	/**
  3384 	 * Retrieve blog_filename content.
  3825 	 * Deprecated.
  3385 	 *
  3826 	 *
  3386 	 * @since 1.5.0
  3827 	 * @since 1.5.0
  3387 	 *
  3828 	 * @deprecated 3.5.0
  3388 	 * @param array $args Method parameters.
       
  3389 	 * @return string
       
  3390 	 */
  3829 	 */
  3391 	function blogger_getTemplate($args) {
  3830 	function blogger_getTemplate($args) {
  3392 
  3831 		return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) );
  3393 		$this->escape($args);
  3832 	}
  3394 
  3833 
  3395 		$blog_ID    = (int) $args[1];
  3834 	/**
  3396 		$username = $args[2];
  3835 	 * Deprecated.
  3397 		$password  = $args[3];
       
  3398 		$template   = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */
       
  3399 
       
  3400 		if ( !$user = $this->login($username, $password) )
       
  3401 			return $this->error;
       
  3402 
       
  3403 		do_action('xmlrpc_call', 'blogger.getTemplate');
       
  3404 
       
  3405 		if ( !current_user_can('edit_themes') )
       
  3406 			return new IXR_Error(401, __('Sorry, this user cannot edit the template.'));
       
  3407 
       
  3408 		/* warning: here we make the assumption that the blog's URL is on the same server */
       
  3409 		$filename = get_option('home') . '/';
       
  3410 		$filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
       
  3411 
       
  3412 		$f = fopen($filename, 'r');
       
  3413 		$content = fread($f, filesize($filename));
       
  3414 		fclose($f);
       
  3415 
       
  3416 		/* so it is actually editable with a windows/mac client */
       
  3417 		// FIXME: (or delete me) do we really want to cater to bad clients at the expense of good ones by BEEPing up their line breaks? commented. $content = str_replace("\n", "\r\n", $content);
       
  3418 
       
  3419 		return $content;
       
  3420 	}
       
  3421 
       
  3422 	/**
       
  3423 	 * Updates the content of blog_filename.
       
  3424 	 *
  3836 	 *
  3425 	 * @since 1.5.0
  3837 	 * @since 1.5.0
  3426 	 *
  3838 	 * @deprecated 3.5.0
  3427 	 * @param array $args Method parameters.
       
  3428 	 * @return bool True when done.
       
  3429 	 */
  3839 	 */
  3430 	function blogger_setTemplate($args) {
  3840 	function blogger_setTemplate($args) {
  3431 
  3841 		return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) );
  3432 		$this->escape($args);
       
  3433 
       
  3434 		$blog_ID    = (int) $args[1];
       
  3435 		$username = $args[2];
       
  3436 		$password  = $args[3];
       
  3437 		$content    = $args[4];
       
  3438 		$template   = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */
       
  3439 
       
  3440 		if ( !$user = $this->login($username, $password) )
       
  3441 			return $this->error;
       
  3442 
       
  3443 		do_action('xmlrpc_call', 'blogger.setTemplate');
       
  3444 
       
  3445 		if ( !current_user_can('edit_themes') )
       
  3446 			return new IXR_Error(401, __('Sorry, this user cannot edit the template.'));
       
  3447 
       
  3448 		/* warning: here we make the assumption that the blog's URL is on the same server */
       
  3449 		$filename = get_option('home') . '/';
       
  3450 		$filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename);
       
  3451 
       
  3452 		if ($f = fopen($filename, 'w+')) {
       
  3453 			fwrite($f, $content);
       
  3454 			fclose($f);
       
  3455 		} else {
       
  3456 			return new IXR_Error(500, __('Either the file is not writable, or something wrong happened. The file has not been updated.'));
       
  3457 		}
       
  3458 
       
  3459 		return true;
       
  3460 	}
  3842 	}
  3461 
  3843 
  3462 	/**
  3844 	/**
  3463 	 * Create new post.
  3845 	 * Create new post.
  3464 	 *
  3846 	 *
  3481 			return $this->error;
  3863 			return $this->error;
  3482 
  3864 
  3483 		do_action('xmlrpc_call', 'blogger.newPost');
  3865 		do_action('xmlrpc_call', 'blogger.newPost');
  3484 
  3866 
  3485 		$cap = ($publish) ? 'publish_posts' : 'edit_posts';
  3867 		$cap = ($publish) ? 'publish_posts' : 'edit_posts';
  3486 		if ( !current_user_can($cap) )
  3868 		if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || !current_user_can($cap) )
  3487 			return new IXR_Error(401, __('Sorry, you are not allowed to post on this site.'));
  3869 			return new IXR_Error(401, __('Sorry, you are not allowed to post on this site.'));
  3488 
  3870 
  3489 		$post_status = ($publish) ? 'publish' : 'draft';
  3871 		$post_status = ($publish) ? 'publish' : 'draft';
  3490 
  3872 
  3491 		$post_author = $user->ID;
  3873 		$post_author = $user->ID;
  3534 		if ( !$user = $this->login($username, $password) )
  3916 		if ( !$user = $this->login($username, $password) )
  3535 			return $this->error;
  3917 			return $this->error;
  3536 
  3918 
  3537 		do_action('xmlrpc_call', 'blogger.editPost');
  3919 		do_action('xmlrpc_call', 'blogger.editPost');
  3538 
  3920 
  3539 		$actual_post = wp_get_single_post($post_ID,ARRAY_A);
  3921 		$actual_post = get_post($post_ID,ARRAY_A);
  3540 
  3922 
  3541 		if ( !$actual_post || $actual_post['post_type'] != 'post' )
  3923 		if ( !$actual_post || $actual_post['post_type'] != 'post' )
  3542 			return new IXR_Error(404, __('Sorry, no such post.'));
  3924 			return new IXR_Error(404, __('Sorry, no such post.'));
  3543 
  3925 
  3544 		$this->escape($actual_post);
  3926 		$this->escape($actual_post);
  3588 		if ( !$user = $this->login($username, $password) )
  3970 		if ( !$user = $this->login($username, $password) )
  3589 			return $this->error;
  3971 			return $this->error;
  3590 
  3972 
  3591 		do_action('xmlrpc_call', 'blogger.deletePost');
  3973 		do_action('xmlrpc_call', 'blogger.deletePost');
  3592 
  3974 
  3593 		$actual_post = wp_get_single_post($post_ID,ARRAY_A);
  3975 		$actual_post = get_post($post_ID,ARRAY_A);
  3594 
  3976 
  3595 		if ( !$actual_post || $actual_post['post_type'] != 'post' )
  3977 		if ( !$actual_post || $actual_post['post_type'] != 'post' )
  3596 			return new IXR_Error(404, __('Sorry, no such post.'));
  3978 			return new IXR_Error(404, __('Sorry, no such post.'));
  3597 
  3979 
  3598 		if ( !current_user_can('delete_post', $post_ID) )
  3980 		if ( !current_user_can('delete_post', $post_ID) )
  3696 				$cap = 'edit_posts';
  4078 				$cap = 'edit_posts';
  3697 			$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
  4079 			$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
  3698 			$post_type = 'post';
  4080 			$post_type = 'post';
  3699 		}
  4081 		}
  3700 
  4082 
       
  4083 		if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) )
       
  4084 			return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts on this site.' ) );
  3701 		if ( !current_user_can( $cap ) )
  4085 		if ( !current_user_can( $cap ) )
  3702 			return new IXR_Error( 401, $error_message );
  4086 			return new IXR_Error( 401, $error_message );
  3703 
  4087 
  3704 		// Check for a valid post format if one was given
  4088 		// Check for a valid post format if one was given
  3705 		if ( isset( $content_struct['wp_post_format'] ) ) {
  4089 		if ( isset( $content_struct['wp_post_format'] ) ) {
  3728 			$menu_order = $content_struct['wp_page_order'];
  4112 			$menu_order = $content_struct['wp_page_order'];
  3729 
  4113 
  3730 		$post_author = $user->ID;
  4114 		$post_author = $user->ID;
  3731 
  4115 
  3732 		// If an author id was provided then use it instead.
  4116 		// If an author id was provided then use it instead.
  3733 		if ( isset($content_struct['wp_author_id']) && ($user->ID != $content_struct['wp_author_id']) ) {
  4117 		if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) {
  3734 			switch ( $post_type ) {
  4118 			switch ( $post_type ) {
  3735 				case "post":
  4119 				case "post":
  3736 					if ( !current_user_can('edit_others_posts') )
  4120 					if ( !current_user_can( 'edit_others_posts' ) )
  3737 						return(new IXR_Error(401, __('You are not allowed to post as this user')));
  4121 						return( new IXR_Error( 401, __( 'You are not allowed to create posts as this user.' ) ) );
  3738 					break;
  4122 					break;
  3739 				case "page":
  4123 				case "page":
  3740 					if ( !current_user_can('edit_others_pages') )
  4124 					if ( !current_user_can( 'edit_others_pages' ) )
  3741 						return(new IXR_Error(401, __('You are not allowed to create pages as this user')));
  4125 						return( new IXR_Error( 401, __( 'You are not allowed to create pages as this user.' ) ) );
  3742 					break;
  4126 					break;
  3743 				default:
  4127 				default:
  3744 					return(new IXR_Error(401, __('Invalid post type')));
  4128 					return( new IXR_Error( 401, __( 'Invalid post type' ) ) );
  3745 					break;
  4129 					break;
  3746 			}
  4130 			}
  3747 			$author = get_userdata( $content_struct['wp_author_id'] );
  4131 			$author = get_userdata( $content_struct['wp_author_id'] );
  3748 			if ( ! $author )
  4132 			if ( ! $author )
  3749 				return new IXR_Error( 404, __( 'Invalid author ID.' ) );
  4133 				return new IXR_Error( 404, __( 'Invalid author ID.' ) );
  3900 		$this->attach_uploads( $post_ID, $post_content );
  4284 		$this->attach_uploads( $post_ID, $post_content );
  3901 
  4285 
  3902 		// Handle post formats if assigned, value is validated earlier
  4286 		// Handle post formats if assigned, value is validated earlier
  3903 		// in this function
  4287 		// in this function
  3904 		if ( isset( $content_struct['wp_post_format'] ) )
  4288 		if ( isset( $content_struct['wp_post_format'] ) )
  3905 			wp_set_post_terms( $post_ID, array( 'post-format-' . $content_struct['wp_post_format'] ), 'post_format' );
  4289 			set_post_format( $post_ID, $content_struct['wp_post_format'] );
  3906 
  4290 
  3907 		$post_ID = wp_insert_post( $postdata, true );
  4291 		$post_ID = wp_insert_post( $postdata, true );
  3908 		if ( is_wp_error( $post_ID ) )
  4292 		if ( is_wp_error( $post_ID ) )
  3909 			return new IXR_Error(500, $post_ID->get_error_message());
  4293 			return new IXR_Error(500, $post_ID->get_error_message());
  3910 
  4294 
  3978 		if ( ! $user = $this->login($username, $password) )
  4362 		if ( ! $user = $this->login($username, $password) )
  3979 			return $this->error;
  4363 			return $this->error;
  3980 
  4364 
  3981 		do_action('xmlrpc_call', 'metaWeblog.editPost');
  4365 		do_action('xmlrpc_call', 'metaWeblog.editPost');
  3982 
  4366 
  3983 		$postdata = wp_get_single_post( $post_ID, ARRAY_A );
  4367 		$postdata = get_post( $post_ID, ARRAY_A );
  3984 
  4368 
  3985 		// If there is no post data for the give post id, stop
  4369 		// If there is no post data for the give post id, stop
  3986 		// now and return an error. Other wise a new post will be
  4370 		// now and return an error. Other wise a new post will be
  3987 		// created (which was the old behavior).
  4371 		// created (which was the old behavior).
  3988 		if ( ! $postdata || empty( $postdata[ 'ID' ] ) )
  4372 		if ( ! $postdata || empty( $postdata[ 'ID' ] ) )
  4217 		$this->attach_uploads( $ID, $post_content );
  4601 		$this->attach_uploads( $ID, $post_content );
  4218 
  4602 
  4219 		// Handle post formats if assigned, validation is handled
  4603 		// Handle post formats if assigned, validation is handled
  4220 		// earlier in this function
  4604 		// earlier in this function
  4221 		if ( isset( $content_struct['wp_post_format'] ) )
  4605 		if ( isset( $content_struct['wp_post_format'] ) )
  4222 			wp_set_post_terms( $post_ID, array( 'post-format-' . $content_struct['wp_post_format'] ), 'post_format' );
  4606 			set_post_format( $post_ID, $content_struct['wp_post_format'] );
  4223 
  4607 
  4224 		do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args );
  4608 		do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args );
  4225 
  4609 
  4226 		return true;
  4610 		return true;
  4227 	}
  4611 	}
  4243 		$password   = $args[2];
  4627 		$password   = $args[2];
  4244 
  4628 
  4245 		if ( !$user = $this->login($username, $password) )
  4629 		if ( !$user = $this->login($username, $password) )
  4246 			return $this->error;
  4630 			return $this->error;
  4247 
  4631 
  4248 		$postdata = wp_get_single_post($post_ID, ARRAY_A);
  4632 		$postdata = get_post($post_ID, ARRAY_A);
  4249 		if ( ! $postdata )
  4633 		if ( ! $postdata )
  4250 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  4634 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  4251 
  4635 
  4252 		if ( !current_user_can( 'edit_post', $post_ID ) )
  4636 		if ( !current_user_can( 'edit_post', $post_ID ) )
  4253 			return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
  4637 			return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
  4378 		$posts_list = wp_get_recent_posts( $query );
  4762 		$posts_list = wp_get_recent_posts( $query );
  4379 
  4763 
  4380 		if ( !$posts_list )
  4764 		if ( !$posts_list )
  4381 			return array();
  4765 			return array();
  4382 
  4766 
       
  4767 		$struct = array();
  4383 		foreach ($posts_list as $entry) {
  4768 		foreach ($posts_list as $entry) {
  4384 			if ( !current_user_can( 'edit_post', $entry['ID'] ) )
  4769 			if ( !current_user_can( 'edit_post', $entry['ID'] ) )
  4385 				continue;
  4770 				continue;
  4386 
  4771 
  4387 			$post_date = $this->_convert_date( $entry['post_date'] );
  4772 			$post_date = $this->_convert_date( $entry['post_date'] );
  4566 		if ( ! empty($upload['error']) ) {
  4951 		if ( ! empty($upload['error']) ) {
  4567 			$errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']);
  4952 			$errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']);
  4568 			return new IXR_Error(500, $errorString);
  4953 			return new IXR_Error(500, $errorString);
  4569 		}
  4954 		}
  4570 		// Construct the attachment array
  4955 		// Construct the attachment array
  4571 		// attach to post_id 0
       
  4572 		$post_id = 0;
  4956 		$post_id = 0;
       
  4957 		if ( ! empty( $data['post_id'] ) ) {
       
  4958 			$post_id = (int) $data['post_id'];
       
  4959 
       
  4960 			if ( ! current_user_can( 'edit_post', $post_id ) )
       
  4961 				return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
       
  4962 		}
  4573 		$attachment = array(
  4963 		$attachment = array(
  4574 			'post_title' => $name,
  4964 			'post_title' => $name,
  4575 			'post_content' => '',
  4965 			'post_content' => '',
  4576 			'post_type' => 'attachment',
  4966 			'post_type' => 'attachment',
  4577 			'post_parent' => $post_id,
  4967 			'post_parent' => $post_id,
  4765 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  5155 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  4766 
  5156 
  4767 		if ( !current_user_can('edit_post', $post_ID) )
  5157 		if ( !current_user_can('edit_post', $post_ID) )
  4768 			return new IXR_Error(401, __('Sorry, you cannot edit this post.'));
  5158 			return new IXR_Error(401, __('Sorry, you cannot edit this post.'));
  4769 
  5159 
       
  5160 		$catids = array();
  4770 		foreach ( $categories as $cat ) {
  5161 		foreach ( $categories as $cat ) {
  4771 			$catids[] = $cat['categoryId'];
  5162 			$catids[] = $cat['categoryId'];
  4772 		}
  5163 		}
  4773 
  5164 
  4774 		wp_set_post_categories($post_ID, $catids);
  5165 		wp_set_post_categories($post_ID, $catids);
  4822 
  5213 
  4823 		$post_ID = intval($args);
  5214 		$post_ID = intval($args);
  4824 
  5215 
  4825 		do_action('xmlrpc_call', 'mt.getTrackbackPings');
  5216 		do_action('xmlrpc_call', 'mt.getTrackbackPings');
  4826 
  5217 
  4827 		$actual_post = wp_get_single_post($post_ID, ARRAY_A);
  5218 		$actual_post = get_post($post_ID, ARRAY_A);
  4828 
  5219 
  4829 		if ( !$actual_post )
  5220 		if ( !$actual_post )
  4830 			return new IXR_Error(404, __('Sorry, no such post.'));
  5221 			return new IXR_Error(404, __('Sorry, no such post.'));
  4831 
  5222 
  4832 		$comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
  5223 		$comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
  4869 		if ( !$user = $this->login($username, $password) )
  5260 		if ( !$user = $this->login($username, $password) )
  4870 			return $this->error;
  5261 			return $this->error;
  4871 
  5262 
  4872 		do_action('xmlrpc_call', 'mt.publishPost');
  5263 		do_action('xmlrpc_call', 'mt.publishPost');
  4873 
  5264 
  4874 		$postdata = wp_get_single_post($post_ID, ARRAY_A);
  5265 		$postdata = get_post($post_ID, ARRAY_A);
  4875 		if ( ! $postdata )
  5266 		if ( ! $postdata )
  4876 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  5267 			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
  4877 
  5268 
  4878 		if ( !current_user_can('publish_posts') || !current_user_can('edit_post', $post_ID) )
  5269 		if ( !current_user_can('publish_posts') || !current_user_can('edit_post', $post_ID) )
  4879 			return new IXR_Error(401, __('Sorry, you cannot publish this post.'));
  5270 			return new IXR_Error(401, __('Sorry, you cannot publish this post.'));
  4932 		} elseif ( preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) {
  5323 		} elseif ( preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) {
  4933 			// the path defines the post_ID (archives/p/XXXX)
  5324 			// the path defines the post_ID (archives/p/XXXX)
  4934 			$blah = explode('/', $match[0]);
  5325 			$blah = explode('/', $match[0]);
  4935 			$post_ID = (int) $blah[1];
  5326 			$post_ID = (int) $blah[1];
  4936 			$way = 'from the path';
  5327 			$way = 'from the path';
  4937 		} elseif ( preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) {
  5328 		} elseif ( isset( $urltest['query'] ) && preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) {
  4938 			// the querystring defines the post_ID (?p=XXXX)
  5329 			// the querystring defines the post_ID (?p=XXXX)
  4939 			$blah = explode('=', $match[0]);
  5330 			$blah = explode('=', $match[0]);
  4940 			$post_ID = (int) $blah[1];
  5331 			$post_ID = (int) $blah[1];
  4941 			$way = 'from the querystring';
  5332 			$way = 'from the querystring';
  4942 		} elseif ( isset($urltest['fragment']) ) {
  5333 		} elseif ( isset($urltest['fragment']) ) {
  4992 		$linea = apply_filters('pre_remote_source', $linea, $pagelinkedto);
  5383 		$linea = apply_filters('pre_remote_source', $linea, $pagelinkedto);
  4993 
  5384 
  4994 		// Work around bug in strip_tags():
  5385 		// Work around bug in strip_tags():
  4995 		$linea = str_replace('<!DOC', '<DOC', $linea);
  5386 		$linea = str_replace('<!DOC', '<DOC', $linea);
  4996 		$linea = preg_replace( '/[\s\r\n\t]+/', ' ', $linea ); // normalize spaces
  5387 		$linea = preg_replace( '/[\s\r\n\t]+/', ' ', $linea ); // normalize spaces
  4997 		$linea = preg_replace( "/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea );
  5388 		$linea = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea );
  4998 
  5389 
  4999 		preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle);
  5390 		preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle);
  5000 		$title = $matchtitle[1];
  5391 		$title = $matchtitle[1];
  5001 		if ( empty( $title ) )
  5392 		if ( empty( $title ) )
  5002 			return new IXR_Error(32, __('We cannot find a title on that page.'));
  5393 			return new IXR_Error(32, __('We cannot find a title on that page.'));
  5083 		if ( !$post_ID ) {
  5474 		if ( !$post_ID ) {
  5084 			// We aren't sure that the resource is available and/or pingback enabled
  5475 			// We aren't sure that the resource is available and/or pingback enabled
  5085 	  		return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.'));
  5476 	  		return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.'));
  5086 		}
  5477 		}
  5087 
  5478 
  5088 		$actual_post = wp_get_single_post($post_ID, ARRAY_A);
  5479 		$actual_post = get_post($post_ID, ARRAY_A);
  5089 
  5480 
  5090 		if ( !$actual_post ) {
  5481 		if ( !$actual_post ) {
  5091 			// No such post = resource not found
  5482 			// No such post = resource not found
  5092 	  		return new IXR_Error(32, __('The specified target URL does not exist.'));
  5483 	  		return new IXR_Error(32, __('The specified target URL does not exist.'));
  5093 		}
  5484 		}