Public Member Functions | |
init ($mounts, $f_ext) | |
Constructor This function should be called to initialise the internal arrays $this->mounts and $this->f_ext. | |
getTotalFileInfo ($wholePath) | |
Returns an array with a whole lot of fileinformation. | |
is_allowed ($iconkey, $type) | |
Checks if a $iconkey (fileextension) is allowed according to $this->f_ext. | |
checkIfFullAccess ($theDest) | |
Returns true if you can operate of ANY file ('*') in the space $theDest is in ('webspace' / 'ftpspace'). | |
is_webpath ($path) | |
Checks if $this->webPath (should be TYPO3_DOCUMENT_ROOT) is in the first part of $path Returns true also if $this->init is not set or if $path is empty... | |
checkIfAllowed ($ext, $theDest, $filename='') | |
If the filename is given, check it against the TYPO3_CONF_VARS[BE][fileDenyPattern] + Checks if the $ext fileextension is allowed in the path $theDest (this is based on whether $theDest is below the $this->webPath). | |
checkFileNameLen ($fileName) | |
Returns true if the input filename string is shorter than $this->maxInputNameLen. | |
is_directory ($theDir) | |
Cleans $theDir for slashes in the end of the string and returns the new path, if it exists on the server. | |
isPathValid ($theFile) | |
Wrapper for t3lib_div::validPathStr(). | |
getUniqueName ($theFile, $theDest, $dontCheckForUnique=0) | |
Returns the destination path/filename of a unique filename/foldername in that path. | |
checkPathAgainstMounts ($thePath) | |
Checks if $thePath is a path under one of the paths in $this->mounts See comment in the header of this class. | |
blindPath ($thePath) | |
Removes filemount part of a path, thus blinding the position. | |
findTempFolder () | |
Find temporary folder Finds the first $this->tempFN ('_temp_' usually) -folder in the internal array of filemounts, $this->mounts. | |
cleanDirectoryName ($theDir) | |
Removes all dots, slashes and spaces after a path... | |
rmDoubleSlash ($string) | |
Converts any double slashes (//) to a single slash (/). | |
slashPath ($path) | |
Returns a string which has a slash '/' appended if it doesn't already have that slash. | |
cleanFileName ($fileName) | |
Returns a string where any character not matching [.a-zA-Z0-9_-] is substituted by '_'. | |
formatSize ($sizeInBytes) | |
Formats an integer, $sizeInBytes, to Mb or Kb or just bytes. | |
Public Attributes | |
$getUniqueNamePrefix = '' | |
$maxNumber = 20 | |
$uniquePrecision = 6 | |
$maxInputNameLen = 30 | |
$tempFN = '_temp_' | |
$f_ext = Array() | |
$mounts = Array() | |
$webPath = '' | |
$isInit = 0 |
|
Removes filemount part of a path, thus blinding the position. Takes a path, $thePath, and removes the part of the path which equals the filemount.
Definition at line 341 of file class.t3lib_basicfilefunc.php. References checkPathAgainstMounts(). 00341 { 00342 $k=$this->checkPathAgainstMounts($thePath); 00343 if ($k) { 00344 $name=''; 00345 $name.='['.$this->mounts[$k]['name'].']: '; 00346 $name.=substr($thePath,strlen($this->mounts[$k]['path'])); 00347 return $name; 00348 } 00349 }
|
|
Returns true if the input filename string is shorter than $this->maxInputNameLen.
Definition at line 238 of file class.t3lib_basicfilefunc.php. Referenced by t3lib_extFileFunctions::func_newfile(), t3lib_extFileFunctions::func_newfolder(), and t3lib_extFileFunctions::func_rename(). 00238 {
00239 return strlen($fileName) <= $this->maxInputNameLen;
00240 }
|
|
If the filename is given, check it against the TYPO3_CONF_VARS[BE][fileDenyPattern] + Checks if the $ext fileextension is allowed in the path $theDest (this is based on whether $theDest is below the $this->webPath).
Definition at line 228 of file class.t3lib_basicfilefunc.php. References is_allowed(). Referenced by t3lib_extFileFunctions::func_copy(), t3lib_extFileFunctions::func_edit(), t3lib_extFileFunctions::func_move(), t3lib_extFileFunctions::func_newfile(), t3lib_extFileFunctions::func_rename(), and t3lib_extFileFunctions::func_upload(). 00228 { 00229 return t3lib_div::verifyFilenameAgainstDenyPattern($filename) && $this->is_allowed($ext,($this->is_webpath($theDest)?'webspace':'ftpspace')); 00230 }
|
|
Returns true if you can operate of ANY file ('*') in the space $theDest is in ('webspace' / 'ftpspace').
Definition at line 194 of file class.t3lib_basicfilefunc.php. References is_webpath(). Referenced by t3lib_extFileFunctions::func_copy(), t3lib_extFileFunctions::func_move(), and t3lib_extFileFunctions::func_unzip(). 00194 { 00195 $type = $this->is_webpath($theDest)?'webspace':'ftpspace'; 00196 if (isset($this->f_ext[$type])) { 00197 if ((string)$this->f_ext[$type]['deny']=='' || $this->f_ext[$type]['allow']=='*') return true; 00198 } 00199 }
|
|
Checks if $thePath is a path under one of the paths in $this->mounts See comment in the header of this class.
Definition at line 323 of file class.t3lib_basicfilefunc.php. References isPathValid(). Referenced by blindPath(), t3lib_extFileFunctions::findRecycler(), t3lib_extFileFunctions::func_copy(), t3lib_extFileFunctions::func_delete(), t3lib_extFileFunctions::func_edit(), t3lib_extFileFunctions::func_move(), t3lib_extFileFunctions::func_newfile(), t3lib_extFileFunctions::func_newfolder(), t3lib_extFileFunctions::func_rename(), t3lib_extFileFunctions::func_unzip(), and t3lib_extFileFunctions::func_upload(). 00323 { 00324 if ($thePath && $this->isPathValid($thePath) && is_array($this->mounts)) { 00325 reset ($this->mounts); 00326 while(list($k,$val)=each($this->mounts)) { 00327 if (t3lib_div::isFirstPartOfStr($thePath,$val['path'])) { 00328 return $k; 00329 } 00330 } 00331 } 00332 }
|
|
Removes all dots, slashes and spaces after a path...
Definition at line 386 of file class.t3lib_basicfilefunc.php. Referenced by t3lib_extFileFunctions::findRecycler(), and is_directory(). 00386 { 00387 return ereg_replace('[\/\. ]*$','',$this->rmDoubleSlash($theDir)); 00388 }
|
|
Returns a string where any character not matching [.a-zA-Z0-9_-] is substituted by '_'.
Definition at line 419 of file class.t3lib_basicfilefunc.php. Referenced by t3lib_extFileFunctions::func_newfile(), t3lib_extFileFunctions::func_newfolder(), t3lib_extFileFunctions::func_rename(), and t3lib_extFileFunctions::func_upload(). 00419 { 00420 $theNewName = ereg_replace('[^.[:alnum:]_-]','_',trim($fileName)); 00421 return $theNewName; 00422 }
|
|
Find temporary folder Finds the first $this->tempFN ('_temp_' usually) -folder in the internal array of filemounts, $this->mounts.
Definition at line 357 of file class.t3lib_basicfilefunc.php. References $val. 00357 { 00358 if ($this->tempFN && is_array($this->mounts)) { 00359 reset ($this->mounts); 00360 while(list($k,$val)=each($this->mounts)) { 00361 $tDir = $val['path'].$this->tempFN; 00362 if (@is_dir($tDir)) { 00363 return $tDir; 00364 } 00365 } 00366 } 00367 }
|
|
Formats an integer, $sizeInBytes, to Mb or Kb or just bytes.
Definition at line 430 of file class.t3lib_basicfilefunc.php. References $val. 00430 { 00431 if ($sizeInBytes>900) { 00432 if ($sizeInBytes>900000) { // MB 00433 $val = $sizeInBytes/(1024*1024); 00434 return number_format($val, (($val<20)?1:0), '.', '').' M'; 00435 } else { // KB 00436 $val = $sizeInBytes/(1024); 00437 return number_format($val, (($val<20)?1:0), '.', '').' K'; 00438 } 00439 } else { // Bytes 00440 return $sizeInBytes.' '; 00441 } 00442 }
|
|
Returns an array with a whole lot of fileinformation.
Definition at line 149 of file class.t3lib_basicfilefunc.php. 00149 {
00150 $theuser = getmyuid();
00151 $info = t3lib_div::split_fileref($wholePath);
00152 $info['tstamp'] = @filectime($wholePath);
00153 $info['size'] = @filesize($wholePath);
00154 $info['type'] = @filetype($wholePath);
00155 $info['owner'] = @fileowner($wholePath);
00156 $info['perms'] = @fileperms($wholePath);
00157 $info['writeable'] = ($info['perms']&2 || ($theuser==$info['owner'] && $info['perms']&128));
00158 $info['readable'] = ($info['perms']&4 || ($theuser==$info['owner'] && $info['perms']&256));
00159 return $info;
00160 }
|
|
Returns the destination path/filename of a unique filename/foldername in that path. If $theFile exists in $theDest (directory) the file have numbers appended up to $this->maxNumber. Hereafter a unique string will be appended. This function is used by fx. TCEmain when files are attached to records and needs to be uniquely named in the uploads/* folders
Definition at line 280 of file class.t3lib_basicfilefunc.php. References $a, and is_directory(). Referenced by t3lib_extFileFunctions::func_copy(), t3lib_extFileFunctions::func_move(), and t3lib_extFileFunctions::func_upload(). 00280 { 00281 $theDest = $this->is_directory($theDest); // $theDest is cleaned up 00282 $origFileInfo = t3lib_div::split_fileref($theFile); // Fetches info about path, name, extention of $theFile 00283 if ($theDest) { 00284 if ($this->getUniqueNamePrefix) { // Adds prefix 00285 $origFileInfo['file'] = $this->getUniqueNamePrefix.$origFileInfo['file']; 00286 $origFileInfo['filebody'] = $this->getUniqueNamePrefix.$origFileInfo['filebody']; 00287 } 00288 00289 // Check if the file exists and if not - return the filename... 00290 $fileInfo = $origFileInfo; 00291 $theDestFile = $theDest.'/'.$fileInfo['file']; // The destinations file 00292 if (!@file_exists($theDestFile) || $dontCheckForUnique) { // If the file does NOT exist we return this filename 00293 return $theDestFile; 00294 } 00295 00296 // Well the filename in its pure form existed. Now we try to append numbers / unique-strings and see if we can find an available filename... 00297 $theTempFileBody = ereg_replace('_[0-9][0-9]$','',$origFileInfo['filebody']); // This removes _xx if appended to the file 00298 $theOrigExt = $origFileInfo['realFileext'] ? '.'.$origFileInfo['realFileext'] : ''; 00299 00300 for ($a=1; $a<=($this->maxNumber+1); $a++) { 00301 if ($a<=$this->maxNumber) { // First we try to append numbers 00302 $insert = '_'.sprintf('%02d', $a); 00303 } else { // .. then we try unique-strings... 00304 $insert = '_'.substr(md5(uniqId('')),0,$this->uniquePrecision); 00305 } 00306 $theTestFile = $theTempFileBody.$insert.$theOrigExt; 00307 $theDestFile = $theDest.'/'.$theTestFile; // The destinations file 00308 if (!@file_exists($theDestFile)) { // If the file does NOT exist we return this filename 00309 return $theDestFile; 00310 } 00311 } 00312 } 00313 }
|
|
Constructor This function should be called to initialise the internal arrays $this->mounts and $this->f_ext. A typical example of the array $mounts is this: $mounts[xx][path] = (..a mounted path..) the 'xx'-keys is just numerical from zero. There are also a [name] and [type] value that just denotes the mountname and type. Not used for athentication here. $this->mounts is traversed in the function checkPathAgainstMounts($thePath), and it is checked that $thePath is actually below one of the mount-paths The mountpaths are with a trailing '/'. $thePath must be with a trailing '/' also! As you can see, $this->mounts is very critical! This is the array that decides where the user will be allowed to copy files!! Typically the global var $WEBMOUNTS would be passed along as $mounts A typical example of the array $f_ext is this: $f_ext['webspace']['allow']=''; $f_ext['webspace']['deny']='php3,php'; $f_ext['ftpspace']['allow']='*'; $f_ext['ftpspace']['deny']=''; The control of fileextensions goes in two catagories. Webspace and Ftpspace. Webspace is folders accessible from a webbrowser (below TYPO3_DOCUMENT_ROOT) and ftpspace is everything else. The control is done like this: If an extension matches 'allow' then the check returns true. If not and an extension matches 'deny' then the check return false. If no match at all, returns true. You list extensions comma-separated. If the value is a '*' every extension is allowed The list is case-insensitive when used in this class (see init()) Typically TYPO3_CONF_VARS['BE']['fileExtensions'] would be passed along as $f_ext. Example: $basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
Definition at line 132 of file class.t3lib_basicfilefunc.php. 00132 { 00133 $this->f_ext['webspace']['allow'] = t3lib_div::uniqueList(strtolower($f_ext['webspace']['allow'])); 00134 $this->f_ext['webspace']['deny'] = t3lib_div::uniqueList(strtolower($f_ext['webspace']['deny'])); 00135 $this->f_ext['ftpspace']['allow'] = t3lib_div::uniqueList(strtolower($f_ext['ftpspace']['allow'])); 00136 $this->f_ext['ftpspace']['deny'] = t3lib_div::uniqueList(strtolower($f_ext['ftpspace']['deny'])); 00137 00138 $this->mounts = $mounts; 00139 $this->webPath = t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT'); 00140 $this->isInit = 1; 00141 }
|
|
Checks if a $iconkey (fileextension) is allowed according to $this->f_ext.
Definition at line 169 of file class.t3lib_basicfilefunc.php. Referenced by checkIfAllowed(). 00169 { 00170 if (isset($this->f_ext[$type])) { 00171 $ik = strtolower($iconkey); 00172 if ($ik) { 00173 // If the extension is found amongst the allowed types, we return true immediately 00174 if ($this->f_ext[$type]['allow']=='*' || t3lib_div::inList($this->f_ext[$type]['allow'],$ik)) return true; 00175 // If the extension is found amongst the denied types, we return false immediately 00176 if ($this->f_ext[$type]['deny']=='*' || t3lib_div::inList($this->f_ext[$type]['deny'],$ik)) return false; 00177 // If no match we return true 00178 return true; 00179 } else { // If no extension: 00180 if ($this->f_ext[$type]['allow']=='*') return true; 00181 if ($this->f_ext[$type]['deny']=='*') return false; 00182 return true; 00183 } 00184 } 00185 return false; 00186 }
|
|
Cleans $theDir for slashes in the end of the string and returns the new path, if it exists on the server.
Definition at line 248 of file class.t3lib_basicfilefunc.php. References cleanDirectoryName(), and isPathValid(). Referenced by t3lib_extFileFunctions::func_copy(), t3lib_extFileFunctions::func_delete(), t3lib_extFileFunctions::func_move(), t3lib_extFileFunctions::func_newfile(), t3lib_extFileFunctions::func_newfolder(), t3lib_extFileFunctions::func_unzip(), t3lib_extFileFunctions::func_upload(), and getUniqueName(). 00248 { 00249 if ($this->isPathValid($theDir)) { 00250 $theDir=$this->cleanDirectoryName($theDir); 00251 if (@is_dir($theDir)) { 00252 return $theDir; 00253 } 00254 } 00255 return false; 00256 }
|
|
Checks if $this->webPath (should be TYPO3_DOCUMENT_ROOT) is in the first part of $path Returns true also if $this->init is not set or if $path is empty...
Definition at line 208 of file class.t3lib_basicfilefunc.php. References slashPath(). Referenced by checkIfFullAccess(). 00208 { 00209 if ($this->isInit) { 00210 $testPath = $this->slashPath($path); 00211 $testPathWeb = $this->slashPath($this->webPath); 00212 if ($testPathWeb && $testPath) { 00213 return t3lib_div::isFirstPartOfStr($testPath,$testPathWeb); 00214 } 00215 } 00216 return true; // Its more safe to return true (as the webpath is more restricted) if something went wrong... 00217 }
|
|
Wrapper for t3lib_div::validPathStr().
Definition at line 265 of file class.t3lib_basicfilefunc.php. Referenced by checkPathAgainstMounts(), t3lib_extFileFunctions::findRecycler(), t3lib_extFileFunctions::func_copy(), t3lib_extFileFunctions::func_delete(), t3lib_extFileFunctions::func_move(), and is_directory(). 00265 {
00266 return t3lib_div::validPathStr($theFile);
00267 }
|
|
Converts any double slashes (//) to a single slash (/).
Definition at line 396 of file class.t3lib_basicfilefunc.php. 00396 { 00397 return str_replace('//','/',$string); 00398 }
|
|
Returns a string which has a slash '/' appended if it doesn't already have that slash.
Definition at line 406 of file class.t3lib_basicfilefunc.php. Referenced by is_webpath(). 00406 { 00407 if (substr($path,-1)!='/') { 00408 return $path.'/'; 00409 } 00410 return $path; 00411 }
|
|
Definition at line 88 of file class.t3lib_basicfilefunc.php. |
|
Definition at line 81 of file class.t3lib_basicfilefunc.php. |
|
Definition at line 91 of file class.t3lib_basicfilefunc.php. |
|
Definition at line 84 of file class.t3lib_basicfilefunc.php. |
|
Definition at line 82 of file class.t3lib_basicfilefunc.php. |
|
Definition at line 89 of file class.t3lib_basicfilefunc.php. |
|
Definition at line 85 of file class.t3lib_basicfilefunc.php. |
|
Definition at line 83 of file class.t3lib_basicfilefunc.php. |
|
Definition at line 90 of file class.t3lib_basicfilefunc.php. |