Applied adapted Drupal core patch #572516 for sites with mixed public and private files

This commit is contained in:
Manuel Cillero 2017-08-20 17:26:27 +02:00
parent 75c72c4cbb
commit 5c5aaddc78
6 changed files with 35 additions and 27 deletions

View file

@ -1926,8 +1926,8 @@ function drupal_get_css($css = NULL) {
$no_theme_preprocess = '';
$preprocess_css = (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
$directory = file_directory_path();
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
$directory = file_directory_path(TRUE);
$is_writable = is_dir($directory) && is_writable($directory);
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
@ -2002,7 +2002,7 @@ function drupal_build_css_cache($types, $filename) {
$data = '';
// 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);
if (!file_exists($csspath .'/'. $filename)) {
@ -2028,7 +2028,7 @@ function drupal_build_css_cache($types, $filename) {
$data = implode('', $matches[0]) . $data;
// 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;
}
@ -2182,7 +2182,7 @@ function _drupal_load_stylesheet($matches) {
* Delete all cached CSS files.
*/
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' => '');
$files = array();
$preprocess_js = (variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
$directory = file_directory_path();
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
$directory = file_directory_path(TRUE);
$is_writable = is_dir($directory) && is_writable($directory);
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
@ -2535,7 +2535,7 @@ function drupal_build_js_cache($files, $filename) {
$contents = '';
// 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);
if (!file_exists($jspath .'/'. $filename)) {
@ -2548,7 +2548,7 @@ function drupal_build_js_cache($files, $filename) {
}
// 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;
@ -2558,7 +2558,7 @@ function drupal_build_js_cache($files, $filename) {
* Delete all cached JS files.
*/
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());
}

View file

@ -60,8 +60,8 @@ function file_create_url($path) {
* appended if necessary, or FALSE if the path is invalid (i.e. outside the
* configured 'files' or temp directories).
*/
function file_create_path($dest = 0) {
$file_path = file_directory_path();
function file_create_path($dest = 0, $public_files = FALSE) {
$file_path = file_directory_path($public_files);
if (!$dest) {
return $file_path;
}
@ -292,8 +292,8 @@ function file_check_location($source, $directory = '') {
* @return
* TRUE for success, FALSE for failure.
*/
function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
$dest = file_create_path($dest);
function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME, $public_files = FALSE) {
$dest = file_create_path($dest, $public_files);
$directory = $dest;
$basename = file_check_path($directory);
@ -413,10 +413,10 @@ function file_destination($destination, $replace) {
* @return
* 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;
if (file_copy($source, $dest, $replace)) {
if (file_copy($source, $dest, $replace, $public_files)) {
$path_current = is_object($source) ? $source->filepath : $source;
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
*/
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();
// On Windows, tempnam() requires an absolute path, so we use realpath().
$file = tempnam(realpath($temp), 'file');
@ -885,7 +885,7 @@ function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
fwrite($fp, $data);
fclose($fp);
if (!file_move($file, $dest, $replace)) {
if (!file_move($file, $dest, $replace, $public_files)) {
return 0;
}
@ -895,7 +895,7 @@ function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
/**
* Set the status of a file.
*
* @param $file
* @param $file
* A Drupal file object.
* @param $status
* A status value to set the file to. One of:
@ -924,7 +924,7 @@ function file_transfer($source, $headers) {
if (ob_get_level()) {
ob_end_clean();
}
// IE cannot download private files because it cannot store files downloaded
// 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
@ -1150,7 +1150,10 @@ function file_directory_temp() {
*
* @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');
}

View file

@ -2181,7 +2181,7 @@ function _locale_rebuild_js($langcode = NULL) {
// Construct the filepath where JS translation files are stored.
// 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.
$changed_hash = $language->javascript != $data_hash;
@ -2199,7 +2199,7 @@ function _locale_rebuild_js($langcode = NULL) {
file_check_directory($dir, TRUE);
// Save the file.
if (file_save_data($data, $dest)) {
if (file_save_data($data, $dest, FILE_EXISTS_REPLACE, TRUE)) {
$language->javascript = $data_hash;
// If we deleted a previous version of the file and we replace it with a
// new one we have an update.