Skip to content

Commit

Permalink
[TASK] Update delete file method to use t3lib_extFileFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Udriot committed Nov 15, 2011
1 parent d14114a commit 7d44495
Showing 1 changed file with 45 additions and 30 deletions.
75 changes: 45 additions & 30 deletions Classes/Service/ExtDirect/File/Actions.php
Expand Up @@ -7,14 +7,19 @@ class Tx_Vidi_Service_ExtDirect_File_Actions {
*/
protected $fileFactory;

/**
* @var t3lib_extFileFunctions
*/
protected $fileProcessor;

public function __construct() {
$this->fileFactory = t3lib_div::makeInstance('t3lib_file_Factory');

// Initializing:
$this->fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
$this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
$this->fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
$this->fileProcessor->dontCheckForUnique = t3lib_div::_GP('overwriteExistingFiles') ? 1 : 0; // @todo change this to fits Vidi UI
$this->fileProcessor->dontCheckForUnique = t3lib_div::_GP('overwriteExistingFiles') ? 1 : 0; // @todo change this to fit Vidi UI
}

/**
Expand All @@ -25,16 +30,14 @@ public function __construct() {
* @return void
*/
public function renameFile($fileIdentifier, $newFileName) {
$file = $this->fileFactory->getFileObjectFromCombinedIdentifier($fileIdentifier);
$file->rename($newFileName);
return;

if ($this->checkReferer()) {

$fileValues = array(
'rename' => array(
'data' => $fileIdentifier,
'target' => $newFileName,
array(
'data' => $fileIdentifier,
'target' => $newFileName,
)
)
);

Expand All @@ -44,34 +47,25 @@ public function renameFile($fileIdentifier, $newFileName) {
}

/**
* Makes sure the referer is correct.
* Delete a file
*
* @return boolean
*/
public function checkReferer() {
$result = TRUE;

// Checking referer / executing:
$refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
$httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');

// @todo: Decide what to do: a check has been removed from original code
// @see class TYPO3_tcefile
// $this->vC != $GLOBALS['BE_USER']->veriCode()
if ($httpHost != $refInfo['host'] && !$GLOBALS['$TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
$this->fileProcessor->writeLog(0,2,1,'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
throw new t3lib_exception("Referer host \"" . $refInfo['host'] . "\" and server host \"$httpHost\" did not match!", 1321247357);
}
return $result;
}

/**
* @param $fileIdentifier
* @return void
*/
public function deleteFile($fileIdentifier) {
$file = $this->fileFactory->getFileObjectFromCombinedIdentifier($fileIdentifier);
$file->delete();
if ($this->checkReferer()) {

$fileValues = array(
array(
'delete' => array(
'data' => $fileIdentifier,
)
)
);

$this->fileProcessor->start($fileValues);
$this->fileProcessor->processData();
}
}

/**
Expand Down Expand Up @@ -114,4 +108,25 @@ public function createFolder($parentFolder, $newFolderName) {
$folder->getStorage()->createFolder($folder->getIdentifier() . '/' . $newFolderName, false); // @TODO this is quite ugly and only will work for LocalDriver
}

/**
* Makes sure the referer is correct.
*
* @return boolean
*/
protected function checkReferer() {
$result = TRUE;

// Checking referer / executing:
$refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
$httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');

// @todo: Decide what to do: a check has been removed from original code
// @see class TYPO3_tcefile
// $this->vC != $GLOBALS['BE_USER']->veriCode()
if ($httpHost != $refInfo['host'] && !$GLOBALS['$TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
$this->fileProcessor->writeLog(0,2,1,'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
throw new t3lib_exception("Referer host \"" . $refInfo['host'] . "\" and server host \"$httpHost\" did not match!", 1321247357);
}
return $result;
}
}

0 comments on commit 7d44495

Please sign in to comment.