Exemplo n.º 1
0
 /**
  * @param $responses
  * @param $eventsToListen
  * @param bool $processOriginal
  */
 protected function parseAndRunEventListeners(&$responses, $eventsToListen, $processOriginal = TRUE)
 {
     if ($processOriginal) {
         foreach ($responses['original'] as $response) {
             $this->hijaxEventDispatcher->parseAndRunEventListeners($response['response']);
         }
     }
     if ($eventsToListen && is_array($eventsToListen)) {
         foreach ($eventsToListen as $listenerId => $eventNames) {
             $shouldProcess = FALSE;
             foreach ($eventNames as $eventName) {
                 if ($this->hijaxEventDispatcher->hasPendingEventWithName($eventName, $listenerId)) {
                     $shouldProcess = TRUE;
                     break;
                 }
             }
             if ($shouldProcess) {
                 /* @var $listener \EssentialDots\ExtbaseHijax\Event\Listener */
                 $listener = $this->listenerFactory->findById($listenerId);
                 if ($listener) {
                     $configuration = $listener->getConfiguration();
                     $bootstrap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Core\\Bootstrap');
                     $bootstrap->cObj = $listener->getCObj();
                     $bootstrap->initialize($configuration);
                     /* @var $request \TYPO3\CMS\Extbase\Mvc\Web\Request */
                     $request = $listener->getRequest();
                     $request->setDispatched(false);
                     $this->setPreventMarkupUpdateOnAjaxLoad(false);
                     /* @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');
                     try {
                         $dispatcher->dispatch($request, $response, $listener);
                         $this->parseHeaders($response);
                         $content = $response->getContent();
                         $this->serviceContent->processIntScripts($content);
                         $this->serviceContent->processAbsRefPrefix($content, $configuration['settings']['absRefPrefix']);
                         $responses['affected'][] = array('id' => $listenerId, 'format' => $request->getFormat(), 'response' => $content, 'preventMarkupUpdate' => $this->getPreventMarkupUpdateOnAjaxLoad());
                     } catch (\EssentialDots\ExtbaseHijax\MVC\Exception\StopProcessingAction $exception) {
                         $this->parseHeaders($response);
                     }
                 } else {
                     // TODO: log error message
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param array $params
  * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj
  * @param string $hookType
  */
 protected function contentPostProc($params, $pObj, $hookType)
 {
     if ($this->extensionConfiguration->shouldIncludeEofe() && !$this->extensionConfiguration->hasIncludedEofe()) {
         $this->extensionConfiguration->setIncludedEofe(true);
         $eofe = $pObj->cObj->cObjGetSingle($pObj->tmpl->setup['config.']['extbase_hijax.']['eofe'], $pObj->tmpl->setup['config.']['extbase_hijax.']['eofe.']);
         $pObj->content = str_ireplace('</body>', $eofe . '</body>', $pObj->content);
     }
     if ($this->extensionConfiguration->shouldIncludeSofe() && !$this->extensionConfiguration->hasIncludedSofe()) {
         $this->extensionConfiguration->setIncludedSofe(true);
         $sofe = $pObj->cObj->cObjGetSingle($pObj->tmpl->setup['config.']['extbase_hijax.']['sofe'], $pObj->tmpl->setup['config.']['extbase_hijax.']['sofe.']);
         $pObj->content = preg_replace('/<body([^>]*)>/msU', '<body$1>' . $sofe, $pObj->content);
     }
     $bodyClass = $pObj->tmpl->setup['config.']['extbase_hijax.']['bodyClass'];
     if ($bodyClass && !$this->extensionConfiguration->hasAddedBodyClass()) {
         $matches = array();
         preg_match('/<body([^>]*)class="([^>]*)">/msU', $pObj->content, $matches);
         $count = 0;
         if (count($matches)) {
             $classes = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(" ", $matches[2], true);
             if (!in_array($bodyClass, $classes)) {
                 $pObj->content = preg_replace('/<body([^>]*)class="([^>]*)">/msU', '<body$1class="$2 ' . $bodyClass . '">', $pObj->content, -1, $count);
             }
         } else {
             $pObj->content = preg_replace('/<body([^>]*)>/msU', '<body$1 class="' . $bodyClass . '">', $pObj->content, -1, $count);
         }
         if ($count) {
             $this->extensionConfiguration->setAddedBodyClass(true);
         }
     }
     if ($hookType == 'output') {
         while ($this->hijaxEventDispatcher->hasPendingNextPhaseEvents()) {
             // trick to force double rendering of some content elements
             $GLOBALS['TSFE']->recordRegister = array();
             // trick to force loading of full TS template
             if (!$pObj->tmpl->loaded) {
                 $pObj->forceTemplateParsing = TRUE;
                 $pObj->getConfigArray();
             }
             $this->hijaxEventDispatcher->promoteNextPhaseEvents();
             $this->hijaxEventDispatcher->parseAndRunEventListeners($pObj->content);
             if (!$pObj->config['INTincScript']) {
                 $pObj->config['INTincScript'] = array();
             }
             $pObj->INTincScript();
             if (self::$loopCount++ > 99) {
                 // preventing dead loops
                 break;
             }
         }
     }
     if ($hookType == 'output' || $pObj->isStaticCacheble()) {
         $this->hijaxEventDispatcher->replaceXMLCommentsWithDivs($pObj->content);
     }
     if ($hookType == 'output') {
         if (count($this->nonCacheableFooterCode)) {
             ksort($this->nonCacheableFooterCode);
             $pObj->content = $this->str_lreplace('</body>', '<!-- x123456 -->' . implode('', $this->nonCacheableFooterCode) . '</body>', $pObj->content);
         }
         if (count($this->nonCacheableHeaderCode)) {
             ksort($this->nonCacheableHeaderCode);
             $pObj->content = $this->str_lreplace('</head>', '<!-- x123456 -->' . implode('', $this->nonCacheableHeaderCode) . '</head>', $pObj->content);
         }
     }
 }