Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

t3lib_extFileFunctions Class Reference

Inherits t3lib_basicFileFunctions.

List of all members.

Public Member Functions

 start ($fileCmds)
 Initialization of the class.
 init_actionPerms ($setup)
 Sets up permission to perform file/directory operations.
 processData ()
 Processing the command array in $this->fileCmdMap.
 printLogErrorMessages ($redirect='')
 Print log error messages from the operations of this script instance.
 findRecycler ($theFile)
 Goes back in the path and checks in each directory if a folder named $this->recyclerFN (usually '_recycler_') is present.
 writeLog ($action, $error, $details_nr, $details, $data)
 Logging file operations.
 func_delete ($cmds)
 Deleting files and folders (action=4).
 func_copy ($cmds)
 Copying files and folders (action=2).
 func_move ($cmds)
 Moving files and folders (action=3).
 func_rename ($cmds)
 Renaming files or foldes (action=5).
 func_newfolder ($cmds)
 This creates a new folder.
 func_newfile ($cmds)
 This creates a new file.
 func_edit ($cmds)
 Editing textfiles or foldes (action=9).
 func_upload ($cmds)
 Upload of files (action=1).
 func_unzip ($cmds)
 Unzipping file (action=7) This is permitted only if the user has fullAccess or if the file resides.

Public Attributes

 $maxCopyFileSize = 10000
 $maxMoveFileSize = 10000
 $maxUploadFileSize = 10000
 $unzipPath = ''
 $dontCheckForUnique = 0
 $actionPerms
 $recyclerFN = '_recycler_'
 $useRecycler = 1
 $PHPFileFunctions = 0
 $dont_use_exec_commands = 0


Member Function Documentation

t3lib_extFileFunctions::findRecycler theFile  ) 
 

Goes back in the path and checks in each directory if a folder named $this->recyclerFN (usually '_recycler_') is present.

If a folder in the tree happens to be a _recycler_-folder (which means that we're deleting something inside a _recycler_-folder) this is ignored

Parameters:
string Takes a valid Path ($theFile)
Returns:
string Returns the path (without trailing slash) of the closest recycle-folder if found. Else false.

Definition at line 326 of file class.t3lib_extfilefunc.php.

References t3lib_basicFileFunctions::checkPathAgainstMounts(), t3lib_basicFileFunctions::cleanDirectoryName(), and t3lib_basicFileFunctions::isPathValid().

Referenced by func_delete().

00326                                     {
00327       if ($this->isPathValid($theFile))   {
00328          $theFile = $this->cleanDirectoryName($theFile);
00329          $fI = t3lib_div::split_fileref($theFile);
00330          $c = 0;
00331          while($this->checkPathAgainstMounts($fI['path']) && $c<20)  {
00332             $rDir = $fI['path'].$this->recyclerFN;
00333             if (@is_dir($rDir) && $this->recyclerFN!=$fI['file']) {
00334                return $rDir;
00335             }
00336             $theFile = $fI['path'];
00337             $theFile = $this->cleanDirectoryName($theFile);
00338             $fI = t3lib_div::split_fileref($theFile);
00339             $c++;
00340          }
00341       }
00342    }

t3lib_extFileFunctions::func_copy cmds  ) 
 

Copying files and folders (action=2).

Parameters:
array $cmds['data'] is the the file/folder to copy. $cmds['target'] is the path where to copy to. $cmds['altName'] (boolean): If set, another filename is found in case the target already exists
Returns:
string Returns the new filename upon success

Definition at line 449 of file class.t3lib_extfilefunc.php.

References t3lib_basicFileFunctions::checkIfAllowed(), t3lib_basicFileFunctions::checkIfFullAccess(), t3lib_basicFileFunctions::checkPathAgainstMounts(), t3lib_basicFileFunctions::getUniqueName(), t3lib_basicFileFunctions::is_directory(), t3lib_basicFileFunctions::isPathValid(), and writelog().

Referenced by processData().

00449                               {
00450       if (!$this->isInit) return FALSE;
00451 
00452          // Initialize and check basic conditions:
00453       $theFile = $cmds['data'];
00454       $theDest = $this->is_directory($cmds['target']);   // Clean up destination directory
00455       $altName = $cmds['altName'];
00456       if (!$theDest) {
00457          $this->writelog(2,2,100,'Destination "%s" was not a directory',Array($cmds['target']));
00458          return FALSE;
00459       }
00460       if (!$this->isPathValid($theFile) || !$this->isPathValid($theDest))  {
00461          $this->writelog(2,2,101,'Target or destination had invalid path (".." and "//" is not allowed in path). T="%s", D="%s"',Array($theFile,$theDest));
00462          return FALSE;
00463       }
00464 
00465          // Processing of file or directory.
00466       if (@is_file($theFile)) {  // If we are copying a file...
00467          if ($this->actionPerms['copyFile']) {
00468             if (filesize($theFile) < ($this->maxCopyFileSize*1024))  {
00469                $fI = t3lib_div::split_fileref($theFile);
00470                if ($altName)  {  // If altName is set, we're allowed to create a new filename if the file already existed
00471                   $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00472                   $fI = t3lib_div::split_fileref($theDestFile);
00473                } else {
00474                   $theDestFile = $theDest.'/'.$fI['file'];
00475                }
00476                if ($theDestFile && !@file_exists($theDestFile))   {
00477                   if ($this->checkIfAllowed($fI['fileext'], $theDest, $fI['file'])) {
00478                      if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile))  {
00479                         if ($this->PHPFileFunctions)  {
00480                            copy ($theFile,$theDestFile);
00481                         } else {
00482                            $cmd = 'cp "'.$theFile.'" "'.$theDestFile.'"';
00483                            exec($cmd);
00484                         }
00485                         clearstatcache();
00486                         if (@is_file($theDestFile))   {
00487                            $this->writelog(2,0,1,'File "%s" copied to "%s"',Array($theFile,$theDestFile));
00488                            return $theDestFile;
00489                         } else $this->writelog(2,2,109,'File "%s" WAS NOT copied to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00490                      } else   $this->writelog(2,1,110,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00491                   } else $this->writelog(2,1,111,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theDest.'/'));
00492                } else $this->writelog(2,1,112,'File "%s" already exists!',Array($theDestFile));
00493             } else $this->writelog(2,1,113,'File "%s" exceeds the size-limit of %s bytes',Array($theFile,$this->maxCopyFileSize*1024));
00494          } else $this->writelog(2,1,114,'You are not allowed to copy files','');
00495          // FINISHED copying file
00496 
00497       } elseif (@is_dir($theFile) && !$this->dont_use_exec_commands) {     // if we're copying a folder
00498          if ($this->actionPerms['copyFolder'])  {
00499             $theFile = $this->is_directory($theFile);
00500             if ($theFile)  {
00501                $fI = t3lib_div::split_fileref($theFile);
00502                if ($altName)  {  // If altName is set, we're allowed to create a new filename if the file already existed
00503                   $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00504                   $fI = t3lib_div::split_fileref($theDestFile);
00505                } else {
00506                   $theDestFile = $theDest.'/'.$fI['file'];
00507                }
00508                if ($theDestFile && !@file_exists($theDestFile))   {
00509                   if (!t3lib_div::isFirstPartOfStr($theDestFile.'/',$theFile.'/'))  {        // Check if the one folder is inside the other or on the same level... to target/dest is the same?
00510                      if ($this->checkIfFullAccess($theDest) || $this->is_webPath($theDestFile)==$this->is_webPath($theFile))  {  // no copy of folders between spaces
00511                         if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile))  {
00512                               // No way to do this under windows!
00513                            $cmd = 'cp -R "'.$theFile.'" "'.$theDestFile.'"';
00514                            exec($cmd);
00515                            clearstatcache();
00516                            if (@is_dir($theDestFile)) {
00517                               $this->writelog(2,0,2,'Directory "%s" copied to "%s"',Array($theFile,$theDestFile));
00518                               return $theDestFile;
00519                            } else $this->writelog(2,2,119,'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00520                         } else $this->writelog(2,1,120,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00521                      } else $this->writelog(2,1,121,'You don\'t have full access to the destination directory "%s"!',Array($theDest.'/'));
00522                   } else $this->writelog(2,1,122,'Destination cannot be inside the target! D="%s", T="%s"',Array($theDestFile.'/',$theFile.'/'));
00523                } else $this->writelog(2,1,123,'Target "%s" already exists!',Array($theDestFile));
00524             } else $this->writelog(2,2,124,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00525          } else $this->writelog(2,1,125,'You are not allowed to copy directories','');
00526          // FINISHED copying directory
00527 
00528       } else {
00529          $this->writelog(2,2,130,'The item "%s" was not a file or directory!',Array($theFile));
00530       }
00531    }

t3lib_extFileFunctions::func_delete cmds  ) 
 

Deleting files and folders (action=4).

Parameters:
array $cmds['data'] is the the file/folder to delete
Returns:
boolean Returns true upon success

Definition at line 382 of file class.t3lib_extfilefunc.php.

References t3lib_basicFileFunctions::checkPathAgainstMounts(), findRecycler(), func_move(), t3lib_basicFileFunctions::is_directory(), t3lib_basicFileFunctions::isPathValid(), and writelog().

Referenced by processData().

00382                                  {
00383       if (!$this->isInit) return FALSE;
00384 
00385          // Checking path:
00386       $theFile = $cmds['data'];
00387       if (!$this->isPathValid($theFile))  {
00388          $this->writelog(4,2,101,'Target "%s" had invalid path (".." and "//" is not allowed in path).',Array($theFile));
00389          return FALSE;
00390       }
00391 
00392          // Recycler moving or not?
00393       if ($this->useRecycler && $recyclerPath=$this->findRecycler($theFile))  {
00394             // If a recycler is found, the deleted items is moved to the recycler and not just deleted.
00395          $newCmds=Array();
00396          $newCmds['data']=$theFile;
00397          $newCmds['target']=$recyclerPath;
00398          $newCmds['altName']=1;
00399          $this->func_move($newCmds);
00400          $this->writelog(4,0,4,'Item "%s" moved to recycler at "%s"',Array($theFile,$recyclerPath));
00401          return TRUE;
00402       } elseif ($this->useRecycler != 2) {   // if $this->useRecycler==2 then we cannot delete for real!!
00403          if (@is_file($theFile)) {  // If we are deleting a file...
00404             if ($this->actionPerms['deleteFile'])  {
00405                if ($this->checkPathAgainstMounts($theFile)) {
00406                   if (@unlink($theFile))  {
00407                      $this->writelog(4,0,1,'File "%s" deleted',Array($theFile));
00408                      return TRUE;
00409                   } else $this->writelog(4,1,110,'Could not delete file "%s". Write-permission problem?', Array($theFile));
00410                } else $this->writelog(4,1,111,'Target was not within your mountpoints! T="%s"',Array($theFile));
00411             } else $this->writelog(4,1,112,'You are not allowed to delete files','');
00412             // FINISHED deleting file
00413 
00414          } elseif (@is_dir($theFile) && !$this->dont_use_exec_commands) {  // if we're deleting a folder
00415             if ($this->actionPerms['deleteFolder'])   {
00416                $theFile = $this->is_directory($theFile);
00417                if ($theFile)  {
00418                   if ($this->checkPathAgainstMounts($theFile)) {  // I choose not to append '/' to $theFile here as this will prevent us from deleting mounts!! (which makes sense to me...)
00419                      if ($this->actionPerms['deleteFolderRecursively']) {
00420                            // No way to do this under windows
00421                         $cmd = 'rm -Rf "'.$theFile.'"';
00422                         exec($cmd);    // This is a quite critical command...
00423                         clearstatcache();
00424                         if (!@file_exists($theFile))  {
00425                            $this->writelog(4,0,2,'Directory "%s" deleted recursively!',Array($theFile));
00426                            return TRUE;
00427                         } else $this->writelog(4,2,119,'Directory "%s" WAS NOT deleted recursively! Write-permission problem?',Array($theFile));
00428                      } else {
00429                         if (@rmdir($theFile))   {
00430                            $this->writelog(4,0,3,'Directory "%s" deleted',Array($theFile));
00431                            return TRUE;
00432                         } else $this->writelog(4,1,120,'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).',Array($theFile));
00433                      }
00434                   } else $this->writelog(4,1,121,'Target was not within your mountpoints! T="%s"',Array($theFile));
00435                } else $this->writelog(4,2,122,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00436             } else $this->writelog(4,1,123,'You are not allowed to delete directories','');
00437             // FINISHED copying directory
00438 
00439          } else $this->writelog(4,2,130,'The item was not a file or directory! "%s"',Array($theFile));
00440       } else $this->writelog(4,1,131,'No recycler found!','');
00441    }

t3lib_extFileFunctions::func_edit cmds  ) 
 

Editing textfiles or foldes (action=9).

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

Definition at line 745 of file class.t3lib_extfilefunc.php.

References $content, $theTarget, t3lib_basicFileFunctions::checkIfAllowed(), t3lib_basicFileFunctions::checkPathAgainstMounts(), and writelog().

Referenced by processData().

00745                               {
00746       if (!$this->isInit) return FALSE;
00747       $theTarget = $cmds['target'];
00748       $content = $cmds['data'];
00749       $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
00750       $type = filetype($theTarget);
00751       if ($type=='file')   {     // $type MUST BE file
00752          $fileInfo = t3lib_div::split_fileref($theTarget);     // Fetches info about path, name, extention of $theTarget
00753          $fI =$fileInfo;
00754          if ($this->checkPathAgainstMounts($fileInfo['path'])) {
00755             if ($this->actionPerms['editFile']) {
00756                $fI = t3lib_div::split_fileref($theTarget);
00757                if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00758                   if (t3lib_div::inList($extList, $fileInfo['fileext']))   {
00759                      if (t3lib_div::writeFile($theTarget,$content))  {
00760                         clearstatcache();
00761                         $this->writelog(9,0,1,'File saved to "%s", bytes: %s, MD5: %s ',Array($fileInfo['file'],@filesize($theTarget),md5($content)));
00762                         return TRUE;
00763                      } else $this->writelog(9,1,100,'File "%s" was not saved! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00764                   } else $this->writelog(9,1,102,'Fileextension "%s" is not a textfile format! (%s)',Array($fI['fileext'], $extList));
00765                } else $this->writelog(9,1,103,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00766             } else $this->writelog(9,1,104,'You are not allowed to edit files!','');
00767          } else $this->writelog(9,1,121,'Destination path "%s" was not within your mountpoints!',Array($fileInfo['path']));
00768       } else $this->writelog(9,2,123,'Target "%s" was not a file!',Array($theTarget));
00769    }

t3lib_extFileFunctions::func_move cmds  ) 
 

Moving files and folders (action=3).

Parameters:
array $cmds['data'] is the the file/folder to move. $cmds['target'] is the path where to move to. $cmds['altName'] (boolean): If set, another filename is found in case the target already exists
Returns:
string Returns the new filename upon success

Definition at line 539 of file class.t3lib_extfilefunc.php.

References t3lib_basicFileFunctions::checkIfAllowed(), t3lib_basicFileFunctions::checkIfFullAccess(), t3lib_basicFileFunctions::checkPathAgainstMounts(), t3lib_basicFileFunctions::getUniqueName(), t3lib_basicFileFunctions::is_directory(), t3lib_basicFileFunctions::isPathValid(), and writelog().

Referenced by func_delete(), and processData().

00539                               {
00540       if (!$this->isInit) return FALSE;
00541 
00542          // Initialize and check basic conditions:
00543       $theFile = $cmds['data'];
00544       $theDest = $this->is_directory($cmds['target']);   // Clean up destination directory
00545       $altName = $cmds['altName'];
00546       if (!$theDest) {
00547          $this->writelog(3,2,100,'Destination "%s" was not a directory',Array($cmds['target']));
00548          return FALSE;
00549       }
00550       if (!$this->isPathValid($theFile) || !$this->isPathValid($theDest))  {
00551          $this->writelog(3,2,101,'Target or destination had invalid path (".." and "//" is not allowed in path). T="%s", D="%s"',Array($theFile,$theDest));
00552          return FALSE;
00553       }
00554 
00555          // Processing of file or directory:
00556       if (@is_file($theFile)) {  // If we are moving a file...
00557          if ($this->actionPerms['moveFile']) {
00558             if (filesize($theFile) < ($this->maxMoveFileSize*1024))  {
00559                $fI = t3lib_div::split_fileref($theFile);
00560                if ($altName)  {  // If altName is set, we're allowed to create a new filename if the file already existed
00561                   $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00562                   $fI = t3lib_div::split_fileref($theDestFile);
00563                } else {
00564                   $theDestFile = $theDest.'/'.$fI['file'];
00565                }
00566                if ($theDestFile && !@file_exists($theDestFile))   {
00567                   if ($this->checkIfAllowed($fI['fileext'], $theDest, $fI['file'])) {
00568                      if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile))  {
00569                         if ($this->PHPFileFunctions)  {
00570                            rename($theFile, $theDestFile);
00571                         } else {
00572                            $cmd = 'mv "'.$theFile.'" "'.$theDestFile.'"';
00573                            exec($cmd);
00574                         }
00575                         clearstatcache();
00576                         if (@is_file($theDestFile))   {
00577                            $this->writelog(3,0,1,'File "%s" moved to "%s"',Array($theFile,$theDestFile));
00578                            return $theDestFile;
00579                         } else $this->writelog(3,2,109,'File "%s" WAS NOT moved to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00580                      } else $this->writelog(3,1,110,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00581                   } else $this->writelog(3,1,111,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theDest.'/'));
00582                } else $this->writelog(3,1,112,'File "%s" already exists!',Array($theDestFile));
00583             } else $this->writelog(3,1,113,'File "%s" exceeds the size-limit of %s bytes',Array($theFile,$this->maxMoveFileSize*1024));
00584          } else $this->writelog(3,1,114,'You are not allowed to move files','');
00585          // FINISHED moving file
00586 
00587       } elseif (@is_dir($theFile)) {   // if we're moving a folder
00588          if ($this->actionPerms['moveFolder'])  {
00589             $theFile = $this->is_directory($theFile);
00590             if ($theFile)  {
00591                $fI = t3lib_div::split_fileref($theFile);
00592                if ($altName)  {  // If altName is set, we're allowed to create a new filename if the file already existed
00593                   $theDestFile = $this->getUniqueName($fI['file'], $theDest);
00594                   $fI = t3lib_div::split_fileref($theDestFile);
00595                } else {
00596                   $theDestFile = $theDest.'/'.$fI['file'];
00597                }
00598                if ($theDestFile && !@file_exists($theDestFile))   {
00599                   if (!t3lib_div::isFirstPartOfStr($theDestFile.'/',$theFile.'/'))  {        // Check if the one folder is inside the other or on the same level... to target/dest is the same?
00600                      if ($this->checkIfFullAccess($theDest) || $this->is_webPath($theDestFile)==$this->is_webPath($theFile))  {  // // no moving of folders between spaces
00601                         if ($this->checkPathAgainstMounts($theDestFile) && $this->checkPathAgainstMounts($theFile))  {
00602                            if ($this->PHPFileFunctions)  {
00603                               rename($theFile, $theDestFile);
00604                            } else {
00605                               $cmd = 'mv "'.$theFile.'" "'.$theDestFile.'"';
00606                               exec($cmd,$errArr,$retVar);
00607                            }
00608                            clearstatcache();
00609                            if (@is_dir($theDestFile)) {
00610                               $this->writelog(3,0,2,'Directory "%s" moved to "%s"',Array($theFile,$theDestFile));
00611                               return $theDestFile;
00612                            } else $this->writelog(3,2,119,'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?',Array($theFile,$theDestFile));
00613                         } else $this->writelog(3,1,120,'Target or destination was not within your mountpoints! T="%s", D="%s"',Array($theFile,$theDestFile));
00614                      } else $this->writelog(3,1,121,'You don\'t have full access to the destination directory "%s"!',Array($theDest.'/'));
00615                   } else $this->writelog(3,1,122,'Destination cannot be inside the target! D="%s", T="%s"',Array($theDestFile.'/',$theFile.'/'));
00616                } else $this->writelog(3,1,123,'Target "%s" already exists!',Array($theDestFile));
00617             } else $this->writelog(3,2,124,'Target seemed not to be a directory! (Shouldn\'t happen here!)','');
00618          } else $this->writelog(3,1,125,'You are not allowed to move directories','');
00619          // FINISHED moving directory
00620 
00621       } else {
00622          $this->writelog(3,2,130,'The item "%s" was not a file or directory!',Array($theFile));
00623       }
00624    }

t3lib_extFileFunctions::func_newfile cmds  ) 
 

This creates a new file.

(action=8)

Parameters:
array $cmds['data'] is the new filename. $cmds['target'] is the path where to create it
Returns:
string Returns the new filename upon success

Definition at line 708 of file class.t3lib_extfilefunc.php.

References $theTarget, t3lib_basicFileFunctions::checkFileNameLen(), t3lib_basicFileFunctions::checkIfAllowed(), t3lib_basicFileFunctions::checkPathAgainstMounts(), t3lib_basicFileFunctions::cleanFileName(), t3lib_basicFileFunctions::is_directory(), and writelog().

Referenced by processData().

00708                                  {
00709       $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
00710       if (!$this->isInit) return FALSE;
00711       $newName = $this->cleanFileName($cmds['data']);
00712       if ($newName)  {
00713          if ($this->checkFileNameLen($newName)) {
00714             $theTarget = $this->is_directory($cmds['target']); // Check the target dir
00715             $fileInfo = t3lib_div::split_fileref($theTarget);     // Fetches info about path, name, extention of $theTarget
00716             if ($theTarget)   {
00717                if ($this->actionPerms['newFile'])  {
00718                   $theNewFile = $theTarget.'/'.$newName;
00719                   if ($this->checkPathAgainstMounts($theNewFile)) {
00720                      if (!@file_exists($theNewFile))  {
00721                         $fI = t3lib_div::split_fileref($theNewFile);
00722                         if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00723                            if (t3lib_div::inList($extList, $fI['fileext']))   {
00724                               if (t3lib_div::writeFile($theNewFile,'')) {
00725                                  clearstatcache();
00726                                  $this->writelog(8,0,1,'File created: "%s"',Array($fI['file']));
00727                                  return $theNewFile;
00728                               } else $this->writelog(8,1,100,'File "%s" was not created! Write-permission problem in "%s"?',Array($fI['file'], $theTarget));
00729                            } else $this->writelog(8,1,107,'Fileextension "%s" is not a textfile format! (%s)',Array($fI['fileext'], $extList));
00730                         } else $this->writelog(8,1,106,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00731                      } else $this->writelog(8,1,101,'File "%s" existed already!',Array($theNewFile));
00732                   } else $this->writelog(8,1,102,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00733                } else $this->writelog(8,1,103,'You are not allowed to create files!','');
00734             } else $this->writelog(8,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00735          } else $this->writelog(8,1,105,'New name "%s" was too long (max %s characters)',Array($newName,$this->maxInputNameLen));
00736       }
00737    }

t3lib_extFileFunctions::func_newfolder cmds  ) 
 

This creates a new folder.

(action=6)

Parameters:
array $cmds['data'] is the foldername. $cmds['target'] is the path where to create it.
Returns:
string Returns the new foldername upon success

Definition at line 678 of file class.t3lib_extfilefunc.php.

References $theTarget, t3lib_basicFileFunctions::checkFileNameLen(), t3lib_basicFileFunctions::checkPathAgainstMounts(), t3lib_basicFileFunctions::cleanFileName(), t3lib_basicFileFunctions::is_directory(), and writelog().

Referenced by processData().

00678                                     {
00679       if (!$this->isInit) return FALSE;
00680 
00681       $theFolder = $this->cleanFileName($cmds['data']);
00682       if ($theFolder)   {
00683          if ($this->checkFileNameLen($theFolder))  {
00684             $theTarget = $this->is_directory($cmds['target']); // Check the target dir
00685             if ($theTarget)   {
00686                if ($this->actionPerms['newFolder'])   {
00687                   $theNewFolder = $theTarget.'/'.$theFolder;
00688                   if ($this->checkPathAgainstMounts($theNewFolder))  {
00689                      if (!@file_exists($theNewFolder))   {
00690                         if (t3lib_div::mkdir($theNewFolder)){
00691                            $this->writelog(6,0,1,'Directory "%s" created in "%s"',Array($theFolder,$theTarget.'/'));
00692                            return $theNewFolder;
00693                         } else $this->writelog(6,1,100,'Directory "%s" not created. Write-permission problem in "%s"?',Array($theFolder,$theTarget.'/'));
00694                      } else $this->writelog(6,1,101,'File or directory "%s" existed already!',Array($theNewFolder));
00695                   } else $this->writelog(6,1,102,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00696                } else $this->writelog(6,1,103,'You are not allowed to create directories!','');
00697             } else $this->writelog(6,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00698          } else $this->writelog(6,1,105,'New name "%s" was too long (max %s characters)',Array($theFolder,$this->maxInputNameLen));
00699       }
00700    }

t3lib_extFileFunctions::func_rename cmds  ) 
 

Renaming files or foldes (action=5).

Parameters:
array $cmds['data'] is the new name. $cmds['target'] is the target (file or dir).
Returns:
string Returns the new filename upon success

Definition at line 632 of file class.t3lib_extfilefunc.php.

References $theTarget, t3lib_basicFileFunctions::checkFileNameLen(), t3lib_basicFileFunctions::checkIfAllowed(), t3lib_basicFileFunctions::checkPathAgainstMounts(), t3lib_basicFileFunctions::cleanFileName(), and writelog().

Referenced by processData().

00632                                  {
00633       if (!$this->isInit) return FALSE;
00634 
00635       $theNewName = $this->cleanFileName($cmds['data']);
00636       if ($theNewName)  {
00637          if ($this->checkFileNameLen($theNewName)) {
00638             $theTarget = $cmds['target'];
00639             $type = filetype($theTarget);
00640             if ($type=='file' || $type=='dir')  {     // $type MUST BE file or dir
00641                $fileInfo = t3lib_div::split_fileref($theTarget);     // Fetches info about path, name, extention of $theTarget
00642                if ($fileInfo['file']!=$theNewName) {  // The name should be different from the current. And the filetype must be allowed
00643                   $theRenameName = $fileInfo['path'].$theNewName;
00644                   if ($this->checkPathAgainstMounts($fileInfo['path'])) {
00645                      if (!@file_exists($theRenameName))  {
00646                         if ($type=='file')   {
00647                            if ($this->actionPerms['renameFile'])  {
00648                               $fI = t3lib_div::split_fileref($theRenameName);
00649                               if ($this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
00650                                  if (@rename($theTarget, $theRenameName))  {
00651                                     $this->writelog(5,0,1,'File renamed from "%s" to "%s"',Array($fileInfo['file'],$theNewName));
00652                                     return $theRenameName;
00653                                  } else $this->writelog(5,1,100,'File "%s" was not renamed! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00654                               } else $this->writelog(5,1,101,'Fileextension "%s" was not allowed!',Array($fI['fileext']));
00655                            } else $this->writelog(5,1,102,'You are not allowed to rename files!','');
00656                         } elseif ($type=='dir') {
00657                            if ($this->actionPerms['renameFolder'])   {
00658                               if (@rename($theTarget, $theRenameName))  {
00659                                  $this->writelog(5,0,2,'Directory renamed from "%s" to "%s"',Array($fileInfo['file'],$theNewName));
00660                                  return $theRenameName;
00661                               } else $this->writelog(5,1,110,'Directory "%s" was not renamed! Write-permission problem in "%s"?',Array($theTarget,$fileInfo['path']));
00662                            } else $this->writelog(5,1,111,'You are not allowed to rename directories!','');
00663                         }
00664                      } else $this->writelog(5,1,120,'Destination "%s" existed already!',Array($theRenameName));
00665                   } else $this->writelog(5,1,121,'Destination path "%s" was not within your mountpoints!',Array($fileInfo['path']));
00666                } else $this->writelog(5,1,122,'Old and new name is the same (%s)',Array($theNewName));
00667             } else $this->writelog(5,2,123,'Target "%s" was neither a directory nor a file!',Array($theTarget));
00668          } else $this->writelog(5,1,124,'New name "%s" was too long (max %s characters)',Array($theNewName,$this->maxInputNameLen));
00669       }
00670    }

t3lib_extFileFunctions::func_unzip cmds  ) 
 

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

Parameters:
array $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:
boolean Returns true on success

Definition at line 815 of file class.t3lib_extfilefunc.php.

References t3lib_basicFileFunctions::checkIfFullAccess(), t3lib_basicFileFunctions::checkPathAgainstMounts(), t3lib_basicFileFunctions::is_directory(), and writelog().

Referenced by processData().

00815                               {
00816       if (!$this->isInit || $this->dont_use_exec_commands) return FALSE;
00817 
00818       $theFile = $cmds['data'];
00819       if (@is_file($theFile)) {
00820          $fI = t3lib_div::split_fileref($theFile);
00821          if (!isset($cmds['target']))  {
00822             $cmds['target'] = $fI['path'];
00823          }
00824          $theDest = $this->is_directory($cmds['target']);   // Clean up destination directory
00825          if ($theDest)  {
00826             if ($this->actionPerms['unzipFile'])   {
00827                if ($fI['fileext']=='zip') {
00828                   if ($this->checkIfFullAccess($theDest)) {
00829                      if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest.'/'))  {
00830                            // No way to do this under windows.
00831                         $cmd = $this->unzipPath.'unzip -qq "'.$theFile.'" -d "'.$theDest.'"';
00832                         exec($cmd);
00833                         $this->writelog(7,0,1,'Unzipping file "%s" in "%s"',Array($theFile,$theDest));
00834                         return TRUE;
00835                      } else $this->writelog(7,1,100,'File "%s" or destination "%s" was not within your mountpoints!',Array($theFile,$theDest));
00836                   } else $this->writelog(7,1,101,'You don\'t have full access to the destination directory "%s"!',Array($theDest));
00837                } else $this->writelog(7,1,102,'Fileextension is not "zip"','');
00838             } else $this->writelog(7,1,103,'You are not allowed to unzip files','');
00839          } else $this->writelog(7,2,104,'Destination "%s" was not a directory',Array($cmds['target']));
00840       } else $this->writelog(7,2,105,'The file "%s" did not exist!',Array($theFile));
00841    }

t3lib_extFileFunctions::func_upload cmds  ) 
 

Upload of files (action=1).

Parameters:
array $cmds['data'] is the ID-number (points to the global var that holds the filename-ref ($_FILES['upload_'.$id]['name']). $cmds['target'] is the target directory
Returns:
string Returns the new filename upon success

Definition at line 777 of file class.t3lib_extfilefunc.php.

References $theTarget, t3lib_basicFileFunctions::checkIfAllowed(), t3lib_basicFileFunctions::checkPathAgainstMounts(), t3lib_basicFileFunctions::cleanFileName(), t3lib_basicFileFunctions::getUniqueName(), t3lib_basicFileFunctions::is_directory(), and writelog().

Referenced by processData().

00777                                  {
00778       if (!$this->isInit) return FALSE;
00779       $id = $cmds['data'];
00780       if ($_FILES['upload_'.$id]['name']) {
00781          $theFile = $_FILES['upload_'.$id]['tmp_name'];           // filename of the uploaded file
00782          $theFileSize = $_FILES['upload_'.$id]['size'];           // filesize of the uploaded file
00783          $theName = $this->cleanFileName(stripslashes($_FILES['upload_'.$id]['name']));   // The original filename
00784          if (is_uploaded_file($theFile) && $theName)  {  // Check the file
00785             if ($this->actionPerms['uploadFile'])  {
00786                if ($theFileSize<($this->maxUploadFileSize*1024))  {
00787                   $fI = t3lib_div::split_fileref($theName);
00788                   $theTarget = $this->is_directory($cmds['target']); // Check the target dir
00789                   if ($theTarget && $this->checkPathAgainstMounts($theTarget.'/'))  {
00790                      if ($this->checkIfAllowed($fI['fileext'], $theTarget, $fI['file'])) {
00791                         $theNewFile = $this->getUniqueName($theName, $theTarget, $this->dontCheckForUnique);
00792                         if ($theNewFile)  {
00793                            t3lib_div::upload_copy_move($theFile,$theNewFile);
00794                            clearstatcache();
00795                            if (@is_file($theNewFile)) {
00796                               $this->writelog(1,0,1,'Uploading file "%s" to "%s"',Array($theName,$theNewFile, $id));
00797                               return $theNewFile;
00798                            } else $this->writelog(1,1,100,'Uploaded file could not be moved! Write-permission problem in "%s"?',Array($theTarget.'/'));
00799                         } else $this->writelog(1,1,101,'No unique filename available in "%s"!',Array($theTarget.'/'));
00800                      } else $this->writelog(1,1,102,'Fileextension "%s" is not allowed in "%s"!',Array($fI['fileext'],$theTarget.'/'));
00801                   } else $this->writelog(1,1,103,'Destination path "%s" was not within your mountpoints!',Array($theTarget.'/'));
00802                } else $this->writelog(1,1,104,'The uploaded file exceeds the size-limit of %s bytes',Array($this->maxUploadFileSize*1024));
00803             } else $this->writelog(1,1,105,'You are not allowed to upload files!','');
00804          } else $this->writelog(1,2,106,'The uploaded file did not exist!','');
00805       }
00806    }

t3lib_extFileFunctions::init_actionPerms setup  ) 
 

Sets up permission to perform file/directory operations.

See below or the be_user-table for the significanse of the various bits in $setup ($BE_USER->user['fileoper_perms'])

Parameters:
integer File permission integer from BE_USER object.
Returns:
void

Definition at line 179 of file class.t3lib_extfilefunc.php.

00179                                        {
00180       if (($setup&1)==1)   {     // Files: Upload,Copy,Move,Delete,Rename
00181          $this->actionPerms['uploadFile']=1;
00182          $this->actionPerms['copyFile']=1;
00183          $this->actionPerms['moveFile']=1;
00184          $this->actionPerms['deleteFile']=1;
00185          $this->actionPerms['renameFile']=1;
00186          $this->actionPerms['editFile']=1;
00187          $this->actionPerms['newFile']=1;
00188       }
00189       if (($setup&2)==2)   {     // Files: Unzip
00190          $this->actionPerms['unzipFile']=1;
00191       }
00192       if (($setup&4)==4)   {     // Directory: Move,Delete,Rename,New
00193          $this->actionPerms['moveFolder']=1;
00194          $this->actionPerms['deleteFolder']=1;
00195          $this->actionPerms['renameFolder']=1;
00196          $this->actionPerms['newFolder']=1;
00197       }
00198       if (($setup&8)==8)   {     // Directory: Copy
00199          $this->actionPerms['copyFolder']=1;
00200       }
00201       if (($setup&16)==16) {     // Directory: Delete recursively (rm -Rf)
00202          $this->actionPerms['deleteFolderRecursively']=1;
00203       }
00204    }

t3lib_extFileFunctions::printLogErrorMessages redirect = ''  ) 
 

Print log error messages from the operations of this script instance.

Parameters:
string Redirect URL (for creating link in message)
Returns:
void (Will exit on error)

Definition at line 268 of file class.t3lib_extfilefunc.php.

References $content, error(), and table().

00268                                                 {
00269 
00270       $res_log = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00271                '*',
00272                'sys_log',
00273                'type=2 AND userid='.intval($GLOBALS['BE_USER']->user['uid']).' AND tstamp='.intval($GLOBALS['EXEC_TIME']).'   AND error!=0'
00274             );
00275       $errorJS = array();
00276       while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_log)) {
00277          $log_data = unserialize($row['log_data']);
00278          $errorJS[] = $row[error].': '.sprintf($row['details'], $log_data[0],$log_data[1],$log_data[2],$log_data[3],$log_data[4]);
00279       }
00280 
00281       if (count($errorJS)) {
00282          $error_doc = t3lib_div::makeInstance('template');
00283          $error_doc->backPath = '';
00284 
00285          $content.= $error_doc->startPage('tce_db.php Error output');
00286 
00287          $lines[] = '
00288                <tr class="bgColor5">
00289                   <td colspan="2" align="center"><strong>Errors:</strong></td>
00290                </tr>';
00291 
00292          foreach($errorJS as $line) {
00293             $lines[] = '
00294                <tr class="bgColor4">
00295                   <td valign="top"><img'.t3lib_iconWorks::skinImg('','gfx/icon_fatalerror.gif','width="18" height="16"').' alt="" /></td>
00296                   <td>'.htmlspecialchars($line).'</td>
00297                </tr>';
00298          }
00299 
00300          $lines[] = '
00301                <tr>
00302                   <td colspan="2" align="center"><br />'.
00303                   '<form action=""><input type="submit" value="Continue" onclick="'.htmlspecialchars('document.location=\''.$redirect.'\';return false;').'" /></form>'.
00304                   '</td>
00305                </tr>';
00306 
00307          $content.= '
00308             <br /><br />
00309             <table border="0" cellpadding="1" cellspacing="1" width="300" align="center">
00310                '.implode('',$lines).'
00311             </table>';
00312 
00313          $content.= $error_doc->endPage();
00314          echo $content;
00315          exit;
00316       }
00317    }

t3lib_extFileFunctions::processData  ) 
 

Processing the command array in $this->fileCmdMap.

Returns:
void

Definition at line 211 of file class.t3lib_extfilefunc.php.

References func_copy(), func_delete(), func_edit(), func_move(), func_newfile(), func_newfolder(), func_rename(), func_unzip(), and func_upload().

00211                            {
00212       if (!$this->isInit) return FALSE;
00213 
00214       if (is_array($this->fileCmdMap)) {
00215 
00216             // Traverse each set of actions
00217          foreach($this->fileCmdMap as $action => $actionData)  {
00218 
00219                // Traverse all action data. More than one file might be affected at the same time.
00220             if (is_array($actionData)) {
00221                foreach($actionData as $cmdArr)  {
00222 
00223                      // Clear file stats
00224                   clearstatcache();
00225 
00226                      // Branch out based on command:
00227                   switch ($action)  {
00228                      case 'delete':
00229                         $this->func_delete($cmdArr);
00230                      break;
00231                      case 'copy':
00232                         $this->func_copy($cmdArr);
00233                      break;
00234                      case 'move':
00235                         $this->func_move($cmdArr);
00236                      break;
00237                      case 'rename':
00238                         $this->func_rename($cmdArr);
00239                      break;
00240                      case 'newfolder':
00241                         $this->func_newfolder($cmdArr);
00242                      break;
00243                      case 'newfile':
00244                         $this->func_newfile($cmdArr);
00245                      break;
00246                      case 'editfile':
00247                         $this->func_edit($cmdArr);
00248                      break;
00249                      case 'upload':
00250                         $this->func_upload($cmdArr);
00251                      break;
00252                      case 'unzip':
00253                         $this->func_unzip($cmdArr);
00254                      break;
00255                   }
00256                }
00257             }
00258          }
00259       }
00260    }

t3lib_extFileFunctions::start fileCmds  ) 
 

Initialization of the class.

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

Definition at line 149 of file class.t3lib_extfilefunc.php.

References TYPO3_OS.

00149                               {
00150 
00151          // Configure settings from TYPO3_CONF_VARS:
00152       if (TYPO3_OS=='WIN' || $GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function'])  {
00153          $this->PHPFileFunctions = 1;
00154          $this->dont_use_exec_commands = 1;
00155       } else {
00156          $this->PHPFileFunctions = $GLOBALS['TYPO3_CONF_VARS']['BE']['usePHPFileFunctions'];
00157       }
00158 
00159       $this->unzipPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'];
00160 
00161       $maxFileSize = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize']);
00162       if ($maxFileSize>0)  {
00163          $this->maxCopyFileSize = $maxFileSize;
00164          $this->maxMoveFileSize = $maxFileSize;
00165          $this->maxUploadFileSize = $maxFileSize;
00166       }
00167 
00168          // Initializing file processing commands:
00169       $this->fileCmdMap = $fileCmds;
00170    }

t3lib_extFileFunctions::writeLog action,
error,
details_nr,
details,
data
 

Logging file operations.

Parameters:
integer The action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
integer The severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
integer This 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 This is the default, raw error message in english
array Array with special information that may go into $details by "%s" marks / sprintf() when the log is shown
Returns:
void
See also:
class.t3lib_userauthgroup.php

Definition at line 355 of file class.t3lib_extfilefunc.php.

References error().

00355                                                                   {
00356       $type = 2;  // Type value for tce_file.php
00357       if (is_object($GLOBALS['BE_USER'])) {
00358          $GLOBALS['BE_USER']->writelog($type,$action,$error,$details_nr,$details,$data);
00359       }
00360    }


Member Data Documentation

t3lib_extFileFunctions::$actionPerms
 

Initial value:

 Array(           // This array is self-explaning (look in the class below). It grants access to the functions. This could be set from outside in order to enabled functions to users. See also the function init_actionPerms() which takes input directly from the user-record
      'deleteFile' => 0,               // Deleting files physically
      'deleteFolder' => 0,          // Deleting foldes physically
      'deleteFolderRecursively' => 0,     // normally folders are deleted by the PHP-function rmdir(), but with this option a user deletes with 'rm -Rf ....' which is pretty wild!
      'moveFile' => 0,
      'moveFolder' => 0,
      'copyFile' => 0,
      'copyFolder' => 0,
      'newFolder' => 0,
      'newFile' => 0,
      'editFile' => 0,
      'unzipFile' => 0,
      'uploadFile' => 0,
      'renameFile' => 0,
      'renameFolder' => 0
   )

Definition at line 115 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$dont_use_exec_commands = 0
 

Definition at line 137 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$dontCheckForUnique = 0
 

Definition at line 113 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$maxCopyFileSize = 10000
 

Definition at line 109 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$maxMoveFileSize = 10000
 

Definition at line 110 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$maxUploadFileSize = 10000
 

Definition at line 111 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$PHPFileFunctions = 0
 

Definition at line 136 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$recyclerFN = '_recycler_'
 

Definition at line 132 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$unzipPath = ''
 

Definition at line 112 of file class.t3lib_extfilefunc.php.

t3lib_extFileFunctions::$useRecycler = 1
 

Definition at line 133 of file class.t3lib_extfilefunc.php.


The documentation for this class was generated from the following file:
Generated on Sun Oct 3 01:06:53 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913