Ticket #15151: patch-15151-1.diff

File patch-15151-1.diff, 3.8 KB (added by koke, 3 years ago)

Proposed patch for getMediaItem/getMediaLibrary

  • wp-includes/class.wp-xmlrpc-server.php

    diff --git a/wp-includes/class.wp-xmlrpc-server.php b/wp-includes/class.wp-xmlrpc-server.php
    index 6aa9aa4..9487a93 100644
    a b class wp_xmlrpc_server extends IXR_Server { 
    6161                        'wp.editComment'                => 'this:wp_editComment', 
    6262                        'wp.newComment'                 => 'this:wp_newComment', 
    6363                        'wp.getCommentStatusList' => 'this:wp_getCommentStatusList', 
     64                        'wp.getMediaItem'               => 'this:wp_getMediaItem', 
     65                        'wp.getMediaLibrary'    => 'this:wp_getMediaLibrary', 
    6466 
    6567                        // Blogger API 
    6668                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', 
    class wp_xmlrpc_server extends IXR_Server { 
    14461448                return $this->_getOptions($option_names); 
    14471449        } 
    14481450 
     1451        /** 
     1452         * Retrieve media item. 
     1453         * 
     1454         * @since unknown 
     1455         * 
     1456         * @param array $args Method parameters. 
     1457         * @return array 
     1458         */ 
     1459        function wp_getMediaItem($args) { 
     1460                $this->escape($args); 
     1461 
     1462                $blog_id                = (int) $args[0]; 
     1463                $username               = $args[1]; 
     1464                $password               = $args[2]; 
     1465                $attachment_id  = (int) $args[3]; 
     1466 
     1467                if ( !$user = $this->login($username, $password) ) 
     1468                        return $this->error; 
     1469 
     1470                if ( !current_user_can( 'upload_files' ) ) 
     1471                        return new IXR_Error( 403, __( 'You are not allowed to upload files on this site.' ) ); 
     1472 
     1473                do_action('xmlrpc_call', 'wp.getMediaItem'); 
     1474 
     1475                if ( ! $attachment = get_post($attachment_id) ) 
     1476                        return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); 
     1477 
     1478                // Format page date. 
     1479                $attachment_date = mysql2date("Ymd\TH:i:s", $attachment->post_date, false); 
     1480                $attachment_date_gmt = mysql2date("Ymd\TH:i:s", $attachment->post_date_gmt, false); 
     1481 
     1482                $link = wp_get_attachment_url($attachment->ID); 
     1483                $thumbnail_link = wp_get_attachment_thumb_url($attachment->ID); 
     1484 
     1485                $attachment_struct = array( 
     1486                        "date_created_gmt"              => new IXR_Date($attachment_date_gmt), 
     1487                        "parent"                                => $attachment->post_parent, 
     1488                        "link"                                  => $link, 
     1489                        "thumbnail"                             => $thumbnail_link, 
     1490                        "title"                                 => $attachment->post_title, 
     1491                        "caption"                               => $attachment->post_excerpt, 
     1492                        "description"                   => $attachment->post_content, 
     1493                        "metadata"                              => wp_get_attachment_metadata($attachment->ID), 
     1494                ); 
     1495 
     1496                return $attachment_struct; 
     1497        } 
     1498 
     1499        /** 
     1500         * Retrieve media library items. 
     1501         * 
     1502         * @since unknown 
     1503         * 
     1504         * @param array $args Method parameters. 
     1505         * @return array 
     1506         */ 
     1507        function wp_getMediaLibrary($args) { 
     1508                $raw_args = $args; 
     1509                $this->escape($args); 
     1510 
     1511                $blog_id        = (int) $args[0]; 
     1512                $username       = $args[1]; 
     1513                $password       = $args[2]; 
     1514                $struct         = $args[3]; 
     1515 
     1516                if ( !$user = $this->login($username, $password) ) 
     1517                        return $this->error; 
     1518 
     1519                if ( !current_user_can( 'upload_files' ) ) 
     1520                        return new IXR_Error( 401, __( 'Sorry, you cannot upload files.' ) ); 
     1521 
     1522                do_action('xmlrpc_call', 'wp.getMediaLibrary'); 
     1523 
     1524                $parent_id = ''; 
     1525                if ( isset($struct['parent_id']) ) 
     1526                        $parent_id = absint($struct['parent_id']); 
     1527 
     1528                $mime_type = ''; 
     1529                if ( isset($struct['mime_type']) ) 
     1530                        $mime_type = $struct['mime_type']; 
     1531 
     1532                $offset = 0; 
     1533                if ( isset($struct['offset']) ) 
     1534                        $offset = absint($struct['offset']); 
     1535 
     1536                $number = -1; 
     1537                if ( isset($struct['number']) ) 
     1538                        $number = absint($struct['number']); 
     1539 
     1540                $attachments = get_posts( array('post_type' => 'attachment', 'post_parent' => $parent_id, 'offset' => $offset, 'numberposts' => $number, 'post_mime_type' => $mime_type ) ); 
     1541                $num_attachments = count($attachments); 
     1542 
     1543                if ( ! $num_attachments ) 
     1544                        return array(); 
     1545 
     1546                $attachments_struct = array(); 
     1547 
     1548                for ( $i = 0; $i < $num_attachments; $i++ ) { 
     1549                        $attachment = wp_xmlrpc_server::wp_getMediaItem(array( 
     1550                                $raw_args[0], $raw_args[1], $raw_args[2], $attachments[$i]->ID, 
     1551                        )); 
     1552                        $attachments_struct[] = $attachment; 
     1553                } 
     1554 
     1555                return $attachments_struct; 
     1556        } 
     1557 
    14491558        /* Blogger API functions. 
    14501559         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/ 
    14511560         */