Merge branch 'MDL-61724-master' of git://github.com/mihailges/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2018-04-03 23:38:59 +02:00
3 changed files with 51 additions and 25 deletions
+27 -17
View File
@@ -442,7 +442,7 @@ define('FEATURE_USES_QUESTIONS', 'usesquestions');
/**
* Maximum filename char size
*/
define('MAX_FILENAME_SIZE', 90);
define('MAX_FILENAME_SIZE', 100);
/** Unspecified module archetype */
define('MOD_ARCHETYPE_OTHER', 0);
@@ -991,21 +991,6 @@ function clean_param($param, $type) {
if ($param === '.' || $param === '..') {
$param = '';
}
// Extract a part of the filename if it's char size exceeds MAX_FILENAME_SIZE.
// If the filename is too long, the file cannot be created on the filesystem due to exceeding max byte size.
// Limiting the filename to a certain size (considering multibyte characters) will prevent this.
if (core_text::strlen($param) > MAX_FILENAME_SIZE) {
// Exclude extension if present in filename.
$mimetypes = get_mimetypes_array();
$extension = pathinfo($param, PATHINFO_EXTENSION);
if ($extension && !empty($mimetypes[$extension])) {
$basename = pathinfo($param, PATHINFO_FILENAME);
$param = core_text::substr($basename, 0, MAX_FILENAME_SIZE);
$param .= '.' . $extension;
} else {
$param = core_text::substr($param, 0, MAX_FILENAME_SIZE);
}
}
return $param;
case PARAM_PATH:
@@ -6813,7 +6798,6 @@ function clean_filename($string) {
return clean_param($string, PARAM_FILE);
}
// STRING TRANSLATION.
/**
@@ -8258,6 +8242,32 @@ function shorten_text($text, $ideal=30, $exact = false, $ending='...') {
return $truncate;
}
/**
* Shortens a given filename by removing characters positioned after the ideal string length.
* When the filename is too long, the file cannot be created on the filesystem due to exceeding max byte size.
* Limiting the filename to a certain size (considering multibyte characters) will prevent this.
*
* @param string $filename file name
* @param int $length ideal string length
* @return string $shortened shortened file name
*/
function shorten_filename($filename, $length = MAX_FILENAME_SIZE) {
$shortened = $filename;
// Extract a part of the filename if it's char size exceeds the ideal string length.
if (core_text::strlen($filename) > $length) {
// Exclude extension if present in filename.
$mimetypes = get_mimetypes_array();
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if ($extension && !empty($mimetypes[$extension])) {
$basename = pathinfo($filename, PATHINFO_FILENAME);
$shortened = core_text::substr($basename, 0, $length);
$shortened .= '.' . $extension;
} else {
$shortened = core_text::substr($filename, 0, $length);
}
}
return $shortened;
}
/**
* Given dates in seconds, how many weeks is the date from startdate