/[drupal]/contributions/modules/swftools/flowplayer3/flowplayer3.module
ViewVC logotype

Contents of /contributions/modules/swftools/flowplayer3/flowplayer3.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.30 - (show annotations) (download) (as text)
Wed Mar 18 00:21:58 2009 UTC (8 months, 1 week ago) by stuartgreenfield
Branch: MAIN
CVS Tags: HEAD
Changes since 1.29: +2 -1 lines
File MIME type: text/x-php
#405498 by fearfox: Background gradient setting for controlbar missing.
1 <?php
2 // $Id: flowplayer3.module,v 1.29 2009/03/17 23:18:10 stuartgreenfield Exp $
3
4 /**
5 * SWF Tools - FlowPlayer 3
6 *
7 * Enables the use of FlowPlayer 3 for media files.
8 * http://flowplayer.org
9 */
10
11 /**
12 * Define constants that can be used to reference aspects relating to FlowPlayer3
13 */
14 define('FLOWPLAYER3_MEDIAPLAYER', 'flowplayer3_mediaplayer');
15 define('FLOWPLAYER3_MEDIAPLAYER_FILE', 'flowplayer-3.0.7.swf');
16 define('FLOWPLAYER3_MEDIAPLAYER_STREAM_PLUGIN', 'flowplayer.rtmp-3.0.2.swf');
17 define('FLOWPLAYER3_DOWNLOAD', 'http://flowplayer.org/');
18
19 /**
20 * Implementation of hook_swftools_methods().
21 */
22 function flowplayer3_swftools_methods() {
23
24 // Initialise an array to hold the results
25 $methods = array();
26
27 /**
28 * Define the FlowPlayer3 media player
29 * name internal name used to refer to this player
30 * module name of the module that provides this player
31 * file name of flash variable to assign the name of the file to be played
32 * version minimum version of flash needed to use this player
33 * shared_file path to the shared file (relative to swftools/shared/
34 * title human readable name of this player
35 * download download path to the player (used to help users obtain the player)
36 */
37 $media_player = array(
38 'name' => FLOWPLAYER3_MEDIAPLAYER,
39 'module' => 'flowplayer3',
40 'file' => '', // Return nothing - do not make a file assignment
41 'version' => '9',
42 'shared_file' => 'flowplayer3/' . variable_get('flowplayer3_mediaplayer_file', FLOWPLAYER3_MEDIAPLAYER_FILE),
43 'title' => t('FlowPlayer 3'),
44 'download' => FLOWPLAYER3_DOWNLOAD,
45 'width' => '500',
46 'height' => '375',
47 );
48
49
50 /**
51 * Define actions that the player can support by returning an array with keys
52 * [action][name_of_player][player_details]
53 */
54 $methods[SWFTOOLS_FLV_DISPLAY][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
55 $methods[SWFTOOLS_FLV_DISPLAY_LIST][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
56 $methods[SWFTOOLS_MP3_DISPLAY][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
57 $methods[SWFTOOLS_MP3_DISPLAY_LIST][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
58 $methods[SWFTOOLS_MEDIA_DISPLAY][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
59 $methods[SWFTOOLS_MEDIA_DISPLAY_LIST][FLOWPLAYER3_MEDIAPLAYER] = $media_player;
60
61 // Return the method results
62 return $methods;
63 }
64
65 /**
66 * Implementation of hook_menu().
67 */
68 function flowplayer3_menu() {
69
70 $items = array();
71
72 $items['admin/settings/swftools/flowplayer3'] = array(
73 'title' => 'FlowPlayer 3',
74 'description' => 'Settings for ' . l('FlowPlayer 3', FLOWPLAYER3_DOWNLOAD) . '.',
75 'access arguments' => array('administer flash'),
76 'page callback' => 'drupal_get_form',
77 'page arguments' => array('flowplayer3_admin_settings'),
78 'file' => 'flowplayer3.admin.inc',
79 'file path' => drupal_get_path('module', 'flowplayer3'),
80 );
81
82 return $items;
83 }
84
85
86 /**
87 * Implementation of swftools_flashvars hook().
88 * Note that $methods and $vars are passed by reference, so the player module
89 * can manipulate them directly if necessary.
90
91 * @param $action
92 * String defining the action that is to be performed, eg SWFTOOLS_FLV_DISPLAY
93 * @param &$methods
94 * Object containing two keys - player and method. Each consists of an array
95 * that defines the details of the resolved player and embedding method that
96 * is being used for this file.
97 * @param &$vars
98 * Object containing three keys - othervars, flashvars and params. These are
99 * arrays containing key/value pairs that contain all the data assigned to this
100 * file so far. Refer to swf() for more details about the $vars array.
101 * @return
102 * Return an array of flashvars needed to allow the player to work.
103 */
104 function flowplayer3_swftools_flashvars($action, &$methods, &$vars) {
105
106 // Initialise array of FlowPlayer3 configuration settings
107 $flowplayer = array();
108
109 // Initialise array to hold data
110 $playlist = array();
111
112 // Initialise flag to show it this content is being streamed
113 $stream = FALSE;
114
115 // Is this file to be streamed? Check for the stream variable being set
116 if (isset($vars->othervars['stream'])) {
117
118 // Set stream flag to true
119 $stream = TRUE;
120
121 }
122
123 // If an image was supplied to be the splash then put this first in the list
124 // This code doesn't seem to be working - the player objects to { url: '' }
125 if (isset($vars->othervars['image'])) {
126 $playlist[] = array(
127 // Get url, checking for file existence, and using a relative url if possible.
128 'url' => swftools_create_url($vars->othervars['image'], TRUE, FALSE),
129 'autoPlay' => 'true',
130 );
131 }
132
133 // If the passed variables includes 'playlist_data' we have a playlist
134 if (isset($vars->othervars['playlist_data'])) {
135
136 // Get file paths out of the playlist_data array and add to FlowPlayer playlist
137 foreach ($vars->othervars['playlist_data']['playlist'] as $play) {
138
139 // If this is a streamed playlist, use filename, if regular, use fileurl
140 if ($stream) {
141 //$playlist[]['url'] = $play['filename'];
142 $playlist[]['url'] = $play['filename'];
143 }
144 else {
145 //$playlist[] = "'" . $play['fileurl'] . "'";
146 $playlist[]['url'] = $play['fileurl'];
147 }
148 }
149 }
150
151 else {
152 // Not a playlist, so populate FlowPlayer3 playlist with the file_url
153 //$playlist[] = "'" . $vars->othervars['file_url'] . "'";
154 $playlist[]['url'] = $vars->othervars['file_url'];
155 }
156
157 // Implode the array to create a string ready for later
158 //$flowplayer['playlist'] = '[ ' . implode(', ', $playlist) . ' ]';
159 $flowplayer['playlist'] = $playlist;
160
161 // Retrieve the current FlowPlayer3 settings
162 $saved_settings = _flowplayer3_settings();
163
164 // Scan through each setting to see if it is over-ridden in $vars->othervars
165 // Unset properties that are blank to keep the resulting code 'tidy'
166 foreach ($saved_settings as $category => $data) {
167 foreach ($data as $property => $value) {
168 if (isset($vars->othervars[$property])) {
169 $saved_settings[$category][$property] = $vars->othervars[$property];
170 }
171 if (!$saved_settings[$category][$property]) {
172 unset($saved_settings[$category][$property]);
173 }
174 }
175 }
176
177 // Add the properties to the flowplayer array ready for rendering
178 $flowplayer['canvas'] = $saved_settings['canvas'];
179 $flowplayer['clip'] = $saved_settings['clip'];
180 $flowplayer['plugins']['controls'] = $saved_settings['controls'];
181
182 // If we are streaming this file, add the stream plugin
183 if (isset($vars->othervars['stream'])) {
184
185 // Define the clip provider as 'stream'
186 $flowplayer['clip']['provider'] = 'stream';
187
188 // Get the name of the stream plugin
189 $flowplayer['plugins']['stream']['url'] = variable_get('flowplayer3_mediaplayer_stream_plugin', FLOWPLAYER3_MEDIAPLAYER_STREAM_PLUGIN);
190
191 // Set the path to the source of the stream
192 $flowplayer['plugins']['stream']['netConnectionUrl'] = $vars->othervars['stream'];
193
194 }
195
196 // Add product key if it has been set
197 if (variable_get('flowplayer3_product_key', '')) {
198 $flowplayer['key'] = variable_get('flowplayer3_product_key', '');
199 }
200
201 // Convert $flowplayer array to an object so we can pass it by reference in module_invoke_all()
202 $flowplayer = (object)$flowplayer;
203
204 // Call any FlowPlayer3 extensions that implement hook_flowplayer3()
205 module_invoke_all('flowplayer3', $action, $methods, $vars, $flowplayer);
206
207 // Convert $flowplayer object back to array
208 $flowplayer = (array)$flowplayer;
209
210 // Attach this array to othervars in case a handler wants it (e.g. flowplayer3_embed)
211 $vars->othervars['flowplayer'] = $flowplayer;
212
213
214
215 // Convert flowplayer array to JSON, and assign to a flashvar called config
216 $flashvars['config'] = drupal_to_js($flowplayer);
217
218 // Replace " with ', and remove quotes from around true and false, to satisfy FlowPlayer
219 $flashvars['config'] = str_replace(array('"', "'false'", "'true'", "'[", "]'"), array("'", "false", "true", "[", "]"), $flashvars['config']);
220
221 // The ' has been escaped, so reverse it where it occurs in the playlist (it gets escaped again later!)
222 //$flashvars['config'] = str_replace(array("\'"), array("'"), $flashvars['config']);
223
224 // Return the finished array of flash variables
225 return $flashvars;
226 }
227
228
229 /**
230 * Implementation of hook_{player}_swftools_playlist().
231 * This function builds the content needed to write to an xml playlist. In the
232 * case of FlowPlayer3 it is not actually necessary to produce an xml playlist,
233 * but we must support this hook as SWF Tools uses its presence to detect that
234 * the player is capable of supporting playlists.
235 * DO WE NEED TO DO THIS? IF THE PLAYER DOESN'T SUPPORT LIST ACTIONS THEN WE ALREADY KNOW THIS?
236 *
237 * @param $xml_data
238 * Array of data that can be used to build the xml playlist. Contains keys
239 * [header][title] Title data that can be used for the playlist
240 * [playlist][key][filepath] The filepath to the file
241 * [playlist][key][filename] The filename of the file
242 * [playlist][key][fileurl] The url of the file
243 * [playlist][key][title] The title of the file
244 * [action] The action to be performed by this playlist (e.g. SWFTOOLS_MP3_DISPLAY_LIST)
245 * @param $method
246 * Object containing two keys - player and method. Each consists of an array
247 * that defines the details of the resolved player and embedding method that
248 * is being used for this file.
249 * @param $vars
250 * Object containing three keys - othervars, flashvars and params. These are
251 * arrays containing key/value pairs that contain all the data assigned to this
252 * file so far. THE ARRAY othervars CONTAINS A KEY playlist_data THAT APPEARS
253 * TO REPEAT THE CONTENTS OF xml_data. IS IT NECESSARY TO PASS BOTH?
254 * @return
255 * String of text that be written to the xml file defining the playlist.
256 */
257 function flowplayer3_flowplayer3_mediaplayer_swftools_playlist($xml_data, &$method, &$vars) {
258
259 // For FlowPlayer3 return nothing and let the handler create an empty xml file
260 return;
261
262 }
263
264
265 /*
266 * Implementation of hook_swftools_variable_mapping().
267 *
268 * @return
269 * Array of data describing how parameters passed to the player should be
270 * mapped. The first keys describe the name of the player, and this contains
271 * a sub-array that consists of key/value pairs. The key describes the name
272 * of the parameter, the value describes what it maps to, e.g. flashvars
273 */
274 function flowplayer3_swftools_variable_mapping() {
275
276 // FlowPlayer3 doesn't need to make any variable mappings
277 return array(
278 FLOWPLAYER3_MEDIAPLAYER => array(),
279 );
280 }
281
282
283 /**
284 * Return player configurations settings that will be used if not over-ridden.
285 *
286 * @return
287 * Because there are so many settings for FlowPlayer3 the defaults are defined
288 * in the array returned by this function. The function initialises an array
289 * of defaults, merges settings from the configuration page, and returns the
290 * result.
291 */
292 function _flowplayer3_settings() {
293
294 // Define the settings list
295 $defaults['clip'] = array(
296 'autoPlay' => 'false',
297 'autoBuffering' => 'false',
298 'scaling' => 'scale',
299 'start' => '',
300 'duration' => '',
301 'accelerated' => 'false',
302 'bufferLength' => '',
303 'provider' => '',
304 'fadeInSpeed' => '',
305 'fadeOutSpeed' => '',
306 'linkUrl' => '',
307 'linkWindow' => '_blank',
308 'live' => 'false',
309 'cuePointMultiplier' => '',
310 );
311
312 $defaults['controls'] = array(
313 'backgroundColor' => '#000000',
314 'timeColor' => '#01DAFF',
315 'durationColor' => '#FFFFFF',
316 'progressColor' => '#015B7A',
317 'backgroundGradient' => 'medium',
318 'progressGradient' => 'medium',
319 'bufferColor' => '#6C9CBC',
320 'bufferGradient' => 'none',
321 'sliderColor' => '#000000',
322 'sliderGradient' => 'none',
323 'buttonColor' => '#889AA4',
324 'buttonOverColor' => '#92B2BD',
325 'autoHide' => 'fullscreen',
326 'play' => 'true',
327 'volume' => 'true',
328 'mute' => 'true',
329 'time' => 'true',
330 'stop' => 'false',
331 'playlist' => 'false',
332 'fullscreen' => 'true',
333 'scrubber' => 'true',
334 'top' => '',
335 'left' => '',
336 'bottom' => '',
337 'right' => '',
338 'opacity' => '',
339 );
340
341 $defaults['canvas'] = array(
342 'backgroundColor' => '#000000',
343 'backgroundImage' => '',
344 'backgroundRepeat' => 'repeat',
345 'backgroundGradient' => 'low',
346 'border' => '',
347 'borderRadius' => '',
348 );
349
350 // Retrieve settings from database, if available
351 $saved_settings = variable_get(FLOWPLAYER3_MEDIAPLAYER, array());
352 $saved_colors = variable_get('flowplayer3_palette', array());
353
354 if ($saved_colors) {
355 // Move background color to canvas
356 $saved_settings['canvas']['backgroundColor'] = $saved_colors['backgroundColor'];
357
358 // Move control bar background color to controls
359 $saved_colors['backgroundColor'] = $saved_colors['controlbarbackgroundColor'];
360 unset($saved_colors['controlbarbackgroundColor']);
361
362 $saved_settings['controls'] += $saved_colors;
363 }
364
365 // Merge the two sets together
366 $defaults = array_merge($defaults, $saved_settings);
367
368 // Return resulting defaults
369 return $defaults;
370 }
371
372
373 /**
374 * Implementation of hook_help().
375 */
376 function flowplayer3_help($path, $arg) {
377 switch ($path) {
378 case 'admin/settings/swftools/flowplayer3':
379 return '<p>' . t('These are the settings for the FlowPlayer 3 media player.
380 For details of what each parameter does refer to the
381 <a href="@flowplayer">FlowPlayer 3 documentation</a>.
382 It is possible that you do not need to change any of
383 these settings and blank values will use FlowPlayer
384 defaults.
385 If content is embedded using the SWF Tools filter then each parameter
386 can be over-ridden by specifying a new value in the filter string.', array('@flowplayer' => 'http://flowplayer.org/demos/index.html')) . '</p>';
387 }
388 }
389
390 /**
391 * Implementation of hook_theme().
392 */
393 function flowplayer3_theme() {
394 return array(
395 'flowplayer3_scheme_form' => array(
396 'arguments' => array('form' => NULL),
397 'file' => 'flowplayer3.admin.inc',
398 ),
399 );
400 }

  ViewVC Help
Powered by ViewVC 1.1.2