Bug #22276 » 13811_v2.diff
t3lib/extjs/class.t3lib_extjs_extdirectapi.php (working copy) | ||
---|---|---|
*/
|
||
class t3lib_extjs_ExtDirectApi {
|
||
/**
|
||
* @var array
|
||
*/
|
||
protected $settings = array();
|
||
/**
|
||
* Constructs this object.
|
||
*/
|
||
public function __construct() {
|
||
if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'])) {
|
||
$this->settings = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'];
|
||
}
|
||
}
|
||
/**
|
||
* Parses the ExtDirect configuration array "$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']"
|
||
* and feeds the given typo3ajax instance with the resulting information. The get parameter
|
||
* Parses the ExtDirect configuration array "$GLOBALS['TYPO3_CONF_VARS']['BE']['ExtDirect']"
|
||
* and feeds the given typo3ajax instance with the resulting informations. The get parameter
|
||
* "namespace" will be used to filter the configuration.
|
||
*
|
||
* This method makes usage of the reflection mechanism to fetch the methods inside the
|
||
* defined classes together with their amount of parameters. This information are building
|
||
* the API and are required by ExtDirect. The result is cached to improve the overall
|
||
* performance.
|
||
* defined classes together with their amount of parameters. This informations are building
|
||
* the API and are required by ExtDirect.
|
||
*
|
||
* @param array $ajaxParams ajax parameters
|
||
* @param TYPO3AJAX $ajaxObj typo3ajax instance
|
||
... | ... | |
public function getAPI($ajaxParams, TYPO3AJAX $ajaxObj) {
|
||
$filterNamespace = t3lib_div::_GET('namespace');
|
||
// look up into the cache
|
||
$cacheIdentifier = 'ExtDirectApi';
|
||
$cacheHash = md5($cacheIdentifier . $filterNamespace . serialize($this->settings));
|
||
$cacheContent = t3lib_pageSelect::getHash($cacheHash);
|
||
// generate the javascript content if it wasn't found inside the cache and cache it!
|
||
if (!$cacheContent) {
|
||
$javascriptNamespaces = $this->generateAPI($filterNamespace);
|
||
t3lib_pageSelect::storeHash(
|
||
$cacheHash,
|
||
serialize($javascriptNamespaces),
|
||
$cacheIdentifier
|
||
);
|
||
} else {
|
||
$javascriptNamespaces = unserialize($cacheContent);
|
||
}
|
||
// return the generated javascript API configuration
|
||
if (count($javascriptNamespaces)) {
|
||
$setup = '
|
||
if (typeof Ext.app.ExtDirectAPI !== "object") {
|
||
Ext.app.ExtDirectAPI = {};
|
||
}
|
||
if (typeof Object.extend !== "function") {
|
||
Object.extend = function(destination, source) {
|
||
for (var property in source) {
|
||
destination[property] = source[property];
|
||
}
|
||
return destination;
|
||
};
|
||
}
|
||
';
|
||
$ajaxObj->setContent($javascriptNamespaces);
|
||
$ajaxObj->setContentFormat('javascript');
|
||
$ajaxObj->setJavascriptCallbackWrap(
|
||
$setup . 'Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, |);'
|
||
);
|
||
}
|
||
}
|
||
/**
|
||
* Generates the API that is configured inside the ExtDirect configuration
|
||
* array "$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']".
|
||
*
|
||
* @param string $filerNamespace namespace that should be loaded like TYPO3.Backend
|
||
* @return array javascript API configuration
|
||
*/
|
||
protected function generateAPI($filterNamespace) {
|
||
$javascriptNamespaces = array();
|
||
if (is_array($this->settings)) {
|
||
foreach ($this->settings as $javascriptName => $className) {
|
||
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'])) {
|
||
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'] as $javascriptName => $className) {
|
||
$splittedJavascriptName = explode('.', $javascriptName);
|
||
$javascriptObjectName = array_pop($splittedJavascriptName);
|
||
$javascriptNamespace = implode('.', $splittedJavascriptName);
|
||
... | ... | |
if (!isset($javascriptNamespaces[$javascriptNamespace])) {
|
||
$javascriptNamespaces[$javascriptNamespace] = array(
|
||
'url' => t3lib_div::locationHeaderUrl('ajax.php?ajaxID=ExtDirect::route&namespace=') . rawurlencode($javascriptNamespace),
|
||
'type' => 'remoting',
|
||
'actions' => array(),
|
||
'namespace' => $javascriptNamespace
|
||
'url' => t3lib_div::locationHeaderUrl('ajax.php?ajaxID=ExtDirect::route&namespace=') . rawurlencode($javascriptNamespace),
|
||
'type' => 'remoting',
|
||
'actions' => array(),
|
||
'namespace' => $javascriptNamespace
|
||
);
|
||
}
|
||
... | ... | |
foreach (get_class_methods($serverObject) as $methodName) {
|
||
$reflectionMethod = new ReflectionMethod($serverObject, $methodName);
|
||
$numberOfParameters = $reflectionMethod->getNumberOfParameters();
|
||
$docHeader = $reflectionMethod->getDocComment();
|
||
$formHandler = (strpos($docHeader, '@formHandler') !== FALSE);
|
||
$javascriptNamespaces[$javascriptNamespace]['actions'][$javascriptObjectName][] = array(
|
||
'name' => $methodName,
|
||
'len' => $numberOfParameters
|
||
'len' => $numberOfParameters,
|
||
'formHandler' => $formHandler
|
||
);
|
||
}
|
||
}
|
||
}
|
||
return $javascriptNamespaces;
|
||
if (count($javascriptNamespaces)) {
|
||
$setup = '
|
||
if (typeof Ext.app.ExtDirectAPI != "object") {
|
||
Ext.app.ExtDirectAPI = {};
|
||
}
|
||
if (typeof Object.extend != "function") {
|
||
Object.extend = function(destination, source) {
|
||
for (var property in source) {
|
||
destination[property] = source[property];
|
||
}
|
||
return destination;
|
||
}
|
||
}
|
||
';
|
||
$ajaxObj->setContent($javascriptNamespaces);
|
||
$ajaxObj->setContentFormat('javascript');
|
||
$ajaxObj->setJavascriptCallbackWrap($setup . 'Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, |);');
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extjs_extdirectapi.php']);
|
||
}
|
||
?>
|
||
?>
|
t3lib/extjs/class.t3lib_extjs_extdirectrouter.php (working copy) | ||
---|---|---|
/**
|
||
* Ext Direct Router
|
||
*
|
||
* Specification:
|
||
* http://www.extjs.com/products/extjs/direct.php
|
||
*
|
||
* @author Sebastian Kurfuerst <sebastian@typo3.org>
|
||
* @author Stefan Galinski <stefan.galinski@gmail.com>
|
||
* @package TYPO3
|
||
*/
|
||
class t3lib_extjs_ExtDirectRouter {
|
||
/**
|
||
* Dispatches the incoming calls to methods about the ExtDirect API.
|
||
* Dispatches the incoming calls to configured server-side methods.
|
||
*
|
||
* @param aray $ajaxParams ajax parameters
|
||
* @param TYPO3AJAX $ajaxObj typo3ajax instance
|
||
... | ... | |
*/
|
||
public function route($ajaxParams, TYPO3AJAX $ajaxObj) {
|
||
try {
|
||
$isForm = false;
|
||
$isUpload = false;
|
||
$isForm = FALSE;
|
||
$isUpload = FALSE;
|
||
$rawPostData = file_get_contents('php://input');
|
||
$postParameters = t3lib_div::_POST();
|
||
$namespace = t3lib_div::_GET('namespace');
|
||
if (!empty($rawPostData)) {
|
||
$ajaxObj->setContentFormat('jsonbody');
|
||
if (!empty($postParameters['extAction'])) {
|
||
$isForm = TRUE;
|
||
$isUpload = $postParameters['extUpload'] === 'true';
|
||
$request->action = $postParameters['extAction'];
|
||
$request->method = $postParameters['extMethod'];
|
||
$request->tid = $postParameters['extTID'];
|
||
$request->data = array($_POST + $_FILES);
|
||
} elseif (!empty($rawPostData)) {
|
||
$request = json_decode($rawPostData);
|
||
} else {
|
||
throw new t3lib_error_Exception('ExtDirect: Missing Parameters!');
|
||
}
|
||
$response = null;
|
||
$response = NULL;
|
||
if (is_array($request)) {
|
||
$response = array();
|
||
foreach ($request as $singleRequest) {
|
||
... | ... | |
$response = $this->processRpc($request, $namespace);
|
||
}
|
||
if ($isForm && $isUpload) {
|
||
$ajaxObj->setContentFormat('plain');
|
||
$response = json_encode($response);
|
||
$response = preg_replace('/"/', '\\"', $response);
|
||
$response = array(
|
||
'<html><body><textarea>' .
|
||
$response .
|
||
'</textarea></body></html>'
|
||
);
|
||
} else {
|
||
$ajaxObj->setContentFormat('jsonbody');
|
||
}
|
||
} catch (t3lib_error_Exception $exception) {
|
||
$response = array(
|
||
'type' => 'exception',
|
||
... | ... | |
);
|
||
} catch (t3lib_error_Exception $exception) {
|
||
$response = array(
|
||
'type' => 'exception',
|
||
'message' => $exception->getMessage(),
|
||
'where' => $exception->getTraceAsString()
|
||
);
|
||
throw $exception;
|
||
}
|
||
return $response;
|
- « Previous
- 1
- 2
- Next »