You are here

function flickr_admin_settings_validate in Flickr 6

Same name and namespace in other branches
  1. 5 flickr.module \flickr_admin_settings_validate()
  2. 7 flickr.admin.inc \flickr_admin_settings_validate()

File

./flickr.admin.inc, line 178

Code

function flickr_admin_settings_validate($form, &$form_state) {
  $key = trim($form_state['values']['flickr_api_key']);
  $sec = trim($form_state['values']['flickr_api_secret']);
  $uid = trim($form_state['values']['flickr_default_userid']);
  $limit1 = trim($form_state['values']['flickr_photos_per_page']);
  $limit2 = trim($form_state['values']['flickr_title_suppress_on_small']);
  $limit3 = trim($form_state['values']['flickr_metadata_suppress_on_small']);
  $limit4 = trim($form_state['values']['flickr_caption_padding']);
  if (!is_numeric($limit1) || $limit1 < 1) {
    form_set_error('flickr_photos_per_page', t('Set a number from 1 to 999.'));
  }

  // Validate the minimum width to suppress title caption.
  if (!is_numeric($limit2) || $limit2 < 0) {
    form_set_error('flickr_title_suppress_on_small', t('Set a width from 0 to 999 px.'));
  }
  if ($key && preg_match('/^[A-Fa-f\\d]{32}$/', $key) != 1) {
    form_set_error('flickr_api_key', t('This does not appear to be a Flickr API key.'));
  }
  if ($sec && preg_match('/^[A-Fa-f\\d]{16}$/', $sec) != 1) {
    form_set_error('flickr_api_secret', t('This does not appear to be a Flickr API secret.'));
  }
  if ($uid) {
    $user = flickr_user_find_by_identifier($uid);
    if (!$user) {
      form_set_error('flickr_default_userid', t('%uid does not appear to be a valid Flickr user.', array(
        '%uid' => $uid,
      )));
    }
  }

  // Validate the number of photos.
  if (!is_numeric($limit1) || $limit1 < 1) {
    form_set_error('flickr_photos_per_page', t('Set a number from 1 to 999.'));
  }

  // Validate the minimum width to suppress title caption.
  if (!is_numeric($limit2) || $limit2 < 0) {
    form_set_error('flickr_title_suppress_on_small', t('Set a width from 0 to 999 px.'));
  }

  // Validate the minimum width to suppress metadata caption.
  if (!is_numeric($limit2) || $limit3 < 0) {
    form_set_error('flickr_metadata_suppress_on_small', t('Set a width from 0 to 999 px.'));
  }

  // Validate the minimum width to suppress metadata caption.
  if (!is_numeric($limit4) || $limit4 < 0) {
    form_set_error('flickr_caption_padding', t('Set a padding from 0 to 99 px.'));
  }
}