You are here

function shadowbox_admin_settings_validate in Shadowbox 6

Same name and namespace in other branches
  1. 5 shadowbox.module \shadowbox_admin_settings_validate()

Validate admin settings form inputs.

File

./shadowbox.module, line 433
Shadowbox, a JavaScript media viewer application for displaying content in a modal dialog.

Code

function shadowbox_admin_settings_validate($form, &$form_state) {
  $asset_url = $form_state['values']['shadowbox_asset_url'];
  $loading_image = $form_state['values']['shadowbox_loading_image'];
  $flv_player = $form_state['values']['shadowbox_flv_player'];
  $resize_duration = $form_state['values']['shadowbox_resize_duration'];
  $fade_duration = $form_state['values']['shadowbox_fade_duration'];
  $initial_height = $form_state['values']['shadowbox_initial_height'];
  $initial_width = $form_state['values']['shadowbox_initial_width'];
  $color = $form_state['values']['shadowbox_overlay_color'];
  $opacity = $form_state['values']['shadowbox_overlay_opacity'];
  $background_image = $form_state['values']['shadowbox_background_image'];
  $viewport_padding = $form_state['values']['shadowbox_viewport_padding'];
  $keys_close = $form_state['values']['shadowbox_keys_close'];
  $keys_previous = $form_state['values']['shadowbox_keys_previous'];
  $keys_next = $form_state['values']['shadowbox_keys_next'];
  if (!preg_match('!^([a-z0-9_-]+/)*[a-z0-9_-]+$!i', $asset_url)) {
    form_set_error('shadowbox_asset_url', 'You must enter a valid path in the form <code>path/to/asset</code> (no leading or trailing slashes).');
  }
  if (!preg_match('!^([a-z0-9_-]+/)*[a-z0-9_-]+\\.gif$!i', $loading_image)) {
    form_set_error('shadowbox_loading_image', 'You must enter a valid path to an animated GIF image in the form <code>images/image.gif</code>.');
  }
  elseif (!file_exists($asset_url . '/' . $loading_image)) {
    form_set_error('shadowbox_loading_image', 'The specified image does not exist.');
  }
  if (!preg_match('!^([a-z0-9_-]+/)*[a-z0-9_-]+\\.swf$!i', $flv_player)) {
    form_set_error('shadowbox_flv_player', 'You must enter a valid path to an SWF Flash Player in the form <code>flvplayer.swf</code>.');
  }
  elseif (!file_exists($asset_url . '/' . $flv_player)) {
    form_set_error('shadowbox_flv_player', 'The FLV player does not exist.');
  }
  if (!is_numeric($resize_duration) || $resize_duration < 0 || $resize_duration > 10) {
    form_set_error('shadowbox_resize_duration', 'You must enter a number between 0 and 10.');
  }
  if (!is_numeric($fade_duration) || $fade_duration < 0 || $fade_duration > 10) {
    form_set_error('shadowbox_fade_duration', 'You must enter a number between 0 and 10.');
  }
  if (!is_numeric($initial_height)) {
    form_set_error('shadowbox_initial_height', 'You must enter a number.');
  }
  else {
    $form_state['values']['shadowbox_initial_height'] = floor($initial_height);
  }
  if (!is_numeric($initial_width)) {
    form_set_error('shadowbox_initial_width', 'You must enter a number.');
  }
  else {
    $form_state['values']['shadowbox_initial_width'] = floor($initial_width);
  }
  if (!preg_match('!^#[a-f0-9]{3}([a-f0-9]{3})?$!i', $color)) {
    form_set_error('shadowbox_overlay_color', 'You must enter a properly formed hex value (e.g. #000 or #000000 for black.)');
  }
  if ($opacity == '' || floor($opacity) != 0 && $opacity != 1) {
    form_set_error('shadowbox_overlay_opacity', 'You must enter a decimal number between 0 and 1.');
  }
  if (!preg_match('!^([a-z0-9_-]+/)*[a-z0-9_-]+\\.png$!i', $background_image)) {
    form_set_error('shadowbox_background_image', 'You must enter a valid path to a PNG image in the form <code>images/overlay-85.png</code>.');
  }
  elseif (!file_exists($asset_url . '/' . $background_image)) {
    form_set_error('shadowbox_background_image', 'The specified image does not exist.');
  }
  if (!is_numeric($viewport_padding) || $viewport_padding < 0 || $viewport_padding > 200) {
    form_set_error('shadowbox_viewport_padding', 'You must enter a number between 0 and 200.');
  }
  else {
    $form_state['values']['shadowbox_viewport_padding'] = (int) $viewport_padding;
  }
  $keys_message = 'You must enter a properly formed string of keys or keycodes seprated by a space.';
  if (_validate_keys_string($keys_close)) {
    form_set_error('shadowbox_keys_close', $keys_message);
  }
  if (_validate_keys_string($keys_previous)) {
    form_set_error('shadowbox_keys_previous', $keys_message);
  }
  if (_validate_keys_string($keys_next)) {
    form_set_error('shadowbox_keys_next', $keys_message);
  }
}