You are here

function designkit_preprocess_page in DesignKit 6

Same name and namespace in other branches
  1. 7 designkit.module \designkit_preprocess_page()

Turn design choices into theme variables.

File

./designkit.module, line 24

Code

function designkit_preprocess_page(&$vars) {
  $info = designkit_get_info();
  $color = !empty($info['designkit']['color']) ? variable_get('designkit_color', array()) : array();
  $image = !empty($info['designkit']['image']) ? variable_get('designkit_image', array()) : array();

  // Clear out stale values for image keys. This prevents themes from
  // getting unexpected values if no images have been set.
  if (!empty($info['designkit']['image'])) {
    foreach (array_keys($info['designkit']['image']) as $name) {
      if (isset($vars[$name])) {
        unset($vars[$name]);
      }
    }
  }

  // Process images array into an array of filepaths & add processed
  // version to page template.
  foreach ($image as $name => $fid) {
    $file = db_fetch_object(db_query('SELECT * FROM {files} f WHERE f.fid = %d', $fid));
    if ($file && $file->filepath && file_exists($file->filepath)) {
      $image[$name] = $file->filepath;
      $vars[$name] = theme('designkit_image', $name, $file->filepath);
    }
    else {
      unset($image[$name]);
    }
  }

  // Generate CSS styles.
  if ($image || array_filter($color, 'designkit_valid_color')) {

    // Add in designkit styles.
    $vars['body_classes'] .= " designkit";

    // Add styles.
    $styles = theme('designkit', $color, $image);

    // Provide in separate variable for themes that reset or blow away styles.
    $vars['styles'] .= $styles;
    $vars['designkit'] = $styles;
  }
}