/** * Updates Metadata to the Brightcove API * * @param array $sanitized_post_data This should be sanitized POST data. * * @return bool|WP_Error */ public function update_bc_playlist($sanitized_post_data) { global $bc_accounts; if (!wp_verify_nonce($_POST['nonce'], '_bc_ajax_search_nonce')) { return false; } $playlist_id = BC_Utility::sanitize_id($sanitized_post_data['playlist_id']); $update_data = array('type' => 'EXPLICIT'); if (array_key_exists('name', $sanitized_post_data) && '' !== $sanitized_post_data['name']) { $update_data['name'] = utf8_uri_encode(sanitize_text_field($sanitized_post_data['name'])); } if (array_key_exists('playlist_videos', $sanitized_post_data) && !empty($sanitized_post_data['playlist_videos'])) { $update_data['video_ids'] = BC_Utility::sanitize_payload_item($sanitized_post_data['playlist_videos']); } $bc_accounts->set_current_account($sanitized_post_data['account']); $request = $this->cms_api->playlist_update($playlist_id, $update_data); $bc_accounts->restore_default_account(); if (is_wp_error($request) || false === $request) { return false; } if (is_array($request) && isset($request['id'])) { return true; } return true; }
/** * Updates Metadata to the Brightcove API * * @param array $sanitized_post_data . This should be sanitized POST data * * @return bool|WP_Error */ public function update_bc_video($sanitized_post_data) { global $bc_accounts; $video_id = BC_Utility::sanitize_id($sanitized_post_data['video_id']); if (array_key_exists('name', $sanitized_post_data) && '' !== $sanitized_post_data['name']) { $update_data['name'] = utf8_uri_encode(sanitize_text_field($sanitized_post_data['name'])); } if (array_key_exists('description', $sanitized_post_data) && !empty($sanitized_post_data['description'])) { $update_data['description'] = BC_Utility::sanitize_payload_item($sanitized_post_data['description']); } if (array_key_exists('long_description', $sanitized_post_data) && !empty($sanitized_post_data['long_description'])) { $update_data['long_description'] = BC_Utility::sanitize_payload_item($sanitized_post_data['long_description']); } if (array_key_exists('tags', $sanitized_post_data) && !empty($sanitized_post_data['tags'])) { // Convert tags string to an array. $update_data['tags'] = array_map('trim', explode(',', $sanitized_post_data['tags'])); } $bc_accounts->set_current_account($sanitized_post_data['account']); $request = $this->cms_api->video_update($video_id, $update_data); $bc_accounts->restore_default_account(); /** * If we had any tags in the update, add them to the tags collection if we don't already track them. */ if (array_key_exists('tags', $update_data) && is_array($update_data['tags']) && count($update_data['tags'])) { $existing_tags = $this->tags->get_tags(); $new_tags = array_diff($update_data['tags'], $existing_tags); if (count($new_tags)) { $this->tags->add_tags($new_tags); } } if (is_wp_error($request) || $request === false) { return false; } return true; }
public function update_profile() { global $bc_accounts; if (!isset($_POST['_bc_profile_nonce'])) { return false; } if (!wp_verify_nonce($_POST['_bc_profile_nonce'], 'bc_profile_nonce')) { return false; } $hash = BC_Utility::sanitize_payload_item($_POST['bc-user-default-source']); $user_id = BC_Utility::sanitize_id($_POST['user_id']); $accounts = $bc_accounts->get_sanitized_all_accounts(); if (!isset($accounts[$hash])) { BC_Utility::admin_notice_messages(array(array('message' => esc_html__('The specified Source does not exist.', 'brightcove'), 'type' => 'error'))); return false; } BC_Utility::update_user_meta($user_id, '_brightcove_default_account_' . get_current_blog_id(), $hash); return true; }
/** * Update a playlist in the Brightcove Video Cloud * * Updates a playlist with the provided id and optional other data in the video cloud. * * @since 1.0.0 * * @param string $playlist_id the id of the playlist to update * @param array $args optional array of other arguments to update in the playlist * * @return array|bool array of data about the updated playlist or false on failure. */ public function playlist_update($playlist_id, $args = array()) { $playlist_id = BC_Utility::sanitize_payload_item($playlist_id); $data = BC_Utility::sanitize_payload_args_recursive($args); return $this->send_request(esc_url_raw(self::CMS_BASE_URL . $this->get_account_id() . '/playlists/' . $playlist_id), 'PATCH', $data); }
public static function update_video_meta() { if (!wp_verify_nonce($_POST['nonce'], '_bc_ajax_search_nonce')) { return; } if (!array_key_exists('update-metadata', $_POST)) { return; } $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 esc_attr($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); }
/** * In the event playlist object data is stale in WordPress, or a playlist has never been generated, * create/update WP data store with Brightcove data. * * @param $playlist * * @return bool|WP_Error */ public function add_or_update_wp_playlist($playlist) { $hash = BC_Utility::get_hash_for_object($playlist); $playlist_id = $playlist['id']; $stored_hash = $this->get_playlist_hash_by_id($playlist_id); // No change to existing playlist if ($hash === $stored_hash) { return true; } $post_excerpt = !is_null($playlist['description']) ? $playlist['description'] : ''; $post_content = $post_excerpt; $post_title = !is_null($playlist['name']) ? $playlist['name'] : ''; $post_date = new DateTime($playlist['created_at']); $post_date = $post_date->format('Y-m-d g:i:s'); $utc_timezone = new DateTimeZone('GMT'); $gmt = new DateTime($playlist['created_at'], $utc_timezone); $gmt = $gmt->format('Y-m-d g:i:s'); $playlist_post_args = array('post_type' => 'brightcove-playlist', 'post_title' => $post_title, 'post_name' => $post_title . uniqid(), 'post_content' => $post_content, 'post_excerpt' => $post_excerpt, 'post_date' => $post_date, 'post_date_gmt' => $gmt, 'post_status' => 'publish'); $existing_post = $this->get_playlist_by_id($playlist_id); if ($existing_post) { $playlist_post_args['ID'] = $existing_post->ID; $post_id = wp_update_post($playlist_post_args, true); } else { $post_id = wp_insert_post($playlist_post_args, true); } if (is_wp_error($post_id)) { $error_message = $post_id->get_error_message(); BC_Logging::log(sprintf('BC WORDPRESS ERROR: %s'), $error_message); return new WP_Error('post-not-created', $error_message); } $this->playlist_ids[] = $post_id; update_post_meta($post_id, '_brightcove_hash', $hash); update_post_meta($post_id, '_brightcove_playlist_id', BC_Utility::sanitize_and_generate_meta_video_id($playlist_id)); update_post_meta($post_id, '_brightcove_account_id', BC_Utility::sanitize_id($playlist['account_id'])); update_post_meta($post_id, '_brightcove_playlist_object', $playlist); $video_ids = BC_Utility::sanitize_payload_item($playlist['video_ids']); foreach ($video_ids as $video_id) { update_post_meta($post_id, '_brightcove_video_id', $video_id); } $meta = array(); $meta_keys = apply_filters('brightcove_meta_keys', array('favorite', 'limit', 'search')); foreach ($meta_keys as $key) { if (!empty($playlist[$key])) { $meta[$key] = $playlist[$key]; } } update_post_meta($post_id, '_brightcove_metadata', $meta); return true; }