| 1 |
<?php
|
| 2 |
// $Id: wijering.module,v 1.9 2009/03/06 19:48:01 stuartgreenfield Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* SWF Tools - Jeroen Wijering's Flash Players
|
| 6 |
*
|
| 7 |
* Enables the use of Jeroen Wijering's Flash Media and Flash Image
|
| 8 |
* Rotator files.
|
| 9 |
*
|
| 10 |
* Author's Site.
|
| 11 |
* http://jeroenwijering.com
|
| 12 |
*/
|
| 13 |
|
| 14 |
define('WIJERING_MEDIAPLAYER', 'wijering_mediaplayer'); // 'player', can display mixed files
|
| 15 |
define('WIJERING_DOWNLOAD', 'http://code.jeroenwijering.com/trac/browser/tags');
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Implementation of hook_swftools_methods().
|
| 19 |
*/
|
| 20 |
function wijering_swftools_methods() {
|
| 21 |
|
| 22 |
$methods = array();
|
| 23 |
|
| 24 |
$media_player = array(
|
| 25 |
'name' => WIJERING_MEDIAPLAYER,
|
| 26 |
'module' => 'wijering',
|
| 27 |
'file' => 'file', // Define which flashvar to assign a 'file to play' variable.
|
| 28 |
'version' => '7',
|
| 29 |
'shared_file' => 'flash_media_player/mediaplayer.swf',
|
| 30 |
'title' => t('JW Media Player 3'),
|
| 31 |
'download' => WIJERING_DOWNLOAD,
|
| 32 |
'width' => '320',
|
| 33 |
'height' => '260',
|
| 34 |
);
|
| 35 |
|
| 36 |
// Wijering support various actions with the same player and info.
|
| 37 |
$methods[SWFTOOLS_FLV_DISPLAY][WIJERING_MEDIAPLAYER] = $media_player;
|
| 38 |
$methods[SWFTOOLS_FLV_DISPLAY_LIST][WIJERING_MEDIAPLAYER] = $media_player;
|
| 39 |
$methods[SWFTOOLS_MP3_DISPLAY][WIJERING_MEDIAPLAYER] = $media_player;
|
| 40 |
$methods[SWFTOOLS_MP3_DISPLAY_LIST][WIJERING_MEDIAPLAYER] = $media_player;
|
| 41 |
$methods[SWFTOOLS_MEDIA_DISPLAY][WIJERING_MEDIAPLAYER] = $media_player;
|
| 42 |
$methods[SWFTOOLS_MEDIA_DISPLAY_LIST][WIJERING_MEDIAPLAYER] = $media_player;
|
| 43 |
$methods[SWFTOOLS_IMAGE_DISPLAY_LIST][WIJERING_MEDIAPLAYER] = $media_player;
|
| 44 |
|
| 45 |
return $methods;
|
| 46 |
}
|
| 47 |
|
| 48 |
/**
|
| 49 |
* Implementation of hook_menu().
|
| 50 |
*/
|
| 51 |
function wijering_menu() {
|
| 52 |
|
| 53 |
$items = array();
|
| 54 |
|
| 55 |
//$items['admin/media/swf/wijering'] = array(
|
| 56 |
$items['admin/settings/swftools/wijering'] = array(
|
| 57 |
'title' => 'JW Media Player 3',
|
| 58 |
'description' => 'Settings for '. l('Jeroen Wijering\'s Media Player 3', WIJERING_DOWNLOAD) .'.',
|
| 59 |
'access arguments' => array('administer flash'),
|
| 60 |
'page callback' => 'drupal_get_form',
|
| 61 |
'page arguments' => array('wijering_admin_form'),
|
| 62 |
'file' => 'wijering.admin.inc',
|
| 63 |
'file path' => drupal_get_path('module', 'wijering'),
|
| 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 _wijering_settings($player) {
|
| 75 |
$opts = _wijering_options();
|
| 76 |
|
| 77 |
switch ($player) {
|
| 78 |
case WIJERING_MEDIAPLAYER:
|
| 79 |
// Define the settings list.
|
| 80 |
$defaults['boolean'] = array(
|
| 81 |
'largecontrols' => 'default',
|
| 82 |
'shuffle' => 'default',
|
| 83 |
'linkfromdisplay' => 'default',
|
| 84 |
'usecaptions' => 'default',
|
| 85 |
'usefullscreen' => 'default',
|
| 86 |
'usekeys' => 'default',
|
| 87 |
'autoscroll' => 'default',
|
| 88 |
'showdigits' => 'default',
|
| 89 |
'showeq' => 'default',
|
| 90 |
'showicons' => 'default',
|
| 91 |
'thumbsinplaylist' => 'default',
|
| 92 |
'autostart' => 'default',
|
| 93 |
'enablejs' => 'default',
|
| 94 |
);
|
| 95 |
$defaults['color'] = array(
|
| 96 |
'backcolor' => '',
|
| 97 |
'frontcolor' => '',
|
| 98 |
'lightcolor' => '',
|
| 99 |
);
|
| 100 |
$defaults['url'] = array(
|
| 101 |
'logo' => '',
|
| 102 |
'callback' => '',
|
| 103 |
'captions' => '',
|
| 104 |
'fsbuttonlink' => '',
|
| 105 |
'link' => '',
|
| 106 |
'streamscript' => '',
|
| 107 |
);
|
| 108 |
$defaults['integer'] = array(
|
| 109 |
'width' => '400',
|
| 110 |
'height' => '320',
|
| 111 |
'displayheight' => '',
|
| 112 |
'displaywidth' => '', // default is blank, otherwise overrides 'displayheight'
|
| 113 |
'bufferlength' => '',
|
| 114 |
'rotatetime' => '',
|
| 115 |
'volume' => '',
|
| 116 |
);
|
| 117 |
$defaults['other'] = array(
|
| 118 |
'type' => '', // Defaults to the filename extension.
|
| 119 |
'repeat' => 'default', // This false is part of {true,false,list}
|
| 120 |
'linktarget' => 'default',
|
| 121 |
'overstretch' => 'default',
|
| 122 |
);
|
| 123 |
$saved_settings = variable_get('swftools_'. WIJERING_MEDIAPLAYER, array());
|
| 124 |
break;
|
| 125 |
}
|
| 126 |
|
| 127 |
// Overwrite initialised variables with those that might be already saved.
|
| 128 |
foreach ($defaults AS $category => $vars) {
|
| 129 |
foreach ($vars AS $key => $setting) {
|
| 130 |
if (isset($saved_settings[$key])) {
|
| 131 |
$defaults[$category][$key] = $saved_settings[$key];
|
| 132 |
}
|
| 133 |
}
|
| 134 |
}
|
| 135 |
|
| 136 |
return $defaults;
|
| 137 |
}
|
| 138 |
|
| 139 |
/**
|
| 140 |
* Implementation of swftools_flashvars hook.
|
| 141 |
* Return an array of flashvars.
|
| 142 |
*/
|
| 143 |
function wijering_swftools_flashvars($action, &$methods, &$vars) {
|
| 144 |
|
| 145 |
// Pad out the user parameters (like those passed through swf(), with our
|
| 146 |
// configured defaults, allowing the user parameters to dominate.
|
| 147 |
$saved_settings = _wijering_flashvars($methods->player['name']);
|
| 148 |
|
| 149 |
$saved = array();
|
| 150 |
foreach ($saved_settings AS $category => $settings) {
|
| 151 |
$saved = array_merge($saved, $settings);
|
| 152 |
}
|
| 153 |
$flashvars = array_merge($saved, $vars->flashvars);
|
| 154 |
if (isset($flashvars['image']) && !valid_url($flashvars['image'], TRUE)) {
|
| 155 |
$flashvars['image'] = swftools_get_media_url(swftools_get_media_path() . $flashvars['image']);
|
| 156 |
}
|
| 157 |
|
| 158 |
if ($vars->params['width']) {$flashvars['width'] = $vars->params['width'];}
|
| 159 |
if ($vars->params['height']) {$flashvars['height'] = $vars->params['height'];}
|
| 160 |
|
| 161 |
// Return an array of flash variables
|
| 162 |
return $flashvars;
|
| 163 |
}
|
| 164 |
|
| 165 |
/**
|
| 166 |
* This function is called from wijering_swftools_flashvars() which is called from swf()
|
| 167 |
* It will return the default flashvar configuration, just prior to any overrides
|
| 168 |
* passed into swf(). We start with the settings defined on admin/swf/wijering
|
| 169 |
* which are returned by _wijering_settings(). Then we prepare these values for output
|
| 170 |
* to html (eg. '1' become 'true') and we unset undefined flashvars to prevent their output.
|
| 171 |
*
|
| 172 |
*/
|
| 173 |
function _wijering_flashvars($this_player) {
|
| 174 |
// Cache this.
|
| 175 |
static $flashvars = array();
|
| 176 |
if (!count($flashvars)) {
|
| 177 |
|
| 178 |
// Media Player
|
| 179 |
foreach (array(WIJERING_MEDIAPLAYER) AS $player) {
|
| 180 |
|
| 181 |
// Get saved settings for this method.
|
| 182 |
$defaults = _wijering_settings($player);
|
| 183 |
foreach ($defaults AS $category => $vars) {
|
| 184 |
foreach ($vars AS $key => $setting) {
|
| 185 |
if (!$setting || $setting == 'default') {
|
| 186 |
unset($defaults[$category][$key]);
|
| 187 |
}
|
| 188 |
else {
|
| 189 |
switch ($category) {
|
| 190 |
case 'color':
|
| 191 |
$defaults['color'][$key] = str_replace('#', '0x', $defaults['color'][$key]);
|
| 192 |
break;
|
| 193 |
case 'boolean':
|
| 194 |
$defaults['boolean'][$key] = _swftools_tf($defaults['boolean'][$key]);
|
| 195 |
break;
|
| 196 |
}
|
| 197 |
}
|
| 198 |
}
|
| 199 |
}
|
| 200 |
|
| 201 |
// Not the same as width/height. This determines the extended width OR height
|
| 202 |
// past the main view area where the actual playlist file names can be found.
|
| 203 |
// Setting both together is not supported.
|
| 204 |
if ($defaults['integer']['displaywidth']) {
|
| 205 |
unset($defaults['integer']['displayheight']);
|
| 206 |
}
|
| 207 |
else {
|
| 208 |
unset($defaults['integer']['displaywidth']);
|
| 209 |
}
|
| 210 |
|
| 211 |
$flashvars[$player] = $defaults;
|
| 212 |
}
|
| 213 |
}
|
| 214 |
|
| 215 |
return $flashvars[$this_player];
|
| 216 |
}
|
| 217 |
|
| 218 |
/**
|
| 219 |
* flashvar and param option arrays. These are used for options settings in the
|
| 220 |
* configuration screen.
|
| 221 |
*
|
| 222 |
*/
|
| 223 |
function _wijering_options() {
|
| 224 |
$options['overstretch'] = array('default' => 'default', 'false' => 'false', 'true' => 'true', 'fit' => 'fit', 'none' => 'none', );
|
| 225 |
$options['repeat'] = array('default' => 'default', 'false' => 'false', 'true' => 'true', 'list' => 'list', );
|
| 226 |
$options['linktarget'] = array('default' => 'default', '_self' => '_self', '_blank' => '_blank', );
|
| 227 |
$options['transition'] = array('default' => 'default', 'fade' => 'fade', 'bgfade' => 'bgfade', 'blocks' => 'blocks', 'circles' => 'circles', 'fluids' => 'fluids', 'lines' => 'lines', 'random' => 'random', );
|
| 228 |
$options['bool'] = array('default' => 'default', 'true' => 'true', 'false' => 'false');
|
| 229 |
return $options;
|
| 230 |
}
|
| 231 |
|
| 232 |
function wijering_wijering_mediaplayer_swftools_playlist($xml_data, &$method, &$vars) {
|
| 233 |
|
| 234 |
$xml = '<playlist version="1" xmlns="http://xspf.org/ns/0/">
|
| 235 |
<title>'. $xml_data['header']['title'] .'</title>
|
| 236 |
<info></info>
|
| 237 |
<annotation></annotation>
|
| 238 |
<trackList>
|
| 239 |
';
|
| 240 |
foreach ($xml_data['playlist'] AS $track => $details) {
|
| 241 |
|
| 242 |
if (!isset($details['background']) && strtolower(substr($details['fileurl'], -3, 3)) == 'mp3') {
|
| 243 |
if (isset($vars->flashvars['image'])) {
|
| 244 |
$details['background'] = swftools_get_media_url(swftools_get_media_path() . $vars->flashvars['image']);
|
| 245 |
} else {
|
| 246 |
$details['background'] = SWFTOOLS_DEFAULT_BG;
|
| 247 |
}
|
| 248 |
}
|
| 249 |
$xml .= "<track>\n";
|
| 250 |
$xml .= "<title>". $details['title'] ."</title>\n";
|
| 251 |
$xml .= "<creator></creator>\n";
|
| 252 |
$xml .= "<location>". $details['fileurl'] ."</location>\n";
|
| 253 |
$xml .= "<image>". $details['background'] ."</image>\n";
|
| 254 |
$xml .= "<info>". $details['fileurl'] ."</info>\n";
|
| 255 |
$xml .= "</track>\n";
|
| 256 |
}
|
| 257 |
$xml .= '</trackList>
|
| 258 |
</playlist>';
|
| 259 |
return $xml;
|
| 260 |
}
|
| 261 |
|
| 262 |
|
| 263 |
/*
|
| 264 |
* Implementation of hook_swftools_variable_mapping.
|
| 265 |
*
|
| 266 |
*/
|
| 267 |
function wijering_swftools_variable_mapping() {
|
| 268 |
return array(
|
| 269 |
WIJERING_MEDIAPLAYER => array(
|
| 270 |
'autostart' => 'flashvars',
|
| 271 |
'repeat' => 'flashvars',
|
| 272 |
'rotatetime' => 'flashvars',
|
| 273 |
'backcolor' => 'flashvars',
|
| 274 |
'frontcolor' => 'flashvars',
|
| 275 |
'lightcolor' => 'flashvars',
|
| 276 |
'displaywidth' => 'flashvars',
|
| 277 |
'displayheight' => 'flashvars',
|
| 278 |
'image' => 'flashvars',
|
| 279 |
),
|
| 280 |
);
|
| 281 |
}
|
| 282 |
|
| 283 |
|
| 284 |
/**
|
| 285 |
* Implementation of hook_help
|
| 286 |
*/
|
| 287 |
function wijering_help($path, $arg) {
|
| 288 |
switch ($path) {
|
| 289 |
case 'admin/settings/swftools/wijering':
|
| 290 |
return '<p>'.t('These are the settings for Jeroen Wijering\'s mediaplayer.swf
|
| 291 |
and correspond (by category and order) to the
|
| 292 |
<a href="@wijering">Media Player and Image Rotator read me</a>.
|
| 293 |
It is possible that you do not need to change any of
|
| 294 |
these settings and blank values will defer to friendly
|
| 295 |
defaults. Note that the label in (<em>brackets</em>)
|
| 296 |
is the actual flashvar name and corresponds to the read me.', array('@wijering' => 'http://jeroenwijering.com/extras/readme.html')).'</p>';
|
| 297 |
}
|
| 298 |
}
|