*/
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;
return \Drupal::service('file_system')->validScheme($scheme);
}
-
/**
* Returns the part of a URI after the schema.
*
// 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 {
$http_host = $host . ':' . $port;
}
- return preg_replace('|^https?://' . $http_host . '|', '', $file_url);
+ return preg_replace('|^https?://' . preg_quote($http_host, '|') . '|', '', $file_url);
}
/**
// 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]);
}
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;
}
}
// 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;
}
$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;
}
* @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.
$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]));
}
}
return file_unmanaged_delete($path);
}
-
/**
* Moves an uploaded file to a new location.
*
// 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;
}