function flowplayer_swftools_flashvars in SWF Tools 6
Same name and namespace in other branches
- 5 flowplayer/flowplayer.module \flowplayer_swftools_flashvars()
- 6.2 flowplayer/flowplayer.module \flowplayer_swftools_flashvars()
Implementation of swftools_flashvars hook. Return an array of flashvars.
File
- flowplayer/
flowplayer.module, line 76
Code
function flowplayer_swftools_flashvars($action, &$methods, &$vars) {
// Pad out the user parameters (like those passed through swf(), with our
// configured defaults, allowing the user parameters to dominate.
$saved_settings = _flowplayer_flashvars($methods->player['name']);
$saved = array();
foreach ($saved_settings as $category => $settings) {
$saved = array_merge($saved, $settings);
}
$flashvars = array_merge($saved, $vars->flashvars);
if (isset($flashvars['image']) && !valid_url($flashvars['image'], TRUE)) {
$flashvars['image'] = swftools_get_media_url(swftools_get_media_path() . $flashvars['image']);
}
if ($vars->params['width']) {
$flashvars['width'] = $vars->params['width'];
}
if ($vars->params['height']) {
$flashvars['height'] = $vars->params['height'];
}
/* FlowPlayer doesn't like "" when JSON is generated, so we have to construct it ourselves here
* and assign it to the variable config.
* Build an array of FlowPlayer configuration settings, then call drupal_to_js to convert
* to JSON format, and then run through str_replac to make FlowPlayer happy!
*/
// Initialise array of FlowPlayer configuration settings
$flowplayer = array();
// If the passed filename ends in xml then it is a playlist
// FlowPlayer format requires a bit of adjusting to get things in the right format
// and we don't want an xml playlist but a flashvars string
if (pathinfo($vars->othervars['file_url'], PATHINFO_EXTENSION) == 'xml') {
// Initialise array to hold data
$playlist = array();
// Get file paths out of existing array and start to form FlowPlayer format
foreach ($vars->othervars['playlist_data']['playlist'] as $play) {
$playlist[] = "{ url: '" . $play['fileurl'] . "' }";
}
// Implode the array to create a flashvar ready for later
$flowplayer['playList'] = '[ ' . implode(', ', $playlist) . ' ]';
}
else {
// If not a playlist simply assign file_url to videoFile
$flowplayer['videoFile'] = $vars->othervars['file_url'];
}
// Find out what configuration settings are available
$available_settings = flowplayer_swftools_variable_mapping();
// See which ones have been set in othervars and copy to flowplayer array
foreach ($available_settings[FLOWPLAYER_MEDIAPLAYER] as $setting => $value) {
if ($flashvars[$setting]) {
$flowplayer[$setting] = $flashvars[$setting];
unset($flashvars[$setting]);
}
}
/**
* FlowPlayer uses 'loop' as the parameter to control looping
* This is already used as flash parameter so using loop in a
* filter means it isn't passed in the flashvars array. So copy
* whatever value we have in the parameter to flowplayer array
*/
if ($vars->othervars['loop']) {
$flowplayer['loop'] = $vars->othervars['loop'];
}
// Convert to JSON
$flashvars['config'] = drupal_to_js($flowplayer);
// Replace " with ', and remove quotes from around true and false, to satisfy FlowPlayer
$flashvars['config'] = str_replace(array(
'"',
"'false'",
"'true'",
"'[",
"]'",
), array(
"'",
"false",
"true",
"[",
"]",
), $flashvars['config']);
// If we had a playlist then the ' has been escaped, so reverse it where it occurs in the playlist
if ($playlist) {
$flashvars['config'] = str_replace(array(
"url: \\'",
"\\' }",
), array(
"url: '",
"' }",
), $flashvars['config']);
}
// Return an array of flash variables
return $flashvars;
}