You are here

function skinr_preprocess in Skinr 6

Same name and namespace in other branches
  1. 8.2 skinr.module \skinr_preprocess()
  2. 6.2 skinr.module \skinr_preprocess()
  3. 7.2 skinr.module \skinr_preprocess()

Implementation of hook_preprocess().

File

./skinr.module, line 310

Code

function skinr_preprocess(&$vars, $hook) {

  // Fix for update script.
  if (defined('MAINTENANCE_MODE')) {
    return;
  }
  static $data = NULL;

  // Caching the data returned from the following functions is reported to
  // improve performance.
  if (is_null($data)) {

    // Let's make sure this has been run. There have been problems where other
    // modules implement a theme function in their hook_init(), so we make doubly
    // sure that the includes are included.
    skinr_init();
    $data['current_theme'] = skinr_current_theme();
    $data['skinr_data'] = skinr_fetch_data();
    $data['info'] = skinr_process_info_files();
    $data['theme_registry'] = theme_get_registry();
  }

  // Add any base themes if they exist for the current theme.
  $theme_list = list_themes();
  $themes = array();
  if (isset($theme_list[$data['current_theme']]->info['base theme'])) {
    $themes = array_keys(system_find_base_themes($theme_list, $data['current_theme']));
  }

  // Add the current theme.
  $themes[] = $data['current_theme'];
  $original_hook = $hook;
  if (isset($data['theme_registry'][$hook]['original hook'])) {
    $original_hook = $data['theme_registry'][$hook]['original hook'];
  }
  $vars['skinr'] = '';
  foreach ($data['skinr_data'] as $module => $settings) {
    if (!empty($settings['preprocess'][$original_hook])) {
      $preprocess_settings = $settings['preprocess'][$original_hook];
      $key = skinr_handler('preprocess_index_handler', 'preprocess', $preprocess_settings['index_handler'], $vars);
      if (!empty($key)) {
        if (is_array($key)) {
          $style = array();
          foreach ($key as $keykey) {
            $style = skinr_get(NULL, $module, $keykey) + $style;
          }
        }
        else {
          $style = skinr_get(NULL, $module, $key);
        }
        foreach ($style as $skin => $classes) {

          // Add custom CSS files.
          if (!empty($data['info'][$data['current_theme']]['skins'][$skin]['stylesheets'])) {
            foreach ($data['info'][$data['current_theme']]['skins'][$skin]['stylesheets'] as $media => $stylesheets) {
              foreach ($stylesheets as $stylesheet) {
                _skinr_add_file($stylesheet, $themes, 'css', $media);
              }
            }
          }

          // Add custom JS files.
          if (isset($data['info'][$data['current_theme']]['skins'][$skin]['scripts'])) {
            foreach ($data['info'][$data['current_theme']]['skins'][$skin]['scripts'] as $script) {
              _skinr_add_file($script, $themes, 'js');
            }
          }
        }

        // Add template files.
        if (!empty($style['_template'])) {
          $vars['template_files'][] = $style['_template'];
          unset($style['_template']);
        }
        $vars['skinr'] = skinr_style_array_to_string($style);
      }
    }
  }
}