- 42A3D6BAF466D997F62B27BD07F1DCE43B164E39091CB05CFC9ECF20E5DA094EBF46F4F297DA4040E2B3DF352CA36D45537EB7F5BAA96758CB3773A7E9D40BD7
+ 400E9FA6918EB20554548892FE6ADA0940A73B906CFF113644FE48C40C349430D258B06FD3D232405558874C67B09DE631D9D56740C931A7E5C0A37463E7687A
mp-wp/wp-includes/classes.php
(1444 . 140)(1444 . 4)
35267 }
35268 }
35269
35270 /**
35271 * Send XML response back to AJAX request.
35272 *
35273 * @package WordPress
35274 * @since 2.1.0
35275 */
35276 class WP_Ajax_Response {
35277 /**
35278 * Store XML responses to send.
35279 *
35280 * @since 2.1.0
35281 * @var array
35282 * @access private
35283 */
35284 var $responses = array();
35285
35286 /**
35287 * PHP4 Constructor - Passes args to {@link WP_Ajax_Response::add()}.
35288 *
35289 * @since 2.1.0
35290 * @see WP_Ajax_Response::add()
35291 *
35292 * @param string|array $args Optional. Will be passed to add() method.
35293 * @return WP_Ajax_Response
35294 */
35295 function WP_Ajax_Response( $args = '' ) {
35296 if ( !empty($args) )
35297 $this->add($args);
35298 }
35299
35300 /**
35301 * Append to XML response based on given arguments.
35302 *
35303 * The arguments that can be passed in the $args parameter are below. It is
35304 * also possible to pass a WP_Error object in either the 'id' or 'data'
35305 * argument. The parameter isn't actually optional, content should be given
35306 * in order to send the correct response.
35307 *
35308 * 'what' argument is a string that is the XMLRPC response type.
35309 * 'action' argument is a boolean or string that acts like a nonce.
35310 * 'id' argument can be WP_Error or an integer.
35311 * 'old_id' argument is false by default or an integer of the previous ID.
35312 * 'position' argument is an integer or a string with -1 = top, 1 = bottom,
35313 * html ID = after, -html ID = before.
35314 * 'data' argument is a string with the content or message.
35315 * 'supplemental' argument is an array of strings that will be children of
35316 * the supplemental element.
35317 *
35318 * @since 2.1.0
35319 *
35320 * @param string|array $args Override defaults.
35321 * @return string XML response.
35322 */
35323 function add( $args = '' ) {
35324 $defaults = array(
35325 'what' => 'object', 'action' => false,
35326 'id' => '0', 'old_id' => false,
35327 'position' => 1,
35328 'data' => '', 'supplemental' => array()
35329 );
35330
35331 $r = wp_parse_args( $args, $defaults );
35332 extract( $r, EXTR_SKIP );
35333 $position = preg_replace( '/[^a-z0-9:_-]/i', '', $position );
35334
35335 if ( is_wp_error($id) ) {
35336 $data = $id;
35337 $id = 0;
35338 }
35339
35340 $response = '';
35341 if ( is_wp_error($data) ) {
35342 foreach ( (array) $data->get_error_codes() as $code ) {
35343 $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
35344 if ( !$error_data = $data->get_error_data($code) )
35345 continue;
35346 $class = '';
35347 if ( is_object($error_data) ) {
35348 $class = ' class="' . get_class($error_data) . '"';
35349 $error_data = get_object_vars($error_data);
35350 }
35351
35352 $response .= "<wp_error_data code='$code'$class>";
35353
35354 if ( is_scalar($error_data) ) {
35355 $response .= "<![CDATA[$error_data]]>";
35356 } elseif ( is_array($error_data) ) {
35357 foreach ( $error_data as $k => $v )
35358 $response .= "<$k><![CDATA[$v]]></$k>";
35359 }
35360
35361 $response .= "</wp_error_data>";
35362 }
35363 } else {
35364 $response = "<response_data><![CDATA[$data]]></response_data>";
35365 }
35366
35367 $s = '';
35368 if ( is_array($supplemental) ) {
35369 foreach ( $supplemental as $k => $v )
35370 $s .= "<$k><![CDATA[$v]]></$k>";
35371 $s = "<supplemental>$s</supplemental>";
35372 }
35373
35374 if ( false === $action )
35375 $action = $_POST['action'];
35376
35377 $x = '';
35378 $x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action
35379 $x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";
35380 $x .= $response;
35381 $x .= $s;
35382 $x .= "</$what>";
35383 $x .= "</response>";
35384
35385 $this->responses[] = $x;
35386 return $x;
35387 }
35388
35389 /**
35390 * Display XML formatted responses.
35391 *
35392 * Sets the content type header to text/xml.
35393 *
35394 * @since 2.1.0
35395 */
35396 function send() {
35397 header('Content-Type: text/xml');
35398 echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
35399 foreach ( (array) $this->responses as $response )
35400 echo $response;
35401 echo '</wp_ajax>';
35402 die();
35403 }
35404 }
35405
35406 ?>