View source
<?php
define('FLOWPLAYER_MEDIAPLAYER', 'flowplayer_mediaplayer');
define('FLOWPLAYER_IMAGEROTATOR', 'flowplayer_imagerotator');
define('FLOWPLAYER_DOWNLOAD', 'http://flowplayer.org/');
function flowplayer_swftools_methods() {
$saved_settings = variable_get('swftools_' . FLOWPLAYER_MEDIAPLAYER, array());
$shared_file = $saved_settings['player'] ? $saved_settings['player'] : 'flowplayer/FlowPlayerClassic.swf';
$methods = array();
$media_player = array(
'name' => FLOWPLAYER_MEDIAPLAYER,
'module' => 'flowplayer',
'file' => 'videoFile',
'version' => '7',
'shared_file' => $shared_file,
'title' => t('FlowPlayer'),
'download' => FLOWPLAYER_DOWNLOAD,
);
$methods[SWFTOOLS_FLV_DISPLAY][FLOWPLAYER_MEDIAPLAYER] = $media_player;
$methods[SWFTOOLS_FLV_DISPLAY_LIST][FLOWPLAYER_MEDIAPLAYER] = $media_player;
$methods[SWFTOOLS_MP3_DISPLAY][FLOWPLAYER_MEDIAPLAYER] = $media_player;
$methods[SWFTOOLS_MP3_DISPLAY_LIST][FLOWPLAYER_MEDIAPLAYER] = $media_player;
$methods[SWFTOOLS_MEDIA_DISPLAY][FLOWPLAYER_MEDIAPLAYER] = $media_player;
$methods[SWFTOOLS_MEDIA_DISPLAY_LIST][FLOWPLAYER_MEDIAPLAYER] = $media_player;
$methods[SWFTOOLS_IMAGE_DISPLAY_LIST][FLOWPLAYER_MEDIAPLAYER] = $media_player;
return $methods;
}
function flowplayer_menu() {
$items = array();
$items['admin/settings/swftools/flowplayer'] = array(
'title' => 'FlowPlayer',
'description' => 'Settings for ' . l('FlowPlayer', FLOWPLAYER_DOWNLOAD) . '.',
'access arguments' => array(
'administer flash',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'flowplayer_admin_form',
),
'file' => 'flowplayer.admin.inc',
'file path' => drupal_get_path('module', 'flowplayer'),
);
return $items;
}
function flowplayer_swftools_flashvars($action, &$methods, &$vars) {
$saved_settings = _flowplayer_flashvars($methods->player['name']);
$saved = array();
foreach ($saved_settings as $category => $settings) {
$saved = array_merge($saved, $settings);
}
$flashvars = array_merge($saved, $vars->flashvars);
if (isset($flashvars['image']) && !valid_url($flashvars['image'], TRUE)) {
$flashvars['image'] = swftools_get_media_url(swftools_get_media_path() . $flashvars['image']);
}
if ($vars->params['width']) {
$flashvars['width'] = $vars->params['width'];
}
if ($vars->params['height']) {
$flashvars['height'] = $vars->params['height'];
}
$flowplayer = array();
if (pathinfo($vars->othervars['file_url'], PATHINFO_EXTENSION) == 'xml') {
$playlist = array();
foreach ($vars->othervars['playlist_data']['playlist'] as $play) {
$playlist[] = "{ url: '" . $play['fileurl'] . "' }";
}
$flowplayer['playList'] = '[ ' . implode(', ', $playlist) . ' ]';
}
else {
$flowplayer['videoFile'] = $vars->othervars['file_url'];
}
$available_settings = flowplayer_swftools_variable_mapping();
foreach ($available_settings[FLOWPLAYER_MEDIAPLAYER] as $setting => $value) {
if ($flashvars[$setting]) {
$flowplayer[$setting] = $flashvars[$setting];
unset($flashvars[$setting]);
}
}
if ($vars->othervars['loop']) {
$flowplayer['loop'] = $vars->othervars['loop'];
}
$flashvars['config'] = drupal_to_js($flowplayer);
$flashvars['config'] = str_replace(array(
'"',
"'false'",
"'true'",
"'[",
"]'",
), array(
"'",
"false",
"true",
"[",
"]",
), $flashvars['config']);
if ($playlist) {
$flashvars['config'] = str_replace(array(
"url: \\'",
"\\' }",
), array(
"url: '",
"' }",
), $flashvars['config']);
}
return $flashvars;
}
function _flowplayer_flashvars($this_player) {
static $flashvars = array();
if (!count($flashvars)) {
foreach (array(
FLOWPLAYER_MEDIAPLAYER,
) as $player) {
$defaults = _flowplayer_settings($player);
foreach ($defaults as $category => $vars) {
foreach ($vars as $key => $setting) {
if (!$setting || $setting == 'default') {
unset($defaults[$category][$key]);
}
else {
switch ($category) {
case 'color':
$defaults['color'][$key] = str_replace('#', '0x', $defaults['color'][$key]);
break;
case 'boolean':
$defaults['boolean'][$key] = _swftools_tf($defaults['boolean'][$key]);
break;
}
}
}
}
if ($defaults['integer']['displaywidth']) {
unset($defaults['integer']['displayheight']);
}
else {
unset($defaults['integer']['displaywidth']);
}
$flashvars[$player] = $defaults;
}
}
return $flashvars[$this_player];
}
function swftools_flowplayer_mediaplayer_playlist($xml_data, &$method, &$vars) {
$xml = '<playlist version="1" xmlns="http://xspf.org/ns/0/">
<title>' . $xml_data['header']['title'] . '</title>
<info></info>
<annotation></annotation>
<trackList>
';
foreach ($xml_data['playlist'] as $track => $details) {
if (!isset($details['background']) && strtolower(substr($details['fileurl'], -3, 3)) == 'mp3') {
if (isset($vars->flashvars['image'])) {
$details['background'] = swftools_get_media_url(swftools_get_media_path() . $vars->flashvars['image']);
}
else {
$details['background'] = SWFTOOLS_DEFAULT_BG;
}
}
$xml .= "<track>\n";
$xml .= "<title>" . $details['title'] . "</title>\n";
$xml .= "<creator></creator>\n";
$xml .= "<location>" . $details['fileurl'] . "</location>\n";
$xml .= "<image>" . $details['background'] . "</image>\n";
$xml .= "<info>" . $details['fileurl'] . "</info>\n";
$xml .= "</track>\n";
}
$xml .= '</trackList>
</playlist>';
return $xml;
}
function flowplayer_swftools_variable_mapping() {
return array(
FLOWPLAYER_MEDIAPLAYER => array(
'videoFile' => 'flashvars',
'autoPlay' => 'flashvars',
'initialVolumePercentage' => 'flashvars',
'usePlayOverlay' => 'flashvars',
'controlBarGloss' => 'flashvars',
'hideControls' => 'flashvars',
'loop' => 'flashvars',
'fullscreen' => 'flashvars',
'showFullScreenButton' => 'flashvars',
'showPlayListButtons' => 'flashvars',
),
);
}
function _flowplayer_settings($player) {
switch ($player) {
case FLOWPLAYER_MEDIAPLAYER:
$defaults['boolean'] = array(
'autoPlay' => 'default',
'usePlayOverlay' => 'default',
'hideControls' => 'default',
'loop' => 'default',
'showFullScreenButton' => 'default',
'showPlayListButtons' => 'default',
);
$defaults['color'] = array();
$defaults['url'] = array();
$defaults['integer'] = array(
'initialVolumePercentage' => '',
);
$defaults['other'] = array(
'player' => 'default',
'controlBarGloss' => 'default',
);
$saved_settings = variable_get('swftools_' . FLOWPLAYER_MEDIAPLAYER, array());
break;
}
foreach ($defaults as $category => $vars) {
foreach ($vars as $key => $setting) {
if (isset($saved_settings[$key])) {
$defaults[$category][$key] = $saved_settings[$key];
}
}
}
return $defaults;
}
function _flowplayer_options() {
$options['type'] = array(
'default' => 'default',
'sound' => 'sound',
'image' => 'image',
'video' => 'video',
'youtube' => 'youtube',
'camera' => 'camera',
'http' => 'http',
'rtmp' => 'rtmp',
);
$options['overstretch'] = array(
'default' => 'default',
'uniform' => 'uniform',
'fill' => 'fill',
'exactfit' => 'exactfit',
'none' => 'none',
);
$options['repeat'] = array(
'default' => 'default',
'none' => 'none',
'list' => 'list',
'always' => 'always',
);
$options['linktarget'] = array(
'default' => 'default',
'_self' => '_self',
'_blank' => '_blank',
'none' => 'none',
);
$options['playlist'] = array(
'default' => 'default',
'bottom' => 'bottom',
'over' => 'over',
'right' => 'right',
'none' => 'none',
);
$options['controlbar'] = array(
'default' => 'default',
'bottom' => 'bottom',
'over' => 'over',
'none' => 'none',
);
$options['displayclick'] = array(
'default' => 'default',
'play' => 'play',
'link' => 'link',
'fullscreen' => 'fullscreen',
'none' => 'none',
'mute' => 'mute',
'next' => 'next',
);
$options['player'] = array(
'flowplayer/FlowPlayerClassic.swf' => 'Classic',
'flowplayer/FlowPlayerDark.swf' => 'Dark',
'flowplayer/FlowPlayerLight.swf' => 'Light',
'flowplayer/FlowPlayerLP.swf' => 'LP',
);
$options['controlBarGloss'] = array(
'default' => 'default',
'high' => 'high',
'low' => 'low',
'none' => 'none',
);
$options['bool'] = array(
'default' => 'default',
'true' => 'true',
'false' => 'false',
);
return $options;
}
function flowplayer_help($path, $arg) {
switch ($path) {
case 'admin/settings/swftools/flowplayer':
return '<p>' . t('These are the settings for the FlowPlayer media player.
For details of what each parameter does refer to the
<a href="@flowplayer">FlowPlayer documentation</a>.
It is possible that you do not need to change any of
these settings and blank values will defer to friendly
defaults. Note that the label in (<em>brackets</em>)
is the configuration setting name and corresponds to the documentation page.
If content is embedded using the SWF Tools filter then each parameter
can be over-ridden by specifying a new value in the filter string.', array(
'@flowplayer' => 'http://flowplayer.org/player/configuration.html',
)) . '</p>';
}
}