You are here

public function sweaver_plugin_styles::sweaver_style_enable in Sweaver 6

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

Menu callback, enable style.

File

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

Class

sweaver_plugin_styles

Code

public function sweaver_style_enable() {
  $style_id = arg(5);

  // First we check if the style has a live version
  $style = db_fetch_object(db_query('SELECT * FROM {sweaver_style} WHERE style_id = %d', $style_id));
  $update = 'style_id';
  if (!$style) {
    $style = db_fetch_object(db_query('SELECT * FROM {sweaver_style_draft} WHERE style_id = %d', $style_id));
    if (!$style) {
      drupal_not_found();
      exit;
    }

    // The "live" does not yet exist, copy the draft.
    $path = file_create_path('sweaver');
    $filenamedraft = $path . '/' . 'sweaver_' . $style->theme . '_' . $style->style_id . '_draft.css';
    $filenamelive = $path . '/' . 'sweaver_' . $style->theme . '_' . $style->style_id . '_live.css';
    file_copy($filenamedraft, $filenamelive);
    $update = array();
  }
  $style->active = 1;
  db_query('UPDATE {sweaver_style} set active = 0 WHERE theme = "%s"', $style->theme);
  drupal_write_record('sweaver_style', $style, $update);
  $this
    ->sweaver_export_file($form_state['values']['css_rendered'], 'live');
  drupal_set_message(t('Style enabled'));
  drupal_goto('admin/settings/sweaver/styles');
}