Given a list of files, grab their contents and glue it into one big string.

Paramètres

array $files: Array of filenames.

array $aggregate_settings: Array of settings.

string $aggregate_filename: Filename of the aggregeate.

Return value

string String containing all the files.

3 calls to advagg_get_js_aggregate_contents()
advagg_does_js_start_with_use_strict dans ./advagg.inc
Given a js string, see if "use strict"; is the first thing ran.
advagg_generate_filesize_processed dans ./advagg.inc
Given a filename calculate the processed filesize.
advagg_save_aggregate dans ./advagg.missing.inc
Save an aggregate given a filename, the files included in it, and the type.

Fichier

./advagg.missing.inc, line 1029

Code

function advagg_get_js_aggregate_contents(array $files, array $aggregate_settings, $aggregate_filename = '') {
    $write_aggregate = TRUE;
    $data = '';
    module_load_include('inc', 'advagg', 'advagg');
    $info_on_files = advagg_load_files_info_into_static_cache(array_keys($files));
    if (!empty($files)) {
        // Build aggregate JS file.
        foreach ($files as $filename => $settings) {
            $contents = '';
            // Append a ';' and a newline after each JS file to prevent them from
            // running together. Also close any comment blocks.
            if (is_readable($filename)) {
                $file_contents = (string) @advagg_file_get_contents($filename);
                $file_contents_hash = drupal_hash_base64($file_contents);
                $cid = 'advagg:file:' . advagg_drupal_hash_base64($filename);
                if (empty($info_on_files[$cid]['content_hash'])) {
                    $results = db_select('advagg_files', 'af')->fields('af', array(
                        'content_hash',
                        'filename_hash',
                    ))
                        ->condition('filename', $filename)
                        ->execute();
                    foreach ($results as $row) {
                        $info_on_files['advagg:file:' . $row->filename_hash]['content_hash'] = $row->content_hash;
                    }
                }
                if (isset($info_on_files[$cid]['content_hash']) && $info_on_files[$cid]['content_hash'] !== $file_contents_hash) {
                    // If the content hash doesn't match don't write the file.
                    $write_aggregate = advagg_missing_file_not_readable($filename, $aggregate_filename, FALSE);
                }
                // Make sure that the file is ended properly.
                $file_contents = trim($file_contents);
                if (!empty($file_contents)) {
                    $file_contents .= "\n;/*})'\"*/\n";
                }
                if (variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL) < 0) {
                    $file_contents .= "/* Above code came from {$filename} */\n\n";
                }
                $contents .= $file_contents;
            }
            else {
                // File is not readable.
                $write_aggregate = advagg_missing_file_not_readable($filename, $aggregate_filename, TRUE);
            }
            // Allow other modules to modify this files contents.
            // Call hook_advagg_get_js_file_contents_alter().
            if (empty($aggregate_settings['settings']['no_alters'])) {
                drupal_alter('advagg_get_js_file_contents', $contents, $filename, $aggregate_settings);
            }
            // Make sure that the file is ended properly.
            $contents = trim($contents);
            if (!empty($contents)) {
                $contents .= ";/*})'\"*/\n";
            }
            $data .= $contents;
        }
    }
    // Allow other modules to modify this aggregates contents.
    // Call hook_advagg_get_js_aggregate_contents_alter().
    if (empty($aggregate_settings['settings']['no_alters'])) {
        drupal_alter('advagg_get_js_aggregate_contents', $data, $files, $aggregate_settings);
    }
    return array(
        $data,
        $write_aggregate,
    );
}