You are here

function shadowbox_admin_settings_validate in Shadowbox 5

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

Validate admin settings form inputs.

File

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

Code

function shadowbox_admin_settings_validate($form_id, &$form) {
  global $form_values;
  $asset_url = $form_values['shadowbox_asset_url'];
  $loading_image = $form_values['shadowbox_loading_image'];
  $flv_player = $form_values['shadowbox_flv_player'];
  $resize_duration = $form_values['shadowbox_resize_duration'];
  $fade_duration = $form_values['shadowbox_fade_duration'];
  $initial_height = $form_values['shadowbox_initial_height'];
  $initial_width = $form_values['shadowbox_initial_width'];
  $color = $form_values['shadowbox_overlay_color'];
  $opacity = $form_values['shadowbox_overlay_opacity'];
  $background_image = $form_values['shadowbox_background_image'];
  $viewport_padding = $form_values['shadowbox_viewport_padding'];
  $keys_close = $form_values['shadowbox_keys_close'];
  $keys_previous = $form_values['shadowbox_keys_previous'];
  $keys_next = $form_values['shadowbox_keys_next'];
  if (!preg_match('!^([a-z0-9_\\-.]+/)*[a-z0-9_\\-]+$!i', $asset_url)) {
    form_set_error('shadowbox_asset_url', t('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', t('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', t('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', t('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', t('The FLV player does not exist.'));
  }
  if (!is_numeric($resize_duration) || $resize_duration < 0 || $resize_duration > 10) {
    form_set_error('shadowbox_resize_duration', t('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', t('You must enter a number between 0 and 10.'));
  }
  if (!is_numeric($initial_height)) {
    form_set_error('shadowbox_initial_height', t('You must enter a number.'));
  }
  else {
    $form_values['shadowbox_initial_height'] = floor($initial_height);
  }
  if (!is_numeric($initial_width)) {
    form_set_error('shadowbox_initial_width', t('You must enter a number.'));
  }
  else {
    $form_values['shadowbox_initial_width'] = floor($initial_width);
  }
  if (!_validate_hex_color($color)) {
    form_set_error('shadowbox_overlay_color', t('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', t('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', t('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', t('The specified image does not exist.'));
  }
  if (!is_numeric($viewport_padding) || $viewport_padding < 0 || $viewport_padding > 200) {
    form_set_error('shadowbox_viewport_padding', t('You must enter a number between 0 and 200.'));
  }
  else {
    $form_values['shadowbox_viewport_padding'] = (int) $viewport_padding;
  }
  $keys_message = t('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);
  }
}