function swftools_flowplayer3_swftools_preprocess_flowplayer3 in SWF Tools 6.3
Implementation of hook_swftools_preprocess_[player]().
File
- flowplayer3/
swftools_flowplayer3.module, line 101 - Enables SWF Tools support for Flowplayer 3.
Code
function swftools_flowplayer3_swftools_preprocess_flowplayer3(&$data) {
// Retrieve the current Flowplayer 3 settings
$saved_settings = _swftools_flowplayer3_settings($data['othervars']['profile']);
// Initialise playlist
$playlist = array();
// If an image was supplied to be the splash then put this first in the list
if ($data['othervars']['image']) {
// Get source path to the image file
$source = swftools_get_url_and_path($data['othervars']['image']);
// If $source succeeded add image to the playlist
if ($source) {
// See if we need to apply an imagecache preset
if ($saved_settings['imagecache']['imagecache_player'] != SWFTOOLS_UNDEFINED) {
$source['fileurl'] = swftools_imagecache_create_path($saved_settings['imagecache']['imagecache_player'], $source['fileurl']);
}
$playlist[] = '{ "url": "' . $source['fileurl'] . '", "autoPlay": true, "duration": "0" }';
}
}
// Attach the playlist from earlier, if we have it
if (isset($data['othervars']['flowplayer3']['playlist'])) {
// Attach the playlist after the splash image
$playlist = $playlist + $data['othervars']['flowplayer3']['playlist'];
// Implode the playlist to a string
$playlist = '[ ' . implode(', ', $playlist) . ' ]';
}
else {
// If there is no splash image just use the file_url
if (!$playlist) {
$playlist[] = $data['othervars']['file_url'];
}
else {
// Attach file url to the splash image
$playlist[] = '{ "url": "' . $data['othervars']['file_url'] . '" }';
// Implode the playlist to a string
$playlist = '[ ' . implode(', ', $playlist) . ' ]';
}
}
// Initialise array of Flowplayer 3 configuration settings
$flowplayer = array();
// Over-ride embedding to use Flowplayer?
if (variable_get('swftools_flowplayer3_embed', FALSE)) {
$data['resolved_methods']['embed']['theme'] = 'swftools_flowplayer3';
}
else {
// Assign a playerId flashvar to initiate the external interface outside of Flowplayer embedding
$flowplayer['playerId'] = $data['othervars']['id'];
}
// Attach the Flowplayer playlist to the configuration
$flowplayer['playlist'] = $playlist;
// Attach logo settings, if required
if ($saved_settings['logo']['use_logo']) {
unset($saved_settings['logo']['use_logo']);
$flowplayer['logo'] = $saved_settings['logo'];
}
// Create accessible controls if necessary
if ($saved_settings['accessibility']['accessible']) {
$data['othervars']['#suffix'] = theme('swftools_flowplayer3_accessible', $data['othervars']['id'], $saved_settings['accessibility']['accessible']);
}
// TODO: Can we just array merge here? And can we recursively unset blank entries?
// TODO: Use swftools_array_merge as a common way to merge a multi-dimensional array
// TODO: See swftools_wijering4.admin.inc for use of array_diff() to unset blanks.
// TODO: Can we optimise this to use fewer passes? Pre-filter the settings to eliminate blanks? Like JW4.
// Scan through each setting to see if it is over-ridden in $data['othervars']
// Unset properties that are blank to keep the resulting code 'tidy'
// TODO: Do the same as wijering4 - we should clear out blanks during form submission
// There is no need to do this here? The only issue is that anything passed on othervars
// is a flat array of keys and values, so we need to locate its key within the Flowplayer 3
// structure. We will also have to consider if anything might have duplicate key names
// (not sure - need to check. Or we could simply make it that Flowplayer can't be
// over-ridden from the input filter - I've never been sure if anyone even uses that feature!
// We could flatten the Flowplayer 3 saved settings, then try an array check to see if we
// have any matches - but then we still have to know where to put the thing afterwards...
// Maybe with the new caching mechanism we shouldn't worry too much - we only run this
// function when we generate content, and then it's done. It we filtered the blanks we
// would have no way of locating the proper place for the value in the array.
foreach ($saved_settings as $category => $values) {
foreach (array_keys($values) as $property) {
if (isset($data['othervars'][$property])) {
$saved_settings[$category][$property] = $data['othervars'][$property];
}
if ($saved_settings[$category][$property] === '') {
unset($saved_settings[$category][$property]);
}
}
}
// If the object doesn't have a width set then assign one
if (!isset($data['params']['width'])) {
$data['params']['width'] = $saved_settings['canvas']['width'];
}
// If the object doesn't have a height set then assign one
if (!isset($data['params']['height'])) {
$data['params']['height'] = $saved_settings['canvas']['height'];
}
// Translate labels if they are set
if (isset($saved_settings['play']['label'])) {
$saved_settings['play']['label'] = t($saved_settings['play']['label']);
}
if (isset($saved_settings['play']['replayLabel'])) {
$saved_settings['play']['replayLabel'] = t($saved_settings['play']['replayLabel']);
}
// Add the properties to the flowplayer array ready for rendering
$flowplayer['canvas'] = $saved_settings['canvas'];
$flowplayer['clip'] = $saved_settings['clip'];
$flowplayer['play'] = $saved_settings['play'];
// Configure the control bar
$flowplayer['plugins']['controls'] = $saved_settings['controls'];
// Assign the control bar url if required
if (variable_get('swftools_flowplayer3_controls', '')) {
$flowplayer['plugins']['controls']['url'] = variable_get('swftools_flowplayer3_controls', '');
}
//swftools_get_library('flowplayer3') . '/' .
// If we are streaming this file, add the stream plugin(s)
if ($data['othervars']['stream']) {
$stream_url = variable_get('swftools_flowplayer3_stream_plugin', SWFTOOLS_FLOWPLAYER3_STREAM_PLUGIN);
// Is the playlist a mix of streams / providers?
if ($data['othervars']['stream'] === TRUE) {
foreach ($data['othervars']['flowplayer3']['providers'] as $provider => $index) {
$flowplayer['plugins']['rtmp' . $index]['url'] = $stream_url;
$flowplayer['plugins']['rtmp' . $index]['netConnectionUrl'] = $provider;
}
}
else {
$flowplayer['plugins']['rtmp']['url'] = $stream_url;
$flowplayer['clip']['provider'] = 'rtmp';
$flowplayer['plugins']['rtmp']['netConnectionUrl'] = $data['othervars']['stream'];
}
}
// Add product key if it has been set
if (variable_get('swftools_flowplayer3_product_key', '')) {
$flowplayer['key'] = variable_get('swftools_flowplayer3_product_key', '');
}
// For now we will attach the complete flowplayer array to othervars so we can access it elsewhere
$data['othervars']['flowplayer3']['config'] = $flowplayer;
// Convert flowplayer array to JSON, ready to assign to a flashvar called config
$config = drupal_to_js($flowplayer);
// Replace " with ', and remove quotes from around true and false, to satisfy Flowplayer
$config = str_replace(array(
'"',
"'false'",
"'true'",
"'[",
"]'",
), array(
"'",
"false",
"true",
"[",
"]",
), $config);
// The ' has been escaped, so reverse it where it occurs in the playlist (it gets escaped again later!)
$config = str_replace(array(
"\\'",
), array(
"'",
), $config);
// Attach config to flashvars
$data['flashvars']['config'] = $config;
// Add JavaScript to enable auto-close behavior and accessibility
swftools_flowplayer3_add_js();
}