Index: t3lib/class.t3lib_pagerenderer.php =================================================================== --- t3lib/class.t3lib_pagerenderer.php (revision 10410) +++ t3lib/class.t3lib_pagerenderer.php (revision ) @@ -948,15 +948,23 @@ return; } $this->extDirectCodeAdded = TRUE; - $token = ''; + $token = $api = ''; if (TYPO3_MODE === 'BE') { $formprotection = t3lib_formprotection_Factory::get(); $token = $formprotection->generateToken('extDirect'); + + /** @var $extDirect t3lib_extjs_ExtDirectApi */ + $extDirect = t3lib_div::makeInstance('t3lib_extjs_ExtDirectApi'); + $api = $extDirect->getApiPhp('TYPO3'); } + if ($api) { + $this->addJsInlineCode('TYPO3ExtDirectAPI', $api); + } + // Note: we need to iterate thru the object, because the addProvider method // does this only with multiple arguments - $this->addExtOnReadyCode(' + $this->addExtOnReadyCode( ' (function() { TYPO3.ExtDirectToken = "' . $token . '"; for (var api in Ext.app.ExtDirectAPI) { Index: typo3/sysext/workspaces/Classes/Controller/PreviewController.php =================================================================== --- typo3/sysext/workspaces/Classes/Controller/PreviewController.php (revision 10222) +++ typo3/sysext/workspaces/Classes/Controller/PreviewController.php (revision ) @@ -50,11 +50,6 @@ // Load JavaScript: $this->pageRenderer->addExtDirectCode(); - $this->pageRenderer->addJsFile( - $this->backPath . 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Workspaces&' . TYPO3_version, - NULL, - FALSE - ); $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js'); $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/iframepanel.js'); Index: typo3/classes/class.livesearch.php =================================================================== --- typo3/classes/class.livesearch.php (revision 10252) +++ typo3/classes/class.livesearch.php (revision ) @@ -93,7 +93,6 @@ */ protected function addJavascriptToBackend() { $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer(); - $pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.LiveSearchActions&' . TYPO3_version, 'text/javascript', $compress = FALSE); $this->backendReference->addJavascriptFile('js/livesearch.js'); } Index: typo3/sysext/em/classes/class.tx_em_extensionmanager.php =================================================================== --- typo3/sysext/em/classes/class.tx_em_extensionmanager.php (revision 10422) +++ typo3/sysext/em/classes/class.tx_em_extensionmanager.php (revision ) @@ -125,17 +125,6 @@ $this->pageRenderer->enableExtJSQuickTips(); // Load JavaScript: - $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . - 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.EM', - NULL, - FALSE - ); - $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . - 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.EMSOAP', - NULL, - FALSE - ); - $this->pageRenderer->addExtDirectCode(); Index: typo3/template.php =================================================================== --- typo3/template.php (revision 10317) +++ typo3/template.php (revision ) @@ -821,11 +821,6 @@ $this->docStyle(); if ($this->extDirectStateProvider) { - $this->pageRenderer->addJsFile( - $this->backPath . 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.ExtDirectStateProvider&' . TYPO3_version, - NULL, - FALSE - ); $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ExtDirect.StateProvider.js'); } @@ -1637,7 +1632,6 @@ protected function loadCshJavascript() { $this->pageRenderer->loadExtJS(); $this->pageRenderer->addJsFile($this->backPath .'../t3lib/js/extjs/contexthelp.js'); - $this->pageRenderer->addJsFile($this->backPath . 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.CSH&' . TYPO3_version, NULL, FALSE); $this->pageRenderer->addExtDirectCode(); } Index: t3lib/core_autoload.php =================================================================== --- t3lib/core_autoload.php (revision 10306) +++ t3lib/core_autoload.php (revision ) @@ -167,6 +167,7 @@ 't3lib_spritemanager_spritebuildinghandler' => PATH_t3lib . 'spritemanager/class.t3lib_spritemanager_spritebuildinghandler.php', 't3lib_spritemanager_abstracthandler' => PATH_t3lib . 'spritemanager/class.t3lib_spritemanager_abstracthandler.php', 't3lib_extjs_extdirectdebug' => PATH_t3lib . 'extjs/class.t3lib_extjs_extdirectdebug.php', + 't3lib_extjs_extdirectapi' => PATH_t3lib . 'extjs/class.t3lib_extjs_extdirectapi.php', 't3lib_tree_abstracttree' => PATH_t3lib . 'tree/class.t3lib_tree_abstracttree.php', 't3lib_tree_abstractdataprovider' => PATH_t3lib . 'tree/class.t3lib_tree_abstractdataprovider.php', 't3lib_tree_abstractstateprovider' => PATH_t3lib . 'tree/class.t3lib_tree_abstractstateprovider.php', Index: typo3/backend.php =================================================================== --- typo3/backend.php (revision 10398) +++ typo3/backend.php (revision ) @@ -234,18 +234,6 @@ $this->pageRenderer->addJsFile($jsFile); } - - // TYPO3.Ajax.ExtDirec is used for BE toolbar items and may be later for general services - if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'])) { - foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'] as $key => $value) { - if (strpos($key, 'TYPO3.Ajax.ExtDirect') !== FALSE) { - $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Ajax.ExtDirect&' . TYPO3_version, NULL, FALSE); - break; - } - } - } - $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.BackendUserSettings&' . TYPO3_version, NULL, FALSE); - $this->generateJavascript(); $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js); @@ -342,18 +330,8 @@ foreach ($jsFiles as $jsFile) { $this->pageRenderer->addJsFile($relativeComponentPath . 'javascript/' . $jsFile); } - - if (is_array($info['extDirectNamespaces']) && count($info['extDirectNamespaces'])) { - foreach ($info['extDirectNamespaces'] as $namespace) { - $this->pageRenderer->addJsFile( - 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=' . $namespace . '&' . TYPO3_version, - NULL, - FALSE - ); - } - } + } + } - } - } /** * renders the items in the top toolbar Index: typo3/sysext/workspaces/Classes/Controller/ReviewController.php =================================================================== --- typo3/sysext/workspaces/Classes/Controller/ReviewController.php (revision 10222) +++ typo3/sysext/workspaces/Classes/Controller/ReviewController.php (revision ) @@ -139,7 +139,6 @@ // Load JavaScript: $this->pageRenderer->addExtDirectCode(); - $this->pageRenderer->addJsFile($this->backPath . 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Workspaces&' . TYPO3_version, NULL, FALSE); $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js'); $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/Ext.grid.RowExpander.js'); Index: t3lib/extjs/class.t3lib_extjs_extdirectapi.php =================================================================== --- t3lib/extjs/class.t3lib_extjs_extdirectapi.php (revision 10185) +++ t3lib/extjs/class.t3lib_extjs_extdirectapi.php (revision ) @@ -64,35 +64,8 @@ public function getAPI($ajaxParams, TYPO3AJAX $ajaxObj) { $filterNamespace = t3lib_div::_GET('namespace'); - // Check GET-parameter no_cache and extCache setting - $extCache = isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache']) && ( - $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] === 0 || - $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] === '0' - ); - $noCache = t3lib_div::_GET('no_cache') ? TRUE : $extCache; + $javascriptNamespaces = $this->getExtDirectApi($filterNamespace, TRUE); - // look up into the cache - $cacheIdentifier = 'ExtDirectApi'; - $cacheHash = md5($cacheIdentifier . $filterNamespace . t3lib_div::getIndpEnv('TYPO3_SSL') . - serialize($this->settings) . TYPO3_MODE . t3lib_div::getIndpEnv('HTTP_HOST')); - - // with no_cache always generate the javascript content - $cacheContent = $noCache ? '' : 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); - if (!empty($javascriptNamespaces)) { - t3lib_pageSelect::storeHash( - $cacheHash, - serialize($javascriptNamespaces), - $cacheIdentifier - ); - } - } else { - $javascriptNamespaces = unserialize($cacheContent); - } - // enable caching $expireDate = date('r', $GLOBALS['EXEC_TIME'] + 3600 * 24 * 30); header('Expires: ' . $expireDate); @@ -101,39 +74,14 @@ // 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; - }; - } - '; - + $setup = $this->getJavascriptIntro(); $ajaxObj->setContent($javascriptNamespaces); $ajaxObj->setContentFormat('javascript'); $ajaxObj->setJavascriptCallbackWrap( $setup . 'Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, |);' ); } else { - if ($filterNamespace) { - // namespace error - $errorMessage = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:ExtDirect.namespaceError'), - __CLASS__, $filterNamespace - ); - } - else { - // no namespace given - $errorMessage = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:ExtDirect.noNamespace'), - __CLASS__ - ); - } + $errorMessage = $this->getNamespaceError($filterNamespace); // make js multiline message $msg = t3lib_div::trimExplode(LF, str_replace('"', '\"', $errorMessage), TRUE); $errorMessage = ''; @@ -155,13 +103,36 @@ } /** + * @throws t3lib_exception + * @param string $filterNamespace + * @return string + */ + public function getApiPhp($filterNamespace) { + $javascriptNamespaces = $this->getExtDirectApi($filterNamespace, TRUE); + // return the generated javascript API configuration + if (count($javascriptNamespaces)) { + return $this->getJavascriptIntro() . ' + Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, ' . + json_encode($javascriptNamespaces) . ') + '; + } else { + $errorMessage = $this->getNamespaceError($filterNamespace); + throw new t3lib_exception( + 1297645190, + $errorMessage + ); + } + } + + + /** * 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) { + public function generateAPI($filterNamespace) { $javascriptNamespaces = array(); if (is_array($this->settings)) { foreach ($this->settings as $javascriptName => $className) { @@ -220,8 +191,90 @@ return $url; } + + /** + * @param $filterNamespace + * @param bool $checkGetParam + * @return string + */ + protected function getExtDirectApi($filterNamespace, $checkGetParam = FALSE) { + // Check GET-parameter no_cache and extCache setting + $noCache = isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache']) && ( + $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] === 0 || + $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] === '0' + ); + if ($checkGetParam) { + $noCache = t3lib_div::_GET('no_cache') ? TRUE : $noCache; -} + } + + // look up into the cache + $cacheIdentifier = 'ExtDirectApi'; + $cacheHash = md5($cacheIdentifier . $filterNamespace . t3lib_div::getIndpEnv('TYPO3_SSL') . + serialize($this->settings) . TYPO3_MODE . t3lib_div::getIndpEnv('HTTP_HOST')); + + // with no_cache always generate the javascript content + $cacheContent = $noCache ? '' : 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); + if (!empty($javascriptNamespaces)) { + t3lib_pageSelect::storeHash( + $cacheHash, + serialize($javascriptNamespaces), + $cacheIdentifier + ); + } + } else { + $javascriptNamespaces = unserialize($cacheContent); + } + + return $javascriptNamespaces; + } + + /** + * @param $filterNamespace + * @return string + */ + protected function getNamespaceError($filterNamespace) { + if ($filterNamespace) { + // namespace error + $errorMessage = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:ExtDirect.namespaceError'), + __CLASS__, $filterNamespace + ); + } + else { + // no namespace given + $errorMessage = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:ExtDirect.noNamespace'), + __CLASS__ + ); + } + + return $errorMessage; + } + + /** + * @return string + */ + protected function getJavascriptIntro() { + return ' + 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; + }; + } + '; + } +} + if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/extjs/class.t3lib_extjs_extdirectapi.php'])) { include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/extjs/class.t3lib_extjs_extdirectapi.php']); }