You are here

function advagg_get_hashes_from_filename in Advanced CSS/JS Aggregation 7.2

Given a filename return the type and 2 hashes.

Parameters

string $filename: Just the filename no path information.

bool $skip_hash_settings: Allows for the skipping of db lookup for required file hooks.

Return value

mixed On failure a string saying why it failed. On success array($ext, $aggregate_hash, $files_hash).

7 calls to advagg_get_hashes_from_filename()
advagg_admin_get_file_info in ./advagg.admin.inc
Get detailed info about the given filename.
advagg_delete_files_if_orphaned in ./advagg.cache.inc
Given an array of files remove that file if there is no associated db record.
advagg_delete_files_if_stale in ./advagg.cache.inc
Given an array of files remove that file if atime is grater than 30 days.
advagg_install_get_first_advagg_file in ./advagg.install
Given a advagg path this will return the first aggregate it can find.
advagg_missing_create_file in ./advagg.missing.inc
Given a filename create that file.

... See full list

File

./advagg.missing.inc, line 648
Advanced CSS/JS aggregation module.

Code

function advagg_get_hashes_from_filename($filename, $skip_hash_settings = FALSE) {

  // Verify requested filename has the correct pattern.
  if (!advagg_match_file_pattern($filename)) {
    return t('Wrong pattern.');
  }

  // Get the extension.
  $ext = substr($filename, strpos($filename, '.', 131 + strlen(ADVAGG_SPACE) * 3) + 1);

  // Set extraction points.
  if ($ext === 'css') {
    $aggregate_filenames_start = 3 + strlen(ADVAGG_SPACE);
    $aggregate_contents_start = 46 + strlen(ADVAGG_SPACE) * 2;
    $hooks_hashes_start = 89 + strlen(ADVAGG_SPACE) * 3;
  }
  elseif ($ext === 'js') {
    $aggregate_filenames_start = 2 + strlen(ADVAGG_SPACE);
    $aggregate_contents_start = 45 + strlen(ADVAGG_SPACE) * 2;
    $hooks_hashes_start = 88 + strlen(ADVAGG_SPACE) * 3;
  }
  else {
    return t('Wrong file type.');
  }

  // Extract info from wanted filename.
  $aggregate_filenames_hash = substr($filename, $aggregate_filenames_start, 43);
  $aggregate_contents_hash = substr($filename, $aggregate_contents_start, 43);
  $hooks_hashes_value = substr($filename, $hooks_hashes_start, 43);
  $aggregate_settings = array();
  if (!$skip_hash_settings) {

    // Verify that the hooks hashes is valid.
    $aggregate_settings = advagg_get_hash_settings($hooks_hashes_value);
    if (empty($aggregate_settings)) {
      if (!variable_get('advagg_weak_file_verification', ADVAGG_WEAK_FILE_VERIFICATION)) {
        return t('Bad hooks hashes value.');
      }
      elseif (variable_get('advagg_debug', ADVAGG_DEBUG) >= 2) {
        watchdog('advagg-debug', 'File @filename has an empty aggregate_settings variable; the 3rd hash is incorrect.', array(
          '@filename' => $filename,
        ), WATCHDOG_DEBUG);
      }
    }
  }
  return array(
    $ext,
    $aggregate_filenames_hash,
    $aggregate_contents_hash,
    $aggregate_settings,
  );
}