You are here

function colorizer_update_stylesheet in Colorizer 7

Create a new stylesheet by replacing color variables Basic filehandling copied from Color module Returns full path to new css file

2 calls to colorizer_update_stylesheet()
colorizer_admin_form_submit in ./colorizer.admin.inc
Helper function to submit/save a colorizer form Mostly copied from Color module
colorizer_preprocess_html in ./colorizer.module
Implements hook_preprocess_html(). Add the colorized style sheet to the site

File

./colorizer.module, line 224
Colorize your theme

Code

function colorizer_update_stylesheet($theme, $instance, $palette) {

  // Delete old files.
  $current_file = colorizer_load($instance, 'stylesheet');
  @drupal_unlink($current_file);

  // Prepare target locations for generated files.
  $id = $instance . '-' . substr(hash('sha256', serialize($palette) . microtime()), 0, 8);
  $target_path = 'public://colorizer';
  if (!is_dir($target_path)) {
    file_prepare_directory($target_path, FILE_CREATE_DIRECTORY);
    @drupal_chmod($target_path, 0777);
  }

  // ensure directory was created
  if (!is_dir($target_path)) {
    watchdog('file', 'The directory %file could not be created.', array(
      '%file' => $target_path,
    ), WATCHDOG_ERROR);
    return '';
  }
  $target_path = $target_path . '/';
  $target_file = '';
  $source_path = drupal_get_path('theme', $theme) . '/';
  $source_file = DRUPAL_ROOT . '/' . $source_path . variable_get('colorizer_cssfile', '');
  if (file_exists($source_file)) {

    // Aggregate @imports recursively for each configured top level CSS file
    // without optimization. Aggregation and optimization will be
    // handled by drupal_build_css_cache() only.
    $source_styles = drupal_load_stylesheet($source_file, FALSE);

    // Rewrite stylesheet with new colors.
    $target_styles = _colorizer_rewrite_stylesheet($palette, $source_styles);
    $target_file = $target_path . $id . '.css';
    _colorizer_save_stylesheet($target_file, $target_styles);
  }
  if (!empty($target_file)) {
    colorizer_save($instance, array(
      'stylesheet' => $target_file,
    ));
  }
  return $target_file;
}