function theme_swftools_swfobject2 in SWF Tools 6.3
Turns an SWF Tools data array in to markup and JavaScript for inclusion on the page.
Parameters
string $file: The path to the file to be displayed.
array $data: An array of additional parameters associated with this item.
int $script_location: (optional) Specify whether JavaScript should be placed in the header, footer, or inline. If not specified it will default to inline. One of the following constants can be used:
Return value
A markup string.
Related topics
File
- swfobject2/
swftools_swfobject2.module, line 119 - Enables SWF Tools support for swfObject 2 JavaScript flash embedding.
Code
function theme_swftools_swfobject2($file, $data, $script_location = SWFTOOLS_JAVASCRIPT_INLINE) {
// Put JavaScript on the page
swftools_swfobject2_add_js();
// If bgcolor isn't assigned a value then unset it
if (isset($data['params']['bgcolor']) && !$data['params']['bgcolor']) {
unset($data['params']['bgcolor']);
}
// Initialise an array to hold output of encoding flashvars
$flashvars = array();
// Encode flashvars
foreach ($data['flashvars'] as $key => $value) {
$flashvars[rawurlencode($key)] = rawurlencode($value);
}
// For JavaScript interaction to work we must assign a name via attributes
$attributes = array(
'name' => $data['othervars']['id'],
);
// TODO: Should we process params to ensure booleans are true/flase, like we do with direct embedding
// Determine if we can use express install (must be available locally, and big enough)
if (swftools_swfobject2_available_locally() && $data['othervars']['width'] >= 310 && $data['othervars']['height'] >= 137) {
$express = base_path() . swftools_get_library('swfobject') . '/expressInstall.swf';
}
else {
$express = '';
}
// Generate js string ready for output to the page header
// swfObject takes parameters swfURL, id, width, height, version, expressinstall, flashvars, params, attributes
// See http://code.google.com/p/swfobject/wiki/documentation
$script = t('swfobject.embedSWF("!url", "!id", "!width", "!height", "!version", "!express", !flashvars, !params, !attributes);', array(
'!url' => $file,
'!id' => $data['othervars']['id'],
'!width' => $data['othervars']['width'],
'!height' => $data['othervars']['height'],
'!version' => $data['params']['version'],
'!express' => $express,
'!flashvars' => drupal_to_js($flashvars),
'!params' => drupal_to_js($data['params']),
'!attributes' => drupal_to_js($attributes),
));
// Generate inline script, or place script in the header
if ($script_location == SWFTOOLS_JAVASCRIPT_INLINE) {
// Add script using container id as context and then retrieve it so we get it formatted and wrapped in CDATA
drupal_add_js($script, 'inline', $data['othervars']['id']);
$script = drupal_get_js($data['othervars']['id']);
}
else {
// Add script to the header, but we also put a copy inline, using id as context, so SWF Tools can cache it
drupal_add_js($script, 'inline', $script_location == SWFTOOLS_JAVASCRIPT_HEADER ? 'header' : 'footer');
drupal_add_js($script, 'inline', $data['othervars']['id']);
$script = '';
}
// Return markup, with script attached if necessary
$html = '<div id="' . $data['othervars']['id'] . '">' . theme('swftools_html_alt', $data) . '</div>' . $script;
// Return html markup
return $html;
}