/** * Render method * * @param mixed $subject * @throws Exception * @return mixed */ public function render($subject = NULL) { if (NULL === $subject && (FALSE === isset($as) || TRUE === empty($as))) { $subject = $this->renderChildren(); } $as = $this->arguments['as']; $array = NULL; if (TRUE === is_array($subject)) { $array = $subject; } elseif (TRUE === $subject instanceof QueryResultInterface) { /** @var QueryResultInterface $subject */ $array = $subject->toArray(); } elseif (TRUE === $subject instanceof \Traversable) { $array = iterator_to_array($subject, TRUE); } elseif (NULL !== $subject) { throw new Exception('Invalid variable type passed to Iterator/RandomViewHelper. Expected any of Array, QueryResult, ' . ' ObjectStorage or Iterator implementation but got ' . gettype($subject), 1370966821); } elseif (NULL === $subject) { return NULL; } $randomElement = $array[array_rand($array)]; if (TRUE === isset($as) && FALSE === empty($as)) { $variables = array($as => $randomElement); $content = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $content; } return $randomElement; }
/** * Render method * * @param integer $count The count of items per chunk or if fixed number of chunks * @param boolean $fixed Whether to allocate items to a fixed number of chunks or not * @param mixed $subject The subject Traversable/Array instance to shift * @param string $as If specified, inserts a template variable with this name, then renders the child content, then removes the variable * @param boolean $preserveKeys If set to true, the original array keys will be preserved in the chunks * @throws \Exception * @return array */ public function render($count, $fixed = FALSE, $subject = NULL, $as = NULL, $preserveKeys = FALSE) { if (NULL === $subject) { $subject = $this->renderChildren(); } if (TRUE === $subject instanceof \Traversable) { $subject = iterator_to_array($subject, TRUE); } elseif (FALSE === is_array($subject)) { throw new \Exception('Cannot get values of unsupported type: ' . gettype($subject), 1357098192); } $output = array(); if (0 >= $count) { return $output; } if (TRUE === (bool) $fixed) { $subjectSize = count($subject); if (0 < $subjectSize) { $chunkSize = ceil($subjectSize / $count); $output = array_chunk($subject, $chunkSize, $preserveKeys); } // Fill the resulting array with empty items to get the desired element count $elementCount = count($output); if ($elementCount < $count) { $output += array_fill($elementCount, $count - $elementCount, NULL); } } else { $output = array_chunk($subject, $count, $preserveKeys); } if (NULL !== $as) { $variables = array($as => $output); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); } return $output; }
/** * Merges arrays/Traversables $a and $b into an array * * @param mixed $a First array/Traversable * @param mixed $b Second array/Traversable * @param boolean $useKeys If TRUE, comparison is done while also observing (and merging) the keys used in each array * @return array */ public function render($a, $b, $useKeys = TRUE) { $this->useKeys = (bool) $useKeys; $a = ViewHelperUtility::arrayFromArrayOrTraversableOrCSV($a, $useKeys); $b = ViewHelperUtility::arrayFromArrayOrTraversableOrCSV($b, $useKeys); $merged = GeneralUtility::array_merge_recursive_overrule($a, $b); return $merged; }
/** * @return array */ public function render() { $a = $this->arguments['a']; if (NULL === $a) { $a = $this->renderChildren(); } $a = ViewHelperUtility::arrayFromArrayOrTraversableOrCSV($a); $b = ViewHelperUtility::arrayFromArrayOrTraversableOrCSV($this->arguments['b']); return array_intersect($a, $b); }
/** * Render method * * @return string */ public function render() { if ('BE' === TYPO3_MODE) { return ''; } $content = $this->getContentRecords(); $as = $this->arguments['as']; if (TRUE === empty($as)) { return implode(LF, $content); } $variables = array($as => $content); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $output; }
/** * @return mixed */ public function render() { $pageUid = $this->arguments['pageUid']; if (0 === $pageUid) { $pageUid = $GLOBALS['TSFE']->id; } $rootLineData = $this->pageSelect->getRootLine($pageUid); $as = $this->arguments['as']; if (TRUE === empty($as)) { return $rootLineData; } $variables = array($as => $rootLineData); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $output; }
/** * @return mixed */ public function render() { $files = $this->getFiles(TRUE); if (1 === count($files)) { $files = array_shift($files); } // Return if no assign $as = $this->arguments['as']; if (TRUE === empty($as)) { return $files; } $variables = array($as => $files); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $output; }
/** * Render method * * @param mixed $subject The subject Traversable/Array instance to pop * @param string $as If specified, inserts a template variable with this name, then renders the child content, then removes the variable * @throws \Exception * @return array */ public function render($subject = NULL, $as = NULL) { if (NULL === $subject) { $subject = $this->renderChildren(); } if (TRUE === $subject instanceof \Traversable) { $subject = iterator_to_array($subject, TRUE); } elseif (FALSE === is_array($subject)) { throw new \Exception('Cannot get values of unsupported type: ' . gettype($subject), 1357098192); } $output = array_pop($subject); if (NULL !== $as) { $variables = array($as => $output); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); } return $output; }
/** * @return array */ public function render() { $subject = $this->arguments['subject']; if (NULL === $subject) { $subject = $this->renderChildren(); } $subject = ViewHelperUtility::arrayFromArrayOrTraversableOrCSV($subject); $content = array_keys($subject); // Return if no assign $as = $this->arguments['as']; if (TRUE === empty($as)) { return $content; } $variables = array($as => $content); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $output; }
/** * Render method * * @param mixed $haystack * @param integer $start * @param integer $length * @param string $as * @throws \Exception * @return array */ public function render($haystack = NULL, $start = 0, $length = NULL, $as = NULL) { if (NULL === $haystack) { $haystack = $this->renderChildren(); } if (TRUE === $haystack instanceof \Iterator) { $haystack = iterator_to_array($haystack, TRUE); } elseif (FALSE === is_array($haystack)) { throw new \Exception('Cannot slice unsupported type: ' . gettype($haystack), 1353812601); } $output = array_slice($haystack, $start, $length, TRUE); if (NULL !== $as) { $variables = array($as => $output); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); } return $output; }
/** * Render method * * @return mixed */ public function render() { $content = $this->arguments['content']; $as = $this->arguments['as']; $glue = $this->resolveGlue(); $contentWasSource = FALSE; if (TRUE === empty($content)) { $content = $this->renderChildren(); $contentWasSource = TRUE; } $output = call_user_func_array($this->method, array($glue, $content)); if (TRUE === empty($as) || TRUE === $contentWasSource) { return $output; } $variables = array($as => $output); $content = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $content; }
/** * Render method * * @param string $pattern * @param string $string * @param boolean $global * @param string $as * @return string */ public function render($pattern, $string, $global = FALSE, $as = NULL) { $matches = array(); if (TRUE === (bool) $global) { preg_match_all($pattern, $string, $matches, PREG_SET_ORDER); } else { preg_match($pattern, $string, $matches); } if (FALSE === empty($as)) { $variables = array($as => $matches); $content = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); } else { if (0 < count($matches)) { $content = $this->renderThenChild(); } else { $content = $this->renderElseChild(); } } return $content; }
/** * Render method * * @return string */ public function render() { $files = $this->getFiles(); $images = $this->preprocessImages($files, TRUE); if (TRUE === empty($images)) { return NULL; } $info = array(); $tags = array(); foreach ($images as &$image) { $source = $this->preprocessSourceUri($image['source']); $width = $image['info'][0]; $height = $image['info'][1]; $alt = $this->arguments['alt']; if (TRUE === empty($alt)) { $alt = $image['file']['alternative']; } $this->tag->addAttribute('src', $source); $this->tag->addAttribute('width', $width); $this->tag->addAttribute('height', $height); $this->tag->addAttribute('alt', $alt); $tag = $this->tag->render(); $image['tag'] = $tag; $tags[] = $tag; $info[] = array('source' => $source, 'width' => $width, 'height' => $height, 'tag' => $tag); } // Return if no assign $as = $this->arguments['as']; if (TRUE === empty($as)) { return implode('', $tags); } $variables = array($as => $info); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $output; }
/** * Get link of language menu entry * * @param $uid * @return string */ protected function getLanguageUrl($uid) { $getValues = GeneralUtility::_GET(); $getValues['L'] = $uid; unset($getValues['id']); unset($getValues['cHash']); $addParams = http_build_query($getValues, '', '&'); $config = array('parameter' => $this->getPageUid(), 'returnLast' => 'url', 'additionalParams' => '&' . $addParams, 'useCacheHash' => $this->arguments['useCHash']); if (TRUE === is_array($this->arguments['configuration'])) { $config = ViewHelperUtility::mergeArrays($config, $this->arguments['configuration']); } return $this->cObj->typoLink('', $config); }
/** * @return mixed */ public function render() { try { $content = $this->renderThenChild(); if (TRUE === empty($content)) { $content = $this->renderChildren(); } } catch (\Exception $error) { $variables = array('exception' => $error); $content = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); } return $content; }
/** * Parses the supplied flags into the proper value for the sorting * function. * * @return integer */ protected function getSortFlags() { $constants = ViewHelperUtility::arrayFromArrayOrTraversableOrCSV($this->arguments['sortFlags']); $flags = 0; foreach ($constants as $constant) { if (FALSE === in_array($constant, $this->allowedSortFlags)) { throw new Exception('The constant "' . $constant . '" you\'re trying to use as a sortFlag is not allowed. Allowed constants are: ' . implode(', ', $this->allowedSortFlags) . '.', 1404220538); } $flags = $flags | constant(trim($constant)); } return $flags; }
/** * @return mixed */ public function render() { $contentUid = intval($this->arguments['contentUid']); if (0 === $contentUid) { $cObj = $this->configurationManager->getContentObject(); $record = $cObj->data; } $field = $this->arguments['field']; if (FALSE === isset($record) && 0 !== $contentUid) { if (NULL !== $field && TRUE === isset($GLOBALS['TCA']['tt_content']['columns'][$field])) { $selectFields = $field; } else { $selectFields = '*'; } $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow($selectFields, 'tt_content', sprintf('uid=%d', $contentUid)); // Add the page overlay $languageUid = intval($GLOBALS['TSFE']->sys_language_uid); if (0 !== $languageUid && $GLOBALS['TSFE']->sys_language_contentOL) { $record = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tt_content', $record, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); } } if (FALSE === $record && FALSE === isset($record)) { throw new \Exception(sprintf('Either record with uid %d or field %s do not exist.', $contentUid, $selectFields), 1358679983); } // Check if single field or whole record should be returned $content = NULL; if (NULL === $field) { $content = $record; } elseif (TRUE === isset($record[$field])) { $content = $record[$field]; } // Return if no assign $as = $this->arguments['as']; if (TRUE === empty($as)) { return $content; } $variables = array($as => $content); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $output; }
/** * Render method * @return NULL|string */ public function render() { // Check if link wizard link $pageUid = $this->arguments['pageUid']; $additionalParameters = (array) $this->arguments['additionalParams']; if (FALSE === is_numeric($pageUid)) { $linkConfig = GeneralUtility::unQuoteFilenames($pageUid, TRUE); if (TRUE === isset($linkConfig[0])) { $pageUid = $linkConfig[0]; } if (TRUE === isset($linkConfig[1]) && '-' !== $linkConfig[1]) { $this->tag->addAttribute('target', $linkConfig[1]); } if (TRUE === isset($linkConfig[2]) && '-' !== $linkConfig[2]) { $this->tag->addAttribute('class', $linkConfig[2]); } if (TRUE === isset($linkConfig[3]) && '-' !== $linkConfig[3]) { $this->tag->addAttribute('title', $linkConfig[3]); } if (TRUE === isset($linkConfig[4]) && '-' !== $linkConfig[4]) { $additionalParametersString = trim($linkConfig[4], '&'); $additionalParametersArray = GeneralUtility::trimExplode('&', $additionalParametersString); foreach ($additionalParametersArray as $parameter) { list($key, $value) = GeneralUtility::trimExplode('=', $parameter); $additionalParameters[$key] = $value; } } } // Get page via pageUid argument or current id $pageUid = intval($pageUid); if (0 === $pageUid) { $pageUid = $GLOBALS['TSFE']->id; } $page = $this->pageSelect->getPage($pageUid); if (TRUE === empty($page)) { return NULL; } // Do not render the link, if the page should be hidden $currentLanguageUid = $GLOBALS['TSFE']->sys_language_uid; $hidePage = $this->pageSelect->hidePageForLanguageUid($pageUid, $currentLanguageUid); if (TRUE === $hidePage) { return NULL; } // Get the title from the page or page overlay if (0 < $currentLanguageUid) { $pageOverlay = $this->pageSelect->getPageOverlay($pageUid, $currentLanguageUid); $title = $this->getTitleValue($pageOverlay); } else { $title = $this->getTitleValue($page); } // Check if we should assign page title to the template variable container $pageTitleAs = $this->arguments['pageTitleAs']; if (FALSE === empty($pageTitleAs)) { $variables = array($pageTitleAs => $title); } else { $variables = array(); } // Render childs to see if an alternative title content should be used $renderedTitle = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); if (FALSE === empty($renderedTitle)) { $title = $renderedTitle; } $uriBuilder = $this->controllerContext->getUriBuilder(); $uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($this->arguments['pageType'])->setNoCache($this->arguments['noCache'])->setUseCacheHash(!$this->arguments['noCacheHash'])->setSection($this->arguments['section'])->setLinkAccessRestrictedPages($this->arguments['linkAccessRestrictedPages'])->setArguments($additionalParameters)->setCreateAbsoluteUri($this->arguments['absolute'])->setAddQueryString($this->arguments['addQueryString'])->setArgumentsToBeExcludedFromQueryString((array) $this->arguments['argumentsToBeExcludedFromQueryString'])->build(); $this->tag->addAttribute('href', $uri); $this->tag->setContent($title); return $this->tag->render(); }
/** * @return mixed */ public function render() { $record = $this->arguments['record']; $uid = $this->arguments['uid']; if (NULL === $record) { if (NULL === $uid) { $record = $this->getActiveRecord(); } else { $record = $this->getRecord($uid); } } if (NULL === $record) { throw new Exception('No record was found. The "record" or "uid" argument must be specified.', 1384611413); } $resources = $this->getResources($record); $as = $this->arguments['as']; if (TRUE === empty($as)) { return $resources; } $variables = array($as => $resources); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $output; }
/** * "Render" method - sorts a target list-type target. Either $array or * $objectStorage must be specified. If both are, ObjectStorage takes precedence. * * Returns the same type as $subject. Ignores NULL values which would be * OK to use in an f:for (empty loop as result) * * @param array|\Iterator $subject An array or Iterator implementation to sort * @throws \Exception * @return mixed */ public function render($subject = NULL) { $as = $this->arguments['as']; if (NULL === $subject && NULL === $as) { // this case enables inline usage if the "as" argument // is not provided. If "as" is provided, the tag content // (which is where inline arguments are taken from) is // expected to contain the rendering rather than the variable. $subject = $this->renderChildren(); } $sorted = NULL; if (TRUE === is_array($subject)) { $sorted = $this->sortArray($subject); } else { if (TRUE === $subject instanceof ObjectStorage || TRUE === $subject instanceof LazyObjectStorage) { $sorted = $this->sortObjectStorage($subject); } elseif (TRUE === $subject instanceof \Iterator) { /** @var \Iterator $subject */ $array = iterator_to_array($subject, TRUE); $sorted = $this->sortArray($array); } elseif (TRUE === $subject instanceof QueryResultInterface) { /** @var QueryResultInterface $subject */ $sorted = $this->sortArray($subject->toArray()); } elseif (NULL !== $subject) { // a NULL value is respected and ignored, but any // unrecognized value other than this is considered a // fatal error. throw new \Exception('Unsortable variable type passed to Iterator/SortViewHelper. Expected any of Array, QueryResult, ' . ' ObjectStorage or Iterator implementation but got ' . gettype($subject), 1351958941); } } if (NULL !== $as) { $variables = array($as => $sorted); $content = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $content; } return $sorted; }
/** * @param array $assets * @return array * @throws \RuntimeException */ private function manipulateAssetsByTypoScriptSettings($assets) { $settings = $this->getSettings(); if (FALSE === (isset($settings['asset']) || isset($settings['assetGroup']))) { return $assets; } $filtered = array(); /** @var \FluidTYPO3\Vhs\Asset $asset */ foreach ($assets as $name => $asset) { $assetSettings = $this->extractAssetSettings($asset); $groupName = $assetSettings['group']; $removed = (bool) (TRUE === isset($assetSettings['removed']) ? $assetSettings['removed'] : FALSE); if (TRUE === $removed) { continue; } $localSettings = (array) $assetSettings; if (TRUE === isset($settings['asset'])) { $localSettings = ViewHelperUtility::mergeArrays($localSettings, (array) $settings['asset']); } if (TRUE === isset($settings['asset'][$name])) { $localSettings = ViewHelperUtility::mergeArrays($localSettings, (array) $settings['asset'][$name]); } if (TRUE === isset($settings['assetGroup'][$groupName])) { $localSettings = ViewHelperUtility::mergeArrays($localSettings, (array) $settings['assetGroup'][$groupName]); } if (TRUE === $asset instanceof \FluidTYPO3\Vhs\ViewHelpers\Asset\AssetInterface) { $asset->setSettings($localSettings); $filtered[$name] = $asset; } else { $filtered[$name] = $assetSettings; } } return $filtered; }
/** * @return mixed */ public function render() { // Get page via pageUid argument or current id $pageUid = intval($this->arguments['pageUid']); if (0 === $pageUid) { $pageUid = $GLOBALS['TSFE']->id; } $page = $this->pageSelect->getPage($pageUid); // Add the page overlay $languageUid = intval($GLOBALS['TSFE']->sys_language_uid); if (0 !== $languageUid) { $pageOverlay = $this->pageSelect->getPageOverlay($pageUid, $languageUid); if (TRUE === is_array($pageOverlay)) { $page = GeneralUtility::array_merge_recursive_overrule($page, $pageOverlay, FALSE, FALSE); } } $content = NULL; // Check if field should be returned or assigned $field = $this->arguments['field']; if (TRUE === empty($field)) { $content = $page; } elseif (TRUE === isset($page[$field])) { $content = $page[$field]; } // Return if no assign $as = $this->arguments['as']; if (TRUE === empty($as)) { return $content; } $variables = array($as => $content); $output = ViewHelperUtility::renderChildrenWithVariables($this, $this->templateVariableContainer, $variables); return $output; }