'admin/swf',
'title' => t('SWF Tools'),
'callback' => 'swftools_admin',
'access' => $swf_admin,
'position' => 'left',
'description' => t('SWF Tools provide integration with Macromedia Flash related methods and tools.'),
);
$items[] = array('path' => 'admin/swf/embed',
'title' => t('Embedding'),
'description' => t('Settings specific to Flash embedding.'),
);
$items[] = array('path' => 'admin/swf/handling',
'title' => t('File handling'),
'description' => t('Flash players and handling for various file types.'),
);
}
return $items;
}
/**
* Show the administration forms, depending the url
*/
function swftools_admin() {
if ($page = arg(2)) {
return drupal_get_form('swftools_admin_'. $page .'_form');
}
else {
return system_admin_menu_block_page();
}
}
/**
* Implementation of hook_perm().
*/
function swftools_perm() {
return array('administer flash');
}
function swftools_admin_embed_form() {
$swf_options = _swf_options();
$form = array();
$form['swftools_method'] = array(
'#type' => 'fieldset',
'#title' => t('JavaScript Embedding'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$methods = swftools_methods_available(SWFTOOLS_EMBED_METHOD);
if (count($methods)) {
foreach ($methods AS $method => $info) {
$swf_embed_methods[$method] = $info['title'];
}
}
$form['swftools_method'][SWFTOOLS_EMBED_METHOD] = array(
'#type' => 'radios',
'#title' => t('Method'),
'#default_value' => variable_get(SWFTOOLS_EMBED_METHOD, 'direct'),
'#options' => $swf_embed_methods,
'#description' => t('JavaScript file that will be used for Flash replacement. Options like SWFObject and UFO are not supported yet.'),
);
// Might have another setting like above for SIFR, if it ever gets used
$form['swftools_method']['swftools_user_no_js'] = array(
'#type' => 'checkbox',
'#title' => t('User override'),
'#disabled' => TRUE,
'#default_value' => variable_get('swftools_user_no_js', FALSE),
'#description' => t('User can choose how Flash content is delivered overriding
the \'Method\' setting above. Adds a setting to the profile page.'),
);
$form['swftools'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Default settings for embedding'),
'#attributes' => array('style' => 'background : #FFFFFF; -moz-border-radius: .5em;'),
);
$form['swftools']['swftools_movie_swliveconnect'] = array(
'#type' => 'checkbox',
'#title' => t('SWLIVECONNECT Specifies whether the browser should start Java when loading the Flash Player for the first time. The default value is false if this attribute is omitted. If you use JavaScript and Flash on the same page, Java must be running for the FSCommand to work.'),
'#default_value' => variable_get('swftools_movie_swliveconnect', false),
'#description' => t('This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf swliveconnect="true|false"] meta-tag'),
);
$form['swftools']['swftools_movie_play'] = array(
'#type' => 'checkbox',
'#title' => t('PLAY Specifies whether the movie begins playing immediately on loading in the browser. The default value is true if this attribute is omitted.'),
'#default_value' => variable_get('swftools_movie_play', true),
'#description' => t('This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf play="true|false"] meta-tag'),
);
$form['swftools']['swftools_movie_loop'] = array(
'#type' => 'checkbox',
'#title' => t('LOOP Specifies whether the movie repeats indefinitely or stops when it reaches the last frame. The default value is true if this attribute is omitted.'),
'#default_value' => variable_get('swftools_movie_loop', true),
'#description' => t('This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf loop="true|false"] meta-tag'),
);
$form['swftools']['swftools_movie_menu'] = array(
'#type' => 'checkbox',
'#title' => t('MENU Displays the full menu, allowing the user a variety of options to enhance or control playback.'),
'#default_value' => variable_get('swftools_movie_menu', true),
'#description' => t('This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf menu="true|false"] meta-tag'),
);
$form['swftools']['swftools_movie_bgcolor'] = array(
'#type' => 'textfield',
'#title' => t('Background color in hexadecimal form'),
'#size' => 7,
'#maxlength' => 7,
'#required' => TRUE,
'#default_value' => variable_get('swftools_movie_bgcolor', '#FFFFFF'),
'#description' => t('(#RRGGBB, hexadecimal RGB value) Specifies the background color of the movie. Use this attribute to override the background color setting specified in the Flash file. This attribute does not affect the background color of the HTML page. This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf bgcolor="#FFFFFF"] meta-tag'),
);
$form['swftools']['swftools_movie_quality'] = array(
'#type' => 'radios',
'#title' => t('Specify the Quality property'),
'#default_value' => variable_get('swftools_movie_quality', 4),
'#options' => $swf_options['quality'],
'#description' => t('
QUALITY - (low, high, autolow, autohigh, best)
Low favors playback speed over appearance and never uses anti-aliasing.
Autolow emphasizes speed at first but improves appearance whenever possible. Playback begins with anti-aliasing turned off. If the Flash Player detects that the processor can handle it, anti-aliasing is turned on.
Autohigh emphasizes playback speed and appearance equally at first but sacrifices appearance for playback speed if necessary. Playback begins with anti-aliasing turned on. If the actual frame rate drops below the specified frame rate, anti-aliasing is turned off to improve playback speed. Use this setting to emulate the View > Antialias setting in Flash.
Medium applies some anti-aliasing and does not smooth bitmaps. It produces a better quality than the Low setting, but lower quality than the High setting.
High favors appearance over playback speed and always applies anti-aliasing. If the movie does not contain animation, bitmaps are smoothed; if the movie has animation, bitmaps are not smoothed.
Best provides the best display quality and does not consider playback speed. All output is anti-aliased and all bitmaps are smoothed.
This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf quality="low|autolow|medium|high|autohigh|best"] meta-tag'),
);
$form['swftools']['swftools_movie_scale'] = array(
'#type' => 'radios',
'#title' => t('Specify the Scale property'),
'#default_value' => variable_get('swftools_movie_scale', 0),
'#options' => $swf_options['scale'],
'#description' => t('
SCALE - (showall, noborder, exactfit)
Default (Show all) makes the entire movie visible in the specified area without distortion, while maintaining the original aspect ratio of the movie. Borders may appear on two sides of the movie.
No Border scales the movie to fill the specified area, without distortion but possibly with some cropping, while maintaining the original aspect ratio of the movie.
Exact Fit makes the entire movie visible in the specified area without trying to preserve the original aspect ratio. Distortion may occur.
This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf scale="showall|noborder|exactfit"] meta-tag'),
);
$form['swftools']['swftools_movie_wmode'] = array(
'#type' => 'radios',
'#title' => t('Specify the Window Mode property'),
'#default_value' => variable_get('swftools_movie_wmode', 0),
'#options' => $swf_options['wmode'],
'#description' => t('
WMODE - (window, opaque, transparent) Sets the Window Mode property of the Flash movie for transparency, layering, and positioning in the browser.
Window movie plays in its own rectangular window on a web page.
Opaque the movie hides everything on the page behind it.
Transparent the background of the HTML page shows through all transparent portions of the movie, this may slow animation performance.
This value will be used with auto embedding and also as a default value when no user input is found in [flash:filename.swf wmode="window|opaque|transparent"] meta-tag'),
);
return system_settings_form($form);
}
function swftools_admin_handling_form() {
$form = array();
$form['swftools'] = array(
'#type' => 'fieldset',
'#title' => t('SWF Tools - File Handling'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$swf_flv_players[0] = 'Link only';
$methods = swftools_methods_available(SWFTOOLS_FLV_DISPLAY);
if (count($methods)) {
foreach ($methods AS $method => $info) {
$swf_flv_players[$method] = $info['title'];
}
}
$form['swftools'][SWFTOOLS_FLV_DISPLAY] = array(
'#type' => 'radios',
'#title' => t('Default player for .flv files'),
'#default_value' => variable_get(SWFTOOLS_FLV_DISPLAY, 'wijering_media'),
'#options' => $swf_flv_players,
);
$swf_mp3_players[0] = 'Link only';
$methods = swftools_methods_available(SWFTOOLS_MP3_DISPLAY);
if (count($methods)) {
foreach ($methods AS $method => $info) {
$swf_mp3_players[$method] = $info['title'];
}
}
$form['swftools'][SWFTOOLS_MP3_DISPLAY] = array(
'#type' => 'radios',
'#title' => t('Default player for .mp3 files'),
'#default_value' => variable_get(SWFTOOLS_MP3_DISPLAY, 'wijering_media'),
'#options' => $swf_mp3_players,
);
return system_settings_form($form);
}
/**
* Return output, which might be embed markup, or pre-flash markup
* that includes the appropriate jQuery added to the
*
* @param $filepath
* The file to be displayed in the player (or a displayed swf file if $type = EMBED_SWF)
* A path relative to the files directory, or a full URL.
* @param $params
* Array of parameters, these will be merged with the defaults returned
* by _swf_params(). Custom parameters can passed here.
* NOTE: Flash version is passed on $params.
* @param $name
* @param $method
* One of the defaults defined in swftools.
*
*/
function swftools_display($filepath, $preview = FALSE, $action = FALSE, $player = FALSE, $embed = FALSE, $params = FALSE, $flashvars = FALSE, $othervars = FALSE) {
// Get all the actions, tools and embedding options available to us.
$all_methods = swftools_methods_available();
// TODO: Use the file type for making smart choices if no $action is available.
// $mime_type = array_pop(explode(".", $filepath));
$action = ($action) ? $action : NULL; // Action is currently required, TODO: dynamically identify from mime.
// Still work to do with previews.
$preview = ($preview) ? $preview : '';
// Create an array for the tools and embedding info
$methods = new StdClass();
// Select the player info.
$player = ($player) ? $player : variable_get($action, 'wijering_media');
$methods->player = $all_methods[$action][$player];
// Identify the type of embedding required.
$embed = ($embed) ? $embed : variable_get(SWFTOOLS_EMBED_METHOD, 'direct');
$methods->embed = $all_methods[SWFTOOLS_EMBED_METHOD][$embed];
// Put all the variables on a simple object to make internal function calls simpler.
$vars = new StdClass();
$vars->params = (is_array($params)) ? $params : array();
$vars->flashvars = (is_array($flashvars)) ? $flashvars : array();
$vars->othervars = (is_array($othervars)) ? $othervars : array();
global $base_url;
// TODO: if the user explicitly declares a player/action, we need to verify it is available.
// TODO: Determine the action/method based on mime;
// $swf = flashembed_swf_by_mime($mime_type);
// Set the file path.
if (valid_url($filepath, TRUE)) {
$file_url = check_url($filepath);
}
else {
$file_url = check_url($base_url .'/'. file_create_path($filepath));
}
// Determine the "src" file part of the embed.
if ($action == SWFTOOLS_SWF_DISPLAY_DIRECT) {
// The file path is the src.
$vars->params['src'] = $file_url;
}
else {
// Get the file we need for this method, eg. the Flash player.
$vars->params['src'] = check_url($base_url .'/'. drupal_get_path('module', 'swftools') .'/shared/'. $methods->player['shared_file']);
// Set the $file_url to othervars, ready for callback to the player module.
$vars->othervars['file_url'] = $file_url;
}
// Merge default and user defined "params".
$vars->params = array_merge(_swf_params(), $vars->params);
// Ask the module implementing the player what flashvars are required, passing
// the user defined flashvars for merging.
$flashvars = module_invoke($methods->player['module'], 'swftools_flashvars', $action, $methods, $vars);
// Build a string out of the flashvars array.
$vars->params['flashvars'] = swftools_build_flashvars($vars->flashvars);
// The call the embedding code to get the html and set the javascript if necessary.
$html = module_invoke($methods->embed['module'], 'swftools_embed', $action, $methods, $vars);
// The $html code is already built, but allow it to be changed.
return theme('swftools_embed', $html, $action, $methods, $vars, $preview);
}
function theme_swftools_embed($html, $action, &$methods, &$vars, $preview) {
return $html;
}
/**
* "flashvars" is a parameter like height and width, which are
* passed into the flash player as a=1&b=2&...
*
*/
function swftools_build_flashvars(&$flashvars) {
return drupal_query_string_encode($flashvars);
}
/**
* Implementation of swftools_embed hook
* Returns the markup for the page.
*/
function swftools_swftools_embed($action, &$methods, &$vars, $preview = 'NA') {
$P = $vars->params; // For legibility.
$html = '' . "\n" ;
return $html;
}
/**
* These are the default flash parameters.
*
*/
function _swf_params() {
$swf_options = _swf_options();
$defaults = array(
'wmode' => $swf_options['wmode'][variable_get('swftools_movie_wmode', '0')],
'bgcolor' => variable_get('swftools_movie_bgcolor', '#FFFFFF'),
'menu' => $swf_options['bool'][variable_get('swftools_movie_menu', '1')],
'play' => $swf_options['bool'][variable_get('swftools_movie_play', '1')],
'loop' => $swf_options['bool'][variable_get('swftools_movie_loop', '1')],
'quality' => $swf_options['quality'][variable_get('swftools_movie_quality', '4')],
'salign' => '',
'scale' => $swf_options['scale'][variable_get('swftools_movie_scale', '0')],
'swliveconnect' => $swf_options['bool'][variable_get('swftools_movie_swliveconnect', '0')],
'name' => variable_get('swftools_movie_menu', '1'),
'width' => '100%',
'height' => '100%',
'title' => '',
);
return $defaults;
}
/**
* flashvar and param option arrays.
*
*/
function _swf_options() {
// cache output each request
static $swf_options = array();
if (!count($swf_options)) {
$swf_options['quality'] = array('0' => 'low', '1' => 'autolow', '2' => 'medium', '3' => 'high', '4' => 'autohigh', '5' => 'best');
$swf_options['wmode'] = array('0' => 'window', '1' => 'opaque', '2' => 'transparent');
$swf_options['scale'] = array('0' => 'showall', '1' => 'noborder', '2' => 'exactfit');
$swf_options['bool'] = array('0' => 'false', '1' => 'true');
}
return $swf_options;
}
/**
* Collect information from all modules about the Flash players, tools and scripts
* available for various actions.
*
*/
function swftools_methods_available($action = NULL, $reset = FALSE) {
// Cache methods array.
static $methods = array();
if ($reset) {
$methods = array();
}
elseif (count($methods)) {
return ($action) ? $methods[$action] : $methods;
}
// Gather methods.
$methods = module_invoke_all('swftools_methods');
// This module implements a default plain HTML embedding method called 'direct'
$methods[SWFTOOLS_EMBED_METHOD]['direct'] = array (
'name' => 'direct',
'module' => 'swftools',
'shared_file' => '',
'title' => t('Embed Flash Directly'),
);
return ($action) ? $methods[$action] : $methods;
}