You are here

function advagg_aggressive_cache_conflicts in Advanced CSS/JS Aggregation 7.2

Check and see if the aggressive cache can safely be enabled.

Return value

array If there are no conflicts, this will return an empty array.

2 calls to advagg_aggressive_cache_conflicts()
advagg_admin_settings_form in ./advagg.admin.inc
Form builder; Configure advagg settings.
advagg_requirements in ./advagg.install
Implements hook_requirements().

File

./advagg.module, line 5335
Advanced CSS/JS aggregation module.

Code

function advagg_aggressive_cache_conflicts() {
  $hooks = array(
    'css_alter' => TRUE,
    'js_alter' => TRUE,
  );
  foreach ($hooks as $hook => $values) {
    $hooks[$hook] = module_implements($hook);

    // Also check themes as drupal_alter() allows for themes to alter things.
    $themes = list_themes();
    $theme_keys = array_keys($themes);
    if (!empty($theme_keys)) {
      foreach ($theme_keys as $theme_key) {
        $function = $theme_key . '_' . $hook;

        // Search loaded themes.
        if (function_exists($function)) {
          $hooks[$hook][] = $theme_key;
          continue;
        }

        // Skip disabled themes.
        if (empty($themes[$theme_key]->status)) {
          continue;
        }

        // Search enabled but not loaded themes.
        $file = dirname($themes[$theme_key]->filename) . '/template.php';
        if (file_exists($file)) {
          $contents = (string) @advagg_file_get_contents($file);
          if (stripos($contents, $function)) {
            $hooks[$hook][] = $theme_key;
          }
        }
      }
    }
  }
  $whitelist = array(
    // Core.
    //
    // locale_js_directory variable; default: languages.
    // javascript_parsed variable; default: array().
    'locale',
    // No control; same every time.
    'simpletest',
    // No control; same every time.
    'seven',
    // Popular contrib.
    //
    // No control; same every time.
    'at_commerce',
    // ais_adaptive_styles variable; Default: array().
    // ais_adaptive_styles_method; Default: 'both-max'.
    // 'ais',
    //
    // No control; same every time.
    'bluecheese',
    // drupal_static('clientside_validation_settings') array.
    // 'clientside_validation',
    //
    // version_compare(VERSION, '7.14', '<').
    'conditional_fields',
    // _css_injector_load_rule() function.
    // Changes the weight of all files added in init so no special handling.
    // 'css_injector',
    //
    // disable_css_ . $theme . _all variable; default: FALSE.
    // disable_css_ . $theme . _modules; default: array().
    // disable_css_ . $theme . _files; default: array().
    // 'disable_css',
    //
    // Empty call; commented code is same every time.
    'elfinder',
    // excluded_css_custom variable; Default: ''.
    // excluded_javascript_custom variable; Default: ''.
    // 'excluded',
    //
    // No control; same every time.
    'fences',
    // jqmulti_jquery_path() function.
    // jqmulti_get_files() function.
    // jqmulti_load_always variable; Default: FALSE.
    // 'jqmulti',
    //
    // No control; same every time.
    'jquery_dollar',
    // labjs_suppress() function.
    'labjs_js',
    // Empty call.
    'panopoly_core',
    // speedy_js_production variable; Default: TRUE.
    'speedy',
    // logintoboggan_validating_id() function.
    'logintoboggan',
  );

  // Allow other modules to modify the $whitelist.
  // Call hook_advagg_aggressive_cache_conflicts_alter()
  drupal_alter('advagg_aggressive_cache_conflicts', $whitelist);
  $questionable_modules = array();
  foreach ($hooks as $hook => $modules) {
    foreach ($modules as $key => $module) {

      // Anything from advagg is ok.
      if (strpos($module, 'advagg') === 0 || strpos($module, '_advagg') === 0) {
        unset($modules[$key]);
        continue;
      }

      // Remove known modules that should work with aggressive caching.
      if (in_array($module, $whitelist)) {
        unset($modules[$key]);
      }
      else {
        $questionable_modules[$module] = $module;
      }
    }
  }
  return $questionable_modules;
}