00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 class t3lib_extjs_ExtDirectRouter {
00037
00038
00039
00040
00041
00042
00043
00044 public function route($ajaxParams, TYPO3AJAX $ajaxObj) {
00045 $isForm = FALSE;
00046 $isUpload = FALSE;
00047 $rawPostData = file_get_contents('php:
00048 $postParameters = t3lib_div::_POST();
00049 $namespace = t3lib_div::_GET('namespace');
00050 $response = array();
00051 $request = NULL;
00052
00053 if (!empty($postParameters['extAction'])) {
00054 $isForm = TRUE;
00055 $isUpload = $postParameters['extUpload'] === 'true';
00056
00057 $request = new stdClass;
00058 $request->action = $postParameters['extAction'];
00059 $request->method = $postParameters['extMethod'];
00060 $request->tid = $postParameters['extTID'];
00061 $request->data = array($_POST + $_FILES);
00062 } elseif (!empty($rawPostData)) {
00063 $request = json_decode($rawPostData);
00064 } else {
00065 $response[] = array(
00066 'type' => 'exception',
00067 'message' => 'Something went wrong with an ExtDirect call!'
00068 );
00069 }
00070
00071 if (!is_array($request)) {
00072 $request = array($request);
00073 }
00074
00075 foreach ($request as $index => $singleRequest) {
00076 $response[$index] = array(
00077 'tid' => $singleRequest->tid,
00078 'action' => $singleRequest->action,
00079 'method' => $singleRequest->method
00080 );
00081
00082 try {
00083 $response[$index]['type'] = 'rpc';
00084 $response[$index]['result'] = $this->processRpc($singleRequest, $namespace);
00085 $response[$index]['debug'] = t3lib_extjs_ExtDirectDebug::toString();
00086
00087 } catch (Exception $exception) {
00088 $response[$index]['type'] = 'exception';
00089 $response[$index]['message'] = $exception->getMessage();
00090 $response[$index]['where'] = $exception->getTraceAsString();
00091 }
00092 }
00093
00094 if ($isForm && $isUpload) {
00095 $ajaxObj->setContentFormat('plain');
00096 $response = json_encode($response);
00097 $response = preg_replace('/"/', '\\"', $response);
00098
00099 $response = array(
00100 '<html><body><textarea>' .
00101 $response .
00102 '</textarea></body></html>'
00103 );
00104 } else {
00105 $ajaxObj->setContentFormat('jsonbody');
00106 }
00107
00108 $ajaxObj->setContent($response);
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 protected function processRpc($singleRequest, $namespace) {
00123 $endpointName = $namespace . '.' . $singleRequest->action;
00124
00125
00126
00127 if (!isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'][$endpointName])) {
00128 throw new UnexpectedValueException('ExtDirect: Call to undefined endpoint: ' . $endpointName);
00129 }
00130
00131 $endpointObject = t3lib_div::getUserObj(
00132 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'][$endpointName],
00133 FALSE
00134 );
00135
00136 return call_user_func_array(
00137 array($endpointObject, $singleRequest->method),
00138 is_array($singleRequest->data) ? $singleRequest->data : array()
00139 );
00140 }
00141 }
00142
00143 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extjs_extdirectrouter.php']) {
00144 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extjs_extdirectrouter.php']);
00145 }
00146
00147 ?>