View source
<?php
define('FLOWPLAYER_PATH', 'sites/all/libraries/flowplayer');
function flowplayer_help($path, $arg) {
switch ($path) {
case 'admin/config/media/flowplayer':
return t('The following provides the default Flowplayer settings when the player is displayed. This does not mean it is how it will be displayed everywhere, it will just be the defaults if these settings are not explicitly sent through to the player.');
case 'admin/help#flowplayer':
$output = '<p>' . t('The following is a demonstration of <a href="@flowplayer">Flowplayer</a>. Note that you can change the defaults of how it looks in the <a href="@settings">Flowplayer settings</a>.', array(
'@flowplayer' => 'http://flowplayer.org',
'@settings' => url('admin/settings/flowplayer'),
)) . '</p>';
$output .= '<p>' . t("To create Flowplayer elements, you can either use the theme('flowplayer') function, or the flowplayer_add() function. The theme function will add the JavaScript to the page, as well as create the markup for you, while the <code>flowplayer_add()</code> function will just add the JavaScript.") . '</p>';
$output .= '<h3>' . t('Theme Funciton') . '</h3>';
$output .= '<p>' . t("Calling <code>theme('flowplayer')</code> will not only add the correct JavaScript to the page, but also construct the markup for you. The second argument passed through here is the video URL, but you can pass the <a href='http://flowplayer.org/documentation/configuration.html'>configuration options</a> instead as seen below.") . '</p>';
$config = array(
'clip' => array(
'url' => 'http://pseudo01.hddn.com/vod/demo.flowplayervod/flowplayer-700.flv',
'autoPlay' => FALSE,
),
);
$output .= theme('flowplayer', array(
'config' => $config,
'id' => 'flowplayer-preview',
'attributes' => array(
'style' => 'width:640px;height:380px;',
),
));
$output .= '<h3>' . t('Flowplayer Add') . '</h3>';
$output .= '<p>' . t("The <code>flowplayer_add()</code> function will add the Flowplayer JavaScript to the page, as well as register the Drupal JavaScript behaviors to load the Flowplayer appropriately. The first argument is the jQuery selector to apply the Flowplayer element to. The second argument is the <a href='http://flowplayer.org/documentation/configuration.html'>configuration options</a>. Using <code>flowplayer_add</code> requires you to already have the markup created.") . '</p>';
$output .= '<a href="http://e1h13.simplecdn.net/flowplayer/flowplayer.flv" id="player" class="flowplayer"></a>';
flowplayer_add('#player', array(
'clip' => array(
'autoPlay' => FALSE,
'linkUrl' => 'http://flowplayer.org',
),
));
$output .= '<h3>' . t('Audio Plugin') . '</h3>';
$output .= theme('flowplayer', array(
'playlist' => array(
array(
'url' => 'http://flowplayer.org/img/demos/national.jpg',
'scaling' => 'orig',
),
array(
'url' => 'http://flowplayer.org/demos/plugins/fake_empire.mp3',
'autoPlay' => FALSE,
),
),
), 'audio', array(
'style' => 'width:300px; height: 243px;',
));
return $output;
break;
}
}
function flowplayer_add($selector = NULL, $config = NULL) {
static $flowplayer_added = FALSE;
static $flowplayer_selectors = array();
$flowplayer_path = flowplayer_get_path();
if (!$flowplayer_path) {
watchdog('flowplayer', 'Flowplayer was not found. Please read the manual for mor instructions on how to set up flowplayer.', array(), WATCHDOG_ERROR);
return FALSE;
}
if ($flowplayer_added === FALSE) {
drupal_add_js(_flowplayer_get_js_path());
drupal_add_css(drupal_get_path('module', 'flowplayer') . '/flowplayer.css');
$settings = array(
'flowplayerSwf' => _flowplayer_get_swf_path(),
);
drupal_add_js($settings, 'setting');
$flowplayer_added = TRUE;
}
if (isset($selector) && !isset($flowplayer_selectors[$selector])) {
if (empty($flowplayer_selectors)) {
drupal_add_js(drupal_get_path('module', 'flowplayer') . '/flowplayer.js');
}
if (is_string($config)) {
$config = array(
'clip' => array(
'url' => $config,
),
);
}
if (!isset($config['key'])) {
$key = variable_get('flowplayer_key', NULL);
if (!empty($key)) {
$config['key'] = $key;
}
}
$scaling = variable_get('flowplayer_scaling', NULL);
if (!empty($scaling)) {
$config['clip']['scaling'] = $scaling;
}
$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;
}
}
}
$buttons = variable_get('flowplayer_buttons', array());
foreach ($buttons as $button => $enabled) {
if (!isset($config['plugins']['controls'][$button])) {
$config['plugins']['controls'][$button] = $enabled ? TRUE : FALSE;
}
}
if (!isset($config['plugins']['controls']['backgroundGradient'])) {
$gradient = variable_get('flowplayer_background_gradient', NULL);
if (!empty($gradient)) {
$config['plugins']['controls']['backgroundGradient'] = $gradient;
}
}
if (!isset($config['plugins']['controls']['borderRadius'])) {
$radius = variable_get('flowplayer_border_radius', NULL);
if (!empty($radius)) {
$config['plugins']['controls']['borderRadius'] = $radius;
}
}
drupal_add_js(array(
'flowplayer' => array(
$selector => $config,
),
), 'setting');
$flowplayer_selectors[$selector] = TRUE;
}
}
function flowplayer_menu() {
$items = array();
$items['admin/config/media/flowplayer'] = array(
'title' => 'Flowplayer',
'description' => 'Manage how Flowplayer is used on your site.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'flowplayer_admin_settings',
),
'file' => 'flowplayer.admin.inc',
'access arguments' => array(
'administer site configuration',
),
);
return $items;
}
function flowplayer_theme() {
return array(
'flowplayer' => array(
'variables' => array(
'config' => NULL,
'id' => 'flowplayer',
'attributes' => array(),
),
),
);
}
function theme_flowplayer($variables) {
$config = $variables['config'];
$id = $variables['id'];
$attributes = $variables['attributes'];
$id = drupal_clean_css_identifier($id);
if (isset($attributes['class'])) {
$attributes['class'] .= ' flowplayer';
}
else {
$attributes['class'] = 'flowplayer';
}
$attributes = drupal_attributes($attributes);
flowplayer_add('#' . $id, $config);
return "<div id='{$id}' {$attributes}></div>";
}
function flowplayer_get_path() {
static $library_path = NULL;
if ($library_path == NULL) {
$path = variable_get('flowplayer_path', FLOWPLAYER_PATH);
if (is_dir($path)) {
$library_path = $path;
}
elseif ($library_path == NULL && module_exists('libraries')) {
if ($path = libraries_get_path('flowplayer')) {
$library_path = $path;
variable_set('flowplayer_path', $library_path);
}
}
elseif ($library_path == NULL) {
$library_path = FLOWPLAYER_PATH;
}
}
return $library_path;
}
function _flowplayer_get_js_path() {
$library_path = flowplayer_get_path();
$files = glob($library_path . '/flowplayer.min.js');
return isset($files[0]) ? $files[0] : FALSE;
}
function _flowplayer_get_swf_path() {
$library_path = flowplayer_get_path();
$files = glob($library_path . '/flowplayer.swf');
return isset($files[0]) ? $files[0] : false;
}
function _flowplayer_get_controls_swf_path() {
$library_path = flowplayer_get_path();
$files = glob($library_path . "/flowplayer.controls-*.swf");
return isset($files[0]) ? $files[0] : false;
}