VideoPress_XMLRPC

VideoPress playback module markup generator.

Defined (1)

The class is defined in the following location(s).

/modules/videopress/class.videopress-xmlrpc.php  
  1. class VideoPress_XMLRPC { 
  2.  
  3. /** 
  4. * @var VideoPress_XMLRPC 
  5. **/ 
  6. private static $instance = null; 
  7.  
  8.  
  9. /** 
  10. * Private VideoPress_XMLRPC constructor. 
  11. * Use the VideoPress_XMLRPC::init() method to get an instance. 
  12. */ 
  13. private function __construct() { 
  14. add_filter( 'jetpack_xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); 
  15.  
  16. /** 
  17. * Initialize the VideoPress_XMLRPC and get back a singleton instance. 
  18. * @return VideoPress_XMLRPC 
  19. */ 
  20. public static function init() { 
  21. if ( is_null( self::$instance ) ) { 
  22. self::$instance = new VideoPress_XMLRPC; 
  23.  
  24. return self::$instance; 
  25.  
  26. /** 
  27. * Adds additional methods the WordPress xmlrpc API for handling VideoPress specific features 
  28. * @param array $methods 
  29. * @return array 
  30. */ 
  31. public function xmlrpc_methods( $methods ) { 
  32.  
  33. $methods['jetpack.createMediaItem'] = array( $this, 'create_media_item' ); 
  34. $methods['jetpack.updateVideoPressMediaItem'] = array( $this, 'update_videopress_media_item' ); 
  35. $methods['jetpack.updateVideoPressPosterImage'] = array( $this, 'update_poster_image' ); 
  36.  
  37. return $methods; 
  38.  
  39. /** 
  40. * This is used by the WPCOM VideoPress uploader in order to create a media item with 
  41. * specific meta data about an uploaded file. After this, the transcoding session will 
  42. * update the meta information via the update_videopress_media_item() method. 
  43. * Note: This method technically handles the creation of multiple media objects, though 
  44. * in practice this is never done. 
  45. * @param array $media 
  46. * @return array 
  47. */ 
  48. public function create_media_item( $media ) { 
  49. foreach ( $media as & $media_item ) { 
  50. $title = sanitize_title( basename( $media_item['url'] ) ); 
  51. $guid = isset( $media['guid'] ) ? $media['guid'] : null; 
  52.  
  53. $media_id = videopress_create_new_media_item( $title, $guid ); 
  54.  
  55. wp_update_attachment_metadata( $media_id, array( 
  56. 'original' => array( 
  57. 'url' => $media_item['url'],  
  58. ),  
  59. ) ); 
  60.  
  61. $media_item['post'] = get_post( $media_id ); 
  62.  
  63. return array( 'media' => $media ); 
  64.  
  65. /** 
  66. * @param array $request 
  67. * @return bool 
  68. */ 
  69. public function update_videopress_media_item( $request ) { 
  70.  
  71. $id = $request['post_id']; 
  72. $status = $request['status']; 
  73. $format = $request['format']; 
  74. $info = $request['info']; 
  75.  
  76. if ( ! $attachment = get_post( $id ) ) { 
  77. return false; 
  78.  
  79. $attachment->guid = $info['original']; 
  80.  
  81. wp_update_post( $attachment ); 
  82.  
  83. // Update the vp guid and set it to a direct meta property. 
  84. update_post_meta( $id, 'videopress_guid', $info['guid'] ); 
  85.  
  86. $meta = wp_get_attachment_metadata( $id ); 
  87.  
  88. $meta['width'] = $info['width']; 
  89. $meta['height'] = $info['height']; 
  90. $meta['original']['url'] = $info['original']; 
  91. $meta['videopress'] = $info; 
  92. $meta['videopress']['url'] = 'https://videopress.com/v/' . $info['guid']; 
  93.  
  94. // Update file statuses 
  95. $valid_formats = array( 'hd', 'ogg', 'mp4', 'dvd' ); 
  96. if ( in_array( $format, $valid_formats ) ) { 
  97. $meta['file_statuses'][ $format ] = $status; 
  98.  
  99. if ( ! get_post_meta( $id, '_thumbnail_id', true ) ) { 
  100. // Update the poster in the VideoPress info. 
  101. $thumbnail_id = videopress_download_poster_image( $info['poster'], $id ); 
  102.  
  103. if ( is_int( $thumbnail_id ) ) { 
  104. update_post_meta( $id, '_thumbnail_id', $thumbnail_id ); 
  105.  
  106. wp_update_attachment_metadata( $id, $meta ); 
  107.  
  108. videopress_update_meta_data( $id ); 
  109.  
  110. // update the meta to tell us that we're processing or complete 
  111. update_post_meta( $id, 'videopress_status', videopress_is_finished_processing( $id ) ? 'complete' : 'processing' ); 
  112.  
  113. return true; 
  114.  
  115. /** 
  116. * @param array $request 
  117. * @return bool 
  118. */ 
  119. public function update_poster_image( $request ) { 
  120.  
  121. $post_id = $request['post_id']; 
  122. $poster = $request['poster']; 
  123.  
  124. if ( ! $attachment = get_post( $post_id ) ) { 
  125. return false; 
  126.  
  127. // We add ssl => 1 to make sure that the videos.files.wordpress.com domain is parsed as photon. 
  128. $poster = apply_filters( 'jetpack_photon_url', $poster, array( 'ssl' => 1 ), 'https' ); 
  129.  
  130. $meta = wp_get_attachment_metadata( $post_id ); 
  131. $meta['videopress']['poster'] = $poster; 
  132. wp_update_attachment_metadata( $post_id, $meta ); 
  133.  
  134. // Update the poster in the VideoPress info. 
  135. $thumbnail_id = videopress_download_poster_image( $poster, $post_id ); 
  136.  
  137. if ( ! is_int( $thumbnail_id ) ) { 
  138. return false; 
  139.  
  140. update_post_meta( $post_id, '_thumbnail_id', $thumbnail_id ); 
  141.  
  142. return true;