Save a string to the specified destination. Verify that file size is not zero.

Paramètres

$data: A string containing the contents of the file.

$dest: A string containing the destination location.

Return value

Boolean indicating if the file save was successful.

1 string reference to 'advagg_js_compress_file_saver'
advagg_js_compress_init dans advagg_js_compress/advagg_js_compress.module
Implements hook_init().

Fichier

advagg_js_compress/advagg_js_compress.module, line 478

Code

function advagg_js_compress_file_saver($data, $dest, $force, $type) {
    if ($type == 'css') {
        return advagg_file_saver($data, $dest, $force, $type);
    }
    if (!variable_get('advagg_gzip_compression', ADVAGG_GZIP_COMPRESSION) || !extension_loaded('zlib')) {
        return advagg_file_saver($data, $dest, $force, $type);
    }
    // Get file save function
    $file_save_data = 'file_save_data';
    $custom_path = variable_get('advagg_custom_files_dir', ADVAGG_CUSTOM_FILES_DIR);
    if (!empty($custom_path)) {
        $file_save_data = 'advagg_file_save_data';
    }
    // Gzip first.
    $gzip_dest = $dest . '.gz';
    advagg_clearstatcache(TRUE, $gzip_dest);
    if (!file_exists($gzip_dest) || $force) {
        $gzip_data = gzencode($data, 9, FORCE_GZIP);
        if (!$file_save_data($gzip_data, $gzip_dest, FILE_EXISTS_REPLACE)) {
            return FALSE;
        }
        // Make sure filesize is not zero.
        advagg_clearstatcache(TRUE, $gzip_dest);
        if (@filesize($gzip_dest) == 0 && !empty($gzip_data)) {
            if (!$file_save_data($gzip_data, $gzip_dest, FILE_EXISTS_REPLACE)) {
                return FALSE;
            }
            advagg_clearstatcache(TRUE, $gzip_dest);
            if (@filesize($gzip_dest) == 0 && !empty($gzip_data)) {
                // Filename is bad, create a new one next time.
                file_delete($gzip_dest);
                return FALSE;
            }
        }
    }
    // Use packer on JS data.
    advagg_js_compress_jspacker($data);
    // Write File.
    if (!$file_save_data($data, $dest, FILE_EXISTS_REPLACE)) {
        return FALSE;
    }
    // Make sure filesize is not zero.
    advagg_clearstatcache(TRUE, $dest);
    if (@filesize($dest) == 0 && !empty($data)) {
        if (!$file_save_data($data, $dest, FILE_EXISTS_REPLACE)) {
            return FALSE;
        }
        advagg_clearstatcache(TRUE, $dest);
        if (@filesize($dest) == 0 && !empty($data)) {
            // Filename is bad, create a new one next time.
            file_delete($dest);
            return FALSE;
        }
    }
    // Make sure .htaccess file exists.
    advagg_htaccess_check_generate($dest);
    cache_set($dest, REQUEST_TIME, 'cache_advagg', CACHE_PERMANENT);
    return TRUE;
}