/**
  * @param AssetInterface $asset
  * @param integer $maximumWidth
  * @param integer $maximumHeight
  * @return array
  */
 protected function getAssetThumbnailImage(AssetInterface $asset, $maximumWidth, $maximumHeight)
 {
     // TODO: Could be configurable at some point
     $iconPackage = 'TYPO3.Media';
     $iconSize = $this->getDocumentIconSize($maximumWidth, $maximumHeight);
     if (is_file('resource://' . $iconPackage . '/Public/Icons/16px/' . $asset->getResource()->getFileExtension() . '.png')) {
         $icon = sprintf('Icons/%spx/' . $asset->getResource()->getFileExtension() . '.png', $iconSize);
     } else {
         $icon = sprintf('Icons/%spx/_blank.png', $iconSize);
     }
     return array('width' => $iconSize, 'height' => $iconSize, 'src' => $this->resourceManager->getPublicPackageResourceUri($iconPackage, $icon));
 }
 /**
  * Render the URI to the resource. The filename is used from child content.
  *
  * @param string $path The location of the resource, can be either a path relative to the Public resource directory of the package or a resource://... URI
  * @param string $package Target package key. If not set, the current package key will be used
  * @param Resource $resource If specified, this resource object is used instead of the path and package information
  * @param boolean $localize Whether resource localization should be attempted or not
  * @return string The absolute URI to the resource
  * @throws InvalidVariableException
  * @api
  */
 public function render($path = null, $package = null, Resource $resource = null, $localize = true)
 {
     if ($resource !== null) {
         $uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
         if ($uri === false) {
             $uri = '404-Resource-Not-Found';
         }
     } else {
         if ($path === null) {
             throw new InvalidVariableException('The ResourceViewHelper did neither contain a valuable "resource" nor "path" argument.', 1353512742);
         }
         if ($package === null) {
             $package = $this->controllerContext->getRequest()->getControllerPackageKey();
         }
         if (strpos($path, 'resource://') === 0) {
             try {
                 list($package, $path) = $this->resourceManager->getPackageAndPathByPublicPath($path);
             } catch (Exception $exception) {
                 throw new InvalidVariableException(sprintf('The specified path "%s" does not point to a public resource.', $path), 1386458851);
             }
         }
         if ($localize === true) {
             $resourcePath = 'resource://' . $package . '/Public/' . $path;
             $localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath);
             $matches = array();
             if (preg_match('#resource://([^/]+)/Public/(.*)#', current($localizedResourcePathData), $matches) === 1) {
                 $package = $matches[1];
                 $path = $matches[2];
             }
         }
         $uri = $this->resourceManager->getPublicPackageResourceUri($package, $path);
     }
     return $uri;
 }
 /**
  * @param boolean $minified
  * @param string $include
  * @return string
  * @throws \Exception
  */
 public function render($minified = true, $include = 'remaining')
 {
     if (!in_array($include, array('all', 'css', 'js', 'remaining'))) {
         throw new \Exception('invalid include parameter. valid values are "remaining", "all", "css" and "js".');
     }
     if ($include == 'remaining') {
         if (self::$cssIncluded && self::$jsIncluded) {
             return '';
         } else {
             if (!self::$cssIncluded && !self::$jsIncluded) {
                 $include = 'all';
             } else {
                 if (!self::$cssIncluded) {
                     $include = 'css';
                 } else {
                     $include = 'js';
                 }
             }
         }
     } else {
         if ($include == 'all' && (self::$cssIncluded || self::$jsIncluded)) {
             throw new \Exception("Some Owlcarousel's dependencies are already included.");
         } else {
             if ($include == 'css' && self::$cssIncluded) {
                 throw new \Exception("Owlcarousel's CSS is already included.");
             } else {
                 if ($include == 'js' && self::$jsIncluded) {
                     throw new \Exception("Owlcarousel's JavaScript is already included.");
                 }
             }
         }
     }
     $return = '';
     if ($include == 'css' || $include == 'all') {
         $css = $this->resourceManager->getPublicPackageResourceUri('Axovis.Flow.Owlcarousel', 'Styles/owl.carousel.css');
         $return .= '<link rel="stylesheet" type="text/css" href="' . $css . '" />';
         self::$cssIncluded = true;
     }
     if ($include == 'js' || $include == 'all') {
         $js = $this->resourceManager->getPublicPackageResourceUri('Axovis.Flow.Owlcarousel', 'JavaScript/owl.carousel' . ($minified ? '.min' : '') . '.js');
         $return .= '<script type="text/javascript" src="' . $js . '"></script>';
         self::$jsIncluded = true;
     }
     return $return;
 }
Example #4
0
 /**
  * @param AssetInterface $asset
  * @param integer $maximumWidth
  * @param integer $maximumHeight
  * @return array
  */
 public function getStaticThumbnailForAsset(AssetInterface $asset, $maximumWidth, $maximumHeight)
 {
     $iconSize = $this->getDocumentIconSize($maximumWidth, $maximumHeight);
     if (is_file('resource://TYPO3.Media/Public/Icons/16px/' . $asset->getResource()->getFileExtension() . '.png')) {
         $icon = sprintf('Icons/%spx/' . $asset->getResource()->getFileExtension() . '.png', $iconSize);
     } else {
         $icon = sprintf('Icons/%spx/_blank.png', $iconSize);
     }
     $icon = $this->resourceManager->getPublicPackageResourceUri('TYPO3.Media', $icon);
     return array('width' => $iconSize, 'height' => $iconSize, 'src' => $icon);
 }
 /**
  * @param string $resourcePath
  * @return string
  */
 protected function getStaticResourceWebBaseUri($resourcePath)
 {
     $localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath);
     $matches = array();
     try {
         if (preg_match('#resource://([^/]+)/Public/(.*)#', current($localizedResourcePathData), $matches) === 1) {
             $packageKey = $matches[1];
             $path = $matches[2];
             return $this->resourceManager->getPublicPackageResourceUri($packageKey, $path);
         }
     } catch (\Exception $exception) {
         $this->systemLogger->logException($exception);
     }
     return '';
 }
 /**
  * @param Thumbnail $thumbnail
  * @return string
  * @throws ThumbnailServiceException
  */
 public function getUriForThumbnail(Thumbnail $thumbnail)
 {
     $resource = $thumbnail->getResource();
     if ($resource) {
         return $this->resourceManager->getPublicPersistentResourceUri($resource);
     }
     $staticResource = $thumbnail->getStaticResource();
     if ($staticResource === null) {
         throw new ThumbnailServiceException(sprintf('Could not generate URI for static thumbnail "%s".', $this->persistenceManager->getIdentifierByObject($thumbnail)), 1450178437);
     }
     try {
         list($package, $path) = $this->resourceManager->getPackageAndPathByPublicPath($staticResource);
         return $this->resourceManager->getPublicPackageResourceUri($package, $path);
     } catch (Exception $exception) {
         return $staticResource;
     }
 }
Example #7
0
 /**
  * Creates a key-value list of JS modules and their sources files
  * out of the given configuration
  *
  * @return array
  */
 protected function transformLegacyModuleMapping()
 {
     $finalMapping = [];
     foreach ($this->legacyModuleMapping as $path => $modules) {
         if (preg_match('#resource://([^/]+)/Public/(.*)#', $path, $matches) === 1) {
             $packageKey = $matches[1];
             $path = $matches[2];
             $realPath = $this->resourceManager->getPublicPackageResourceUri($packageKey, $path);
             foreach ($modules as $module => $migratesTo) {
                 $finalMapping[$module] = ['target' => $realPath, 'migratesTo' => $migratesTo];
             }
             continue;
         }
         throw new \Exception(sprintf('"%s" is not a valid path to a public JavaScript. ' . 'Please provide a resource path ("resource://...")', $path), 1463923183);
     }
     return $finalMapping;
 }
 /**
  * Returns the absolute URL of a resource
  *
  * @return string
  * @throws TypoScriptException
  */
 public function evaluate()
 {
     $resource = $this->getResource();
     if ($resource !== null) {
         $uri = false;
         if ($resource instanceof Resource) {
             $uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
         }
         if ($uri === false) {
             throw new TypoScriptException('The specified resource is invalid', 1386458728);
         }
         return $uri;
     }
     $path = $this->getPath();
     if ($path === null) {
         throw new TypoScriptException('Neither "resource" nor "path" were specified', 1386458763);
     }
     if (strpos($path, 'resource://') === 0) {
         $matches = array();
         if (preg_match('#^resource://([^/]+)/Public/(.*)#', $path, $matches) !== 1) {
             throw new TypoScriptException(sprintf('The specified path "%s" does not point to a public resource.', $path), 1386458851);
         }
         $package = $matches[1];
         $path = $matches[2];
     } else {
         $package = $this->getPackage();
         if ($package === null) {
             $controllerContext = $this->tsRuntime->getControllerContext();
             /** @var $actionRequest ActionRequest */
             $actionRequest = $controllerContext->getRequest();
             $package = $actionRequest->getControllerPackageKey();
         }
     }
     $localize = $this->isLocalize();
     if ($localize === true) {
         $resourcePath = 'resource://' . $package . '/Public/' . $path;
         $localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath);
         $matches = array();
         if (preg_match('#resource://([^/]+)/Public/(.*)#', current($localizedResourcePathData), $matches) === 1) {
             $package = $matches[1];
             $path = $matches[2];
         }
     }
     return $this->resourceManager->getPublicPackageResourceUri($package, $path);
 }
 /**
  * If ui.help.message is set in $configuration, translate it if requested and then convert it from markdown to HTML.
  *
  * @param array $configuration
  * @param string $idPrefix
  * @param string $nodeTypeName
  * @return void
  */
 protected function translateAndConvertHelpMessage(array &$configuration, $idPrefix, $nodeTypeName = null)
 {
     $helpMessage = '';
     if (isset($configuration['ui']['help'])) {
         // message handling
         if (isset($configuration['ui']['help']['message'])) {
             if ($this->shouldFetchTranslation($configuration['ui']['help'], 'message')) {
                 $translationIdentifier = $this->splitIdentifier($idPrefix . 'ui.help.message');
                 $helpMessage = $this->translator->translateById($translationIdentifier['id'], [], null, null, $translationIdentifier['source'], $translationIdentifier['packageKey']);
             } else {
                 $helpMessage = $configuration['ui']['help']['message'];
             }
         }
         // prepare thumbnail
         if ($nodeTypeName !== null) {
             $thumbnailUrl = '';
             if (isset($configuration['ui']['help']['thumbnail'])) {
                 $thumbnailUrl = $configuration['ui']['help']['thumbnail'];
                 $matches = [];
                 if (preg_match('/resource:\\/\\/(?P<packageKey>[^\\/]+)\\/(?P<relativePathAndFilename>.+)/', $thumbnailUrl, $matches) === 1) {
                     $thumbnailUrl = $this->resourceManager->getPublicPackageResourceUri($matches['packageKey'], $matches['relativePathAndFilename']);
                 }
             } else {
                 # look in well know location
                 $splitPrefix = $this->splitIdentifier($nodeTypeName);
                 $relativePathAndFilename = 'NodeTypes/Thumbnails/' . $splitPrefix['id'] . '.png';
                 if (file_exists('resource://' . $splitPrefix['packageKey'] . '/Public/' . $relativePathAndFilename)) {
                     $thumbnailUrl = $this->resourceManager->getPublicPackageResourceUri($splitPrefix['packageKey'], $relativePathAndFilename);
                 }
             }
             if ($thumbnailUrl !== '') {
                 $helpMessage = '![alt text](' . $thumbnailUrl . ') ' . $helpMessage;
             }
         }
         if ($helpMessage !== '') {
             $helpMessage = $this->markdownConverter->convertToHtml($helpMessage);
             $helpMessage = $this->addTargetAttribute($helpMessage);
         }
     }
     $configuration['ui']['help']['message'] = $helpMessage;
 }
 /**
  * Render the URI to the resource. The filename is used from child content.
  *
  * @param string $path The location of the resource, can be either a path relative to the Public resource directory of the package or a resource://... URI
  * @param string $package Target package key. If not set, the current package key will be used
  * @param Resource $resource If specified, this resource object is used instead of the path and package information
  * @param boolean $localize Whether resource localization should be attempted or not
  * @return string The absolute URI to the resource
  * @throws InvalidVariableException
  * @api
  */
 public function render($path = NULL, $package = NULL, Resource $resource = NULL, $localize = TRUE)
 {
     if ($resource !== NULL) {
         $uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
         if ($uri === FALSE) {
             $uri = '404-Resource-Not-Found';
         }
     } else {
         if ($path === NULL) {
             throw new InvalidVariableException('The ResourceViewHelper did neither contain a valuable "resource" nor "path" argument.', 1353512742);
         }
         if ($package === NULL) {
             $package = $this->controllerContext->getRequest()->getControllerPackageKey();
         }
         if (strpos($path, 'resource://') === 0) {
             $matches = array();
             if (preg_match('#^resource://([^/]+)/Public/(.*)#', $path, $matches) === 1) {
                 $package = $matches[1];
                 $path = $matches[2];
             } else {
                 throw new InvalidVariableException(sprintf('The path "%s" which was given to the ResourceViewHelper must point to a public resource.', $path), 1353512639);
             }
         }
         if ($localize === TRUE) {
             $resourcePath = 'resource://' . $package . '/Public/' . $path;
             $localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath);
             $matches = array();
             if (preg_match('#resource://([^/]+)/Public/(.*)#', current($localizedResourcePathData), $matches) === 1) {
                 $package = $matches[1];
                 $path = $matches[2];
             }
         }
         $uri = $this->resourceManager->getPublicPackageResourceUri($package, $path);
     }
     return $uri;
 }
 /**
  * @param Asset $asset
  * @return array
  */
 protected function getAssetProperties(Asset $asset)
 {
     $thumbnail = $this->getAssetThumbnailImage($asset, 16, 16);
     $assetProperties = array('assetUuid' => $this->persistenceManager->getIdentifierByObject($asset), 'filename' => $asset->getResource()->getFilename(), 'previewImageResourceUri' => $this->resourceManager->getPublicPackageResourceUri($thumbnail['package'], $thumbnail['src']), 'previewSize' => array('w' => $thumbnail['width'], 'h' => $thumbnail['height']));
     return $assetProperties;
 }
    /**
     * @param array $items array of Resources,Assets or strings (uri)
     * @param string $id of the carousel instance
     * @param string $class class attribute of carousel element
     * @param bool $autoinclude include scripts and styles if not already done
     * @param int $numItems number of items to display at once
     * @param bool $itemsScaleUp scale up carousel items
     * @param bool $singleItem always display a single item
     * @param bool $showNavigation show carousel navigation
     * @param bool $pagination enable pagination
     * @param int $paginationSpeed speed of the pagination
     * @param bool $paginationNumbers show pagination numbers
     * @param bool $rewindNavigation rewind navigation on end
     * @param bool $autoplay enable autoplay
     * @param int $autoplaySpeed speed of autoplay
     * @param bool $pauseOnHover pause autoplay on hover
     * @param bool $loop loop animation instead of rewind
     * @param bool $isResponsive enable responsive design
     * @param array<string,int> $responsiveConfig responsive configuration array("{minScreenSize}" => [numElements],...))
     * @param int $itemMaxWidth image thumbnail max width
     * @param int $itemMaxHeight image thumbnail max height
     * @param bool $itemAllowCropping allow cropping thumbnails
     * @param bool $itemAllowUpscaling allow upscaling thumbnails
     *
     * @return string
     */
    public function render($items, $id = null, $class = null, $autoinclude = true, $numItems = 1, $itemsScaleUp = true, $singleItem = true, $showNavigation = true, $pagination = true, $paginationSpeed = 800, $paginationNumbers = true, $rewindNavigation = true, $autoplay = true, $autoplaySpeed = 200, $pauseOnHover = true, $loop = true, $isResponsive = false, $responsiveConfig = array("0" => 1, "479" => 2, "768" => 3, "1199" => 5), $itemMaxWidth = null, $itemMaxHeight = null, $itemAllowCropping = false, $itemAllowUpscaling = false)
    {
        if ($id == null) {
            $id = 'oc' . md5(microtime());
        }
        if ($class == null) {
            $class = 'owl-carousel';
        } else {
            $class .= ' owl-carousel';
        }
        //build config array
        $config = array();
        $config['items'] = $numItems;
        $config['itemsScaleUp'] = $itemsScaleUp;
        $config['singleItem'] = $singleItem;
        $config['nav'] = $showNavigation;
        $config['pagination'] = $pagination;
        $config['paginationSpeed'] = $paginationSpeed;
        $config['paginationNumbers'] = $paginationNumbers;
        $config['rewindNav'] = $rewindNavigation;
        $config['autoplay'] = $autoplay;
        $config['autoplaySpeed'] = $autoplaySpeed;
        $config['autoplayHoverPause'] = $pauseOnHover;
        $config['loop'] = $loop;
        $config['responsiveClass'] = $isResponsive;
        //include dependencies if necessary
        $includeContent = '';
        if ($autoinclude) {
            $viewHelper = $this->objectManager->get('Axovis\\Flow\\Owlcarousel\\ViewHelpers\\IncludeViewHelper');
            $includeContent = $viewHelper->render(true, 'remaining');
        }
        //build items content
        $itemsContent = '';
        foreach ($items as $item) {
            $title = '';
            $caption = '';
            if ($item instanceof Resource) {
                $uri = $this->resourceManager->getPublicPersistentResourceUri($item);
            } else {
                if ($item instanceof Asset) {
                    $thumbnailConfiguration = new ThumbnailConfiguration(null, $itemMaxWidth, null, $itemMaxHeight, $itemAllowCropping, $itemAllowUpscaling, false);
                    $uri = $this->assetService->getThumbnailUriAndSizeForAsset($item, $thumbnailConfiguration)['src'];
                    //$uri = $this->resourceManager->getPublicPersistentResourceUri($item->getResource());
                    $title = $item->getTitle();
                    $caption = $item->getCaption();
                } else {
                    if (is_string($item)) {
                        $uri = $item;
                    } else {
                        $title = 'Dummy Image';
                        $uri = $this->resourceManager->getPublicPackageResourceUri('Axovis.Flow.Owlcarousel', 'Images/dummy-image.png');
                    }
                }
            }
            $itemsContent .= '
                <div class="item">
                    <div>
                        <img src="' . $uri . '" title="' . $title . '" alt="' . $title . '" />
                        <div class="carousel-caption">
                            ' . $caption . '
                        </div>
                    </div>
                </div>
            ';
        }
        //build responsive config content
        $responsiveConfigContent = '';
        if ($isResponsive) {
            $responsiveConfigContent = 'config.responsive = {};';
            foreach ($responsiveConfig as $screen => $numItems) {
                $responsiveConfigContent .= '
                    config.responsive["' . $screen . '"] = {};
                    config.responsive["' . $screen . '"].items = ' . $numItems . ';
                ';
            }
        }
        return '
            ' . $includeContent . '
            <div id="' . $id . '" class="' . $class . '">
                ' . $itemsContent . '
            </div>
            <script type="text/javascript">
                $(document).ready(function(){
                    var config = ' . json_encode($config, JSON_NUMERIC_CHECK) . ';
                    ' . $responsiveConfigContent . '

                    $("#' . $id . '").owlCarousel(config);
                });
            </script>
        ';
    }