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

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

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


Revision 1.8 - (show annotations) (download) (as text)
Tue Mar 17 23:18:10 2009 UTC (8 months, 1 week ago) by stuartgreenfield
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +3 -1 lines
File MIME type: text/x-php
In response to #348437 reported by stormsweeper two changes are implemented. Added status report to main Drupal status page, and SWF Tools status, to give a warning if the zlib library isn't present. This library is needed to read height and width data from compressed swf files. Secondly, player modules now report a default height and width, so if all else fails we can fall back on those so that media content will display correctly. As part of this the sizing function has been separated in to a new swftools_set_size() function to try and clarify the code.
1 <?php
2 // $Id: imagerotator.module,v 1.7 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, branded forms of which ship with SWF Tools module.
9 *
10 * Author's Site.
11 * http://jeroenwijering.com
12 */
13
14 define('WIJERING_IMAGEROTATOR', 'wijering_imagerotator'); // 'player', can display images.
15 define('IMAGEROTATOR_DOWNLOAD', 'http://www.jeroenwijering.com/?item=jw_image_rotator');
16
17 /**
18 * Implementation of hook_swftools_methods().
19 */
20 function imagerotator_swftools_methods() {
21
22 $methods = array();
23
24 // And with rotator
25 $image_rotator = array(
26 'name' => WIJERING_IMAGEROTATOR,
27 'module' => 'imagerotator',
28 'file' => 'file', // Define which flashvar to assign a 'file to play' variable.
29 'version' => '7',
30 'shared_file' => 'flash_image_rotator/imagerotator.swf',
31 'title' => t('JW Image Rotator 3'),
32 'download' => IMAGEROTATOR_DOWNLOAD,
33 'width' => '400',
34 'height' => '320',
35 );
36
37 $methods[SWFTOOLS_IMAGE_DISPLAY_LIST][WIJERING_IMAGEROTATOR] = $image_rotator;
38
39 return $methods;
40 }
41
42 /**
43 * Implementation of hook_menu().
44 */
45 function imagerotator_menu() {
46
47 $items = array();
48
49 //$items['admin/media/swf/imagerotator'] = array(
50 $items['admin/settings/swftools/imagerotator'] = array(
51 'title' => 'JW Image Rotator 3',
52 'description' => 'Plug-in for '. l('Jeroen Wijering\'s Image Rotator 3', IMAGEROTATOR_DOWNLOAD) .'.',
53 'access arguments' => array('administer flash'),
54 'page callback' => 'drupal_get_form',
55 'page arguments' => array('imagerotator_admin_form'),
56 'file' => 'imagerotator.admin.inc',
57 'file path' => drupal_get_path('module', 'imagerotator'),
58 );
59
60 return $items;
61 }
62
63
64 /**
65 * These are the default settings as they are stored in the database and displayed
66 * on the settings page.
67 */
68 function _imagerotator_settings($player) {
69 $opts = _imagerotator_options();
70
71 switch ($player) {
72 case WIJERING_IMAGEROTATOR:
73 // Define the settings list.
74 $defaults['boolean'] = array(
75 'shuffle' => 'default',
76 'shownavigation' => 'default',
77 'linkfromdisplay' => 'default',
78 'showicons' => 'default',
79 'enablejs' => 'default',
80 );
81 $defaults['color'] = array(
82 'backcolor' => '',
83 'frontcolor' => '',
84 'lightcolor' => '',
85 );
86 $defaults['url'] = array(
87 'logo' => '',
88 'link' => '',
89 );
90 $defaults['integer'] = array(
91 'width' => '400',
92 'height' => '320',
93 'rotatetime' => '3',
94 );
95 $defaults['other'] = array(
96 'transition' => 'default',
97 'linktarget' => 'default',
98 'overstretch' => 'default',
99 );
100 $saved_settings = variable_get('swftools_'. WIJERING_IMAGEROTATOR, array());
101 break;
102 }
103
104 // Overwrite initialised variables with those that might be already saved.
105 foreach ($defaults AS $category => $vars) {
106 foreach ($vars AS $key => $setting) {
107 if (isset($saved_settings[$key])) {
108 $defaults[$category][$key] = $saved_settings[$key];
109 }
110 }
111 }
112
113 return $defaults;
114 }
115
116 /**
117 * Implementation of swftools_flashvars hook.
118 * Return an array of flashvars.
119 */
120 function imagerotator_swftools_flashvars($action, &$methods, &$vars) {
121
122 // Pad out the user parameters (like those passed through swf(), with our
123 // configured defaults, allowing the user parameters to dominate.
124 $saved_settings = _imagerotator_flashvars($methods->player['name']);
125
126 $saved = array();
127 foreach ($saved_settings AS $category => $settings) {
128 $saved = array_merge($saved, $settings);
129 }
130 $flashvars = array_merge($saved, $vars->flashvars);
131 if (isset($flashvars['image']) && !valid_url($flashvars['image'], TRUE)) {
132 $flashvars['image'] = swftools_get_media_url(swftools_get_media_path() . $flashvars['image']);
133 }
134
135 if ($vars->params['width']) {$flashvars['width'] = $vars->params['width'];}
136 if ($vars->params['height']) {$flashvars['height'] = $vars->params['height'];}
137
138 // Return an array of flash variables
139 return $flashvars;
140 }
141
142 /**
143 * This function is called from imagerotator_swftools_flashvars() which is called from swf()
144 * It will return the default flashvar configuration, just prior to any overrides
145 * passed into swf(). We start with the settings defined on admin/swf/imagerotator
146 * which are returned by _imagerotator_settings(). Then we prepare these values for output
147 * to html (eg. '1' become 'true') and we unset undefined flashvars to prevent their output.
148 *
149 */
150 function _imagerotator_flashvars($this_player) {
151 // Cache this.
152 static $flashvars = array();
153 if (!count($flashvars)) {
154
155 // Media Player
156 foreach (array(WIJERING_IMAGEROTATOR) AS $player) {
157
158 // Get saved settings for this method.
159 $defaults = _imagerotator_settings($player);
160 foreach ($defaults AS $category => $vars) {
161 foreach ($vars AS $key => $setting) {
162 if (!$setting || $setting == 'default') {
163 unset($defaults[$category][$key]);
164 }
165 else {
166 switch ($category) {
167 case 'color':
168 $defaults['color'][$key] = str_replace('#', '0x', $defaults['color'][$key]);
169 break;
170 case 'boolean':
171 $defaults['boolean'][$key] = _swftools_tf($defaults['boolean'][$key]);
172 break;
173 }
174 }
175 }
176 }
177
178 // Not the same as width/height. This determines the extended width OR height
179 // past the main view area where the actual playlist file names can be found.
180 // Setting both together is not supported.
181 if ($defaults['integer']['displaywidth']) {
182 unset($defaults['integer']['displayheight']);
183 }
184 else {
185 unset($defaults['integer']['displaywidth']);
186 }
187
188 $flashvars[$player] = $defaults;
189 }
190 }
191
192 return $flashvars[$this_player];
193 }
194
195 /**
196 * flashvar and param option arrays. These are used for options settings in the
197 * configuration screen.
198 *
199 */
200 function _imagerotator_options() {
201 $options['overstretch'] = array('default' => 'default', 'false' => 'false', 'true' => 'true', 'fit' => 'fit', 'none' => 'none', );
202 $options['repeat'] = array('default' => 'default', 'false' => 'false', 'true' => 'true', 'list' => 'list', );
203 $options['linktarget'] = array('default' => 'default', '_self' => '_self', '_blank' => '_blank', );
204 $options['transition'] = array('default' => 'default', 'fade' => 'fade', 'bgfade' => 'bgfade', 'blocks' => 'blocks', 'bubbles' => 'bubbles', 'circles' => 'circles', 'flash' => 'flash', 'fluids' => 'fluids', 'lines' => 'lines', 'slowfade' => 'slowfade', 'random' => 'random', );
205 $options['bool'] = array('default' => 'default', 'true' => 'true', 'false' => 'false');
206 return $options;
207 }
208
209
210 function imagerotator_wijering_imagerotator_swftools_playlist($xml_data, &$method, &$vars) {
211
212 $xml = '<playlist version="1" xmlns="http://xspf.org/ns/0/">
213 <title>'. $xml_data['header']['title'] .'</title>
214 <info></info>
215 <annotation></annotation>
216 <trackList>
217 ';
218
219 foreach($xml_data['playlist'] AS $track => $details) {
220 $xml .= "<track>\n";
221 $xml .= "<title>". $details['title'] ."</title>\n";
222 $xml .= "<creator></creator>\n";
223 $xml .= "<location>". $details['fileurl'] ."</location>\n";
224 $xml .= "<info>". $details['fileurl'] ."</info>\n";
225 $xml .= "</track>\n";
226 }
227 $xml .= '</trackList>
228 </playlist>';
229
230 return $xml;
231 }
232
233
234 /*
235 * Implementation of hook_swftools_variable_mapping.
236 *
237 */
238 function imagerotator_swftools_variable_mapping() {
239 return array(
240 WIJERING_IMAGEROTATOR => array(
241 'shuffle' => 'flashvars',
242 'shownavigation' => 'flashvars',
243 'linkfromdisplay' => 'flashvars',
244 'showicons' => 'flashvars',
245 'enablejs' => 'flashvars',
246 'backcolor' => 'flashvars',
247 'frontcolor' => 'flashvars',
248 'lightcolor' => 'flashvars',
249 'logo' => 'flashvars',
250 'link' => 'flashvars',
251 'rotatetime' => 'flashvars',
252 'transition' => 'flashvars',
253 'linktarget' => 'flashvars',
254 'overstretch' => 'flashvars',
255 ),
256 );
257 }
258
259
260 /**
261 * Implementation of hook_help
262 */
263 function imagerotator_help($path, $arg) {
264 switch ($path) {
265 case 'admin/settings/swftools/imagerotator':
266 return '<p>'.t('These are the settings for Jeroen Wijering\'s imagerotator.swf
267 and correspond (by category and order) to the
268 <a href="@imagerotator">Media Player and Image Rotator read me</a>.
269 It is possible that you do not need to change any of
270 these settings and blank values will defer to friendly
271 defaults. Note that the label in (<em>brackets</em>)
272 is the actual flashvar name and corresponds to the read me.', array('@imagerotator' => 'http://jeroenwijering.com/extras/readme.html')).'</p>';
273 }
274 }

  ViewVC Help
Powered by ViewVC 1.1.2