Contao\Backend::addFilesBreadcrumb PHP Method

addFilesBreadcrumb() public static method

Add a breadcrumb menu to the file tree
public static addFilesBreadcrumb ( string $strKey = 'tl_files_node' )
$strKey string
    public static function addFilesBreadcrumb($strKey = 'tl_files_node')
    {
        /** @var AttributeBagInterface $objSession */
        $objSession = \System::getContainer()->get('session')->getBag('contao_backend');
        // Set a new node
        if (isset($_GET['fn'])) {
            // Check the path (thanks to Arnaud Buchoux)
            if (\Validator::isInsecurePath(\Input::get('fn', true))) {
                throw new \RuntimeException('Insecure path ' . \Input::get('fn', true));
            }
            $objSession->set($strKey, \Input::get('fn', true));
            \Controller::redirect(preg_replace('/(&|\\?)fn=[^&]*/', '', \Environment::get('request')));
        }
        $strNode = $objSession->get($strKey);
        if ($strNode == '') {
            return;
        }
        // Check the path (thanks to Arnaud Buchoux)
        if (\Validator::isInsecurePath($strNode)) {
            throw new \RuntimeException('Insecure path ' . $strNode);
        }
        // Currently selected folder does not exist
        if (!is_dir(TL_ROOT . '/' . $strNode)) {
            $objSession->set($strKey, '');
            return;
        }
        $objUser = \BackendUser::getInstance();
        $strPath = \Config::get('uploadPath');
        $arrNodes = explode('/', preg_replace('/^' . preg_quote(\Config::get('uploadPath'), '/') . '\\//', '', $strNode));
        $arrLinks = array();
        // Add root link
        $arrLinks[] = \Image::getHtml('filemounts.svg') . ' <a href="' . \Backend::addToUrl('fn=') . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['selectAllNodes']) . '">' . $GLOBALS['TL_LANG']['MSC']['filterAll'] . '</a>';
        // Generate breadcrumb trail
        foreach ($arrNodes as $strFolder) {
            $strPath .= '/' . $strFolder;
            // Do not show pages which are not mounted
            if (!$objUser->hasAccess($strPath, 'filemounts')) {
                continue;
            }
            // No link for the active folder
            if ($strPath == $strNode) {
                $arrLinks[] = \Image::getHtml('folderC.svg') . ' ' . $strFolder;
            } else {
                $arrLinks[] = \Image::getHtml('folderC.svg') . ' <a href="' . \Backend::addToUrl('fn=' . $strPath) . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '">' . $strFolder . '</a>';
            }
        }
        // Check whether the node is mounted
        if (!$objUser->hasAccess($strNode, 'filemounts')) {
            $objSession->set($strKey, '');
            throw new AccessDeniedException('Folder ID "' . $strNode . '" is not mounted');
        }
        // Limit tree
        $GLOBALS['TL_DCA']['tl_files']['list']['sorting']['root'] = array($strNode);
        // Insert breadcrumb menu
        $GLOBALS['TL_DCA']['tl_files']['list']['sorting']['breadcrumb'] .= '

<ul id="tl_breadcrumb">
  <li>' . implode(' &gt; </li><li>', $arrLinks) . '</li>
</ul>';
    }

Usage Example

Esempio n. 1
0
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $this->import('BackendUser', 'User');
       $this->convertValuesToPaths();
       /** @var AttributeBagInterface $objSessionBag */
       $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
       $strNode = $objSessionBag->get('tl_files_picker');
       // Unset the node if it is not within the path (see #5899)
       if ($strNode != '' && $this->path != '') {
           if (strncmp($strNode . '/', $this->path . '/', strlen($this->path) + 1) !== 0) {
               $objSessionBag->remove('tl_files_picker');
           }
       }
       // Add the breadcrumb menu
       if (\Input::get('do') != 'files') {
           \Backend::addFilesBreadcrumb('tl_files_picker');
       }
       $tree = '';
       // Root nodes (breadcrumb menu)
       if (!empty($GLOBALS['TL_DCA']['tl_files']['list']['sorting']['root'])) {
           $nodes = $this->eliminateNestedPaths($GLOBALS['TL_DCA']['tl_files']['list']['sorting']['root']);
           foreach ($nodes as $node) {
               $tree .= $this->renderFiletree(TL_ROOT . '/' . $node, 0, true);
           }
       } elseif ($this->path != '') {
           $protected = true;
           $path = $this->path;
           // Check if the folder is protected (see #287)
           do {
               if (file_exists(TL_ROOT . '/' . $path . '/.public')) {
                   $protected = false;
               }
               $path = dirname($path);
           } while ($path != '.' && $protected !== false);
           $tree .= $this->renderFiletree(TL_ROOT . '/' . $this->path, 0, false, $protected);
       } elseif ($this->User->isAdmin) {
           $tree .= $this->renderFiletree(TL_ROOT . '/' . \Config::get('uploadPath'), 0);
       } else {
           $nodes = $this->eliminateNestedPaths($this->User->filemounts);
           foreach ($nodes as $node) {
               $tree .= $this->renderFiletree(TL_ROOT . '/' . $node, 0, true);
           }
       }
       // Select all checkboxes
       if ($this->fieldType == 'checkbox') {
           $strReset = "\n" . '    <li class="tl_folder"><div class="tl_left">&nbsp;</div> <div class="tl_right"><label for="check_all_' . $this->strId . '" class="tl_change_selected">' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</label> <input type="checkbox" id="check_all_' . $this->strId . '" class="tl_tree_checkbox" value="" onclick="Backend.toggleCheckboxGroup(this,\'' . $this->strName . '\')"></div><div style="clear:both"></div></li>';
       } else {
           $strReset = "\n" . '    <li class="tl_folder"><div class="tl_left">&nbsp;</div> <div class="tl_right"><label for="reset_' . $this->strId . '" class="tl_change_selected">' . $GLOBALS['TL_LANG']['MSC']['resetSelected'] . '</label> <input type="radio" name="' . $this->strName . '" id="reset_' . $this->strName . '" class="tl_tree_radio" value="" onfocus="Backend.getScrollOffset()"></div><div style="clear:both"></div></li>';
       }
       // Return the tree
       return '<ul class="tl_listing tree_view picker_selector' . ($this->strClass != '' ? ' ' . $this->strClass : '') . '" id="' . $this->strId . '">
   <li class="tl_folder_top"><div class="tl_left">' . \Image::getHtml($GLOBALS['TL_DCA']['tl_files']['list']['sorting']['icon'] ?: 'filemounts.gif') . ' ' . (\Config::get('websiteTitle') ?: 'Contao Open Source CMS') . '</div> <div class="tl_right">&nbsp;</div><div style="clear:both"></div></li><li class="parent" id="' . $this->strId . '_parent"><ul>' . $tree . $strReset . '
 </ul></li></ul>';
   }
All Usage Examples Of Contao\Backend::addFilesBreadcrumb