/** * Log a message if a post is deleted * * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint * @Flow\Around("method(TYPO3\Neos\View\TypoScriptView->render())") * @return void */ public function replacePlaceholdersIfNecessary(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) { $result = $joinPoint->getAdviceChain()->proceed($joinPoint); /* @var $typoScriptView TypoScriptView */ $typoScriptView = $joinPoint->getProxy(); $viewVariables = ObjectAccess::getProperty($typoScriptView, 'variables', TRUE); if (!isset($viewVariables['value']) || !$viewVariables['value']->getNodeType()->isOfType('Sandstorm.Newsletter:Newsletter')) { // No newsletter, so logic does not apply return $result; } /* @var $httpRequest Request */ $httpRequest = $this->controllerContext->getRequest()->getHttpRequest(); $arguments = $httpRequest->getUri()->getArguments(); if (!isset($arguments['hmac'])) { if ($this->securityContext->isInitialized() && $this->securityContext->hasRole('TYPO3.Neos:Editor')) { // Logged into backend, so we don't need to do anything. return $result; } else { // No HMAC sent -- so we return the email INCLUDING placeholders (as per customer's request) return $result; //return '<h1>Error: HMAC not included in the link.</h1>'; } } $actualHmac = $arguments['hmac']; $uriWithoutHmac = str_replace('&hmac=' . $actualHmac, '', (string) $httpRequest->getUri()); $expectedHmac = hash_hmac('sha1', urldecode($uriWithoutHmac), $this->hmacUrlSecret); if ($expectedHmac !== $actualHmac) { return '<h1>Error: Wrong link clicked.</h1>Please contact your administrator for help'; } $result = preg_replace_callback(ReplacePlaceholdersInLiveImplementation::PLACEHOLDER_REGEX, function ($element) use($arguments) { return ObjectAccess::getPropertyPath($arguments, $element[1]); }, $result); return $result; }
/** * Renders the not found view * * @return string The rendered view * @throws \TYPO3\Flow\Mvc\Exception if no request has been set * @api */ public function render() { if (!is_object($this->controllerContext->getRequest())) { throw new \TYPO3\Flow\Mvc\Exception('Can\'t render view without request object.', 1192450280); } $template = file_get_contents($this->getTemplatePathAndFilename()); $template = str_replace('{BASEURI}', $this->controllerContext->getRequest()->getHttpRequest()->getBaseUri(), $template); foreach ($this->variablesMarker as $variableName => $marker) { $variableValue = isset($this->variables[$variableName]) ? $this->variables[$variableName] : ''; $template = str_replace('{' . $marker . '}', $variableValue, $template); } $this->controllerContext->getResponse()->setStatus(404); return $template; }
/** * Build a list of sites * * @param ControllerContext $controllerContext * @return array */ public function buildSiteList(ControllerContext $controllerContext) { $requestUriHost = $controllerContext->getRequest()->getHttpRequest()->getUri()->getHost(); $domainsFound = false; $sites = array(); foreach ($this->siteRepository->findOnline() as $site) { $uri = null; $active = false; /** @var $site Site */ if ($site->hasActiveDomains()) { $activeHostPatterns = $site->getActiveDomains()->map(function ($domain) { return $domain->getHostPattern(); })->toArray(); $active = in_array($requestUriHost, $activeHostPatterns, true); if ($active) { $uri = $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)->uriFor('index', array(), 'Backend\\Backend', 'TYPO3.Neos'); } else { $uri = $controllerContext->getUriBuilder()->reset()->uriFor('switchSite', array('site' => $site), 'Backend\\Backend', 'TYPO3.Neos'); } $domainsFound = true; } $sites[] = array('name' => $site->getName(), 'nodeName' => $site->getNodeName(), 'uri' => $uri, 'active' => $active); } if ($domainsFound === false) { $uri = $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)->uriFor('index', array(), 'Backend\\Backend', 'TYPO3.Neos'); $sites[0]['uri'] = $uri; } return $sites; }
/** * Build parser configuration * * @return \TYPO3\Fluid\Core\Parser\Configuration */ protected function buildParserConfiguration() { $parserConfiguration = $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\Configuration'); if (in_array($this->controllerContext->getRequest()->getFormat(), array('html', NULL))) { $parserConfiguration->addInterceptor($this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\Interceptor\\Escape')); $parserConfiguration->addInterceptor($this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\Interceptor\\Resource')); } return $parserConfiguration; }
/** * Get variables from configuration that should be set in the context by default. * For example Eel helpers are made available by this. * * @return array Array with default context variable objects. */ protected function getDefaultContextVariables() { if ($this->defaultContextVariables === null) { $this->defaultContextVariables = array(); if (isset($this->settings['defaultContext']) && is_array($this->settings['defaultContext'])) { $this->defaultContextVariables = EelUtility::getDefaultContextVariables($this->settings['defaultContext']); } $this->defaultContextVariables['request'] = $this->controllerContext->getRequest(); } return $this->defaultContextVariables; }
/** * Build a list of sites * * @param \TYPO3\Flow\Mvc\Controller\ControllerContext $controllerContext * @return array */ public function buildSiteList(ControllerContext $controllerContext) { $requestUri = $controllerContext->getRequest()->getHttpRequest()->getUri(); $baseUri = $controllerContext->getRequest()->getHttpRequest()->getBaseUri(); $domainsFound = FALSE; $sites = array(); foreach ($this->siteRepository->findOnline() as $site) { $uri = NULL; /** @var $site \TYPO3\Neos\Domain\Model\Site */ if ($site->hasActiveDomains()) { $uri = $controllerContext->getUriBuilder()->reset()->uriFor('index', array(), 'Backend\\Backend', 'TYPO3.Neos'); $uri = sprintf('%s://%s%s%s', $requestUri->getScheme(), $site->getFirstActiveDomain()->getHostPattern(), rtrim($baseUri->getPath(), '/'), $uri); $domainsFound = TRUE; } $sites[] = array('name' => $site->getName(), 'nodeName' => $site->getNodeName(), 'uri' => $uri, 'active' => parse_url($uri, PHP_URL_HOST) === $requestUri->getHost() ? TRUE : FALSE); } if ($domainsFound === FALSE) { $uri = $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(TRUE)->uriFor('index', array(), 'Backend\\Backend', 'TYPO3.Neos'); $sites[0]['uri'] = $uri; } return $sites; }
/** * Build parser configuration * * @return Configuration */ protected function buildParserConfiguration() { /** @var Configuration $parserConfiguration */ $parserConfiguration = $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\Configuration'); /** @var EscapeInterceptor $escapeInterceptor */ $escapeInterceptor = $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\Interceptor\\Escape'); $parserConfiguration->addEscapingInterceptor($escapeInterceptor); $request = $this->controllerContext->getRequest(); if ($request instanceof ActionRequest && in_array($request->getFormat(), array('html', NULL))) { /** @var ResourceInterceptor $resourceInterceptor */ $resourceInterceptor = $this->objectManager->get('TYPO3\\Fluid\\Core\\Parser\\Interceptor\\Resource'); $parserConfiguration->addInterceptor($resourceInterceptor); } return $parserConfiguration; }
public function onLogout(ControllerContext $controllerContext) { // Check if config for redirect is done if (is_array($this->redirectAfterLogout) && array_key_exists('action', $this->redirectAfterLogout) && array_key_exists('controller', $this->redirectAfterLogout) && array_key_exists('package', $this->redirectAfterLogout)) { $controllerArguments = []; if (array_key_exists('controllerArguments', $this->redirectAfterLogout) && is_array($this->redirectAfterLogout['controllerArguments'])) { $controllerArguments = $this->redirectAfterLogout['controllerArguments']; } return $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)->uriFor($this->redirectAfterLogout['action'], $controllerArguments, $this->redirectAfterLogout['controller'], $this->redirectAfterLogout['package']); } // Neos only logic (configuration at node or via TS) /** @var ActionRequest $actionRequest */ $actionRequest = $controllerContext->getRequest(); if ($actionRequest->getInternalArgument('__redirectAfterLogout')) { return $this->getNodeLinkingService()->createNodeUri($controllerContext, $actionRequest->getInternalArgument('__redirectAfterLogout')); } }
/** * Renders the URI to a given node instance or -path. * * @param ControllerContext $controllerContext * @param mixed $node A node object or a string node path, if a relative path is provided the baseNode argument is required * @param NodeInterface $baseNode * @param string $format Format to use for the URL, for example "html" or "json" * @param boolean $absolute If set, an absolute URI is rendered * @param array $arguments Additional arguments to be passed to the UriBuilder (for example pagination parameters) * @param string $section * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE * @param boolean $resolveShortcuts INTERNAL Parameter - if FALSE, shortcuts are not redirected to their target. Only needed on rare backend occasions when we want to link to the shortcut itself. * @return string The rendered URI * @throws \InvalidArgumentException if the given node/baseNode is not valid * @throws NeosException if no URI could be resolved for the given node */ public function createNodeUri(ControllerContext $controllerContext, $node = null, NodeInterface $baseNode = null, $format = null, $absolute = false, array $arguments = array(), $section = '', $addQueryString = false, array $argumentsToBeExcludedFromQueryString = array(), $resolveShortcuts = true) { $this->lastLinkedNode = null; if (!($node instanceof NodeInterface || is_string($node) || $baseNode instanceof NodeInterface)) { throw new \InvalidArgumentException('Expected an instance of NodeInterface or a string for the node argument, or alternatively a baseNode argument.', 1373101025); } if (is_string($node)) { $nodeString = $node; if ($nodeString === '') { throw new NeosException(sprintf('Empty strings can not be resolved to nodes.', $nodeString), 1415709942); } preg_match(NodeInterface::MATCH_PATTERN_CONTEXTPATH, $nodeString, $matches); if (isset($matches['WorkspaceName']) && $matches['WorkspaceName'] !== '') { $node = $this->propertyMapper->convert($nodeString, 'TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface'); } else { if ($baseNode === null) { throw new NeosException('The baseNode argument is required for linking to nodes with a relative path.', 1407879905); } /** @var ContentContext $contentContext */ $contentContext = $baseNode->getContext(); $normalizedPath = $this->nodeService->normalizePath($nodeString, $baseNode->getPath(), $contentContext->getCurrentSiteNode()->getPath()); $node = $contentContext->getNode($normalizedPath); } if (!$node instanceof NodeInterface) { throw new NeosException(sprintf('The string "%s" could not be resolved to an existing node.', $nodeString), 1415709674); } } elseif (!$node instanceof NodeInterface) { $node = $baseNode; } if (!$node instanceof NodeInterface) { throw new NeosException(sprintf('Node must be an instance of NodeInterface or string, given "%s".', gettype($node)), 1414772029); } $this->lastLinkedNode = $node; if ($resolveShortcuts === true) { $resolvedNode = $this->nodeShortcutResolver->resolveShortcutTarget($node); } else { // this case is only relevant in extremely rare occasions in the Neos Backend, when we want to generate // a link towards the *shortcut itself*, and not to its target. $resolvedNode = $node; } if (is_string($resolvedNode)) { return $resolvedNode; } if (!$resolvedNode instanceof NodeInterface) { throw new NeosException(sprintf('Could not resolve shortcut target for node "%s"', $node->getPath()), 1414771137); } /** @var ActionRequest $request */ $request = $controllerContext->getRequest()->getMainRequest(); $uriBuilder = clone $controllerContext->getUriBuilder(); $uriBuilder->setRequest($request); $uri = $uriBuilder->reset()->setSection($section)->setCreateAbsoluteUri($absolute)->setArguments($arguments)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setFormat($format ?: $request->getFormat())->uriFor('show', array('node' => $resolvedNode), 'Frontend\\Node', 'TYPO3.Neos'); return $uri; }
/** * @param ControllerContext $controllerContext * @param Site $site * @return string * @throws NeosException */ public function createSiteUri(ControllerContext $controllerContext, Site $site) { $primaryDomain = $site->getPrimaryDomain(); if ($primaryDomain === null) { throw new NeosException(sprintf('Cannot link to a site "%s" since it has no active domains.', $site->getName()), 1460443524); } $requestUri = $controllerContext->getRequest()->getHttpRequest()->getUri(); $baseUri = $controllerContext->getRequest()->getHttpRequest()->getBaseUri(); $port = $primaryDomain->getPort() ?: $requestUri->getPort(); return sprintf('%s://%s%s%s', $primaryDomain->getScheme() ?: $requestUri->getScheme(), $primaryDomain->getHostPattern(), $port && !in_array($port, [80, 443], true) ? ':' . $port : '', rtrim($baseUri->getPath(), '/')); }