You are here

public function sweaver_plugin_styles::sweaver_autosave in Sweaver 7

Same name and namespace in other branches
  1. 6 plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc \sweaver_plugin_styles::sweaver_autosave()

Autosave post.

File

plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc, line 806
Styles plugin.

Class

sweaver_plugin_styles

Code

public function sweaver_autosave() {

  // Prevent caching of JS output.
  $GLOBALS['conf']['cache'] = FALSE;

  // Prevent Devel from hi-jacking our output in any case.
  $GLOBALS['devel_shutdown'] = FALSE;

  // Load CTools object cache.
  ctools_include('object-cache');
  $sweaver = Sweaver::get_instance();
  $working_style = $sweaver
    ->get_current_style();

  // Save current styling.
  $style = new stdClass();
  $style->style_id = 0;
  $style->style = t('Temporary');
  $style->css = isset($_POST['css']) ? $_POST['css'] : $working_style->css;
  $style->customcss = isset($_POST['customcss']) ? $_POST['customcss'] : $working_style->customcss;
  $style->palette = isset($_POST['palette']) ? $_POST['palette'] : $working_style->palette;

  // Get the themesettings if applicable and overwrite style id & style name.
  if (isset($working_style->themesettings)) {
    $style->theme = $working_style->theme;
    $style->themesettings = $working_style->themesettings;
  }

  // An image might have been uploaded by a managed_file field, permanant status needs to be set up
  if (!empty($_POST['managed_file_fid'])) {
    $fid = filter_input(INPUT_POST, 'managed_file_fid', FILTER_SANITIZE_NUMBER_INT);
    if ($fid > 0) {
      $file = file_load($fid);
      $file->status = FILE_STATUS_PERMANENT;
      $file->description = $file->filename;
      file_save($file);
      drupal_write_record('sweaver_image', $file);
    }
  }

  // Save to CTools object cache.
  ctools_object_cache_set('sweaver-styling', 'sweaver-styling', $style);

  // Set session variable.
  sweaver_session(TRUE, 'sweaver_temp');

  // Exit.
  exit(drupal_json_encode(array(
    'error' => 0,
  )));
}