function shortcode($atts, $content = null)
{
static $num;
// do not display markup in feeds
if (is_feed()) {
return;
}
// handle the 'legacy' shortcode format: [ooyala code12345]
if (empty($atts['code'])) {
if (isset($atts[0])) {
$atts['code'] = $atts[0];
} else {
// we need a code!
return;
}
}
$num++;
$settings = $this->get_settings();
// fill in defaults saved in user settings
if (empty($atts['player_id']) && !empty($settings['player_id'])) {
$atts['player_id'] = $settings['player_id'];
}
// set a width from some defaults
if (empty($atts['width'])) {
if (!empty($settings['video_width'])) {
$atts['width'] = $settings['video_width'];
} elseif (!empty($GLOBALS['content_width'])) {
$atts['width'] = $GLOBALS['content_width'];
}
}
// fill in remaining player defaults
$atts = shortcode_atts(apply_filters('ooyala_default_query_args', $this->playerDefaults), $atts);
//coerce string true and false to their respective boolean counterparts
$atts = array_map(function ($value) {
if ($value === 'true') {
return true;
} elseif ($value === 'false') {
return false;
} else {
return $value;
}
}, $atts);
// match against allowed values
foreach (array('wmode', 'platform') as $att) {
$atts[$att] = in_array($atts[$att], $this->allowed_values[$att]) ? $atts[$att] : $this->playerDefaults[$att];
}
$width = (int) $atts['width'];
$height = (int) $atts['height'];
$player_style = '';
ob_start();
if ($atts['auto']) {
// Auto-size the player by stretching it into a fixed-ratio container
$container_style = 'max-width:' . $width . 'px;';
$player_style = 'position:absolute;top:0;right:0;bottom:0;left:0';
$sizer_style = 'width:auto;' . 'padding-top:' . $height / $width * 100 . '%;' . 'position:relative';
?>
<div class="ooyala-container" style="<?php
echo esc_attr($container_style);
?>
">
<div class="ooyala-sizer" style="<?php
echo esc_attr($sizer_style);
?>
">
<?php
}
if (!empty($atts['player_id'])) {
// player query string parameters
$query_params = array('namespace' => 'OoyalaPlayer' . $num);
// JS parameters - start with passed json, if any
if ($content && ($json = json_decode($content, true)) && is_array($json) && count(array_filter(array_keys($json), 'is_string'))) {
$js_params = $json;
} else {
$js_params = array();
}
// pick out all other params
foreach ($atts as $key => $value) {
switch ($key) {
// no-op bc these have special placement in the embed code
case 'width':
case 'height':
if (!$atts['auto']) {
$js_params[$key] = (int) $value;
}
break;
case 'code':
case 'player_id':
break;
// these are query params and are appended to the player script URL
// these are query params and are appended to the player script URL
case 'platform':
$query_params[$key] = $value;
break;
case 'chromeless':
if (!$this->is_default($key, $value)) {
$js_params['layout'] = 'chromeless';
}
break;
// all other params become JS parameters
// these will override values of the same name supplied from the JSON content block
// all other params become JS parameters
// these will override values of the same name supplied from the JSON content block
default:
if (!$this->is_default($key, $value)) {
$js_params[isset($this->paramMapping[$key]) ? $this->paramMapping[$key] : $key] = $value;
}
break;
}
}
?>
<script src="<?php
echo esc_url('//player.ooyala.com/v3/' . $atts['player_id'] . '?' . http_build_query($query_params));
?>
"></script>
<div id="ooyalaplayer-<?php
echo (int) $num;
?>
" class="<?php
echo esc_attr($atts['wrapper_class']);
?>
" style="<?php
echo esc_attr($player_style);
?>
" ></div>
<script>
var ooyalaplayers = ooyalaplayers || [];
<?php
$player = 'OoyalaPlayer' . $num;
$params = array("ooyalaplayer-{$num}", $atts['code']);
$js_params = apply_filters('ooyala_js_params', $js_params);
if (count($js_params)) {
$params[] = $js_params;
}
?>
var config<?php
echo (int) $num;
?>
= <?php
echo json_encode($params);
?>
;
if(config<?php
echo (int) $num;
?>
[config<?php
echo (int) $num;
?>
.length - 1]["amazon-ads-manager"] && window[config<?php
echo (int) $num;
?>
[config<?php
echo (int) $num;
?>
.length - 1]["amazon-ads-manager"].adTag]){
config<?php
echo (int) $num;
?>
[config<?php
echo (int) $num;
?>
.length - 1]["google-ima-ads-manager"] = {'adTagUrl' : ''} ;
config<?php
echo (int) $num;
?>
[config<?php
echo (int) $num;
?>
.length - 1]["google-ima-ads-manager"].adTagUrl = window[config<?php
echo (int) $num;
?>
[config<?php
echo (int) $num;
?>
.length - 1]["amazon-ads-manager"].adTag];
delete config<?php
echo (int) $num;
?>
[config<?php
echo (int) $num;
?>
.length - 1]["amazon-ads-manager"];
}
<?php
echo esc_js($player) . '.ready(function() { ooyalaplayers.push(' . esc_js($player) . '.Player.create.apply(this, config' . $num . ') ); });';
?>
</script>
<noscript><div><?php
esc_html_e('Please enable Javascript to watch this video', 'ooyala');
?>
</div></noscript>
<?php
// no player id, use the v2 player
} else {
if (!$atts['auto']) {
$player_style = '';
}
$script_url = add_query_arg(array('width' => $atts['width'], 'height' => $atts['height'], 'embedCode' => $atts['code'], 'autoplay' => $atts['autoplay'] ? '1' : '0', 'callback' => $atts['callback'], 'wmode' => $atts['wmode'], 'version' => 2), 'https://player.ooyala.com/player.js');
?>
<div id="ooyalaplayer-<?php
echo (int) $num;
?>
" class="<?php
echo esc_attr($atts['wrapper_class']);
?>
" style="<?php
echo esc_attr($player_style);
?>
">
<script src="<?php
echo esc_url($script_url);
?>
"></script>
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="<?php
echo (int) $atts['width'];
?>
" height="<?php
echo (int) $atts['height'];
?>
" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="<?php
echo esc_url('http://player.ooyala.com/player.swf?embedCode=' . $atts['code'] . '&version=2');
?>
">
<param name="bgcolor" value="#000000">
<param name="allowScriptAccess" value="always">
<param name="allowFullScreen" value="true">
<param name="wmode" value="<?php
echo esc_attr($atts['wmode']);
?>
">
<param name="flashvars" value="embedType=noscriptObjectTag&embedCode=###VID###">
<embed src="<?php
echo esc_url('http://player.ooyala.com/player.swf?embedCode=' . $atts['code'] . '&version=2');
?>
" bgcolor="#000000" width="<?php
echo (int) $atts['width'];
?>
" height="<?php
echo (int) $atts['height'];
?>
" align="middle" play="true" loop="false" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" flashvars="&embedCode=<?php
echo esc_attr($atts['code']);
?>
" pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</noscript>
</div>
<?php
}
if ($atts['auto']) {
?>
</div>
</div>
<?php
}
return ob_get_clean();
}