| 1 |
<?php
|
| 2 |
// $Id: wijering4.module,v 1.9 2009/03/06 19:47:59 stuartgreenfield Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* SWF Tools - Jeroen Wijering's Media Player version 4
|
| 6 |
*
|
| 7 |
* Enables the use of Jeroen Wijering's FLV Media Player version 4
|
| 8 |
*
|
| 9 |
* Author's Site.
|
| 10 |
* http://jeroenwijering.com
|
| 11 |
*/
|
| 12 |
|
| 13 |
define('WIJERING4_MEDIAPLAYER', 'wijering4_mediaplayer'); // 'player', can display mixed files
|
| 14 |
define('WIJERING4_IMAGEROTATOR', 'wijering4_imagerotator'); // 'player', can display images.
|
| 15 |
define('WIJERING4_DOWNLOAD', 'http://www.jeroenwijering.com/?item=JW_FLV_Media_Player');
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Implementation of hook_swftools_methods().
|
| 19 |
*/
|
| 20 |
function wijering4_swftools_methods() {
|
| 21 |
|
| 22 |
$methods = array();
|
| 23 |
|
| 24 |
$media_player = array(
|
| 25 |
'name' => WIJERING4_MEDIAPLAYER,
|
| 26 |
'module' => 'wijering4',
|
| 27 |
'file' => 'file', // Define which flashvar to assign a 'file to play' variable.
|
| 28 |
'version' => '7',
|
| 29 |
'shared_file' => 'flash_media_player/player.swf',
|
| 30 |
'title' => t('JW Media Player 4'),
|
| 31 |
'download' => WIJERING4_DOWNLOAD,
|
| 32 |
'width' => '400',
|
| 33 |
'height' => '300',
|
| 34 |
);
|
| 35 |
|
| 36 |
// Wijering support various actions with the same player and info.
|
| 37 |
$methods[SWFTOOLS_FLV_DISPLAY][WIJERING4_MEDIAPLAYER] = $media_player;
|
| 38 |
$methods[SWFTOOLS_FLV_DISPLAY_LIST][WIJERING4_MEDIAPLAYER] = $media_player;
|
| 39 |
$methods[SWFTOOLS_MP3_DISPLAY][WIJERING4_MEDIAPLAYER] = $media_player;
|
| 40 |
$methods[SWFTOOLS_MP3_DISPLAY_LIST][WIJERING4_MEDIAPLAYER] = $media_player;
|
| 41 |
$methods[SWFTOOLS_MEDIA_DISPLAY][WIJERING4_MEDIAPLAYER] = $media_player;
|
| 42 |
$methods[SWFTOOLS_MEDIA_DISPLAY_LIST][WIJERING4_MEDIAPLAYER] = $media_player;
|
| 43 |
$methods[SWFTOOLS_IMAGE_DISPLAY_LIST][WIJERING4_MEDIAPLAYER] = $media_player;
|
| 44 |
|
| 45 |
return $methods;
|
| 46 |
}
|
| 47 |
|
| 48 |
/**
|
| 49 |
* Implementation of hook_menu().
|
| 50 |
*/
|
| 51 |
function wijering4_menu() {
|
| 52 |
|
| 53 |
$items = array();
|
| 54 |
|
| 55 |
//$items['admin/media/swf/wijering4'] = array(
|
| 56 |
$items['admin/settings/swftools/wijering4'] = array(
|
| 57 |
'title' => 'JW Media Player 4',
|
| 58 |
'description' => 'Settings for '. l('Jeroen Wijering\'s FLV Media Player 4', WIJERING4_DOWNLOAD) .'.',
|
| 59 |
'access arguments' => array('administer flash'),
|
| 60 |
'page callback' => 'drupal_get_form',
|
| 61 |
'page arguments' => array('wijering4_admin_form'),
|
| 62 |
'file' => 'wijering4.admin.inc',
|
| 63 |
'file path' => drupal_get_path('module', 'wijering4'),
|
| 64 |
);
|
| 65 |
|
| 66 |
return $items;
|
| 67 |
}
|
| 68 |
|
| 69 |
|
| 70 |
/**
|
| 71 |
* These are the default settings as they are stored in the database and displayed
|
| 72 |
* on the settings page.
|
| 73 |
*/
|
| 74 |
function _wijering4_settings($player) {
|
| 75 |
|
| 76 |
switch ($player) {
|
| 77 |
case WIJERING4_MEDIAPLAYER:
|
| 78 |
// Define the settings list.
|
| 79 |
$defaults['boolean'] = array(
|
| 80 |
'shuffle' => 'default',
|
| 81 |
'fullscreen' => 'default',
|
| 82 |
'autostart' => 'default',
|
| 83 |
'quality' => 'default',
|
| 84 |
);
|
| 85 |
$defaults['color'] = array(
|
| 86 |
'backcolor' => '',
|
| 87 |
'frontcolor' => '',
|
| 88 |
'lightcolor' => '',
|
| 89 |
'screencolor' => '',
|
| 90 |
);
|
| 91 |
$defaults['url'] = array(
|
| 92 |
'logo' => '',
|
| 93 |
'captions' => '',
|
| 94 |
'link' => '',
|
| 95 |
'streamscript' => '',
|
| 96 |
'skin' => '',
|
| 97 |
);
|
| 98 |
$defaults['integer'] = array(
|
| 99 |
'width' => '400',
|
| 100 |
'height' => '320',
|
| 101 |
'playlistsize' => '',
|
| 102 |
'bufferlength' => '',
|
| 103 |
'volume' => '',
|
| 104 |
);
|
| 105 |
$defaults['other'] = array(
|
| 106 |
'type' => 'default',
|
| 107 |
'repeat' => 'default',
|
| 108 |
'linktarget' => 'default',
|
| 109 |
'stretching' => 'default',
|
| 110 |
'playlist' => 'default',
|
| 111 |
'controlbar' => 'default',
|
| 112 |
'displayclick' => 'default',
|
| 113 |
);
|
| 114 |
$saved_settings = variable_get('swftools_'. WIJERING4_MEDIAPLAYER, array());
|
| 115 |
break;
|
| 116 |
|
| 117 |
}
|
| 118 |
|
| 119 |
// Overwrite initialised variables with those that might be already saved.
|
| 120 |
foreach ($defaults AS $category => $vars) {
|
| 121 |
foreach ($vars AS $key => $setting) {
|
| 122 |
if (isset($saved_settings[$key])) {
|
| 123 |
$defaults[$category][$key] = $saved_settings[$key];
|
| 124 |
}
|
| 125 |
}
|
| 126 |
}
|
| 127 |
|
| 128 |
return $defaults;
|
| 129 |
}
|
| 130 |
|
| 131 |
/**
|
| 132 |
* Implementation of hook_swftools_flashvars().
|
| 133 |
* Return an array of flashvars.
|
| 134 |
*/
|
| 135 |
function wijering4_swftools_flashvars($action, &$methods, &$vars) {
|
| 136 |
|
| 137 |
// Pad out the user parameters (like those passed through swf(), with our
|
| 138 |
// configured defaults, allowing the user parameters to dominate.
|
| 139 |
$saved_settings = _wijering4_flashvars($methods->player['name']);
|
| 140 |
|
| 141 |
$saved = array();
|
| 142 |
foreach ($saved_settings AS $category => $settings) {
|
| 143 |
$saved = array_merge($saved, $settings);
|
| 144 |
}
|
| 145 |
$flashvars = array_merge($saved, $vars->flashvars);
|
| 146 |
|
| 147 |
if (isset($flashvars['image']) && !valid_url($flashvars['image'], TRUE)) {
|
| 148 |
$flashvars['image'] = swftools_get_media_url(swftools_get_media_path() . $flashvars['image']);
|
| 149 |
}
|
| 150 |
|
| 151 |
if ($vars->params['width']) {$flashvars['width'] = $vars->params['width'];}
|
| 152 |
if ($vars->params['height']) {$flashvars['height'] = $vars->params['height'];}
|
| 153 |
|
| 154 |
// Is this file to be streamed? Check for the stream variable being set
|
| 155 |
if (isset($vars->othervars['stream'])) {
|
| 156 |
|
| 157 |
// Extract path info from the $file_url variable describing the file
|
| 158 |
$info = pathinfo($vars->othervars['file_url']);
|
| 159 |
|
| 160 |
// Set the streamer flashvar
|
| 161 |
$vars->flashvars['streamer'] = $vars->othervars['stream'];
|
| 162 |
|
| 163 |
// Replace the current (non streamed) file url with the stream filename
|
| 164 |
$vars->othervars['file_url'] = $info['basename'];
|
| 165 |
|
| 166 |
}
|
| 167 |
|
| 168 |
// Return an array of flash variables
|
| 169 |
return $flashvars;
|
| 170 |
}
|
| 171 |
|
| 172 |
/**
|
| 173 |
* This function is called from wijering4_swftools_flashvars() which is called from swf()
|
| 174 |
* It will return the default flashvar configuration, just prior to any overrides
|
| 175 |
* passed into swf(). We start with the settings defined on admin/swf/wijering
|
| 176 |
* which are returned by _wijering4_settings(). Then we prepare these values for output
|
| 177 |
* to html (eg. '1' become 'true') and we unset undefined flashvars to prevent their output.
|
| 178 |
*
|
| 179 |
*/
|
| 180 |
function _wijering4_flashvars($this_player) {
|
| 181 |
// Cache this.
|
| 182 |
static $flashvars = array();
|
| 183 |
if (!count($flashvars)) {
|
| 184 |
|
| 185 |
// Media Player
|
| 186 |
foreach (array(WIJERING4_MEDIAPLAYER) AS $player) {
|
| 187 |
|
| 188 |
// Get saved settings for this method.
|
| 189 |
$defaults = _wijering4_settings($player);
|
| 190 |
foreach ($defaults AS $category => $vars) {
|
| 191 |
foreach ($vars AS $key => $setting) {
|
| 192 |
if (!$setting || $setting == 'default') {
|
| 193 |
unset($defaults[$category][$key]);
|
| 194 |
}
|
| 195 |
else {
|
| 196 |
switch ($category) {
|
| 197 |
case 'color':
|
| 198 |
$defaults['color'][$key] = str_replace('#', '0x', $defaults['color'][$key]);
|
| 199 |
break;
|
| 200 |
case 'boolean':
|
| 201 |
$defaults['boolean'][$key] = _swftools_tf($defaults['boolean'][$key]);
|
| 202 |
break;
|
| 203 |
}
|
| 204 |
}
|
| 205 |
}
|
| 206 |
}
|
| 207 |
|
| 208 |
// Not the same as width/height. This determines the extended width OR height
|
| 209 |
// past the main view area where the actual playlist file names can be found.
|
| 210 |
// Setting both together is not supported.
|
| 211 |
if ($defaults['integer']['displaywidth']) {
|
| 212 |
unset($defaults['integer']['displayheight']);
|
| 213 |
}
|
| 214 |
else {
|
| 215 |
unset($defaults['integer']['displaywidth']);
|
| 216 |
}
|
| 217 |
|
| 218 |
$flashvars[$player] = $defaults;
|
| 219 |
}
|
| 220 |
}
|
| 221 |
|
| 222 |
return $flashvars[$this_player];
|
| 223 |
}
|
| 224 |
|
| 225 |
/**
|
| 226 |
* flashvar and param option arrays. These are used for options settings in the
|
| 227 |
* configuration screen.
|
| 228 |
*
|
| 229 |
*/
|
| 230 |
function _wijering4_options() {
|
| 231 |
$options['type'] = array('default' => 'default', 'sound' => 'sound', 'image' => 'image', 'video' => 'video', 'youtube' => 'youtube', 'camera' => 'camera', 'http' => 'http', 'rtmp' => 'rtmp', );
|
| 232 |
$options['overstretch'] = array('default' => 'default', 'uniform' => 'uniform', 'fill' => 'fill', 'exactfit' => 'exactfit', 'none' => 'none', );
|
| 233 |
$options['repeat'] = array('default' => 'default', 'none' => 'none', 'list' => 'list', 'always' => 'always', );
|
| 234 |
$options['linktarget'] = array('default' => 'default', '_self' => '_self', '_blank' => '_blank', 'none' => 'none', );
|
| 235 |
$options['playlist'] = array('default' => 'default', 'bottom' => 'bottom', 'over' => 'over', 'right' => 'right', 'none' => 'none', );
|
| 236 |
$options['controlbar'] = array('default' => 'default', 'bottom' => 'bottom', 'over' => 'over', 'none' => 'none', );
|
| 237 |
$options['displayclick'] = array('default' => 'default', 'play' => 'play', 'link' => 'link', 'fullscreen' => 'fullscreen', 'none' => 'none', 'mute' => 'mute', 'next' => 'next', );
|
| 238 |
$options['bool'] = array('default' => 'default', 'true' => 'true', 'false' => 'false');
|
| 239 |
return $options;
|
| 240 |
}
|
| 241 |
|
| 242 |
function wijering4_wijering4_mediaplayer_swftools_playlist($xml_data, &$method, &$vars) {
|
| 243 |
|
| 244 |
$xml = '<playlist version="1" xmlns="http://xspf.org/ns/0/">
|
| 245 |
<title>'. $xml_data['header']['title'] .'</title>
|
| 246 |
<info></info>
|
| 247 |
<annotation></annotation>
|
| 248 |
<trackList>
|
| 249 |
';
|
| 250 |
foreach ($xml_data['playlist'] AS $track => $details) {
|
| 251 |
|
| 252 |
if (!isset($details['background']) && strtolower(substr($details['fileurl'], -3, 3)) == 'mp3') {
|
| 253 |
if (isset($vars->flashvars['image'])) {
|
| 254 |
$details['background'] = swftools_get_media_url(swftools_get_media_path() . $vars->flashvars['image']);
|
| 255 |
} else {
|
| 256 |
$details['background'] = SWFTOOLS_DEFAULT_BG;
|
| 257 |
}
|
| 258 |
}
|
| 259 |
$xml .= "<track>\n";
|
| 260 |
$xml .= "<title>". $details['title'] ."</title>\n";
|
| 261 |
$xml .= "<creator></creator>\n";
|
| 262 |
$xml .= "<location>". $details['fileurl'] ."</location>\n";
|
| 263 |
$xml .= "<image>". $details['background'] ."</image>\n";
|
| 264 |
$xml .= "<info>". $details['fileurl'] ."</info>\n";
|
| 265 |
$xml .= "</track>\n";
|
| 266 |
}
|
| 267 |
$xml .= '</trackList>
|
| 268 |
</playlist>';
|
| 269 |
return $xml;
|
| 270 |
}
|
| 271 |
|
| 272 |
|
| 273 |
/*
|
| 274 |
* Implementation of hook_swftools_variable_mapping.
|
| 275 |
*
|
| 276 |
*/
|
| 277 |
function wijering4_swftools_variable_mapping() {
|
| 278 |
return array(
|
| 279 |
WIJERING4_MEDIAPLAYER => array(
|
| 280 |
'shuffle' => 'flashvars',
|
| 281 |
'fullscreen' => 'flashvars',
|
| 282 |
'autostart' => 'flashvars',
|
| 283 |
'quality' => 'flashvars',
|
| 284 |
'backcolor' => 'flashvars',
|
| 285 |
'frontcolor' => 'flashvars',
|
| 286 |
'lightcolor' => 'flashvars',
|
| 287 |
'screencolor' => 'flashvars',
|
| 288 |
'logo' => 'flashvars',
|
| 289 |
'captions' => 'flashvars',
|
| 290 |
'link' => 'flashvars',
|
| 291 |
'streamscript' => 'flashvars',
|
| 292 |
'skin' => 'flashvars',
|
| 293 |
'playlistsize' => 'flashvars',
|
| 294 |
'bufferlength' => 'flashvars',
|
| 295 |
'volume' => 'flashvars',
|
| 296 |
'type' => 'flashvars',
|
| 297 |
'repeat' => 'flashvars',
|
| 298 |
'linktarget' => 'flashvars',
|
| 299 |
'stretching' => 'flashvars',
|
| 300 |
'playlist' => 'flashvars',
|
| 301 |
'controlbar' => 'flashvars',
|
| 302 |
'displayclick' => 'flashvars',
|
| 303 |
),
|
| 304 |
);
|
| 305 |
}
|
| 306 |
|
| 307 |
|
| 308 |
/**
|
| 309 |
* Implementation of hook_help
|
| 310 |
*/
|
| 311 |
function wijering4_help($path, $arg) {
|
| 312 |
switch ($path) {
|
| 313 |
case 'admin/settings/swftools/wijering4':
|
| 314 |
return '<p>'.t('These are the settings for Jeroen Wijering\'s FLV Media Player 4.
|
| 315 |
For details of what each parameter does refer to the
|
| 316 |
<a href="@wijering">JW Player for Flash wiki page</a>.
|
| 317 |
It is possible that you do not need to change any of
|
| 318 |
these settings and blank values will defer to friendly
|
| 319 |
defaults. Note that the label in (<em>brackets</em>)
|
| 320 |
is the actual flashvar name and corresponds to the wiki page.
|
| 321 |
If content is embedded using the SWF Tools filter then each parameter
|
| 322 |
can be over-ridden by specifying a new value in the filter string.', array('@wijering' => 'http://code.jeroenwijering.com/trac/wiki/FlashVars')).'</p>';
|
| 323 |
}
|
| 324 |
}
|