/** * Sends a redirect header response and exits. Additionaly the URL is * checked and if needed corrected to match the format required for a * Location redirect header. By default the HTTP status code sent is * a 'HTTP/1.1 303 See Other'. * * @param string $url The target URL to redirect to * @param string $httpStatus An optional HTTP status header. Default is 'HTTP/1.1 303 See Other' * @throws \EssentialDots\ExtbaseHijax\MVC\Exception\RedirectAction */ protected function redirectInstance($url, $httpStatus = \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303) { if ($this->ajaxDispatcher->getIsActive()) { /* @var $redirectException \EssentialDots\ExtbaseHijax\MVC\Exception\RedirectAction */ $redirectException = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('EssentialDots\\ExtbaseHijax\\MVC\\Exception\\RedirectAction'); $redirectException->setUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($url)); $redirectException->setHttpStatus($httpStatus); throw $redirectException; } else { header($httpStatus); header('Location: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($url)); exit; } }
/** * Tracks display of an object on a page * * @param \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject $object Object to use * @param mixed $hash Hash or page id (depending on the type) for which the object display will be associated * @param string $type 'hash' (for only one hash) or 'id' (for complete page cache of a page, for all hash combinations) * @return void */ public function trackObjectOnPage(\TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject $object = NULL, $type = 'hash', $hash = false) { if ($object && !$this->ajaxDispatcher->getIsActive()) { $this->signalSlotDispatcher->dispatch(__CLASS__, self::SIGNAL_PreTrackObjectOnPage, array('object' => $object, 'type' => $type, 'hash' => $hash)); if ($type) { switch ($type) { case 'id': if (!$hash) { $hash = intval($this->fe->id); } $pageHash = 'id-' . $hash; break; case 'hash': default: if (!$hash) { $hash = $this->fe->getHash(); } $pageHash = 'hash-' . $hash; break; } $objectIdentifier = $this->getObjectIdentifierForObject($object); $sharedLock = null; $sharedLockAcquired = $this->acquireLock($sharedLock, $objectIdentifier, FALSE); if ($sharedLockAcquired) { if ($this->trackingCache->has($objectIdentifier)) { $pageHashs = $this->trackingCache->get($objectIdentifier); if (!in_array($pageHash, $pageHashs)) { $exclusiveLock = null; $exclusiveLockAcquired = $this->acquireLock($exclusiveLock, $objectIdentifier . '-e', TRUE); if ($exclusiveLockAcquired) { $pageHashs = $this->trackingCache->get($objectIdentifier); if (!in_array($pageHash, $pageHashs)) { $pageHashs[] = $pageHash; $this->trackingCache->set($objectIdentifier, array_unique($pageHashs)); } $this->releaseLock($exclusiveLock); } } } else { $this->trackingCache->set($objectIdentifier, array($pageHash)); } $this->releaseLock($sharedLock); } } } return; }
/** * Dispatches a request to a controller and initializes the security framework. * * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request to dispatch * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response The response, to be modified by the controller * @param \EssentialDots\ExtbaseHijax\Event\Listener $listener Listener * @return void */ public function dispatch(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response, \EssentialDots\ExtbaseHijax\Event\Listener $listener = NULL) { /* @var $request \TYPO3\CMS\Extbase\Mvc\Request */ $this->currentRequest = $request; array_push($this->requestsStack, $this->currentRequest); if (defined('TYPO3_cliMode') && TYPO3_cliMode === TRUE) { parent::dispatch($request, $response); } else { array_push($this->listenersStack, $this->currentListener); if ($listener) { $this->currentListener = $listener; } else { $this->currentListener = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('EssentialDots\\ExtbaseHijax\\Event\\Listener', $request); } if (!$this->serviceContent->getExecuteExtbasePlugins()) { $this->listenerFactory->persist($this->currentListener); $this->serviceContent->setCurrentListener($this->currentListener); } else { $this->hijaxEventDispatcher->startContentElement(); try { parent::dispatch($request, $response); } catch (\TYPO3\CMS\Extbase\Mvc\Controller\Exception\RequiredArgumentMissingException $requiredArgumentMissingException) { try { // this happens with simple reload on pages where some argument is required $configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); $defaultControllerName = current(array_keys($configuration['controllerConfiguration'])); $allowedControllerActions = array(); foreach ($configuration['controllerConfiguration'] as $controllerName => $controllerActions) { $allowedControllerActions[$controllerName] = $controllerActions['actions']; } $defaultActionName = is_array($allowedControllerActions[$request->getControllerName()]) ? current($allowedControllerActions[$request->getControllerName()]) : ''; // try to run the current controller with the default action $request->setDispatched(false); $request->setControllerActionName($defaultActionName); parent::dispatch($request, $response); } catch (\TYPO3\CMS\Extbase\Mvc\Controller\Exception\RequiredArgumentMissingException $requiredArgumentMissingException) { if ($defaultControllerName != $request->getControllerName()) { $request->setControllerName($defaultControllerName); $defaultActionName = is_array($allowedControllerActions[$defaultControllerName]) ? current($allowedControllerActions[$defaultControllerName]) : ''; // try to run the default plugin controller with the default action $request->setDispatched(false); $request->setControllerActionName($defaultActionName); parent::dispatch($request, $response); } } } if ($this->hijaxEventDispatcher->getIsHijaxElement()) { $this->listenerFactory->persist($this->currentListener); } if (($this->ajaxDispatcher->getIsActive() || $this->hijaxEventDispatcher->getIsHijaxElement()) && !$this->ajaxDispatcher->getPreventMarkupUpdateOnAjaxLoad()) { $currentListeners = $this->hijaxEventDispatcher->getListeners('', TRUE); $signature = $this->getCurrentListener()->getId() . '(' . $this->convertArrayToCSV(array_keys($currentListeners)) . '); '; $content = $response->getContent(); $content = '<!-- ###EVENT_LISTENER_' . self::$id . '### START ' . $signature . ' -->' . $content . '<!-- ###EVENT_LISTENER_' . self::$id . '### END -->'; if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID') && \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID') != 'extbase_hijax_dispatcher') { $this->hijaxEventDispatcher->replaceXMLCommentsWithDivs($content, 'html'); } $response->setContent($content); $this->extensionConfiguration->setNextElementId(++self::$id); } $this->hijaxEventDispatcher->endContentElement(); } $this->currentListener = array_pop($this->listenersStack); } $this->currentRequest = array_pop($this->requestsStack); }
/** * @return boolean */ public function render() { return (bool) $this->ajaxDispatcher->getIsActive(); }
/** * Constructor */ public function __construct() { parent::__construct(); $this->cache = $GLOBALS['typo3CacheManager']->getCache('extbase_hijax_img_storage'); }
/** * @param string $src * @param string $type * @param boolean $compress * @param boolean $forceOnTop * @param string $allWrap * @param boolean $excludeFromConcatenation * @param string $section * @param boolean $preventMarkupUpdateOnAjaxLoad * @param boolean $moveToExternalFile * @param boolean $noCache * @param string $name * * @return string */ public function render($src = "", $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE, $section = 'footer', $preventMarkupUpdateOnAjaxLoad = false, $moveToExternalFile = false, $noCache = false, $name = '') { $content = $this->renderChildren(); if ($this->ajaxDispatcher->getIsActive()) { if ($preventMarkupUpdateOnAjaxLoad) { $this->ajaxDispatcher->setPreventMarkupUpdateOnAjaxLoad(true); } // need to just echo the code in ajax call if (!$src) { if ($compress) { $content = $this->compressScript($content); } return \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS($content); } else { return '<script type="' . htmlspecialchars($type) . '" src="' . htmlspecialchars($src) . '"></script>'; } } else { if ($this->isCached()) { if ($noCache) { if ($src) { $content = '<script type="' . htmlspecialchars($type) . '" src="' . htmlspecialchars($src) . '"></script>'; } else { if ($compress) { $content = $this->compressScript($content); } $content = \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS($content); } $tslibFE = GeneralUtility::makeInstance('EssentialDots\\ExtbaseHijax\\Tslib\\FE\\Hook'); /* @var $tslibFE \EssentialDots\ExtbaseHijax\Tslib\FE\Hook */ if ($section == 'footer') { $tslibFE->addNonCacheableFooterCode($name ? $name : md5($content), $content); } else { $tslibFE->addNonCacheableHeaderCode($name ? $name : md5($content), $content); } return ''; } else { if (!$src && $moveToExternalFile) { $src = 'typo3temp' . DIRECTORY_SEPARATOR . 'extbase_hijax' . DIRECTORY_SEPARATOR . md5($content) . '.js'; \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir(PATH_site . $src, $content); if ($GLOBALS['TSFE']) { if ($GLOBALS['TSFE']->baseUrl) { $src = $GLOBALS['TSFE']->baseUrl . $src; } elseif ($GLOBALS['TSFE']->absRefPrefix) { $src = $GLOBALS['TSFE']->absRefPrefix . $src; } } } if (!$src) { if ($section == 'footer') { $this->pageRenderer->addJsFooterInlineCode($name ? $name : md5($content), $content, $compress, $forceOnTop); } else { $this->pageRenderer->addJsInlineCode($name ? $name : md5($content), $content, $compress, $forceOnTop); } } else { if ($section == 'footer') { $this->pageRenderer->addJsFooterFile($src, $type, $compress, $forceOnTop, $allWrap, $excludeFromConcatenation); } else { $this->pageRenderer->addJsFile($src, $type, $compress, $forceOnTop, $allWrap, $excludeFromConcatenation); } } } } else { // additionalFooterData not possible in USER_INT if (!$src) { $GLOBALS['TSFE']->additionalHeaderData[$name ? $name : md5($content)] = \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS($content); } else { $GLOBALS['TSFE']->additionalHeaderData[$name ? $name : md5($content)] = '<script type="' . htmlspecialchars($type) . '" src="' . htmlspecialchars($src) . '"></script>'; } } } return ''; }