/** * Ensure there is a playlist capable player available */ public function validate_players() { global $pagenow, $plugin_page; // only on admin.php?page=page-brightcove-playlists if ($pagenow != 'admin.php' || $plugin_page != 'page-brightcove-playlists') { return; } $player_api = new BC_Player_Management_API(); $players = $player_api->player_list_playlist_enabled(); if (is_wp_error($players) || !is_array($players) || $players['item_count'] < 1) { BC_Utility::admin_notice_messages(array(array('message' => __('A specified Source does not have a playlist capable player <a href="https://studio.brightcove.com/products/videocloud/players/">configured</a>. Make sure there is at least one player with "Display Playlist" enabled.', 'brightcove'), 'type' => 'error'))); } }
/** * Retrieve a list of players available for usage on the front-end * * Requires the following fields: * - nonce WordPress nonce to prevent replay attacks * - account ID of the account we're referencing * * Will return an array of objects (in JSON) representing available players. Each player will roughly contain: * - accountId (string) * - id (string) * - name (string) * - description (string) * - branches (object) * - created_at (datetime) * - url (string) * - embed_count (integer) * * @see http://docs.brightcove.com/en/video-cloud/player-management/reference/versions/v1/index.html#api-Players-Get_All_Players * * @global BC_Accounts $bc_accounts */ public function ajax_players() { global $bc_accounts; // Ensure all required fields were sent foreach (array('nonce', 'account') as $parameter) { if (!isset($_POST[$parameter])) { wp_send_json_error(); } } // Validate our nonce if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], '_bc_ajax_players')) { wp_send_json_error(); // Nonce was invalid, fail } // Set up the account from which we're fetching data $account_id = sanitize_text_field($_POST['account']); $account = $bc_accounts->set_current_account_by_id($account_id); if (false === $account) { wp_send_json_error(); // Account was invalid, fail } // Get players from Brightcove $players = $this->player_api->player_list(); // Restore our global, default account $bc_accounts->restore_default_account(); if (false === $players) { wp_send_json_error(); // Retrieval failed, fail } wp_send_json_success($players); }
/** * Render Player * * Renders the player from Brightcove based on passed parameters * * @since 1.0 * * @param string $type "playlist" or "video". * @param string $id The brightcove player or video ID. * @param string $account_id The Brightcove account ID. * @param string $player_id The brightcove player ID. * @param int $width The Width to display. * @param int $height The height to display. * * @return string The HTML code for the player */ public static function player($type, $id, $account_id, $player_id = 'default', $width = 0, $height = 0) { // Sanitize and Verify. $account_id = BC_Utility::sanitize_id($account_id); $player_id = 'default' == $player_id ? 'default' : BC_Utility::sanitize_id($player_id); $id = BC_Utility::sanitize_id($id); $height = (int) $height; $width = (int) $width; $type = 'playlist' === $type ? 'playlist' : 'video'; if ('playlist' === $type && 'default' === $player_id) { $player_api = new BC_Player_Management_API(); $players = $player_api->player_list_playlist_enabled(); if (is_wp_error($players) || !is_array($players) || $players['item_count'] < 1) { return '<div class="brightcove-player-warning">' . __('A specified Source does not have a playlist capable player <a href="https://studio.brightcove.com/products/videocloud/players/">configured</a>. Make sure there is at least one player with "Display Playlist" enabled.', 'brightcove') . '</div>'; } $player_id = esc_attr($players['items'][0]['id']); } $html = '<!-- Start of Brightcove Player -->'; if (0 === $width && 0 === $height) { $html .= '<div style="display: block; position: relative; max-width: 100%;"><div style="padding-top: 56.25%;">'; } $html .= sprintf('<iframe src="//players.brightcove.net/%s/%s_default/index.html?%sId=%s" allowfullscreen="" webkitallowfullscreen="" mozallowfullscreen="" style="width: %s; height: %s;%s"></iframe>', $account_id, $player_id, $type, $id, 0 === $width ? '100%' : $width . 'px', 0 === $height ? '100%' : $height . 'px', 0 === $width && 0 === $height ? 'position: absolute; top: 0px; bottom: 0px; right: 0px; left: 0px;' : ''); if (0 === $width && 0 === $height) { $html .= '</div></div>'; } $html .= '<!-- End of Brightcove Player -->'; return $html; }
/** * Check permission level for an account. * * @return array List of permission issues. */ protected function check_permissions_level() { $permission_issues = array(); $video_id = false; // Start enumerating permissions that we'll need to ensure the account is good. $cms_api = new BC_CMS_API(); // Create a video $video_creation = $cms_api->video_add(__('Brightcove WordPress plugin test video', 'brightcove')); if (!$video_creation || is_wp_error($video_creation)) { $permission_issues[] = esc_html__('create videos', 'brightcove'); } else { $video_id = $video_creation['id']; // Update a video $renamed_title = __('Brightcove WordPress plugin test video renamed', 'brightcove'); $video_renamed = $cms_api->video_update($video_id, array('name' => $renamed_title)); if (!$video_renamed || $renamed_title !== $video_renamed['name']) { $permission_issues[] = esc_html__('modify videos', 'brightcove'); } } $playlist = $cms_api->playlist_add(__('Brightcove WordPress plugin test playlist', 'brightcove')); if (!$playlist || !is_array($playlist) || !isset($playlist['id'])) { $permission_issues[] = esc_html__('create playlists', 'brightcove'); } else { // For use through other Playlist test API calls. $playlist_id = $playlist['id']; $update_data = array('video_ids' => array($video_id), 'type' => 'EXPLICIT'); $updated_playlist = $cms_api->playlist_update($playlist_id, $update_data); if (!$updated_playlist || !is_array($updated_playlist) || !isset($updated_playlist['id'])) { $permission_issues[] = esc_html__('modify playlists', 'brightcove'); } // Delete a playlist if (!$cms_api->playlist_delete($playlist_id)) { $permission_issues[] = esc_html__('delete playlists', 'brightcove'); } } // Delete a video if (!$cms_api->video_delete($video_id)) { $permission_issues[] = esc_html__('delete videos', 'brightcove'); } $player_api = new BC_Player_Management_API($this); // Fetch all players $players = $player_api->player_list(); if (is_wp_error($players) || !is_array($players['items'])) { $permission_issues[] = esc_html__('fetch players', 'brightcove'); } return $permission_issues; }
public static function admin_enqueue_scripts() { global $wp_version; global $bc_accounts; // Use minified libraries if SCRIPT_DEBUG is turned off. $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; $player_api = new BC_Player_Management_API(); $players = $player_api->all_player_by_account(); $js_variable = array('path' => esc_url(BRIGHTCOVE_URL . 'assets/js/src/'), 'preload' => BC_Setup::preload_params(), 'wp_version' => $wp_version, 'languages' => BC_Utility::languages(), 'players' => $players, 'str_badformat' => esc_html__('This file is not the proper format. Please use .vtt files, for more information visit', 'brightcove'), 'badformat_link' => esc_url('https://support.brightcove.com/en/video-cloud/docs/adding-captions-videos#captionsfile'), 'str_addcaption' => esc_html__('Add Another Caption', 'brightcove'), 'str_addremote' => esc_html__('Add another remote file', 'brightcove'), 'str_selectfile' => esc_html__('Select File', 'brightcove'), 'str_useremote' => esc_html__('Use a remote file instead', 'brightcove'), 'str_apifailure' => esc_html__("Sorry! We weren't able to reach the Brightcove API even after trying a few times. Please try refreshing the page.", 'brightcove'), 'posts_per_page' => absint(apply_filters('brightcove_posts_per_page', 100))); wp_register_script('brightcove', '//sadmin.brightcove.com/js/BrightcoveExperiences.js'); $playlist_enabled_players_for_accounts = array(); $accounts = $bc_accounts->get_sanitized_all_accounts(); foreach ($accounts as $account) { $playlist_enabled_players_for_accounts[$account['account_id']] = get_option('_bc_player_playlist_ids_' . $account['account_id']); } wp_enqueue_script('tinymce_preview', esc_url(BRIGHTCOVE_URL . 'assets/js/src/tinymce.js'), array('mce-view')); wp_localize_script('tinymce_preview', 'bctiny', array('wp_version' => $wp_version, 'playlistEnabledPlayers' => $playlist_enabled_players_for_accounts)); $dependencies = array('jquery', 'backbone', 'wp-backbone', 'media', 'media-editor', 'media-grid', 'media-models', 'media-upload', 'media-views', 'plupload-all', 'brightcove', 'wp-mediaelement', 'tinymce_preview'); wp_register_script('brightcove-admin', esc_url(BRIGHTCOVE_URL . 'assets/js/brightcove-admin' . $suffix . '.js'), $dependencies); wp_localize_script('brightcove-admin', 'wpbc', $js_variable); wp_enqueue_script('brightcove-admin'); wp_enqueue_media(); wp_register_style('brightcove-video-connect', esc_url(BRIGHTCOVE_URL . 'assets/css/brightcove_video_connect' . $suffix . '.css'), array()); wp_enqueue_style('brightcove-video-connect'); }
public function render_edit_html($account) { global $bc_accounts; ?> <div class="wrap"> <h2><?php printf('<img src="%s" class="brightcove-admin-icon"/>', plugins_url('images/admin/menu-icon.svg', dirname(dirname(__DIR__)))); ?> <?php esc_html_e('Edit Source', 'brightcove'); ?> </h2> <form action="" method="post"> <table class="form-table brightcove-add-source-name"> <tbody> <tr class="brightcove-account-row"> <th scope="row"><?php esc_html_e('Source Name', 'brightcove'); ?> </th> <td> <?php echo esc_html($account['account_name']); ?> </td> </tr> </tbody> </table> <table class="form-table brightcove-add-source-details"> <tbody> <tr class="brightcove-account-row"> <th scope="row"><?php esc_html_e('Account ID', 'brightcove'); ?> </th> <td> <?php echo esc_html($account['account_id']); ?> </td> </tr> </table> <table class="form-table"> <tr class="brightcove-account-row"> <th scope="row"><?php esc_html_e('Default Source', 'brightcove'); ?> </th> <td> <input type="checkbox" name="source-default-account" <?php checked(get_option('_brightcove_default_account'), $account['hash']); ?> > <?php esc_html_e('Make this the default source for new users', 'brightcove'); ?> </td> </tr> <!-- Pending Unblocking on Player API setting Default Player <tr class="brightcove-account-row"> <th scope="row"><?php esc_html_e('Default Player', 'brightcove'); ?> </th> <td> <?php $bc_accounts->get_account_details_for_user(); $player_api = new BC_Player_Management_API(); $players = $player_api->player_list(); ?> <select name="sources-players"> <?php foreach ($players['items'] as $player) { printf('<option value="%1$s" %3$s>%2$s</option>', esc_attr($player['id']), esc_html($player['name']), selected('default', $player['id'])); } ?> </select> </td> </tr>--> </table> <?php wp_nonce_field('_brightcove_check_oauth_for_source', 'brightcove-check_oauth', false, true); ?> <p class="submit"> <input type="hidden" name="hash" value="<?php echo esc_attr($account['hash']); ?> "> <input type="hidden" name="source-action" value="update"/> <input type="submit" name="brightcove-edit-account-submit" id="brightcove-edit-account-submit" class="button button-primary" value="<?php esc_html_e('Save Changes', 'brightcove'); ?> "> </p> </form> </div> <?php }