function flowplayer_add in Flowplayer API 7
Same name and namespace in other branches
- 5 flowplayer.module \flowplayer_add()
- 6 flowplayer.module \flowplayer_add()
- 7.2 flowplayer.module \flowplayer_add()
Adds a FlowPlayer element to the page.
Parameters
$selector: (optional) The jQuery selector to apply the FlowPlayer to. If not given, will just add the FlowPlayer JavaScript plugin.
$config: (optional) Can either be a string representing the media to load, or an array of arguments containing the options provided on this page: http://flowplayer.org/documentation/configuration.html
2 calls to flowplayer_add()
- flowplayer_help in ./
flowplayer.module - Implementation of hook_help().
- theme_flowplayer in ./
flowplayer.module - Creates the markup and adds the JavaScript to display a media file in
1 string reference to 'flowplayer_add'
- flowplayer_jq in ./
flowplayer.jq.inc - @file Adds support for the jQ module.
File
- ./
flowplayer.module, line 86 - Provides integration with FlowPlayer.
Code
function flowplayer_add($selector = NULL, $config = NULL) {
// Maintain kill switches for both Flowplayer and the Drupal behaviors.
static $flowplayer_added = FALSE;
static $flowplayer_selectors = array();
// Add Flowplayer to the page if it hasn't been added yet.
if ($flowplayer_added === FALSE) {
// Add the FlowPlayer JavaScript and CSS to the page.
drupal_add_js(drupal_get_path('module', 'flowplayer') . '/flowplayer/example/flowplayer.min.js');
drupal_add_css(drupal_get_path('module', 'flowplayer') . '/flowplayer.css');
// Tell the JavaScript where flowplayer.swf is.
$settings = array(
'flowplayerSwf' => drupal_get_path('module', 'flowplayer') . '/flowplayer/flowplayer.swf',
);
drupal_add_js($settings, 'setting');
$flowplayer_added = TRUE;
}
// Add the settings if they haven't been added for the selector yet.
if (isset($selector) && !isset($flowplayer_selectors[$selector])) {
// Register the FlowPlayer Drupal behavior so that the elements are processed.
if (empty($flowplayer_selectors)) {
// Note that this is only added for the first one added because we only need
// it if we are processing through settings.flowplayer.
drupal_add_js(drupal_get_path('module', 'flowplayer') . '/flowplayer.js');
}
// Convert any strings to an array so that we can merge in the defaults.
if (is_string($config)) {
$config = array(
'clip' => array(
'url' => $config,
),
);
}
// Merge in the defaults, starting with the license key.
if (!isset($config['key'])) {
$key = variable_get('flowplayer_key', NULL);
if (!empty($key)) {
$config['key'] = $key;
}
}
// Merge scaling option in the defaults.
$scaling = variable_get('flowplayer_scaling', NULL);
if (!empty($scaling)) {
$config['clip']['scaling'] = $scaling;
}
// The player colors.
$colors = array(
'backgroundColor',
'sliderColor',
'buttonColor',
'buttonOverColor',
'durationColor',
'timeColor',
'progressColor',
'bufferColor',
);
foreach ($colors as $color) {
if (!isset($config['plugins']['controls'][$color])) {
$color_value = variable_get('flowplayer_color_' . $color, NULL);
if (!empty($color_value)) {
$config['plugins']['controls'][$color] = $color_value;
}
}
}
// The controlbar styling.
$buttons = variable_get('flowplayer_buttons', array());
foreach ($buttons as $button => $enabled) {
if (!isset($config['plugins']['controls'][$button])) {
$config['plugins']['controls'][$button] = $enabled ? TRUE : FALSE;
}
}
// Gradient.
if (!isset($config['plugins']['controls']['backgroundGradient'])) {
$gradient = variable_get('flowplayer_background_gradient', NULL);
if (!empty($gradient)) {
$config['plugins']['controls']['backgroundGradient'] = $gradient;
}
}
// Border radius.
if (!isset($config['plugins']['controls']['borderRadius'])) {
$radius = variable_get('flowplayer_border_radius', NULL);
if (!empty($radius)) {
$config['plugins']['controls']['borderRadius'] = $radius;
}
}
// Add the flowplayer element to the settings so that it's processed by the behaviours.
drupal_add_js(array(
'flowplayer' => array(
$selector => $config,
),
), 'setting');
$flowplayer_selectors[$selector] = TRUE;
}
}