You are here

function views_sexy_throbber_settings_submit in Views Sexy Throbber 7.2

Submit handler for views_sexy_throbber_settings().

File

./settings_form.inc, line 180
Settings form for Views Sexy Throbber.

Code

function views_sexy_throbber_settings_submit($form, &$form_state) {

  // Include the views sexy throbber variables.
  include 'variables.inc';

  // Get image info.
  $image_info = image_get_info($user_directory . "/" . $form_state['values']['views_sexy_throbber_image']);

  // Shuld we add the "div.view" css prefix?
  $css_views_prefix = $form_state['values']['views_sexy_throbber_use_in_other_modules'] == TRUE ? '' : 'div.view ';

  // Should we perpend !important?
  $css_important = $form_state['values']['views_sexy_throbber_append_important'] == TRUE ? ' !important' : NULL;

  // Generate the CSS file.
  $css = '' . $css_views_prefix . 'div.ajax-progress {
  background: rgba(' . $form_state['values']['views_sexy_throbber_background'] . ',' . $form_state['values']['views_sexy_throbber_opacity'] . ')' . $css_important . ';
  -pie-background: rgba(' . $form_state['values']['views_sexy_throbber_background'] . ',' . $form_state['values']['views_sexy_throbber_opacity'] . ')' . $css_important . ';
  height: 100%' . $css_important . ';
  left: 0' . $css_important . ';
  position: fixed' . $css_important . ';
  top: 0' . $css_important . ';
  width: 100%' . $css_important . ';
  z-index: 9998' . $css_important . ';
}

' . $css_views_prefix . 'div.throbber {
  background: url("' . $form_state['values']['views_sexy_throbber_image'] . '") no-repeat scroll 50% 50%' . $css_important . ';
  background-color: ' . ($form_state['values']['views_sexy_throbber_image_background'] ? 'rgb(' . $form_state['values']['views_sexy_throbber_background'] . ')' : 'transparent') . '' . $css_important . ';
  border-radius: ' . ($form_state['values']['views_sexy_throbber_image_background_use_border_radius'] ? $form_state['values']['views_sexy_throbber_image_background_border_radius'] : '0') . 'px' . $css_important . ';
  height: ' . $image_info['height'] . 'px' . $css_important . ';
  left: 50%' . $css_important . ';
  margin-left: -' . $image_info['width'] * 0.5 . 'px' . $css_important . ';
  margin-top: -' . $image_info['height'] * 0.5 . 'px' . $css_important . ';
  padding: 10px' . $css_important . ';
  position: fixed' . $css_important . ';
  top: 50%' . $css_important . ';
  width: ' . $image_info['width'] . 'px' . $css_important . ';
  z-index: 9999' . $css_important . ';
}
';

  // Format the css code output and remove some unnecessary spaces.
  $css = str_replace("\t", " ", $css);

  // Write the final formated css file.
  file_unmanaged_save_data($css, $user_css_uri, FILE_EXISTS_REPLACE);

  // Exclude unnecessary elements.
  form_state_values_clean($form_state);
  foreach ($form_state['values'] as $key => $value) {
    if (is_array($value) && isset($form_state['values']['array_filter'])) {
      $value = array_keys(array_filter($value));
    }
    variable_set($key, $value);
  }
  drupal_set_message(t('The configuration options have been saved.'));
}