Ejemplo n.º 1
0
function jwplayer_shortcode_create_js_embed($media_hash, $player_hash = null, $params = array())
{
    global $jwplayer_shortcode_embedded_players;
    $player_hash = null === $player_hash ? get_option('jwplayer_player') : $player_hash;
    $content_mask = jwplayer_get_content_mask();
    $protocol = is_ssl() && JWPLAYER_CONTENT_MASK === $content_mask ? 'https' : 'http';
    if (in_array($player_hash, $jwplayer_shortcode_embedded_players, true)) {
        $player_script = '';
    } else {
        // Injecting script tag because there's no way to properly enqueue a javascript
        // at this point in the process :'-(
        $player_script = true;
        $jwplayer_shortcode_embedded_players[] = $player_hash;
    }
    $element_id = "jwplayer_{$media_hash}_{$player_hash}_div";
    $timeout = intval(get_option('jwplayer_timeout'));
    $js_lib = "{$protocol}://{$content_mask}/libraries/{$player_hash}.js";
    $json = "{$protocol}://{$content_mask}/feeds/{$media_hash}.json";
    if ($timeout > 0) {
        $api_secret = get_option('jwplayer_api_secret');
        $expires = time() + 60 * $timeout;
        $js_lib_sig = md5("libraries/{$player_hash}.js:" . $expires . ':' . $api_secret);
        $js_lib = "{$js_lib}?exp={$expires}&sig={$js_lib_sig}";
        $json_sig = md5("feeds/{$media_hash}.json:" . $expires . ':' . $api_secret);
        $json = "{$json}?exp={$expires}&sig={$json_sig}";
    }
    $params = jwplayer_shortcode_filter_player_params($params);
    if (count($params)) {
        // Support for player tracks.
        foreach (array('sources', 'tracks') as $option) {
            if (isset($params[$option])) {
                $json = '[' . $params[$option] . ']';
                $obj = json_decode(preg_replace('/[{, ]{1}(\\w+):/i', '"\\1":', $json));
                if (null === $obj) {
                    $json = str_replace(array('"', "'"), array('\\"', '"'), $json);
                    $obj = json_decode(preg_replace('/[{, ]{1}(\\w+):/i', '"\\1":', $json));
                }
                $params[$option] = $obj;
            }
        }
    }
    if (!isset($params['source'])) {
        $params['playlist'] = $json;
    }
    // Set ph value for player hosting source
    $params['ph'] = 2;
    // Redeclare fitVids to stop it from breaking the JW Player embedding.
    if (JWPLAYER_DISABLE_FITVIDS) {
        if ($player_script) {
            return "\n\t\t<script type='text/javascript' src='" . esc_url($js_lib) . "'></script>\n\t\t\t<div id='" . esc_attr($element_id) . "'></div>\n\t\t<script type='text/javascript'>\n\t\t\t" . 'if(typeof(jQuery)=="function"){(function($){$.fn.fitVids=function(){}})(jQuery)};' . "\n\t\t\t\tjwplayer('" . esc_attr($element_id) . "').setup(\n\t\t\t\t" . wp_json_encode($params) . "\n\t\t\t);\n\t\t</script>\n\t";
        } else {
            // no player script
            return "\n\t\t\t<div id='" . esc_attr($element_id) . "'></div>\n\t\t<script type='text/javascript'>\n\t\t\t" . 'if(typeof(jQuery)=="function"){(function($){$.fn.fitVids=function(){}})(jQuery)};' . "\n\t\t\t\tjwplayer('" . esc_attr($element_id) . "').setup(\n\t\t\t\t" . wp_json_encode($params) . "\n\t\t\t);\n\t\t</script>\n\t";
        }
    } else {
        // no fitvids script here.
        if ($player_script) {
            return "\n\t\t<script type='text/javascript' src='" . esc_url($js_lib) . "></script>\n\t\t\t<div id='" . esc_attr($element_id) . "'></div>\n\t\t<script type='text/javascript'>\n\t\t\t\tjwplayer('" . esc_attr($element_id) . "').setup(\n\t\t\t\t" . wp_json_encode($params) . "\n\t\t\t);\n\t\t</script>\n\t";
        } else {
            // no player script
            return "\n\t\t\t<div id='" . esc_attr($element_id) . "'></div>\n\t\t<script type='text/javascript'>\n\t\t\t\tjwplayer('" . esc_attr($element_id) . "').setup(\n\t\t\t\t" . wp_json_encode($params) . "\n\t\t\t);\n\t\t</script>\n\t";
        }
    }
}
Ejemplo n.º 2
0
function jwplayer_shortcode_create_js_embed($media_hash, $player_hash = null, $params = array())
{
    global $jwplayer_shortcode_embedded_players;
    $player_hash = null === $player_hash ? get_option('jwplayer_player') : $player_hash;
    $content_mask = jwplayer_get_content_mask();
    $protocol = is_ssl() && $content_mask === BOTR_CONTENT_MASK ? 'https' : 'http';
    if (in_array($player_hash, $jwplayer_shortcode_embedded_players)) {
        $player_script = '';
    } else {
        // Injecting script tag because there's no way to properly enqueue a javascript
        // at this point in the process :'-(
        $player_script = "<script type='text/javascript' src='{$protocol}://{$content_mask}/libraries/{$player_hash}.js'></script>";
        $jwplayer_shortcode_embedded_players[] = $player_hash;
    }
    $element_id = "jwplayer_{$media_hash}_{$player_hash}_div";
    $timeout = intval(get_option('jwplayer_timeout'));
    $xml = "{$protocol}://{$content_mask}/jw6/{$media_hash}.xml";
    if ($timeout > 0) {
        $api_secret = get_option('jwplayer_api_secret');
        $expires = time() + 60 * $timeout;
        $signature = md5("jw6/{$media_hash}.xml:" . $expires . ':' . $api_secret);
        $xml = "{$xml}?exp={$expires}&sig={$signature}";
    }
    $params = jwplayer_shortcode_filter_player_params($params);
    if (count($params)) {
        // Support for player tracks.
        foreach (array('sources', 'tracks') as $option) {
            if (isset($params[$option])) {
                $json = '[' . $params[$option] . ']';
                $obj = json_decode(preg_replace('/[{, ]{1}(\\w+):/i', '"\\1":', $json));
                if (null === $obj) {
                    $json = str_replace(array('"', "'"), array('\\"', '"'), $json);
                    $obj = json_decode(preg_replace('/[{, ]{1}(\\w+):/i', '"\\1":', $json));
                }
                $params[$option] = $obj;
            }
        }
    }
    if (!isset($params['source'])) {
        $params['playlist'] = $xml;
    }
    $paramstring = json_encode($params);
    foreach (array('&amp;' => '&', '&#038;' => '&', '\\/' => '/') as $from => $to) {
        $paramstring = str_replace($from, $to, $paramstring);
    }
    // Redeclare fitVids to stop it from breaking the JW Player embedding.
    $fitbits = JWPLAYER_DISABLE_FITVIDS ? 'if(typeof(jQuery)=="function"){(function($){$.fn.fitVids=function(){}})(jQuery)};' : '';
    return "\n\t\t{$player_script}\n\t\t<div id='{$element_id}'></div>\n\t\t<script type='text/javascript'>\n\t\t\t{$fitbits}\n\t\t\tjwplayer('{$element_id}').setup(\n\t\t\t\t{$paramstring}\n\t\t\t);\n\t\t</script>\n\t";
}