Given a filename return the type and 2 hashes.

Paramètres

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 dans ./advagg.admin.inc
Get detailed info about the given filename.
advagg_delete_files_if_orphaned dans ./advagg.cache.inc
Given an array of files remove that file if there is no associated db record.
advagg_delete_files_if_stale dans ./advagg.cache.inc
Given an array of files remove that file if atime is grater than 30 days.
advagg_install_get_first_advagg_file dans ./advagg.install
Given a advagg path this will return the first aggregate it can find.
advagg_missing_create_file dans ./advagg.missing.inc
Given a filename create that file.

... See full list

Fichier

./advagg.missing.inc, line 648

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,
    );
}