/** * Add pending video ID and uploaded filename to the _brightcove_pending_videos option * * @param $video_id * @param string $filename * * @return boolean status of update_option */ public static function add_pending_upload($video_id, $filename = '') { $video_id = BC_Utility::sanitize_and_generate_meta_video_id($video_id); BC_Utility::remove_pending_uploads(); $pending_videos = get_option('_brightcove_pending_videos', array()); $pending_videos[$video_id] = array('filename' => $filename, 'added' => time()); return update_option('_brightcove_pending_videos', $pending_videos); }
/** * 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; }