@@ -19,155 +19,155 @@ |
||
| 19 | 19 | abstract class AbstractThumbnailProcessor implements ThumbnailProcessorInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var ThumbnailService |
|
| 24 | - */ |
|
| 25 | - protected $thumbnailService; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Store a Processed File along the processing. |
|
| 29 | - * |
|
| 30 | - * @var \TYPO3\CMS\Core\Resource\ProcessedFile |
|
| 31 | - */ |
|
| 32 | - protected $processedFile; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Define what are the rendering steps for a thumbnail. |
|
| 36 | - * |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - protected $renderingSteps = [ |
|
| 40 | - ThumbnailInterface::OUTPUT_URI => 'renderUri', |
|
| 41 | - ThumbnailInterface::OUTPUT_IMAGE => 'renderTagImage', |
|
| 42 | - ThumbnailInterface::OUTPUT_IMAGE_WRAPPED => 'renderTagAnchor', |
|
| 43 | - ]; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param ThumbnailService $thumbnailService |
|
| 47 | - * @return $this |
|
| 48 | - */ |
|
| 49 | - public function setThumbnailService(ThumbnailService $thumbnailService) |
|
| 50 | - { |
|
| 51 | - $this->thumbnailService = $thumbnailService; |
|
| 52 | - return $this; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Return what needs to be rendered |
|
| 57 | - * |
|
| 58 | - * @return array |
|
| 59 | - */ |
|
| 60 | - protected function getRenderingSteps() |
|
| 61 | - { |
|
| 62 | - $position = array_search($this->thumbnailService->getOutputType(), array_keys($this->renderingSteps)); |
|
| 63 | - return array_slice($this->renderingSteps, 0, $position + 1); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Render additional attribute for this DOM element. |
|
| 69 | - * |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - protected function renderAttributes() |
|
| 73 | - { |
|
| 74 | - $result = ''; |
|
| 75 | - $attributes = $this->thumbnailService->getAttributes(); |
|
| 76 | - if (is_array($attributes)) { |
|
| 77 | - foreach ($attributes as $attribute => $value) { |
|
| 78 | - $result .= sprintf('%s="%s" ', |
|
| 79 | - htmlspecialchars($attribute), |
|
| 80 | - htmlspecialchars($value) |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - return $result; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @return array |
|
| 89 | - * @throws \Fab\Media\Exception\InvalidKeyInArrayException |
|
| 90 | - * @throws \Fab\Media\Exception\EmptyValueException |
|
| 91 | - */ |
|
| 92 | - protected function getConfiguration() |
|
| 93 | - { |
|
| 94 | - $configuration = $this->thumbnailService->getConfiguration(); |
|
| 95 | - if (!$configuration) { |
|
| 96 | - $dimension = ImagePresetUtility::getInstance()->preset('image_thumbnail'); |
|
| 97 | - $configuration = array( |
|
| 98 | - 'width' => $dimension->getWidth(), |
|
| 99 | - 'height' => $dimension->getHeight(), |
|
| 100 | - ); |
|
| 101 | - } |
|
| 102 | - return $configuration; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Returns a path to an icon given an extension. |
|
| 107 | - * |
|
| 108 | - * @param string $extension File extension |
|
| 109 | - * @return string |
|
| 110 | - */ |
|
| 111 | - protected function getIcon($extension) |
|
| 112 | - { |
|
| 113 | - $resource = Path::getRelativePath(sprintf('Icons/MimeType/%s.png', $extension)); |
|
| 114 | - |
|
| 115 | - // If file is not found, fall back to a default icon |
|
| 116 | - if (Path::notExists($resource)) { |
|
| 117 | - $resource = Path::getRelativePath('Icons/MissingMimeTypeIcon.png'); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $resource; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param string $uri |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function prefixUri($uri) |
|
| 128 | - { |
|
| 129 | - if ($this->isFrontendMode() && $this->getFrontendObject()->absRefPrefix) { |
|
| 130 | - $uri = $this->getFrontendObject()->absRefPrefix . $uri; |
|
| 131 | - } |
|
| 132 | - return $uri; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Returns true whether an thumbnail can be generated |
|
| 137 | - * |
|
| 138 | - * @param string $extension File extension |
|
| 139 | - * @return boolean |
|
| 140 | - */ |
|
| 141 | - protected function isThumbnailPossible($extension) |
|
| 142 | - { |
|
| 143 | - return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($extension)); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return File |
|
| 148 | - */ |
|
| 149 | - protected function getFile() |
|
| 150 | - { |
|
| 151 | - return $this->thumbnailService->getFile(); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Returns whether the current mode is Frontend |
|
| 156 | - * |
|
| 157 | - * @return bool |
|
| 158 | - */ |
|
| 159 | - protected function isFrontendMode() |
|
| 160 | - { |
|
| 161 | - return TYPO3_MODE === 'FE'; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Returns an instance of the Frontend object. |
|
| 166 | - * |
|
| 167 | - * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController |
|
| 168 | - */ |
|
| 169 | - protected function getFrontendObject() |
|
| 170 | - { |
|
| 171 | - return $GLOBALS['TSFE']; |
|
| 172 | - } |
|
| 22 | + /** |
|
| 23 | + * @var ThumbnailService |
|
| 24 | + */ |
|
| 25 | + protected $thumbnailService; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Store a Processed File along the processing. |
|
| 29 | + * |
|
| 30 | + * @var \TYPO3\CMS\Core\Resource\ProcessedFile |
|
| 31 | + */ |
|
| 32 | + protected $processedFile; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Define what are the rendering steps for a thumbnail. |
|
| 36 | + * |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + protected $renderingSteps = [ |
|
| 40 | + ThumbnailInterface::OUTPUT_URI => 'renderUri', |
|
| 41 | + ThumbnailInterface::OUTPUT_IMAGE => 'renderTagImage', |
|
| 42 | + ThumbnailInterface::OUTPUT_IMAGE_WRAPPED => 'renderTagAnchor', |
|
| 43 | + ]; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param ThumbnailService $thumbnailService |
|
| 47 | + * @return $this |
|
| 48 | + */ |
|
| 49 | + public function setThumbnailService(ThumbnailService $thumbnailService) |
|
| 50 | + { |
|
| 51 | + $this->thumbnailService = $thumbnailService; |
|
| 52 | + return $this; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Return what needs to be rendered |
|
| 57 | + * |
|
| 58 | + * @return array |
|
| 59 | + */ |
|
| 60 | + protected function getRenderingSteps() |
|
| 61 | + { |
|
| 62 | + $position = array_search($this->thumbnailService->getOutputType(), array_keys($this->renderingSteps)); |
|
| 63 | + return array_slice($this->renderingSteps, 0, $position + 1); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Render additional attribute for this DOM element. |
|
| 69 | + * |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + protected function renderAttributes() |
|
| 73 | + { |
|
| 74 | + $result = ''; |
|
| 75 | + $attributes = $this->thumbnailService->getAttributes(); |
|
| 76 | + if (is_array($attributes)) { |
|
| 77 | + foreach ($attributes as $attribute => $value) { |
|
| 78 | + $result .= sprintf('%s="%s" ', |
|
| 79 | + htmlspecialchars($attribute), |
|
| 80 | + htmlspecialchars($value) |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + return $result; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @return array |
|
| 89 | + * @throws \Fab\Media\Exception\InvalidKeyInArrayException |
|
| 90 | + * @throws \Fab\Media\Exception\EmptyValueException |
|
| 91 | + */ |
|
| 92 | + protected function getConfiguration() |
|
| 93 | + { |
|
| 94 | + $configuration = $this->thumbnailService->getConfiguration(); |
|
| 95 | + if (!$configuration) { |
|
| 96 | + $dimension = ImagePresetUtility::getInstance()->preset('image_thumbnail'); |
|
| 97 | + $configuration = array( |
|
| 98 | + 'width' => $dimension->getWidth(), |
|
| 99 | + 'height' => $dimension->getHeight(), |
|
| 100 | + ); |
|
| 101 | + } |
|
| 102 | + return $configuration; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Returns a path to an icon given an extension. |
|
| 107 | + * |
|
| 108 | + * @param string $extension File extension |
|
| 109 | + * @return string |
|
| 110 | + */ |
|
| 111 | + protected function getIcon($extension) |
|
| 112 | + { |
|
| 113 | + $resource = Path::getRelativePath(sprintf('Icons/MimeType/%s.png', $extension)); |
|
| 114 | + |
|
| 115 | + // If file is not found, fall back to a default icon |
|
| 116 | + if (Path::notExists($resource)) { |
|
| 117 | + $resource = Path::getRelativePath('Icons/MissingMimeTypeIcon.png'); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $resource; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param string $uri |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function prefixUri($uri) |
|
| 128 | + { |
|
| 129 | + if ($this->isFrontendMode() && $this->getFrontendObject()->absRefPrefix) { |
|
| 130 | + $uri = $this->getFrontendObject()->absRefPrefix . $uri; |
|
| 131 | + } |
|
| 132 | + return $uri; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Returns true whether an thumbnail can be generated |
|
| 137 | + * |
|
| 138 | + * @param string $extension File extension |
|
| 139 | + * @return boolean |
|
| 140 | + */ |
|
| 141 | + protected function isThumbnailPossible($extension) |
|
| 142 | + { |
|
| 143 | + return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($extension)); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return File |
|
| 148 | + */ |
|
| 149 | + protected function getFile() |
|
| 150 | + { |
|
| 151 | + return $this->thumbnailService->getFile(); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Returns whether the current mode is Frontend |
|
| 156 | + * |
|
| 157 | + * @return bool |
|
| 158 | + */ |
|
| 159 | + protected function isFrontendMode() |
|
| 160 | + { |
|
| 161 | + return TYPO3_MODE === 'FE'; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Returns an instance of the Frontend object. |
|
| 166 | + * |
|
| 167 | + * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController |
|
| 168 | + */ |
|
| 169 | + protected function getFrontendObject() |
|
| 170 | + { |
|
| 171 | + return $GLOBALS['TSFE']; |
|
| 172 | + } |
|
| 173 | 173 | } |
@@ -20,313 +20,313 @@ |
||
| 20 | 20 | class ThumbnailService |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - protected $allowedOutputTypes = array( |
|
| 27 | - ThumbnailInterface::OUTPUT_IMAGE, |
|
| 28 | - ThumbnailInterface::OUTPUT_IMAGE_WRAPPED, |
|
| 29 | - ThumbnailInterface::OUTPUT_URI, |
|
| 30 | - ); |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Configure the output of the thumbnail service whether it is wrapped or not. |
|
| 34 | - * Default output is: ThumbnailInterface::OUTPUT_IMAGE |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected $outputType = ThumbnailInterface::OUTPUT_IMAGE; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var File |
|
| 42 | - */ |
|
| 43 | - protected $file; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Define width, height and all sort of attributes to render a thumbnail. |
|
| 47 | - * @see TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::Image |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected $configuration = []; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Define width, height and all sort of attributes to render the anchor file |
|
| 54 | - * which is wrapping the image |
|
| 55 | - * |
|
| 56 | - * @see TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::Image |
|
| 57 | - * @var array |
|
| 58 | - */ |
|
| 59 | - protected $configurationWrap = []; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * DOM attributes to add to the image preview. |
|
| 63 | - * |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 66 | - protected $attributes = [ |
|
| 67 | - 'class' => 'thumbnail', |
|
| 68 | - ]; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Define in which window will the thumbnail be opened. |
|
| 72 | - * Does only apply if the thumbnail is wrapped (with an anchor). |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - protected $target = ThumbnailInterface::TARGET_BLANK; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * URI of the wrapping anchor pointing to the file. |
|
| 80 | - * replacing the "?" <a href="?">...</a> |
|
| 81 | - * The URI is automatically computed if not set. |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 84 | - protected $anchorUri; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Whether a time stamp is appended to the image. |
|
| 88 | - * Appending the time stamp can prevent caching |
|
| 89 | - * |
|
| 90 | - * @var bool |
|
| 91 | - */ |
|
| 92 | - protected $appendTimeStamp = false; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Define the processing type for the thumbnail. |
|
| 96 | - * As instance for image the default is ProcessedFile::CONTEXT_IMAGECROPSCALEMASK. |
|
| 97 | - * |
|
| 98 | - * @var string |
|
| 99 | - */ |
|
| 100 | - protected $processingType; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Constructor |
|
| 104 | - * |
|
| 105 | - * @param File $file |
|
| 106 | - */ |
|
| 107 | - public function __construct(File $file = null) |
|
| 108 | - { |
|
| 109 | - $this->file = $file; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Render a thumbnail of a media |
|
| 114 | - * |
|
| 115 | - * @throws MissingTcaConfigurationException |
|
| 116 | - * @return string |
|
| 117 | - * @throws \InvalidArgumentException |
|
| 118 | - */ |
|
| 119 | - public function create() |
|
| 120 | - { |
|
| 121 | - |
|
| 122 | - if (!$this->file) { |
|
| 123 | - throw new MissingTcaConfigurationException('Missing File object. Forgotten to set a file?', 1355933144); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // Default class name |
|
| 127 | - $className = 'Fab\Media\Thumbnail\FallBackThumbnailProcessor'; |
|
| 128 | - if (File::FILETYPE_IMAGE === $this->file->getType()) { |
|
| 129 | - $className = 'Fab\Media\Thumbnail\ImageThumbnailProcessor'; |
|
| 130 | - } elseif (File::FILETYPE_AUDIO === $this->file->getType()) { |
|
| 131 | - $className = 'Fab\Media\Thumbnail\AudioThumbnailProcessor'; |
|
| 132 | - } elseif (File::FILETYPE_VIDEO === $this->file->getType()) { |
|
| 133 | - $className = 'Fab\Media\Thumbnail\VideoThumbnailProcessor'; |
|
| 134 | - } elseif (File::FILETYPE_APPLICATION === $this->file->getType() || File::FILETYPE_TEXT === $this->file->getType()) { |
|
| 135 | - $className = 'Fab\Media\Thumbnail\ApplicationThumbnailProcessor'; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** @var $processorInstance \Fab\Media\Thumbnail\ThumbnailProcessorInterface */ |
|
| 139 | - $processorInstance = GeneralUtility::makeInstance($className); |
|
| 140 | - |
|
| 141 | - $thumbnail = ''; |
|
| 142 | - if ($this->file->exists()) { |
|
| 143 | - $thumbnail = $processorInstance->setThumbnailService($this)->create(); |
|
| 144 | - } else { |
|
| 145 | - $logger = Logger::getInstance($this); |
|
| 146 | - $logger->warning(sprintf('Resource not found for File uid "%s" at %s', $this->file->getUid(), $this->file->getIdentifier())); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $thumbnail; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function getConfigurationWrap() |
|
| 156 | - { |
|
| 157 | - return $this->configurationWrap; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param array $configurationWrap |
|
| 162 | - * @return $this |
|
| 163 | - */ |
|
| 164 | - public function setConfigurationWrap($configurationWrap) |
|
| 165 | - { |
|
| 166 | - $this->configurationWrap = $configurationWrap; |
|
| 167 | - return $this; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @return mixed |
|
| 172 | - */ |
|
| 173 | - public function getFile() |
|
| 174 | - { |
|
| 175 | - return $this->file; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return array |
|
| 180 | - */ |
|
| 181 | - public function getConfiguration() |
|
| 182 | - { |
|
| 183 | - return $this->configuration; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param array|ThumbnailConfiguration $configuration |
|
| 188 | - * @return $this |
|
| 189 | - */ |
|
| 190 | - public function setConfiguration($configuration) |
|
| 191 | - { |
|
| 192 | - if ($configuration instanceof ThumbnailConfiguration) { |
|
| 193 | - $configurationObject = $configuration; |
|
| 194 | - $configuration = []; |
|
| 195 | - |
|
| 196 | - if ($configurationObject->getWidth() > 0) { |
|
| 197 | - $configuration['width'] = $configurationObject->getWidth(); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($configurationObject->getHeight() > 0) { |
|
| 201 | - $configuration['height'] = $configurationObject->getHeight(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ($configurationObject->getStyle()) { |
|
| 205 | - $this->attributes['style'] = $configurationObject->getStyle(); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if ($configurationObject->getClassName()) { |
|
| 209 | - $this->attributes['class'] = $configurationObject->getClassName(); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $this->configuration = $configuration; |
|
| 214 | - return $this; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @return array |
|
| 219 | - */ |
|
| 220 | - public function getAttributes() |
|
| 221 | - { |
|
| 222 | - return $this->attributes; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param array $attributes |
|
| 227 | - * @return $this |
|
| 228 | - */ |
|
| 229 | - public function setAttributes($attributes) |
|
| 230 | - { |
|
| 231 | - $this->attributes = $attributes; |
|
| 232 | - return $this; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function getOutputType() |
|
| 239 | - { |
|
| 240 | - return $this->outputType; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @throws InvalidKeyInArrayException |
|
| 245 | - * @param string $outputType |
|
| 246 | - * @return $this |
|
| 247 | - */ |
|
| 248 | - public function setOutputType($outputType) |
|
| 249 | - { |
|
| 250 | - if (!in_array($outputType, $this->allowedOutputTypes)) { |
|
| 251 | - throw new InvalidKeyInArrayException( |
|
| 252 | - sprintf('Output type "%s" is not allowed', $outputType), |
|
| 253 | - 1373020076 |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - $this->outputType = $outputType; |
|
| 257 | - return $this; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @return string |
|
| 262 | - */ |
|
| 263 | - public function getTarget() |
|
| 264 | - { |
|
| 265 | - return $this->target; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @param string $target |
|
| 270 | - * @return $this |
|
| 271 | - */ |
|
| 272 | - public function setTarget($target) |
|
| 273 | - { |
|
| 274 | - $this->target = $target; |
|
| 275 | - return $this; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @return string |
|
| 280 | - */ |
|
| 281 | - public function getAnchorUri() |
|
| 282 | - { |
|
| 283 | - return $this->anchorUri; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param string $anchorUri |
|
| 288 | - * @return $this |
|
| 289 | - */ |
|
| 290 | - public function setAnchorUri($anchorUri) |
|
| 291 | - { |
|
| 292 | - $this->anchorUri = $anchorUri; |
|
| 293 | - return $this; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @return boolean |
|
| 298 | - */ |
|
| 299 | - public function getAppendTimeStamp() |
|
| 300 | - { |
|
| 301 | - return $this->appendTimeStamp; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param boolean $appendTimeStamp |
|
| 306 | - * @return $this |
|
| 307 | - */ |
|
| 308 | - public function setAppendTimeStamp($appendTimeStamp) |
|
| 309 | - { |
|
| 310 | - $this->appendTimeStamp = (bool)$appendTimeStamp; |
|
| 311 | - return $this; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @return string |
|
| 316 | - */ |
|
| 317 | - public function getProcessingType() |
|
| 318 | - { |
|
| 319 | - $this->processingType; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * @param string $processingType |
|
| 324 | - * @return $this |
|
| 325 | - */ |
|
| 326 | - public function setProcessingType($processingType) |
|
| 327 | - { |
|
| 328 | - $this->processingType = $processingType; |
|
| 329 | - return $this; |
|
| 330 | - } |
|
| 23 | + /** |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + protected $allowedOutputTypes = array( |
|
| 27 | + ThumbnailInterface::OUTPUT_IMAGE, |
|
| 28 | + ThumbnailInterface::OUTPUT_IMAGE_WRAPPED, |
|
| 29 | + ThumbnailInterface::OUTPUT_URI, |
|
| 30 | + ); |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Configure the output of the thumbnail service whether it is wrapped or not. |
|
| 34 | + * Default output is: ThumbnailInterface::OUTPUT_IMAGE |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected $outputType = ThumbnailInterface::OUTPUT_IMAGE; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var File |
|
| 42 | + */ |
|
| 43 | + protected $file; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Define width, height and all sort of attributes to render a thumbnail. |
|
| 47 | + * @see TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::Image |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected $configuration = []; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Define width, height and all sort of attributes to render the anchor file |
|
| 54 | + * which is wrapping the image |
|
| 55 | + * |
|
| 56 | + * @see TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::Image |
|
| 57 | + * @var array |
|
| 58 | + */ |
|
| 59 | + protected $configurationWrap = []; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * DOM attributes to add to the image preview. |
|
| 63 | + * |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | + protected $attributes = [ |
|
| 67 | + 'class' => 'thumbnail', |
|
| 68 | + ]; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Define in which window will the thumbnail be opened. |
|
| 72 | + * Does only apply if the thumbnail is wrapped (with an anchor). |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + protected $target = ThumbnailInterface::TARGET_BLANK; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * URI of the wrapping anchor pointing to the file. |
|
| 80 | + * replacing the "?" <a href="?">...</a> |
|
| 81 | + * The URI is automatically computed if not set. |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | + protected $anchorUri; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Whether a time stamp is appended to the image. |
|
| 88 | + * Appending the time stamp can prevent caching |
|
| 89 | + * |
|
| 90 | + * @var bool |
|
| 91 | + */ |
|
| 92 | + protected $appendTimeStamp = false; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Define the processing type for the thumbnail. |
|
| 96 | + * As instance for image the default is ProcessedFile::CONTEXT_IMAGECROPSCALEMASK. |
|
| 97 | + * |
|
| 98 | + * @var string |
|
| 99 | + */ |
|
| 100 | + protected $processingType; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Constructor |
|
| 104 | + * |
|
| 105 | + * @param File $file |
|
| 106 | + */ |
|
| 107 | + public function __construct(File $file = null) |
|
| 108 | + { |
|
| 109 | + $this->file = $file; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Render a thumbnail of a media |
|
| 114 | + * |
|
| 115 | + * @throws MissingTcaConfigurationException |
|
| 116 | + * @return string |
|
| 117 | + * @throws \InvalidArgumentException |
|
| 118 | + */ |
|
| 119 | + public function create() |
|
| 120 | + { |
|
| 121 | + |
|
| 122 | + if (!$this->file) { |
|
| 123 | + throw new MissingTcaConfigurationException('Missing File object. Forgotten to set a file?', 1355933144); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // Default class name |
|
| 127 | + $className = 'Fab\Media\Thumbnail\FallBackThumbnailProcessor'; |
|
| 128 | + if (File::FILETYPE_IMAGE === $this->file->getType()) { |
|
| 129 | + $className = 'Fab\Media\Thumbnail\ImageThumbnailProcessor'; |
|
| 130 | + } elseif (File::FILETYPE_AUDIO === $this->file->getType()) { |
|
| 131 | + $className = 'Fab\Media\Thumbnail\AudioThumbnailProcessor'; |
|
| 132 | + } elseif (File::FILETYPE_VIDEO === $this->file->getType()) { |
|
| 133 | + $className = 'Fab\Media\Thumbnail\VideoThumbnailProcessor'; |
|
| 134 | + } elseif (File::FILETYPE_APPLICATION === $this->file->getType() || File::FILETYPE_TEXT === $this->file->getType()) { |
|
| 135 | + $className = 'Fab\Media\Thumbnail\ApplicationThumbnailProcessor'; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** @var $processorInstance \Fab\Media\Thumbnail\ThumbnailProcessorInterface */ |
|
| 139 | + $processorInstance = GeneralUtility::makeInstance($className); |
|
| 140 | + |
|
| 141 | + $thumbnail = ''; |
|
| 142 | + if ($this->file->exists()) { |
|
| 143 | + $thumbnail = $processorInstance->setThumbnailService($this)->create(); |
|
| 144 | + } else { |
|
| 145 | + $logger = Logger::getInstance($this); |
|
| 146 | + $logger->warning(sprintf('Resource not found for File uid "%s" at %s', $this->file->getUid(), $this->file->getIdentifier())); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $thumbnail; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function getConfigurationWrap() |
|
| 156 | + { |
|
| 157 | + return $this->configurationWrap; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param array $configurationWrap |
|
| 162 | + * @return $this |
|
| 163 | + */ |
|
| 164 | + public function setConfigurationWrap($configurationWrap) |
|
| 165 | + { |
|
| 166 | + $this->configurationWrap = $configurationWrap; |
|
| 167 | + return $this; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @return mixed |
|
| 172 | + */ |
|
| 173 | + public function getFile() |
|
| 174 | + { |
|
| 175 | + return $this->file; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return array |
|
| 180 | + */ |
|
| 181 | + public function getConfiguration() |
|
| 182 | + { |
|
| 183 | + return $this->configuration; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param array|ThumbnailConfiguration $configuration |
|
| 188 | + * @return $this |
|
| 189 | + */ |
|
| 190 | + public function setConfiguration($configuration) |
|
| 191 | + { |
|
| 192 | + if ($configuration instanceof ThumbnailConfiguration) { |
|
| 193 | + $configurationObject = $configuration; |
|
| 194 | + $configuration = []; |
|
| 195 | + |
|
| 196 | + if ($configurationObject->getWidth() > 0) { |
|
| 197 | + $configuration['width'] = $configurationObject->getWidth(); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($configurationObject->getHeight() > 0) { |
|
| 201 | + $configuration['height'] = $configurationObject->getHeight(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ($configurationObject->getStyle()) { |
|
| 205 | + $this->attributes['style'] = $configurationObject->getStyle(); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if ($configurationObject->getClassName()) { |
|
| 209 | + $this->attributes['class'] = $configurationObject->getClassName(); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $this->configuration = $configuration; |
|
| 214 | + return $this; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @return array |
|
| 219 | + */ |
|
| 220 | + public function getAttributes() |
|
| 221 | + { |
|
| 222 | + return $this->attributes; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param array $attributes |
|
| 227 | + * @return $this |
|
| 228 | + */ |
|
| 229 | + public function setAttributes($attributes) |
|
| 230 | + { |
|
| 231 | + $this->attributes = $attributes; |
|
| 232 | + return $this; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function getOutputType() |
|
| 239 | + { |
|
| 240 | + return $this->outputType; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @throws InvalidKeyInArrayException |
|
| 245 | + * @param string $outputType |
|
| 246 | + * @return $this |
|
| 247 | + */ |
|
| 248 | + public function setOutputType($outputType) |
|
| 249 | + { |
|
| 250 | + if (!in_array($outputType, $this->allowedOutputTypes)) { |
|
| 251 | + throw new InvalidKeyInArrayException( |
|
| 252 | + sprintf('Output type "%s" is not allowed', $outputType), |
|
| 253 | + 1373020076 |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + $this->outputType = $outputType; |
|
| 257 | + return $this; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 263 | + public function getTarget() |
|
| 264 | + { |
|
| 265 | + return $this->target; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @param string $target |
|
| 270 | + * @return $this |
|
| 271 | + */ |
|
| 272 | + public function setTarget($target) |
|
| 273 | + { |
|
| 274 | + $this->target = $target; |
|
| 275 | + return $this; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @return string |
|
| 280 | + */ |
|
| 281 | + public function getAnchorUri() |
|
| 282 | + { |
|
| 283 | + return $this->anchorUri; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param string $anchorUri |
|
| 288 | + * @return $this |
|
| 289 | + */ |
|
| 290 | + public function setAnchorUri($anchorUri) |
|
| 291 | + { |
|
| 292 | + $this->anchorUri = $anchorUri; |
|
| 293 | + return $this; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @return boolean |
|
| 298 | + */ |
|
| 299 | + public function getAppendTimeStamp() |
|
| 300 | + { |
|
| 301 | + return $this->appendTimeStamp; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param boolean $appendTimeStamp |
|
| 306 | + * @return $this |
|
| 307 | + */ |
|
| 308 | + public function setAppendTimeStamp($appendTimeStamp) |
|
| 309 | + { |
|
| 310 | + $this->appendTimeStamp = (bool)$appendTimeStamp; |
|
| 311 | + return $this; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @return string |
|
| 316 | + */ |
|
| 317 | + public function getProcessingType() |
|
| 318 | + { |
|
| 319 | + $this->processingType; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * @param string $processingType |
|
| 324 | + * @return $this |
|
| 325 | + */ |
|
| 326 | + public function setProcessingType($processingType) |
|
| 327 | + { |
|
| 328 | + $this->processingType = $processingType; |
|
| 329 | + return $this; |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | 332 | } |
@@ -17,96 +17,96 @@ |
||
| 17 | 17 | class VideoThumbnailProcessor extends AbstractThumbnailProcessor |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Render a thumbnail of a resource of type video. |
|
| 22 | - * |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public function create() |
|
| 26 | - { |
|
| 27 | - $steps = $this->getRenderingSteps(); |
|
| 28 | - |
|
| 29 | - $result = ''; |
|
| 30 | - while ($step = array_shift($steps)) { |
|
| 31 | - $result = $this->$step($result); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - return $result; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Render the URI of the thumbnail. |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function renderUri() |
|
| 43 | - { |
|
| 44 | - |
|
| 45 | - $relativePath = sprintf('Icons/MimeType/%s.png', $this->getFile()->getProperty('extension')); |
|
| 46 | - $fileNameAndPath = GeneralUtility::getFileAbsFileName('EXT:media/Resources/Public/' . $relativePath); |
|
| 47 | - if (!file_exists($fileNameAndPath)) { |
|
| 48 | - $relativePath = 'Icons/UnknownMimeType.png'; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $uri = Path::getRelativePath($relativePath); |
|
| 52 | - return $this->prefixUri($uri); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Render the tag image which is the main one for a thumbnail. |
|
| 57 | - * |
|
| 58 | - * @param string $result |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function renderTagImage($result) |
|
| 62 | - { |
|
| 63 | - |
|
| 64 | - // Variable $result corresponds to an URL in this case. |
|
| 65 | - // Analyse the URL and compute the adequate separator between arguments. |
|
| 66 | - $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
| 67 | - |
|
| 68 | - return sprintf( |
|
| 69 | - '<img src="%s%s" title="%s" alt="%s" %s/>', |
|
| 70 | - $result, |
|
| 71 | - $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getFile()->getProperty('tstamp') : '', |
|
| 72 | - $this->getTitle(), |
|
| 73 | - $this->getTitle(), |
|
| 74 | - $this->renderAttributes() |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Compute and return the title of the file. |
|
| 80 | - * |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - protected function getTitle() |
|
| 84 | - { |
|
| 85 | - $result = $this->getFile()->getProperty('title'); |
|
| 86 | - if (!$result) { |
|
| 87 | - $result = $this->getFile()->getName(); |
|
| 88 | - } |
|
| 89 | - return htmlspecialchars($result); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Render a wrapping anchor around the thumbnail. |
|
| 94 | - * |
|
| 95 | - * @param string $result |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public function renderTagAnchor($result) |
|
| 99 | - { |
|
| 100 | - |
|
| 101 | - $file = $this->getFile(); |
|
| 102 | - |
|
| 103 | - return sprintf( |
|
| 104 | - '<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
|
| 105 | - $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true), |
|
| 106 | - $this->thumbnailService->getAppendTimeStamp() ? '?' . $file->getProperty('tstamp') : '', |
|
| 107 | - $this->thumbnailService->getTarget(), |
|
| 108 | - $file->getUid(), |
|
| 109 | - $result |
|
| 110 | - ); |
|
| 111 | - } |
|
| 20 | + /** |
|
| 21 | + * Render a thumbnail of a resource of type video. |
|
| 22 | + * |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public function create() |
|
| 26 | + { |
|
| 27 | + $steps = $this->getRenderingSteps(); |
|
| 28 | + |
|
| 29 | + $result = ''; |
|
| 30 | + while ($step = array_shift($steps)) { |
|
| 31 | + $result = $this->$step($result); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + return $result; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Render the URI of the thumbnail. |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function renderUri() |
|
| 43 | + { |
|
| 44 | + |
|
| 45 | + $relativePath = sprintf('Icons/MimeType/%s.png', $this->getFile()->getProperty('extension')); |
|
| 46 | + $fileNameAndPath = GeneralUtility::getFileAbsFileName('EXT:media/Resources/Public/' . $relativePath); |
|
| 47 | + if (!file_exists($fileNameAndPath)) { |
|
| 48 | + $relativePath = 'Icons/UnknownMimeType.png'; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $uri = Path::getRelativePath($relativePath); |
|
| 52 | + return $this->prefixUri($uri); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Render the tag image which is the main one for a thumbnail. |
|
| 57 | + * |
|
| 58 | + * @param string $result |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function renderTagImage($result) |
|
| 62 | + { |
|
| 63 | + |
|
| 64 | + // Variable $result corresponds to an URL in this case. |
|
| 65 | + // Analyse the URL and compute the adequate separator between arguments. |
|
| 66 | + $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
| 67 | + |
|
| 68 | + return sprintf( |
|
| 69 | + '<img src="%s%s" title="%s" alt="%s" %s/>', |
|
| 70 | + $result, |
|
| 71 | + $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getFile()->getProperty('tstamp') : '', |
|
| 72 | + $this->getTitle(), |
|
| 73 | + $this->getTitle(), |
|
| 74 | + $this->renderAttributes() |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Compute and return the title of the file. |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + protected function getTitle() |
|
| 84 | + { |
|
| 85 | + $result = $this->getFile()->getProperty('title'); |
|
| 86 | + if (!$result) { |
|
| 87 | + $result = $this->getFile()->getName(); |
|
| 88 | + } |
|
| 89 | + return htmlspecialchars($result); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Render a wrapping anchor around the thumbnail. |
|
| 94 | + * |
|
| 95 | + * @param string $result |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public function renderTagAnchor($result) |
|
| 99 | + { |
|
| 100 | + |
|
| 101 | + $file = $this->getFile(); |
|
| 102 | + |
|
| 103 | + return sprintf( |
|
| 104 | + '<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
|
| 105 | + $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true), |
|
| 106 | + $this->thumbnailService->getAppendTimeStamp() ? '?' . $file->getProperty('tstamp') : '', |
|
| 107 | + $this->thumbnailService->getTarget(), |
|
| 108 | + $file->getUid(), |
|
| 109 | + $result |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -15,96 +15,96 @@ |
||
| 15 | 15 | class ThumbnailConfiguration |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var int |
|
| 20 | - */ |
|
| 21 | - protected $width = 0; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var int |
|
| 25 | - */ |
|
| 26 | - protected $height = 0; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - protected $style = ''; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $className = ''; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @return int |
|
| 40 | - */ |
|
| 41 | - public function getWidth() |
|
| 42 | - { |
|
| 43 | - return $this->width; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param int $width |
|
| 48 | - * @return $this |
|
| 49 | - */ |
|
| 50 | - public function setWidth($width) |
|
| 51 | - { |
|
| 52 | - $this->width = $width; |
|
| 53 | - return $this; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return int |
|
| 58 | - */ |
|
| 59 | - public function getHeight() |
|
| 60 | - { |
|
| 61 | - return $this->height; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param int $height |
|
| 66 | - * @return $this |
|
| 67 | - */ |
|
| 68 | - public function setHeight($height) |
|
| 69 | - { |
|
| 70 | - $this->height = $height; |
|
| 71 | - return $this; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function getStyle() |
|
| 78 | - { |
|
| 79 | - return $this->style; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param string $style |
|
| 84 | - * @return $this |
|
| 85 | - */ |
|
| 86 | - public function setStyle($style) |
|
| 87 | - { |
|
| 88 | - $this->style = $style; |
|
| 89 | - return $this; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public function getClassName() |
|
| 96 | - { |
|
| 97 | - return $this->className; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param string $className |
|
| 102 | - * @return $this |
|
| 103 | - */ |
|
| 104 | - public function setClassName($className) |
|
| 105 | - { |
|
| 106 | - $this->className = $className; |
|
| 107 | - return $this; |
|
| 108 | - } |
|
| 18 | + /** |
|
| 19 | + * @var int |
|
| 20 | + */ |
|
| 21 | + protected $width = 0; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var int |
|
| 25 | + */ |
|
| 26 | + protected $height = 0; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + protected $style = ''; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $className = ''; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @return int |
|
| 40 | + */ |
|
| 41 | + public function getWidth() |
|
| 42 | + { |
|
| 43 | + return $this->width; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param int $width |
|
| 48 | + * @return $this |
|
| 49 | + */ |
|
| 50 | + public function setWidth($width) |
|
| 51 | + { |
|
| 52 | + $this->width = $width; |
|
| 53 | + return $this; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return int |
|
| 58 | + */ |
|
| 59 | + public function getHeight() |
|
| 60 | + { |
|
| 61 | + return $this->height; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param int $height |
|
| 66 | + * @return $this |
|
| 67 | + */ |
|
| 68 | + public function setHeight($height) |
|
| 69 | + { |
|
| 70 | + $this->height = $height; |
|
| 71 | + return $this; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function getStyle() |
|
| 78 | + { |
|
| 79 | + return $this->style; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param string $style |
|
| 84 | + * @return $this |
|
| 85 | + */ |
|
| 86 | + public function setStyle($style) |
|
| 87 | + { |
|
| 88 | + $this->style = $style; |
|
| 89 | + return $this; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public function getClassName() |
|
| 96 | + { |
|
| 97 | + return $this->className; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param string $className |
|
| 102 | + * @return $this |
|
| 103 | + */ |
|
| 104 | + public function setClassName($className) |
|
| 105 | + { |
|
| 106 | + $this->className = $className; |
|
| 107 | + return $this; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | } |
@@ -17,96 +17,96 @@ |
||
| 17 | 17 | class AudioThumbnailProcessor extends AbstractThumbnailProcessor |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Render a thumbnail of a resource of type audio. |
|
| 22 | - * |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public function create() |
|
| 26 | - { |
|
| 27 | - $steps = $this->getRenderingSteps(); |
|
| 28 | - |
|
| 29 | - $result = ''; |
|
| 30 | - while ($step = array_shift($steps)) { |
|
| 31 | - $result = $this->$step($result); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - return $result; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Render the URI of the thumbnail. |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function renderUri() |
|
| 43 | - { |
|
| 44 | - |
|
| 45 | - $relativePath = sprintf('Icons/MimeType/%s.png', $this->getFile()->getProperty('extension')); |
|
| 46 | - $fileNameAndPath = GeneralUtility::getFileAbsFileName('EXT:media/Resources/Public/' . $relativePath); |
|
| 47 | - if (!file_exists($fileNameAndPath)) { |
|
| 48 | - $relativePath = 'Icons/UnknownMimeType.png'; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $uri = Path::getRelativePath($relativePath); |
|
| 52 | - return $this->prefixUri($uri); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Render the tag image which is the main one for a thumbnail. |
|
| 57 | - * |
|
| 58 | - * @param string $result |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function renderTagImage($result) |
|
| 62 | - { |
|
| 63 | - |
|
| 64 | - // Variable $result corresponds to an URL in this case. |
|
| 65 | - // Analyse the URL and compute the adequate separator between arguments. |
|
| 66 | - $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
| 67 | - |
|
| 68 | - return sprintf( |
|
| 69 | - '<img src="%s%s" title="%s" alt="%s" %s/>', |
|
| 70 | - $result, |
|
| 71 | - $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getFile()->getProperty('tstamp') : '', |
|
| 72 | - $this->getTitle(), |
|
| 73 | - $this->getTitle(), |
|
| 74 | - $this->renderAttributes() |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Compute and return the title of the file. |
|
| 80 | - * |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - protected function getTitle() |
|
| 84 | - { |
|
| 85 | - $result = $this->getFile()->getProperty('title'); |
|
| 86 | - if (!$result) { |
|
| 87 | - $result = $this->getFile()->getName(); |
|
| 88 | - } |
|
| 89 | - return htmlspecialchars($result); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Render a wrapping anchor around the thumbnail. |
|
| 94 | - * |
|
| 95 | - * @param string $result |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public function renderTagAnchor($result) |
|
| 99 | - { |
|
| 100 | - |
|
| 101 | - $file = $this->getFile(); |
|
| 102 | - |
|
| 103 | - return sprintf( |
|
| 104 | - '<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
|
| 105 | - $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true), |
|
| 106 | - $this->thumbnailService->getAppendTimeStamp() ? '?' . $file->getProperty('tstamp') : '', |
|
| 107 | - $this->thumbnailService->getTarget(), |
|
| 108 | - $file->getUid(), |
|
| 109 | - $result |
|
| 110 | - ); |
|
| 111 | - } |
|
| 20 | + /** |
|
| 21 | + * Render a thumbnail of a resource of type audio. |
|
| 22 | + * |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public function create() |
|
| 26 | + { |
|
| 27 | + $steps = $this->getRenderingSteps(); |
|
| 28 | + |
|
| 29 | + $result = ''; |
|
| 30 | + while ($step = array_shift($steps)) { |
|
| 31 | + $result = $this->$step($result); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + return $result; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Render the URI of the thumbnail. |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function renderUri() |
|
| 43 | + { |
|
| 44 | + |
|
| 45 | + $relativePath = sprintf('Icons/MimeType/%s.png', $this->getFile()->getProperty('extension')); |
|
| 46 | + $fileNameAndPath = GeneralUtility::getFileAbsFileName('EXT:media/Resources/Public/' . $relativePath); |
|
| 47 | + if (!file_exists($fileNameAndPath)) { |
|
| 48 | + $relativePath = 'Icons/UnknownMimeType.png'; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $uri = Path::getRelativePath($relativePath); |
|
| 52 | + return $this->prefixUri($uri); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Render the tag image which is the main one for a thumbnail. |
|
| 57 | + * |
|
| 58 | + * @param string $result |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function renderTagImage($result) |
|
| 62 | + { |
|
| 63 | + |
|
| 64 | + // Variable $result corresponds to an URL in this case. |
|
| 65 | + // Analyse the URL and compute the adequate separator between arguments. |
|
| 66 | + $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
| 67 | + |
|
| 68 | + return sprintf( |
|
| 69 | + '<img src="%s%s" title="%s" alt="%s" %s/>', |
|
| 70 | + $result, |
|
| 71 | + $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getFile()->getProperty('tstamp') : '', |
|
| 72 | + $this->getTitle(), |
|
| 73 | + $this->getTitle(), |
|
| 74 | + $this->renderAttributes() |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Compute and return the title of the file. |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + protected function getTitle() |
|
| 84 | + { |
|
| 85 | + $result = $this->getFile()->getProperty('title'); |
|
| 86 | + if (!$result) { |
|
| 87 | + $result = $this->getFile()->getName(); |
|
| 88 | + } |
|
| 89 | + return htmlspecialchars($result); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Render a wrapping anchor around the thumbnail. |
|
| 94 | + * |
|
| 95 | + * @param string $result |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public function renderTagAnchor($result) |
|
| 99 | + { |
|
| 100 | + |
|
| 101 | + $file = $this->getFile(); |
|
| 102 | + |
|
| 103 | + return sprintf( |
|
| 104 | + '<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
|
| 105 | + $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true), |
|
| 106 | + $this->thumbnailService->getAppendTimeStamp() ? '?' . $file->getProperty('tstamp') : '', |
|
| 107 | + $this->thumbnailService->getTarget(), |
|
| 108 | + $file->getUid(), |
|
| 109 | + $result |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -18,140 +18,140 @@ |
||
| 18 | 18 | class ApplicationThumbnailProcessor extends AbstractThumbnailProcessor |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Render a thumbnail of a resource of type application. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function create() |
|
| 27 | - { |
|
| 28 | - |
|
| 29 | - $steps = $this->getRenderingSteps(); |
|
| 30 | - |
|
| 31 | - $result = ''; |
|
| 32 | - while ($step = array_shift($steps)) { |
|
| 33 | - $result = $this->$step($result); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - return $result; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Render the URI of the thumbnail. |
|
| 41 | - * |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function renderUri() |
|
| 45 | - { |
|
| 46 | - if ($this->isThumbnailPossible($this->getFile()->getExtension())) { |
|
| 47 | - $this->processedFile = $this->getFile()->process($this->getProcessingType(), $this->getConfiguration()); |
|
| 48 | - $uri = $this->processedFile->getPublicUrl(true); |
|
| 49 | - |
|
| 50 | - // Update time stamp of processed image at this stage. This is needed for the browser to get new version of the thumbnail. |
|
| 51 | - if ($this->processedFile->getProperty('originalfilesha1') !== $this->getFile()->getProperty('sha1')) { |
|
| 52 | - $this->processedFile->updateProperties(array('tstamp' => $this->getFile()->getProperty('tstamp'))); |
|
| 53 | - } |
|
| 54 | - } else { |
|
| 55 | - $uri = $this->getIcon($this->getFile()->getExtension()); |
|
| 56 | - } |
|
| 57 | - return $this->prefixUri($uri); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Render the tag image which is the main one for a thumbnail. |
|
| 62 | - * |
|
| 63 | - * @param string $result |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function renderTagImage($result) |
|
| 67 | - { |
|
| 68 | - |
|
| 69 | - // Variable $result corresponds to an URL in this case. |
|
| 70 | - // Analyse the URL and compute the adequate separator between arguments. |
|
| 71 | - $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
| 72 | - |
|
| 73 | - return sprintf( |
|
| 74 | - '<img src="%s%s" title="%s" alt="%s" %s/>', |
|
| 75 | - $result, |
|
| 76 | - $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getTimeStamp() : '', |
|
| 77 | - $this->getTitle(), |
|
| 78 | - $this->getTitle(), |
|
| 79 | - $this->renderAttributes() |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Compute and return the time stamp. |
|
| 85 | - * |
|
| 86 | - * @return int |
|
| 87 | - */ |
|
| 88 | - protected function getTimeStamp() |
|
| 89 | - { |
|
| 90 | - $result = $this->getFile()->getProperty('tstamp'); |
|
| 91 | - if ($this->processedFile) { |
|
| 92 | - $result = $this->processedFile->getProperty('tstamp'); |
|
| 93 | - } |
|
| 94 | - return $result; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Compute and return the title of the file. |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - protected function getTitle() |
|
| 103 | - { |
|
| 104 | - $result = $this->getFile()->getProperty('title'); |
|
| 105 | - if (empty($result)) { |
|
| 106 | - $result = $this->getFile()->getName(); |
|
| 107 | - } |
|
| 108 | - return htmlspecialchars($result); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Render a wrapping anchor around the thumbnail. |
|
| 113 | - * |
|
| 114 | - * @param string $result |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public function renderTagAnchor($result) |
|
| 118 | - { |
|
| 119 | - $uri = $this->thumbnailService->getAnchorUri(); |
|
| 120 | - if (!$uri) { |
|
| 121 | - $uri = $this->getUri(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return sprintf( |
|
| 125 | - '<a href="%s" target="_blank" data-uid="%s">%s</a>', |
|
| 126 | - $uri, |
|
| 127 | - $this->getFile()->getUid(), |
|
| 128 | - $result |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - protected function getUri() |
|
| 136 | - { |
|
| 137 | - $urlParameters = array( |
|
| 138 | - MediaModule::getParameterPrefix() => [ |
|
| 139 | - 'controller' => 'Asset', |
|
| 140 | - 'action' => 'download', |
|
| 141 | - 'file' => $this->getFile()->getUid(), |
|
| 142 | - ], |
|
| 143 | - ); |
|
| 144 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return string |
|
| 149 | - */ |
|
| 150 | - public function getProcessingType() |
|
| 151 | - { |
|
| 152 | - if ($this->thumbnailService->getProcessingType() === null) { |
|
| 153 | - return ProcessedFile::CONTEXT_IMAGECROPSCALEMASK; |
|
| 154 | - } |
|
| 155 | - return $this->thumbnailService->getProcessingType(); |
|
| 156 | - } |
|
| 21 | + /** |
|
| 22 | + * Render a thumbnail of a resource of type application. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function create() |
|
| 27 | + { |
|
| 28 | + |
|
| 29 | + $steps = $this->getRenderingSteps(); |
|
| 30 | + |
|
| 31 | + $result = ''; |
|
| 32 | + while ($step = array_shift($steps)) { |
|
| 33 | + $result = $this->$step($result); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + return $result; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Render the URI of the thumbnail. |
|
| 41 | + * |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function renderUri() |
|
| 45 | + { |
|
| 46 | + if ($this->isThumbnailPossible($this->getFile()->getExtension())) { |
|
| 47 | + $this->processedFile = $this->getFile()->process($this->getProcessingType(), $this->getConfiguration()); |
|
| 48 | + $uri = $this->processedFile->getPublicUrl(true); |
|
| 49 | + |
|
| 50 | + // Update time stamp of processed image at this stage. This is needed for the browser to get new version of the thumbnail. |
|
| 51 | + if ($this->processedFile->getProperty('originalfilesha1') !== $this->getFile()->getProperty('sha1')) { |
|
| 52 | + $this->processedFile->updateProperties(array('tstamp' => $this->getFile()->getProperty('tstamp'))); |
|
| 53 | + } |
|
| 54 | + } else { |
|
| 55 | + $uri = $this->getIcon($this->getFile()->getExtension()); |
|
| 56 | + } |
|
| 57 | + return $this->prefixUri($uri); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Render the tag image which is the main one for a thumbnail. |
|
| 62 | + * |
|
| 63 | + * @param string $result |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function renderTagImage($result) |
|
| 67 | + { |
|
| 68 | + |
|
| 69 | + // Variable $result corresponds to an URL in this case. |
|
| 70 | + // Analyse the URL and compute the adequate separator between arguments. |
|
| 71 | + $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
| 72 | + |
|
| 73 | + return sprintf( |
|
| 74 | + '<img src="%s%s" title="%s" alt="%s" %s/>', |
|
| 75 | + $result, |
|
| 76 | + $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getTimeStamp() : '', |
|
| 77 | + $this->getTitle(), |
|
| 78 | + $this->getTitle(), |
|
| 79 | + $this->renderAttributes() |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Compute and return the time stamp. |
|
| 85 | + * |
|
| 86 | + * @return int |
|
| 87 | + */ |
|
| 88 | + protected function getTimeStamp() |
|
| 89 | + { |
|
| 90 | + $result = $this->getFile()->getProperty('tstamp'); |
|
| 91 | + if ($this->processedFile) { |
|
| 92 | + $result = $this->processedFile->getProperty('tstamp'); |
|
| 93 | + } |
|
| 94 | + return $result; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Compute and return the title of the file. |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + protected function getTitle() |
|
| 103 | + { |
|
| 104 | + $result = $this->getFile()->getProperty('title'); |
|
| 105 | + if (empty($result)) { |
|
| 106 | + $result = $this->getFile()->getName(); |
|
| 107 | + } |
|
| 108 | + return htmlspecialchars($result); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Render a wrapping anchor around the thumbnail. |
|
| 113 | + * |
|
| 114 | + * @param string $result |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public function renderTagAnchor($result) |
|
| 118 | + { |
|
| 119 | + $uri = $this->thumbnailService->getAnchorUri(); |
|
| 120 | + if (!$uri) { |
|
| 121 | + $uri = $this->getUri(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return sprintf( |
|
| 125 | + '<a href="%s" target="_blank" data-uid="%s">%s</a>', |
|
| 126 | + $uri, |
|
| 127 | + $this->getFile()->getUid(), |
|
| 128 | + $result |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + protected function getUri() |
|
| 136 | + { |
|
| 137 | + $urlParameters = array( |
|
| 138 | + MediaModule::getParameterPrefix() => [ |
|
| 139 | + 'controller' => 'Asset', |
|
| 140 | + 'action' => 'download', |
|
| 141 | + 'file' => $this->getFile()->getUid(), |
|
| 142 | + ], |
|
| 143 | + ); |
|
| 144 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return string |
|
| 149 | + */ |
|
| 150 | + public function getProcessingType() |
|
| 151 | + { |
|
| 152 | + if ($this->thumbnailService->getProcessingType() === null) { |
|
| 153 | + return ProcessedFile::CONTEXT_IMAGECROPSCALEMASK; |
|
| 154 | + } |
|
| 155 | + return $this->thumbnailService->getProcessingType(); |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -16,180 +16,180 @@ |
||
| 16 | 16 | class ImageThumbnailProcessor extends AbstractThumbnailProcessor |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $defaultConfigurationWrap = array( |
|
| 23 | - 'width' => 0, |
|
| 24 | - 'height' => 0, |
|
| 25 | - ); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Render a thumbnail of a resource of type image. |
|
| 29 | - * |
|
| 30 | - * @return string |
|
| 31 | - */ |
|
| 32 | - public function create() |
|
| 33 | - { |
|
| 34 | - $steps = $this->getRenderingSteps(); |
|
| 35 | - |
|
| 36 | - $result = ''; |
|
| 37 | - while ($step = array_shift($steps)) { |
|
| 38 | - $result = $this->$step($result); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - return $result; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Render the URI of the thumbnail. |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - * @throws \Fab\Media\Exception\EmptyValueException |
|
| 49 | - */ |
|
| 50 | - public function renderUri() |
|
| 51 | - { |
|
| 52 | - |
|
| 53 | - // Makes sure the width and the height of the thumbnail is not bigger than the actual file |
|
| 54 | - $configuration = $this->getConfiguration(); |
|
| 55 | - if (!empty($configuration['width']) && $configuration['width'] > $this->getFile()->getProperty('width')) { |
|
| 56 | - $configuration['width'] = $this->getFile()->getProperty('width'); |
|
| 57 | - } |
|
| 58 | - if (!empty($configuration['height']) && $configuration['height'] > $this->getFile()->getProperty('height')) { |
|
| 59 | - $configuration['height'] = $this->getFile()->getProperty('height'); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $configuration = $this->computeFinalImageDimension($configuration); |
|
| 63 | - $this->processedFile = $this->getFile()->process($this->getProcessingType(), $configuration); |
|
| 64 | - $uri = $this->processedFile->getPublicUrl(true); |
|
| 65 | - |
|
| 66 | - // Update time stamp of processed image at this stage. This is needed for the browser to get new version of the thumbnail. |
|
| 67 | - if ($this->processedFile->getProperty('originalfilesha1') !== $this->getFile()->getProperty('sha1')) { |
|
| 68 | - $this->processedFile->updateProperties(array('tstamp' => $this->getFile()->getProperty('tstamp'))); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return $this->prefixUri($uri); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Render the tag image which is the main one for a thumbnail. |
|
| 76 | - * |
|
| 77 | - * @param string $result |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - public function renderTagImage($result) |
|
| 81 | - { |
|
| 82 | - |
|
| 83 | - // Variable $result corresponds to an URL in this case. |
|
| 84 | - // Analyse the URL and compute the adequate separator between arguments. |
|
| 85 | - $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
| 86 | - |
|
| 87 | - return sprintf('<img src="%s%s" title="%s" alt="%s" %s/>', |
|
| 88 | - $result, |
|
| 89 | - $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->processedFile->getProperty('tstamp') : '', |
|
| 90 | - $this->getTitle(), |
|
| 91 | - $this->getTitle(), |
|
| 92 | - $this->renderAttributes() |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Compute and return the title of the file. |
|
| 98 | - * |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - protected function getTitle() |
|
| 102 | - { |
|
| 103 | - $result = $this->getFile()->getProperty('title'); |
|
| 104 | - if (!$result) { |
|
| 105 | - $result = $this->getFile()->getName(); |
|
| 106 | - } |
|
| 107 | - return htmlspecialchars($result); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Render a wrapping anchor around the thumbnail. |
|
| 112 | - * |
|
| 113 | - * @param string $result |
|
| 114 | - * @return string |
|
| 115 | - */ |
|
| 116 | - public function renderTagAnchor($result) |
|
| 117 | - { |
|
| 118 | - |
|
| 119 | - $file = $this->getFile(); |
|
| 120 | - |
|
| 121 | - // Perhaps the wrapping file must be processed |
|
| 122 | - $configurationWrap = $this->thumbnailService->getConfigurationWrap(); |
|
| 123 | - |
|
| 124 | - // Make sure we have configurationWrap initialized correctly |
|
| 125 | - if (!empty($configurationWrap['width']) || !empty($configurationWrap['height'])) { |
|
| 126 | - $configurationWrap = array_merge($this->defaultConfigurationWrap, $configurationWrap); |
|
| 127 | - |
|
| 128 | - // It looks maxW or maxH does not work as expected with CONTEXT_IMAGEPREVIEW... |
|
| 129 | - // ... uses "width" and "height" instead. |
|
| 130 | - if ($configurationWrap['width'] < $this->getFile()->getProperty('width') |
|
| 131 | - || $configurationWrap['height'] < $this->getFile()->getProperty('height') |
|
| 132 | - ) { |
|
| 133 | - $configurationWrap = $this->computeFinalImageDimension($configurationWrap); |
|
| 134 | - $file = $this->getFile()->process($this->getProcessingType(), $configurationWrap); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // Analyse the current $url and compute the adequate separator between arguments. |
|
| 139 | - $url = $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true); |
|
| 140 | - $parameterSeparator = strpos($url, '?') === false ? '?' : '&'; |
|
| 141 | - |
|
| 142 | - return sprintf('<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
|
| 143 | - $url, |
|
| 144 | - $this->thumbnailService->getAppendTimeStamp() && !$this->thumbnailService->getAnchorUri() ? $parameterSeparator . $file->getProperty('tstamp') : '', |
|
| 145 | - $this->thumbnailService->getTarget(), |
|
| 146 | - $file->getUid(), |
|
| 147 | - $result |
|
| 148 | - ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Compute the final configuration for the image preview. |
|
| 153 | - * Keep ratio of width / height for the image. |
|
| 154 | - * |
|
| 155 | - * @param array $configuration |
|
| 156 | - * @return array |
|
| 157 | - */ |
|
| 158 | - protected function computeFinalImageDimension(array $configuration) |
|
| 159 | - { |
|
| 160 | - $ratio = $this->computeImageRatio(); |
|
| 161 | - |
|
| 162 | - if ($ratio > 1) { |
|
| 163 | - $configuration['height'] = round($configuration['width'] / $ratio); |
|
| 164 | - } else { |
|
| 165 | - $configuration['width'] = round($configuration['height'] * $ratio); |
|
| 166 | - } |
|
| 167 | - return $configuration; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Compute the width / height ratio of the image. |
|
| 172 | - * |
|
| 173 | - * @return null|float |
|
| 174 | - */ |
|
| 175 | - protected function computeImageRatio() |
|
| 176 | - { |
|
| 177 | - $ratio = null; |
|
| 178 | - if ($this->getFile()->getProperty('width') > 0 && $this->getFile()->getProperty('height') > 0) { |
|
| 179 | - $ratio = $this->getFile()->getProperty('width') / $this->getFile()->getProperty('height'); |
|
| 180 | - } |
|
| 181 | - return $ratio; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function getProcessingType() |
|
| 188 | - { |
|
| 189 | - if ($this->thumbnailService->getProcessingType() === null) { |
|
| 190 | - return ProcessedFile::CONTEXT_IMAGECROPSCALEMASK; |
|
| 191 | - } |
|
| 192 | - return $this->thumbnailService->getProcessingType(); |
|
| 193 | - } |
|
| 19 | + /** |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $defaultConfigurationWrap = array( |
|
| 23 | + 'width' => 0, |
|
| 24 | + 'height' => 0, |
|
| 25 | + ); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Render a thumbnail of a resource of type image. |
|
| 29 | + * |
|
| 30 | + * @return string |
|
| 31 | + */ |
|
| 32 | + public function create() |
|
| 33 | + { |
|
| 34 | + $steps = $this->getRenderingSteps(); |
|
| 35 | + |
|
| 36 | + $result = ''; |
|
| 37 | + while ($step = array_shift($steps)) { |
|
| 38 | + $result = $this->$step($result); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + return $result; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Render the URI of the thumbnail. |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + * @throws \Fab\Media\Exception\EmptyValueException |
|
| 49 | + */ |
|
| 50 | + public function renderUri() |
|
| 51 | + { |
|
| 52 | + |
|
| 53 | + // Makes sure the width and the height of the thumbnail is not bigger than the actual file |
|
| 54 | + $configuration = $this->getConfiguration(); |
|
| 55 | + if (!empty($configuration['width']) && $configuration['width'] > $this->getFile()->getProperty('width')) { |
|
| 56 | + $configuration['width'] = $this->getFile()->getProperty('width'); |
|
| 57 | + } |
|
| 58 | + if (!empty($configuration['height']) && $configuration['height'] > $this->getFile()->getProperty('height')) { |
|
| 59 | + $configuration['height'] = $this->getFile()->getProperty('height'); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $configuration = $this->computeFinalImageDimension($configuration); |
|
| 63 | + $this->processedFile = $this->getFile()->process($this->getProcessingType(), $configuration); |
|
| 64 | + $uri = $this->processedFile->getPublicUrl(true); |
|
| 65 | + |
|
| 66 | + // Update time stamp of processed image at this stage. This is needed for the browser to get new version of the thumbnail. |
|
| 67 | + if ($this->processedFile->getProperty('originalfilesha1') !== $this->getFile()->getProperty('sha1')) { |
|
| 68 | + $this->processedFile->updateProperties(array('tstamp' => $this->getFile()->getProperty('tstamp'))); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return $this->prefixUri($uri); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Render the tag image which is the main one for a thumbnail. |
|
| 76 | + * |
|
| 77 | + * @param string $result |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + public function renderTagImage($result) |
|
| 81 | + { |
|
| 82 | + |
|
| 83 | + // Variable $result corresponds to an URL in this case. |
|
| 84 | + // Analyse the URL and compute the adequate separator between arguments. |
|
| 85 | + $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
| 86 | + |
|
| 87 | + return sprintf('<img src="%s%s" title="%s" alt="%s" %s/>', |
|
| 88 | + $result, |
|
| 89 | + $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->processedFile->getProperty('tstamp') : '', |
|
| 90 | + $this->getTitle(), |
|
| 91 | + $this->getTitle(), |
|
| 92 | + $this->renderAttributes() |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Compute and return the title of the file. |
|
| 98 | + * |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + protected function getTitle() |
|
| 102 | + { |
|
| 103 | + $result = $this->getFile()->getProperty('title'); |
|
| 104 | + if (!$result) { |
|
| 105 | + $result = $this->getFile()->getName(); |
|
| 106 | + } |
|
| 107 | + return htmlspecialchars($result); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Render a wrapping anchor around the thumbnail. |
|
| 112 | + * |
|
| 113 | + * @param string $result |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 116 | + public function renderTagAnchor($result) |
|
| 117 | + { |
|
| 118 | + |
|
| 119 | + $file = $this->getFile(); |
|
| 120 | + |
|
| 121 | + // Perhaps the wrapping file must be processed |
|
| 122 | + $configurationWrap = $this->thumbnailService->getConfigurationWrap(); |
|
| 123 | + |
|
| 124 | + // Make sure we have configurationWrap initialized correctly |
|
| 125 | + if (!empty($configurationWrap['width']) || !empty($configurationWrap['height'])) { |
|
| 126 | + $configurationWrap = array_merge($this->defaultConfigurationWrap, $configurationWrap); |
|
| 127 | + |
|
| 128 | + // It looks maxW or maxH does not work as expected with CONTEXT_IMAGEPREVIEW... |
|
| 129 | + // ... uses "width" and "height" instead. |
|
| 130 | + if ($configurationWrap['width'] < $this->getFile()->getProperty('width') |
|
| 131 | + || $configurationWrap['height'] < $this->getFile()->getProperty('height') |
|
| 132 | + ) { |
|
| 133 | + $configurationWrap = $this->computeFinalImageDimension($configurationWrap); |
|
| 134 | + $file = $this->getFile()->process($this->getProcessingType(), $configurationWrap); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // Analyse the current $url and compute the adequate separator between arguments. |
|
| 139 | + $url = $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true); |
|
| 140 | + $parameterSeparator = strpos($url, '?') === false ? '?' : '&'; |
|
| 141 | + |
|
| 142 | + return sprintf('<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
|
| 143 | + $url, |
|
| 144 | + $this->thumbnailService->getAppendTimeStamp() && !$this->thumbnailService->getAnchorUri() ? $parameterSeparator . $file->getProperty('tstamp') : '', |
|
| 145 | + $this->thumbnailService->getTarget(), |
|
| 146 | + $file->getUid(), |
|
| 147 | + $result |
|
| 148 | + ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Compute the final configuration for the image preview. |
|
| 153 | + * Keep ratio of width / height for the image. |
|
| 154 | + * |
|
| 155 | + * @param array $configuration |
|
| 156 | + * @return array |
|
| 157 | + */ |
|
| 158 | + protected function computeFinalImageDimension(array $configuration) |
|
| 159 | + { |
|
| 160 | + $ratio = $this->computeImageRatio(); |
|
| 161 | + |
|
| 162 | + if ($ratio > 1) { |
|
| 163 | + $configuration['height'] = round($configuration['width'] / $ratio); |
|
| 164 | + } else { |
|
| 165 | + $configuration['width'] = round($configuration['height'] * $ratio); |
|
| 166 | + } |
|
| 167 | + return $configuration; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Compute the width / height ratio of the image. |
|
| 172 | + * |
|
| 173 | + * @return null|float |
|
| 174 | + */ |
|
| 175 | + protected function computeImageRatio() |
|
| 176 | + { |
|
| 177 | + $ratio = null; |
|
| 178 | + if ($this->getFile()->getProperty('width') > 0 && $this->getFile()->getProperty('height') > 0) { |
|
| 179 | + $ratio = $this->getFile()->getProperty('width') / $this->getFile()->getProperty('height'); |
|
| 180 | + } |
|
| 181 | + return $ratio; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function getProcessingType() |
|
| 188 | + { |
|
| 189 | + if ($this->thumbnailService->getProcessingType() === null) { |
|
| 190 | + return ProcessedFile::CONTEXT_IMAGECROPSCALEMASK; |
|
| 191 | + } |
|
| 192 | + return $this->thumbnailService->getProcessingType(); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | 195 | } |
@@ -16,39 +16,39 @@ |
||
| 16 | 16 | class Dimension |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var int |
|
| 21 | - */ |
|
| 22 | - protected $width = 0; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 27 | - protected $height = 0; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param string $dimension |
|
| 31 | - */ |
|
| 32 | - public function __construct($dimension) |
|
| 33 | - { |
|
| 34 | - $dimensions = GeneralUtility::trimExplode('x', $dimension); |
|
| 35 | - $this->width = empty($dimensions[0]) ? 0 : $dimensions[0]; |
|
| 36 | - $this->height = empty($dimensions[1]) ? 0 : $dimensions[1]; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @return mixed |
|
| 41 | - */ |
|
| 42 | - public function getWidth() |
|
| 43 | - { |
|
| 44 | - return $this->width; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @return int |
|
| 49 | - */ |
|
| 50 | - public function getHeight() |
|
| 51 | - { |
|
| 52 | - return $this->height; |
|
| 53 | - } |
|
| 19 | + /** |
|
| 20 | + * @var int |
|
| 21 | + */ |
|
| 22 | + protected $width = 0; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | + protected $height = 0; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param string $dimension |
|
| 31 | + */ |
|
| 32 | + public function __construct($dimension) |
|
| 33 | + { |
|
| 34 | + $dimensions = GeneralUtility::trimExplode('x', $dimension); |
|
| 35 | + $this->width = empty($dimensions[0]) ? 0 : $dimensions[0]; |
|
| 36 | + $this->height = empty($dimensions[1]) ? 0 : $dimensions[1]; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @return mixed |
|
| 41 | + */ |
|
| 42 | + public function getWidth() |
|
| 43 | + { |
|
| 44 | + return $this->width; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @return int |
|
| 49 | + */ |
|
| 50 | + public function getHeight() |
|
| 51 | + { |
|
| 52 | + return $this->height; |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -18,267 +18,267 @@ |
||
| 18 | 18 | abstract class AbstractFormField implements FormFieldInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $template = ''; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $value = ''; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $name = ''; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $id = ''; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - protected $prefix = ''; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - protected $label = ''; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Store what child element will contain this element. |
|
| 53 | - * |
|
| 54 | - * @var array |
|
| 55 | - */ |
|
| 56 | - protected $items = []; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Attributes in sense of DOM attribute, e.g. class, style, etc... |
|
| 60 | - * |
|
| 61 | - * @var array |
|
| 62 | - */ |
|
| 63 | - protected $attributes = []; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function render() |
|
| 69 | - { |
|
| 70 | - return $this->template; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Render the label if possible. Otherwise return an empty string. |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function renderLabel() |
|
| 79 | - { |
|
| 80 | - $result = ''; |
|
| 81 | - if ($this->label) { |
|
| 82 | - $template = '<label class="control-label" for="%s">%s</label>'; |
|
| 83 | - |
|
| 84 | - if (strpos($this->label, 'LLL:') === 0) { |
|
| 85 | - $this->label = LocalizationUtility::translate($this->label, ''); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $result = sprintf($template, |
|
| 89 | - $this->getId(), |
|
| 90 | - $this->label |
|
| 91 | - ); |
|
| 92 | - } |
|
| 93 | - return $result; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Render additional attribute for this DOM element. |
|
| 98 | - * |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public function renderAttributes() |
|
| 102 | - { |
|
| 103 | - $result = ''; |
|
| 104 | - if (!empty($this->attributes)) { |
|
| 105 | - foreach ($this->attributes as $attribute => $value) { |
|
| 106 | - $result .= sprintf('%s="%s" ', |
|
| 107 | - htmlspecialchars($attribute), |
|
| 108 | - htmlspecialchars($value) |
|
| 109 | - ); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - return $result; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Add an additional (DOM) attribute to be added to this template. |
|
| 117 | - * |
|
| 118 | - * @throws InvalidStringException |
|
| 119 | - * @param array $attribute associative array that contains attribute => value |
|
| 120 | - * @return \Fab\Media\Form\AbstractFormField |
|
| 121 | - */ |
|
| 122 | - public function addAttribute(array $attribute) |
|
| 123 | - { |
|
| 124 | - if (!empty($attribute)) { |
|
| 125 | - reset($attribute); |
|
| 126 | - $key = key($attribute); |
|
| 127 | - if (!is_string($key)) { |
|
| 128 | - throw new InvalidStringException('Not an associative array. Is not a key: ' . $key, 1356478742); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $this->attributes[$key] = $attribute[$key]; |
|
| 132 | - } |
|
| 133 | - return $this; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - public function getTemplate() |
|
| 140 | - { |
|
| 141 | - return $this->template; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param string $template |
|
| 146 | - * @return \Fab\Media\Form\AbstractFormField |
|
| 147 | - */ |
|
| 148 | - public function setTemplate($template) |
|
| 149 | - { |
|
| 150 | - $this->template = $template; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @return string |
|
| 155 | - */ |
|
| 156 | - public function getLabel() |
|
| 157 | - { |
|
| 158 | - return $this->label; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param string $label |
|
| 163 | - * @return \Fab\Media\Form\AbstractFormField |
|
| 164 | - */ |
|
| 165 | - public function setLabel($label) |
|
| 166 | - { |
|
| 167 | - $this->label = $label; |
|
| 168 | - return $this; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @return string |
|
| 173 | - */ |
|
| 174 | - public function getPrefix() |
|
| 175 | - { |
|
| 176 | - return $this->prefix; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @param string $prefix |
|
| 181 | - * @return \Fab\Media\Form\AbstractFormField |
|
| 182 | - */ |
|
| 183 | - public function setPrefix($prefix) |
|
| 184 | - { |
|
| 185 | - $this->prefix = $prefix; |
|
| 186 | - return $this; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @return array |
|
| 191 | - */ |
|
| 192 | - public function getItems() |
|
| 193 | - { |
|
| 194 | - return $this->items; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param array $items |
|
| 199 | - */ |
|
| 200 | - public function setItems($items) |
|
| 201 | - { |
|
| 202 | - $this->items = $items; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function getValue() |
|
| 209 | - { |
|
| 210 | - return htmlspecialchars($this->value); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @param string $value |
|
| 215 | - * @return \Fab\Media\Form\AbstractFormField |
|
| 216 | - */ |
|
| 217 | - public function setValue($value) |
|
| 218 | - { |
|
| 219 | - $this->value = $value; |
|
| 220 | - return $this; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @return string |
|
| 225 | - */ |
|
| 226 | - public function getName() |
|
| 227 | - { |
|
| 228 | - $result = $this->name; |
|
| 229 | - if ($this->getPrefix()) { |
|
| 230 | - $result = sprintf('%s[%s]', $this->getPrefix(), $this->name); |
|
| 231 | - } |
|
| 232 | - return $result; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @param string $name |
|
| 237 | - * @return \Fab\Media\Form\AbstractFormField |
|
| 238 | - */ |
|
| 239 | - public function setName($name) |
|
| 240 | - { |
|
| 241 | - $this->name = $name; |
|
| 242 | - return $this; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - public function getId() |
|
| 249 | - { |
|
| 250 | - if ($this->id === '') { |
|
| 251 | - $this->id = DomElement::getInstance()->formatId($this->getName()); |
|
| 252 | - } |
|
| 253 | - return $this->id; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @param string $id |
|
| 258 | - * @return \Fab\Media\Form\AbstractFormField |
|
| 259 | - */ |
|
| 260 | - public function setId($id) |
|
| 261 | - { |
|
| 262 | - $this->id = $id; |
|
| 263 | - return $this; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @return array |
|
| 268 | - */ |
|
| 269 | - public function getAttributes() |
|
| 270 | - { |
|
| 271 | - return $this->attributes; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @param array $attributes |
|
| 276 | - * @return \Fab\Media\Form\AbstractFormField |
|
| 277 | - */ |
|
| 278 | - public function setAttributes($attributes) |
|
| 279 | - { |
|
| 280 | - $this->attributes = $attributes; |
|
| 281 | - return $this; |
|
| 282 | - } |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $template = ''; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $value = ''; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $name = ''; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $id = ''; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + protected $prefix = ''; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + protected $label = ''; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Store what child element will contain this element. |
|
| 53 | + * |
|
| 54 | + * @var array |
|
| 55 | + */ |
|
| 56 | + protected $items = []; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Attributes in sense of DOM attribute, e.g. class, style, etc... |
|
| 60 | + * |
|
| 61 | + * @var array |
|
| 62 | + */ |
|
| 63 | + protected $attributes = []; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function render() |
|
| 69 | + { |
|
| 70 | + return $this->template; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Render the label if possible. Otherwise return an empty string. |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function renderLabel() |
|
| 79 | + { |
|
| 80 | + $result = ''; |
|
| 81 | + if ($this->label) { |
|
| 82 | + $template = '<label class="control-label" for="%s">%s</label>'; |
|
| 83 | + |
|
| 84 | + if (strpos($this->label, 'LLL:') === 0) { |
|
| 85 | + $this->label = LocalizationUtility::translate($this->label, ''); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $result = sprintf($template, |
|
| 89 | + $this->getId(), |
|
| 90 | + $this->label |
|
| 91 | + ); |
|
| 92 | + } |
|
| 93 | + return $result; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Render additional attribute for this DOM element. |
|
| 98 | + * |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public function renderAttributes() |
|
| 102 | + { |
|
| 103 | + $result = ''; |
|
| 104 | + if (!empty($this->attributes)) { |
|
| 105 | + foreach ($this->attributes as $attribute => $value) { |
|
| 106 | + $result .= sprintf('%s="%s" ', |
|
| 107 | + htmlspecialchars($attribute), |
|
| 108 | + htmlspecialchars($value) |
|
| 109 | + ); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + return $result; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Add an additional (DOM) attribute to be added to this template. |
|
| 117 | + * |
|
| 118 | + * @throws InvalidStringException |
|
| 119 | + * @param array $attribute associative array that contains attribute => value |
|
| 120 | + * @return \Fab\Media\Form\AbstractFormField |
|
| 121 | + */ |
|
| 122 | + public function addAttribute(array $attribute) |
|
| 123 | + { |
|
| 124 | + if (!empty($attribute)) { |
|
| 125 | + reset($attribute); |
|
| 126 | + $key = key($attribute); |
|
| 127 | + if (!is_string($key)) { |
|
| 128 | + throw new InvalidStringException('Not an associative array. Is not a key: ' . $key, 1356478742); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $this->attributes[$key] = $attribute[$key]; |
|
| 132 | + } |
|
| 133 | + return $this; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + public function getTemplate() |
|
| 140 | + { |
|
| 141 | + return $this->template; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param string $template |
|
| 146 | + * @return \Fab\Media\Form\AbstractFormField |
|
| 147 | + */ |
|
| 148 | + public function setTemplate($template) |
|
| 149 | + { |
|
| 150 | + $this->template = $template; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @return string |
|
| 155 | + */ |
|
| 156 | + public function getLabel() |
|
| 157 | + { |
|
| 158 | + return $this->label; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param string $label |
|
| 163 | + * @return \Fab\Media\Form\AbstractFormField |
|
| 164 | + */ |
|
| 165 | + public function setLabel($label) |
|
| 166 | + { |
|
| 167 | + $this->label = $label; |
|
| 168 | + return $this; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @return string |
|
| 173 | + */ |
|
| 174 | + public function getPrefix() |
|
| 175 | + { |
|
| 176 | + return $this->prefix; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @param string $prefix |
|
| 181 | + * @return \Fab\Media\Form\AbstractFormField |
|
| 182 | + */ |
|
| 183 | + public function setPrefix($prefix) |
|
| 184 | + { |
|
| 185 | + $this->prefix = $prefix; |
|
| 186 | + return $this; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @return array |
|
| 191 | + */ |
|
| 192 | + public function getItems() |
|
| 193 | + { |
|
| 194 | + return $this->items; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param array $items |
|
| 199 | + */ |
|
| 200 | + public function setItems($items) |
|
| 201 | + { |
|
| 202 | + $this->items = $items; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function getValue() |
|
| 209 | + { |
|
| 210 | + return htmlspecialchars($this->value); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @param string $value |
|
| 215 | + * @return \Fab\Media\Form\AbstractFormField |
|
| 216 | + */ |
|
| 217 | + public function setValue($value) |
|
| 218 | + { |
|
| 219 | + $this->value = $value; |
|
| 220 | + return $this; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @return string |
|
| 225 | + */ |
|
| 226 | + public function getName() |
|
| 227 | + { |
|
| 228 | + $result = $this->name; |
|
| 229 | + if ($this->getPrefix()) { |
|
| 230 | + $result = sprintf('%s[%s]', $this->getPrefix(), $this->name); |
|
| 231 | + } |
|
| 232 | + return $result; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @param string $name |
|
| 237 | + * @return \Fab\Media\Form\AbstractFormField |
|
| 238 | + */ |
|
| 239 | + public function setName($name) |
|
| 240 | + { |
|
| 241 | + $this->name = $name; |
|
| 242 | + return $this; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + public function getId() |
|
| 249 | + { |
|
| 250 | + if ($this->id === '') { |
|
| 251 | + $this->id = DomElement::getInstance()->formatId($this->getName()); |
|
| 252 | + } |
|
| 253 | + return $this->id; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @param string $id |
|
| 258 | + * @return \Fab\Media\Form\AbstractFormField |
|
| 259 | + */ |
|
| 260 | + public function setId($id) |
|
| 261 | + { |
|
| 262 | + $this->id = $id; |
|
| 263 | + return $this; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @return array |
|
| 268 | + */ |
|
| 269 | + public function getAttributes() |
|
| 270 | + { |
|
| 271 | + return $this->attributes; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @param array $attributes |
|
| 276 | + * @return \Fab\Media\Form\AbstractFormField |
|
| 277 | + */ |
|
| 278 | + public function setAttributes($attributes) |
|
| 279 | + { |
|
| 280 | + $this->attributes = $attributes; |
|
| 281 | + return $this; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | 284 | } |