[ Index ]
 

Code source de Typo3 4.1.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/t3lib/ -> class.t3lib_basicfilefunc.php (sommaire)

Contains class with basic file management functions $Id: class.t3lib_basicfilefunc.php 1979 2007-02-04 21:04:20Z mundaun $ Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj

Author: Kasper Skaarhoj <kasperYYYY@typo3.com>
Poids: 506 lignes (20 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

t3lib_basicFileFunctions:: (19 méthodes):
  init()
  getTotalFileInfo()
  is_allowed()
  checkIfFullAccess()
  is_webpath()
  checkIfAllowed()
  checkFileNameLen()
  is_directory()
  isPathValid()
  getUniqueName()
  checkPathAgainstMounts()
  findFirstWebFolder()
  blindPath()
  findTempFolder()
  cleanDirectoryName()
  rmDoubleSlash()
  slashPath()
  cleanFileName()
  formatSize()


Classe: t3lib_basicFileFunctions  - X-Ref

Contains functions for management, validation etc of files in TYPO3, using the concepts of web- and ftp-space. Please see the comment for the init() function

init($mounts, $f_ext)   X-Ref
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']);

param: array        Contains the paths of the file mounts for the current BE user. Normally $GLOBALS['FILEMOUNTS'] is passed. This variable is set during backend user initialization; $FILEMOUNTS = $BE_USER->returnFilemounts(); (see typo3/init.php)
param: array        Array with information about allowed and denied file extensions. Typically passed: $TYPO3_CONF_VARS['BE']['fileExtensions']
return: void

getTotalFileInfo($wholePath)   X-Ref
Returns an array with a whole lot of fileinformation.

param: string        Filepath to existing file. Should probably be absolute. Filefunctions are performed on this value.
return: array        Information about the file in the filepath

is_allowed($iconkey,$type)   X-Ref
Checks if a $iconkey (fileextension) is allowed according to $this->f_ext.

param: string        The extension to check, eg. "php" or "html" etc.
param: string        Either "webspage" or "ftpspace" - points to a key in $this->f_ext
return: boolean        True if file extension is allowed.

checkIfFullAccess($theDest)   X-Ref
Returns true if you can operate of ANY file ('*') in the space $theDest is in ('webspace' / 'ftpspace')

param: string        Absolute path
return: boolean

is_webpath($path)   X-Ref
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...

param: string        Absolute path to check
return: boolean

checkIfAllowed($ext, $theDest, $filename='')   X-Ref
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)

param: string        File extension, eg. "php" or "html"
param: string        Absolute path for which to test
param: string        Filename to check against TYPO3_CONF_VARS[BE][fileDenyPattern]
return: boolean        True if extension/filename is allowed

checkFileNameLen($fileName)   X-Ref
Returns true if the input filename string is shorter than $this->maxInputNameLen.

param: string        Filename, eg "somefile.html"
return: boolean

is_directory($theDir)   X-Ref
Cleans $theDir for slashes in the end of the string and returns the new path, if it exists on the server.

param: string        Directory path to check
return: string        Returns the cleaned up directory name if OK, otherwise false.

isPathValid($theFile)   X-Ref
Wrapper for t3lib_div::validPathStr()

param: string        Filepath to evaluate
return: boolean        True, if no '//', '..' or '\' is in the $theFile

getUniqueName($theFile, $theDest, $dontCheckForUnique=0)   X-Ref
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

param: string        The input filename to check
param: string        The directory for which to return a unique filename for $theFile. $theDest MUST be a valid directory. Should be absolute.
param: boolean        If set the filename is returned with the path prepended without checking whether it already existed!
return: string        The destination absolute filepath (not just the name!) of a unique filename/foldername in that path.

checkPathAgainstMounts($thePath)   X-Ref
Checks if $thePath is a path under one of the paths in $this->mounts
See comment in the header of this class.

param: string        $thePath MUST HAVE a trailing '/' in order to match correctly with the mounts
return: string        The key to the first mount found, otherwise nothing is returned.

findFirstWebFolder()   X-Ref
Find first web folder (relative to PATH_site.'fileadmin') in filemounts array

return: string        The key to the first mount inside PATH_site."fileadmin" found, otherwise nothing is returned.

blindPath($thePath)   X-Ref
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.

param: string        $thePath is a path which MUST be found within one of the internally set filemounts, $this->mounts
return: string        The processed input path

findTempFolder()   X-Ref
Find temporary folder
Finds the first $this->tempFN ('_temp_' usually) -folder in the internal array of filemounts, $this->mounts

return: string        Returns the path if found, otherwise nothing if error.

cleanDirectoryName($theDir)   X-Ref
Removes all dots, slashes and spaces after a path...

param: string        Input string
return: string        Output string

rmDoubleSlash($string)   X-Ref
Converts any double slashes (//) to a single slash (/)

param: string        Input value
return: string        Returns the converted string

slashPath($path)   X-Ref
Returns a string which has a slash '/' appended if it doesn't already have that slash

param: string        Input string
return: string        Output string with a slash in the end (if not already there)

cleanFileName($fileName,$charset='')   X-Ref
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 current charset; depending on context)
return: string        Output string with any characters not matching [.a-zA-Z0-9_-] is substituted by '_'

formatSize($sizeInBytes)   X-Ref
Formats an integer, $sizeInBytes, to Mb or Kb or just bytes

param: integer        Bytes to be formated
return: string        Formatted with M,K or &nbsp;&nbsp; appended.



Généré le : Sun Nov 25 17:13:16 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics