get() public static méthode

Resize an image and store the resized version in the image target folder
Deprecation: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the contao.image.image_factory service instead.
public static get ( string $image, integer $width, integer $height, string $mode = '', string $target = null, boolean $force = false ) : string | null
$image string The image path
$width integer The target width
$height integer The target height
$mode string The resize mode
$target string An optional target path
$force boolean Override existing target images
Résultat string | null The path of the resized image or null
 public function generateLabel($row, $label)
 {
     $sReturn = '';
     $objFile = \FilesModel::findByPk(deserialize($row['logo']));
     if ($objFile->path != '') {
         $sReturn = '<figure style="float: left; margin-right: 1em;"><img src="' . Image::get($objFile->path, 80, 50, 'center_center') . '"></figure>';
     }
     $sReturn .= '<div>' . $label . '</div>';
     return $sReturn;
 }
 /**
  * Tests the legacy get() method.
  *
  * @param array $arguments
  * @param array $expectedResult
  *
  * @dataProvider getLegacyGet
  */
 public function testLegacyGet($arguments, $expectedResult)
 {
     $result = Image::get($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]);
     $this->assertSame($result, $expectedResult);
 }
    /**
     * Render a row of a box and return it as HTML string
     *
     * @param string $strPalette
     *
     * @return string
     *
     * @throws AccessDeniedException
     * @throws \Exception
     */
    protected function row($strPalette = null)
    {
        $arrData = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField];
        // Check if the field is excluded
        if ($arrData['exclude']) {
            throw new AccessDeniedException('Field "' . $this->strTable . '.' . $this->strField . '" is excluded from being edited.');
        }
        $xlabel = '';
        // Toggle line wrap (textarea)
        if ($arrData['inputType'] == 'textarea' && !isset($arrData['eval']['rte'])) {
            $xlabel .= ' ' . \Image::getHtml('wrap.svg', $GLOBALS['TL_LANG']['MSC']['wordWrap'], 'title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['wordWrap']) . '" class="toggleWrap" onclick="Backend.toggleWrap(\'ctrl_' . $this->strInputName . '\')"');
        }
        // Add the help wizard
        if ($arrData['eval']['helpwizard']) {
            $xlabel .= ' <a href="contao/help.php?table=' . $this->strTable . '&amp;field=' . $this->strField . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['helpWizard']) . '" onclick="Backend.openModalIframe({\'width\':735,\'title\':\'' . \StringUtil::specialchars(str_replace("'", "\\'", $arrData['label'][0])) . '\',\'url\':this.href});return false">' . \Image::getHtml('about.svg', $GLOBALS['TL_LANG']['MSC']['helpWizard'], 'style="vertical-align:text-bottom"') . '</a>';
        }
        // Add a custom xlabel
        if (is_array($arrData['xlabel'])) {
            foreach ($arrData['xlabel'] as $callback) {
                if (is_array($callback)) {
                    $this->import($callback[0]);
                    $xlabel .= $this->{$callback[0]}->{$callback[1]}($this);
                } elseif (is_callable($callback)) {
                    $xlabel .= $callback($this);
                }
            }
        }
        // Input field callback
        if (is_array($arrData['input_field_callback'])) {
            $this->import($arrData['input_field_callback'][0]);
            return $this->{$arrData['input_field_callback'][0]}->{$arrData['input_field_callback'][1]}($this, $xlabel);
        } elseif (is_callable($arrData['input_field_callback'])) {
            return $arrData['input_field_callback']($this, $xlabel);
        }
        /** @var Widget $strClass */
        $strClass = $GLOBALS['BE_FFL'][$arrData['inputType']];
        // Return if the widget class does not exists
        if (!class_exists($strClass)) {
            return '';
        }
        $arrData['eval']['required'] = false;
        // Use strlen() here (see #3277)
        if ($arrData['eval']['mandatory']) {
            if (is_array($this->varValue)) {
                if (empty($this->varValue)) {
                    $arrData['eval']['required'] = true;
                }
            } else {
                if (!strlen($this->varValue)) {
                    $arrData['eval']['required'] = true;
                }
            }
        }
        // Convert insert tags in src attributes (see #5965)
        if (isset($arrData['eval']['rte']) && strncmp($arrData['eval']['rte'], 'tiny', 4) === 0) {
            $this->varValue = \StringUtil::insertTagToSrc($this->varValue);
        }
        /** @var Widget $objWidget */
        $objWidget = new $strClass($strClass::getAttributesFromDca($arrData, $this->strInputName, $this->varValue, $this->strField, $this->strTable, $this));
        $objWidget->xlabel = $xlabel;
        $objWidget->currentRecord = $this->intId;
        // Validate the field
        if (\Input::post('FORM_SUBMIT') == $this->strTable) {
            $key = \Input::get('act') == 'editAll' ? 'FORM_FIELDS_' . $this->intId : 'FORM_FIELDS';
            // Calculate the current palette
            $postPaletteFields = implode(',', \Input::post($key));
            $postPaletteFields = array_unique(\StringUtil::trimsplit('[,;]', $postPaletteFields));
            // Compile the palette if there is none
            if ($strPalette === null) {
                $newPaletteFields = \StringUtil::trimsplit('[,;]', $this->getPalette());
            } else {
                // Use the given palette ($strPalette is an array in editAll mode)
                $newPaletteFields = is_array($strPalette) ? $strPalette : \StringUtil::trimsplit('[,;]', $strPalette);
                // Re-check the palette if the current field is a selector field
                if (isset($GLOBALS['TL_DCA'][$this->strTable]['palettes']['__selector__']) && in_array($this->strField, $GLOBALS['TL_DCA'][$this->strTable]['palettes']['__selector__'])) {
                    // If the field value has changed, recompile the palette
                    if ($this->varValue != \Input::post($this->strInputName)) {
                        $newPaletteFields = \StringUtil::trimsplit('[,;]', $this->getPalette());
                    }
                }
            }
            // Adjust the names in editAll mode
            if (\Input::get('act') == 'editAll') {
                foreach ($newPaletteFields as $k => $v) {
                    $newPaletteFields[$k] = $v . '_' . $this->intId;
                }
                if ($this->User->isAdmin) {
                    $newPaletteFields['pid'] = 'pid_' . $this->intId;
                    $newPaletteFields['sorting'] = 'sorting_' . $this->intId;
                }
            }
            $paletteFields = array_intersect($postPaletteFields, $newPaletteFields);
            // Validate and save the field
            if (in_array($this->strInputName, $paletteFields) || \Input::get('act') == 'overrideAll') {
                $objWidget->validate();
                if ($objWidget->hasErrors()) {
                    // Skip mandatory fields on auto-submit (see #4077)
                    if (\Input::post('SUBMIT_TYPE') != 'auto' || !$objWidget->mandatory || $objWidget->value != '') {
                        $this->noReload = true;
                    }
                } elseif ($objWidget->submitInput()) {
                    $varValue = $objWidget->value;
                    // Sort array by key (fix for JavaScript wizards)
                    if (is_array($varValue)) {
                        ksort($varValue);
                        $varValue = serialize($varValue);
                    }
                    // Convert file paths in src attributes (see #5965)
                    if ($varValue && isset($arrData['eval']['rte']) && strncmp($arrData['eval']['rte'], 'tiny', 4) === 0) {
                        $varValue = \StringUtil::srcToInsertTag($varValue);
                    }
                    // Save the current value
                    try {
                        $this->save($varValue);
                    } catch (\Exception $e) {
                        $this->noReload = true;
                        $objWidget->addError($e->getMessage());
                    }
                }
            }
        }
        $wizard = '';
        $strHelpClass = '';
        // Date picker
        if ($arrData['eval']['datepicker']) {
            $rgxp = $arrData['eval']['rgxp'];
            $format = \Date::formatToJs(\Config::get($rgxp . 'Format'));
            switch ($rgxp) {
                case 'datim':
                    $time = ",\n      timePicker:true";
                    break;
                case 'time':
                    $time = ",\n      pickOnly:\"time\"";
                    break;
                default:
                    $time = '';
                    break;
            }
            $wizard .= ' ' . \Image::getHtml('assets/datepicker/images/icon.svg', '', 'title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['datepicker']) . '" id="toggle_' . $objWidget->id . '" style="cursor:pointer"') . '
  <script>
    window.addEvent("domready", function() {
      new Picker.Date($("ctrl_' . $objWidget->id . '"), {
        draggable: false,
        toggle: $("toggle_' . $objWidget->id . '"),
        format: "' . $format . '",
        positionOffset: {x:-211,y:-209}' . $time . ',
        pickerClass: "datepicker_bootstrap",
        useFadeInOut: !Browser.ie,
        startDay: ' . $GLOBALS['TL_LANG']['MSC']['weekOffset'] . ',
        titleFormat: "' . $GLOBALS['TL_LANG']['MSC']['titleFormat'] . '"
      });
    });
  </script>';
        }
        // Color picker
        if ($arrData['eval']['colorpicker']) {
            // Support single fields as well (see #5240)
            $strKey = $arrData['eval']['multiple'] ? $this->strField . '_0' : $this->strField;
            $wizard .= ' ' . \Image::getHtml('pickcolor.svg', $GLOBALS['TL_LANG']['MSC']['colorpicker'], 'title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['colorpicker']) . '" id="moo_' . $this->strField . '"') . '
  <script>
    window.addEvent("domready", function() {
      new MooRainbow("moo_' . $this->strField . '", {
        id: "ctrl_' . $strKey . '",
        startColor: ((cl = $("ctrl_' . $strKey . '").value.hexToRgb(true)) ? cl : [255, 0, 0]),
        imgPath: "assets/colorpicker/images/",
        onComplete: function(color) {
          $("ctrl_' . $strKey . '").value = color.hex.replace("#", "");
        }
      });
    });
  </script>';
        }
        // Add a custom wizard
        if (is_array($arrData['wizard'])) {
            foreach ($arrData['wizard'] as $callback) {
                if (is_array($callback)) {
                    $this->import($callback[0]);
                    $wizard .= $this->{$callback[0]}->{$callback[1]}($this);
                } elseif (is_callable($callback)) {
                    $wizard .= $callback($this);
                }
            }
        }
        $objWidget->wizard = $wizard;
        // Set correct form enctype
        if ($objWidget instanceof \uploadable) {
            $this->blnUploadable = true;
        }
        // Mark floated single checkboxes
        if ($arrData['inputType'] == 'checkbox' && !$arrData['eval']['multiple'] && strpos($arrData['eval']['tl_class'], 'w50') !== false) {
            $arrData['eval']['tl_class'] .= ' cbx';
        } elseif ($arrData['inputType'] == 'text' && $arrData['eval']['multiple'] && strpos($arrData['eval']['tl_class'], 'wizard') !== false) {
            $arrData['eval']['tl_class'] .= ' inline';
        }
        // No 2-column layout in "edit all" mode
        if (\Input::get('act') == 'editAll' || \Input::get('act') == 'overrideAll') {
            $arrData['eval']['tl_class'] = str_replace(array('w50', 'clr', 'wizard', 'long', 'm12', 'cbx'), '', $arrData['eval']['tl_class']);
        }
        $updateMode = '';
        // Replace the textarea with an RTE instance
        if (!empty($arrData['eval']['rte'])) {
            list($file, $type) = explode('|', $arrData['eval']['rte'], 2);
            /** @var BackendTemplate|object $objTemplate */
            $objTemplate = new \BackendTemplate("be_{$file}");
            $objTemplate->selector = 'ctrl_' . $this->strInputName;
            // Deprecated since Contao 4.0, to be removed in Contao 5.0
            $objTemplate->language = \Backend::getTinyMceLanguage();
            $updateMode = $objTemplate->parse();
            unset($file, $type);
        } elseif (\Input::get('act') == 'overrideAll' && ($arrData['inputType'] == 'checkbox' || $arrData['inputType'] == 'checkboxWizard') && $arrData['eval']['multiple']) {
            $updateMode = '
</div>
<div>
  <fieldset class="tl_radio_container">
  <legend>' . $GLOBALS['TL_LANG']['MSC']['updateMode'] . '</legend>
    <input type="radio" name="' . $this->strInputName . '_update" id="opt_' . $this->strInputName . '_update_1" class="tl_radio" value="add" onfocus="Backend.getScrollOffset()"> <label for="opt_' . $this->strInputName . '_update_1">' . $GLOBALS['TL_LANG']['MSC']['updateAdd'] . '</label><br>
    <input type="radio" name="' . $this->strInputName . '_update" id="opt_' . $this->strInputName . '_update_2" class="tl_radio" value="remove" onfocus="Backend.getScrollOffset()"> <label for="opt_' . $this->strInputName . '_update_2">' . $GLOBALS['TL_LANG']['MSC']['updateRemove'] . '</label><br>
    <input type="radio" name="' . $this->strInputName . '_update" id="opt_' . $this->strInputName . '_update_0" class="tl_radio" value="replace" checked="checked" onfocus="Backend.getScrollOffset()"> <label for="opt_' . $this->strInputName . '_update_0">' . $GLOBALS['TL_LANG']['MSC']['updateReplace'] . '</label>
  </fieldset>';
        }
        $strPreview = '';
        // Show a preview image (see #4948)
        if ($this->strTable == 'tl_files' && $this->strField == 'name' && $this->objActiveRecord !== null && $this->objActiveRecord->type == 'file') {
            $objFile = new \File($this->objActiveRecord->path);
            if ($objFile->isImage) {
                $image = \Image::getPath('placeholder.svg');
                if ($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) {
                    if ($objFile->width > 699 || $objFile->height > 524 || !$objFile->width || !$objFile->height) {
                        $image = rawurldecode(\Image::get($objFile->path, 699, 524, 'box'));
                    } else {
                        $image = $objFile->path;
                    }
                }
                $objImage = new \File($image);
                $ctrl = 'ctrl_preview_' . substr(md5($image), 0, 8);
                $strPreview = '

<div id="' . $ctrl . '" class="tl_edit_preview" data-original-width="' . $objFile->viewWidth . '" data-original-height="' . $objFile->viewHeight . '">
  <img src="' . $objImage->dataUri . '" width="' . $objImage->width . '" height="' . $objImage->height . '" alt="">
</div>';
                // Add the script to mark the important part
                if (basename($image) !== 'placeholder.svg') {
                    $strPreview .= '<script>Backend.editPreviewWizard($(\'' . $ctrl . '\'));</script>';
                    if (\Config::get('showHelp')) {
                        $strPreview .= '<p class="tl_help tl_tip">' . $GLOBALS['TL_LANG'][$this->strTable]['edit_preview_help'] . '</p>';
                    }
                }
            }
        }
        return $strPreview . '
<div' . ($arrData['eval']['tl_class'] ? ' class="' . $arrData['eval']['tl_class'] . '"' : '') . '>' . $objWidget->parse() . $updateMode . (!$objWidget->hasErrors() ? $this->help($strHelpClass) : '') . '
</div>';
    }
 /**
  * Resize an image and crop it if necessary
  *
  * @param string  $image  The image path
  * @param integer $width  The target width
  * @param integer $height The target height
  * @param string  $mode   An optional resize mode
  * @param string  $target An optional target to be replaced
  * @param boolean $force  Override existing target images
  *
  * @return string|null The image path or null
  *
  * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
  *             Use Image::get() instead.
  */
 protected function getImage($image, $width, $height, $mode = '', $target = null, $force = false)
 {
     trigger_error('Using Controller::getImage() has been deprecated and will no longer work in Contao 5.0. Use Image::get() instead.', E_USER_DEPRECATED);
     return \Image::get($image, $width, $height, $mode, $target, $force);
 }
 /**
  * Render the file tree and return it as HTML string
  *
  * @param string  $path
  * @param integer $intMargin
  * @param boolean $mount
  * @param boolean $blnProtected
  * @param array   $arrClipboard
  *
  * @return string
  */
 protected function generateTree($path, $intMargin, $mount = false, $blnProtected = true, $arrClipboard = null)
 {
     static $session;
     /** @var AttributeBagInterface $objSessionBag */
     $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
     $session = $objSessionBag->all();
     // Get the session data and toggle the nodes
     if (\Input::get('tg')) {
         $session['filetree'][\Input::get('tg')] = isset($session['filetree'][\Input::get('tg')]) && $session['filetree'][\Input::get('tg')] == 1 ? 0 : 1;
         $objSessionBag->replace($session);
         $this->redirect(preg_replace('/(&(amp;)?|\\?)tg=[^& ]*/i', '', \Environment::get('request')));
     }
     $return = '';
     $files = array();
     $folders = array();
     $intSpacing = 20;
     $level = $intMargin / $intSpacing + 1;
     // Mount folder
     if ($mount) {
         $folders = array($path);
     } else {
         foreach (scan($path) as $v) {
             if (strncmp($v, '.', 1) === 0) {
                 continue;
             }
             if (is_file($path . '/' . $v)) {
                 $files[] = $path . '/' . $v;
             } else {
                 if ($v == '__new__') {
                     $this->Files->rmdir(str_replace(TL_ROOT . '/', '', $path) . '/' . $v);
                 } else {
                     $folders[] = $path . '/' . $v;
                 }
             }
         }
         natcasesort($folders);
         $folders = array_values($folders);
         natcasesort($files);
         $files = array_values($files);
     }
     // Folders
     for ($f = 0, $c = count($folders); $f < $c; $f++) {
         $md5 = substr(md5($folders[$f]), 0, 8);
         $content = scan($folders[$f]);
         $currentFolder = str_replace(TL_ROOT . '/', '', $folders[$f]);
         $session['filetree'][$md5] = is_numeric($session['filetree'][$md5]) ? $session['filetree'][$md5] : 0;
         $currentEncoded = $this->urlEncode($currentFolder);
         $countFiles = count($content);
         // Subtract files that will not be shown
         foreach ($content as $file) {
             if (strncmp($file, '.', 1) === 0) {
                 --$countFiles;
             } elseif (!empty($this->arrValidFileTypes) && is_file($folders[$f] . '/' . $file) && !in_array(strtolower(substr($file, strrpos($file, '.') + 1)), $this->arrValidFileTypes)) {
                 --$countFiles;
             }
         }
         $return .= "\n  " . '<li class="tl_folder click2edit toggle_select" onmouseover="Theme.hoverDiv(this,1)" onmouseout="Theme.hoverDiv(this,0)"><div class="tl_left" style="padding-left:' . ($intMargin + ($countFiles < 1 ? 20 : 0)) . 'px">';
         // Add a toggle button if there are childs
         if ($countFiles > 0) {
             $img = $session['filetree'][$md5] == 1 ? 'folMinus.gif' : 'folPlus.gif';
             $alt = $session['filetree'][$md5] == 1 ? $GLOBALS['TL_LANG']['MSC']['collapseNode'] : $GLOBALS['TL_LANG']['MSC']['expandNode'];
             $return .= '<a href="' . $this->addToUrl('tg=' . $md5) . '" title="' . specialchars($alt) . '" onclick="Backend.getScrollOffset(); return AjaxRequest.toggleFileManager(this, \'filetree_' . $md5 . '\', \'' . $currentFolder . '\', ' . $level . ')">' . \Image::getHtml($img, '', 'style="margin-right:2px"') . '</a>';
         }
         $protected = $blnProtected;
         // Check whether the folder is public
         if ($protected === true && array_search('.public', $content) !== false) {
             $protected = false;
         }
         $folderImg = $session['filetree'][$md5] == 1 && $countFiles > 0 ? $protected ? 'folderOP.gif' : 'folderO.gif' : ($protected ? 'folderCP.gif' : 'folderC.gif');
         // Add the current folder
         $strFolderNameEncoded = utf8_convert_encoding(specialchars(basename($currentFolder)), \Config::get('characterSet'));
         $return .= \Image::getHtml($folderImg, '') . ' <a href="' . $this->addToUrl('node=' . $currentEncoded) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '"><strong>' . $strFolderNameEncoded . '</strong></a></div> <div class="tl_right">';
         // Paste buttons
         if ($arrClipboard !== false && \Input::get('act') != 'select') {
             $imagePasteInto = \Image::getHtml('pasteinto.gif', $GLOBALS['TL_LANG'][$this->strTable]['pasteinto'][0]);
             $return .= ($arrClipboard['mode'] == 'cut' || $arrClipboard['mode'] == 'copy') && preg_match('/^' . preg_quote($arrClipboard['id'], '/') . '/i', $currentFolder) ? \Image::getHtml('pasteinto_.gif') : '<a href="' . $this->addToUrl('act=' . $arrClipboard['mode'] . '&amp;mode=2&amp;pid=' . $currentEncoded . (!is_array($arrClipboard['id']) ? '&amp;id=' . $arrClipboard['id'] : '')) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['pasteinto'][1]) . '" onclick="Backend.getScrollOffset()">' . $imagePasteInto . '</a> ';
         } else {
             // Do not display buttons for mounted folders
             if ($this->User->isAdmin || !in_array($currentFolder, $this->User->filemounts)) {
                 $return .= \Input::get('act') == 'select' ? '<input type="checkbox" name="IDS[]" id="ids_' . md5($currentEncoded) . '" class="tl_tree_checkbox" value="' . $currentEncoded . '">' : $this->generateButtons(array('id' => $currentEncoded, 'popupWidth' => 600, 'popupHeight' => 123, 'fileNameEncoded' => $strFolderNameEncoded), $this->strTable);
             }
             // Upload button
             if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable'] && \Input::get('act') != 'select') {
                 $return .= ' <a href="' . $this->addToUrl('&amp;act=move&amp;mode=2&amp;pid=' . $currentEncoded) . '" title="' . specialchars(sprintf($GLOBALS['TL_LANG']['tl_files']['uploadFF'], $currentEncoded)) . '">' . \Image::getHtml('new.gif', $GLOBALS['TL_LANG'][$this->strTable]['move'][0]) . '</a>';
             }
         }
         $return .= '</div><div style="clear:both"></div></li>';
         // Call the next node
         if (!empty($content) && $session['filetree'][$md5] == 1) {
             $return .= '<li class="parent" id="filetree_' . $md5 . '"><ul class="level_' . $level . '">';
             $return .= $this->generateTree($folders[$f], $intMargin + $intSpacing, false, $protected, $arrClipboard);
             $return .= '</ul></li>';
         }
     }
     // Process files
     for ($h = 0, $c = count($files); $h < $c; $h++) {
         $thumbnail = '';
         $popupWidth = 600;
         $popupHeight = 161;
         $currentFile = str_replace(TL_ROOT . '/', '', $files[$h]);
         $objFile = new \File($currentFile);
         if (!empty($this->arrValidFileTypes) && !in_array($objFile->extension, $this->arrValidFileTypes)) {
             continue;
         }
         $currentEncoded = $this->urlEncode($currentFile);
         $return .= "\n  " . '<li class="tl_file click2edit toggle_select" onmouseover="Theme.hoverDiv(this,1)" onmouseout="Theme.hoverDiv(this,0)"><div class="tl_left" style="padding-left:' . ($intMargin + $intSpacing) . 'px">';
         // Generate the thumbnail
         if ($objFile->isImage && $objFile->height > 0) {
             $popupWidth = $objFile->width > 600 ? $objFile->width + 61 : 661;
             $popupHeight = $objFile->height + 200;
             $thumbnail .= ' <span class="tl_gray">(' . $this->getReadableSize($objFile->filesize) . ', ' . $objFile->width . 'x' . $objFile->height . ' px)</span>';
             if (\Config::get('thumbnails') && ($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth'))) {
                 $_height = $objFile->height < 50 ? $objFile->height : 50;
                 $_width = $objFile->width * $_height / $objFile->height > 400 ? 90 : '';
                 $thumbnail .= '<br><img src="' . TL_FILES_URL . \Image::get($currentEncoded, $_width, $_height) . '" alt="" style="margin:0 0 2px -19px">';
             }
         } else {
             $thumbnail .= ' <span class="tl_gray">(' . $this->getReadableSize($objFile->filesize) . ')</span>';
         }
         $strFileNameEncoded = utf8_convert_encoding(specialchars(basename($currentFile)), \Config::get('characterSet'));
         // No popup links for templates and in the popup file manager
         if ($this->strTable == 'tl_templates' || \Input::get('popup')) {
             $return .= \Image::getHtml($objFile->icon) . ' ' . $strFileNameEncoded . $thumbnail . '</div> <div class="tl_right">';
         } else {
             $return .= '<a href="' . $currentEncoded . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['view']) . '" target="_blank">' . \Image::getHtml($objFile->icon, $objFile->mime) . '</a> ' . $strFileNameEncoded . $thumbnail . '</div> <div class="tl_right">';
         }
         // Buttons
         if ($arrClipboard !== false && \Input::get('act') != 'select') {
             $_buttons = '&nbsp;';
         } else {
             $_buttons = \Input::get('act') == 'select' ? '<input type="checkbox" name="IDS[]" id="ids_' . md5($currentEncoded) . '" class="tl_tree_checkbox" value="' . $currentEncoded . '">' : $this->generateButtons(array('id' => $currentEncoded, 'popupWidth' => $popupWidth, 'popupHeight' => $popupHeight, 'fileNameEncoded' => $strFileNameEncoded), $this->strTable);
         }
         $return .= $_buttons . '</div><div style="clear:both"></div></li>';
     }
     return $return;
 }
 /**
  * Handle a resize image event.
  *
  * @param ResizeImageEvent $event The event.
  *
  * @return void
  */
 public function handleResize(ResizeImageEvent $event)
 {
     $event->setResultImage(Image::get($event->getImage(), $event->getWidth(), $event->getHeight(), $event->getMode(), $event->getTarget(), $event->isForced()));
 }
 /**
  * Recursively render the filetree
  *
  * @param string  $path
  * @param integer $intMargin
  * @param boolean $mount
  * @param boolean $blnProtected
  *
  * @return string
  */
 protected function renderFiletree($path, $intMargin, $mount = false, $blnProtected = true)
 {
     // Invalid path
     if (!is_dir($path)) {
         return '';
     }
     // Make sure that $this->varValue is an array (see #3369)
     if (!is_array($this->varValue)) {
         $this->varValue = array($this->varValue);
     }
     static $session;
     /** @var AttributeBagInterface $objSessionBag */
     $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
     $session = $objSessionBag->all();
     $flag = substr($this->strField, 0, 2);
     $node = 'tree_' . $this->strTable . '_' . $this->strField;
     $xtnode = 'tree_' . $this->strTable . '_' . $this->strName;
     // Get session data and toggle nodes
     if (\Input::get($flag . 'tg')) {
         $session[$node][\Input::get($flag . 'tg')] = isset($session[$node][\Input::get($flag . 'tg')]) && $session[$node][\Input::get($flag . 'tg')] == 1 ? 0 : 1;
         $objSessionBag->replace($session);
         $this->redirect(preg_replace('/(&(amp;)?|\\?)' . $flag . 'tg=[^& ]*/i', '', \Environment::get('request')));
     }
     $return = '';
     $intSpacing = 20;
     $files = array();
     $folders = array();
     $level = $intMargin / $intSpacing + 1;
     // Mount folder
     if ($mount) {
         $folders = array($path);
     } else {
         foreach (scan($path) as $v) {
             if (strncmp($v, '.', 1) === 0) {
                 continue;
             }
             if (is_dir($path . '/' . $v)) {
                 $folders[] = $path . '/' . $v;
             } else {
                 $files[] = $path . '/' . $v;
             }
         }
     }
     natcasesort($folders);
     $folders = array_values($folders);
     natcasesort($files);
     $files = array_values($files);
     // Sort descending (see #4072)
     if ($this->sort == 'desc') {
         $folders = array_reverse($folders);
         $files = array_reverse($files);
     }
     $folderClass = $this->files || $this->filesOnly ? 'tl_folder' : 'tl_file';
     // Process folders
     for ($f = 0, $c = count($folders); $f < $c; $f++) {
         $countFiles = 0;
         $content = scan($folders[$f]);
         $return .= "\n    " . '<li class="' . $folderClass . ' toggle_select" onmouseover="Theme.hoverDiv(this, 1)" onmouseout="Theme.hoverDiv(this, 0)"><div class="tl_left" style="padding-left:' . $intMargin . 'px">';
         // Check whether there are subfolders or files
         foreach ($content as $v) {
             if (is_dir($folders[$f] . '/' . $v) || $this->files || $this->filesOnly) {
                 $countFiles++;
             }
         }
         $tid = md5($folders[$f]);
         $folderAttribute = 'style="margin-left:20px"';
         $session[$node][$tid] = is_numeric($session[$node][$tid]) ? $session[$node][$tid] : 0;
         $currentFolder = str_replace(TL_ROOT . '/', '', $folders[$f]);
         $blnIsOpen = $session[$node][$tid] == 1 || count(preg_grep('/^' . preg_quote($currentFolder, '/') . '\\//', $this->varValue)) > 0;
         // Add a toggle button if there are childs
         if ($countFiles > 0) {
             $folderAttribute = '';
             $img = $blnIsOpen ? 'folMinus.gif' : 'folPlus.gif';
             $alt = $blnIsOpen ? $GLOBALS['TL_LANG']['MSC']['collapseNode'] : $GLOBALS['TL_LANG']['MSC']['expandNode'];
             $return .= '<a href="' . $this->addToUrl($flag . 'tg=' . $tid) . '" title="' . specialchars($alt) . '" onclick="return AjaxRequest.toggleFiletree(this,\'' . $xtnode . '_' . $tid . '\',\'' . $currentFolder . '\',\'' . $this->strField . '\',\'' . $this->strName . '\',' . $level . ')">' . \Image::getHtml($img, '', 'style="margin-right:2px"') . '</a>';
         }
         $protected = $blnProtected;
         // Check whether the folder is public
         if ($protected === true && array_search('.public', $content) !== false) {
             $protected = false;
         }
         $folderImg = $blnIsOpen && $countFiles > 0 ? $protected ? 'folderOP.gif' : 'folderO.gif' : ($protected ? 'folderCP.gif' : 'folderC.gif');
         $folderLabel = $this->files || $this->filesOnly ? '<strong>' . specialchars(basename($currentFolder)) . '</strong>' : specialchars(basename($currentFolder));
         // Add the current folder
         $return .= \Image::getHtml($folderImg, '', $folderAttribute) . ' <a href="' . $this->addToUrl('node=' . $this->urlEncode($currentFolder)) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '">' . $folderLabel . '</a></div> <div class="tl_right">';
         // Add a checkbox or radio button
         if (!$this->filesOnly) {
             switch ($this->fieldType) {
                 case 'checkbox':
                     $return .= '<input type="checkbox" name="' . $this->strName . '[]" id="' . $this->strName . '_' . md5($currentFolder) . '" class="tl_tree_checkbox" value="' . specialchars($currentFolder) . '" onfocus="Backend.getScrollOffset()"' . $this->optionChecked($currentFolder, $this->varValue) . '>';
                     break;
                 case 'radio':
                     $return .= '<input type="radio" name="' . $this->strName . '" id="' . $this->strName . '_' . md5($currentFolder) . '" class="tl_tree_radio" value="' . specialchars($currentFolder) . '" onfocus="Backend.getScrollOffset()"' . $this->optionChecked($currentFolder, $this->varValue) . '>';
                     break;
             }
         }
         $return .= '</div><div style="clear:both"></div></li>';
         // Call the next node
         if ($countFiles > 0 && $blnIsOpen) {
             $return .= '<li class="parent" id="' . $xtnode . '_' . $tid . '"><ul class="level_' . $level . '">';
             $return .= $this->renderFiletree($folders[$f], $intMargin + $intSpacing, false, $protected);
             $return .= '</ul></li>';
         }
     }
     // Process files
     if ($this->files || $this->filesOnly) {
         $allowedExtensions = null;
         if ($this->extensions != '') {
             $allowedExtensions = trimsplit(',', $this->extensions);
         }
         for ($h = 0, $c = count($files); $h < $c; $h++) {
             $thumbnail = '';
             $currentFile = str_replace(TL_ROOT . '/', '', $files[$h]);
             $currentEncoded = $this->urlEncode($currentFile);
             $objFile = new \File($currentFile);
             // Check file extension
             if (is_array($allowedExtensions) && !in_array($objFile->extension, $allowedExtensions)) {
                 continue;
             }
             $return .= "\n    " . '<li class="tl_file toggle_select" onmouseover="Theme.hoverDiv(this, 1)" onmouseout="Theme.hoverDiv(this, 0)"><div class="tl_left" style="padding-left:' . ($intMargin + $intSpacing) . 'px">';
             // Generate thumbnail
             if ($objFile->isImage && $objFile->height > 0) {
                 $thumbnail .= ' <span class="tl_gray">(' . $objFile->width . 'x' . $objFile->height . ')</span>';
                 if (\Config::get('thumbnails') && ($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth'))) {
                     $_height = $objFile->height < 50 ? $objFile->height : 50;
                     $_width = $objFile->width * $_height / $objFile->height > 400 ? 90 : '';
                     $thumbnail .= '<br><img src="' . TL_FILES_URL . \Image::get($currentEncoded, $_width, $_height) . '" alt="" style="margin:0 0 2px -19px">';
                 }
             }
             $return .= \Image::getHtml($objFile->icon, $objFile->mime) . ' ' . utf8_convert_encoding(specialchars(basename($currentFile)), \Config::get('characterSet')) . $thumbnail . '</div> <div class="tl_right">';
             // Add checkbox or radio button
             switch ($this->fieldType) {
                 case 'checkbox':
                     $return .= '<input type="checkbox" name="' . $this->strName . '[]" id="' . $this->strName . '_' . md5($currentFile) . '" class="tl_tree_checkbox" value="' . specialchars($currentFile) . '" onfocus="Backend.getScrollOffset()"' . $this->optionChecked($currentFile, $this->varValue) . '>';
                     break;
                 case 'radio':
                     $return .= '<input type="radio" name="' . $this->strName . '" id="' . $this->strName . '_' . md5($currentFile) . '" class="tl_tree_radio" value="' . specialchars($currentFile) . '" onfocus="Backend.getScrollOffset()"' . $this->optionChecked($currentFile, $this->varValue) . '>';
                     break;
             }
             $return .= '</div><div style="clear:both"></div></li>';
         }
     }
     return $return;
 }