|
<?php
|
|
/**
|
|
* Class overriding extbase's RequestBuilder
|
|
* to take into account $_FILES global array as request arguments
|
|
* @author Alexandre Martinez <alexandre.martinez76@gmail.com>
|
|
*
|
|
* @scope prototype
|
|
*/
|
|
class ux_Tx_Extbase_MVC_Web_RequestBuilder extends Tx_Extbase_MVC_Web_RequestBuilder
|
|
{
|
|
/**
|
|
* Builds a web request object from the raw HTTP information and the configuration
|
|
* Alex Martinez: also adds files to params
|
|
* Files cannot be added to $_POST array because of stripslashed arrays
|
|
* May be a security problem...
|
|
* @TODO try adding slashes to array before adding to $_POST array
|
|
* @return Tx_Extbase_MVC_Web_Request The web request as an object
|
|
*/
|
|
public function build() {
|
|
$parameters = t3lib_div::_GPmerged('tx_' . strtolower($this->extensionName) . '_' . strtolower($this->pluginName));
|
|
// Edit AM
|
|
$parameters = array_merge($parameters,$this->fetchFileParameters('tx_' . strtolower($this->extensionName) . '_' . strtolower($this->pluginName)));
|
|
|
|
if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $this->allowedControllerActions)) {
|
|
$controllerName = filter_var($parameters['controller'], FILTER_SANITIZE_STRING);
|
|
$allowedActions = $this->allowedControllerActions[$controllerName];
|
|
if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
|
|
$actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING);
|
|
} else {
|
|
$actionName = $this->defaultActionName;
|
|
}
|
|
} else {
|
|
$controllerName = $this->defaultControllerName;
|
|
$actionName = $this->defaultActionName;
|
|
}
|
|
|
|
$request = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Request');
|
|
$request->setPluginName($this->pluginName);
|
|
$request->setControllerExtensionName($this->extensionName);
|
|
$request->setControllerName($controllerName);
|
|
$request->setControllerActionName($actionName);
|
|
$request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
|
|
$request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
|
|
$request->setMethod((isset($_SERVER['REQUEST_METHOD'])) ? $_SERVER['REQUEST_METHOD'] : NULL);
|
|
|
|
if (is_string($parameters['format']) && (strlen($parameters['format']))) {
|
|
$request->setFormat(filter_var($parameters['format'], FILTER_SANITIZE_STRING));
|
|
}
|
|
|
|
foreach ($parameters as $argumentName => $argumentValue) {
|
|
$request->setArgument($argumentName, $argumentValue);
|
|
}
|
|
|
|
return $request;
|
|
}
|
|
|
|
/**
|
|
* Reorders file data
|
|
* @param string $key
|
|
* @return array
|
|
*/
|
|
protected function fetchFileParameters($key)
|
|
{
|
|
$results=array();
|
|
$files=$_FILES[$key];
|
|
if (is_array($files)) {
|
|
foreach($files as $propertyName=>$propertyValue){
|
|
foreach ($propertyValue as $paramName=>$paramValue) {
|
|
$results[$paramName][$propertyName]=$paramValue;
|
|
}
|
|
}
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
}
|