コード例 #1
0
 public static function update_video_meta()
 {
     if (!wp_verify_nonce($_POST['nonce'], '_bc_ajax_search_nonce')) {
         return false;
     }
     if (!array_key_exists('update-metadata', $_POST)) {
         return false;
     }
     $video_id = BC_Utility::sanitize_id($_POST['video-id']);
     $api = new BC_CMS_API();
     $video = $api->video_get($video_id);
     $updated_data = array();
     foreach ($_POST as $key => $postdata) {
         echo $key;
         $updated_data = BC_Utility::sanitize_payload_item($postdata);
     }
     if (array_key_exists('video-related-url', $_POST)) {
         $video_related_url = esc_url_raw($_POST['video-related-url']);
         if (strlen($video_related_url)) {
             $updated_data['link'] = array_merge($video['link'], array('url' => $video_related_url));
         }
     }
     if (array_key_exists('video-related-text', $_POST)) {
         $updated_data['link'] = array_merge($video['link'], array('text' => sanitize_text_field($_POST['video-related-text'])));
     }
     if (array_key_exists('video-tags', $_POST)) {
         $tags = explode(',', $_POST['video-tags']);
         $tags = array_filter($tags, 'trim');
         $tags = array_filter($tags, 'sanitize_text_field');
         $updated_data['tags'] = array_merge($video['tags'], $tags);
     }
     $api->video_update($video_id, $updated_data);
 }
コード例 #2
0
 /**
  * Function for processing a callback notification from Brightcove
  *
  * Valid callback URI: /wp-admin/admin-post.php?bc_auth=4455f75b
  * Valid callback JSON:
  * {"timestamp":1427307045995,"account_id":"4089003419001","event":"video-change","video":"4133902975001","version":0}
  **/
 public function video_notification()
 {
     if (!isset($_GET['bc_auth'])) {
         return;
     }
     $auth = $_GET['bc_auth'];
     $json = file_get_contents('php://input');
     $decoded = json_decode($json, true);
     if (!is_array($decoded)) {
         return;
     }
     if (!isset($decoded['account_id']) || !isset($decoded['video'])) {
         return;
     }
     $account_id = BC_Utility::sanitize_id($decoded['account_id']);
     $valid_auth = BC_Utility::get_auth_key_for_id($account_id);
     if ($valid_auth !== $auth) {
         // Someone was spoofing callbacks?
         return;
     }
     $video_id = BC_Utility::sanitize_id($decoded['video']);
     if (!$video_id) {
         wp_send_json_error('missing video id');
         // Some sort of error occurred with the callback and we have no video_id.
     }
     global $bc_accounts;
     if (!$bc_accounts->set_current_account_by_id($account_id)) {
         wp_send_json_error('bad account id');
         // Bad account id in callback
     }
     $cms_api = new BC_CMS_API();
     $video_details = $cms_api->video_get($video_id);
     if (false === $video_details) {
         wp_send_json_error('video does not exist');
     }
     $videos = new BC_Videos();
     $video_update = $videos->add_or_update_wp_video($video_details);
     $bc_accounts->restore_default_account();
     $this->trigger_background_fetch();
     if ($video_update) {
         wp_send_json_success('video successfully updated');
     } else {
         wp_send_json_error('unable to update video');
     }
 }