Skip to content

Commit

Permalink
Merge pull request #109 from 10up/develop
Browse files Browse the repository at this point in the history
Version 1.6.0
  • Loading branch information
Allan Collins authored Sep 19, 2018
2 parents 99a7be9 + ffed5d3 commit a7cad1f
Show file tree
Hide file tree
Showing 17 changed files with 530 additions and 237 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function ( grunt ) {

const sass = require('node-sass');
// Start out by loading the grunt modules we'll need
require ( 'load-grunt-tasks' ) ( grunt );

Expand Down Expand Up @@ -46,6 +46,7 @@ module.exports = function ( grunt ) {
production : {

options : {
implementation: sass,
style : 'expanded',
noCache : true
},
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ http://httpd.apache.org/docs/current/mod/core.html#limitrequestbody (LimitReques

## Changelog

##### 1.6.0

* Enhancement: Gutenberg support.
* Fix: Fixed a bug causing video previews not to show.
* Fix: Fixed a bug causing playlist videos to not be listed.
* Fix: Update to the 'brightcove_media_query_results' filter to allow $processed_results to be used.
* Fix: Removal of deprecated options for Plupload.
* Fix: Adding last two parameters to add_action to remove PHP 7.2 warnings.
* Fix: Removal of hardcoded video page height.

##### 1.5.0

* Enhancement: Video Experience player.
Expand Down
1 change: 0 additions & 1 deletion assets/css/brightcove_video_connect.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ div.brightcove-uploader div.brightcove-messages .updated {
border-right: 1px solid #ddd;
border-top: none;
position: static;
height: 600px;
width: calc(100% - 370px);
float: left;
margin-right: 30px;
Expand Down
2 changes: 1 addition & 1 deletion assets/css/brightcove_video_connect.min.css

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion assets/js/brightcove-admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/js/brightcove-admin.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/brightcove-admin.min.js

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions assets/js/src/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/* global wp, bctiny, bcBlock */

( function( blocks, element, components, editor ) {
var el = element.createElement,
registerBlockType = blocks.registerBlockType,
Placeholder = components.Placeholder,
BlockControls = editor.BlockControls,
IconButton = components.IconButton,
userPermission = !!bcBlock.userPermission;

registerBlockType( 'bc/brightcove', {
title: 'Brightcove',
description: 'The Brightcove block allows you to embed videos from Brightcove.',
icon: 'video-alt3',
category: 'common',
supports: {
inserter: userPermission,
html: false
},

edit: function( props ) {
// Set the field we want to target
var target = 'brightcove-' + props.id;

// Attributes needed to render
var accountId = props.attributes.account_id || '';
var playerId = props.attributes.player_id || '';
var videoId = props.attributes.video_id || '';
var playlistId = props.attributes.playlist_id || '';
var experienceId = props.attributes.experience_id || '';
var videoIds = props.attributes.video_ids || '';
var height = props.attributes.height || '';
var width = props.attributes.width || '';
var minWidth = props.attributes.min_width || '';
var maxWidth = props.attributes.max_width || '';
var paddingTop = props.attributes.padding_top || '';
var autoplay = props.attributes.autoplay || '';
var embed = props.attributes.embed || '';

// Sanitize the IDs we need
var sanitizeIds = function( id ) {
return id.replace( /\D/g, '' );
};

/**
* Set attributes when a video is selected.
*
* Listens to the change event on our hidden
* input and will grab the shortcode from the
* inputs value, parsing out the attributes
* we need and setting those as props.
*/
var onSelectVideo = function() {
var btn = document.getElementById( target );
var attrs = wp.shortcode.attrs( btn.value );
var setAttrs = {
account_id: sanitizeIds( attrs.named.account_id ),
player_id: '',
video_id: '',
playlist_id: '',
experience_id: '',
video_ids: '',
height: attrs.named.height,
width: attrs.named.width,
min_width: attrs.named.min_width,
max_width: attrs.named.max_width,
padding_top: '',
autoplay: '',
embed: attrs.named.embed
};

if ( '[bc_video' === attrs.numeric[0] ) {
setAttrs.player_id = attrs.named.player_id;
setAttrs.video_id = sanitizeIds( attrs.named.video_id );
setAttrs.autoplay = attrs.named.autoplay;
setAttrs.padding_top = attrs.named.padding_top;
} else if ( '[bc_playlist' === attrs.numeric[0] ) {
setAttrs.player_id = attrs.named.player_id;
setAttrs.playlist_id = sanitizeIds( attrs.named.playlist_id );
setAttrs.autoplay = attrs.named.autoplay;
setAttrs.padding_top = attrs.named.padding_top;
} else if ( '[bc_experience' === attrs.numeric[0] ) {
setAttrs.experience_id = attrs.named.experience_id;

if ( 'undefined' !== typeof attrs.named.video_ids ) {
setAttrs.video_ids = sanitizeIds( attrs.named.video_ids );
} else {
setAttrs.playlist_id = sanitizeIds( attrs.named.playlist_id );
}
}

props.setAttributes( setAttrs );
};

// Listen for a change event on our hidden input
jQuery( document ).on( 'change', '#' + target, onSelectVideo );

// Set up our controls
var controls = el(
BlockControls,
{ key: 'controls' },
el( 'div', { className: 'components-toolbar' },
el(
IconButton,
{
className: 'brightcove-add-media components-icon-button components-toolbar__control',
label: videoId.playlist_id ? 'Change Playlist' : 'Change Video',
icon: 'edit',
'data-target': '#' + target
}
)
)
);

// If no video has been selected yet, show the selection view
if ( ! accountId.length && ( ! playerId.length || ! experienceId.length ) && ( ! videoId.length || ! playlistId.length || videoIds.length ) ) {
return el( Placeholder, {
icon: 'media-video',
label: 'Brightcove',
instructions: userPermission ? 'Select a video file or playlist from your Brightcove library' : 'You don\'t have permissions to add Brightcove videos.',
children: [
userPermission ? el( 'button', { className: 'brightcove-add-media button button-large', 'data-target': '#' + target, key: 'button' }, 'Brightcove Media' ) : '',
el( 'input', { id: target, hidden: true, key: 'input' } )
]
} );

// Otherwise render the shortcode
} else {
var src = '';

if ( experienceId.length ) {
var urlAttrs = '';
if ( videoIds.length ) {
urlAttrs = 'videoIds=' + videoIds;
} else {
urlAttrs = 'playlistId=' + playlistId;
}
src = '//players.brightcove.net/' + accountId + '/experience_' + experienceId + '/index.html?' + urlAttrs;
} else if ( videoId.length ) {
src = '//players.brightcove.net/' + accountId + '/' + playerId + '_default/index.html?videoId=' + videoId;
} else {
playerId = bctiny.playlistEnabledPlayers[ accountId ][0] || 'default';
src = '//players.brightcove.net/' + accountId + '/' + playerId + '_default/index.html?playlistId=' + playlistId;
}

if ( 'undefined' === typeof height ) {
height = 250;
}

if ( 'undefined' === typeof width ) {
width = 500;
}

return [
userPermission ? controls : '',
el( 'iframe', { src: src, style: { height: height, width: width, display: 'block', margin: '0 auto' }, allowFullScreen: true, key: 'iframe' } ),
el( 'input', { id: target, hidden: true, key: 'input' } )
];
}
},

save: function() {
return null;
}

} );

} )( window.wp.blocks, window.wp.element, window.wp.components, window.wp.editor );
4 changes: 3 additions & 1 deletion assets/js/src/views/video-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ var VideoPreviewView = BrightcoveView.extend( {
method: 'POST',
data: {
'action':'bc_resolve_shortcode',
'shortcode': this.shortcode
'shortcode': this.shortcode,
'video_id' : options.id,
'account_id': options.account_id,
},
success: function( results ) {
that.$el.html( results.data );
Expand Down
1 change: 0 additions & 1 deletion assets/scss/components/_video-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
border-right: 1px solid #ddd;
border-top : none;
position : static;
height: 600px;
width: calc(100% - 370px);
float: left;
margin-right: 30px;
Expand Down
4 changes: 2 additions & 2 deletions brightcove-video-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Brightcove Video Connect
* Plugin URI: https://wordpress.org/plugins/brightcove-video-connect/
* Description: A Brightcove™ Connector for WordPress that leverages enhanced APIs and Brightcove™ Capabilities
* Version: 1.5.0
* Version: 1.6.0
* Author: 10up
* Author URI: http://10up.com
* License: GPLv2+
Expand All @@ -29,7 +29,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 021.0.2301 USA
*/

define( 'BRIGHTCOVE_VERSION', '1.4.1' );
define( 'BRIGHTCOVE_VERSION', '1.6.0' );
define( 'BRIGHTCOVE_URL', plugin_dir_url( __FILE__ ) );
define( 'BRIGHTCOVE_PATH', dirname( __FILE__ ) . '/' );
define( 'BRIGHTCOVE_BASENAME', plugin_basename( __FILE__ ) );
Expand Down
17 changes: 12 additions & 5 deletions includes/admin/api/class-bc-admin-media-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function __construct() {
add_action( 'wp_ajax_bc_media_update', array( $this, 'bc_ajax_update_video_or_playlist' ) );
add_action( 'wp_ajax_bc_media_delete', array( $this, 'bc_ajax_delete_video_or_playlist' ) );
add_action( 'wp_ajax_bc_media_upload', array( $this, 'brightcove_media_upload' ) ); // For uploading a file.
add_action( 'wp_ajax_bc_poster_upload', array( $this, 'ajax_poster_upload' ) );
add_action( 'wp_ajax_bc_thumb_upload', array( $this, 'ajax_thumb_upload' ) );
add_action( 'wp_ajax_bc_caption_upload', array( $this, 'ajax_caption_upload' ) );
add_action( 'wp_ajax_bc_poster_upload', array( $this, 'ajax_poster_upload' ), 10, 5 );
add_action( 'wp_ajax_bc_thumb_upload', array( $this, 'ajax_thumb_upload' ), 10, 5 );
add_action( 'wp_ajax_bc_caption_upload', array( $this, 'ajax_caption_upload' ), 10, 3 );
add_action( 'wp_ajax_bc_media_players', array( $this, 'ajax_players' ) );
add_filter( 'heartbeat_received', array( $this, 'heartbeat_received' ), 10, 2 );
add_filter( 'brightcove_media_query_results', array( $this, 'add_in_process_videos' ), 10, 2 );
Expand All @@ -63,7 +63,14 @@ public function __construct() {
}

public function resolve_shortcode() {
$shortcode = stripslashes( sanitize_text_field( $_POST['shortcode'] ) );

$video_id = ( ! empty( $_POST['video_id'] ) ) ? sanitize_text_field( wp_unslash( $_POST['video_id'] ) ) : 0;
$account_id = ( ! empty( $_POST['account_id'] ) ) ? sanitize_text_field( wp_unslash( $_POST['account_id'] ) ) : 0;

$default_shortcode = '[bc_video video_id="' . absint($video_id) . '" account_id="' . absint($account_id) . '" player_id="default" embed="iframe" padding_top="56%" autoplay="" min_width="0px" max_width="640px" mute="" width="100%" height="100%"]';

// If no shortcode was supplied, let's show a default one.
$shortcode = ( ! empty( $_POST['shortcode'] ) ) ? sanitize_text_field( wp_unslash( $_POST['shortcode'] ) ) : $default_shortcode;

wp_send_json_success( do_shortcode( $shortcode ) );
}
Expand Down Expand Up @@ -722,7 +729,7 @@ public function brightcove_media_query() {
*
* @since 1.3
*/
$results = apply_filters( 'brightcove_media_query_results', $results, $type );
$results = apply_filters( 'brightcove_media_query_results', $processed_results, $type );

wp_send_json_success( $results );
}
Expand Down
21 changes: 19 additions & 2 deletions includes/api/class-bc-cms-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ public function playlist_list() {

}

/**
* Retrieve a playlist videos
*
* Retrieves a specified playlist videos from the CMS API.
*
* @since 1.4.2
*
* @param string $playlist_id the id of the requested playlist.
* @return array|bool array of the video information retrieved or false if error.
*/
public function playlist_get_videos( $playlist_id ) {
$playlist_id = sanitize_title_with_dashes( $playlist_id );
return $this->send_request( esc_url_raw( self::CMS_BASE_URL . $this->get_account_id() . '/playlists/' . $playlist_id . '/videos' ) );
}

/**
* Update a playlist in the Brightcove Video Cloud
*
Expand Down Expand Up @@ -426,9 +441,11 @@ public function video_list( $limit = 20, $offset = 0, $query = '', $sort = '-cre
$args['q'] = sanitize_text_field( $query );

}
// rawurlencode will convert spaces to %20, and plus signs to %2b, which is required according to BC API Docs.

$args = array_map( 'rawurlencode', $args );
if ( false === strpos( $args['q'], 'id:' ) ) {
$args = array_map( 'urlencode', $args );
}


$url = add_query_arg(
$args,
Expand Down
Loading

0 comments on commit a7cad1f

Please sign in to comment.