Exemplo n.º 1
0
 /**
  * Invoke the ViewHelper described by the ViewHelperNode, the properties
  * of which will already have been filled by the ViewHelperResolver.
  *
  * @param string|ViewHelperInterface $viewHelperClassName
  * @param array $arguments
  * @param RenderingContextInterface $renderingContext
  * @param \Closure $renderChildrenClosure
  * @return mixed
  */
 public function invoke($viewHelperClassNameOrInstance, array $arguments, RenderingContextInterface $renderingContext, \Closure $renderChildrenClosure = NULL)
 {
     if ($viewHelperClassNameOrInstance instanceof ViewHelperInterface) {
         $viewHelper = $viewHelperClassNameOrInstance;
     } else {
         $viewHelper = $this->viewHelperResolver->createViewHelperInstanceFromClassName($viewHelperClassNameOrInstance);
     }
     $expectedViewHelperArguments = $renderingContext->getViewHelperResolver()->getArgumentDefinitionsForViewHelper($viewHelper);
     // Rendering process
     $evaluatedArguments = array();
     foreach ($expectedViewHelperArguments as $argumentName => $argumentDefinition) {
         if (isset($arguments[$argumentName])) {
             /** @var NodeInterface|mixed $argumentValue */
             $argumentValue = $arguments[$argumentName];
             $evaluatedArguments[$argumentName] = $argumentValue instanceof NodeInterface ? $argumentValue->evaluate($renderingContext) : $argumentValue;
         } else {
             $evaluatedArguments[$argumentName] = $argumentDefinition->getDefaultValue();
         }
     }
     $this->abortIfUnregisteredArgumentsExist($expectedViewHelperArguments, $evaluatedArguments);
     $this->abortIfRequiredArgumentsAreMissing($expectedViewHelperArguments, $evaluatedArguments);
     $viewHelper->setArguments($evaluatedArguments);
     $viewHelper->setRenderingContext($renderingContext);
     if ($renderChildrenClosure) {
         $viewHelper->setRenderChildrenClosure($renderChildrenClosure);
     }
     return $viewHelper->initializeArgumentsAndRender();
 }
 /**
  * Pre-process the template source before it is returned to the TemplateParser or passed to
  * the next TemplateProcessorInterface instance.
  *
  * Detects all tags that carry an `xmlns:` definition using a Fluid-compatible prefix and a
  * conventional namespace URL (http://typo3.org/ns/). Extracts the detected namespaces and
  * removes the detected tag.
  *
  * @param string $templateSource
  * @return string
  */
 public function preProcessSource($templateSource)
 {
     $matches = array();
     $namespacePattern = 'xmlns:([a-z0-9]+)="(http\\:\\/\\/typo3\\.org\\/ns\\/[^"]+)"';
     $matched = preg_match('/<([a-z0-9]+)(?:[^>]*?)\\s+' . $namespacePattern . '[^>]*>/', $templateSource, $matches);
     if ($matched) {
         $namespaces = array();
         preg_match_all('/' . $namespacePattern . '/', $matches[0], $namespaces, PREG_SET_ORDER);
         foreach ($namespaces as $set) {
             $namespaceUrl = $set[2];
             $namespaceUri = substr($namespaceUrl, 20);
             $namespacePhp = str_replace('/', '\\', $namespaceUri);
             $this->renderingContext->getViewHelperResolver()->addNamespace($set[1], $namespacePhp);
         }
         if (strpos($matches[0], 'data-namespace-typo3-fluid="true"')) {
             $templateSource = str_replace($matches[0], '', $templateSource);
             $closingTagName = $matches[1];
             $closingTag = '</' . $closingTagName . '>';
             if (strpos($templateSource, $closingTag)) {
                 $templateSource = substr($templateSource, 0, strrpos($templateSource, $closingTag)) . substr($templateSource, strrpos($templateSource, $closingTag) + strlen($closingTag));
             }
         } else {
             if (!empty($namespaces)) {
                 $namespaceAttributesToRemove = [];
                 foreach ($namespaces as $namespace) {
                     $namespaceAttributesToRemove[] = preg_quote($namespace[1], '/') . '="' . preg_quote($namespace[2], '/') . '"';
                 }
                 $matchWithRemovedNamespaceAttributes = preg_replace('/(?:\\s*+xmlns:(?:' . implode('|', $namespaceAttributesToRemove) . ')\\s*+)++/', ' ', $matches[0]);
                 $templateSource = str_replace($matches[0], $matchWithRemovedNamespaceAttributes, $templateSource);
             }
         }
     }
     return $templateSource;
 }
Exemplo n.º 3
0
 /**
  * Invoke the ViewHelper described by the ViewHelperNode, the properties
  * of which will already have been filled by the ViewHelperResolver.
  *
  * @param string|ViewHelperInterface $viewHelperClassNameOrInstance
  * @param array $arguments
  * @param RenderingContextInterface $renderingContext
  * @param null|\Closure $renderChildrenClosure
  * @return string
  */
 public function invoke($viewHelperClassNameOrInstance, array $arguments, RenderingContextInterface $renderingContext, \Closure $renderChildrenClosure = null)
 {
     $viewHelperResolver = $renderingContext->getViewHelperResolver();
     if ($viewHelperClassNameOrInstance instanceof ViewHelperInterface) {
         $viewHelper = $viewHelperClassNameOrInstance;
     } else {
         $viewHelper = $viewHelperResolver->createViewHelperInstanceFromClassName($viewHelperClassNameOrInstance);
     }
     $expectedViewHelperArguments = $viewHelperResolver->getArgumentDefinitionsForViewHelper($viewHelper);
     // Rendering process
     $evaluatedArguments = [];
     $undeclaredArguments = [];
     foreach ($expectedViewHelperArguments as $argumentName => $argumentDefinition) {
         if (isset($arguments[$argumentName])) {
             /** @var NodeInterface|mixed $argumentValue */
             $argumentValue = $arguments[$argumentName];
             $evaluatedArguments[$argumentName] = $argumentValue instanceof NodeInterface ? $argumentValue->evaluate($renderingContext) : $argumentValue;
         } else {
             $evaluatedArguments[$argumentName] = $argumentDefinition->getDefaultValue();
         }
     }
     foreach ($arguments as $argumentName => $argumentValue) {
         if (!array_key_exists($argumentName, $evaluatedArguments)) {
             $undeclaredArguments[$argumentName] = $argumentValue instanceof NodeInterface ? $argumentValue->evaluate($renderingContext) : $argumentValue;
         }
     }
     if ($renderChildrenClosure) {
         $viewHelper->setRenderChildrenClosure($renderChildrenClosure);
     }
     $viewHelper->setRenderingContext($renderingContext);
     $viewHelper->setArguments($evaluatedArguments);
     $viewHelper->handleAdditionalArguments($undeclaredArguments);
     return $viewHelper->initializeArgumentsAndRender();
 }
 /**
  * @param RenderingContextInterface $renderingContext
  * @return void
  */
 public function setRenderingContext(RenderingContextInterface $renderingContext)
 {
     $this->renderingContext = $renderingContext;
     $this->templateVariableContainer = $renderingContext->getVariableProvider();
     $this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
     if ($renderingContext instanceof FlowAwareRenderingContextInterface) {
         $this->controllerContext = $renderingContext->getControllerContext();
     }
 }
Exemplo n.º 5
0
 /**
  * Evaluate this node and return the correct object.
  *
  * Handles each part (denoted by .) in $this->objectPath in the following order:
  * - call appropriate getter
  * - call public property, if exists
  * - fail
  *
  * The first part of the object path has to be a variable in the
  * VariableProvider.
  *
  * @param RenderingContextInterface $renderingContext
  * @return mixed The evaluated object, can be any object type.
  */
 public function evaluate(RenderingContextInterface $renderingContext)
 {
     $objectPath = strtolower($this->objectPath);
     $variableProvider = $renderingContext->getVariableProvider();
     if ($objectPath === '_all') {
         return $variableProvider->getAll();
     }
     return VariableExtractor::extract($variableProvider, $this->objectPath, $this->accessors);
 }
Exemplo n.º 6
0
 /**
  * @param mixed $candidate
  * @param RenderingContextInterface $renderingContext
  * @return mixed
  */
 protected static function getTemplateVariableOrValueItself($candidate, RenderingContextInterface $renderingContext)
 {
     $variables = $renderingContext->getVariableProvider()->getAll();
     $extractor = new VariableExtractor();
     $suspect = $extractor->getByPath($variables, $candidate);
     if (NULL === $suspect) {
         return $candidate;
     }
     return $suspect;
 }
Exemplo n.º 7
0
 /**
  * Constructor.
  *
  * @param RenderingContextInterface $renderingContext a RenderingContext, provided by invoker
  * @param string $namespace the namespace identifier of the ViewHelper.
  * @param string $identifier the name of the ViewHelper to render, inside the namespace provided.
  * @param NodeInterface[] $arguments Arguments of view helper - each value is a RootNode.
  * @param ParsingState $state
  */
 public function __construct(RenderingContextInterface $renderingContext, $namespace, $identifier, array $arguments, ParsingState $state)
 {
     $resolver = $renderingContext->getViewHelperResolver();
     $this->arguments = $arguments;
     $this->viewHelperClassName = $resolver->resolveViewHelperClassName($namespace, $identifier);
     $this->uninitializedViewHelper = $resolver->createViewHelperInstanceFromClassName($this->viewHelperClassName);
     $this->uninitializedViewHelper->setRenderingContext($renderingContext);
     $this->uninitializedViewHelper->setViewHelperNode($this);
     $this->argumentDefinitions = $resolver->getArgumentDefinitionsForViewHelper($this->uninitializedViewHelper);
     $this->rewriteBooleanNodesInArgumentsObjectTree($this->argumentDefinitions, $this->arguments);
     $this->validateArguments($this->argumentDefinitions, $this->arguments);
 }
Exemplo n.º 8
0
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $table = $arguments['table'];
     $field = $arguments['field'];
     $wrap = $arguments['wrap'];
     if ($table === null) {
         $currentRequest = $renderingContext->getControllerContext()->getRequest();
         $moduleName = $currentRequest->getPluginName();
         $table = '_MOD_' . $moduleName;
     }
     return '<div class="docheader-csh">' . BackendUtility::cshItem($table, $field, '', $wrap) . '</div>';
 }
Exemplo n.º 9
0
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return mixed
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $templateVariableContainer = $renderingContext->getVariableProvider();
     $map = $arguments['map'];
     foreach ($map as $aliasName => $value) {
         $templateVariableContainer->add($aliasName, $value);
     }
     $output = $renderChildrenClosure();
     foreach ($map as $aliasName => $value) {
         $templateVariableContainer->remove($aliasName);
     }
     return $output;
 }
Exemplo n.º 10
0
 /**
  * Constructor.
  *
  * @param RenderingContextInterface $renderingContext a RenderingContext, provided by invoker
  * @param string $namespace the namespace identifier of the ViewHelper.
  * @param string $identifier the name of the ViewHelper to render, inside the namespace provided.
  * @param NodeInterface[] $arguments Arguments of view helper - each value is a RootNode.
  * @param ParsingState $state
  */
 public function __construct(RenderingContextInterface $renderingContext, $namespace, $identifier, array $arguments, ParsingState $state)
 {
     $resolver = $renderingContext->getViewHelperResolver();
     $this->arguments = $arguments;
     $this->viewHelperClassName = $resolver->resolveViewHelperClassName($namespace, $identifier);
     $this->uninitializedViewHelper = $resolver->createViewHelperInstanceFromClassName($this->viewHelperClassName);
     $this->uninitializedViewHelper->setViewHelperNode($this);
     // Note: RenderingContext required here though replaced later. See https://github.com/TYPO3Fluid/Fluid/pull/93
     $this->uninitializedViewHelper->setRenderingContext($renderingContext);
     $this->argumentDefinitions = $resolver->getArgumentDefinitionsForViewHelper($this->uninitializedViewHelper);
     $this->rewriteBooleanNodesInArgumentsObjectTree($this->argumentDefinitions, $this->arguments);
     $this->validateArguments($this->argumentDefinitions, $this->arguments);
 }
 /**
  * @param null $arguments
  * @param RenderingContextInterface $renderingContext
  * @return bool
  */
 protected static function evaluateCondition($arguments = null, RenderingContextInterface $renderingContext)
 {
     $objectManager = $renderingContext->getObjectManager();
     /** @var Context $securityContext */
     $securityContext = $objectManager->get(Context::class);
     $activeTokens = $securityContext->getAuthenticationTokens();
     $isAuthenticated = false;
     foreach ($activeTokens as $token) {
         if ($token->isAuthenticated()) {
             $isAuthenticated = true;
         }
     }
     return $isAuthenticated;
 }
 /**
  * Sets up this test case
  *
  * @return void
  */
 protected function setUp()
 {
     $this->singletonInstances = GeneralUtility::getSingletonInstances();
     $this->view = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\StandaloneView::class, array('testFileExistence', 'buildParserConfiguration', 'getOrParseAndStoreTemplate'), array(), '', false);
     $this->mockConfigurationManager = $this->getMock(ConfigurationManagerInterface::class);
     $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
     $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'objectManagerCallback')));
     $this->mockRequest = $this->getMock(Request::class);
     $this->mockUriBuilder = $this->getMock(UriBuilder::class);
     $this->mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
     $this->mockControllerContext = $this->getMock(ControllerContext::class);
     $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockRequest));
     $this->mockTemplatePaths = $this->getMock(TemplatePaths::class);
     $this->mockViewHelperVariableContainer = $this->getMock(ViewHelperVariableContainer::class);
     $this->mockRenderingContext = $this->getMock(\TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextFixture::class);
     $this->mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext));
     $this->mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->mockViewHelperVariableContainer));
     $this->mockRenderingContext->expects($this->any())->method('getVariableProvider')->willReturn($this->mockVariableProvider);
     $this->mockRenderingContext->expects($this->any())->method('getTemplatePaths')->willReturn($this->mockTemplatePaths);
     $this->view->_set('objectManager', $this->mockObjectManager);
     $this->view->_set('baseRenderingContext', $this->mockRenderingContext);
     $this->view->_set('controllerContext', $this->mockControllerContext);
     $this->view->expects($this->any())->method('getOrParseAndStoreTemplate')->willReturn($this->mockParsedTemplate);
     GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $this->mockObjectManager);
     GeneralUtility::addInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $this->mockContentObject);
     $this->mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager::class, array(), array(), '', false);
     $mockCache = $this->getMock(\TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface::class, array(), array(), '', false);
     $this->mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
     GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $this->mockCacheManager);
 }
 /**
  * Pre-process the template source before it is
  * returned to the TemplateParser or passed to
  * the next TemplateProcessorInterface instance.
  *
  * @param string $templateSource
  * @return string
  */
 public function preProcessSource($templateSource)
 {
     $matches = [];
     preg_match_all(self::$SCAN_PATTERN_ESCAPINGMODIFIER, $templateSource, $matches, PREG_SET_ORDER);
     if ($matches === []) {
         return $templateSource;
     }
     if (count($matches) > 1) {
         throw new Exception('There is more than one escaping modifier defined. There can only be one {escapingEnabled=...} per template.', 1407331080);
     }
     if (strtolower($matches[0]['enabled']) === 'false') {
         $this->renderingContext->getTemplateParser()->setEscapingEnabled(false);
     }
     $templateSource = preg_replace(self::$SCAN_PATTERN_ESCAPINGMODIFIER, '', $templateSource);
     return $templateSource;
 }
Exemplo n.º 14
0
 /**
  * Loads the template source and render the template.
  * If "layoutName" is set in a PostParseFacet callback, it will render the file with the given layout.
  *
  * @param string $actionName If set, this action's template will be rendered instead of the one defined in the context.
  * @return string Rendered Template
  * @api
  */
 public function render($actionName = NULL)
 {
     $this->templateParser->setConfiguration($this->buildParserConfiguration());
     $this->templateParser->setVariableProvider($this->baseRenderingContext->getVariableProvider());
     $this->templateParser->setViewHelperResolver($this->viewHelperResolver);
     $this->baseRenderingContext->setViewHelperResolver($this->viewHelperResolver);
     $controllerName = $this->baseRenderingContext->getControllerName();
     if (!$actionName) {
         $actionName = $this->baseRenderingContext->getControllerAction();
     }
     $actionName = ucfirst($actionName);
     if (empty($templateIdentifier)) {
         $templateIdentifier = $this->templatePaths->getTemplateIdentifier($controllerName, $actionName);
     }
     $parsedTemplate = $this->getOrParseAndStoreTemplate($templateIdentifier, function ($parent, TemplatePaths $paths) use($controllerName, $actionName) {
         return $paths->getTemplateSource($controllerName, $actionName);
     });
     $parsedTemplate->addCompiledNamespaces($this->baseRenderingContext);
     if (!$parsedTemplate->hasLayout()) {
         $this->startRendering(self::RENDERING_TEMPLATE, $parsedTemplate, $this->baseRenderingContext);
         $output = $parsedTemplate->render($this->baseRenderingContext);
         $this->stopRendering();
     } else {
         $layoutName = $parsedTemplate->getLayoutName($this->baseRenderingContext);
         $layoutIdentifier = $this->templatePaths->getLayoutIdentifier($layoutName);
         $parsedLayout = $this->getOrParseAndStoreTemplate($layoutIdentifier, function ($parent, TemplatePaths $paths) use($layoutName) {
             return $paths->getLayoutSource($layoutName);
         });
         $this->startRendering(self::RENDERING_LAYOUT, $parsedTemplate, $this->baseRenderingContext);
         $output = $parsedLayout->render($this->baseRenderingContext);
         $this->stopRendering();
     }
     return $output;
 }
 /**
  * Throw an UnknownNamespaceException for any unknown and not ignored
  * namespace inside the template string
  *
  * @param string $templateSource
  * @return void
  */
 public function throwExceptionsForUnhandledNamespaces($templateSource)
 {
     $viewHelperResolver = $this->renderingContext->getViewHelperResolver();
     $splitTemplate = preg_split(Patterns::$SPLIT_PATTERN_TEMPLATE_DYNAMICTAGS, $templateSource, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     foreach ($splitTemplate as $templateElement) {
         if (preg_match(Patterns::$SCAN_PATTERN_TEMPLATE_VIEWHELPERTAG, $templateElement, $matchedVariables) > 0) {
             if (!$viewHelperResolver->isNamespaceValidOrIgnored($matchedVariables['NamespaceIdentifier'])) {
                 throw new UnknownNamespaceException('Unkown Namespace: ' . htmlspecialchars($matchedVariables[0]));
             }
             continue;
         } elseif (preg_match(Patterns::$SCAN_PATTERN_TEMPLATE_CLOSINGVIEWHELPERTAG, $templateElement, $matchedVariables) > 0) {
             continue;
         }
         $sections = preg_split(Patterns::$SPLIT_PATTERN_SHORTHANDSYNTAX, $templateElement, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
         foreach ($sections as $section) {
             if (preg_match(Patterns::$SCAN_PATTERN_SHORTHANDSYNTAX_OBJECTACCESSORS, $section, $matchedVariables) > 0) {
                 preg_match_all(Patterns::$SPLIT_PATTERN_SHORTHANDSYNTAX_VIEWHELPER, $section, $shorthandViewHelpers, PREG_SET_ORDER);
                 if (is_array($shorthandViewHelpers) === true) {
                     foreach ($shorthandViewHelpers as $shorthandViewHelper) {
                         if (!$viewHelperResolver->isNamespaceValidOrIgnored($shorthandViewHelper['NamespaceIdentifier'])) {
                             throw new UnknownNamespaceException('Unkown Namespace: ' . $shorthandViewHelper['NamespaceIdentifier']);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 16
0
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $pageUid = $arguments['pageUid'];
     $additionalParams = $arguments['additionalParams'];
     $pageType = $arguments['pageType'];
     $noCache = $arguments['noCache'];
     $noCacheHash = $arguments['noCacheHash'];
     $section = $arguments['section'];
     $linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages'];
     $absolute = $arguments['absolute'];
     $addQueryString = $arguments['addQueryString'];
     $argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'];
     $addQueryStringMethod = $arguments['addQueryStringMethod'];
     $uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
     $uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setAddQueryStringMethod($addQueryStringMethod)->build();
     return $uri;
 }
Exemplo n.º 17
0
 /**
  * Return array element by key.
  *
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return string
  * @api
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $element = $arguments['element'];
     $formRuntime = $arguments['formRuntime'];
     $property = null;
     if (!empty($arguments['property'])) {
         $property = $arguments['property'];
     } elseif (!empty($arguments['renderingOptionProperty'])) {
         $property = $arguments['renderingOptionProperty'];
     }
     if ($formRuntime === null) {
         /** @var RendererInterface $fluidFormRenderer */
         $fluidFormRenderer = $renderingContext->getViewHelperVariableContainer()->getView();
         $formRuntime = $fluidFormRenderer->getFormRuntime();
     }
     return TranslationService::getInstance()->translateFormElementValue($element, $property, $formRuntime);
 }
 /**
  * @param \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
  * @return void
  */
 public function setRenderingContext(\TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 {
     $this->renderingContext = $renderingContext;
     $this->templateVariableContainer = $renderingContext->getVariableProvider();
     $this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
     if ($renderingContext instanceof \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext) {
         $this->controllerContext = $renderingContext->getControllerContext();
     }
 }
Exemplo n.º 19
0
 /**
  * Evaluate this node and return the correct object.
  *
  * Handles each part (denoted by .) in $this->objectPath in the following order:
  * - call appropriate getter
  * - call public property, if exists
  * - fail
  *
  * The first part of the object path has to be a variable in the
  * VariableProvider.
  *
  * @param RenderingContextInterface $renderingContext
  * @return object The evaluated object, can be any object type.
  */
 public function evaluate(RenderingContextInterface $renderingContext)
 {
     $variableProvider = $renderingContext->getVariableProvider();
     switch (strtolower($this->objectPath)) {
         case '_all':
             return $variableProvider->getAll();
         case 'true':
         case 'on':
         case 'yes':
             return TRUE;
         case 'false':
         case 'off':
         case 'no':
             return FALSE;
         default:
             return VariableExtractor::extract($variableProvider, $this->objectPath, $this->accessors);
     }
 }
Exemplo n.º 20
0
 /**
  * Render the URI to the resource. The filename is used from child content.
  *
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return string The URI to the resource
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $path = $arguments['path'];
     $extensionName = $arguments['extensionName'];
     $absolute = $arguments['absolute'];
     if ($extensionName === null) {
         $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName();
     }
     $uri = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
     $uri = GeneralUtility::getFileAbsFileName($uri);
     $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri);
     if (TYPO3_MODE === 'BE' && $absolute === false && $uri !== false) {
         $uri = '../' . $uri;
     }
     if ($absolute === true) {
         $uri = $renderingContext->getControllerContext()->getRequest()->getBaseUri() . $uri;
     }
     return $uri;
 }
Exemplo n.º 21
0
 /**
  * @return ParsingState
  */
 protected function getParsingState()
 {
     $rootNode = new RootNode();
     $variableProvider = $this->renderingContext->getVariableProvider();
     $state = new ParsingState();
     $state->setRootNode($rootNode);
     $state->pushNodeToStack($rootNode);
     $state->setVariableProvider($variableProvider->getScopeCopy($variableProvider->getAll()));
     return $state;
 }
Exemplo n.º 22
0
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  *
  * @return mixed|string
  * @throws Exception
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $value = $arguments['value'];
     $default = $arguments['default'];
     $viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
     if ($default !== false) {
         GeneralUtility::deprecationLog('Argument "default" on f:case is deprecated - use f:defaultCase instead');
     }
     if ($value === null && $default === false) {
         throw new Exception('The case View helper must have either value or default argument', 1382867521);
     }
     $expression = $viewHelperVariableContainer->get(OriginalSwitchViewHelper::class, 'switchExpression');
     // non-type-safe comparison by intention
     if ($default === true || $expression == $value) {
         $viewHelperVariableContainer->addOrUpdate(OriginalSwitchViewHelper::class, 'break', true);
         return $renderChildrenClosure();
     }
     return '';
 }
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  *
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $uid = $arguments['uid'];
     if (isset(static::$workspaceTitleRuntimeCache[$uid])) {
         return htmlspecialchars(static::$workspaceTitleRuntimeCache[$uid]);
     }
     if ($uid === 0) {
         static::$workspaceTitleRuntimeCache[$uid] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('live', $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName());
     } elseif (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')) {
         static::$workspaceTitleRuntimeCache[$uid] = '';
     } else {
         $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $workspaceRepository = $objectManager->get(\TYPO3\CMS\Belog\Domain\Repository\WorkspaceRepository::class);
         /** @var $workspace \TYPO3\CMS\Belog\Domain\Model\Workspace */
         $workspace = $workspaceRepository->findByUid($uid);
         // $workspace may be null, force empty string in this case
         static::$workspaceTitleRuntimeCache[$uid] = $workspace === null ? '' : $workspace->getTitle();
     }
     return htmlspecialchars(static::$workspaceTitleRuntimeCache[$uid]);
 }
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $getVars = $arguments['getVars'];
     $setVars = $arguments['setVars'];
     $mayMakeShortcut = $GLOBALS['BE_USER']->mayMakeShortcut();
     if ($mayMakeShortcut) {
         $doc = GeneralUtility::makeInstance(DocumentTemplate::class);
         $currentRequest = $renderingContext->getControllerContext()->getRequest();
         $extensionName = $currentRequest->getControllerExtensionName();
         $moduleName = $currentRequest->getPluginName();
         if (count($getVars) === 0) {
             $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
             $getVars = array('id', 'M', $modulePrefix);
         }
         $getList = implode(',', $getVars);
         $setList = implode(',', $setVars);
         return $doc->makeShortcutIcon($getList, $setList, $moduleName);
     }
     return '';
 }
Exemplo n.º 25
0
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return mixed
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $values = $arguments['values'];
     $as = $arguments['as'];
     if ($values === null) {
         return $renderChildrenClosure();
     }
     $values = static::initializeValues($values);
     $index = static::initializeIndex($as, $renderingContext->getViewHelperVariableContainer());
     $currentValue = isset($values[$index]) ? $values[$index] : null;
     $renderingContext->getVariableProvider()->add($as, $currentValue);
     $output = $renderChildrenClosure();
     $renderingContext->getVariableProvider()->remove($as);
     $index++;
     if (!isset($values[$index])) {
         $index = 0;
     }
     $renderingContext->getViewHelperVariableContainer()->addOrUpdate(static::class, $as, $index);
     return $output;
 }
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  *
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
     $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
     /** @var \TYPO3\CMS\Belog\Domain\Repository\HistoryEntryRepository $historyEntryRepository */
     $historyEntryRepository = $objectManager->get(HistoryEntryRepository::class);
     /** @var \TYPO3\CMS\Belog\Domain\Model\HistoryEntry $historyEntry */
     $historyEntry = $historyEntryRepository->findOneBySysLogUid($arguments['uid']);
     /** @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext */
     $controllerContext = $renderingContext->getControllerContext();
     /** @var IconFactory $iconFactory */
     $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
     if (!$historyEntry instanceof HistoryEntry) {
         return '';
     }
     $historyLabel = LocalizationUtility::translate('changesInFields', $controllerContext->getRequest()->getControllerExtensionName(), array($historyEntry->getFieldlist()));
     $titleLable = LocalizationUtility::translate('showHistory', $controllerContext->getRequest()->getControllerExtensionName());
     $historyIcon = $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render();
     $historyHref = BackendUtility::getModuleUrl('record_history', array('sh_uid' => $historyEntry->getUid(), 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')));
     $historyLink = '<a href="' . htmlspecialchars($historyHref) . '" title="' . htmlspecialchars($titleLable) . '">' . $historyIcon . '</a>';
     return $historyLabel . '&nbsp;' . $historyLink;
 }
Exemplo n.º 27
0
 /**
  * Resolve workspace title from UID.
  *
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  *
  * @return string workspace title or UID
  * @throws \InvalidArgumentException
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     if (!$renderingContext instanceof RenderingContext) {
         throw new \InvalidArgumentException('The given rendering context is not of type "TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext"', 1468363946);
     }
     $uid = $arguments['uid'];
     if (isset(static::$workspaceTitleRuntimeCache[$uid])) {
         return static::$workspaceTitleRuntimeCache[$uid];
     }
     if ($uid === 0) {
         static::$workspaceTitleRuntimeCache[$uid] = LocalizationUtility::translate('live', $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName());
     } elseif (!ExtensionManagementUtility::isLoaded('workspaces')) {
         static::$workspaceTitleRuntimeCache[$uid] = '';
     } else {
         $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
         $workspaceRepository = $objectManager->get(WorkspaceRepository::class);
         /** @var \TYPO3\CMS\Belog\Domain\Model\Workspace $workspace */
         $workspace = $workspaceRepository->findByUid($uid);
         // $workspace may be null, force empty string in this case
         static::$workspaceTitleRuntimeCache[$uid] = $workspace === null ? '' : $workspace->getTitle();
     }
     return static::$workspaceTitleRuntimeCache[$uid];
 }
Exemplo n.º 28
0
 /**
  * @param RenderingContextInterface $renderingContext
  * @param string $expression
  * @param array $matches
  * @return integer|float
  */
 public static function evaluateExpression(RenderingContextInterface $renderingContext, $expression, array $matches)
 {
     // Split the expression on all recognized operators
     $matches = array();
     preg_match_all('/([+\\-*\\^\\/\\%]|[a-z0-9\\.]+)/s', $expression, $matches);
     $matches[0] = array_map('trim', $matches[0]);
     // Like the BooleanNode, we dumb down the processing logic to not apply
     // any special precedence on the priority of operators. We simply process
     // them in order.
     $variables = $renderingContext->getVariableProvider()->getAll();
     $result = array_shift($matches[0]);
     $result = parent::getTemplateVariableOrValueItself($result, $renderingContext);
     $operator = NULL;
     $operators = array('*', '^', '-', '+', '/', '%');
     foreach ($matches[0] as $part) {
         if (in_array($part, $operators)) {
             $operator = $part;
         } else {
             $part = parent::getTemplateVariableOrValueItself($part, $renderingContext);
             $result = self::evaluateOperation($result, $operator, $part);
         }
     }
     return $result;
 }
Exemplo n.º 29
0
 /**
  * Renders a partial.
  *
  * @param string $partialName
  * @param string $sectionName
  * @param array $variables
  * @param boolean $ignoreUnknown Ignore an unknown section and just return an empty string
  * @return string
  */
 public function renderPartial($partialName, $sectionName, array $variables, $ignoreUnknown = FALSE)
 {
     if (!isset($this->partialIdentifierCache[$partialName])) {
         $this->partialIdentifierCache[$partialName] = $this->baseRenderingContext->getTemplatePaths()->getPartialIdentifier($partialName);
     }
     $partialIdentifier = $this->partialIdentifierCache[$partialName];
     $parsedPartial = $this->baseRenderingContext->getTemplateParser()->getOrParseAndStoreTemplate($partialIdentifier, function ($parent, TemplatePaths $paths) use($partialName) {
         return $paths->getPartialSource($partialName);
     });
     $renderingContext = clone $this->getCurrentRenderingContext();
     $renderingContext->setVariableProvider($renderingContext->getVariableProvider()->getScopeCopy($variables));
     $this->startRendering(self::RENDERING_PARTIAL, $parsedPartial, $renderingContext);
     if ($sectionName !== NULL) {
         $output = $this->renderSection($sectionName, $variables, $ignoreUnknown);
     } else {
         $output = $parsedPartial->render($renderingContext);
     }
     $this->stopRendering();
     return $output;
 }
Exemplo n.º 30
0
    /**
     * @param string $identifier
     * @param ParsingState $parsingState
     * @return void
     */
    public function store($identifier, ParsingState $parsingState)
    {
        if ($this->isDisabled()) {
            if ($this->renderingContext->isCacheEnabled()) {
                // Compiler is disabled but cache is enabled. Flush cache to make sure.
                $this->renderingContext->getCache()->flush($identifier);
            }
            $parsingState->setCompilable(FALSE);
            return;
        }
        $identifier = $this->sanitizeIdentifier($identifier);
        $this->nodeConverter->setVariableCounter(0);
        $generatedRenderFunctions = $this->generateSectionCodeFromParsingState($parsingState);
        $generatedRenderFunctions .= $this->generateCodeForSection($this->nodeConverter->convertListOfSubNodes($parsingState->getRootNode()), 'render', 'Main Render function');
        $classDefinition = 'class ' . $identifier . ' extends \\TYPO3Fluid\\Fluid\\Core\\Compiler\\AbstractCompiledTemplate';
        $templateCode = <<<EOD
<?php

%s {

public function getLayoutName(\\TYPO3Fluid\\Fluid\\Core\\Rendering\\RenderingContextInterface \$renderingContext) {
\$layout = %s;
if (!\$layout) {
\$layout = '%s';
}
return \$layout;
}
public function hasLayout() {
return %s;
}
public function addCompiledNamespaces(\\TYPO3Fluid\\Fluid\\Core\\Rendering\\RenderingContextInterface \$renderingContext) {
\$renderingContext->getViewHelperResolver()->addNamespaces(%s);
}

%s

}
EOD;
        $templateCode = sprintf($templateCode, $classDefinition, '$renderingContext->getVariableProvider()->get(\'layoutName\')', $parsingState->getVariableContainer()->get('layoutName'), $parsingState->hasLayout() ? 'TRUE' : 'FALSE', var_export($this->renderingContext->getViewHelperResolver()->getNamespaces(), TRUE), $generatedRenderFunctions);
        $this->renderingContext->getCache()->set($identifier, $templateCode);
    }