Same name in other branches
- 7.x-1.x advagg.module \advagg_htaccess_check_generate()
Generate .htaccess rules and place them in advagg dir.
Paramètres
array $files_to_save: Array of files that where saved.
string $type: String: css or js.
bool $force: (Optional) force recreate the .htaccess file.
Return value
array Empty array if not errors happened, list of errors if the write had any issues.
8 calls to advagg_htaccess_check_generate()
- advagg_admin_operations_form dans ./
advagg.admin.inc - Form builder; Do advagg operations.
- advagg_admin_regenerate_htaccess_button dans ./
advagg.admin.inc - Recreate the advagg htaccess files.
- advagg_admin_settings_form_submit dans ./
advagg.admin.inc - Clear out the advagg cache bin when the save configuration button is pressed.
- advagg_admin_settings_form_submit dans ./
advagg.admin.inc - Clear out the advagg cache bin when the save configuration button is pressed.
- advagg_install_update_htaccess dans ./
advagg.install - Callback to delete files if size == 0 and modified more than 60 seconds ago.
5 string references to 'advagg_htaccess_check_generate'
- advagg.module dans ./
advagg.module - Advanced CSS/JS aggregation module.
- advagg_admin_operations_form dans ./
advagg.admin.inc - Form builder; Do advagg operations.
- advagg_admin_settings_form_submit dans ./
advagg.admin.inc - Clear out the advagg cache bin when the save configuration button is pressed.
- advagg_install_update_htaccess dans ./
advagg.install - Callback to delete files if size == 0 and modified more than 60 seconds ago.
- advagg_missing_create_file dans ./
advagg.missing.inc - Given a filename create that file.
Fichier
-
./
advagg.missing.inc, line 492
Code
function advagg_htaccess_check_generate(array $files_to_save, $type, $force = FALSE) {
list($css_path, $js_path) = advagg_get_root_files_dir();
$content_type = $type;
if ($content_type === 'js') {
$content_type = 'javascript';
$advagg_dir = basename($js_path[1]);
}
elseif ($content_type === 'css') {
$advagg_dir = basename($css_path[1]);
}
$type_upper = strtoupper($type);
$data = "\n";
// Some hosting companies do not allow "FollowSymLinks" but will support
// "SymLinksIfOwnerMatch".
if (variable_get('advagg_htaccess_symlinksifownermatch', ADVAGG_HTACCESS_SYMLINKSIFOWNERMATCH)) {
$data .= "Options +SymLinksIfOwnerMatch\n";
}
else {
$data .= "Options +FollowSymLinks\n";
}
if ($GLOBALS['base_path'] !== '/') {
$data .= "\n ErrorDocument 404 {$GLOBALS['base_path']}index.php\n";
}
// See if RewriteBase is needed.
$advagg_htaccess_rewritebase = trim(variable_get('advagg_htaccess_rewritebase', ADVAGG_HTACCESS_REWRITEBASE));
if (!empty($advagg_htaccess_rewritebase) && !empty($advagg_dir)) {
$rewrite_base_rule = str_replace('//', '/', $advagg_htaccess_rewritebase . '/' . $advagg_dir);
$data .= "RewriteBase {$rewrite_base_rule}\n";
}
$data .= "\n";
$data .= "<IfModule mod_rewrite.c>\n";
$data .= " RewriteEngine on\n";
$data .= " <IfModule mod_headers.c>\n";
$data .= " # Serve brotli compressed {$type_upper} files if they exist and the client accepts br.\n";
$data .= " RewriteCond %{HTTP:Accept-encoding} br\n";
$data .= " RewriteCond %{REQUEST_FILENAME}\\.br -s\n";
$data .= " RewriteRule ^(.*)\\.{$type} " . '$1' . "\\.{$type}\\.br [QSA]\n";
if ($type === 'css') {
$data .= " RewriteRule \\.{$type}\\.br\$ - [T=text/{$content_type},E=no-gzip:1]\n";
}
else {
$data .= " RewriteRule \\.{$type}\\.br\$ - [T=application/{$content_type},E=no-gzip:1]\n";
}
$data .= "\n";
$data .= " <FilesMatch \"\\.{$type}\\.br\$\">\n";
$data .= " # Serve correct encoding type.\n";
$data .= " Header set Content-Encoding br\n";
$data .= " # Force proxies to cache gzipped & non-gzipped css/js files separately.\n";
$data .= " Header append Vary Accept-Encoding\n";
$data .= " </FilesMatch>\n";
$data .= "\n";
$data .= " # Serve gzip compressed {$type_upper} files if they exist and the client accepts gzip.\n";
$data .= " RewriteCond %{HTTP:Accept-encoding} gzip\n";
$data .= " RewriteCond %{REQUEST_FILENAME}\\.gz -s\n";
$data .= " RewriteRule ^(.*)\\.{$type} " . '$1' . "\\.{$type}\\.gz [QSA]\n";
if ($type === 'css') {
$data .= " RewriteRule \\.{$type}\\.gz\$ - [T=text/{$content_type},E=no-gzip:1]\n";
}
else {
$data .= " RewriteRule \\.{$type}\\.gz\$ - [T=application/{$content_type},E=no-gzip:1]\n";
}
$data .= "\n";
$data .= " <FilesMatch \"\\.{$type}\\.gz\$\">\n";
$data .= " # Serve correct encoding type.\n";
$data .= " Header set Content-Encoding gzip\n";
$data .= " # Force proxies to cache gzipped & non-gzipped css/js files separately.\n";
$data .= " Header append Vary Accept-Encoding\n";
$data .= " </FilesMatch>\n";
$data .= " </IfModule>\n";
$data .= "</IfModule>\n";
$data .= "\n";
$data .= "<FilesMatch \"^{$type}" . ADVAGG_SPACE . "[A-Za-z0-9-_]{43}" . ADVAGG_SPACE . "[A-Za-z0-9-_]{43}" . ADVAGG_SPACE . "[A-Za-z0-9-_]{43}.{$type}(\\.gz|\\.br)?\">\n";
$data .= " # No mod_headers. Apache module headers is not enabled.\n";
$data .= " <IfModule !mod_headers.c>\n";
$data .= " # No mod_expires. Apache module expires is not enabled.\n";
$data .= " <IfModule !mod_expires.c>\n";
$data .= " # Use ETags.\n";
$data .= " FileETag MTime Size\n";
$data .= " </IfModule>\n";
$data .= " </IfModule>\n";
$data .= "\n";
$data .= " # Use Expires Directive if apache module expires is enabled.\n";
$data .= " <IfModule mod_expires.c>\n";
$data .= " # Do not use ETags.\n";
$data .= " FileETag None\n";
$data .= " # Enable expirations.\n";
$data .= " ExpiresActive On\n";
$data .= " # Cache all aggregated {$type} files for 52 weeks after access (A).\n";
$data .= " ExpiresDefault A31449600\n";
$data .= " </IfModule>\n";
$data .= "\n";
$data .= " # Use Headers Directive if apache module headers is enabled.\n";
$data .= " <IfModule mod_headers.c>\n";
$data .= " # Do not use etags for cache validation.\n";
$data .= " Header unset ETag\n";
$data .= " # Serve correct content type.\n";
if ($type === 'css') {
$data .= " Header set Content-Type text/{$content_type}\n";
}
else {
$data .= " Header set Content-Type application/{$content_type}\n";
}
$data .= " <IfModule !mod_expires.c>\n";
$data .= " # Set a far future Cache-Control header to 52 weeks.\n";
if (variable_get('advagg_resource_hints_use_immutable', ADVAGG_RESOURCE_HINTS_USE_IMMUTABLE)) {
$data .= " Header set Cache-Control \"max-age=31449600, public, immutable\"\n";
}
else {
$data .= " Header set Cache-Control \"max-age=31449600, public\"\n";
}
$data .= " </IfModule>\n";
$data .= " <IfModule mod_expires.c>\n";
if (variable_get('advagg_resource_hints_use_immutable', ADVAGG_RESOURCE_HINTS_USE_IMMUTABLE)) {
$data .= " Header append Cache-Control \"public, immutable\"\n";
}
else {
$data .= " Header append Cache-Control \"public\"\n";
}
$data .= " </IfModule>\n";
$data .= " </IfModule>\n";
if ($type === 'css') {
$data .= " ForceType text/{$content_type}\n";
}
else {
$data .= " ForceType application/{$content_type}\n";
}
$data .= "</FilesMatch>\n";
$errors = array();
foreach (array_keys($files_to_save) as $uri) {
$dir = dirname($uri);
$htaccess_file = $dir . '/.htaccess';
if (!$force && file_exists($htaccess_file)) {
continue;
}
$errors = advagg_save_data($htaccess_file, $data, $force);
}
return $errors;
}