You are here

function flickr_admin_settings_submit in Flickr 7

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

Submit form data.

1 string reference to 'flickr_admin_settings_submit'
flickr_admin_settings in ./flickr.admin.inc
Implements hook_settings().

File

./flickr.admin.inc, line 754
The admin settings for the Flickr module

Code

function flickr_admin_settings_submit($form, &$form_state) {

  // Uncollapse the preview. Likely we want to see the changes we just made.
  variable_set('flickr_preview_collapsed', FALSE);
  if (variable_get('flickr_css', 1) && module_exists('style_settings')) {

    // Concatenate the caption font-size value and unit.
    variable_set('flickr_capsize', $form_state['values']['flickr_capsize_value'] . $form_state['values']['flickr_capsize_unit']);

    // Concatenate the caption font-size value and unit.
    variable_set('flickr_sswidth', $form_state['values']['flickr_sswidth_value'] . $form_state['values']['flickr_sswidth_unit']);
    $ssratio = $form_state['values']['flickr_sswidth_value'] * $form_state['values']['flickr_sshratio'] / $form_state['values']['flickr_sswratio'];
    $ssratio = $ssratio > 100 ? $ssratio . 'px' : $ssratio . '%';
    variable_set('flickr_slideshow_ratio', $ssratio);

    // IMAGE URL: Reset to default if empty.
    if (module_exists('flickrstyle')) {
      if (trim($form_state['values']['flickrstyle_magnifier_image']) == '') {
        $form_state['values']['flickrstyle_magnifier_image'] = '/' . drupal_get_path('module', 'flickrstyle') . '/img/magnifier.png';
        drupal_set_message(t('The image URL has been reset to the default.'), 'warning', FALSE);
      }
    }
  }
  if (module_exists('flickr_filter')) {

    // Reset to the default preview template if it is found empty.
    $trimmed = trim($form_state['values']['flickr_preview_html']['value']);
    $form_state['values']['flickr_preview_html'] = empty($trimmed) ? variable_set('flickr_preview_html', array(
      'value' => '[flickr-user:id=lolandese1, size=q, num=2, sort=views]',
      'format' => 'full_html',
    )) : $form_state['values']['flickr_preview_html'];
  }

  // Optionally make changes visible after form submit.
  if ($form_state['values']['flickr_cc']) {
    drupal_flush_all_caches();
    drupal_set_message(t('All caches are flushed.'), 'status', FALSE);
  }
  elseif (variable_get('flickr_css', 1) && module_exists('style_settings')) {
    _drupal_flush_css_js();
  }

  // Clean up the data.
  $form_state['values']['flickr_api_key'] = trim($form_state['values']['flickr_api_key']);
  $form_state['values']['flickr_api_secret'] = trim($form_state['values']['flickr_api_secret']);
  $form_state['values']['flickr_photos_per_page'] = trim($form_state['values']['flickr_photos_per_page']);
  $form_state['values']['flickr_default_userid'] = trim($form_state['values']['flickr_default_userid']);

  // Replace the usernames with a uid.
  // As emails or usernames might change, replace them with a unique nsid.
  if (!flickr_is_nsid($form_state['values']['flickr_default_userid'])) {
    $userid = $form_state['values']['flickr_default_userid'];
    if (empty($userid)) {
      return;
    }
    if ($user = flickr_user_find_by_identifier($userid)) {
      drupal_set_message(t("The Flickr user associated with '%userid' has internally been replaced with the corresponding Flickr ID '%uid'.", array(
        '%userid' => $form_state['values']['flickr_default_userid'],
        '%uid' => $user,
      )));
      $form_state['values']['flickr_default_userid'] = $user;
    }
  }
  else {
    $info = flickr_people_getinfo($form_state['values']['flickr_default_userid']);
    drupal_set_message(t("The Flickr user associated with '%uid' will be shown to you as Flickr user '%userid'.", array(
      '%uid' => $form_state['values']['flickr_default_userid'],
      '%userid' => $info['username']['_content'],
    )));
  }
}