Utility to simulate frontend enviroment in backend enviroment.
コード例 #1
0
 /**
  * used to attach srcset variants of a given image to the specified tag
  *
  * @param \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder $tag the tag to add the srcset as argument
  * @param string $src image path to render srcsets for
  * @return array
  */
 public function addSourceSet($tag, $src)
 {
     $srcsets = $this->getSourceSetWidths();
     if ('BE' === TYPO3_MODE) {
         FrontendSimulationUtility::simulateFrontendEnvironment();
     }
     $format = $this->arguments['format'];
     $quality = $this->arguments['quality'];
     $treatIdAsReference = (bool) $this->arguments['treatIdAsReference'];
     if (true === $treatIdAsReference) {
         $src = $this->arguments['src'];
     }
     $imageSources = [];
     $srcsetVariants = [];
     foreach ($srcsets as $key => $width) {
         $srcsetVariant = $this->getImgResource($src, $width, $format, $quality, $treatIdAsReference);
         $srcsetVariantSrc = rawurldecode($srcsetVariant[3]);
         $srcsetVariantSrc = $this->preprocessSourceUri(GeneralUtility::rawUrlEncodeFP($srcsetVariantSrc));
         $imageSources[$srcsetVariant[0]] = ['src' => $srcsetVariantSrc, 'width' => $srcsetVariant[0], 'height' => $srcsetVariant[1]];
         $srcsetVariants[$srcsetVariant[0]] = $srcsetVariantSrc . ' ' . $srcsetVariant[0] . 'w';
     }
     $tag->addAttribute('srcset', implode(',', $srcsetVariants));
     if ('BE' === TYPO3_MODE) {
         FrontendSimulationUtility::resetFrontendEnvironment();
     }
     return $imageSources;
 }
コード例 #2
0
ファイル: CaseViewHelper.php プロジェクト: fluidtypo3/vhs
 /**
  * @param string $string
  * @param string $case
  * @return string
  */
 public function render($string = null, $case = null)
 {
     if (null === $string) {
         $string = $this->renderChildren();
     }
     if ('BE' === TYPO3_MODE) {
         $tsfeBackup = FrontendSimulationUtility::simulateFrontendEnvironment();
     }
     $charset = $GLOBALS['TSFE']->renderCharset;
     switch ($case) {
         case self::CASE_LOWER:
             $string = $GLOBALS['TSFE']->csConvObj->conv_case($charset, $string, 'toLower');
             break;
         case self::CASE_UPPER:
             $string = $GLOBALS['TSFE']->csConvObj->conv_case($charset, $string, 'toUpper');
             break;
         case self::CASE_UCWORDS:
             $string = ucwords($string);
             break;
         case self::CASE_UCFIRST:
             $string = $GLOBALS['TSFE']->csConvObj->convCaseFirst($charset, $string, 'toUpper');
             break;
         case self::CASE_LCFIRST:
             $string = $GLOBALS['TSFE']->csConvObj->convCaseFirst($charset, $string, 'toLower');
             break;
         case self::CASE_CAMELCASE:
             $string = GeneralUtility::underscoredToUpperCamelCase($string);
             break;
         case self::CASE_LOWERCAMELCASE:
             $string = GeneralUtility::underscoredToLowerCamelCase($string);
             break;
         case self::CASE_UNDERSCORED:
             $string = GeneralUtility::camelCaseToLowerCaseUnderscored($string);
             break;
         default:
             break;
     }
     if ('BE' === TYPO3_MODE) {
         FrontendSimulationUtility::resetFrontendEnvironment($tsfeBackup);
     }
     return $string;
 }
コード例 #3
0
ファイル: SourceViewHelper.php プロジェクト: smichaelsen/vhs
 /**
  * Render method
  *
  * @return string
  */
 public function render()
 {
     $src = $this->viewHelperVariableContainer->get(self::SCOPE, self::SCOPE_VARIABLE_SRC);
     if ('BE' === TYPO3_MODE) {
         $tsfeBackup = FrontendSimulationUtility::simulateFrontendEnvironment();
     }
     $setup = array('width' => $this->arguments['width'], 'height' => $this->arguments['height'], 'minW' => $this->arguments['minW'], 'minH' => $this->arguments['minH'], 'maxW' => $this->arguments['maxW'], 'maxH' => $this->arguments['maxH']);
     $quality = $this->arguments['quality'];
     $format = $this->arguments['format'];
     if (FALSE === empty($format)) {
         $setup['ext'] = $format;
     }
     if (0 < intval($quality)) {
         $quality = MathUtility::forceIntegerInRange($quality, 10, 100, 75);
         $setup['params'] .= ' -quality ' . $quality;
     }
     if ('BE' === TYPO3_MODE && '../' === substr($src, 0, 3)) {
         $src = substr($src, 3);
     }
     $result = $this->contentObject->getImgResource($src, $setup);
     if ('BE' === TYPO3_MODE) {
         FrontendSimulationUtility::resetFrontendEnvironment($tsfeBackup);
     }
     $src = $this->preprocessSourceUri(rawurldecode($result[3]));
     if (NULL === $this->arguments['media']) {
         $this->viewHelperVariableContainer->addOrUpdate(self::SCOPE, self::SCOPE_VARIABLE_DEFAULT_SOURCE, $src);
     } else {
         $this->tag->addAttribute('media', $this->arguments['media']);
     }
     $this->tag->addAttribute('srcset', $src);
     return $this->tag->render();
 }