Skip to content

Commit

Permalink
* Basic kaltura playlist iframe support ( does not do fancy iframe ca…
Browse files Browse the repository at this point in the history
…che of payload like single player ( but basically working )

** adjusted flashvars passing 
** added postEmbedJS test for presence of vid tag in nativeEmbed
* Removed integrationTest folder ( to be hosted outside of the svn ) 
* Updated localSettings.php.sample to include mention of   wgAllowCustomResourceIncludes configuration option ( disabled by default ) 
** Custom resource injection since it allows resource injection, and if your KMC accounts were not sequre and you are not running the html5 on a separate subdomain, could result in XSS issues.   

git-svn-id: http://www.kaltura.org/kalorg/html5video/trunk/mwEmbed@2037 b58a29cf-3064-46da-94c6-1c29cc75c8e5
  • Loading branch information
KalturaGitBot committed May 26, 2011
1 parent 91204e1 commit 30454a5
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 63 deletions.
10 changes: 9 additions & 1 deletion LocalSettings.php.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ $wgEnableIframeApi = true;

$wgEnableIpadHTMLControls = true;
$wgKalturaUseManifestUrls = true;
$wgAllowRemoteKalturaService = true;

// Allows remote kaltura service queries from php ( usefull for onPrem or CE editions using the iframe )
$wgAllowRemoteKalturaService = false;

// Allows custom resources to be loaded from the ui-conf, useful for custom plugins,
// DO NOT enable this if you have other services on the same domain as the iframe as it essentially
// allows any ui-conf user to include javascript on the iframe player page
$wgAllowCustomResourceIncludes = false;


$wgMwEmbedEnabledModules = array( 'EmbedPlayer', 'KalturaSupport', 'AdSupport', 'Playlist', 'TimedText', 'FreeWheel' );
?>
3 changes: 3 additions & 0 deletions includes/DefaultSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@

$wgKalturaUseManifestUrls = true;

// By default do not allow custom resource includes.
$wgAllowCustomResourceIncludes = false;

/*********************************************************
* Include local settings override:
********************************************************/
Expand Down
3 changes: 3 additions & 0 deletions modules/EmbedPlayer/mw.EmbedPlayerNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ mw.EmbedPlayerNative = {

// Setup local pointer:
var vid = this.getPlayerElement();
if(!vid){
return ;
}
// Apply media element bindings:
this.applyMediaElementBindings();

Expand Down
14 changes: 10 additions & 4 deletions modules/KalturaSupport/KalturaGetResultObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class KalturaGetResultObject {
var $resultObj = null; // lazy init with getResultObject
var $clientTag = null;

var $isPlaylist = null; // if the current request object is a playlist


// Local flag to store whether output was came from cache or was a fresh request
private $outputFromCache = false;

Expand All @@ -28,6 +25,7 @@ class KalturaGetResultObject {
'uiconf_id' => null,
'entry_id' => null,
'flashvars' => null,
'playlist_id' => null,
);

function __construct( $clientTag = 'php'){
Expand Down Expand Up @@ -63,7 +61,10 @@ public static function getErrorVideoSources(){
)
);
}

// check if the requested url is a playlist
public function isPlaylist(){
return ( $this->urlParameters['playlist_id'] !== null );
}
public function isCachedOutput(){
return $this->outputFromCache;
}
Expand Down Expand Up @@ -144,6 +145,11 @@ public function isAccessControlAllowed( &$resultObject = null ) {

$accessControl = $resultObject['accessControl'];

// Check if we had no access control due to playlist
if( is_array( $accessControl ) && isset( $accessControl['code'] ) && $accessControl['code'] == 'MISSING_MANDATORY_PARAMETER' ){
return true;
}

// Checks if admin
if( $accessControl->isAdmin ) {
return true;
Expand Down
90 changes: 58 additions & 32 deletions modules/KalturaSupport/kalturaIframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function getVideoHTML( ){
$this->getResultObject()->getPartnerId() . '00/thumbnail/' .
'entry_id/' . $this->getResultObject()->getEntryId() .
'/height/480';
try{
try {
$sources = $this->getResultObject()->getSources();
} catch ( Exception $e ){
$this->fatalError( $e->getMessage() );
Expand Down Expand Up @@ -174,18 +174,23 @@ private function getVideoHTML( ){
*/
private function getFlashEmbedHTML( $childHTML = '' ){
return $this->getPreFlashVars() .
$this->getDefaultFlashVars() .
$this->getFlashVarsString() .
$this->getPostFlashVars( $childHTML );
}
private function getDefaultFlashVars(){
return 'externalInterfaceDisabled=false';
private function getFlashVarsString(){
// output the escaped flash vars from get arguments
$s = 'externalInterfaceDisabled=false';
foreach( $_REQUEST['flashvars'] as $key=>$val ){
$s.= '&' . htmlspecialchars( $key ) . '=' . urlencode( $val );
}
return $s;
}
/**
* Get custom player includes for css and javascript
*/
private function getCustomPlayerIncludesJSON(){
if( ! $this->getResultObject()->getUiConf() ){
return '';
return false;
}
$xml = new SimpleXMLElement( $this->getResultObject()->getUiConf() );
$resourceIncludes = array();
Expand Down Expand Up @@ -217,6 +222,7 @@ private function getCustomPlayerConfig(){
foreach ($xml->uiVars->var as $var ){
if( isset( $var['key'] ) && isset( $var['value'] ) &&
$var['key'] != 'HTML5PluginUrl' && $var['key'] != 'HTML5PlayerCssUrl'
&& $var['key'] != 'Mw.CustomResourceIncludes'
){

$o.="mw.setConfig('" . htmlspecialchars($var['key'] ) . "', ";
Expand Down Expand Up @@ -246,7 +252,10 @@ private function getSwfUrl(){
}

private function getPreFlashVars(){
return '<object id="kaltura_player_iframe_no_rewrite" name="kaltura_player" ' .
// Check if a playlist
$playerId = ( $this->getResultObject()->isPlaylist() ) ? 'kaltura_player' : 'kaltura_player_iframe_no_rewrite';

return '<object id="' . $playerId . '" name="kaltura_player" ' .
'type="application/x-shockwave-flash" allowFullScreen="true" '.
'allowNetworking="all" allowScriptAccess="always" height="100%" width="100%" style="height:100%;width:100%" '.
'xmlns:dc="http://purl.org/dc/terms/" '.
Expand Down Expand Up @@ -374,7 +383,6 @@ private function outputIframeHeadCss(){
</style>
<?php
}

function outputIFrame( ){
global $wgMwEmbedPathUrl;

Expand All @@ -396,10 +404,15 @@ function outputIFrame( ){
</script>

<script type="text/javascript">
mw.setConfig( 'Mw.CustomResourceIncludes', <?php echo $this->getCustomPlayerIncludesJSON() ?>);

// try to set custom global vars for this player:
<?php echo $this->getCustomPlayerConfig() ?>
<?php
global $wgAllowCustomResourceIncludes;
if( $wgAllowCustomResourceIncludes && $this->getCustomPlayerIncludesJSON() ){
echo 'mw.setConfig( \'Mw.CustomResourceIncludes\', '. $this->getCustomPlayerIncludesJSON() .' );';
}
// Set custom global vars for this player:
echo $this->getCustomPlayerConfig();
?>


// Don't do an iframe rewrite inside an iframe!
mw.setConfig( 'Kaltura.IframeRewrite', false );
Expand All @@ -416,7 +429,7 @@ function outputIFrame( ){
mw.setConfig( 'EmbedPlayer.WaitForMeta', false );

// Add Packaging Kaltura Player Data ( JSON Encoded )
mw.setConfig('KalturaSupport.BootstrapPlayerData', <?php echo $this->getResultObject()->getJSON(); ?>);
mw.setConfig( 'KalturaSupport.BootstrapPlayerData', <?php echo $this->getResultObject()->getJSON(); ?>);

// Parse any configuration options passed in via hash url:
var hashString = document.location.hash;
Expand Down Expand Up @@ -450,13 +463,36 @@ function outputIFrame( ){

// Identify the player as an iframe player
mw.setConfig( "EmbedPlayer.IsIframePlayer", true );

if( kIsHTML5FallForward() ){
// Don't confuse the rewrite engine ( remove the kaltura swf )
var el = document.getElementById('kaltura_player_iframe_no_rewrite');
if( el )
el.parentNode.removeChild( el );


<?php
if( !$this->getResultObject()->isPlaylist() ){
echo $this->javascriptPlayerLogic();
}
?>
</script>
</head>
<body>
<?php
if( $this->getResultObject()->isPlaylist() ){
echo "<!-- Playlist is rewriteen from flash object ( no standard html5 representation atm ) -->\n";
// if playlist just output the playlist object and let javascript rewrite it:
echo $this->getFlashEmbedHTML() . "\n";
}else {
?>
<div id="videoContainer" >
<div id="iframeLoadingSpinner" class="loadingSpinner"></div>
<?php echo $this->getVideoHTML(); ?>
</div>
<?php
}
?>
</body>
</html>
<?php
}
private function javaScriptPlayerLogic(){
?>
if( kIsHTML5FallForward() ){
// Load the mwEmbed resource library and add resize binding
mw.ready(function(){
var embedPlayer = $j( '#<?php echo htmlspecialchars( $this->playerIframeId )?>' ).get(0);
Expand All @@ -478,7 +514,6 @@ function outputIFrame( ){
});
});
} else {

// Remove the video tag and output a clean "object" or file link
// ( if javascript is off the child of the video tag so would be played,
// but rewriting gives us flexiblity in in selection criteria as
Expand All @@ -489,7 +524,7 @@ function outputIFrame( ){

if( kSupportsFlash() || mw.getConfig( 'Kaltura.ForceFlashOnDesktop' ) ){
// Build the flash vars string
var flashVarsString = '<?php echo $this->getDefaultFlashVars() ?>';
var flashVarsString = '<?php echo $this->getFlashVarsString() ?>';
var flashVars = mw.getConfig('Kaltura.Flashvars');
if( flashVars ){
var and = '';
Expand Down Expand Up @@ -529,17 +564,8 @@ function outputIFrame( ){
return true;
};
}
}
</script>
</head>
<body>
<div id="videoContainer" >
<div id="iframeLoadingSpinner" class="loadingSpinner"></div>
<?php echo $this->getVideoHTML(); ?>
</div>
</body>
</html>
<?php
}
<?php
}
/**
* Very simple error handling for now:
Expand Down
37 changes: 22 additions & 15 deletions modules/KalturaSupport/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@
}
var kEmbedSettings = mw.getKalturaEmbedSettings( swfSource, flashvars );

// check if its a playlist or a entryId
mw.log("Got kEmbedSettings.entryId: " + kEmbedSettings.entry_id + " uiConf: " + kEmbedSettings.uiconf_id);
// Check if its a playlist or a entryId
mw.log( "Got kEmbedSettings.entryId: " + kEmbedSettings.entry_id + " uiConf: " + kEmbedSettings.uiconf_id);
var height = $j( element ).attr('height');
var width = $j( element ).attr('width');

// Check that the id is unique per player embed instance ( else give it a vid_{inx} id:
var videoId = $j( element ).attr('id');
$j('.mwEmbedKalturaVideoSwap,.mwEmbedKalturaPlaylistSwap').each(function( inx, swapElement){
Expand Down Expand Up @@ -172,8 +171,8 @@
'src' : thumb_url
})
.css({
'width' : width + 'px',
'height' : height + 'px',
'width' : width,
'height' : height,
'position' : 'absolute',
'top' : '0px',
'left' : '0px'
Expand All @@ -183,7 +182,8 @@
// Assume playlist
loadPlaylistFlag = true;
kalturaSwapObjectClass = 'mwEmbedKalturaPlaylistSwap';
// check if we can get the playlist id from a url in the embed code

// Check if we can get the playlist id from a url in the embed code
// ( some version of kaltura embed code work this way)
if( flashvars['playlistAPI.kpl0Url'] ){
videoEmbedAttributes['kplaylistid'] = mw.parseUri( flashvars['playlistAPI.kpl0Url'] ).queryKey['playlist_id'];
Expand All @@ -192,18 +192,20 @@
}
}
}

// Replace with a mwEmbedKalturaVideoSwap
$j( element ).replaceWith(
$j('<div />')
.attr( videoEmbedAttributes )
.css( {
'width' : width + 'px',
'height' : height + 'px',
'width' : width,
'height' : height,
'position': 'relative',
'display' : 'block',
'float' : 'left',
'padding' : '3px'
} )
.data( 'flashvars', flashvars )
.addClass( kalturaSwapObjectClass )
.append(
$imgThumb,
Expand Down Expand Up @@ -250,11 +252,16 @@
kParams[ iframeRequestMap[tagKey] ] = $j(playerTarget).attr( tagKey );
}
}
// XXX UGLY TEMPORARY HACK ( don't use iframe for playlist )
if( kParams['entry_id'] ){
iframeRewriteCount++;
$j( playerTarget ).removeClass('mwEmbedKalturaVideoSwap').kalturaIframePlayer( kParams, doneWithIframePlayer);
if( $j( playerTarget).data('flashvars') ){
kParams['flashvars'] = $j( playerTarget).data('flashvars');
}

// XXX UGLY TEMPORARY HACK ( don't use iframe for playlist )
iframeRewriteCount++;
$j( playerTarget )
.removeClass('mwEmbedKalturaPlaylistSwap')
.removeClass('mwEmbedKalturaVideoSwap')
.kalturaIframePlayer( kParams, doneWithIframePlayer);
});
// if there are no playlists left to process return:
if( $j( '.mwEmbedKalturaPlaylistSwap' ).length == 0 ){
Expand All @@ -281,7 +288,7 @@
} else {
var kalturaPlaylistHanlder = new mw.PlaylistHandlerKaltura( playlistConfig );
}
// quick non-ui conf check for layout mode
// Quick non-ui conf check for layout mode
var layout = ( $j( playlistTarget ).width() > $j( playlistTarget ).height() )
? 'horizontal' : 'vertical';
var playlistPlayer = $j( '#' + playlistTarget.id ).playlist({
Expand Down Expand Up @@ -364,7 +371,7 @@
}
// Add the flashvars to the request:
if( iframeParams['flashvars'] ){
iframeRequest += '?' + $j.param( iframeParams['flashvars'] );
iframeRequest += argSeperator + $j.param( {'flashvars': iframeParams['flashvars'] } );
}

var iframeId = $j( playerTarget ).attr('id');
Expand Down Expand Up @@ -452,7 +459,7 @@
continue;
}
}
mw.log( 'mw.getKalturaPlayerList found ' + kalturaPlayers.length + 'kalturaPlayers' );
mw.log( 'mw.getKalturaPlayerList found ' + kalturaPlayers.length + ' kalturaPlayers' );
return kalturaPlayers;
};

Expand Down
2 changes: 1 addition & 1 deletion modules/KalturaSupport/mw.KDPMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
};

// Listen for the proxyReady event from the server:
$j( playerProxy ).bind('proxyReady', function(){
$j( playerProxy ).bind( 'proxyReady', function(){
if( window.KalturaKDPCallbackReady ){
window.KalturaKDPCallbackReady( playerProxy.id );
}
Expand Down
Loading

0 comments on commit 30454a5

Please sign in to comment.