[TYPO3-core] create nice filenames
Martin Kutschker
Martin.Kutschker at blackbox.net
Thu Nov 10 14:21:05 CET 2005
This is a CVS patch request.
Type: New feature
Description:
In the BE when you create new file names (or folder names) every forbidden character is replaced by a _. This is annoying, especially for UTF-8 where two _'s will be generated.
Solution:
Modify the file name cleaning routine to do an ASCII-conversion with t3lib_cs. Use the correct charset depending on context, but provide an interface for overriding.
Additionally increase the max length to 60. 30 was to short for me on many occasions (I like to have rather descriptive names for my template files).
Branches: HEAD
Masi
PS: Why is a + not allowed?
-------------- next part --------------
--- class.t3lib_basicfilefunc-orig.php 2005-11-10 14:07:34.000000000 +0100
+++ class.t3lib_basicfilefunc.php 2005-11-10 14:08:51.000000000 +0100
@@ -82,7 +82,7 @@
var $getUniqueNamePrefix = ''; // Prefix which will be prepended the file when using the getUniqueName-function
var $maxNumber = 20; // This number decides the highest allowed appended number used on a filename before we use naming with unique strings
var $uniquePrecision = 6; // This number decides how many characters out of a unique MD5-hash that is appended to a filename if getUniqueName is asked to find an available filename.
- var $maxInputNameLen = 30; // This is the maximum length of names treated by cleanFileName()
+ var $maxInputNameLen = 60; // This is the maximum length of names treated by cleanFileName()
var $tempFN = '_temp_'; // Temp-foldername. A folder in the root of one of the mounts with this name is regarded a TEMP-folder (used for upload from clipboard)
// internal
@@ -438,11 +438,28 @@
* Returns a string where any character not matching [.a-zA-Z0-9_-] is substituted by '_'
*
* @param string Input string, typically the body of a filename
+ * @param string Charset of the a filename (defaults to currentcharset; depending on context)
* @return string Output string with any characters not matching [.a-zA-Z0-9_-] is substituted by '_'
*/
function cleanFileName($fileName) {
- $theNewName = ereg_replace('[^.[:alnum:]_-]','_',trim($fileName));
- return $theNewName;
+ if (!is_object($this->csConvObj)) {
+ if (TYPO3_MODE=='FE') {
+ $this->csConvObj = &$GLOBALS['TSFE']->csConvObj;
+ $charset = $GLOBALS['TSFE']->renderCharset;
+ } elseif(is_object($GLOBALS['LANG'])) { // BE assumed:
+ $this->csConvObj = &$GLOBALS['LANG']->csConvObj;
+ $charset = $GLOBALS['LANG']->charSet;
+ } else { // The object may not exist yet, so we need to create it now. Happens in the Install Tool for example.
+ $this->csConvObj = &t3lib_div::makeInstance('t3lib_cs');
+ $charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
+ }
+ }
+
+ if ($charset) {
+ $fileName = $this->csConvObj->specCharsToASCII($charset,$fileName);
+ }
+
+ return preg_replace('/[^.[:alnum:]_-]/','_',trim($fileName));
}
/**
@@ -471,4 +488,4 @@
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_basicfilefunc.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_basicfilefunc.php']);
}
-?>
\ No newline at end of file
+?>
More information about the TYPO3-team-core
mailing list