TYPO3  7.6
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ExtendedFileUtility Class Reference
Inheritance diagram for ExtendedFileUtility:
BasicFileUtility

Public Member Functions

 getExistingFilesConflictMode ()
 
 setExistingFilesConflictMode ($existingFilesConflictMode)
 
 start ($fileCmds)
 
 setActionPermissions (array $permissions=array())
 
 processData ()
 
 pushErrorMessagesToFlashMessageQueue ()
 
 getErrorMessages ()
 
 writeLog ($action, $error, $details_nr, $details, $data)
 
 func_rename ($cmds)
 
 func_newfolder ($cmds)
 
 func_newfile ($cmds)
 
 func_edit ($cmds)
 
 func_unzip ($cmds)
 
- Public Member Functions inherited from BasicFileUtility
 init ($mounts, $f_ext)
 
 is_allowed ($iconkey, $type)
 
 checkIfFullAccess ($theDest)
 
 is_webpath ($path)
 
 checkIfAllowed ($ext, $theDest, $filename= '')
 
 is_directory ($theDir)
 
 getUniqueName ($theFile, $theDest, $dontCheckForUnique=0)
 
 checkPathAgainstMounts ($thePath)
 
 findFirstWebFolder ()
 
 slashPath ($path)
 
 cleanFileName ($fileName, $charset= '')
 

Public Attributes

 $unzipPath = ''
 
 $dontCheckForUnique = 0
 
 $actionPerms
 
 $recyclerFN = '_recycler_'
 
 $internalUploadMap = array()
 
 $lastError = ''
 
- Public Attributes inherited from BasicFileUtility
const UNSAFE_FILENAME_CHARACTER_EXPRESSION = '\\x00-\\x2C\\/\\x3A-\\x3F\\x5B-\\x60\\x7B-\\xBF'
 
 $getUniqueNamePrefix = ''
 
 $maxNumber = 99
 
 $uniquePrecision = 6
 
 $maxInputNameLen = 60
 
 $tempFN = '_temp_'
 
 $f_ext = array()
 
 $mounts = array()
 
 $webPath = ''
 
 $isInit = 0
 
 $csConvObj
 

Protected Member Functions

 transformFileReferenceToRecordReference (array $referenceRecord)
 
 getFileObject ($identifier)
 
 func_move ($cmds)
 
 replaceFile (array $cmdArr)
 
 getIndexer (ResourceStorage $storage)
 
 getDatabaseConnection ()
 
 getBackendUser ()
 

Protected Attributes

 $existingFilesConflictMode
 
 $errorMessages = array()
 
 $fileCmdMap
 
 $fileFactory
 

Detailed Description

Contains functions for performing file operations like copying, pasting, uploading, moving, deleting etc. through the TCE

See document "TYPO3 Core API" for syntax

This class contains functions primarily used by tce_file.php (TYPO3 Core Engine for file manipulation) Functions include copying, moving, deleting, uploading and so on...

Important internal variables:

$filemounts (see basicFileFunctions) $f_ext (see basicFileFunctions)

All fileoperations must be within the filemount-paths. Further the fileextension MUST validate TRUE with the f_ext array

The unzip-function allows unzip only if the destination path has it's f_ext[]['allow'] set to '*'!! You are allowed to copy/move folders within the same 'space' (web/ftp). You are allowed to copy/move folders between spaces (web/ftp) IF the destination has it's f_ext[]['allow'] set to '*'!

Advice: You should always exclude php-files from the webspace. This will keep people from uploading, copy/moving and renaming files to become executable php scripts. You should never mount a ftp_space 'below' the webspace so that it reaches into the webspace. This is because if somebody unzips a zip-file in the ftp-space so that it reaches out into the webspace this will be a violation of the safety For example this is a bad idea: you have an ftp-space that is '/www/' and a web-space that is '/www/htdocs/'

Definition at line 59 of file ExtendedFileUtility.php.

Member Function Documentation

func_edit (   $cmds)

Editing textfiles or folders (action=9)

Parameters
array$cmds$cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
Returns
bool Returns TRUE on success

Definition at line 899 of file ExtendedFileUtility.php.

References $GLOBALS, ExtendedFileUtility\getFileObject(), and GeneralUtility\inList().

Referenced by ExtendedFileUtility\processData().

func_move (   $cmds)
protected

Moving files and folders (action=3)

$cmds['data'] (string): The file/folder to move

  • example "4:mypath/tomyfolder/myfile.jpg")
  • for backwards compatibility: the identifier was the path+filename $cmds['target'] (string): The path where to move to.
  • example "2:targetpath/targetfolder/" $cmds['altName'] (string): Use an alternative name if the target already exists
Parameters
array$cmdsCommand details as described above
Returns

Definition at line 690 of file ExtendedFileUtility.php.

References DuplicationBehavior\CANCEL, ExtendedFileUtility\getFileObject(), and DuplicationBehavior\RENAME.

Referenced by ExtendedFileUtility\processData().

func_newfile (   $cmds)

This creates a new file. (action=8) $cmds['data'] (string): The new file name $cmds['target'] (string): The path where to create it.

  • example "2:targetpath/targetfolder/"
Parameters
array$cmdsCommand details as described above
Returns
string Returns the new filename upon success

Definition at line 862 of file ExtendedFileUtility.php.

References ExtendedFileUtility\getFileObject(), and ExtendedFileUtility\writeLog().

Referenced by ExtendedFileUtility\processData().

func_newfolder (   $cmds)

This creates a new folder. (action=6)

$cmds['data'] (string): The new folder name $cmds['target'] (string): The path where to copy to.

  • example "2:targetpath/targetfolder/"
Parameters
array$cmdsCommand details as described above
Returns
Returns the new foldername upon success

Definition at line 824 of file ExtendedFileUtility.php.

References ExtendedFileUtility\getFileObject().

Referenced by ExtendedFileUtility\processData().

func_rename (   $cmds)

Renaming files or foldes (action=5)

$cmds['data'] (string): The file/folder to copy

  • example "4:mypath/tomyfolder/myfile.jpg")
  • for backwards compatibility: the identifier was the path+filename $cmds['target'] (string): New name of the file/folder
Parameters
array$cmdsCommand details as described above
Returns
Returns the new file upon success

Definition at line 770 of file ExtendedFileUtility.php.

References ExtendedFileUtility\getFileObject().

Referenced by ExtendedFileUtility\processData().

func_unzip (   $cmds)

Unzipping file (action=7) This is permitted only if the user has fullAccess or if the file resides

Parameters
array$cmds$cmds['data'] is the zip-file. $cmds['target'] is the target directory. If not set we'll default to the same directory as the file is in.
Returns
bool Returns TRUE on success

Definition at line 1040 of file ExtendedFileUtility.php.

References BasicFileUtility\checkIfFullAccess(), BasicFileUtility\checkPathAgainstMounts(), CommandUtility\exec(), BasicFileUtility\is_directory(), and GeneralUtility\split_fileref().

Referenced by ExtendedFileUtility\processData().

getBackendUser ( )
protected
Returns

Definition at line 1191 of file ExtendedFileUtility.php.

References $GLOBALS.

Referenced by ExtendedFileUtility\writeLog().

getDatabaseConnection ( )
protected

Get database connection

Returns

Definition at line 1183 of file ExtendedFileUtility.php.

References $GLOBALS.

Referenced by ExtendedFileUtility\transformFileReferenceToRecordReference().

getErrorMessages ( )

Return all error messages from the file operations of this script instance

Returns
array all errorMessages as a numerical array

Definition at line 343 of file ExtendedFileUtility.php.

References ExtendedFileUtility\$errorMessages.

Referenced by ExtendedFileUtility\pushErrorMessagesToFlashMessageQueue().

getExistingFilesConflictMode ( )

Get existingFilesConflictMode

Returns
string

Definition at line 157 of file ExtendedFileUtility.php.

References ExtendedFileUtility\$existingFilesConflictMode.

getFileObject (   $identifier)
protected

Gets a File or a Folder object from an identifier [storage]:[fileId]

Parameters
string$identifier
Returns
|
Exceptions
\TYPO3\CMS\Core\Resource\Exception\InvalidFileException

Definition at line 588 of file ExtendedFileUtility.php.

Referenced by ExtendedFileUtility\func_edit(), ExtendedFileUtility\func_move(), ExtendedFileUtility\func_newfile(), ExtendedFileUtility\func_newfolder(), ExtendedFileUtility\func_rename(), and ExtendedFileUtility\replaceFile().

getIndexer ( ResourceStorage  $storage)
protected

Gets Indexer

Parameters
\TYPO3\CMS\Core\Resource\ResourceStorage$storage
Returns

Definition at line 1173 of file ExtendedFileUtility.php.

References GeneralUtility\makeInstance().

processData ( )

Processing the command array in $this->fileCmdMap

Returns
mixed FALSE, if the file functions were not initialized
Exceptions
\UnexpectedValueException

Definition at line 225 of file ExtendedFileUtility.php.

References $GLOBALS, ExtendedFileUtility\func_edit(), ExtendedFileUtility\func_move(), ExtendedFileUtility\func_newfile(), ExtendedFileUtility\func_newfolder(), ExtendedFileUtility\func_rename(), ExtendedFileUtility\func_unzip(), GeneralUtility\getUserObj(), ExtendedFileUtility\replaceFile(), and ExtendedFileUtility\writeLog().

pushErrorMessagesToFlashMessageQueue ( )

Adds all log error messages from the operations of this script instance to the FlashMessageQueue

Returns
void

Definition at line 324 of file ExtendedFileUtility.php.

References AbstractMessage\ERROR, ExtendedFileUtility\getErrorMessages(), and GeneralUtility\makeInstance().

replaceFile ( array  $cmdArr)
protected

Replaces a file on the filesystem and changes the identifier of the persisted file object in sys_file if keepFilename is not checked. If keepFilename is checked, only the file content will be replaced.

Parameters
array$cmdArr
Returns
array|bool
Exceptions
\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
\TYPO3\CMS\Core\Resource\Exception\InvalidFileException

Definition at line 1095 of file ExtendedFileUtility.php.

References ExtendedFileUtility\getFileObject(), DuplicationBehavior\RENAME, and DuplicationBehavior\REPLACE.

Referenced by ExtendedFileUtility\processData().

setActionPermissions ( array  $permissions = array())

Sets the file action permissions. If no argument is given, permissions of the currently logged in backend user are taken into account.

Parameters
array$permissionsFile Permissions.
Returns
void

Definition at line 211 of file ExtendedFileUtility.php.

References $GLOBALS.

setExistingFilesConflictMode (   $existingFilesConflictMode)

Set existingFilesConflictMode

Parameters
\TYPO3\CMS\Core\Resource\DuplicationBehavior | string$existingFilesConflictModeInstance or constant of
Returns
void
Exceptions
Exception

Definition at line 169 of file ExtendedFileUtility.php.

References ExtendedFileUtility\$existingFilesConflictMode, Enumeration\cast(), and Enumeration\getConstants().

start (   $fileCmds)

Initialization of the class

Parameters
array$fileCmdsArray with the commands to execute. See "TYPO3 Core API" document
Returns
void

Definition at line 190 of file ExtendedFileUtility.php.

References $GLOBALS, ExtendedFileUtility\$unzipPath, and ResourceFactory\getInstance().

transformFileReferenceToRecordReference ( array  $referenceRecord)
protected

Maps results from the fal file reference table on the structure of the normal reference index table.

Parameters
array$referenceRecord
Returns
array

Definition at line 564 of file ExtendedFileUtility.php.

References ExtendedFileUtility\getDatabaseConnection().

writeLog (   $action,
  $error,
  $details_nr,
  $details,
  $data 
)
Parameters
int$actionThe action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
int$errorThe severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
int$details_nrThis number is unique for every combination of $type and $action. This is the error-message number, which can later be used to translate error messages.
string$detailsThis is the default, raw error message in english
array$dataArray with special information that may go into $details by "%s" marks / sprintf() when the log is shown
Returns
void

Definition at line 356 of file ExtendedFileUtility.php.

References ExtendedFileUtility\$lastError, and ExtendedFileUtility\getBackendUser().

Referenced by ExtendedFileUtility\func_newfile(), and ExtendedFileUtility\processData().

Member Data Documentation

$actionPerms
Initial value:
= array(
'addFile' => false,
'readFile' => false,
'writeFile' => false,
'copyFile' => false,
'moveFile' => false,
'renameFile' => false,
'unzipFile' => false,
'deleteFile' => false,
'addFolder' => false,
'readFolder' => false,
'writeFolder' => false,
'copyFolder' => false,
'moveFolder' => false,
'renameFolder' => false,
'deleteFolder' => false,
'recursivedeleteFolder' => false
)

Definition at line 93 of file ExtendedFileUtility.php.

$dontCheckForUnique = 0

Definition at line 76 of file ExtendedFileUtility.php.

$errorMessages = array()
protected

Definition at line 138 of file ExtendedFileUtility.php.

Referenced by ExtendedFileUtility\getErrorMessages().

$existingFilesConflictMode
protected
$fileCmdMap
protected

Definition at line 143 of file ExtendedFileUtility.php.

$fileFactory
protected

Definition at line 150 of file ExtendedFileUtility.php.

$internalUploadMap = array()

Definition at line 126 of file ExtendedFileUtility.php.

$lastError = ''

Definition at line 131 of file ExtendedFileUtility.php.

Referenced by ExtendedFileUtility\writeLog().

$recyclerFN = '_recycler_'

Definition at line 119 of file ExtendedFileUtility.php.

$unzipPath = ''

Definition at line 68 of file ExtendedFileUtility.php.

Referenced by ExtendedFileUtility\start().