From 345b3495800a8c958afadbaa3109df19e79b1e6c Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Fri, 15 Jul 2022 09:55:12 -0500 Subject: [PATCH 01/66] Bump tested up to --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 17f78576..060c48d7 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: 10up, oscarssanchez, collinsinternet, ivankk, technosailor, ChrisW Donate link: https://supporters.eff.org/donate Tags: brightcove, 10up, videos, video Requires at least: 4.2 -Tested up to: 5.8 +Tested up to: 6.0 Stable tag: 2.7.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html From b184483aabd9f24eaefa89114a57435834c53354 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Mon, 1 Aug 2022 13:56:58 -0500 Subject: [PATCH 02/66] Initial PHPCS checks --- .github/workflows/lint.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2f623408..b7323fa2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,4 +22,24 @@ jobs: - name: npm install run: npm install - name: eslint - run: npm run lint-js \ No newline at end of file + run: npm run lint-js + + phpcs: + name: PHP Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: PHP version + uses: shivammathur/setup-php@v2 + with: + php-version: '7.2' + coverage: none + + - name: composer install + run: composer install + + - name: PHPCS check + run: composer run lint \ No newline at end of file From 6692501afaa383b03b09bd7c7d2fc0310eb85bcc Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Mon, 1 Aug 2022 14:15:46 -0500 Subject: [PATCH 03/66] PHPCBF fixes --- brightcove-video-connect.php | 2 +- includes/class-bc-utility.php | 2 +- includes/class-bc-video-shortcode.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/brightcove-video-connect.php b/brightcove-video-connect.php index b05c8c5b..822d7c93 100644 --- a/brightcove-video-connect.php +++ b/brightcove-video-connect.php @@ -72,7 +72,7 @@ function brightcove_deactivate() { // Wireup actions. if ( is_admin() ) { - add_action( 'admin_notices', array( 'BC_Setup', 'bc_admin_notices' ) ); + add_action( 'admin_notices', array( 'BC_Setup', 'bc_admin_notices' ) ); } add_action( 'init', array( 'BC_Setup', 'action_init' ) ); diff --git a/includes/class-bc-utility.php b/includes/class-bc-utility.php index 740708b9..08c45497 100644 --- a/includes/class-bc-utility.php +++ b/includes/class-bc-utility.php @@ -861,7 +861,7 @@ public static function get_video_player( $atts ) { myPlayer.pip(); }); -
diff --git a/includes/class-bc-video-shortcode.php b/includes/class-bc-video-shortcode.php index 92d66762..cfca71e3 100644 --- a/includes/class-bc-video-shortcode.php +++ b/includes/class-bc-video-shortcode.php @@ -38,7 +38,7 @@ public static function bc_video( $atts ) { 'width' => 0, 'playsinline' => '', 'picture_in_picture' => '', - 'language_detection' => '' + 'language_detection' => '', ); $atts = shortcode_atts( $defaults, $atts, 'bc_video' ); From 65171b298087ec9981c49e7000034646b727bbed Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 14:32:34 -0500 Subject: [PATCH 04/66] brightcove-video-connect.php phpcs fixes --- brightcove-video-connect.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightcove-video-connect.php b/brightcove-video-connect.php index 822d7c93..c39a0de2 100644 --- a/brightcove-video-connect.php +++ b/brightcove-video-connect.php @@ -9,6 +9,8 @@ * License: GPLv2+ * Text Domain: brightcove * Domain Path: /languages + * + * @package Brightcove_Video_Connect */ /** @@ -83,8 +85,6 @@ function brightcove_deactivate() { add_action( 'init', array( 'BC_Setup', 'action_init_all' ), 9 ); // Ensures the menu is loaded on all pages. add_action( 'init', array( 'BC_Notification_API', 'setup' ), 9 ); -// add_action( 'brightcove_upgrade', array( 'BC_Notification_API', 'maybe_backport_subscriptions' ) ); // @TODO Verify API as errors don't seem to match the documentation - if ( ! defined( 'WPCOM_IS_VIP_ENV' ) || ! WPCOM_IS_VIP_ENV ) { // Activation / Deactivation. From 015d5469edf085dc46d2bafb273f232a9c20b9fe Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 14:33:00 -0500 Subject: [PATCH 05/66] cli/class-brightcove-cli.php phpcs fixes --- cli/class-brightcove-cli.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cli/class-brightcove-cli.php b/cli/class-brightcove-cli.php index 227678f0..e92ea431 100644 --- a/cli/class-brightcove-cli.php +++ b/cli/class-brightcove-cli.php @@ -1,4 +1,9 @@ Date: Thu, 4 Aug 2022 14:33:29 -0500 Subject: [PATCH 06/66] class-bc-admin-media-api.php phpcs fixes --- .../admin/api/class-bc-admin-media-api.php | 103 ++++++++++++------ 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/includes/admin/api/class-bc-admin-media-api.php b/includes/admin/api/class-bc-admin-media-api.php index 4efac577..cc29c671 100644 --- a/includes/admin/api/class-bc-admin-media-api.php +++ b/includes/admin/api/class-bc-admin-media-api.php @@ -1,37 +1,60 @@ cms_api->video_fields(); $use_history = false; foreach ( $fields['custom_fields'] as $item ) { - if ( '_change_history' == $item['id'] ) { + if ( '_change_history' === $item['id'] ) { $use_history = true; break; } @@ -187,10 +216,10 @@ public function bc_ajax_update_video_or_playlist() { $user = wp_get_current_user(); $history[] = array( 'user' => $user->user_login, - 'time' => date( 'Y-m-d H:i:s', time() ), + 'time' => gmdate( 'Y-m-d H:i:s', time() ), ); - $custom['_change_history'] = json_encode( $history ); + $custom['_change_history'] = wp_json_encode( $history ); } $updated_data['custom_fields'] = $custom; @@ -200,7 +229,7 @@ public function bc_ajax_update_video_or_playlist() { $status = false; - if ( ! in_array( $_POST['type'], array( 'playlists', 'videos' ) ) ) { + if ( ! in_array( $_POST['type'], array( 'playlists', 'videos' ), true ) ) { wp_send_json_error( __( 'Type is not specified', 'brightcove' ) ); } @@ -225,11 +254,11 @@ public function bc_ajax_update_video_or_playlist() { } else { $status = $this->videos->update_bc_video( $updated_data ); - if ( isset( $_POST['folderId'] ) && isset( $_POST['oldFolderId'] ) ) { - $folderId = sanitize_text_field( $_POST['folderId'] ); - $oldFolderId = sanitize_text_field( $_POST['oldFolderId'] ); + if ( isset( $_POST['folder_id'] ) && isset( $_POST['oldfolder_id'] ) ) { + $folder_id = sanitize_text_field( $_POST['folder_id'] ); + $old_folder_id = sanitize_text_field( $_POST['oldfolder_id'] ); - $this->cms_api->add_folder_to_video( $oldFolderId, $folderId, $updated_data['video_id'] ); + $this->cms_api->add_folder_to_video( $old_folder_id, $folder_id, $updated_data['video_id'] ); } // Maybe update poster @@ -302,7 +331,7 @@ public function bc_ajax_delete_video_or_playlist() { $id = BC_Utility::sanitize_id( $_POST['id'] ); // Get type brightcove-playlist or brightcove-video. - if ( ! in_array( $type, array( 'playlists', 'videos' ) ) ) { + if ( ! in_array( $type, array( 'playlists', 'videos' ), true ) ) { wp_send_json_error( esc_html__( 'Type is not specified!', 'brightcove' ) ); } @@ -458,7 +487,9 @@ public function fetch_all( $type, $posts_per_page = 100, $page = 1, $query_strin $account_ids = array_unique( $account_ids ); - while ( count( $results ) <= ( $page * $posts_per_page ) ) { + $count_results = count( $results ); + + while ( $count_results <= ( $page * $posts_per_page ) ) { if ( 0 === count( $account_ids ) ) { @@ -548,7 +579,7 @@ public function brightcove_media_query() { $query = ( isset( $_POST['search'] ) && '' !== $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : false; $tag_name = ( isset( $_POST['tagName'] ) && '' !== $_POST['tagName'] ) ? sanitize_text_field( $_POST['tagName'] ) : false; $dates = ( isset( $_POST['dates'] ) && 'all' !== $_POST['dates'] ) ? BC_Utility::sanitize_date( $_POST['dates'] ) : false; - $folder_id = ( isset( $_POST['folderId'] ) && '' !== $_POST['folderId'] ) ? sanitize_text_field( $_POST['folderId'] ) : false; + $folder_id = ( isset( $_POST['folder_id'] ) && '' !== $_POST['folder_id'] ) ? sanitize_text_field( $_POST['folder_id'] ) : false; $label = ( isset( $_POST['labelPath'] ) && '' !== $_POST['labelPath'] ) ? sanitize_text_field( $_POST['labelPath'] ) : false; $state = ( isset( $_POST['state'] ) && '' !== $_POST['state'] ) ? sanitize_text_field( $_POST['state'] ) : apply_filters( 'brightcove_state_filter', false ); @@ -565,7 +596,7 @@ public function brightcove_media_query() { $type = isset( $_POST['type'] ) ? sanitize_key( $_POST['type'] ) : false; - if ( ! $type || ! in_array( $type, array( 'videos', 'playlists', 'videoexperience', 'playlistexperience', 'inpageexperiences' ) ) ) { + if ( ! $type || ! in_array( $type, array( 'videos', 'playlists', 'videoexperience', 'playlistexperience', 'inpageexperiences' ), true ) ) { wp_send_json_error( esc_html__( 'Invalid Search Type', 'brightcove' ) ); exit; // Type can only be videos or playlists. @@ -742,7 +773,7 @@ public function brightcove_media_query() { if ( isset( $result['custom_fields'] ) ) { foreach ( $result['custom_fields'] as $id => $value ) { // Extract the change tracking item explicitly - if ( $id == '_change_history' ) { + if ( '_change_history' === $id ) { $result['history'] = $value; continue; } @@ -846,11 +877,11 @@ public function ajax_players() { * * @global BC_Accounts $bc_accounts * - * @param string $account_hash - * @param int $video_id - * @param string $url - * @param int $width - * @param int $height + * @param string $account_hash The account hash for the account. + * @param int $video_id The ID of the video to associate the image with. + * @param string $url The URL of the image to upload. + * @param int $width The width of the image. + * @param int $height The height of the image. */ public function ajax_poster_upload( $account_hash, $video_id, $url, $width, $height ) { global $bc_accounts; @@ -887,11 +918,11 @@ public function ajax_poster_upload( $account_hash, $video_id, $url, $width, $hei * * @global BC_Accounts $bc_accounts * - * @param string $account_hash - * @param int $video_id - * @param string $url - * @param int $width - * @param int $height + * @param string $account_hash The account hash for the account. + * @param int $video_id The video ID. + * @param string $url The URL of the thumbnail attachment. + * @param int $width The width of the thumbnail. + * @param int $height The height of the thumbnail. */ public function ajax_thumb_upload( $account_hash, $video_id, $url, $width, $height ) { global $bc_accounts; @@ -928,8 +959,8 @@ public function ajax_thumb_upload( $account_hash, $video_id, $url, $width, $heig * * @global BC_Accounts $bc_accounts * - * @param string $account_hash - * @param int $video_id + * @param string $account_hash The account hash to which the video belongs. + * @param int $video_id The ID of the video from which to delete captions. */ public function ajax_caption_delete( $account_hash, $video_id ) { global $bc_accounts; @@ -953,9 +984,9 @@ public function ajax_caption_delete( $account_hash, $video_id ) { * * @global BC_Accounts $bc_accounts * - * @param string $account_hash - * @param int $video_id - * @param array $raw_captions + * @param string $account_hash The account hash for the account. + * @param int $video_id The video ID + * @param array $raw_captions The raw captions data. */ public function ajax_caption_upload( $account_hash, $video_id, $raw_captions ) { global $bc_accounts; @@ -986,7 +1017,7 @@ public function ajax_caption_upload( $account_hash, $video_id, $raw_captions ) { $label = isset( $caption['label'] ) ? sanitize_text_field( $caption['label'] ) : ''; $default = ( isset( $caption['default'] ) && 'checked' === $caption['default'] ); - $source = parse_url( $caption['source'] ); + $source = wp_parse_url( $caption['source'] ); if ( 0 === strpos( $source['host'], 'brightcove' ) ) { // If the hostname starts with "brightcove," assume this media has already been ingested and add to old captions. $old_captions[] = new BC_Text_Track( $url, $lang, 'captions', $label, $default ); @@ -1014,8 +1045,8 @@ public function ajax_caption_upload( $account_hash, $video_id, $raw_captions ) { /** * Return a set of the most recent videos for the specified account. * - * @param string $account_id - * @param int $count + * @param string $account_id The account ID to retrieve videos for. + * @param int $count The number of videos to return. * * @global BC_Accounts $bc_accounts * @@ -1058,7 +1089,7 @@ protected function fetch_videos( $account_id, $count = 10 ) { foreach ( $result['custom_fields'] as $id => $value ) { // Extract the change tracking item explicitly - if ( $id == '_change_history' ) { + if ( '_change_history' === $id ) { $result['history'] = $value; continue; } @@ -1098,8 +1129,8 @@ protected function fetch_videos( $account_id, $count = 10 ) { /** * When a WP heartbeat is received with an account hash, respond with the most recent 10 videos available. * - * @param array $response - * @param array $data + * @param array $response WP heartbeat response. + * @param array $data Data received from heartbeat * * @return array */ @@ -1127,7 +1158,7 @@ public function add_in_process_videos( $videos ) { foreach ( $video_post_ids as $video_post_id ) { $in_process_video_id = BC_Utility::get_sanitized_video_id( $video_post_id ); - if ( in_array( $in_process_video_id, $video_ids ) ) { + if ( in_array( $in_process_video_id, $video_ids, true ) ) { wp_delete_post( $video_post_id, true ); } else { $videos[] = get_post_meta( $video_post_id, '_brightcove_video_object', true ); From 3fea880901c0b1756113fbb81368d9821e26fe9a Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 14:33:48 -0500 Subject: [PATCH 07/66] class-bc-admin-labels-page.php phpcs fixes --- includes/admin/class-bc-admin-labels-page.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/includes/admin/class-bc-admin-labels-page.php b/includes/admin/class-bc-admin-labels-page.php index ddd32ade..a953be31 100644 --- a/includes/admin/class-bc-admin-labels-page.php +++ b/includes/admin/class-bc-admin-labels-page.php @@ -1,10 +1,22 @@ " class="validate"> - + @@ -58,7 +70,7 @@ public function render_edit_label_page() { * Generates an HTML table with all configured sources */ public function render_labels_page() { - $maybe_refresh = isset( $_GET['refresh_labels'] ) ? (bool) $_GET['refresh_labels'] : false; + $maybe_refresh = isset( $_GET['refresh_labels'] ) && (bool) $_GET['refresh_labels']; // phpcs:ignore $labels = $this->bc_labels->fetch_all( $maybe_refresh ); ?>
From cf0b1c35668430ee10cb558ad7397a64e0c7a7ae Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 14:34:17 -0500 Subject: [PATCH 08/66] class-bc-admin-menu.php phpcs fixes --- includes/admin/class-bc-admin-menu.php | 58 ++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/includes/admin/class-bc-admin-menu.php b/includes/admin/class-bc-admin-menu.php index ea46824a..7cb47fed 100644 --- a/includes/admin/class-bc-admin-menu.php +++ b/includes/admin/class-bc-admin-menu.php @@ -1,7 +1,18 @@ Date: Thu, 4 Aug 2022 14:34:34 -0500 Subject: [PATCH 09/66] class-bc-admin-playlists-page.php phpcs fixes --- includes/admin/class-bc-admin-playlists-page.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/includes/admin/class-bc-admin-playlists-page.php b/includes/admin/class-bc-admin-playlists-page.php index cb574ddf..7e09cd88 100644 --- a/includes/admin/class-bc-admin-playlists-page.php +++ b/includes/admin/class-bc-admin-playlists-page.php @@ -1,9 +1,19 @@ load() for the hook into * the Backbone app for playlist-media. @@ -36,7 +46,7 @@ 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' ) { + if ( 'admin.php' !== $pagenow || 'page-brightcove-playlists' !== $plugin_page ) { return; } From 3e70d61bed6bb4e31ea45d04fdaf43e6070f8989 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 14:34:49 -0500 Subject: [PATCH 10/66] class-bc-admin-settings-page.php --- .../admin/class-bc-admin-settings-page.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/includes/admin/class-bc-admin-settings-page.php b/includes/admin/class-bc-admin-settings-page.php index d387a799..97faf5b9 100644 --- a/includes/admin/class-bc-admin-settings-page.php +++ b/includes/admin/class-bc-admin-settings-page.php @@ -1,7 +1,18 @@
render_source_rows(); + echo $this->render_source_rows() // phpcs:ignore ?>
- +

@@ -126,7 +142,7 @@ public function render() { /** * Creates a filterable list of actions that can be performed on each source. By default, the only action link is an edit link * - * @param $source_id + * @param string $hash The hash of the source * * @return string */ @@ -196,7 +212,8 @@ public function render_source_rows() { /** * Renders a row in the the source table and populates with relevant information about that particular source * - * @param $source object + * @param string $hash The hash of the source + * @param object $source The source object * * @return string */ From 3c7f09c18ae413e99ad1911c035568648500bd2c Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 14:35:03 -0500 Subject: [PATCH 11/66] class-bc-admin-sources.php phpcs fixes --- includes/admin/class-bc-admin-sources.php | 48 ++++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/includes/admin/class-bc-admin-sources.php b/includes/admin/class-bc-admin-sources.php index 483cc97e..0c93cca1 100644 --- a/includes/admin/class-bc-admin-sources.php +++ b/includes/admin/class-bc-admin-sources.php @@ -1,4 +1,9 @@ notices = array(); @@ -27,9 +37,9 @@ public function render() { global $bc_accounts; - if ( array_key_exists( 'account', $_GET ) ) { + if ( array_key_exists( 'account', $_GET ) ) { // phpcs:ignore - $hash = sanitize_text_field( $_GET['account'] ); + $hash = sanitize_text_field( $_GET['account'] ); // phpcs:ignore $account = $bc_accounts->get_account_by_hash( $hash ); if ( ! $account ) { @@ -199,6 +209,9 @@ public function admin_notice_handler() { } + /** + * Render add source html + */ public function render_add_html() { $source_name = ''; $account_id = ''; @@ -229,7 +242,7 @@ public function render_add_html() {

', plugins_url( 'images/menu-icon.svg', dirname( __DIR__ ) ) ); + printf( '', esc_url( plugins_url( 'images/menu-icon.svg', dirname( __DIR__ ) ) ) ); ?>

@@ -240,8 +253,8 @@ public function render_add_html() { + placeholder="" + class="regular-text" required="required" value="">

@@ -251,14 +264,14 @@ class="regular-text" required="required" value=" - %s %s.', esc_html__( 'The following information can be found by logging into your', 'brightcove' ), esc_html__( 'Video Cloud Studio', 'brightcove' ), esc_html__( 'account', 'brightcove' ) ); - ?> + ?>
+ required="required" value=""> + required="required" value="">

@@ -289,7 +302,7 @@ class="regular-text" required="required" value=" + class="regular-text" required="required" value="">

@@ -318,13 +331,18 @@ class="regular-text" required="required" value=" + class="button button-primary" value="">

@@ -332,7 +350,7 @@ public function render_edit_html( $account ) {

', plugins_url( 'images/menu-icon.svg', dirname( __DIR__ ) ) ); + printf( '', esc_url( plugins_url( 'images/menu-icon.svg' ), dirname( __DIR__ ) ) ); ?>

@@ -381,8 +399,8 @@ public function render_edit_html( $account ) {

- +

From 53ca539121eae3abaef2312127c5a7631f8fc319 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:03:08 -0500 Subject: [PATCH 12/66] class-bc-admin-user-profile.php phpcs fixes --- .../admin/class-bc-admin-user-profile.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/includes/admin/class-bc-admin-user-profile.php b/includes/admin/class-bc-admin-user-profile.php index 62151c1c..e2a0c24d 100644 --- a/includes/admin/class-bc-admin-user-profile.php +++ b/includes/admin/class-bc-admin-user-profile.php @@ -1,19 +1,36 @@ Date: Thu, 4 Aug 2022 15:07:48 -0500 Subject: [PATCH 13/66] class-bc-admin-videos-page.php phpcs fixes --- includes/admin/class-bc-admin-videos-page.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/admin/class-bc-admin-videos-page.php b/includes/admin/class-bc-admin-videos-page.php index 75ede4a4..dfc9a1dc 100644 --- a/includes/admin/class-bc-admin-videos-page.php +++ b/includes/admin/class-bc-admin-videos-page.php @@ -1,7 +1,18 @@ Date: Thu, 4 Aug 2022 15:08:11 -0500 Subject: [PATCH 14/66] class-bc-templates.php phpcs fixes --- includes/admin/class-bc-templates.php | 111 ++++++++++++++------------ 1 file changed, 60 insertions(+), 51 deletions(-) diff --git a/includes/admin/class-bc-templates.php b/includes/admin/class-bc-templates.php index efdd814e..c58f467d 100644 --- a/includes/admin/class-bc-templates.php +++ b/includes/admin/class-bc-templates.php @@ -1,6 +1,18 @@ @@ -462,58 +474,55 @@ class="brightcove-datetime brightcove-end-date" @@ -607,7 +616,7 @@ class="brightcove-datetime brightcove-end-date"

-

+

From feae4b8d3aae34d5c04be8c89427114b36b7a4d1 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:08:28 -0500 Subject: [PATCH 15/66] class-bc-api.php phpcs fixes --- includes/api/class-bc-api.php | 37 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/includes/api/class-bc-api.php b/includes/api/class-bc-api.php index ede9b0c9..a84ee144 100644 --- a/includes/api/class-bc-api.php +++ b/includes/api/class-bc-api.php @@ -1,4 +1,9 @@ errors = array(); - } /** @@ -87,6 +93,13 @@ public function get_last_error() { } + /** + * Tries to get cached item first, then falls back to API call. + * + * @param string $url the url to call + * @param array $args the arguments to pass to the API call + * @return array|false|mixed|WP_Error + */ private function cached_get( $url, $args ) { global $bc_accounts; @@ -108,7 +121,7 @@ private function cached_get( $url, $args ) { } $successful_response_codes = array( 200, 201, 202, 204 ); - if ( in_array( wp_remote_retrieve_response_code( $request ), $successful_response_codes ) ) { + if ( in_array( wp_remote_retrieve_response_code( $request ), $successful_response_codes, true ) ) { BC_Utility::set_cache_item( $transient_key, '', $request, $cache_time_in_seconds ); } } @@ -143,12 +156,12 @@ protected function send_request( $url, $method = 'GET', $data = array(), $force_ 'JSON_POST', ); // only allow methods required by the brightcove APIs - if ( ! in_array( $method, $allowed_methods ) ) { + if ( ! in_array( $method, $allowed_methods, true ) ) { return false; } $transient_key = false; - if ( $method === 'GET' ) { + if ( 'GET' === $method ) { $hash = substr( BC_Utility::get_hash_for_object( array( @@ -204,10 +217,9 @@ protected function send_request( $url, $method = 'GET', $data = array(), $force_ default: $args['method'] = $method; - $args['body'] = wp_json_encode( $data ); if ( ! empty( $data ) ) { - $args['body'] = json_encode( $data ); + $args['body'] = wp_json_encode( $data ); } $request = wp_remote_request( $url, $args ); @@ -248,7 +260,7 @@ protected function send_request( $url, $method = 'GET', $data = array(), $force_ $successful_response_codes = array( 200, 201, 202, 204 ); - if ( ! in_array( wp_remote_retrieve_response_code( $request ), $successful_response_codes ) ) { + if ( ! in_array( wp_remote_retrieve_response_code( $request ), $successful_response_codes, true ) ) { $message = esc_html__( 'An unspecified error has occurred.', 'brightcove' ); if ( isset( $body[0] ) && isset( $body[0]['error_code'] ) ) { @@ -269,7 +281,7 @@ protected function send_request( $url, $method = 'GET', $data = array(), $force_ return false; } - if ( '204' == wp_remote_retrieve_response_code( $request ) ) { + if ( 204 === wp_remote_retrieve_response_code( $request ) ) { return true; @@ -297,10 +309,11 @@ protected function send_request( $url, $method = 'GET', $data = array(), $force_ /** * Increase the http timeout for API requests + * + * @param int $timeout The timeout value + * @return int */ - public function increase_http_timeout( $timeout ) { - $timeout += 5; return $timeout; @@ -319,7 +332,7 @@ protected function get_authorization_header( $force_new_token = false ) { $oauth = new BC_Oauth_API(); - $token = $oauth->_request_access_token( $force_new_token ); + $token = $oauth->request_access_token( $force_new_token ); if ( is_wp_error( $token ) ) { return $token; From 051658b8b991cbd6f982e019832d7e134a92ed94 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:08:45 -0500 Subject: [PATCH 16/66] class-bc-cms-api.php phpcs fixes --- includes/api/class-bc-cms-api.php | 126 +++++++++++++----------------- 1 file changed, 56 insertions(+), 70 deletions(-) diff --git a/includes/api/class-bc-cms-api.php b/includes/api/class-bc-cms-api.php index 4b277776..a200af25 100644 --- a/includes/api/class-bc-cms-api.php +++ b/includes/api/class-bc-cms-api.php @@ -1,4 +1,9 @@ get_account_id() . '/playlists'; if ( $query ) { - $url = add_query_arg( 'q', urlencode( $query ), $url ); + $url = add_query_arg( 'q', rawurlencode( $query ), $url ); } $results = $this->send_request( esc_url_raw( $url ) ); @@ -261,6 +249,7 @@ public function video_add( $name, $args = array() ) { * * @since 1.0.0 * + * @param string $filter Optional filter to apply to the video count. * @return int|bool number of videos in the account or false if failure */ public function video_count( $filter = '' ) { @@ -398,8 +387,7 @@ public function video_list( $playable = true, $folder_id = false ) { - - /* + /** * Available fields for sort: * * name @@ -415,30 +403,30 @@ public function video_list( * * Available Search Fields * - * name strings or quoted strings - * text strings or quoted strings (name, description, long_description) - * tags strings or quoted strings - * reference_id string or quoted string - * state ACTIVE, INACTIVE, DELETED, PENDING - * updated_at date range - * created_at date range - * schedule.starts_at date range - * schedule.ends_at date range - * published_at date range - * complete true or false + * name strings or quoted strings + * text strings or quoted strings (name, description, long_description) + * tags strings or quoted strings + * reference_id string or quoted string + * state ACTIVE, INACTIVE, DELETED, PENDING + * updated_at date range + * created_at date range + * schedule.starts_at date range + * schedule.ends_at date range + * published_at date range + * complete true or false */ $args = array(); - if ( 20 != absint( $limit ) ) { + if ( 20 !== absint( $limit ) ) { $args['limit'] = absint( $limit ); } - if ( 0 != absint( $offset ) ) { + if ( 0 !== absint( $offset ) ) { $args['offset'] = absint( $offset ); } - if ( 'updated_at' != sanitize_text_field( $sort ) ) { + if ( 'updated_at' !== sanitize_text_field( $sort ) ) { $args['sort'] = sanitize_text_field( $sort ); } @@ -446,7 +434,7 @@ public function video_list( $args['playable'] = false; } - if ( '' != sanitize_text_field( $query ) ) { + if ( '' !== sanitize_text_field( $query ) ) { // If Post variables are being escaped, the encoded quote do not return the intended results from the API. $query = stripslashes( $query ); @@ -568,8 +556,8 @@ public function video_upload( $video_id, $video_url, $profile = '' ) { * * @param string $video_id Video cloud ID * @param string $poster_url URL for the video poster image - * @param int [ $height] Pixel height of the image - * @param int [ $width] Pixel width of the image + * @param int $height Pixel height of the image + * @param int $width Pixel width of the image * * @return string|bool The ingest request ID or false on failure */ @@ -577,7 +565,7 @@ public function poster_upload( $video_id, $poster_url, $height = 0, $width = 0 ) // Sanitize values $height = absint( $height ); $width = absint( $width ); - $video_id = urlencode( $video_id ); + $video_id = rawurlencode( $video_id ); // Build out the data $data = array(); @@ -605,8 +593,8 @@ public function poster_upload( $video_id, $poster_url, $height = 0, $width = 0 ) * * @param string $video_id Video cloud ID * @param string $thumbnail_url URL for the thumbnail image - * @param int [ $height] Pixel height of the image - * @param int [ $width] Pixel width of the image + * @param int $height Pixel height of the image + * @param int $width Pixel width of the image * * @return string|bool The ingest request ID or false on failure */ @@ -614,7 +602,7 @@ public function thumbnail_upload( $video_id, $thumbnail_url, $height = 0, $width // Sanitize values $height = absint( $height ); $width = absint( $width ); - $video_id = urlencode( $video_id ); + $video_id = rawurlencode( $video_id ); // Build out the data $data = array(); @@ -661,10 +649,10 @@ public function variant_update( $video_id, $language, $args = array() ) { * * Sends a URL of the video's caption file to the Dynamic Ingest API for processing. * - * @param string $video_id Video cloud ID - * @param string $caption_file_url URL for a WebVTT file - * @param string [ $language] ISO 639 2-letter language code for text tracks - * @param string [ $label] User-readable title + * @param string $video_id Video cloud ID + * @param string $caption_file_url URL for a WebVTT file + * @param string $language ISO 639 2-letter language code for text tracks + * @param string $label User-readable title * * @return string|bool The ingest request ID or false on failure */ @@ -681,8 +669,8 @@ public function caption_upload( $video_id, $caption_file_url, $language = 'en', * * Sends the URLs of various video text track files to the Dynamic Ingest API for processing. * - * @param string $video_id - * @param BC_Text_Track[] $text_tracks + * @param string $video_id Video id. + * @param BC_Text_Track[] $text_tracks Array of text tracks to upload. * * @return string|bool The ingest request ID or false on failure */ @@ -692,7 +680,7 @@ public function text_track_upload( $video_id, $text_tracks ) { $data['callbacks'] = BC_Notification_API::callback_paths(); $data['text_tracks'] = array(); foreach ( $text_tracks as $track ) { - $data['text_tracks'][] = $track->toArray(); + $data['text_tracks'][] = $track->to_array(); } // Send the data @@ -704,8 +692,8 @@ public function text_track_upload( $video_id, $text_tracks ) { * * Sends a PATCH request to replace existing text tracks. * - * @param string $video_id - * @param BC_Text_Track[] $text_tracks + * @param string $video_id The id of the video to update. + * @param BC_Text_Track[] $text_tracks The text tracks to update. * * @return string|bool The request ID or false on failure. */ @@ -713,7 +701,7 @@ public function text_track_update( $video_id, $text_tracks ) { $data = array(); $data['text_tracks'] = array(); foreach ( $text_tracks as $track ) { - $data['text_tracks'][] = $track->toArrayPatch(); + $data['text_tracks'][] = $track->to_array_patch(); } return $this->send_request( esc_url_raw( self::DI_BASE_URL . $this->get_account_id() . '/videos/' . $video_id ), 'PATCH', $data ); @@ -722,7 +710,7 @@ public function text_track_update( $video_id, $text_tracks ) { /** * Deletes the existing text tracks by sending an empty JSON text_track array * - * @param $video_id + * @param string $video_id The video ID to delete text tracks for. * @return string|bool The request ID or false on failure. */ public function text_track_delete( $video_id ) { @@ -746,8 +734,8 @@ public function video_fields() { /** * Subscribe to Brightcove API events * - * @param string $endpoint - * @param array $events + * @param string $endpoint The endpoint. + * @param array $events Array of event names to subscribe to. * * @return string|bool Subscription ID on success, false on failure */ @@ -772,9 +760,7 @@ public function create_subscription( $endpoint, $events = array() ) { /** * Unsubscribe from Brightcove API events * - * @param string $subscription_id - * - * @return mixed|bool + * @param string $subscription_id The ID of the subscription to delete. */ public function remove_subscription( $subscription_id ) { $subscription_id = sanitize_text_field( $subscription_id ); @@ -810,28 +796,28 @@ public function fetch_folders() { /** * Add/Remove a video from a folder. * - * @param string $oldFolderId The previous folder ID assigned to video. - * @param string $folderId The folder ID that the video should be in. - * @param int $videoId The video ID. + * @param string $old_folder_id The previous folder ID assigned to video. + * @param string $folder_id The folder ID that the video should be in. + * @param int $video_id The video ID. */ - public function add_folder_to_video( $oldFolderId, $folderId, $videoId ) { - if ( '' === $folderId && '' !== $oldFolderId ) { - $this->remove_folder_from_video( $oldFolderId, $videoId ); + public function add_folder_to_video( $old_folder_id, $folder_id, $video_id ) { + if ( '' === $folder_id && '' !== $old_folder_id ) { + $this->remove_folder_from_video( $old_folder_id, $video_id ); return; } - $api_url = self::CMS_BASE_URL . $this->get_account_id() . '/folders/' . $folderId . '/videos/' . $videoId; + $api_url = self::CMS_BASE_URL . $this->get_account_id() . '/folders/' . $folder_id . '/videos/' . $video_id; $this->send_request( esc_url_raw( $api_url ), 'PUT' ); } /** * Remove a video from a folder. * - * @param string $folderId The folder that contains the video. - * @param int $videoId The video ID. + * @param string $folder_id The folder that contains the video. + * @param int $video_id The video ID. */ - protected function remove_folder_from_video( $folderId, $videoId ) { - $api_url = self::CMS_BASE_URL . $this->get_account_id() . '/folders/' . $folderId . '/videos/' . $videoId; + protected function remove_folder_from_video( $folder_id, $video_id ) { + $api_url = self::CMS_BASE_URL . $this->get_account_id() . '/folders/' . $folder_id . '/videos/' . $video_id; $this->send_request( esc_url_raw( $api_url ), 'DELETE' ); } From 594c612c33082f1bb5bea02f84231d382b520844 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:15:46 -0500 Subject: [PATCH 17/66] class-bc-experiences-api.php phpcs fixes --- includes/api/class-bc-experiences-api.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/includes/api/class-bc-experiences-api.php b/includes/api/class-bc-experiences-api.php index 03ba0c71..0d05f06d 100644 --- a/includes/api/class-bc-experiences-api.php +++ b/includes/api/class-bc-experiences-api.php @@ -1,4 +1,9 @@ Date: Thu, 4 Aug 2022 15:15:55 -0500 Subject: [PATCH 18/66] includes/api/class-bc-oauth.php phpcs fixes --- includes/api/class-bc-oauth.php | 72 ++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/includes/api/class-bc-oauth.php b/includes/api/class-bc-oauth.php index 138cb732..aff788d1 100644 --- a/includes/api/class-bc-oauth.php +++ b/includes/api/class-bc-oauth.php @@ -1,4 +1,9 @@ transient_name = BC_Utility::generate_transient_key( 'brightcove_oauth_access_token_', $bc_accounts->get_account_hash() ); - $this->set_account_credentials( $bc_accounts->get_client_id(), $bc_accounts->get_client_secret() ); + $this->set_account_credentials( $bc_accounts->getclient_id(), $bc_accounts->getclient_secret() ); } /** * Sets keys and headers to be used in oAuth calls * - * @param $client_id - * @param $client_secret + * @param string $client_id Client ID + * @param string $client_secret Client Secret */ public function set_account_credentials( $client_id, $client_secret ) { - - $this->_client_id = $client_id; - $this->_client_secret = $client_secret; - $this->_http_headers = array( + $this->client_id = $client_id; + $this->client_secret = $client_secret; + $this->http_headers = array( 'headers' => array( 'Content-type' => 'application/json', - 'Authorization' => sprintf( 'Basic %s', base64_encode( $this->_client_id . ':' . $this->_client_secret ) ), + 'Authorization' => sprintf( 'Basic %s', base64_encode( $this->client_id . ':' . $this->client_secret ) ), // phpcs:ignore ), ); @@ -61,7 +91,7 @@ public function set_account_credentials( $client_id, $client_secret ) { * * @return string|WP_Error */ - public function _request_access_token( $force_new_token = false, $retry = true ) { + public function request_access_token( $force_new_token = false, $retry = true ) { $transient_name = $this->transient_name; @@ -71,13 +101,14 @@ public function _request_access_token( $force_new_token = false, $retry = true ) $endpoint = esc_url_raw( self::ENDPOINT_BASE . '/access_token?grant_type=client_credentials' ); - $request = wp_remote_post( $endpoint, $this->_http_headers ); + $request = wp_remote_post( $endpoint, $this->http_headers ); - if ( '400' == wp_remote_retrieve_response_code( $request ) ) { + if ( 400 === wp_remote_retrieve_response_code( $request ) ) { // Just in case BC_Utility::delete_cache_item( $transient_name ); + // translators: %1$s: client_id, %2$s: client_secret $oauth_error = new WP_Error( 'oauth_access_token_failure', sprintf( __( 'There is a problem with your Brightcove %1$s or %2$s', 'brightcove' ), 'client_id', 'client_secret' ) ); BC_Logging::log( sprintf( 'BC OAUTH ERROR: %s', $oauth_error->get_error_message() ) ); @@ -100,7 +131,7 @@ public function _request_access_token( $force_new_token = false, $retry = true ) return new WP_Error( 'oauth_access_token_response_failure', sprintf( esc_html__( 'oAuth API did not return us an access token', 'brightcove' ) ) ); } - return $this->_request_access_token( $force_new_token, false ); + return $this->request_access_token( $force_new_token, false ); } } @@ -109,9 +140,14 @@ public function _request_access_token( $force_new_token = false, $retry = true ) } + /** + * Checks if the account credentials are valid. + * + * @return bool true if valid, false if not + */ public function is_valid_account_credentials() { - $token = $this->_request_access_token(); + $token = $this->request_access_token(); if ( is_wp_error( $token ) || false === $token ) { return false; From b2976a14591db663000cf91516347d0e88870990 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:16:11 -0500 Subject: [PATCH 19/66] includes/api/class-bc-player-management-api.php phpcs fixes --- .../api/class-bc-player-management-api.php | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/includes/api/class-bc-player-management-api.php b/includes/api/class-bc-player-management-api.php index 6ba6694a..7788276e 100644 --- a/includes/api/class-bc-player-management-api.php +++ b/includes/api/class-bc-player-management-api.php @@ -1,4 +1,9 @@ send_request( $url ); } - public function player_delete() { - } - /** * Retrieve configuration of specific player. * @@ -97,7 +84,7 @@ public function player_get( $player_id, $branch = false ) { $player_id = sanitize_title_with_dashes( $player_id ); - if ( in_array( $branch, array( 'master', 'preview' ) ) ) { + if ( in_array( $branch, array( 'master', 'preview' ), true ) ) { $url = esc_url_raw( self::BASE_URL . $bc_accounts->get_account_id() . '/players/' . $player_id . '/configuration/' . $branch ); } else { $url = esc_url_raw( self::BASE_URL . $bc_accounts->get_account_id() . '/players/' . $player_id . '/configuration' ); @@ -123,7 +110,7 @@ public function player_list( $player_id = '' ) { global $bc_accounts; - if ( '' != $player_id ) { + if ( '' !== $player_id ) { $player_id = utf8_uri_encode( sanitize_text_field( $player_id ) ) . '/embeds'; } @@ -225,7 +212,6 @@ public function player_config_update( $player_id, $autoplay = false, $media = ar if ( is_array( $media ) ) { $data->media = new stdClass(); - // $data->media = (object) $media; foreach ( $media as $key => $val ) { $data->media->key = is_array( $val ) ? (object) $val : $val; } From 898975cc80b82c5bebbe3ddadf087993ede05cf2 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:16:27 -0500 Subject: [PATCH 20/66] includes/api/class-bc-player-management-api2.php phpcs fixes --- includes/api/class-bc-player-management-api2.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/includes/api/class-bc-player-management-api2.php b/includes/api/class-bc-player-management-api2.php index f44ab6e1..eda1837b 100644 --- a/includes/api/class-bc-player-management-api2.php +++ b/includes/api/class-bc-player-management-api2.php @@ -1,4 +1,9 @@ Date: Thu, 4 Aug 2022 15:16:39 -0500 Subject: [PATCH 21/66] includes/api/class-bc-text-track.php phpcs fixes --- includes/api/class-bc-text-track.php | 64 +++++++++++++++++----------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/includes/api/class-bc-text-track.php b/includes/api/class-bc-text-track.php index 1cb68b77..d1742d23 100644 --- a/includes/api/class-bc-text-track.php +++ b/includes/api/class-bc-text-track.php @@ -1,52 +1,68 @@ url = esc_url_raw( $url ); - $this->srcLang = sanitize_text_field( $language ); + $this->url = esc_url_raw( $url ); + $this->src_lang = sanitize_text_field( $language ); if ( ! in_array( $kind, array( 'captions', 'subtitles', 'descriptions', 'chapters', 'metadata' ), true ) ) { $this->kind = 'captions'; } else { @@ -61,12 +77,12 @@ public function __construct( $url, $language = 'en-US', $kind = 'captions', $lab * * @return array */ - public function toArray() { + public function to_array() { $data = array( - 'url' => $this->url, - 'srclang' => $this->srcLang, - 'kind' => $this->kind, - 'default' => $this->default, + 'url' => $this->url, + 'src_lang' => $this->src_lang, + 'kind' => $this->kind, + 'default' => $this->default, ); if ( ! empty( $this->label ) ) { @@ -81,13 +97,13 @@ public function toArray() { * * @return array Data to submit. */ - public function toArrayPatch() { + public function to_array_patch() { $data = array( 'src' => $this->url, - 'srclang' => $this->srcLang, + 'src_lang' => $this->src_lang, 'kind' => $this->kind, 'default' => $this->default, - 'mime_type' => $this->mimeType, + 'mime_type' => $this->mime_type, ); if ( ! empty( $this->label ) ) { From dad8c04333a4e57d602cdc770ac6ee6c41166f43 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:16:48 -0500 Subject: [PATCH 22/66] includes/class-bc-accounts.php phpcs fixes --- includes/class-bc-accounts.php | 152 ++++++++++++++++++++++++++++++--- 1 file changed, 142 insertions(+), 10 deletions(-) diff --git a/includes/class-bc-accounts.php b/includes/class-bc-accounts.php index c65fb470..a97d2c52 100644 --- a/includes/class-bc-accounts.php +++ b/includes/class-bc-accounts.php @@ -1,4 +1,9 @@ original_account = $this->get_account_details_for_user(); $this->current_account = $this->original_account; } + /** + * Get all the account ids + * + * @return array + */ public function get_all_accounts_id() { $all_accounts = $this->get_all_accounts(); $account_ids = array(); @@ -45,31 +68,61 @@ public function get_all_accounts_id() { return $account_ids; } + /** + * Get account id + * + * @return false|mixed + */ public function get_account_id() { return $this->current_account ? $this->current_account['account_id'] : false; } + /** + * Get client id + * + * @return false|mixed + */ public function get_client_id() { return $this->current_account ? $this->current_account['client_id'] : false; } + /** + * Retrieves client secret. + * + * @return false|mixed + */ public function get_client_secret() { - return $this->current_account ? $this->current_account['client_secret'] : false; } + /** + * Get the account name. + * + * @return false|mixed + */ public function get_account_name() { return $this->current_account ? $this->current_account['account_name'] : false; } + /** + * Get the account hash. + * + * @return false|mixed + */ public function get_account_hash() { return $this->current_account ? $this->current_account['hash'] : false; } + /** + * Get the sync type + * + * @param string|int $account_id The account ID to get the sync type for. If not provided, the current account is used. + * @return false|mixed|void + */ public function get_sync_type( $account_id ) { $option_key_sync_type = '_brightcove_sync_type_' . BC_Utility::sanitize_id( $account_id ); @@ -77,6 +130,14 @@ public function get_sync_type( $account_id ) { return get_option( $option_key_sync_type, 'full' ); } + /** + * Set the sync type for an account + * + * @param int|string $account_id The account ID + * @param string $type The sync type to set + * @param int $hours The number of hours to sync + * @return bool + */ public function set_sync_type( $account_id, $type, $hours = 0 ) { $option_key_sync_type = '_brightcove_sync_type_' . BC_Utility::sanitize_id( $account_id ); @@ -90,6 +151,17 @@ public function set_sync_type( $account_id, $type, $hours = 0 ) { return update_option( $option_key_sync_type, $sync_val ); } + /** + * Add an account. + * + * @param int|string $account_id The account ID. + * @param int $client_id The client ID. + * @param string $client_secret The client secret. + * @param string $account_name The account name. + * @param string $set_default Whether to set this account as the default. + * @param bool $allow_update Whether to allow updates to the account. + * @return bool|WP_Error + */ public function add_account( $account_id, $client_id, $client_secret, $account_name = '', $set_default = '', $allow_update = true ) { if ( empty( $account_name ) ) { @@ -168,6 +240,12 @@ public function add_account( $account_id, $client_id, $client_secret, $account_n } + /** + * Delete an account + * + * @param string $hash The hash of the account to delete + * @return bool|WP_Error + */ public function delete_account( $hash ) { if ( ! self::get_account_by_hash( $hash ) ) { @@ -195,7 +273,7 @@ public function delete_account( $hash ) { unset( $all_accounts[ $hash ] ); - if ( $hash === get_option( '_brightcove_default_account' ) ) { + if ( get_option( '_brightcove_default_account' ) === $hash ) { if ( ! empty( $all_accounts ) ) { @@ -222,7 +300,9 @@ public function delete_account( $hash ) { } /** - * @param $hash + * Get account by hash + * + * @param string $hash The hash of the account to get. * * @return false | array keys: 'account_id', 'account_name', 'client_id', 'client_secret' */ @@ -230,7 +310,7 @@ public function get_account_by_hash( $hash ) { $all_accounts = $this->get_all_accounts(); - if ( is_array( $all_accounts ) && is_string( $hash ) && $hash !== '' && isset( $all_accounts[ $hash ] ) ) { + if ( is_array( $all_accounts ) && is_string( $hash ) && '' !== $hash && isset( $all_accounts[ $hash ] ) ) { return $all_accounts[ $hash ]; } @@ -238,9 +318,11 @@ public function get_account_by_hash( $hash ) { } /** + * Get account details + * * @param bool $user_id (default is current ID) * - * @return $account if exists or false if no accounts or permission denied. + * @return array $account if exists or false if no accounts or permission denied. */ public function get_account_details_for_user( $user_id = false ) { @@ -271,6 +353,13 @@ public function get_account_details_for_user( $user_id = false ) { return current( $accounts ); } + /** + * Set account details for default account + * + * @param string $hash hash of account to set as default + * @param int|bool $user_id (default is current ID) + * @return false|void + */ public function set_account_details_for_user( $hash, $user_id = false ) { if ( ! $user_id ) { @@ -315,6 +404,12 @@ public function set_current_account( $hash ) { } + /** + * Set the current account to the default account for the site. + * + * @param int $account_id the account ID to set as the default. + * @return array|bool + */ public function set_current_account_by_id( $account_id ) { $accounts = $this->get_all_accounts(); @@ -353,6 +448,12 @@ public function restore_default_account() { } + /** + * Set the current account to the default account. + * + * @param string $hash The account hash + * @return false|void + */ public function set_account_details_for_site( $hash ) { if ( ! current_user_can( 'brightcove_set_site_default_account' ) ) { @@ -364,6 +465,11 @@ public function set_account_details_for_site( $hash ) { } } + /** + * Get the current account + * + * @return array|false + */ public function get_account_details_for_site() { $account = $this->get_account_by_hash( get_option( '_brightcove_default_account' ) ); @@ -375,11 +481,21 @@ public function get_account_details_for_site() { } + /** + * Get all the accounts + * + * @return false|mixed|void + */ protected function get_all_accounts() { return get_option( $this->options_key, array() ); } + /** + * Get sanitized accounts + * + * @return false|mixed|void + */ public function get_sanitized_all_accounts() { $accounts = $this->get_all_accounts(); @@ -394,17 +510,23 @@ public function get_sanitized_all_accounts() { return $accounts; } + /** + * Update the account details for a given account hash. + * + * @param string $account The account hash + * @return false|mixed|string + */ public function make_account_change( $account ) { $attributes = array( 'account_id', 'account_name', 'client_id', 'client_secret', 'set_default', 'operation' ); foreach ( $attributes as $key ) { - if ( ! is_string( $account[ $key ] ) && $account['operation'] !== 'update' ) { + if ( ! is_string( $account[ $key ] ) && 'update' !== $account['operation'] ) { return false; } } - if ( isset( $account['account_hash'] ) && $account['account_hash'] !== '' ) { + if ( isset( $account['account_hash'] ) && '' !== $account['account_hash'] ) { $hash = $account['account_hash']; } else { $hash = BC_Utility::get_hash_for_account( $account ); @@ -416,7 +538,7 @@ public function make_account_change( $account ) { $operation = $account['operation']; - if ( $operation === 'delete' ) { + if ( 'delete' === $operation ) { if ( isset( $existing_accounts[ $hash ] ) ) { unset( $existing_accounts[ $hash ] ); @@ -443,7 +565,7 @@ public function make_account_change( $account ) { } $operation = $account['operation']; unset( $account['operation'] ); // Remove the operation from stored value - if ( $operation !== 'update' ) { + if ( 'update' !== $operation ) { $existing_accounts[ $hash ] = $account; // Add / update the account. /** @@ -524,6 +646,16 @@ protected function check_permissions_level() { return $permission_issues; } + /** + * Checks if account is valid + * + * @param int $account_id Account ID. + * @param int $client_id Client ID. + * @param string $client_secret Client secret. + * @param string $account_name Account name. + * @param bool $check_access Whether to check access. + * @return array|bool + */ protected function is_valid_account( $account_id, $client_id, $client_secret, $account_name, $check_access = true ) { // Save current account as $old_account. From 67da919a6cbcc0f5369812b2727d77545dd92020 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:16:58 -0500 Subject: [PATCH 23/66] includes/class-bc-errors.php phpcs fixes --- includes/class-bc-errors.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/includes/class-bc-errors.php b/includes/class-bc-errors.php index 0574b243..3ebddf2b 100644 --- a/includes/class-bc-errors.php +++ b/includes/class-bc-errors.php @@ -1,5 +1,13 @@ '; } - echo $html; + echo $html; // phpcs:ignore } } From df0fd2b0bb915f3cb69467f4a8ebba5760c23e42 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:17:08 -0500 Subject: [PATCH 24/66] includes/class-bc-experiences-shortcode.php phpcs fixes --- includes/class-bc-experiences-shortcode.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/class-bc-experiences-shortcode.php b/includes/class-bc-experiences-shortcode.php index 6281d3c1..10698a4b 100644 --- a/includes/class-bc-experiences-shortcode.php +++ b/includes/class-bc-experiences-shortcode.php @@ -1,5 +1,13 @@ '', 'account_id' => '', From 9808c3005df833e98c4111ef9e61816ddd70e035 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Thu, 4 Aug 2022 15:17:18 -0500 Subject: [PATCH 25/66] includes/class-bc-in-page-experience-shortcode.php phpcs fixes --- includes/class-bc-in-page-experience-shortcode.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/class-bc-in-page-experience-shortcode.php b/includes/class-bc-in-page-experience-shortcode.php index caa383ff..7766bb8c 100644 --- a/includes/class-bc-in-page-experience-shortcode.php +++ b/includes/class-bc-in-page-experience-shortcode.php @@ -1,4 +1,9 @@
- +