コード例 #1
0
 /**
  * Take an uploaded file, and a supplied name and create a video ID and
  * ingestion request for them.
  * @param $name video name
  * @return bool|string|WP_Error
  */
 public function process_uploaded_video($files, $account_hash, $tags, $name)
 {
     global $bc_accounts;
     $status = array('upload' => 'fail', 'ingest' => 'fail', 'url' => '');
     $account = $bc_accounts->get_account_by_hash($account_hash);
     if (!$account) {
         return new WP_Error('invalid-account', esc_html__('Invalid account', 'brightcove'));
     }
     if (isset($files) && isset($files['file'])) {
         $cms_api = $this->cms_api;
         // check that file is supported by WP
         if ($this->check_allowed_file($files['file']) === false) {
             $error_message = esc_html__('Video type is not supported', 'brightcove');
             BC_Logging::log(sprintf('VIDEO UPLOAD: %s', $error_message));
             return new WP_Error('video_upload_error', $error_message);
         }
         $uploaded = wp_handle_upload($files['file'], array('test_form' => false));
         if (isset($uploaded['error'])) {
             $error_message = esc_html__($uploaded['error'], 'brightcove');
             BC_Logging::log(sprintf('VIDEO UPLOAD ERROR: %s', $error_message));
             return new WP_Error('video_upload_error', $error_message);
         } else {
             $status['upload'] = 'success';
             $status['url'] = $uploaded['url'];
         }
         $tags_array = $this->process_tags($tags);
         $data = array();
         if (false !== $tags_array) {
             $data['tags'] = $tags_array;
         }
         $video_id_creation_result = $cms_api->video_add($name, $data);
         if (false === $video_id_creation_result) {
             return new WP_Error(esc_html__('Unable to create a video on brightcove side', 'brightcove'));
         }
         if (is_wp_error($video_id_creation_result)) {
             return $video_id_creation_result;
         }
         if (isset($video_id_creation_result['created_at'])) {
             $video_id = BC_Utility::sanitize_and_generate_meta_video_id($video_id_creation_result['id']);
             $status['video_id'] = $video_id_creation_result['id'];
             BC_Utility::add_pending_upload($video_id, $uploaded['file']);
             $video_ingestion_request_result = $cms_api->video_upload($video_id_creation_result['id'], $uploaded['url']);
             if (is_array($video_ingestion_request_result) && isset($video_ingestion_request_result['id'])) {
                 $status['ingest'] = 'success';
                 $status['ingestId'] = $video_ingestion_request_result['id'];
             }
             $status['videoDetails'] = $video_id_creation_result;
         }
     }
     return $status;
 }
コード例 #2
0
 public static function get_video_playlist_dates($type, $account_id = false)
 {
     if (!in_array($type, array('videos', 'playlists'))) {
         return false;
     }
     $key = '_brightcove_dates_' . $type;
     $all_dates = get_option($key);
     if (is_array($all_dates)) {
         if ($account_id) {
             $id = BC_Utility::sanitize_and_generate_meta_video_id($account_id);
             if (isset($all_dates[$id])) {
                 return $all_dates[$id];
             } else {
                 return array();
                 // No dates empty array
             }
         } else {
             return is_array($all_dates) ? $all_dates : array();
         }
     }
     return array();
 }
コード例 #3
0
 /**
  * We receive a post with JSON (nothing in $_POST)
  * $_GET['id'] must contain the video ID
  * $_GET['auth'] must contain the anti spoof hash.
  */
 public function ingest_callback()
 {
     $json = file_get_contents('php://input');
     $decoded = json_decode($json, true);
     if (!isset($decoded['entity']) || !isset($_GET['id']) || !isset($_GET['auth']) || "SUCCESS" !== $decoded['status']) {
         exit;
     }
     $video_id = BC_Utility::sanitize_and_generate_meta_video_id($_GET['id']);
     $valid_auth = BC_Utility::get_auth_key_for_id($video_id);
     if (BC_Utility::sanitize_and_generate_meta_video_id($decoded['entity']) !== $video_id) {
         // We get lots of callbacks so we want to make sure that it's not
         // one of the transcodes that has completed, but rather this video.
         exit;
     }
     if ($valid_auth !== $_GET['auth']) {
         // Someone was spoofing callbacks?
         exit;
     }
     BC_Utility::remove_pending_uploads($video_id);
     // @todo: Set video uploaded state as complete.
     $this->trigger_background_fetch();
     exit;
 }
コード例 #4
0
 public function sort_api_response($playlists)
 {
     foreach ($playlists as $key => $playlist) {
         $id = BC_Utility::sanitize_and_generate_meta_video_id($playlist['id']);
         $playlists[$id] = $playlist;
         unset($playlists[$key]);
     }
     ksort($playlists);
     return $playlists;
 }
コード例 #5
0
 /**
  * Accepts a video ID and checks to see if there is a record in WordPress. Returns the post object on success and false on failure.
  *
  * @param $video_id
  *
  * @return bool|WP_Post
  */
 public function get_video_by_id($video_id)
 {
     $video_id = BC_Utility::sanitize_and_generate_meta_video_id($video_id);
     $existing_video = new WP_Query(array('meta_key' => '_brightcove_video_id', 'meta_value' => $video_id, 'post_type' => $this->video_cpt, 'posts_per_page' => 1, 'update_post_term_cache' => false));
     if (!$existing_video->have_posts()) {
         return false;
     }
     return end($existing_video->posts);
 }
コード例 #6
0
 public function sort_api_response($videos)
 {
     foreach ($videos as $key => $video) {
         $id = BC_Utility::sanitize_and_generate_meta_video_id($video['id']);
         $videos[$id] = $video;
         unset($videos[$key]);
     }
     ksort($videos);
     return $videos;
 }