Applied adapted Drupal core patch #572516 for sites with mixed public and private files
This commit is contained in:
parent
75c72c4cbb
commit
5c5aaddc78
6 changed files with 35 additions and 27 deletions
|
@ -52,6 +52,11 @@ $conf = array(
|
||||||
// Site main values:
|
// Site main values:
|
||||||
'site_name' => 'My SuiteDesk site',
|
'site_name' => 'My SuiteDesk site',
|
||||||
|
|
||||||
|
// Files directories (private, public and temp):
|
||||||
|
'file_directory_path' => '../files/default',
|
||||||
|
'file_dirpublic_path' => 'files/default',
|
||||||
|
'file_directory_temp' => '/tmp',
|
||||||
|
|
||||||
// Social links:
|
// Social links:
|
||||||
# 'social_website' => 'http://www.example.com',
|
# 'social_website' => 'http://www.example.com',
|
||||||
# 'social_rss' => 'http://www.example.com/feed',
|
# 'social_rss' => 'http://www.example.com/feed',
|
||||||
|
|
|
@ -1926,8 +1926,8 @@ function drupal_get_css($css = NULL) {
|
||||||
$no_theme_preprocess = '';
|
$no_theme_preprocess = '';
|
||||||
|
|
||||||
$preprocess_css = (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
|
$preprocess_css = (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
|
||||||
$directory = file_directory_path();
|
$directory = file_directory_path(TRUE);
|
||||||
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
|
$is_writable = is_dir($directory) && is_writable($directory);
|
||||||
|
|
||||||
// A dummy query-string is added to filenames, to gain control over
|
// A dummy query-string is added to filenames, to gain control over
|
||||||
// browser-caching. The string changes on every update or full cache
|
// browser-caching. The string changes on every update or full cache
|
||||||
|
@ -2002,7 +2002,7 @@ function drupal_build_css_cache($types, $filename) {
|
||||||
$data = '';
|
$data = '';
|
||||||
|
|
||||||
// Create the css/ within the files folder.
|
// Create the css/ within the files folder.
|
||||||
$csspath = file_create_path('css');
|
$csspath = file_create_path('css', TRUE);
|
||||||
file_check_directory($csspath, FILE_CREATE_DIRECTORY);
|
file_check_directory($csspath, FILE_CREATE_DIRECTORY);
|
||||||
|
|
||||||
if (!file_exists($csspath .'/'. $filename)) {
|
if (!file_exists($csspath .'/'. $filename)) {
|
||||||
|
@ -2028,7 +2028,7 @@ function drupal_build_css_cache($types, $filename) {
|
||||||
$data = implode('', $matches[0]) . $data;
|
$data = implode('', $matches[0]) . $data;
|
||||||
|
|
||||||
// Create the CSS file.
|
// Create the CSS file.
|
||||||
file_save_data($data, $csspath .'/'. $filename, FILE_EXISTS_REPLACE);
|
file_save_data($data, $csspath .'/'. $filename, FILE_EXISTS_REPLACE, TRUE);
|
||||||
}
|
}
|
||||||
return $csspath .'/'. $filename;
|
return $csspath .'/'. $filename;
|
||||||
}
|
}
|
||||||
|
@ -2182,7 +2182,7 @@ function _drupal_load_stylesheet($matches) {
|
||||||
* Delete all cached CSS files.
|
* Delete all cached CSS files.
|
||||||
*/
|
*/
|
||||||
function drupal_clear_css_cache() {
|
function drupal_clear_css_cache() {
|
||||||
file_scan_directory(file_create_path('css'), '.*', array('.', '..', 'CVS'), 'file_delete', TRUE);
|
file_scan_directory(file_create_path('css', TRUE), '.*', array('.', '..', 'CVS'), 'file_delete', TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2333,8 +2333,8 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
|
||||||
$no_preprocess = array('core' => '', 'module' => '', 'theme' => '');
|
$no_preprocess = array('core' => '', 'module' => '', 'theme' => '');
|
||||||
$files = array();
|
$files = array();
|
||||||
$preprocess_js = (variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
|
$preprocess_js = (variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
|
||||||
$directory = file_directory_path();
|
$directory = file_directory_path(TRUE);
|
||||||
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
|
$is_writable = is_dir($directory) && is_writable($directory);
|
||||||
|
|
||||||
// A dummy query-string is added to filenames, to gain control over
|
// A dummy query-string is added to filenames, to gain control over
|
||||||
// browser-caching. The string changes on every update or full cache
|
// browser-caching. The string changes on every update or full cache
|
||||||
|
@ -2535,7 +2535,7 @@ function drupal_build_js_cache($files, $filename) {
|
||||||
$contents = '';
|
$contents = '';
|
||||||
|
|
||||||
// Create the js/ within the files folder.
|
// Create the js/ within the files folder.
|
||||||
$jspath = file_create_path('js');
|
$jspath = file_create_path('js', TRUE);
|
||||||
file_check_directory($jspath, FILE_CREATE_DIRECTORY);
|
file_check_directory($jspath, FILE_CREATE_DIRECTORY);
|
||||||
|
|
||||||
if (!file_exists($jspath .'/'. $filename)) {
|
if (!file_exists($jspath .'/'. $filename)) {
|
||||||
|
@ -2548,7 +2548,7 @@ function drupal_build_js_cache($files, $filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the JS file.
|
// Create the JS file.
|
||||||
file_save_data($contents, $jspath .'/'. $filename, FILE_EXISTS_REPLACE);
|
file_save_data($contents, $jspath .'/'. $filename, FILE_EXISTS_REPLACE, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $jspath .'/'. $filename;
|
return $jspath .'/'. $filename;
|
||||||
|
@ -2558,7 +2558,7 @@ function drupal_build_js_cache($files, $filename) {
|
||||||
* Delete all cached JS files.
|
* Delete all cached JS files.
|
||||||
*/
|
*/
|
||||||
function drupal_clear_js_cache() {
|
function drupal_clear_js_cache() {
|
||||||
file_scan_directory(file_create_path('js'), '.*', array('.', '..', 'CVS'), 'file_delete', TRUE);
|
file_scan_directory(file_create_path('js', TRUE), '.*', array('.', '..', 'CVS'), 'file_delete', TRUE);
|
||||||
variable_set('javascript_parsed', array());
|
variable_set('javascript_parsed', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,8 @@ function file_create_url($path) {
|
||||||
* appended if necessary, or FALSE if the path is invalid (i.e. outside the
|
* appended if necessary, or FALSE if the path is invalid (i.e. outside the
|
||||||
* configured 'files' or temp directories).
|
* configured 'files' or temp directories).
|
||||||
*/
|
*/
|
||||||
function file_create_path($dest = 0) {
|
function file_create_path($dest = 0, $public_files = FALSE) {
|
||||||
$file_path = file_directory_path();
|
$file_path = file_directory_path($public_files);
|
||||||
if (!$dest) {
|
if (!$dest) {
|
||||||
return $file_path;
|
return $file_path;
|
||||||
}
|
}
|
||||||
|
@ -292,8 +292,8 @@ function file_check_location($source, $directory = '') {
|
||||||
* @return
|
* @return
|
||||||
* TRUE for success, FALSE for failure.
|
* TRUE for success, FALSE for failure.
|
||||||
*/
|
*/
|
||||||
function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
|
function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME, $public_files = FALSE) {
|
||||||
$dest = file_create_path($dest);
|
$dest = file_create_path($dest, $public_files);
|
||||||
|
|
||||||
$directory = $dest;
|
$directory = $dest;
|
||||||
$basename = file_check_path($directory);
|
$basename = file_check_path($directory);
|
||||||
|
@ -413,10 +413,10 @@ function file_destination($destination, $replace) {
|
||||||
* @return
|
* @return
|
||||||
* TRUE for success, FALSE for failure.
|
* TRUE for success, FALSE for failure.
|
||||||
*/
|
*/
|
||||||
function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
|
function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME, $public_files = FALSE) {
|
||||||
$path_original = is_object($source) ? $source->filepath : $source;
|
$path_original = is_object($source) ? $source->filepath : $source;
|
||||||
|
|
||||||
if (file_copy($source, $dest, $replace)) {
|
if (file_copy($source, $dest, $replace, $public_files)) {
|
||||||
$path_current = is_object($source) ? $source->filepath : $source;
|
$path_current = is_object($source) ? $source->filepath : $source;
|
||||||
|
|
||||||
if ($path_original == $path_current || file_delete($path_original)) {
|
if ($path_original == $path_current || file_delete($path_original)) {
|
||||||
|
@ -874,7 +874,7 @@ function file_validate_image_resolution(&$file, $maximum_dimensions = 0, $minimu
|
||||||
*
|
*
|
||||||
* @return A string containing the resulting filename or 0 on error
|
* @return A string containing the resulting filename or 0 on error
|
||||||
*/
|
*/
|
||||||
function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
|
function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME, $public_files = FALSE) {
|
||||||
$temp = file_directory_temp();
|
$temp = file_directory_temp();
|
||||||
// On Windows, tempnam() requires an absolute path, so we use realpath().
|
// On Windows, tempnam() requires an absolute path, so we use realpath().
|
||||||
$file = tempnam(realpath($temp), 'file');
|
$file = tempnam(realpath($temp), 'file');
|
||||||
|
@ -885,7 +885,7 @@ function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
|
||||||
fwrite($fp, $data);
|
fwrite($fp, $data);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
if (!file_move($file, $dest, $replace)) {
|
if (!file_move($file, $dest, $replace, $public_files)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -895,7 +895,7 @@ function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
|
||||||
/**
|
/**
|
||||||
* Set the status of a file.
|
* Set the status of a file.
|
||||||
*
|
*
|
||||||
* @param $file
|
* @param $file
|
||||||
* A Drupal file object.
|
* A Drupal file object.
|
||||||
* @param $status
|
* @param $status
|
||||||
* A status value to set the file to. One of:
|
* A status value to set the file to. One of:
|
||||||
|
@ -924,7 +924,7 @@ function file_transfer($source, $headers) {
|
||||||
if (ob_get_level()) {
|
if (ob_get_level()) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
// IE cannot download private files because it cannot store files downloaded
|
// IE cannot download private files because it cannot store files downloaded
|
||||||
// over HTTPS in the browser cache. The problem can be solved by sending
|
// over HTTPS in the browser cache. The problem can be solved by sending
|
||||||
// custom headers to IE. See http://support.microsoft.com/kb/323308/en-us
|
// custom headers to IE. See http://support.microsoft.com/kb/323308/en-us
|
||||||
|
@ -1150,7 +1150,10 @@ function file_directory_temp() {
|
||||||
*
|
*
|
||||||
* @return A string containing the path to Drupal's 'files' directory.
|
* @return A string containing the path to Drupal's 'files' directory.
|
||||||
*/
|
*/
|
||||||
function file_directory_path() {
|
function file_directory_path($public_files = FALSE) {
|
||||||
|
if ($public_files) {
|
||||||
|
return variable_get('file_dirpublic_path', 'files');
|
||||||
|
}
|
||||||
return variable_get('file_directory_path', conf_path() .'/files');
|
return variable_get('file_directory_path', conf_path() .'/files');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2181,7 +2181,7 @@ function _locale_rebuild_js($langcode = NULL) {
|
||||||
|
|
||||||
// Construct the filepath where JS translation files are stored.
|
// Construct the filepath where JS translation files are stored.
|
||||||
// There is (on purpose) no front end to edit that variable.
|
// There is (on purpose) no front end to edit that variable.
|
||||||
$dir = file_create_path(variable_get('locale_js_directory', 'languages'));
|
$dir = file_create_path(variable_get('locale_js_directory', 'languages'), TRUE);
|
||||||
|
|
||||||
// Delete old file, if we have no translations anymore, or a different file to be saved.
|
// Delete old file, if we have no translations anymore, or a different file to be saved.
|
||||||
$changed_hash = $language->javascript != $data_hash;
|
$changed_hash = $language->javascript != $data_hash;
|
||||||
|
@ -2199,7 +2199,7 @@ function _locale_rebuild_js($langcode = NULL) {
|
||||||
file_check_directory($dir, TRUE);
|
file_check_directory($dir, TRUE);
|
||||||
|
|
||||||
// Save the file.
|
// Save the file.
|
||||||
if (file_save_data($data, $dest)) {
|
if (file_save_data($data, $dest, FILE_EXISTS_REPLACE, TRUE)) {
|
||||||
$language->javascript = $data_hash;
|
$language->javascript = $data_hash;
|
||||||
// If we deleted a previous version of the file and we replace it with a
|
// If we deleted a previous version of the file and we replace it with a
|
||||||
// new one we have an update.
|
// new one we have an update.
|
||||||
|
|
|
@ -496,7 +496,7 @@ function locale_system_update($components) {
|
||||||
function locale_update_js_files() {
|
function locale_update_js_files() {
|
||||||
global $language;
|
global $language;
|
||||||
|
|
||||||
$dir = file_create_path(variable_get('locale_js_directory', 'languages'));
|
$dir = file_create_path(variable_get('locale_js_directory', 'languages'), TRUE);
|
||||||
$parsed = variable_get('javascript_parsed', array());
|
$parsed = variable_get('javascript_parsed', array());
|
||||||
|
|
||||||
// The first three parameters are NULL in order to get an array with all
|
// The first three parameters are NULL in order to get an array with all
|
||||||
|
|
|
@ -1391,11 +1391,11 @@ function system_performance_settings() {
|
||||||
$form['bandwidth_optimizations'] = array(
|
$form['bandwidth_optimizations'] = array(
|
||||||
'#type' => 'fieldset',
|
'#type' => 'fieldset',
|
||||||
'#title' => t('Bandwidth optimizations'),
|
'#title' => t('Bandwidth optimizations'),
|
||||||
'#description' => t('<p>Drupal can automatically optimize external resources like CSS and JavaScript, which can reduce both the size and number of requests made to your website. CSS files can be aggregated and compressed into a single file, while JavaScript files are aggregated (but not compressed). These optional optimizations may reduce server load, bandwidth requirements, and page loading times.</p><p>These options are disabled if you have not set up your files directory, or if your download method is set to private.</p>')
|
'#description' => t('<p>Drupal can automatically optimize external resources like CSS and JavaScript, which can reduce both the size and number of requests made to your website. CSS files can be aggregated and compressed into a single file, while JavaScript files are aggregated (but not compressed). These optional optimizations may reduce server load, bandwidth requirements, and page loading times.</p><p>These options are disabled if you have not set up your files directory, or if your download method is set to private and directory %public_files does not exists or isn\'t writable.</p>', array('%public_files' => variable_get('file_dirpublic_path', 'files')))
|
||||||
);
|
);
|
||||||
|
|
||||||
$directory = file_directory_path();
|
$directory = file_directory_path(0, TRUE);
|
||||||
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
|
$is_writable = is_dir($directory) && is_writable($directory);
|
||||||
$form['bandwidth_optimizations']['preprocess_css'] = array(
|
$form['bandwidth_optimizations']['preprocess_css'] = array(
|
||||||
'#type' => 'radios',
|
'#type' => 'radios',
|
||||||
'#title' => t('Optimize CSS files'),
|
'#title' => t('Optimize CSS files'),
|
||||||
|
|
Reference in a new issue