function advagg_validator_test_css_files

cis7 advagg_validator.inc advagg_validator_test_css_files($files, $options = array())
cle7 advagg_validator.inc advagg_validator_test_css_files($files, $options = array())
elmsmedia7 advagg_validator.inc advagg_validator_test_css_files($files, $options = array())
icor7 advagg_validator.inc advagg_validator_test_css_files($files, $options = array())
meedjum_blog7 advagg_validator.inc advagg_validator_test_css_files($files, $options = array())
mooc7 advagg_validator.inc advagg_validator_test_css_files($files, $options = array())

Test all given files with the w3c validator.

Return value

array An array of files with the result from the w3c validator.

6 calls to advagg_validator_test_css_files()
advagg_validator_admin_test_advagg_css_directory_callback in sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
Display file info via ajax callback.
advagg_validator_admin_test_advagg_css_directory_submit in sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
Display file info in a drupal message.
advagg_validator_admin_test_advagg_css_subdirectory_callback in sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
Display file info via ajax callback.
advagg_validator_admin_test_advagg_css_subdirectory_submit in sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
Display file info in a drupal message.
advagg_validator_test_advagg_css in sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.inc
Test all css files used by AdvAgg.

... See full list

File

sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.inc, line 69
Advanced aggregation validation module.

Code

function advagg_validator_test_css_files($files, $options = array()) {
  $output = array();
  foreach ($files as $filename) {
    // Skip missing files.
    if (!file_exists($filename)) {
      continue;
    }

    $file_contents = file_get_contents($filename);
    $lines = file($filename);
    $filename_hash = drupal_hash_base64($filename);
    $content_hash = drupal_hash_base64($file_contents);
    $update = FALSE;

    // See if this file needs to be scanned.
    $file_ok = db_select('advagg_validator', 'av')->fields('av', array('content_hash', 'data'))->condition('filename_hash', $filename_hash)->condition('filetype', 'css')->execute()->fetchAllKeyed();
    if (!empty($file_ok)) {
      foreach ($file_ok as $content_hash_db => $serialized_data) {
        if ($content_hash_db == $content_hash) {
          $output[$filename] = unserialize($serialized_data);
          continue 2;
        }
      }
      $update = TRUE;
    }

    // Run jigsaw.w3.org validator.
    $output[$filename]['jigsaw.w3.org'] = advagg_validator_test_css_file_w3c($filename, $options);

    // Get extra context for errors.
    if (!empty($output[$filename]['jigsaw.w3.org']['errors'])) {
      foreach ($output[$filename]['jigsaw.w3.org']['errors'] as $key => &$value) {
        if (isset($value['line'])) {
          $value['linedata'] = $lines[($value['line'] - 1)];
          if (strlen($value['linedata']) > 512) {
            unset($value['linedata']);
          }
        }
      }
    }
    if (!empty($output[$filename]['jigsaw.w3.org']['warnings'])) {
      foreach ($output[$filename]['jigsaw.w3.org']['warnings'] as $key => &$value) {
        if (isset($value['line'])) {
          $value['linedata'] = $lines[$value['line'] - 1];
          if (strlen($value['linedata']) > 512) {
            unset($value['linedata']);
          }
        }
      }
    }

    // Save data.
    if (empty($output[$filename]['jigsaw.w3.org']['error'])) {
      $record = array(
        'filename' => $filename,
        'filename_hash' => $filename_hash,
        'content_hash' => $content_hash,
        'filetype' => 'css',
        'data' => $output[$filename],
      );
      if ($update) {
        drupal_write_record('advagg_validator', $record, array('filename_hash'));
      }
      else {
        drupal_write_record('advagg_validator', $record);
      }
    }
  }
  return $output;
}