function swftools_flowplayer_swftools_preprocess_flowplayer in SWF Tools 6.3
Implementation of hook_swftools_preprocess_[player]().
File
- flowplayer/
swftools_flowplayer.module, line 61 - Enables SWF Tools support for Flowplayer.
Code
function swftools_flowplayer_swftools_preprocess_flowplayer(&$data) {
// Pad out the user parameters (like those passed through swf(), with our
// configured defaults, allowing the user parameters to dominate.
$defaults = _swftools_flowplayer_flashvars();
// Merge defaults and user supplied values, letting user supplied values dominate
$data['flashvars'] = array_merge($defaults, $data['flashvars']);
// If an image is set then use it
if ($data['flashvars']['image']) {
// Retrieve path data
$source = swftools_get_url_and_path($data['flashvars']['image']);
// If a path was returned then assign it to the flashvar
if ($source) {
$data['flashvars']['image'] = $source['fileurl'];
}
}
// 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();
// Are we handling a playlist?
if ($data['othervars']['playlist_data']) {
// Initialise array to hold data
$playlist = array();
// Get file paths out of existing array and start to form Flowplayer format
foreach ($data['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'] = $data['othervars']['file_url'];
}
// Find out what configuration settings are available
$available_settings = swftools_flowplayer_swftools_variable_mapping();
// See which ones have been set in othervars and copy to flowplayer array
foreach ($available_settings['flowplayer'] as $setting => $value) {
if (isset($data['flashvars'][$setting])) {
$flowplayer[$setting] = $data['flashvars'][$setting];
unset($data['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 (isset($data['othervars']['loop']) && $data['othervars']['loop']) {
$flowplayer['loop'] = $data['othervars']['loop'];
}
// Merge $data['othervars'] in to flashvars
//$flowplayer = array_merge($flowplayer, $data['othervars']);
// Convert to JSON
$data['flashvars']['config'] = drupal_to_js($flowplayer);
// Replace " with ', and remove quotes from around true and false, to satisfy Flowplayer
$data['flashvars']['config'] = str_replace(array(
'"',
"'false'",
"'true'",
"'[",
"]'",
), array(
"'",
"false",
"true",
"[",
"]",
), $data['flashvars']['config']);
// If we had a playlist then the ' has been escaped, so reverse it where it occurs in the playlist
if (isset($playlist) && $playlist) {
$data['flashvars']['config'] = str_replace(array(
"url: \\'",
"\\' }",
), array(
"url: '",
"' }",
), $data['flashvars']['config']);
}
}