Example #1
0
 /**
  * @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
  * @api
  */
 public function getFlashMessageQueue()
 {
     if (!$this->flashMessageQueue instanceof \TYPO3\CMS\Core\Messaging\FlashMessageQueue) {
         $this->flashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier('extbase.flashmessages.' . $this->extensionService->getPluginNamespace($this->request->getControllerExtensionName(), $this->request->getPluginName()));
     }
     return $this->flashMessageQueue;
 }
 /**
  * Renders hijax-related data attributes
  *
  * @param null $action
  * @param array $arguments
  * @param null $controller
  * @param null $extensionName
  * @param null $pluginName
  */
 protected function renderHijaxDataAttributes($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL)
 {
     $request = $this->controllerContext->getRequest();
     $this->tag->addAttribute('data-hijax-element-type', 'ajax');
     $this->tag->addAttribute('class', trim($this->arguments['class'] . ' hijax-element'));
     if ($action === NULL) {
         $action = $request->getControllerActionName();
     }
     $this->tag->addAttribute('data-hijax-action', $action);
     if ($controller === NULL) {
         $controller = $request->getControllerName();
     }
     $this->tag->addAttribute('data-hijax-controller', $controller);
     if ($extensionName === NULL) {
         $extensionName = $request->getControllerExtensionName();
     }
     $this->tag->addAttribute('data-hijax-extension', $extensionName);
     if ($pluginName === NULL && TYPO3_MODE === 'FE') {
         $pluginName = $this->extensionService->getPluginNameByAction($extensionName, $controller, $action);
     }
     if ($pluginName === NULL) {
         $pluginName = $request->getPluginName();
     }
     $this->tag->addAttribute('data-hijax-plugin', $pluginName);
     if ($arguments) {
         $this->tag->addAttribute('data-hijax-arguments', serialize($arguments));
     }
     /* @var $listener \EssentialDots\ExtbaseHijax\Event\Listener */
     $listener = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('EssentialDots\\ExtbaseHijax\\MVC\\Dispatcher')->getCurrentListener();
     $this->tag->addAttribute('data-hijax-settings', $listener->getId());
     $pluginNamespace = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
     $this->tag->addAttribute('data-hijax-namespace', $pluginNamespace);
 }
 /**
  * @param string $action
  * @param array $arguments
  * @param string $controller
  * @param string $extensionName
  * @param string $pluginName
  * @param string $format
  * @param int $pageUid
  * 
  * @return string
  */
 public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $format = '', $pageUid = 0)
 {
     $request = $this->mvcDispatcher->getCurrentRequest();
     if ($request) {
         if ($action === NULL) {
             $action = $request->getControllerActionName();
         }
         if ($controller === NULL) {
             $controller = $request->getControllerName();
         }
         if ($extensionName === NULL) {
             $extensionName = $request->getControllerExtensionName();
         }
         if ($pluginName === NULL && TYPO3_MODE === 'FE') {
             $pluginName = $this->extensionService->getPluginNameByAction($extensionName, $controller, $action);
         }
         if ($pluginName === NULL) {
             $pluginName = $request->getPluginName();
         }
     }
     $additionalArguments = array();
     $this->hA('r[0][arguments]', $arguments, $additionalArguments);
     $language = intval($GLOBALS['TSFE'] ? $GLOBALS['TSFE']->sys_language_content : 0);
     $additionalParams = "&r[0][extension]={$extensionName}&r[0][plugin]={$pluginName}&r[0][controller]={$controller}&r[0][action]={$action}&r[0][format]={$format}&eID=extbase_hijax_dispatcher&L={$language}";
     if ($additionalArguments) {
         $additionalParams .= '&' . implode('&', $additionalArguments);
     }
     /* @var $cObj \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
     $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
     return $cObj->typoLink('', array('returnLast' => 'url', 'additionalParams' => $additionalParams, 'parameter' => $pageUid ? $pageUid : ($GLOBALS['TSFE'] ? $GLOBALS['TSFE']->id : 0)));
 }
Example #4
0
 /**
  * Builds a web request object from the raw HTTP information and the configuration
  *
  * @return \TYPO3\CMS\Extbase\Mvc\Web\Request The web request as an object
  */
 public function build()
 {
     $this->loadDefaultValues();
     $pluginNamespace = $this->extensionService->getPluginNamespace($this->extensionName, $this->pluginName);
     $parameters = \TYPO3\CMS\Core\Utility\GeneralUtility::_GPmerged($pluginNamespace);
     $files = $this->untangleFilesArray($_FILES);
     if (isset($files[$pluginNamespace]) && is_array($files[$pluginNamespace])) {
         $parameters = array_replace_recursive($parameters, $files[$pluginNamespace]);
     }
     $controllerName = $this->resolveControllerName($parameters);
     $actionName = $this->resolveActionName($controllerName, $parameters);
     /** @var $request \TYPO3\CMS\Extbase\Mvc\Web\Request */
     $request = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Request::class);
     if ($this->vendorName !== null) {
         $request->setControllerVendorName($this->vendorName);
     }
     $request->setPluginName($this->pluginName);
     $request->setControllerExtensionName($this->extensionName);
     $request->setControllerName($controllerName);
     $request->setControllerActionName($actionName);
     $request->setRequestUri(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
     $request->setBaseUri(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
     $request->setMethod($this->environmentService->getServerRequestMethod());
     if (is_string($parameters['format']) && $parameters['format'] !== '') {
         $request->setFormat(filter_var($parameters['format'], FILTER_SANITIZE_STRING));
     } else {
         $request->setFormat($this->defaultFormat);
     }
     foreach ($parameters as $argumentName => $argumentValue) {
         $request->setArgument($argumentName, $argumentValue);
     }
     return $request;
 }
 /**
  * Gets the POST data from the requests and returns all data in the plugin namespace if defined
  *
  * @return array|null
  */
 protected function getPostData()
 {
     $data = [];
     $pluginNamespace = $this->extensionService->getPluginNamespace($this->request->getControllerExtensionName(), $this->request->getPluginName());
     $requestBody = file_get_contents('php://input');
     parse_str($requestBody, $data);
     return array_key_exists($pluginNamespace, $data) ? $data[$pluginNamespace] : null;
 }
 /**
  * Get the URI for an AJAX Request.
  *
  * @return string the AJAX URI
  */
 protected function getAjaxUri()
 {
     list($table, $uid) = explode(':', $this->configurationManager->getContentObject()->currentRecord);
     $pluginName = $this->arguments['pluginName'];
     $extensionName = $this->arguments['extensionName'];
     $pluginNamespace = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
     $arguments = $this->hasArgument('arguments') ? $this->arguments['arguments'] : array();
     $ajaxContext = array('record' => $table . '_' . $uid, 'path' => 'tt_content.list.20.' . str_replace('tx_', '', $pluginNamespace));
     $additionalParams['tx_typoscriptrendering']['context'] = json_encode($ajaxContext);
     $uriBuilder = $this->controllerContext->getUriBuilder();
     $argumentPrefix = $uriBuilder->getArgumentPrefix();
     $uriBuilder->reset()->setArguments(array_merge(array($argumentPrefix => $arguments), $additionalParams))->setSection($this->arguments['section'])->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format'])->setUseCacheHash(TRUE);
     // TYPO3 6.0 compatibility check:
     if (method_exists($uriBuilder, 'setAddQueryStringMethod')) {
         $uriBuilder->setAddQueryStringMethod($this->arguments['addQueryStringMethod']);
     }
     return $uriBuilder->build();
 }
Example #7
0
 /**
  * Checks if the given action is cacheable or not.
  * In this case disables caching if option enableSearch is set. Useful for search forms in an action
  * which is mostly cached but if you have an search field caching is a problem.
  *
  * @param string $extensionName Name of the target extension, without underscores
  * @param string $pluginName Name of the target plugin
  * @param string $controllerName Name of the target controller
  * @param string $actionName Name of the action to be called
  * @return boolean TRUE if the specified plugin action is cacheable, otherwise FALSE
  */
 public function isActionCacheable($extensionName, $pluginName, $controllerName, $actionName)
 {
     $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
     if ($frameworkConfiguration['settings']['enableSearch'] == 1) {
         return false;
     } else {
         return parent::isActionCacheable($extensionName, $pluginName, $controllerName, $actionName);
     }
 }
 /**
  * @param string $action
  * @param array $arguments
  * @param string $controller
  * @param string $extensionName
  * @param string $pluginName
  * @param string $format
  * @param int $pageUid
  * @param boolean $cachedAjaxIfPossible TRUE if the URI should be cached (with respect to non-cacheable actions)
  * @param boolean $forceContext TRUE if the controller/action/... should be passed
  * @param boolean $noAjax
  *
  * @return string
  */
 public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $format = '', $pageUid = NULL, $cachedAjaxIfPossible = TRUE, $forceContext = TRUE, $noAjax = FALSE)
 {
     $request = $this->mvcDispatcher->getCurrentRequest();
     if ($forceContext) {
         $requestArguments = $this->controllerContext->getRequest()->getArguments();
         $requestArguments = array_merge($requestArguments, $this->hijaxEventDispatcher->getContextArguments());
         $requestArguments = array_merge($requestArguments, $arguments);
         $arguments = $requestArguments;
     }
     if ($noAjax) {
         return parent::render($action, $arguments, $controller, $extensionName, $pluginName, $pageUid);
     } else {
         /* @var $listener \EssentialDots\ExtbaseHijax\Event\Listener */
         $listener = $this->mvcDispatcher->getCurrentListener();
         if ($request) {
             if ($action === NULL) {
                 $action = $request->getControllerActionName();
             }
             if ($controller === NULL) {
                 $controller = $request->getControllerName();
             }
             if ($extensionName === NULL) {
                 $extensionName = $request->getControllerExtensionName();
             }
             if ($pluginName === NULL && TYPO3_MODE === 'FE') {
                 $pluginName = $this->extensionService->getPluginNameByAction($extensionName, $controller, $action);
             }
             if ($pluginName === NULL) {
                 $pluginName = $request->getPluginName();
             }
             $cachedAjaxIfPossible = $cachedAjaxIfPossible ? $this->configurationManager->getContentObject()->getUserObjectType() != ContentObjectRenderer::OBJECTTYPE_USER_INT : false;
             if ($cachedAjaxIfPossible) {
                 /* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */
                 $cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator');
                 $chash = $cacheHash->calculateCacheHash(array('encryptionKey' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 'action' => $action, 'controller' => $controller, 'extension' => $extensionName, 'plugin' => $pluginName, 'arguments' => $this->array_map_recursive('strval', $arguments), 'settingsHash' => $listener->getId()));
             }
         }
         $additionalArguments = array();
         $this->hA('r[0][arguments]', $arguments, $additionalArguments);
         $language = intval($GLOBALS['TSFE'] ? $GLOBALS['TSFE']->sys_language_content : 0);
         $additionalParams = "&r[0][extension]={$extensionName}&r[0][plugin]={$pluginName}&r[0][controller]={$controller}&r[0][action]={$action}&r[0][format]={$format}&r[0][settingsHash]={$listener->getId()}&eID=extbase_hijax_dispatcher&L={$language}";
         if ($additionalArguments) {
             $additionalParams .= '&' . implode('&', $additionalArguments);
         }
         if ($chash) {
             $additionalParams .= '&r[0][chash]=' . $chash;
         }
         /* @var $cObj \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
         $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
         $uri = $cObj->typoLink('', array('returnLast' => 'url', 'additionalParams' => $additionalParams, 'parameter' => $pageUid ? $pageUid : ($GLOBALS['TSFE'] ? $GLOBALS['TSFE']->id : 0)));
         $this->tag->addAttribute('href', $uri);
         $this->tag->setContent($this->renderChildren());
         $this->tag->forceClosingTag(TRUE);
         return $this->tag->render();
     }
 }
 /**
  * Add some generic arguments that might be useful
  *
  * @return void
  */
 protected function addGenericArguments()
 {
     $this->arguments['veriCode'] = $this->generateVeriCode();
     $this->arguments['extPath'] = $this->relExtPath;
     $this->arguments['typo3Path'] = $this->typo3Path;
     $this->arguments['extKey'] = $this->extKey;
     if (is_object($this->controllerContext)) {
         $this->arguments['pluginNamespace'] = $this->extensionService->getPluginNamespace($this->controllerContext->getRequest()->getControllerExtensionName(), $this->controllerContext->getRequest()->getPluginName());
     }
 }
Example #10
0
 /**
  * @test
  * @expectedException \TYPO3\CMS\Core\Error\Http\PageNotFoundException
  */
 public function buildThrowsPageNotFoundExceptionIfEnabledAndSpecifiedActionIsNotAllowed()
 {
     $this->configuration['mvc']['throwPageNotFoundExceptionIfActionCantBeResolved'] = 1;
     $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration));
     $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager);
     $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue('tx_myextension_pi1'));
     $this->requestBuilder->_set('extensionService', $this->mockExtensionService);
     $_GET = array('tx_myextension_pi1' => array('action' => 'someInvalidAction'));
     $this->requestBuilder->build();
 }
 /**
  * Handles the web request. The response will automatically be sent to the client.
  *
  * @return \TYPO3\CMS\Extbase\Mvc\ResponseInterface|NULL
  */
 public function handleRequest()
 {
     $request = $this->requestBuilder->build();
     if ($this->extensionService->isActionCacheable(NULL, NULL, $request->getControllerName(), $request->getControllerActionName())) {
         $request->setIsCached(TRUE);
     } else {
         $contentObject = $this->configurationManager->getContentObject();
         if ($contentObject->getUserObjectType() === \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::OBJECTTYPE_USER) {
             $contentObject->convertToUserIntObject();
             // \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::convertToUserIntObject() will recreate the object, so we have to stop the request here
             return NULL;
         }
         $request->setIsCached(FALSE);
     }
     /** @var $response \TYPO3\CMS\Extbase\Mvc\ResponseInterface */
     $response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');
     $this->dispatcher->dispatch($request, $response);
     return $response;
 }
 /**
  * @param string $identifier Queue-identifier
  * @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
  * @api
  */
 public function getFlashMessageQueue($identifier = null)
 {
     if ($identifier === null) {
         if ($this->flashMessageQueueDefaultIdentifier === null) {
             // cache the default-identifier for performance-reasons
             $this->flashMessageQueueDefaultIdentifier = 'extbase.flashmessages.' . $this->extensionService->getPluginNamespace($this->request->getControllerExtensionName(), $this->request->getPluginName());
         }
         $identifier = $this->flashMessageQueueDefaultIdentifier;
     }
     return $this->flashMessageService->getMessageQueueByIdentifier($identifier);
 }
Example #13
0
 /**
  * @test
  */
 public function removeDefaultControllerAndActionRemovesControllerAndActionIfBothAreEqualToTheDefault()
 {
     $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultControllerNameByPlugin')->with('ExtensionName', 'PluginName')->will($this->returnValue('DefaultController'));
     $this->mockExtensionService->expects($this->atLeastOnce())->method('getDefaultActionNameByPluginAndController')->with('ExtensionName', 'PluginName', 'DefaultController')->will($this->returnValue('defaultAction'));
     $arguments = array('controller' => 'DefaultController', 'action' => 'defaultAction', 'foo' => 'bar');
     $extensionName = 'ExtensionName';
     $pluginName = 'PluginName';
     $expectedResult = array('foo' => 'bar');
     $actualResult = $this->uriBuilder->_callRef('removeDefaultControllerAndAction', $arguments, $extensionName, $pluginName);
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @test
  */
 public function renderAddsDefaultFieldNamePrefixToTemplateVariableContainerIfNoPrefixIsSpecified()
 {
     $expectedPrefix = 'tx_someextension_someplugin';
     $viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, array('renderChildren', 'renderHiddenIdentityField', 'renderHiddenReferrerFields', 'renderRequestHashField', 'addFormFieldNamesToViewHelperVariableContainer', 'removeFormFieldNamesFromViewHelperVariableContainer', 'renderTrustedPropertiesField'), array(), '', false);
     $this->mockExtensionService->expects($this->once())->method('getPluginNamespace')->with('SomeExtension', 'SomePlugin')->will($this->returnValue('tx_someextension_someplugin'));
     $viewHelper->_set('extensionService', $this->mockExtensionService);
     $this->injectDependenciesIntoViewHelper($viewHelper);
     $viewHelper->setArguments(array('extensionName' => 'SomeExtension', 'pluginName' => 'SomePlugin'));
     $this->viewHelperVariableContainer->expects($this->once())->method('add')->with(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix', $expectedPrefix);
     $this->viewHelperVariableContainer->expects($this->once())->method('remove')->with(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix');
     $viewHelper->render();
 }
Example #15
0
 /**
  * Handles the web request. The response will automatically be sent to the client.
  *
  * @return \TYPO3\CMS\Extbase\Mvc\ResponseInterface|NULL
  */
 public function handleRequest()
 {
     $request = $this->requestBuilder->build();
     if ($this->extensionService->isActionCacheable(null, null, $request->getControllerName(), $request->getControllerActionName())) {
         $request->setIsCached(true);
     } else {
         $contentObject = $this->configurationManager->getContentObject();
         if ($contentObject->getUserObjectType() === \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::OBJECTTYPE_USER) {
             $contentObject->convertToUserIntObject();
             // \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::convertToUserIntObject() will recreate the object, so we have to stop the request here
             return null;
         }
         $request->setIsCached(false);
     }
     if ($this->configurationManager->isFeatureEnabled('requireCHashArgumentForActionArguments')) {
         $pluginNamespace = $this->extensionService->getPluginNamespace($request->getControllerExtensionName(), $request->getPluginName());
         $this->cacheHashEnforcer->enforceForRequest($request, $pluginNamespace);
     }
     /** @var $response \TYPO3\CMS\Extbase\Mvc\ResponseInterface */
     $response = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Response::class);
     $this->dispatcher->dispatch($request, $response);
     return $response;
 }
 /**
  * Initialize the Widget Context, before the Render method is called.
  *
  * @return void
  */
 private function initializeWidgetContext()
 {
     $this->widgetContext->setWidgetConfiguration($this->getWidgetConfiguration());
     $this->initializeWidgetIdentifier();
     $this->widgetContext->setControllerObjectName(get_class($this->controller));
     $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
     $pluginName = $this->controllerContext->getRequest()->getPluginName();
     $this->widgetContext->setParentExtensionName($extensionName);
     $this->widgetContext->setParentPluginName($pluginName);
     $pluginNamespace = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
     $this->widgetContext->setParentPluginNamespace($pluginNamespace);
     $this->widgetContext->setWidgetViewHelperClassName(get_class($this));
     if ($this->ajaxWidget === true) {
         $this->ajaxWidgetContextHolder->store($this->widgetContext);
     }
 }
 /**
  * Initialize the Widget Context, before the Render method is called.
  *
  * @return void
  */
 private function initializeWidgetContext()
 {
     $this->widgetContext->setWidgetConfiguration($this->getWidgetConfiguration());
     $this->initializeWidgetIdentifier();
     $controllerObjectName = $this->controller instanceof \Tx_Fluid_AOP_ProxyInterface ? $this->controller->FLOW3_AOP_Proxy_getProxyTargetClassName() : get_class($this->controller);
     $this->widgetContext->setControllerObjectName($controllerObjectName);
     $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
     $pluginName = $this->controllerContext->getRequest()->getPluginName();
     $this->widgetContext->setParentExtensionName($extensionName);
     $this->widgetContext->setParentPluginName($pluginName);
     $pluginNamespace = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
     $this->widgetContext->setParentPluginNamespace($pluginNamespace);
     $this->widgetContext->setWidgetViewHelperClassName(get_class($this));
     if ($this->ajaxWidget === TRUE) {
         $this->ajaxWidgetContextHolder->store($this->widgetContext);
     }
 }
Example #18
0
 /**
  * Retrieves the default field name prefix for this form
  *
  * @return string default field name prefix
  */
 protected function getDefaultFieldNamePrefix()
 {
     $request = $this->renderingContext->getControllerContext()->getRequest();
     if ($this->hasArgument('extensionName')) {
         $extensionName = $this->arguments['extensionName'];
     } else {
         $extensionName = $request->getControllerExtensionName();
     }
     if ($this->hasArgument('pluginName')) {
         $pluginName = $this->arguments['pluginName'];
     } else {
         $pluginName = $request->getPluginName();
     }
     if ($extensionName !== null && $pluginName != null) {
         return $this->extensionService->getPluginNamespace($extensionName, $pluginName);
     } else {
         return '';
     }
 }
 /**
  * Returns JS callback for the given action
  *
  * @param null $action
  * @param array $arguments
  * @param null $controller
  * @param null $extensionName
  * @param null $pluginName
  * @param string $format
  * @param string $section
  * @return string
  */
 public function getAjaxFunction($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $format = '', $section = 'footer')
 {
     // current element needs to have additional logic...
     $this->hijaxEventDispatcher->setIsHijaxElement(true);
     $request = $this->mvcDispatcher->getCurrentRequest();
     if ($request) {
         if ($action === NULL) {
             $action = $request->getControllerActionName();
         }
         if ($controller === NULL) {
             $controller = $request->getControllerName();
         }
         if ($extensionName === NULL) {
             $extensionName = $request->getControllerExtensionName();
         }
         if ($pluginName === NULL && TYPO3_MODE === 'FE') {
             $pluginName = $this->extensionService->getPluginNameByAction($extensionName, $controller, $action);
         }
         if ($pluginName === NULL) {
             $pluginName = $request->getPluginName();
         }
     }
     $settings = array('extension' => $extensionName, 'plugin' => $pluginName, 'controller' => $controller, 'format' => $format ? $format : 'html', 'action' => $action, 'arguments' => $arguments, 'settingsHash' => $this->mvcDispatcher->getCurrentListener() ? $this->mvcDispatcher->getCurrentListener()->getId() : '', 'namespace' => $extensionName && $pluginName ? $this->extensionService->getPluginNamespace($extensionName, $pluginName) : '');
     $functionName = 'extbaseHijax_' . md5(serialize($settings));
     $content = "; {$functionName}=function(settings, pendingElement, loaders) {";
     foreach ($settings as $k => $v) {
         $content .= "if (typeof settings.{$k} == 'undefined') settings.{$k}=" . json_encode($v) . ";";
     }
     $content .= "return jQuery.hijax(settings, pendingElement, loaders);};";
     if ($this->isCached()) {
         if ($section == 'footer') {
             $this->pageRenderer->addJsFooterInlineCode(md5($content), $content, FALSE, TRUE);
         } else {
             $this->pageRenderer->addJsInlineCode(md5($content), $content, FALSE, TRUE);
         }
     } else {
         // additionalFooterData not possible in USER_INT
         $GLOBALS['TSFE']->additionalHeaderData[md5($content)] = \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS($content);
     }
     return $functionName;
 }
 /**
  * @param \TYPO3\CMS\Extbase\Core\Bootstrap $bootstrap
  * @param array $configuration
  * @param array $r
  * @param \TYPO3\CMS\Extbase\Mvc\Web\Request $request
  * @param \EssentialDots\ExtbaseHijax\Event\Listener $listener
  * @param bool $isCacheCallback
  * @return array
  * @throws \Tx_EdCache_Exception_PreventActionCaching
  */
 public function handleFrontendRequest($bootstrap, $configuration, $r, $request, $listener, $isCacheCallback = FALSE)
 {
     $this->initialize();
     $bootstrap->initialize($configuration);
     $this->setPreventMarkupUpdateOnAjaxLoad(false);
     /* @var $request \TYPO3\CMS\Extbase\Mvc\Web\Request */
     $request = $this->buildRequest($r, $request);
     $request->setDispatched(false);
     $namespace = $this->extensionService->getPluginNamespace($request->getControllerExtensionName(), $request->getPluginName());
     $_POST[$namespace] = $request->getArguments();
     /* @var $response \TYPO3\CMS\Extbase\Mvc\Web\Response */
     $response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');
     /* @var $dispatcher \EssentialDots\ExtbaseHijax\MVC\Dispatcher */
     $dispatcher = $this->objectManager->get('EssentialDots\\ExtbaseHijax\\MVC\\Dispatcher');
     $dispatcher->dispatch($request, $response, $listener);
     $this->parseHeaders($response);
     $_POST[$namespace] = array();
     $content = $response->getContent();
     $this->serviceContent->processIntScripts($content);
     $this->serviceContent->processAbsRefPrefix($content, $configuration['settings']['absRefPrefix']);
     $response->setContent($content);
     // convert HTML to specified format
     $htmlConverter = $this->objectManager->get('EssentialDots\\ExtbaseHijax\\HTMLConverter\\ConverterFactory');
     /* @var $htmlConverter \EssentialDots\ExtbaseHijax\HTMLConverter\ConverterFactory */
     $converter = $htmlConverter->getConverter($request->getFormat());
     try {
         $response = $converter->convert($response);
     } catch (\EssentialDots\ExtbaseHijax\HTMLConverter\FailedConversionException $e) {
         $this->errorWhileConverting = TRUE;
     }
     $result = array('id' => $r['id'], 'format' => $request->getFormat(), 'response' => $response->getContent(), 'preventMarkupUpdate' => $this->getPreventMarkupUpdateOnAjaxLoad(), 'headers' => $response->getHeaders());
     if (!$this->errorWhileConverting && $isCacheCallback && !$request->isCached() && $this->cacheRepository) {
         error_log('Throwing Tx_EdCache_Exception_PreventActionCaching, did you missconfigure cacheable actions in Extbase?');
         /* @var $preventActionCaching \Tx_EdCache_Exception_PreventActionCaching */
         $preventActionCaching = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_EdCache_Exception_PreventActionCaching');
         $preventActionCaching->setResult($result);
         throw $preventActionCaching;
     }
     return $result;
 }
Example #21
0
 /**
  * Builds a TypoLink configuration array from the current settings
  *
  * @return array typolink configuration array
  * @see TSref/typolink
  */
 protected function buildTypolinkConfiguration()
 {
     $typolinkConfiguration = array();
     $typolinkConfiguration['parameter'] = $this->targetPageUid !== null ? $this->targetPageUid : $GLOBALS['TSFE']->id;
     if ($this->targetPageType !== 0) {
         $typolinkConfiguration['parameter'] .= ',' . $this->targetPageType;
     } elseif ($this->format !== '') {
         $targetPageType = $this->extensionService->getTargetPageTypeByFormat($this->request->getControllerExtensionName(), $this->format);
         $typolinkConfiguration['parameter'] .= ',' . $targetPageType;
     }
     if (!empty($this->arguments)) {
         $arguments = $this->convertDomainObjectsToIdentityArrays($this->arguments);
         $this->lastArguments = $arguments;
         $typolinkConfiguration['additionalParams'] = GeneralUtility::implodeArrayForUrl(null, $arguments);
     }
     if ($this->addQueryString === true) {
         $typolinkConfiguration['addQueryString'] = 1;
         if (!empty($this->argumentsToBeExcludedFromQueryString)) {
             $typolinkConfiguration['addQueryString.'] = array('exclude' => implode(',', $this->argumentsToBeExcludedFromQueryString));
         }
         if ($this->addQueryStringMethod) {
             $typolinkConfiguration['addQueryString.']['method'] = $this->addQueryStringMethod;
         }
     }
     if ($this->noCache === true) {
         $typolinkConfiguration['no_cache'] = 1;
     } elseif ($this->useCacheHash) {
         $typolinkConfiguration['useCacheHash'] = 1;
     }
     if ($this->section !== '') {
         $typolinkConfiguration['section'] = $this->section;
     }
     if ($this->linkAccessRestrictedPages === true) {
         $typolinkConfiguration['linkAccessRestrictedPages'] = 1;
     }
     return $typolinkConfiguration;
 }
 /**
  * @test
  */
 public function getDefaultActionNameByPluginAndControllerReturnsFirstActionNameOfGivenController()
 {
     $expectedResult = 'someAction';
     $actualResult = $this->extensionService->getDefaultActionNameByPluginAndController('SomeOtherExtensionName', 'SecondPlugin', 'SecondControllerName');
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * Renders hijax-related data attributes
  *
  * @param null $action
  * @param array $arguments
  * @param array $contextArguments
  * @param bool $ajax
  * @param bool $cachedAjaxIfPossible
  * @param bool $forceContext
  * @return string
  */
 protected function getWidgetUri($action = NULL, array $arguments = array(), array $contextArguments = array(), $ajax = TRUE, $cachedAjaxIfPossible = TRUE, $forceContext = FALSE)
 {
     $this->hijaxEventDispatcher->setIsHijaxElement(true);
     $request = $this->controllerContext->getRequest();
     /* @var $widgetContext \EssentialDots\ExtbaseHijax\Core\Widget\WidgetContext */
     $widgetContext = $request->getWidgetContext();
     $tagAttributes = array();
     if ($ajax) {
         $tagAttributes['data-hijax-element-type'] = 'link';
         $this->tag->addAttribute('class', trim($this->arguments['class'] . ' hijax-element'));
     }
     if ($action === NULL) {
         $action = $widgetContext->getParentControllerContext()->getRequest()->getControllerActionName();
     }
     if ($ajax) {
         $tagAttributes['data-hijax-action'] = $action;
     }
     $controller = $widgetContext->getParentControllerContext()->getRequest()->getControllerName();
     if ($ajax) {
         $tagAttributes['data-hijax-controller'] = $controller;
     }
     $extensionName = $widgetContext->getParentControllerContext()->getRequest()->getControllerExtensionName();
     if ($ajax) {
         $tagAttributes['data-hijax-extension'] = $extensionName;
     }
     if (TYPO3_MODE === 'FE') {
         $pluginName = $this->extensionService->getPluginNameByAction($extensionName, $controller, $action);
     }
     if (!$pluginName) {
         $pluginName = $request->getPluginName();
     }
     if (!$pluginName) {
         $pluginName = $widgetContext->getParentPluginName();
     }
     if ($ajax) {
         $tagAttributes['data-hijax-plugin'] = $pluginName;
     }
     $pluginNamespace = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
     if ($ajax) {
         $tagAttributes['data-hijax-namespace'] = $pluginNamespace;
     }
     $requestArguments = $widgetContext->getParentControllerContext()->getRequest()->getArguments();
     $requestArguments = array_merge($requestArguments, $this->hijaxEventDispatcher->getContextArguments());
     $requestArguments = array_merge($requestArguments, $contextArguments);
     $requestArguments[$widgetContext->getWidgetIdentifier()] = $arguments && is_array($arguments) ? $arguments : array();
     if (version_compare(TYPO3_version, '6.1.0', '>=')) {
         $variableContainer = $widgetContext->getViewHelperChildNodeRenderingContext()->getViewHelperVariableContainer();
         if ($variableContainer->exists('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formFieldNames')) {
             $formFieldNames = $variableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formFieldNames');
             $mvcPropertyMappingConfigurationService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\MvcPropertyMappingConfigurationService');
             /* @var $mvcPropertyMappingConfigurationService \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService */
             $requestHash = $mvcPropertyMappingConfigurationService->generateTrustedPropertiesToken($formFieldNames, $pluginNamespace);
             $requestArguments['__trustedProperties'] = $requestHash;
         }
     }
     if ($ajax) {
         $tagAttributes['data-hijax-arguments'] = serialize($requestArguments);
     }
     /* @var $listener \EssentialDots\ExtbaseHijax\Event\Listener */
     $listener = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('EssentialDots\\ExtbaseHijax\\MVC\\Dispatcher')->getCurrentListener();
     if ($ajax) {
         $tagAttributes['data-hijax-settings'] = $listener->getId();
     }
     $cachedAjaxIfPossible = $cachedAjaxIfPossible ? $this->configurationManager->getContentObject()->getUserObjectType() != ContentObjectRenderer::OBJECTTYPE_USER_INT : false;
     if ($cachedAjaxIfPossible) {
         /* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */
         $cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator');
         $tagAttributes['data-hijax-chash'] = $cacheHash->calculateCacheHash(array('encryptionKey' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 'action' => $tagAttributes['data-hijax-action'], 'controller' => $tagAttributes['data-hijax-controller'], 'extension' => $tagAttributes['data-hijax-extension'], 'plugin' => $tagAttributes['data-hijax-plugin'], 'arguments' => $tagAttributes['data-hijax-arguments'], 'settingsHash' => $tagAttributes['data-hijax-settings']));
     }
     foreach ($tagAttributes as $tagAttribute => $attributeValue) {
         $this->tag->addAttribute($tagAttribute, $attributeValue);
     }
     $uriBuilder = $this->controllerContext->getUriBuilder();
     $argumentPrefix = $this->controllerContext->getRequest()->getArgumentPrefix();
     if ($this->hasArgument('format') && $this->arguments['format'] !== '') {
         $requestArguments['format'] = $this->arguments['format'];
     }
     $uriBuilder->reset()->setArguments(array($pluginNamespace => $requestArguments))->setSection($this->arguments['section'])->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format']);
     if ($forceContext) {
         return $uriBuilder->uriFor($action, $arguments, $controller, $extensionName, $pluginName);
     } else {
         return $uriBuilder->build();
     }
 }