/** * Walk all files and fetch desired additional information like image sizes etc. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ protected function fetchAdditionalData() { $this->modifiedTime = array(); $this->outputBuffer = array(); if (!$this->foundFiles) { return; } /** @var EventDispatcherInterface $dispatcher */ $dispatcher = $GLOBALS['container']['event-dispatcher']; $resizeInfo = $this->getResizeImages(); $intWidth = $resizeInfo[0] ? $resizeInfo[0] : ''; $intHeight = $resizeInfo[1] ? $resizeInfo[1] : ''; $strMode = $resizeInfo[2] ? $resizeInfo[2] : ''; foreach ($this->foundFiles as $strFile) { $objFile = new \File($strFile); $arrMeta = $this->metaInformation[dirname($strFile)][$objFile->basename]; $strBasename = strlen($arrMeta['title']) ? $arrMeta['title'] : specialchars($objFile->basename); if (strlen($arrMeta['caption'])) { $strAltText = $arrMeta['caption']; } else { $strAltText = ucfirst(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename))); } $strIcon = 'assets/contao/images/' . $objFile->icon; $arrSource = array('file' => $strFile, 'mtime' => $objFile->mtime, 'alt' => $strAltText, 'caption' => strlen($arrMeta['caption']) ? $arrMeta['caption'] : '', 'title' => $strBasename, 'metafile' => $arrMeta, 'icon' => $strIcon, 'extension' => $objFile->extension, 'size' => $objFile->filesize, 'sizetext' => sprintf('(%s)', \Controller::getReadableSize($objFile->filesize, 2)), 'url' => specialchars($this->getDownloadLink($strFile))); // Prepare images. if ($arrSource['isGdImage'] = $objFile->isGdImage) { if ($this->getShowImages() && ($intWidth || $intHeight || $strMode)) { $event = new ResizeImageEvent($strFile, $intWidth, $intHeight, $strMode); $dispatcher->dispatch(ContaoEvents::IMAGE_RESIZE, $event); $strSrc = $event->getResultImage(); } else { $strSrc = $strFile; } $arrSource['src'] = $strSrc; if (file_exists(TL_ROOT . '/' . urldecode($strSrc))) { $size = getimagesize(TL_ROOT . '/' . urldecode($strSrc)); $arrSource['lb'] = 'lb' . $this->getLightboxId(); $arrSource['w'] = $size[0]; $arrSource['h'] = $size[1]; $arrSource['wh'] = $size[3]; } } $this->modifiedTime[] = $objFile->mtime; $this->outputBuffer[] = $arrSource; } }