You are here

function nivo_slider_settings_submit in Nivo Slider 7

Save settings data.

1 string reference to 'nivo_slider_settings_submit'
nivo_slider_slide_configuration_form in ./nivo_slider_slides.admin.inc
Configuration form for slider slides.

File

./nivo_slider_slides.admin.inc, line 171
Generate configuration form and save settings.

Code

function nivo_slider_settings_submit($form, &$form_state) {

  // Create an array to hold slides
  $slides = array();

  // Create a file object to hold the slide image file
  $file = new stdClass();

  // Process the available slides
  foreach ($form_state['values']['images'] as $slide => $settings) {

    // Ensure that only slide settings are processed
    if (is_numeric($slide)) {
      if (is_array($settings)) {

        // Delete the slide if required otherwise add it to the array of slides
        if ($settings['delete']) {

          // Load the file with the file ID
          if (isset($settings['fid'])) {
            $file = file_load($settings['fid']);

            // Delete the file
            if (!empty($file)) {
              file_delete($file);
            }
          }
        }
        else {
          $slides[] = $settings;
        }
      }
    }
  }

  // Update / create translation source for user defined slide strings
  if (function_exists('i18n_string_update')) {
    nivo_slider_locale_refresh($slides);
  }

  // Create a new slide if an image was uploaded
  if ($file = file_save_upload('upload')) {

    // Store slide images in a folder named 'banner'
    $banner_folder = 'public://' . variable_get('nivo_slider_dir_name', 'banner');

    // Create the banner directory if it does not currently exist
    file_prepare_directory($banner_folder, FILE_CREATE_DIRECTORY);

    // Find information about the file
    $parts = pathinfo($file->filename);

    // Create a destination for the slide image
    $destination = $banner_folder . '/' . $parts['basename'];

    // Indicate that the slide image is permanent
    $file->status = FILE_STATUS_PERMANENT;

    // Copy the slide image into the banner folder
    $file = file_copy($file, $destination, FILE_EXISTS_RENAME);

    // Create a new slide
    $slides[] = array(
      'fid' => $file->fid,
      'title' => '',
      'description' => array(
        'value' => '',
        'format' => filter_fallback_format(),
      ),
      'url' => '',
      'visibility' => '*',
      'transition' => '',
      'weight' => 1,
      'published' => 1,
      'delete' => 0,
    );
  }

  // Sort the slides by weight
  usort($slides, 'drupal_sort_weight');

  // Save the slides
  variable_set('nivo_slider_banner_settings', $slides);
}