TYPO3 CMS  TYPO3_6-2
ImageRenderingController.php
Go to the documentation of this file.
1 <?php
3 
19 
24 
30  public $prefixId = 'ImageRenderingController';
31 
37  public $scriptRelPath = 'Classes/Controller/ImageRenderingController.php';
38 
44  public $extKey = 'rtehtmlarea';
45 
51  public $conf = array();
52 
58  public $cObj;
59 
67  public function renderImageAttributes($content = '', $conf) {
68 
69  $imageAttributes = $this->getImageAttributes();
70 
71  // It is pretty rare to be in presence of an external image as the default behaviour
72  // of the RTE is to download the external image and create a local image.
73  // However, it may happen if the RTE has the flag "disable"
74  if (!$this->isExternalImage()) {
75  $fileUid = (int)$imageAttributes['data-htmlarea-file-uid'];
76  if ($fileUid) {
77  try {
78  $file = Resource\ResourceFactory::getInstance()->getFileObject($fileUid);
79  if ($imageAttributes['src'] !== $file->getPublicUrl()) {
80  // Source file is a processed image
81  $imageConfiguration = array(
82  'width' => (int)$imageAttributes['width'],
83  'height' => (int)$imageAttributes['height']
84  );
85  $processedFile = $this->getMagicImageService()->createMagicImage($file, $imageConfiguration);
86  $additionalAttributes = array(
87  'src' => $processedFile->getPublicUrl(),
88  'title' => $imageAttributes['title'] ?: $file->getProperty('title'),
89  'alt' => $imageAttributes['alt'] ?: $file->getProperty('alternative'),
90  'width' => $processedFile->getProperty('width'),
91  'height' => $processedFile->getProperty('height'),
92  );
93  $imageAttributes = array_merge($imageAttributes, $additionalAttributes);
94  }
95  } catch (Resource\Exception\FileDoesNotExistException $fileDoesNotExistException) {
96  // Log the fact the file could not be retrieved.
97  $message = sprintf('I could not find file with uid "%s"', $fileUid);
98  $this->getLogger()->error($message);
99  }
100  }
101  }
102  return '<img ' . GeneralUtility::implodeAttributes($imageAttributes, TRUE, TRUE) . ' />';
103  }
104 
110  protected function getImageAttributes() {
111  return $this->cObj->parameters;
112  }
113 
119  protected function getMagicImageService() {
120 
122  $magicImageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\MagicImageService');
123 
124  // Get RTE configuration
125  $pageTSConfig = $this->getFrontendObject()->getPagesTSconfig();
126  if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.']['default.'])) {
127  $magicImageService->setMagicImageMaximumDimensions($pageTSConfig['RTE.']['default.']);
128  }
129 
130  return $magicImageService;
131  }
132 
138  protected function isExternalImage() {
139  $srcAbsoluteUrl = $this->cObj->parameters['src'];
140  return strtolower(substr($srcAbsoluteUrl, 0, 4)) === 'http' || substr($srcAbsoluteUrl, 0, 2) === '//';
141  }
142 
146  protected function getLogger() {
147 
149  $logManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager');
150 
151  return $logManager->getLogger(get_class($this));
152  }
153 
159  protected function getFrontendObject() {
160  return $GLOBALS['TSFE'];
161  }
162 }
static implodeAttributes(array $arr, $xhtmlSafe=FALSE, $dontOmitBlankAttribs=FALSE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]