/** * Generate the navigation menu and return it as array * * @param boolean $blnShowAll * * @return array */ public function navigation($blnShowAll = false) { /** @var AttributeBagInterface $objSessionBag */ $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend'); $arrModules = array(); $session = $objSessionBag->all(); // Toggle nodes if (\Input::get('mtg')) { $session['backend_modules'][\Input::get('mtg')] = isset($session['backend_modules'][\Input::get('mtg')]) && $session['backend_modules'][\Input::get('mtg')] == 0 ? 1 : 0; $objSessionBag->replace($session); \Controller::redirect(preg_replace('/(&(amp;)?|\\?)mtg=[^& ]*/i', '', \Environment::get('request'))); } foreach ($GLOBALS['BE_MOD'] as $strGroupName => $arrGroupModules) { if (!empty($arrGroupModules) && ($strGroupName == 'system' || $this->hasAccess(array_keys($arrGroupModules), 'modules'))) { $arrModules[$strGroupName]['icon'] = 'modMinus.gif'; $arrModules[$strGroupName]['title'] = specialchars($GLOBALS['TL_LANG']['MSC']['collapseNode']); $arrModules[$strGroupName]['label'] = ($label = is_array($GLOBALS['TL_LANG']['MOD'][$strGroupName]) ? $GLOBALS['TL_LANG']['MOD'][$strGroupName][0] : $GLOBALS['TL_LANG']['MOD'][$strGroupName]) != false ? $label : $strGroupName; $arrModules[$strGroupName]['href'] = \Controller::addToUrl('mtg=' . $strGroupName); // Do not show the modules if the group is closed if (!$blnShowAll && isset($session['backend_modules'][$strGroupName]) && $session['backend_modules'][$strGroupName] < 1) { $arrModules[$strGroupName]['modules'] = false; $arrModules[$strGroupName]['icon'] = 'modPlus.gif'; $arrModules[$strGroupName]['title'] = specialchars($GLOBALS['TL_LANG']['MSC']['expandNode']); } else { foreach ($arrGroupModules as $strModuleName => $arrModuleConfig) { // Check access if ($strModuleName == 'undo' || $this->hasAccess($strModuleName, 'modules')) { $arrModules[$strGroupName]['modules'][$strModuleName] = $arrModuleConfig; $arrModules[$strGroupName]['modules'][$strModuleName]['title'] = specialchars($GLOBALS['TL_LANG']['MOD'][$strModuleName][1]); $arrModules[$strGroupName]['modules'][$strModuleName]['label'] = ($label = is_array($GLOBALS['TL_LANG']['MOD'][$strModuleName]) ? $GLOBALS['TL_LANG']['MOD'][$strModuleName][0] : $GLOBALS['TL_LANG']['MOD'][$strModuleName]) != false ? $label : $strModuleName; $arrModules[$strGroupName]['modules'][$strModuleName]['icon'] = !empty($arrModuleConfig['icon']) ? sprintf(' style="background-image:url(\'%s%s\')"', TL_ASSETS_URL, $arrModuleConfig['icon']) : ''; $arrModules[$strGroupName]['modules'][$strModuleName]['class'] = 'navigation ' . $strModuleName; $arrModules[$strGroupName]['modules'][$strModuleName]['href'] = TL_SCRIPT . '?do=' . $strModuleName . '&ref=' . TL_REFERER_ID; // Mark the active module and its group if (\Input::get('do') == $strModuleName) { $arrModules[$strGroupName]['class'] = ' trail'; $arrModules[$strGroupName]['modules'][$strModuleName]['class'] .= ' active'; } } } } } } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getUserNavigation']) && is_array($GLOBALS['TL_HOOKS']['getUserNavigation'])) { foreach ($GLOBALS['TL_HOOKS']['getUserNavigation'] as $callback) { $this->import($callback[0]); $arrModules = $this->{$callback[0]}->{$callback[1]}($arrModules, $blnShowAll); } } return $arrModules; }
/** * Add the request token to the URL * * @param string $strRequest * @param boolean $blnAddRef * @param array $arrUnset * * @return string */ public static function addToUrl($strRequest, $blnAddRef = true, $arrUnset = array()) { // Unset the "no back button" flag $arrUnset[] = 'nb'; return parent::addToUrl($strRequest . ($strRequest != '' ? '&' : '') . 'rt=' . REQUEST_TOKEN, $blnAddRef, $arrUnset); }
/** * Add some suffix to the current URL. * * @param AddToUrlEvent $event The event. * * @return void */ public static function handleAddToUrl(AddToUrlEvent $event) { $event->setUrl(Controller::addToUrl($event->getSuffix())); }
/** * Add a request string to the current URL * * @param string $strRequest The string to be added * * @return string The new URL * * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0. * Use Controller::addToUrl() instead. */ public static function addToUrl($strRequest) { @trigger_error('Using System::addToUrl() has been deprecated and will no longer work in Contao 5.0. Use Controller::addToUrl() instead.', E_USER_DEPRECATED); return \Controller::addToUrl($strRequest); }
/** * Add a breadcrumb menu to the file tree * * @param string $strKey * * @throws \RuntimeException */ 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['node'])) { // Check the path (thanks to Arnaud Buchoux) if (\Validator::isInsecurePath(\Input::get('node', true))) { throw new \RuntimeException('Insecure path ' . \Input::get('node', true)); } $objSession->set($strKey, \Input::get('node', true)); \Controller::redirect(preg_replace('/(&|\\?)node=[^&]*/', '', \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[] = '<img src="' . TL_FILES_URL . 'system/themes/' . \Backend::getTheme() . '/images/filemounts.gif" width="18" height="18" alt=""> <a href="' . \Controller::addToUrl('node=') . '" title="' . 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 ($strFolder == basename($strNode)) { $arrLinks[] = '<img src="' . TL_FILES_URL . 'system/themes/' . \Backend::getTheme() . '/images/folderC.gif" width="18" height="18" alt=""> ' . $strFolder; } else { $arrLinks[] = '<img src="' . TL_FILES_URL . 'system/themes/' . \Backend::getTheme() . '/images/folderC.gif" width="18" height="18" alt=""> <a href="' . \Controller::addToUrl('node=' . $strPath) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '">' . $strFolder . '</a>'; } } // Check whether the node is mounted if (!$objUser->hasAccess($strNode, 'filemounts')) { $objSession->set($strKey, ''); \System::log('Folder ID ' . $strNode . ' was not mounted', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } // 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(' > </li><li>', $arrLinks) . '</li> </ul>'; }