Contao\DC_Folder::showAll PHP Метод

showAll() публичный Метод

List all files and folders of the file system
public showAll ( ) : string
Результат string
    public function showAll()
    {
        $return = '';
        /** @var SessionInterface $objSession */
        $objSession = \System::getContainer()->get('session');
        /** @var AttributeBagInterface $objSessionBag */
        $objSessionBag = $objSession->getBag('contao_backend');
        $session = $objSessionBag->all();
        // Add to clipboard
        if (\Input::get('act') == 'paste') {
            if (\Input::get('mode') != 'create' && \Input::get('mode') != 'move') {
                $this->isValid($this->intId);
            }
            $arrClipboard = $objSession->get('CLIPBOARD');
            $arrClipboard[$this->strTable] = array('id' => $this->urlEncode($this->intId), 'childs' => \Input::get('childs'), 'mode' => \Input::get('mode'));
            $objSession->set('CLIPBOARD', $arrClipboard);
        }
        // Get the session data and toggle the nodes
        if (\Input::get('tg') == 'all') {
            // Expand tree
            if (!is_array($session['filetree']) || empty($session['filetree']) || current($session['filetree']) != 1) {
                $session['filetree'] = $this->getMD5Folders(\Config::get('uploadPath'));
            } else {
                $session['filetree'] = array();
            }
            $objSessionBag->replace($session);
            $this->redirect(preg_replace('/(&(amp;)?|\\?)tg=[^& ]*/i', '', \Environment::get('request')));
        }
        $blnClipboard = false;
        $arrClipboard = $objSession->get('CLIPBOARD');
        // Check clipboard
        if (!empty($arrClipboard[$this->strTable])) {
            $blnClipboard = true;
            $arrClipboard = $arrClipboard[$this->strTable];
        }
        $this->import('Files');
        $this->import('BackendUser', 'User');
        $arrFound = array();
        $for = $session['search'][$this->strTable]['value'];
        // Limit the results by modifying $this->arrFilemounts
        if ($for != '') {
            // Wrap in a try catch block in case the regular expression is invalid (see #7743)
            try {
                $strPattern = "CAST(name AS CHAR) REGEXP ?";
                if (substr(\Config::get('dbCollation'), -3) == '_ci') {
                    $strPattern = "LOWER(CAST(name AS CHAR)) REGEXP LOWER(?)";
                }
                if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields']['name']['foreignKey'])) {
                    list($t, $f) = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields']['name']['foreignKey']);
                    $objRoot = $this->Database->prepare("SELECT path, type, extension FROM {$this->strTable} WHERE (" . $strPattern . " OR " . sprintf($strPattern, "(SELECT {$f} FROM {$t} WHERE {$t}.id={$this->strTable}.name)") . ") GROUP BY path")->execute($for, $for);
                } else {
                    $objRoot = $this->Database->prepare("SELECT path, type, extension FROM {$this->strTable} WHERE " . $strPattern . " GROUP BY path")->execute($for);
                }
                if ($objRoot->numRows < 1) {
                    $this->arrFilemounts = array();
                } else {
                    $arrRoot = array();
                    // Respect existing limitations (root IDs)
                    if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['root'])) {
                        while ($objRoot->next()) {
                            foreach ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['root'] as $root) {
                                if (strncmp($root . '/', $objRoot->path . '/', strlen($root) + 1) === 0) {
                                    if ($objRoot->type == 'folder' || empty($this->arrValidFileTypes) || in_array($objRoot->extension, $this->arrValidFileTypes)) {
                                        $arrFound[] = $objRoot->path;
                                    }
                                    $arrRoot[] = $objRoot->type == 'folder' ? $objRoot->path : dirname($objRoot->path);
                                    continue 2;
                                }
                            }
                        }
                    } else {
                        while ($objRoot->next()) {
                            if ($objRoot->type == 'folder' || empty($this->arrValidFileTypes) || in_array($objRoot->extension, $this->arrValidFileTypes)) {
                                $arrFound[] = $objRoot->path;
                            }
                            $arrRoot[] = $objRoot->type == 'folder' ? $objRoot->path : dirname($objRoot->path);
                        }
                    }
                    $this->arrFilemounts = $this->eliminateNestedPaths(array_unique($arrRoot));
                }
            } catch (\Exception $e) {
            }
        }
        // Call recursive function tree()
        if (empty($this->arrFilemounts) && !is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['root']) && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['root'] !== false) {
            $return .= $this->generateTree(TL_ROOT . '/' . \Config::get('uploadPath'), 0, false, true, $blnClipboard ? $arrClipboard : false, $arrFound);
        } else {
            for ($i = 0, $c = count($this->arrFilemounts); $i < $c; $i++) {
                if ($this->arrFilemounts[$i] != '' && is_dir(TL_ROOT . '/' . $this->arrFilemounts[$i])) {
                    $return .= $this->generateTree(TL_ROOT . '/' . $this->arrFilemounts[$i], 0, true, true, $blnClipboard ? $arrClipboard : false, $arrFound);
                }
            }
        }
        // Check for the "create new" button
        $clsNew = 'header_new_folder';
        $lblNew = $GLOBALS['TL_LANG'][$this->strTable]['new'][0];
        $ttlNew = $GLOBALS['TL_LANG'][$this->strTable]['new'][1];
        $hrfNew = '&amp;act=paste&amp;mode=create';
        if (isset($GLOBALS['TL_DCA'][$this->strTable]['list']['new'])) {
            $clsNew = $GLOBALS['TL_DCA'][$this->strTable]['list']['new']['class'];
            $lblNew = $GLOBALS['TL_DCA'][$this->strTable]['list']['new']['label'][0];
            $ttlNew = $GLOBALS['TL_DCA'][$this->strTable]['list']['new']['label'][1];
            $hrfNew = $GLOBALS['TL_DCA'][$this->strTable]['list']['new']['href'];
        }
        $imagePasteInto = \Image::getHtml('pasteinto.svg', $GLOBALS['TL_LANG'][$this->strTable]['pasteinto'][0]);
        // Build the tree
        $return = $this->panel() . '
<div id="tl_buttons">' . (\Input::get('act') == 'select' ? '
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> ' : '') . (\Input::get('act') != 'select' && !$blnClipboard && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable'] ? '
<a href="' . $this->addToUrl($hrfNew) . '" class="' . $clsNew . '" title="' . \StringUtil::specialchars($ttlNew) . '" accesskey="n" onclick="Backend.getScrollOffset()">' . $lblNew . '</a>
<a href="' . $this->addToUrl('&amp;act=paste&amp;mode=move') . '" class="header_new" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG'][$this->strTable]['move'][1]) . '" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG'][$this->strTable]['move'][0] . '</a> ' : '') . ($blnClipboard ? '
<a href="' . $this->addToUrl('clipboard=1') . '" class="header_clipboard" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['clearClipboard']) . '" accesskey="x">' . $GLOBALS['TL_LANG']['MSC']['clearClipboard'] . '</a> ' : $this->generateGlobalButtons()) . '
</div>' . \Message::generate() . (\Input::get('act') == 'select' ? '

<form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_select" class="tl_form' . (\Input::get('act') == 'select' ? ' unselectable' : '') . '" method="post" novalidate>
<div class="tl_formbody">
<input type="hidden" name="FORM_SUBMIT" value="tl_select">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' : '') . ($session['search'][$this->strTable]['value'] != '' ? '

<div class="tl_message">
 <p class="tl_info">' . $GLOBALS['TL_LANG']['MSC']['searchExclude'] . '</p>
</div>' : '') . ($blnClipboard ? '

<div id="paste_hint">
  <p>' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '</p>
</div>' : '') . '

<div class="tl_listing_container tree_view" id="tl_listing">' . (isset($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['breadcrumb']) ? $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['breadcrumb'] : '') . (\Input::get('act') == 'select' ? '

<div class="tl_select_trigger">
<label for="tl_select_trigger" class="tl_select_label">' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</label> <input type="checkbox" id="tl_select_trigger" onclick="Backend.toggleCheckboxes(this)" class="tl_tree_checkbox">
</div>' : '') . '

<ul class="tl_listing">
  <li class="tl_folder_top cf"><div class="tl_left">' . \Image::getHtml('filemounts.svg') . ' ' . $GLOBALS['TL_LANG']['MSC']['filetree'] . '</div> <div class="tl_right">' . ($blnClipboard && empty($this->arrFilemounts) && !is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['root']) && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['root'] !== false ? '<a href="' . $this->addToUrl('&amp;act=' . $arrClipboard['mode'] . '&amp;mode=2&amp;pid=' . \Config::get('uploadPath') . (!is_array($arrClipboard['id']) ? '&amp;id=' . $arrClipboard['id'] : '')) . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG'][$this->strTable]['pasteinto'][1]) . '" onclick="Backend.getScrollOffset()">' . $imagePasteInto . '</a>' : '&nbsp;') . '</div></li>' . $return . '
</ul>

</div>';
        // Close the form
        if (\Input::get('act') == 'select') {
            // Submit buttons
            $arrButtons = array();
            if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) {
                $arrButtons['edit'] = '<button type="submit" name="edit" id="edit" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['editSelected'] . '</button>';
            }
            if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) {
                $arrButtons['cut'] = '<button type="submit" name="cut" id="cut" class="tl_submit" accesskey="x">' . $GLOBALS['TL_LANG']['MSC']['moveSelected'] . '</button>';
            }
            if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) {
                $arrButtons['copy'] = '<button type="submit" name="copy" id="copy" class="tl_submit" accesskey="c">' . $GLOBALS['TL_LANG']['MSC']['copySelected'] . '</button>';
            }
            if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notDeletable']) {
                $arrButtons['delete'] = '<button type="submit" name="delete" id="delete" class="tl_submit" accesskey="d" onclick="return confirm(\'' . $GLOBALS['TL_LANG']['MSC']['delAllConfirmFile'] . '\')">' . $GLOBALS['TL_LANG']['MSC']['deleteSelected'] . '</button>';
            }
            // Call the buttons_callback (see #4691)
            if (is_array($GLOBALS['TL_DCA'][$this->strTable]['select']['buttons_callback'])) {
                foreach ($GLOBALS['TL_DCA'][$this->strTable]['select']['buttons_callback'] as $callback) {
                    if (is_array($callback)) {
                        $this->import($callback[0]);
                        $arrButtons = $this->{$callback[0]}->{$callback[1]}($arrButtons, $this);
                    } elseif (is_callable($callback)) {
                        $arrButtons = $callback($arrButtons, $this);
                    }
                }
            }
            if (count($arrButtons) < 3) {
                $strButtons = implode(' ', $arrButtons);
            } else {
                $strButtons = array_shift($arrButtons) . ' ';
                $strButtons .= '<div class="split-button">';
                $strButtons .= array_shift($arrButtons) . '<button type="button" id="sbtog">' . \Image::getHtml('navcol.svg') . '</button> <ul class="invisible">';
                foreach ($arrButtons as $strButton) {
                    $strButtons .= '<li>' . $strButton . '</li>';
                }
                $strButtons .= '</ul></div>';
            }
            $return .= '

<div class="tl_formbody_submit" style="text-align:right">

<div class="tl_submit_container">
  ' . $strButtons . '
</div>

</div>
</div>
</form>';
        }
        return $return;
    }