2

I am trying to develop a module to use JWPlayer's URL Toekn Signing (docs can be found here http://developer.jwplayer.com/jw-platform/reference/v1/content_signing.html) but I'm having an issue with the output.

I am using the following fields in the module's XML:

<field name="key" type="text" label="API Key" default="key" description="API Key" />
<field name="secret" type="text" label="API Secret" default="secret" description="API Secret" />
<field name="expires" type="text" label="Expires" default="Expires" description="Expires" />
<field name="mediaid" type="text" label="Media ID" default="Media ID" description="Media ID" />
<field name="domain" type="text" label="DNS Masking" default="Domain" description="Domain" />

These variables output correctly via PHP. However, when I'm building the URL using Javascript, it's failing.

I have written the following for the modules default.php

$key = $params->get('key');
$secret = $params->get('secret');
$domain = $params->get('domain');
$mediaid = $params->get('mediaid');
$expires = $params->get('expires');

function get_signed_player($key,$mediaid,$domain,$secret,$expires) {
  $path = "players/".$key."-".$mediaid.".js";
  $signature = md5($path.':'.$expires.':'.$secret);
  $url = 'http://'.$domain.'/'.$path.'?exp='.$expires.'&sig='.$signature;
  return $url;
};

echo "<p>Watch this cool video:</p>"
echo "<script type='text/javascript' src='".get_signed_player($key,'ALJ3XQCI')."'></script>";
?>

Any ideas where I'm going wrong?

1
  • Just a long shot, but you missing a ; (semi-colon) after the first echo. Also, you don't need a ; after your function's closing bracket
    – Lodder
    Commented Mar 21, 2016 at 16:15

1 Answer 1

1

Ok just realised that the reason it's not working is because you're not passing the parameter values through the function.

Try this:

$key     = $params->get('key');
$secret  = $params->get('secret');
$domain  = $params->get('domain');
$mediaid = $params->get('mediaid');
$expires = $params->get('expires');

function get_signed_player($key, $mediaid, $domain, $secret, $expires)
{
    $path      = 'players/' . $key . '-' . $mediaid . '.js';
    $signature = md5($path . ':' . $expires . ':' . $secret);
    $url       = 'http://' . $domain . '/' . $path . '?exp=' . $expires . '&sig=' . $signature;

    return $url;
}

echo '<p>Watch this cool video:</p>';
echo '<script src="' . get_signed_player($key, $mediaid, $domain, $secret, $expires) . '"></script>';

As you can see, I've replaced:

get_signed_player($key,'ALJ3XQCI')

with:

get_signed_player($key, $mediaid, $domain, $secret, $expires)

So that everything is passed through correctly.

Not sure why, but I've also formatted the code as I'm in one of those pedantic moods today.

Just as an FYI, your function should really go into a helper.php file, rather than being in the default.php. This file of for the view of the module and therefore should contain the HTML markup. Any processing/excecution of data, should be in a separate helper file.

Hope this helps

3
  • @RustyJoomla - You're welcome as always :)
    – Lodder
    Commented Mar 21, 2016 at 16:35
  • Quick question, would it cause a problem if this module was shown for different videos but on the same page? Commented Mar 21, 2016 at 16:40
  • No, it shouldn't be a problem
    – Lodder
    Commented Mar 21, 2016 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.