function flowplayer3_swftools_embed in SWF Tools 6.2
1 call to flowplayer3_swftools_embed()
- flowplayer3_init in flowplayer3/
flowplayer3.module - Implementation of hook_init().
File
- flowplayer3/
flowplayer3.module, line 409
Code
function flowplayer3_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
// Set flag to indicate if the javascript has been added to the header
static $flowplayer3_has_run;
// Output JavaScript to the header to load the SWF Object code
if (!$flowplayer3_has_run) {
// Add flowplayer3 embedding script
drupal_add_js(swftools_get_player_path() . '/flowplayer3/' . variable_get('flowplayer3_mediaplayer_javascript', FLOWPLAYER3_MEDIAPLAYER_JAVASCRIPT));
// Add flowplayer3 css to ensure the container div is set to display:block
drupal_add_css(drupal_get_path('module', 'flowplayer3') . '/flowplayer3.css');
// Set flag to show script is in place
$flowplayer3_has_run = TRUE;
}
// If this is all that is being done then return here
if ($action == 'add_js') {
return;
}
// Initialise a counter to give each div a unique id
static $unique_id = 0;
$unique_id++;
// Construct a unique id for each div by using time() combined with $unique_id
// This is necessary to prevent clashes between cached content
$id = time() . $unique_id;
$id = 'flowplayer3-id-' . $id;
/**
* If the container div includes markup then this is shown until the div is clicked because of the dynamic loading mechanism
* that flowplayer uses.
*/
// Check if a splash image was set
if (isset($vars->othervars['image'])) {
$image_path = swftools_get_media_url(swftools_get_media_path() . $vars->othervars['image']);
$image_style = 'style="background-image:url(' . $image_path . ');"';
}
else {
$image_style = '';
}
/**
* If the container actually has some content in it then flowplayer won't actually display the player.
* It will wait until the container is clicked, and then load the player on demand. For now we will
* suppress this behaviour by omitting the alt text. Empty containers are populated with the player immediately
* upon load. This behavior is more consistent with how the module worked before. However, with background images
* and css there is potential for some efficient coding here using this approach!
*/
// // Build a simple HTML string to act as the container - this version shows the play buton
// $html = t('<div id="!id" class="flowplayer3-container" !image_style><img src="!img" alt="!alt" class="flowplayer3-play-button" /></div>', array(
// '!id' => $id,
// '!alt' => $html_alt,
// '!img' => base_path() . drupal_get_path('module', 'flowplayer3') . '/play_large.png',
// '!image_style' => $image_style,
// ));
// Build a simple HTML string to act as the container - this version excludes alternate text so the player appears
$html = t('<div id="!id" class="flowplayer3-container">!alt</div>', array(
'!id' => $id,
'!alt' => variable_get('swftools_flowplayer3_load', TRUE) ? '' : $html_alt,
));
// Unset properties we don't want output as part of the flash configuration
unset($vars->params['src_path']);
unset($vars->params['flashvars']);
// Clear wmode parameter as if this is not window then FlowPlayer will not display
unset($vars->params['wmode']);
// Convert parameters to JSON
$parameters = drupal_to_js($vars->params);
// Replace " with ', and remove quotes from around true and false, to satisfy FlowPlayer
$parameters = str_replace(array(
'"',
"'false'",
"'true'",
"'[",
"]'",
), array(
"'",
"false",
"true",
"[",
"]",
), $parameters);
// Create the script to create a flowplayer instance, set the height and width, and then load it
// Note that if the load() function is not called then the player won't actually appear until the container is clicked!
$script = t('<script type="text/javascript">!prefix
flowplayer("!id", !url, !config);
$("#!id").height(!height).width(!width);
!suffix</script>', array(
'!url' => $parameters,
'!id' => $id,
'!height' => $vars->params['height'],
'!width' => $vars->params['width'],
'!config' => $vars->flashvars['config'],
'!load' => variable_get('swftools_flowplayer3_load', TRUE) ? 'flowplayer("' . $id . '").load();' : '',
// For inline Javascript to validate as XHTML, all Javascript containing
// XHTML needs to be wrapped in CDATA. To make that backwards compatible
// with HTML 4, we need to comment out the CDATA-tag.
'!prefix' => '<!--//--><![CDATA[//><!--',
'!suffix' => '//--><!]]>',
));
// Return placeholder and JavaScript ready to be cached
return $html . "\n" . $script;
}