Пример #1
0
 /**
  * Ajax method that is used by the VideoPress uploader to get a token to upload a file to the wpcom api.
  *
  * @return void
  */
 public function wp_ajax_videopress_get_upload_token()
 {
     $options = VideoPress_Options::get_options();
     $args = array('method' => 'POST');
     $endpoint = "sites/{$options['shadow_blog_id']}/media/token";
     $result = Jetpack_Client::wpcom_json_api_request_as_blog($endpoint, Jetpack_Client::WPCOM_JSON_API_VERSION, $args);
     if (is_wp_error($result)) {
         wp_send_json_error(array('message' => __('Could not obtain a VideoPress upload token. Please try again later.', 'jetpack')));
         return;
     }
     $response = json_decode($result['body'], true);
     if (empty($response['upload_token'])) {
         wp_send_json_error(array('message' => __('Could not obtain a VideoPress upload token. Please try again later.', 'jetpack')));
         return;
     }
     $title = sanitize_title(basename($_POST['filename']));
     $response['upload_action_url'] = videopress_make_media_upload_path($options['shadow_blog_id']);
     $response['upload_media_id'] = videopress_create_new_media_item($title);
     wp_send_json_success($response);
 }
 /**
  * This is used by the WPCOM VideoPress uploader in order to create a media item with
  * specific meta data about an uploaded file. After this, the transcoding session will
  * update the meta information via the xmlrpc_update_videopress_info() method.
  *
  * Note: This method technically handles the creation of multiple media objects, though
  * in practice this is never done.
  *
  * @param array $media
  *
  * @return array
  */
 public function create_media_item($media)
 {
     $created_items = array();
     foreach ($media as $media_item) {
         $media_id = videopress_create_new_media_item(sanitize_title(basename($media_item['url'])));
         wp_update_attachment_metadata($media_id, array('original' => array('url' => $media_item['url'])));
         $created_items[] = array('id' => $media_id, 'post' => get_post($media_id));
     }
     return array('media' => $created_items);
 }