/** * @param CM_Params $params * @param CM_Http_Response_View_Ajax $response * @throws CM_Exception_Invalid * @return array */ public function loadPage(CM_Params $params, CM_Http_Response_View_Ajax $response) { $path = $params->getString('path'); $currentLayoutClass = $params->getString('currentLayout'); $request = $this->_createGetRequestWithUrl($path); $responseFactory = new CM_Http_ResponseFactory($this->getServiceManager()); $count = 0; $fragments = []; do { $fragment = CM_Util::link($request->getPath(), $request->getQuery()); $fragments[] = $fragment; $url = $this->getRender()->getSite()->getUrlBase() . $fragment; if ($count++ > 10) { throw new CM_Exception_Invalid('Page redirect loop detected (' . implode(' -> ', $fragments) . ').'); } $responsePage = $responseFactory->getResponse($request); if (!$responsePage->getSite()->equals($this->getSite())) { $redirectExternalFragment = CM_Util::link($responsePage->getRequest()->getPath(), $responsePage->getRequest()->getQuery()); return array('redirectExternal' => $responsePage->getRender()->getUrl($redirectExternalFragment)); } $responseEmbed = new CM_Http_Response_Page_Embed($responsePage->getRequest(), $responsePage->getSite(), $this->getServiceManager()); $responseEmbed->process(); $request = $responseEmbed->getRequest(); if ($redirectUrl = $responseEmbed->getRedirectUrl()) { if (!$this->_isPageOnSameSite($redirectUrl)) { return array('redirectExternal' => $redirectUrl); } } } while ($redirectUrl); foreach ($responseEmbed->getCookies() as $name => $cookieParameters) { $response->setCookie($name, $cookieParameters['value'], $cookieParameters['expire'], $cookieParameters['path']); } $page = $responseEmbed->getPage(); $this->_setStringRepresentation(get_class($page)); $frontend = $responseEmbed->getRender()->getGlobalResponse(); $html = $responseEmbed->getContent(); $js = $frontend->getJs(); $autoId = $frontend->getTreeRoot()->getValue()->getAutoId(); $frontend->clear(); $layoutRendering = null; $layoutClass = $page->getLayout($this->getRender()->getEnvironment()); if ($layoutClass !== $currentLayoutClass) { $layout = new $layoutClass(); $layoutRendering = $this->_getComponentRendering($layout); } $title = $responseEmbed->getTitle(); $menuList = array_merge($this->getSite()->getMenus($this->getRender()->getEnvironment()), $responseEmbed->getRender()->getMenuList()); $menuEntryHashList = $this->_getMenuEntryHashList($menuList, get_class($page), $page->getParams()); $jsTracking = $responseEmbed->getRender()->getServiceManager()->getTrackings()->getJs(); return ['pageRendering' => ['js' => $js, 'html' => $html, 'autoId' => $autoId], 'layoutRendering' => $layoutRendering, 'title' => $title, 'url' => $url, 'menuEntryHashList' => $menuEntryHashList, 'jsTracking' => $jsTracking]; }
/** * @param CM_Params $params * @param CM_Http_Response_View_Ajax $response * @throws CM_Exception_Invalid * @return array */ public function loadPage(CM_Params $params, CM_Http_Response_View_Ajax $response) { $request = new CM_Http_Request_Get($params->getString('path'), $this->getRequest()->getHeaders(), $this->getRequest()->getServer(), $this->getRequest()->getViewer()); $count = 0; $paths = array($request->getPath()); do { $url = $this->getRender()->getUrl(CM_Util::link($request->getPath(), $request->getQuery())); if ($count++ > 10) { throw new CM_Exception_Invalid('Page redirect loop detected (' . implode(' -> ', $paths) . ').'); } $responsePage = new CM_Http_Response_Page_Embed($request, $this->getServiceManager()); $responsePage->process(); $request = $responsePage->getRequest(); $paths[] = $request->getPath(); if ($redirectUrl = $responsePage->getRedirectUrl()) { $redirectExternal = 0 !== mb_stripos($redirectUrl, $this->getRender()->getUrl()); if ($redirectExternal) { return array('redirectExternal' => $redirectUrl); } } } while ($redirectUrl); foreach ($responsePage->getCookies() as $name => $cookieParameters) { $response->setCookie($name, $cookieParameters['value'], $cookieParameters['expire'], $cookieParameters['path']); } $page = $responsePage->getPage(); $this->_setStringRepresentation(get_class($page)); $frontend = $responsePage->getRender()->getGlobalResponse(); $html = $responsePage->getContent(); $js = $frontend->getJs(); $autoId = $frontend->getTreeRoot()->getValue()->getAutoId(); $frontend->clear(); $title = $responsePage->getTitle(); $layoutClass = get_class($page->getLayout($this->getRender()->getEnvironment())); $menuList = array_merge($this->getSite()->getMenus(), $responsePage->getRender()->getMenuList()); $menuEntryHashList = $this->_getMenuEntryHashList($menuList, get_class($page), $page->getParams()); $jsTracking = $responsePage->getRender()->getServiceManager()->getTrackings()->getJs(); return array('autoId' => $autoId, 'html' => $html, 'js' => $js, 'title' => $title, 'url' => $url, 'layoutClass' => $layoutClass, 'menuEntryHashList' => $menuEntryHashList, 'jsTracking' => $jsTracking); }