I am developing a module (see here for details Mixing PHP variables and JS variables in output) this shows multiple uses of the same javascript function, as follows:
$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>';
However, when I assign more than one module to a page the page crashes, I'm thinking due to the usage of a duplicate javascript function.
I'm hoping I can assign an ID to the function name. I was thinking the easiest way would be to echo the module ID using
echo $module->id;
but if I add this to the function name, it still breaks. Ideally I want something along these lines:
function get_signed_player' . $module->id . '($playerkey, $videokey, $domain, $secret, $expires)
Which I then call for the frontend:
echo '<script src="' . get_signed_player' . $module->id . '($playerkey, $videokey, $domain, $secret, $expires) . '"></script>';