X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fincludes%2Ffile.inc;fp=web%2Fcore%2Fincludes%2Ffile.inc;h=77a743eab044ad4ec095b26c1fa159a4a56dba25;hp=e532bf1d08ce54a4e401d0f8152ef6812685c42c;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/includes/file.inc b/web/core/includes/file.inc index e532bf1d0..77a743eab 100644 --- a/web/core/includes/file.inc +++ b/web/core/includes/file.inc @@ -6,7 +6,6 @@ */ use Drupal\Component\FileSystem\FileSystem as ComponentFileSystem; -use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\UrlHelper; use Drupal\Component\PhpStorage\FileStorage; use Drupal\Component\Utility\Bytes; @@ -100,7 +99,6 @@ function file_stream_wrapper_valid_scheme($scheme) { return \Drupal::service('file_system')->validScheme($scheme); } - /** * Returns the part of a URI after the schema. * @@ -202,7 +200,7 @@ function file_create_url($uri) { // HTTP and to https://example.com/bar.jpg when viewing a HTTPS page) // Both types of relative URIs are characterized by a leading slash, hence // we can use a single check. - if (Unicode::substr($uri, 0, 1) == '/') { + if (mb_substr($uri, 0, 1) == '/') { return $uri; } else { @@ -270,7 +268,7 @@ function file_url_transform_relative($file_url) { $http_host = $host . ':' . $port; } - return preg_replace('|^https?://' . $http_host . '|', '', $file_url); + return preg_replace('|^https?://' . preg_quote($http_host, '|') . '|', '', $file_url); } /** @@ -512,8 +510,9 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E // Assert that the source file actually exists. if (!file_exists($source)) { - // @todo Replace drupal_set_message() calls with exceptions instead. - drupal_set_message(t('The specified file %file could not be moved/copied because no file by that name exists. Please check that you supplied the correct filename.', ['%file' => $original_source]), 'error'); + // @todo Replace \Drupal::messenger()->addError() calls with exceptions + // instead. + \Drupal::messenger()->addError(t('The specified file %file could not be moved/copied because no file by that name exists. Please check that you supplied the correct filename.', ['%file' => $original_source])); if (($realpath = $file_system->realpath($original_source)) !== FALSE) { $logger->notice('File %file (%realpath) could not be moved/copied because it does not exist.', ['%file' => $original_source, '%realpath' => $realpath]); } @@ -539,7 +538,7 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E if (!file_prepare_directory($dirname)) { // The destination is not valid. $logger->notice('File %file could not be moved/copied because the destination directory %destination is not configured correctly.', ['%file' => $original_source, '%destination' => $dirname]); - drupal_set_message(t('The specified file %file could not be moved/copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', ['%file' => $original_source]), 'error'); + \Drupal::messenger()->addError(t('The specified file %file could not be moved/copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', ['%file' => $original_source])); return FALSE; } } @@ -547,7 +546,7 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E // Determine whether we can perform this operation based on overwrite rules. $destination = file_destination($destination, $replace); if ($destination === FALSE) { - drupal_set_message(t('The file %file could not be moved/copied because a file by that name already exists in the destination directory.', ['%file' => $original_source]), 'error'); + \Drupal::messenger()->addError(t('The file %file could not be moved/copied because a file by that name already exists in the destination directory.', ['%file' => $original_source])); $logger->notice('File %file could not be moved/copied because a file by that name already exists in the destination directory (%destination)', ['%file' => $original_source, '%destination' => $destination]); return FALSE; } @@ -556,7 +555,7 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E $real_source = $file_system->realpath($source); $real_destination = $file_system->realpath($destination); if ($source == $destination || ($real_source !== FALSE) && ($real_source == $real_destination)) { - drupal_set_message(t('The specified file %file was not moved/copied because it would overwrite itself.', ['%file' => $source]), 'error'); + \Drupal::messenger()->addError(t('The specified file %file was not moved/copied because it would overwrite itself.', ['%file' => $source])); $logger->notice('File %file could not be moved/copied because it would overwrite itself.', ['%file' => $source]); return FALSE; } @@ -698,8 +697,8 @@ function file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXIST * @param $extensions * A space-separated list of extensions that should not be altered. * @param $alerts - * If TRUE, drupal_set_message() will be called to display a message if the - * file name was changed. + * If TRUE, \Drupal::messenger()->addStatus() will be called to display + * a message if the file name was changed. * * @return string * The potentially modified $filename. @@ -735,7 +734,7 @@ function file_munge_filename($filename, $extensions, $alerts = TRUE) { $filename = $new_filename . '.' . $final_extension; if ($alerts && $original != $filename) { - drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $filename])); + \Drupal::messenger()->addStatus(t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $filename])); } } @@ -926,7 +925,6 @@ function file_unmanaged_delete_recursive($path, $callback = NULL) { return file_unmanaged_delete($path); } - /** * Moves an uploaded file to a new location. * @@ -969,7 +967,7 @@ function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EX // Write the data to a temporary file. $temp_name = drupal_tempnam('temporary://', 'file'); if (file_put_contents($temp_name, $data) === FALSE) { - drupal_set_message(t('The file could not be created.'), 'error'); + \Drupal::messenger()->addError(t('The file could not be created.')); return FALSE; }