You are here

function advagg_advagg_scan_for_changes in Advanced CSS/JS Aggregation 7.2

Implements hook_advagg_scan_for_changes().

Used to see if the responsive files inside an adaptive theme has changed.

Related topics

1 call to advagg_advagg_scan_for_changes()
advagg_advagg_changed_files in ./advagg.advagg.inc
Implements hook_advagg_changed_files().

File

./advagg.advagg.inc, line 525
Advanced CSS/JS aggregation module.

Code

function advagg_advagg_scan_for_changes($filename, $save_changes = FALSE) {

  // Skip if this file is not a css file.
  $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
  if ($ext !== 'css') {
    return FALSE;
  }

  // Skip if the file is not in an adaptive theme.
  $adaptivethemes = array();
  $themes = list_themes();
  foreach ($themes as $theme_name => $theme_values) {
    $path = variable_get('theme_' . $theme_name . '_files_directory', '');
    if (!empty($path) && strpos($filename, $path) !== FALSE) {
      $adaptivethemes[$theme_name] = $path;
    }
  }
  if (empty($adaptivethemes)) {
    return;
  }
  $file_changed = array();
  foreach ($adaptivethemes as $theme_name => $path) {

    // Set up some paths we use to get and save files.
    $path_to_responsive_css = drupal_get_path('theme', $theme_name) . '/css/';
    $path_to_panels_css = drupal_get_path('theme', 'adaptivetheme') . '/layouts/css/';

    // Map files to generated file names.
    $file_map = array(
      "{$path}/{$theme_name}.responsive.styles.css" => array(
        $path_to_responsive_css . 'responsive.custom.css',
        $path_to_responsive_css . 'responsive.smalltouch.portrait.css',
        $path_to_responsive_css . 'responsive.smartphone.portrait.css',
        $path_to_responsive_css . 'responsive.smalltouch.landscape.css',
        $path_to_responsive_css . 'responsive.smartphone.landscape.css',
        $path_to_responsive_css . 'responsive.tablet.portrait.css',
        $path_to_responsive_css . 'responsive.tablet.landscape.css',
        $path_to_responsive_css . 'responsive.desktop.css',
      ),
      "{$path}/{$theme_name}.lt-ie8.layout.css" => array(
        $path_to_panels_css . 'ie_defaults.css',
      ),
    );
    if (!isset($file_map[$filename])) {
      continue;
    }

    // See if anything has changed.
    $changes = advagg_detect_subfile_changes($filename, $file_map[$filename], 'adaptivetheme', $save_changes);
    if (!empty($changes)) {
      $file_changed[$path] = $changes;
    }
  }
  return $file_changed;
}