/[drupal]/contributions/modules/shadowbox/shadowbox.module
ViewVC logotype

Contents of /contributions/modules/shadowbox/shadowbox.module

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


Revision 1.7 - (show annotations) (download) (as text)
Sun Jun 1 22:55:57 2008 UTC (17 months, 3 weeks ago) by psynaptic
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +37 -33 lines
File MIME type: text/x-php
Syncing HEAD back with DRUPAL-6--1 after CVS mistake.
1 <?php
2 // $Id: shadowbox.module,v 1.5 2008/05/12 22:39:42 psynaptic Exp $
3
4
5 /**
6 * Implementation of hook_help().
7 */
8 function shadowbox_help($path, $arg) {
9 switch ($path) {
10 case 'admin/help#shadowbox':
11 $output = '<p>'. t('Shadowbox is a modal media viewer application akin to <a href="!lightbox_project">Lightbox2</a> and <a href="!thickbox_project">Thickbox</a>. You can use it to display images, movies, and other web content in a window that is overlaid on top of the originating page.', array('!thickbox_project' => url('http://drupal.org/project/thickbox', array('absolute' => TRUE)), '!lightbox_project' => url('http://drupal.org/project/lightbox2', array('absolute' => TRUE)))) .'</p>';
12 $output .= '<strong>'. t('From the author of Shadowbox:') .'</strong>';
13 $output .= '<blockquote>'. t('Shadowbox is a cross-browser, cross-platform, cleanly-coded and fully-documented media viewer application written entirely in JavaScript. Using Shadowbox, website authors can display a wide assortment of media in all major browsers without navigating away from the linking page.') .'</blockquote>';
14 $output .= '<p>'. t('This module currently provides only the most basic of functionality. It has <a href="!shadowbox_settings">global settings</a> that work on a site-wide basis. This means if you change a setting it will apply to all the Shadowboxes on your site.', array('!shadowbox_settings' => url('admin/settings/shadowbox'))) .'</p>';
15 $output .= '<p>'. t('Future versions of this module will integrate with imagefield, imagecache and other important Drupal image modules and provide more options for configuring Shadowbox on a per-instance basis.') .'</p>';
16 $output .= '<h3>'. t('Usage:') .'</h3>';
17 $output .= '<p>'. t('Currently, to activate Shadowbox for a link, you must manually inject the required attribute. Depending on your needs you may need to do this on the theming layer. To open any link in shadowbox you need to add a <strong><code>rel</code></strong> attribute with a value of <strong><code>shadowbox</code></strong> (for compatibility with Lightbox you can also use a value of <strong><code>lightbox</code></strong>).') .'</p>';
18 $output .= '<strong>'. t('Single image:') .'</strong>';
19 $output .= '<p>'. t('The important thing to note here is the <code>rel</code> attribute. This tells Shadowbox you wish to activate it for this link. The <code>title</code> attribute is optional and can be used to give a caption to the instance.') .'</p>';
20 $output .= '<p>'. t('<code><pre>&lt;a href=&quot;/files/image1.jpg&quot; rel=&quot;shadowbox&quot; title=&quot;Caption&quot;&gt;Image&lt;/a&gt;</pre></code>') .'</p>';
21 $output .= '<strong>'. t('Multiple instances (gallery mode):') .'</strong>';
22 $output .= '<p>'. t('Media can be grouped into a gallery using <code>shadowbox[name]</code> where <code>name</code> is any name you wish to apply. The value of <code>[name]</code> is only used internally by Shadowbox and won\'t be shown to the user.') .'</p>';
23 $output .= '<p>'. t('<code><pre>&lt;a href=&quot;/files/image1.jpg&quot; rel=&quot;shadowbox[gallery]&quot; title=&quot;Caption 1&quot;&gt;Image&lt;/a&gt;
24 &lt;a href=&quot;/files/image2.jpg&quot; rel=&quot;shadowbox[gallery]&quot; title=&quot;Caption 2&quot;&gt;Image&lt;/a&gt;
25 &lt;a href=&quot;/files/image3.jpg&quot; rel=&quot;shadowbox[gallery]&quot; title=&quot;Caption 3&quot;&gt;Image&lt;/a&gt;</pre></code>') .'</p>';
26 $output .= '<strong>'. t('External URL:') .'</strong>';
27 $output .= '<p>'. t('A powerful feature of Shadowbox is the ability to open web pages directly on top of the current page. Try out the example and see how the site still functions as normal on top of the originating page.') .'</p>';
28 $output .= '<p>'. t('<code><pre>&lt;a href=&quot;http://google.com&quot; rel=&quot;shadowbox&quot; title=&quot;Google&quot;&gt;Google&lt;/a&gt;</pre></code>') .'<p>';
29 $output .= '<h3>'. t('Advanced usage:') .'</h3>';
30 $output .= '<p>'. t('Shadowbox allows you to specify options on a per-instance basis by using a JSON-formatted parameter. More information on this feature can be found on the <a href="!shadowbox_usage">Shadowbox usage page</a>.', array('!shadowbox_usage' => url('http://mjijackson.com/shadowbox/doc/usage.html#markup', array('absolute' => TRUE)))) .'</p>';
31 return $output;
32
33 case 'admin/settings/shadowbox':
34 return t('<p>This page provides access to the Shadowbox settings. The settings work globally so any changes made here will affect Shadowbox for the entire site.</p>');
35 }
36 }
37
38 /**
39 * Implementation of hook_menu().
40 */
41 function shadowbox_menu() {
42 $items = array();
43
44 $items['admin/settings/shadowbox'] = array(
45 'title' => 'Shadowbox',
46 'page callback' => 'drupal_get_form',
47 'page arguments' => array('shadowbox_admin_settings'),
48 'access callback' => 'user_access',
49 'access arguments' => array('administer shadowbox'),
50 'description' => 'Configure the settings for Shadowbox',
51 'type' => MENU_NORMAL_ITEM,
52 );
53
54 return $items;
55 }
56
57 /**
58 * Implementation of hook_perm().
59 */
60 function shadowbox_perm() {
61 return array('administer shadowbox');
62 }
63
64 /**
65 * Implementation of hook_init().
66 */
67 function shadowbox_init() {
68 if (variable_get('shadowbox_enabled', TRUE)) {
69 $options['shadowbox'] = array(
70 'asset_url' => variable_get('shadowbox_asset_url', url(drupal_get_path('module', 'shadowbox') .'/shadowbox/')),
71 'loading_image' => variable_get('shadowbox_loading_image', 'images/loading.gif'),
72 'animation' => variable_get('shadowbox_animate', TRUE),
73 'animation_sequence' => variable_get('shadowbox_animation_sequence', 'wh'),
74 'overlay_color' => variable_get('shadowbox_overlay_color', '#000'),
75 'overlay_opacity' => variable_get('shadowbox_overlay_opacity', 0.85),
76 'overlay_listen' => variable_get('shadowbox_overlay_listen', TRUE),
77 'resize_duration' => variable_get('shadowbox_resize_duration', 0.35),
78 'fade_duration' => variable_get('shadowbox_fade_duration', 0.35),
79 'display_nav' => variable_get('shadowbox_display_nav', TRUE),
80 'flv_player' => variable_get('shadowbox_flv_player', 'flvplayer.swf'),
81 'background_image' => variable_get('shadowbox_background_image', 'images/overlay-85.png'),
82 'autoplay_movies' => variable_get('shadowbox_autoplay_movies', TRUE),
83 'show_movie_controls' => variable_get('shadowbox_show_movie_controls', TRUE),
84 'continuous_galleries' => variable_get('shadowbox_continuous_galleries', FALSE),
85 'display_counter' => variable_get('shadowbox_display_counter', TRUE),
86 'counter_type' => variable_get('shadowbox_counter_type', 'default'),
87 'viewport_padding' => variable_get('shadowbox_viewport_padding', 20),
88 'initial_height' => variable_get('shadowbox_initial_height', 160),
89 'initial_width' => variable_get('shadowbox_initial_width', 320),
90 'enable_keys' => variable_get('shadowbox_enable_keys', TRUE),
91 'keys_close' => _explode_to_int(variable_get('shadowbox_keys_close', 'c q 27'), ' '),
92 'keys_previous' => _explode_to_int(variable_get('shadowbox_keys_previous', 'p 37'), ' '),
93 'keys_next' => _explode_to_int(variable_get('shadowbox_keys_next', 'n 39'), ' '),
94 'handle_large_images' => variable_get('shadowbox_handle_large_images', 'resize'),
95 'handle_unsupported' => variable_get('shadowbox_handle_unsupported', 'link'),
96 );
97 drupal_add_js($options, 'setting');
98 }
99 }
100
101 /**
102 * FAPI definition for the Shadowbox admin settings form.
103 *
104 * @ingroup forms
105 * @see shadowbox_admin_settings_validate()
106 */
107 function shadowbox_admin_settings() {
108 // Global settings
109 $form['shadowbox'] = array(
110 '#type' => 'fieldset',
111 '#title' => t('Global settings'),
112 '#access' => user_access('administer shadowbox'),
113 '#collapsible' => TRUE,
114 '#collapsed' => FALSE,
115 );
116 $form['shadowbox']['shadowbox_enabled'] = array(
117 '#type' => 'checkbox',
118 '#title' => t('Enable Shadowbox'),
119 '#default_value' => variable_get('shadowbox_enabled', TRUE),
120 '#description' => t('Check this box to enable Shadowbox for the site.'),
121 );
122 // Options
123 $form['shadowbox']['shadowbox_options'] = array(
124 '#type' => 'fieldset',
125 '#title' => t('Options'),
126 '#description' => t('Shadowbox is highly configurable, but can also be used with little to no configuration at all. The following options may be used to configure Shadowbox on a site-wide basis.'),
127 '#collapsible' => TRUE,
128 '#collapsed' => FALSE,
129 '#access' => user_access('administer shadowbox'),
130 );
131 // Assets
132 $form['shadowbox']['shadowbox_options']['asset_paths'] = array(
133 '#type' => 'fieldset',
134 '#title' => t('Assets'),
135 '#collapsible' => TRUE,
136 '#collapsed' => TRUE,
137 );
138 $form['shadowbox']['shadowbox_options']['asset_paths']['shadowbox_asset_url'] = array(
139 '#type' => 'textfield',
140 '#title' => t('Base asset URL'),
141 '#description' => t('A base URL that will be prepended to the loadingImage, flvPlayer, and overlayBgImage options to save on typing.'),
142 '#size' => 40,
143 '#maxlength' => 255,
144 '#default_value' => variable_get('shadowbox_asset_url', url(drupal_get_path('module', 'shadowbox') .'/shadowbox/')),
145 );
146 $form['shadowbox']['shadowbox_options']['asset_paths']['shadowbox_loading_image'] = array(
147 '#type' => 'textfield',
148 '#title' => t('Loading image path'),
149 '#description' => t('The URL of an image to use as a loading indicator while loading content.'),
150 '#size' => 40,
151 '#maxlength' => 255,
152 '#default_value' => variable_get('shadowbox_loading_image', 'images/loading.gif'),
153 );
154 $form['shadowbox']['shadowbox_options']['asset_paths']['shadowbox_flv_player'] = array(
155 '#type' => 'textfield',
156 '#title' => t('FLV Player'),
157 '#description' => t('The URL of the flash video player.'),
158 '#size' => 40,
159 '#maxlength' => 255,
160 '#default_value' => variable_get('shadowbox_flv_player', 'flvplayer.swf'),
161 );
162 // Animation
163 $form['shadowbox']['shadowbox_options']['animation_settings'] = array(
164 '#type' => 'fieldset',
165 '#title' => t('Animation'),
166 '#collapsible' => TRUE,
167 '#collapsed' => TRUE,
168 );
169 $form['shadowbox']['shadowbox_options']['animation_settings']['shadowbox_animate'] = array(
170 '#type' => 'checkbox',
171 '#title' => t('Enable animation'),
172 '#description' => t('Enable all fancy dimension and opacity animations. Disabling this option can improve the overall effect on computers with poor performance.'),
173 '#default_value' => variable_get('shadowbox_animate', TRUE),
174 );
175 $form['shadowbox']['shadowbox_options']['animation_settings']['shadowbox_animation_sequence'] = array(
176 '#type' => 'select',
177 '#title' => t('Animation sequence'),
178 '#multiple' => FALSE,
179 '#description' => t('The animation sequence to use when resizing Shadowbox.'),
180 '#options' => array(
181 'wh' => t('Width then height'),
182 'hw' => t('Height then width'),
183 'sync' => t('Simultaneously'),
184 ),
185 '#default_value' => variable_get('shadowbox_animation_sequence', 'wh'),
186 );
187 $form['shadowbox']['shadowbox_options']['animation_settings']['shadowbox_resize_duration'] = array(
188 '#type' => 'textfield',
189 '#title' => t('Resize duration'),
190 '#description' => t('The duration (in seconds) of the resizing animations.'),
191 '#size' => 5,
192 '#maxlength' => 4,
193 '#default_value' => variable_get('shadowbox_resize_duration', 0.35),
194 '#validate' => array('shadowbox_validate'),
195 );
196 $form['shadowbox']['shadowbox_options']['animation_settings']['shadowbox_fade_duration'] = array(
197 '#type' => 'textfield',
198 '#title' => t('Fade duration'),
199 '#description' => t('The duration (in seconds) of the overlay fade animation.'),
200 '#size' => 5,
201 '#maxlength' => 4,
202 '#default_value' => variable_get('shadowbox_fade_duration', 0.35),
203 '#validate' => array('shadowbox_validate'),
204 );
205 $form['shadowbox']['shadowbox_options']['animation_settings']['shadowbox_initial_height'] = array(
206 '#type' => 'textfield',
207 '#title' => t('Initial height'),
208 '#description' => t('The height of Shadowbox (in pixels) when it first appears on the screen.'),
209 '#size' => 5,
210 '#maxlength' => 4,
211 '#default_value' => variable_get('shadowbox_initial_height', 160),
212 '#validate' => array('shadowbox_validate'),
213 );
214 $form['shadowbox']['shadowbox_options']['animation_settings']['shadowbox_initial_width'] = array(
215 '#type' => 'textfield',
216 '#title' => t('Initial width'),
217 '#description' => t('The width of Shadowbox (in pixels) when it first appears on the screen. '),
218 '#size' => 5,
219 '#maxlength' => 4,
220 '#default_value' => variable_get('shadowbox_initial_width', 320),
221 '#validate' => array('shadowbox_validate'),
222 );
223 // Overlay
224 $form['shadowbox']['shadowbox_options']['overlay'] = array(
225 '#type' => 'fieldset',
226 '#title' => t('Overlay'),
227 '#collapsible' => TRUE,
228 '#collapsed' => TRUE,
229 );
230 $form['shadowbox']['shadowbox_options']['overlay']['shadowbox_overlay_color'] = array(
231 '#type' => 'textfield',
232 '#title' => t('Overlay color'),
233 '#description' => t('Select a hexadecimal color value for the overlay (e.g. #000 or #000000 for black).'),
234 '#size' => 8,
235 '#maxlength' => 7,
236 '#default_value' => variable_get('shadowbox_overlay_color', '#000'),
237 '#validate' => array('shadowbox_validate'),
238 );
239 $form['shadowbox']['shadowbox_options']['overlay']['shadowbox_overlay_opacity'] = array(
240 '#type' => 'textfield',
241 '#title' => t('Overlay opacity'),
242 '#description' => t('The opacity of the overlay. Accepts values between 0 and 1. 0 is fully transparent, 1 is fully opaque.'),
243 '#size' => 5,
244 '#maxlength' => 4,
245 '#default_value' => variable_get('shadowbox_overlay_opacity', 0.85),
246 '#validate' => array('shadowbox_validate'),
247 );
248 $form['shadowbox']['shadowbox_options']['overlay']['shadowbox_background_image'] = array(
249 '#type' => 'textfield',
250 '#title' => t('Overlay backround image'),
251 '#description' => t('The URL of a pre-made image to use for browsers (such as FF Mac) that don\'t support playing movies over backgrounds that are not 100% opaque.'),
252 '#size' => 40,
253 '#maxlength' => 255,
254 '#default_value' => variable_get('shadowbox_background_image', 'images/overlay-85.png'),
255 );
256 $form['shadowbox']['shadowbox_options']['overlay']['shadowbox_viewport_padding'] = array(
257 '#type' => 'textfield',
258 '#title' => t('Viewport padding'),
259 '#description' => t('The amount of padding (in pixels) to maintain around the edge of the browser window.'),
260 '#size' => 4,
261 '#maxlength' => 4,
262 '#default_value' => variable_get('shadowbox_viewport_padding', 20),
263 );
264 // Galleries
265 $form['shadowbox']['shadowbox_options']['gallery'] = array(
266 '#type' => 'fieldset',
267 '#title' => t('Galleries'),
268 '#collapsible' => TRUE,
269 '#collapsed' => TRUE,
270 );
271 $form['shadowbox']['shadowbox_options']['gallery']['shadowbox_display_nav'] = array(
272 '#type' => 'checkbox',
273 '#title' => t('Display gallery navigation.'),
274 '#description' => t('Uncheck this option to hide the gallery navigation controls.'),
275 '#default_value' => variable_get('shadowbox_display_nav', TRUE),
276 );
277 $form['shadowbox']['shadowbox_options']['gallery']['shadowbox_continuous_galleries'] = array(
278 '#type' => 'checkbox',
279 '#title' => t('Enable continuous galleries'),
280 '#description' => t('Check this option to enable "continuous" galleries. By default, the galleries will not let a user go before the first image or after the last. Enabling this feature will let the user go directly to the first image in a gallery from the last one by selecting "Next".'),
281 '#default_value' => variable_get('shadowbox_continuous_galleries', FALSE),
282 );
283 $form['shadowbox']['shadowbox_options']['gallery']['shadowbox_display_counter'] = array(
284 '#type' => 'checkbox',
285 '#title' => t('Enable counter'),
286 '#description' => t('Uncheck this option to hide the gallery counter. Counters are never displayed on elements that are not part of a gallery.'),
287 '#default_value' => variable_get('shadowbox_display_counter', TRUE),
288 );
289 $form['shadowbox']['shadowbox_options']['gallery']['shadowbox_counter_type'] = array(
290 '#type' => 'select',
291 '#title' => t('Counter type'),
292 '#multiple' => FALSE,
293 '#description' => t('The mode to use for the gallery counter. May be either \'default\' or \'skip\'. The default counter is a simple \'1 of 5\' message. The skip counter displays a separate link to each piece in the gallery, enabling quick navigation in large galleries.'),
294 '#options' => array(
295 'default' => t('Default'),
296 'skip' => t('Skip'),
297 ),
298 '#default_value' => variable_get('shadowbox_counter_type', 'default'),
299 );
300 // Movies
301 $form['shadowbox']['shadowbox_options']['movies'] = array(
302 '#type' => 'fieldset',
303 '#title' => t('Movies'),
304 '#collapsible' => TRUE,
305 '#collapsed' => TRUE,
306 );
307 $form['shadowbox']['shadowbox_options']['movies']['shadowbox_autoplay_movies'] = array(
308 '#type' => 'checkbox',
309 '#title' => t('Enable auto-play movies'),
310 '#description' => t('Set this false to disable automatically playing movies when they are loaded.'),
311 '#default_value' => variable_get('shadowbox_autoplay_movies', TRUE),
312 );
313 $form['shadowbox']['shadowbox_options']['movies']['shadowbox_show_movie_controls'] = array(
314 '#type' => 'checkbox',
315 '#title' => t('Enable movie controls'),
316 '#description' => t('Set this false to disable displaying QuickTime and Windows Media player movie control bars.'),
317 '#default_value' => variable_get('shadowbox_show_movie_controls', TRUE),
318 );
319 // Input controls
320 $form['shadowbox']['shadowbox_options']['input'] = array(
321 '#type' => 'fieldset',
322 '#title' => t('Input controls'),
323 '#collapsible' => TRUE,
324 '#collapsed' => TRUE,
325 );
326 $form['shadowbox']['shadowbox_options']['input']['shadowbox_overlay_listen'] = array(
327 '#type' => 'checkbox',
328 '#title' => t('Mouse click closes overlay.'),
329 '#description' => t('Set this false to disable listening for mouse clicks on the overlay that will close Shadowbox.'),
330 '#default_value' => variable_get('shadowbox_overlay_listen', TRUE),
331 );
332 $form['shadowbox']['shadowbox_options']['input']['keyboard'] = array(
333 '#type' => 'fieldset',
334 '#title' => t('Keyboard controls'),
335 '#collapsible' => TRUE,
336 '#collapsed' => TRUE,
337 );
338 $form['shadowbox']['shadowbox_options']['input']['keyboard']['shadowbox_enable_keys'] = array(
339 '#type' => 'checkbox',
340 '#title' => t('Enable keys'),
341 '#description' => t('Set this false to disable keyboard navigation of galleries.'),
342 '#default_value' => variable_get('shadowbox_enable_keys', TRUE),
343 );
344 $form['shadowbox']['shadowbox_options']['input']['keyboard']['shadowbox_keys_close'] = array(
345 '#type' => 'textfield',
346 '#title' => t('Close keys'),
347 '#description' => t('A list of keys (or key codes) that a user may use to close Shadowbox. Values should be separated by a space. Defaults to \'c q 27\' (c, q, or esc).'),
348 '#size' => 40,
349 '#maxlength' => 255,
350 '#default_value' => variable_get('shadowbox_keys_close', 'c q 27'),
351 '#validate' => array('shadowbox_validate'),
352 );
353 $form['shadowbox']['shadowbox_options']['input']['keyboard']['shadowbox_keys_previous'] = array(
354 '#type' => 'textfield',
355 '#title' => t('Previous keys'),
356 '#description' => t('An list of keys (or key codes) that a user may use to skip to the previous piece in the gallery. Values should be separated by a space. Defaults to \'p, 37\' (p or left arrow).'),
357 '#size' => 40,
358 '#maxlength' => 255,
359 '#default_value' => variable_get('shadowbox_keys_previous', 'p 37'),
360 '#validate' => array('shadowbox_validate'),
361 );
362 $form['shadowbox']['shadowbox_options']['input']['keyboard']['shadowbox_keys_next'] = array(
363 '#type' => 'textfield',
364 '#title' => t('Next keys'),
365 '#description' => t('A list of keys (or key codes) that a user may use to skip to the next piece in the gallery. Values should be separated by a space. Defaults to \'n, 39\' (n or right arrow).'),
366 '#size' => 40,
367 '#maxlength' => 255,
368 '#default_value' => variable_get('shadowbox_keys_next', 'n 39'),
369 '#validate' => array('shadowbox_validate'),
370 );
371 // Media handling
372 $form['shadowbox']['shadowbox_options']['media_handling'] = array(
373 '#type' => 'fieldset',
374 '#title' => t('Media handling'),
375 '#collapsible' => TRUE,
376 '#collapsed' => TRUE,
377 );
378 $form['shadowbox']['shadowbox_options']['media_handling']['shadowbox_handle_large_images'] = array(
379 '#type' => 'select',
380 '#title' => t('Handle large images'),
381 '#multiple' => FALSE,
382 '#description' => t('The mode to use for handling images that are too large for the viewport. May be one of "none", "resize", or "drag". The "none" setting will not alter the image dimensions, though clipping will occur. Setting this to "resize" enables on-the-fly resizing of large images. In this mode, the height and width of large images will be adjusted so that they may still be viewed in their entirety while maintaining the original aspect ratio. The "drag" mode will display the image at its original resolution, but will allow the user to drag the image within the view to see portions that may be clipped.'),
383 '#options' => array(
384 'resize' => t('Resize'),
385 'drag' => t('Drag'),
386 'none' => t('None'),
387 ),
388 '#default_value' => variable_get('shadowbox_handle_large_images', 'resize'),
389 );
390 $form['shadowbox']['shadowbox_options']['media_handling']['shadowbox_handle_unsupported'] = array(
391 '#type' => 'select',
392 '#title' => t('Handle unsupported'),
393 '#multiple' => FALSE,
394 '#description' => t('The mode to use for handling unsupported media. May be either <strong>link</strong> or <strong>remove</strong>. Media are unsupported when the browser plugin required to display the media properly is not installed. The link option will display a user-friendly error message with a link to a page where the needed plugin can be downloaded. The remove option will simply remove any unsupported gallery elements from the gallery before displaying it. With this option, if the element is not part of a gallery, the link will simply be followed.'),
395 '#options' => array(
396 'link' => t('Link'),
397 'remove' => t('Remove'),
398 ),
399 '#default_value' => variable_get('shadowbox_handle_unsupported', 'link'),
400 );
401
402 return system_settings_form($form);
403 }
404
405 /**
406 * Validate admin settings form inputs.
407 */
408 function shadowbox_admin_settings_validate($form, &$form_state) {
409 $asset_url = $form_state['values']['shadowbox_asset_url'];
410 if (!preg_match('!^(/[a-z0-9_-]+)+(/{1}$)!i', $asset_url)) {
411 form_set_error('asset_url', 'You must enter a valid path in the form <code>/path/to/asset/</code>. Leading and trailing slashes are required.');
412 }
413 $loading_image = $form_state['values']['shadowbox_loading_image'];
414 if (!preg_match('!^([a-z0-9_-]+/)*[a-z0-9_-]+\.gif$!i', $loading_image)) {
415 form_set_error('loading_image', 'You must enter a valid path to an animated GIF image in the form <code>images/image.gif</code>.');
416 }
417 $flv_player = $form_state['values']['shadowbox_flv_player'];
418 if (!preg_match('!^([a-z0-9_-]+/)*[a-z0-9_-]+\.swf$!i', $flv_player)) {
419 form_set_error('flv_player', 'You must enter a valid path to an SWF Flash Player in the form <code>flvplayer.swf</code>.');
420 }
421 $resize_duration = $form_state['values']['shadowbox_resize_duration'];
422 if (!is_numeric($resize_duration) || $resize_duration < 0 || $resize_duration > 10) {
423 form_set_error('resize_duration', 'You must enter a number between 0 and 10.');
424 }
425 $fade_duration = $form_state['values']['shadowbox_fade_duration'];
426 if (!is_numeric($fade_duration) || $fade_duration < 0 || $fade_duration > 10) {
427 form_set_error('fade_duration', 'You must enter a number between 0 and 10.');
428 }
429 $initial_height = $form_state['values']['shadowbox_initial_height'];
430 if (!is_numeric($initial_height)) {
431 form_set_error('initial_height', 'You must enter a number.');
432 }
433 else {
434 $form_state['values']['shadowbox_initial_height'] = floor($initial_height);
435 }
436 $initial_width = $form_state['values']['shadowbox_initial_width'];
437 if (!is_numeric($initial_width)) {
438 form_set_error('initial_width', 'You must enter a number.');
439 }
440 else {
441 $form_state['values']['shadowbox_initial_height'] = floor($initial_width);
442 }
443 $color = $form_state['values']['shadowbox_overlay_color'];
444 if (!preg_match('!^#[a-f0-9]{3}([a-f0-9]{3})?$!i', $color)) {
445 form_set_error('overlay_color', 'You must enter a properly formed hex value (e.g. #000 or #000000 for black.)');
446 }
447 $opacity = $form_state['values']['shadowbox_overlay_opacity'];
448 if ($opacity == '' || (floor($opacity) != 0 && $opacity != 1)) {
449 form_set_error('overlay_opacity', 'You must enter a decimal number between 0 and 1.');
450 }
451 $background_image = $form_state['values']['shadowbox_background_image'];
452 if (!preg_match('!^([a-z0-9_-]+/)*[a-z0-9_-]+\.png$!i', $background_image)) {
453 form_set_error('background_image', 'You must enter a valid path to a PNG image in the form <code>images/overlay-85.png</code>.');
454 }
455 $viewport_padding = $form_state['values']['shadowbox_viewport_padding'];
456 if (!is_numeric($viewport_padding) || $viewport_padding < 0 || $viewport_padding > 200) {
457 form_set_error('shadowbox_viewport_padding', 'You must enter a number between 0 and 200.');
458 }
459 else {
460 $form_state['values']['shadowbox_viewport_padding'] = (int)$viewport_padding;
461 }
462 $keys_close = $form_state['values']['shadowbox_keys_close'];
463 if (_validate_keys_string($keys_close)) {
464 form_set_error('shadowbox_keys_close', 'You must enter a properly formed string of keys or keycodes seprated by a space.');
465 }
466 $keys_previous = $form_state['values']['shadowbox_keys_previous'];
467 if (_validate_keys_string($keys_previous)) {
468 form_set_error('shadowbox_keys_previous', 'You must enter a properly formed string of keys or keycodes seprated by a space.');
469 }
470 $keys_next = $form_state['values']['shadowbox_keys_next'];
471 if (_validate_keys_string($keys_next)) {
472 form_set_error('shadowbox_keys_next', 'You must enter a properly formed string of keys or keycodes seprated by a space.');
473 }
474 }
475
476 /**
477 * Implementation of hook_nodeapi().
478 */
479 function shadowbox_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
480 if (variable_get('shadowbox_enabled', TRUE)) {
481 switch ($op) {
482 case 'view':
483 $path = drupal_get_path('module', 'shadowbox');
484 drupal_add_css($path ."/shadowbox/build/css/shadowbox.css");
485 drupal_add_js($path ."/shadowbox/build/js/adapter/shadowbox-jquery.js");
486 drupal_add_js($path ."/shadowbox/build/js/shadowbox.js");
487 drupal_add_js($path ."/shadowbox.js");
488 }
489 }
490 }
491
492 /**
493 * Convert numerical value(s) within a delimited string to integer(s).
494 *
495 * Explode a delimted string e.g. 'a b 2' or 'a,b,2' and type cast numeric
496 * string values to int.
497 *
498 * @param $string
499 * A delimited string containing a numerical value.
500 * @param $delimiter
501 * The boundary string by which to explode.
502 *
503 * @return
504 * An array containing strings and integrers.
505 */
506 function _explode_to_int($string, $delimiter) {
507 foreach (explode($delimiter, $string) as $value) {
508 (is_numeric($value)) ? $output[] = (int)$value : $output[] = $value;
509 }
510 return $output;
511 }
512
513 /**
514 * Validate a delimited string of keys and/or keycodes.
515 *
516 * @param $input
517 * A delimited string of keys and/or keycodes to validate.
518 *
519 * @return
520 * TRUE if $input is valid otherwise FALSE.
521 */
522 function _validate_keys_string($input) {
523 foreach (explode(' ', $input) as $value) {
524 (preg_match('!^(?:[a-z]|\d{1,3})$!i', $value)) ? $items[] = TRUE : $items[] = FALSE;
525 }
526 (in_array(FALSE, $items)) ? $return = TRUE : $return = FALSE;
527 return $return;
528 }
529

  ViewVC Help
Powered by ViewVC 1.1.2