| 1 |
<?php
|
| 2 |
// $Id: flowplayer.module,v 1.10 2009/03/15 15:24:36 stuartgreenfield Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* SWF Tools - FlowPlayer
|
| 6 |
*
|
| 7 |
* Enables the use of FlowPlayer for media files
|
| 8 |
*
|
| 9 |
* Author's Site.
|
| 10 |
* http://flowplayer.org
|
| 11 |
*/
|
| 12 |
|
| 13 |
define('FLOWPLAYER_MEDIAPLAYER', 'flowplayer_mediaplayer'); // 'player', can display mixed files
|
| 14 |
define('FLOWPLAYER_IMAGEROTATOR', 'flowplayer_imagerotator'); // 'player', can display images.
|
| 15 |
define('FLOWPLAYER_DOWNLOAD', 'http://www.tucows.com/download.html?software_id=519713&t=2');
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Implementation of swftools_methods hook
|
| 19 |
* Report methods back to SWF Tools
|
| 20 |
*/
|
| 21 |
function flowplayer_swftools_methods() {
|
| 22 |
|
| 23 |
// FlowPlayer has a few different player files, so we need to determine
|
| 24 |
// which one is currently active
|
| 25 |
$saved_settings = variable_get('swftools_'. FLOWPLAYER_MEDIAPLAYER, array());
|
| 26 |
$shared_file = $saved_settings['player'] ? $saved_settings['player'] : 'flowplayer/FlowPlayerClassic.swf';
|
| 27 |
|
| 28 |
$methods = array();
|
| 29 |
$media_player = array(
|
| 30 |
'name' => FLOWPLAYER_MEDIAPLAYER,
|
| 31 |
'module' => 'flowplayer',
|
| 32 |
'file' => '',
|
| 33 |
'version' => '7',
|
| 34 |
//'shared_file' => 'flowplayer/FlowPlayerClassic.swf',
|
| 35 |
'shared_file' => $shared_file,
|
| 36 |
'title' => t('FlowPlayer'),
|
| 37 |
'download' => FLOWPLAYER_DOWNLOAD,
|
| 38 |
'width' => '320',
|
| 39 |
'height' => '263',
|
| 40 |
);
|
| 41 |
// Wijering support various actions with the same player and info.
|
| 42 |
$methods[SWFTOOLS_FLV_DISPLAY][FLOWPLAYER_MEDIAPLAYER] = $media_player;
|
| 43 |
$methods[SWFTOOLS_FLV_DISPLAY_LIST][FLOWPLAYER_MEDIAPLAYER] = $media_player;
|
| 44 |
$methods[SWFTOOLS_MP3_DISPLAY][FLOWPLAYER_MEDIAPLAYER] = $media_player;
|
| 45 |
$methods[SWFTOOLS_MP3_DISPLAY_LIST][FLOWPLAYER_MEDIAPLAYER] = $media_player;
|
| 46 |
$methods[SWFTOOLS_MEDIA_DISPLAY][FLOWPLAYER_MEDIAPLAYER] = $media_player;
|
| 47 |
$methods[SWFTOOLS_MEDIA_DISPLAY_LIST][FLOWPLAYER_MEDIAPLAYER] = $media_player;
|
| 48 |
$methods[SWFTOOLS_IMAGE_DISPLAY_LIST][FLOWPLAYER_MEDIAPLAYER] = $media_player;
|
| 49 |
|
| 50 |
return $methods;
|
| 51 |
}
|
| 52 |
|
| 53 |
/**
|
| 54 |
* Implementation of hook_menu().
|
| 55 |
*/
|
| 56 |
function flowplayer_menu() {
|
| 57 |
|
| 58 |
$items = array();
|
| 59 |
|
| 60 |
//$items['admin/media/swf/flowplayer'] = array(
|
| 61 |
$items['admin/settings/swftools/flowplayer'] = array(
|
| 62 |
'title' => 'FlowPlayer',
|
| 63 |
'description' => 'Settings for '. l('FlowPlayer', FLOWPLAYER_DOWNLOAD) .'.',
|
| 64 |
'access arguments' => array('administer flash'),
|
| 65 |
'page callback' => 'drupal_get_form',
|
| 66 |
'page arguments' => array('flowplayer_admin_form'),
|
| 67 |
'file' => 'flowplayer.admin.inc',
|
| 68 |
'file path' => drupal_get_path('module', 'flowplayer'),
|
| 69 |
);
|
| 70 |
|
| 71 |
return $items;
|
| 72 |
}
|
| 73 |
|
| 74 |
|
| 75 |
/**
|
| 76 |
* Implementation of swftools_flashvars hook.
|
| 77 |
* Return an array of flashvars.
|
| 78 |
*/
|
| 79 |
function flowplayer_swftools_flashvars($action, &$methods, &$vars) {
|
| 80 |
|
| 81 |
// Pad out the user parameters (like those passed through swf(), with our
|
| 82 |
// configured defaults, allowing the user parameters to dominate.
|
| 83 |
$saved_settings = _flowplayer_flashvars($methods->player['name']);
|
| 84 |
|
| 85 |
$saved = array();
|
| 86 |
foreach ($saved_settings as $category => $settings) {
|
| 87 |
$saved = array_merge($saved, $settings);
|
| 88 |
}
|
| 89 |
$flashvars = array_merge($saved, $vars->flashvars);
|
| 90 |
|
| 91 |
if (isset($flashvars['image']) && !valid_url($flashvars['image'], TRUE)) {
|
| 92 |
$flashvars['image'] = swftools_get_media_url(swftools_get_media_path() . $flashvars['image']);
|
| 93 |
}
|
| 94 |
|
| 95 |
if ($vars->params['width']) {$flashvars['width'] = $vars->params['width'];}
|
| 96 |
if ($vars->params['height']) {$flashvars['height'] = $vars->params['height'];}
|
| 97 |
|
| 98 |
/* FlowPlayer doesn't like "" when JSON is generated, so we have to construct it ourselves here
|
| 99 |
* and assign it to the variable config.
|
| 100 |
* Build an array of FlowPlayer configuration settings, then call drupal_to_js to convert
|
| 101 |
* to JSON format, and then run through str_replac to make FlowPlayer happy!
|
| 102 |
*/
|
| 103 |
|
| 104 |
// Initialise array of FlowPlayer configuration settings
|
| 105 |
$flowplayer = array();
|
| 106 |
|
| 107 |
// If the passed filename ends in xml then it is a playlist
|
| 108 |
// FlowPlayer format requires a bit of adjusting to get things in the right format
|
| 109 |
// and we don't want an xml playlist but a flashvars string
|
| 110 |
if (pathinfo($vars->othervars['file_url'], PATHINFO_EXTENSION) == 'xml') {
|
| 111 |
|
| 112 |
// Initialise array to hold data
|
| 113 |
$playlist = array();
|
| 114 |
|
| 115 |
// Get file paths out of existing array and start to form FlowPlayer format
|
| 116 |
foreach ($vars->othervars['playlist_data']['playlist'] as $play) {
|
| 117 |
$playlist[] = "{ url: '".$play['fileurl']."' }";
|
| 118 |
}
|
| 119 |
|
| 120 |
// Implode the array to create a flashvar ready for later
|
| 121 |
$flowplayer['playList'] = '[ '. implode(', ', $playlist) .' ]';
|
| 122 |
} else {
|
| 123 |
|
| 124 |
// If not a playlist simply assign file_url to videoFile
|
| 125 |
$flowplayer['videoFile'] = $vars->othervars['file_url'];
|
| 126 |
}
|
| 127 |
|
| 128 |
// Find out what configuration settings are available
|
| 129 |
$available_settings = flowplayer_swftools_variable_mapping();
|
| 130 |
|
| 131 |
// See which ones have been set in othervars and copy to flowplayer array
|
| 132 |
foreach ($available_settings[FLOWPLAYER_MEDIAPLAYER] as $setting => $value) {
|
| 133 |
|
| 134 |
if (isset($flashvars[$setting])) {
|
| 135 |
$flowplayer[$setting] = $flashvars[$setting];
|
| 136 |
unset($vars->flashvars[$setting]);
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
| 140 |
/**
|
| 141 |
* FlowPlayer uses 'loop' as the parameter to control looping
|
| 142 |
* This is already used as flash parameter so using loop in a
|
| 143 |
* filter means it isn't passed in the flashvars array. So copy
|
| 144 |
* whatever value we have in the parameter to flowplayer array
|
| 145 |
*/
|
| 146 |
if ($vars->othervars['loop']) {
|
| 147 |
$flowplayer['loop'] = $vars->othervars['loop'];
|
| 148 |
}
|
| 149 |
|
| 150 |
// Merge $vars->othervars in to flashvars
|
| 151 |
//$flowplayer = array_merge($flowplayer, $vars->othervars);
|
| 152 |
|
| 153 |
// Convert to JSON
|
| 154 |
$flashvars['config'] = drupal_to_js($flowplayer);
|
| 155 |
|
| 156 |
// Replace " with ', and remove quotes from around true and false, to satisfy FlowPlayer
|
| 157 |
$flashvars['config'] = str_replace(array('"', "'false'", "'true'", "'[", "]'"), array("'", "false", "true", "[", "]"), $flashvars['config']);
|
| 158 |
|
| 159 |
// If we had a playlist then the ' has been escaped, so reverse it where it occurs in the playlist
|
| 160 |
if ($playlist) {
|
| 161 |
$flashvars['config'] = str_replace(array("url: \'", "\' }"), array("url: '", "' }"), $flashvars['config']);
|
| 162 |
}
|
| 163 |
|
| 164 |
// Return an array of flash variables
|
| 165 |
return $flashvars;
|
| 166 |
}
|
| 167 |
|
| 168 |
/**
|
| 169 |
* This function is called from flowplayer_swftools_flashvars() which is called from swf()
|
| 170 |
* It will return the default flashvar configuration, just prior to any overrides
|
| 171 |
* passed into swf(). We start with the settings defined on admin/swf/wijering
|
| 172 |
* which are returned by _flowplayer_settings(). Then we prepare these values for output
|
| 173 |
* to html (eg. '1' become 'true') and we unset undefined flashvars to prevent their output.
|
| 174 |
*
|
| 175 |
*/
|
| 176 |
function _flowplayer_flashvars($this_player) {
|
| 177 |
// Cache this.
|
| 178 |
static $flashvars = array();
|
| 179 |
if (!count($flashvars)) {
|
| 180 |
|
| 181 |
// Media Player
|
| 182 |
foreach (array(FLOWPLAYER_MEDIAPLAYER) AS $player) {
|
| 183 |
|
| 184 |
// Get saved settings for this method.
|
| 185 |
$defaults = _flowplayer_settings($player);
|
| 186 |
foreach ($defaults AS $category => $vars) {
|
| 187 |
foreach ($vars AS $key => $setting) {
|
| 188 |
if (!$setting || $setting == 'default') {
|
| 189 |
unset($defaults[$category][$key]);
|
| 190 |
}
|
| 191 |
else {
|
| 192 |
switch ($category) {
|
| 193 |
case 'color':
|
| 194 |
$defaults['color'][$key] = str_replace('#', '0x', $defaults['color'][$key]);
|
| 195 |
break;
|
| 196 |
case 'boolean':
|
| 197 |
$defaults['boolean'][$key] = _swftools_tf($defaults['boolean'][$key]);
|
| 198 |
break;
|
| 199 |
}
|
| 200 |
}
|
| 201 |
}
|
| 202 |
}
|
| 203 |
|
| 204 |
// Not the same as width/height. This determines the extended width OR height
|
| 205 |
// past the main view area where the actual playlist file names can be found.
|
| 206 |
// Setting both together is not supported.
|
| 207 |
if ($defaults['integer']['displaywidth']) {
|
| 208 |
unset($defaults['integer']['displayheight']);
|
| 209 |
}
|
| 210 |
else {
|
| 211 |
unset($defaults['integer']['displaywidth']);
|
| 212 |
}
|
| 213 |
$flashvars[$player] = $defaults;
|
| 214 |
}
|
| 215 |
}
|
| 216 |
|
| 217 |
return $flashvars[$this_player];
|
| 218 |
}
|
| 219 |
|
| 220 |
|
| 221 |
function flowplayer_flowplayer_mediaplayer_swftools_playlist($xml_data, &$method, &$vars) {
|
| 222 |
|
| 223 |
$xml = '<playlist version="1" xmlns="http://xspf.org/ns/0/">
|
| 224 |
<title>'. $xml_data['header']['title'] .'</title>
|
| 225 |
<info></info>
|
| 226 |
<annotation></annotation>
|
| 227 |
<trackList>
|
| 228 |
';
|
| 229 |
foreach ($xml_data['playlist'] AS $track => $details) {
|
| 230 |
|
| 231 |
if (!isset($details['background']) && strtolower(substr($details['fileurl'], -3, 3)) == 'mp3') {
|
| 232 |
if (isset($vars->flashvars['image'])) {
|
| 233 |
$details['background'] = swftools_get_media_url(swftools_get_media_path() . $vars->flashvars['image']);
|
| 234 |
} else {
|
| 235 |
$details['background'] = SWFTOOLS_DEFAULT_BG;
|
| 236 |
}
|
| 237 |
}
|
| 238 |
$xml .= "<track>\n";
|
| 239 |
$xml .= "<title>". $details['title'] ."</title>\n";
|
| 240 |
$xml .= "<creator></creator>\n";
|
| 241 |
$xml .= "<location>". $details['fileurl'] ."</location>\n";
|
| 242 |
$xml .= "<image>". $details['background'] ."</image>\n";
|
| 243 |
$xml .= "<info>". $details['fileurl'] ."</info>\n";
|
| 244 |
$xml .= "</track>\n";
|
| 245 |
}
|
| 246 |
$xml .= '</trackList>
|
| 247 |
</playlist>';
|
| 248 |
return $xml;
|
| 249 |
}
|
| 250 |
|
| 251 |
|
| 252 |
/*
|
| 253 |
* Implementation of hook_swftools_variable_mapping.
|
| 254 |
* We don't map anything to flashvars, but we want to know what
|
| 255 |
* settings are available
|
| 256 |
*
|
| 257 |
*/
|
| 258 |
function flowplayer_swftools_variable_mapping() {
|
| 259 |
return array(
|
| 260 |
FLOWPLAYER_MEDIAPLAYER => array(
|
| 261 |
'videoFile' => 'flashvars',
|
| 262 |
'autoPlay' => 'flashvars',
|
| 263 |
'initialVolumePercentage' => 'flashvars',
|
| 264 |
'usePlayOverlay' => 'flashvars',
|
| 265 |
'controlBarGloss' => 'flashvars',
|
| 266 |
'hideControls' => 'flashvars',
|
| 267 |
'loop' => 'flashvars',
|
| 268 |
'fullscreen' => 'flashvars',
|
| 269 |
'showFullScreenButton' => 'flashvars',
|
| 270 |
'showPlayListButtons' => 'flashvars',
|
| 271 |
),
|
| 272 |
);
|
| 273 |
}
|
| 274 |
|
| 275 |
|
| 276 |
/**
|
| 277 |
* These are the default settings as they are stored in the database and displayed
|
| 278 |
* on the settings page.
|
| 279 |
*/
|
| 280 |
function _flowplayer_settings($player) {
|
| 281 |
|
| 282 |
switch ($player) {
|
| 283 |
case FLOWPLAYER_MEDIAPLAYER:
|
| 284 |
// Define the settings list.
|
| 285 |
$defaults['boolean'] = array(
|
| 286 |
'autoPlay' => 'default',
|
| 287 |
'usePlayOverlay' => 'default',
|
| 288 |
'hideControls' => 'default',
|
| 289 |
'loop' => 'default',
|
| 290 |
'showFullScreenButton'=> 'default',
|
| 291 |
'showPlayListButtons' => 'default',
|
| 292 |
'fullscreen' => 'default',
|
| 293 |
);
|
| 294 |
$defaults['color'] = array(
|
| 295 |
);
|
| 296 |
$defaults['url'] = array(
|
| 297 |
);
|
| 298 |
$defaults['integer'] = array(
|
| 299 |
'initialVolumePercentage' => '',
|
| 300 |
);
|
| 301 |
$defaults['other'] = array(
|
| 302 |
'player' => 'default',
|
| 303 |
'controlBarGloss' => 'default',
|
| 304 |
);
|
| 305 |
$saved_settings = variable_get('swftools_'. FLOWPLAYER_MEDIAPLAYER, array());
|
| 306 |
break;
|
| 307 |
|
| 308 |
}
|
| 309 |
|
| 310 |
// Overwrite initialised variables with those that might be already saved.
|
| 311 |
foreach ($defaults AS $category => $vars) {
|
| 312 |
foreach ($vars AS $key => $setting) {
|
| 313 |
if (isset($saved_settings[$key])) {
|
| 314 |
$defaults[$category][$key] = $saved_settings[$key];
|
| 315 |
}
|
| 316 |
}
|
| 317 |
}
|
| 318 |
|
| 319 |
return $defaults;
|
| 320 |
}
|
| 321 |
|
| 322 |
|
| 323 |
/**
|
| 324 |
* flashvar and param option arrays. These are used for options settings in the
|
| 325 |
* configuration screen.
|
| 326 |
*
|
| 327 |
*/
|
| 328 |
function _flowplayer_options() {
|
| 329 |
$options['type'] = array('default' => 'default', 'sound' => 'sound', 'image' => 'image', 'video' => 'video', 'youtube' => 'youtube', 'camera' => 'camera', 'http' => 'http', 'rtmp' => 'rtmp', );
|
| 330 |
$options['overstretch'] = array('default' => 'default', 'uniform' => 'uniform', 'fill' => 'fill', 'exactfit' => 'exactfit', 'none' => 'none', );
|
| 331 |
$options['repeat'] = array('default' => 'default', 'none' => 'none', 'list' => 'list', 'always' => 'always', );
|
| 332 |
$options['linktarget'] = array('default' => 'default', '_self' => '_self', '_blank' => '_blank', 'none' => 'none', );
|
| 333 |
$options['playlist'] = array('default' => 'default', 'bottom' => 'bottom', 'over' => 'over', 'right' => 'right', 'none' => 'none', );
|
| 334 |
$options['controlbar'] = array('default' => 'default', 'bottom' => 'bottom', 'over' => 'over', 'none' => 'none', );
|
| 335 |
$options['displayclick'] = array('default' => 'default', 'play' => 'play', 'link' => 'link', 'fullscreen' => 'fullscreen', 'none' => 'none', 'mute' => 'mute', 'next' => 'next', );
|
| 336 |
|
| 337 |
$options['player'] = array('flowplayer/FlowPlayerClassic.swf' => 'Classic', 'flowplayer/FlowPlayerDark.swf' => 'Dark', 'flowplayer/FlowPlayerLight.swf' => 'Light', 'flowplayer/FlowPlayerLP.swf' => 'LP', );
|
| 338 |
$options['controlBarGloss'] = array('default' => 'default', 'high' => 'high', 'low' => 'low', 'none' => 'none', );
|
| 339 |
$options['bool'] = array('default' => 'default', 'true' => 'true', 'false' => 'false');
|
| 340 |
return $options;
|
| 341 |
}
|
| 342 |
|
| 343 |
|
| 344 |
/**
|
| 345 |
* Implementation of hook_help
|
| 346 |
*/
|
| 347 |
function flowplayer_help($path, $arg) {
|
| 348 |
switch ($path) {
|
| 349 |
case 'admin/settings/swftools/flowplayer':
|
| 350 |
return '<p>'.t('These are the settings for the FlowPlayer media player.
|
| 351 |
For details of what each parameter does refer to the
|
| 352 |
<a href="@flowplayer">FlowPlayer documentation</a>.
|
| 353 |
It is possible that you do not need to change any of
|
| 354 |
these settings and blank values will defer to friendly
|
| 355 |
defaults. Note that the label in (<em>brackets</em>)
|
| 356 |
is the configuration setting name and corresponds to the documentation page.
|
| 357 |
If content is embedded using the SWF Tools filter then each parameter
|
| 358 |
can be over-ridden by specifying a new value in the filter string.', array('@flowplayer' => 'http://flowplayer.org/player/configuration.html')).'</p>';
|
| 359 |
}
|
| 360 |
}
|