You are here

function ctools_stylizer_build_style in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/stylizer.inc \ctools_stylizer_build_style()

Build the files for a stylizer given the proper settings.

1 call to ctools_stylizer_build_style()
ctools_stylizer_add_css in includes/stylizer.inc
Add the necessary CSS for a stylizer plugin to the page.

File

includes/stylizer.inc, line 94
Create customized CSS and images from palettes created by user input.

Code

function ctools_stylizer_build_style($plugin, $settings, $add_css = FALSE) {
  $path = ctools_stylizer_get_image_path($plugin, $settings);
  if (!$path) {
    return;
  }
  $replacements = array();

  // Set up palette conversions
  foreach ($settings['palette'] as $key => $color) {
    $replacements['%' . $key] = $color;
  }

  // Process image actions:
  if (!empty($plugin['actions'])) {
    $processor = new ctools_stylizer_image_processor();
    $processor
      ->execute($path, $plugin, $settings);

    // @todo -- there needs to be an easier way to get at this.
    //  dsm($processor->message_log);
    // Add filenames to our conversions.
  }

  // Convert and write the CSS file.
  $css = file_get_contents($plugin['path'] . '/' . $plugin['css']);

  // Replace %style keyword with our generated class name.
  // @todo We need one more unique identifier I think.
  $class = ctools_stylizer_get_css_class($plugin, $settings);
  $replacements['%style'] = '.' . $class;
  if (!empty($processor) && !empty($processor->paths)) {
    foreach ($processor->paths as $file => $image) {
      $replacements[$file] = file_create_url($image);
    }
  }
  if (!empty($plugin['build']) && function_exists($plugin['build'])) {
    $plugin['build']($plugin, $settings, $css, $replacements);
  }
  $css = strtr($css, $replacements);
  ctools_include('css');
  $filename = ctools_css_store(ctools_stylizer_get_css_id($plugin, $settings), $css, FALSE);
  if ($add_css) {
    drupal_add_css($filename);
  }
}