/** * Add a request string to the current URL * * @param string $strRequest The string to be added * * @return string The new URL * * @deprecated Use Controller::addToUrl() instead */ public static function addToUrl($strRequest) { 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') { $objSession = \Session::getInstance(); // 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 ($strPath == $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>'; }
/** * Generate the navigation menu and return it as array * * @param boolean $blnShowAll * * @return array */ public function navigation($blnShowAll = false) { $arrModules = array(); $session = $this->Session->getData(); // 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; $this->Session->setData($session); \Controller::redirect(preg_replace('/(&(amp;)?|\\?)mtg=[^& ]*/i', '', \Environment::get('request'))); } $arrInactiveModules = \ModuleLoader::getDisabled(); $blnCheckInactiveModules = is_array($arrInactiveModules); 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) { // Exclude inactive modules if ($blnCheckInactiveModules && in_array($strModuleName, $arrInactiveModules)) { continue; } // 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; }
/** * Get the paste buttons depending on the layer type. * * @param \DataContainer $dataContainer The dataContainer driver. * @param array $row The data row. * @param string $table The table name. * @param null $whatever Who knows what the purpose of this var is. * @param array $children The child content. * * @return string * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getPasteButtons($dataContainer, $row, $table, $whatever, $children) { $pasteAfterUrl = \Controller::addToUrl('act=' . $children['mode'] . '&mode=1&pid=' . $row['id'] . (!is_array($children['id']) ? '&id=' . $children['id'] : '')); $buffer = sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', $pasteAfterUrl, specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])), \Image::getHtml('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id']))); if (!empty($this->layers[$row['type']]['children'])) { $pasteIntoUrl = \Controller::addToUrl(sprintf('act=%s&mode=2&pid=%s%s', $children['mode'], $row['id'], !is_array($children['id']) ? '&id=' . $children['id'] : '')); $buffer .= sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', $pasteIntoUrl, specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id'])), \Image::getHtml('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id']))); } elseif ($row['id'] > 0) { $buffer .= \Image::getHtml('pasteinto_.gif'); } return $buffer; }
/** * 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 breadcrumb menu to the page tree * * @return string */ protected static function getPagesBreadcrumb() { $session = \Session::getInstance()->getData(); // Set a new gid if (isset($_GET['page'])) { $session['filter']['tl_iso_product']['iso_page'] = (int) \Input::get('page'); \Session::getInstance()->setData($session); \Controller::redirect(preg_replace('/&page=[^&]*/', '', \Environment::get('request'))); } $intNode = $session['filter']['tl_iso_product']['iso_page']; if ($intNode < 1) { return ''; } $arrIds = array(); $arrLinks = array(); /** @var \BackendUser $objUser */ $objUser = \BackendUser::getInstance(); // Generate breadcrumb trail if ($intNode) { $intId = $intNode; $objDatabase = \Database::getInstance(); do { $objPage = $objDatabase->prepare("SELECT * FROM tl_page WHERE id=?")->limit(1)->execute($intId); if ($objPage->numRows < 1) { // Currently selected page does not exits if ($intId == $intNode) { $session['filter']['tl_iso_product']['iso_page'] = 0; \Session::getInstance()->setData($session); return ''; } break; } $arrIds[] = $intId; // No link for the active page if ($objPage->id == $intNode) { $arrLinks[] = \Backend::addPageIcon($objPage->row(), '', null, '', true) . ' ' . $objPage->title; } else { $arrLinks[] = \Backend::addPageIcon($objPage->row(), '', null, '', true) . ' <a href="' . \Controller::addToUrl('page=' . $objPage->id) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '">' . $objPage->title . '</a>'; } // Do not show the mounted pages if (!$objUser->isAdmin && $objUser->hasAccess($objPage->id, 'pagemounts')) { break; } $intId = $objPage->pid; } while ($intId > 0 && $objPage->type != 'root'); } // Check whether the node is mounted if (!$objUser->isAdmin && !$objUser->hasAccess($arrIds, 'pagemounts')) { $session['filter']['tl_iso_product']['iso_page'] = 0; \Session::getInstance()->setData($session); \System::log('Page ID ' . $intNode . ' was not mounted', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } // Limit tree $GLOBALS['TL_DCA']['tl_page']['list']['sorting']['root'] = array($intNode); // Add root link $arrLinks[] = '<img src="' . TL_FILES_URL . 'system/themes/' . \Backend::getTheme() . '/images/pagemounts.gif" width="18" height="18" alt=""> <a href="' . \Controller::addToUrl('page=0') . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectAllNodes']) . '">' . $GLOBALS['TL_LANG']['MSC']['filterAll'] . '</a>'; $arrLinks = array_reverse($arrLinks); // Insert breadcrumb menu return ' <ul id="tl_breadcrumb"> <li>' . implode(' > </li><li>', $arrLinks) . '</li> </ul>'; }
/** * Add and remove parameters from the current url. * * @param string|array $parameters Array of parameters to set. * * @param bool $addRefererId Flag if the referer token shall be added to the url. * * @param array $unsetParameters Array of parameters that shall be unset. * * @return string * * @SuppressWarnings(PHPMD.CamelCaseMethodName) * @codingStandardsIgnoreStart */ public function _addToUrl($parameters, $addRefererId = true, $unsetParameters = array()) { if (is_array($parameters)) { $parameters = http_build_query($parameters); } if (TL_MODE == 'BE') { return \Backend::addToUrl($parameters, $addRefererId, $unsetParameters); } return \Controller::addToUrl($parameters, $addRefererId, $unsetParameters); }
/** * Add the request token to the URL * @param string * @return string */ public static function addToUrl($strRequest) { return parent::addToUrl($strRequest . ($strRequest != '' ? '&' : '') . 'rt=' . REQUEST_TOKEN); }
/** * Generate the widget and return it as string * @return string */ public function generate() { $this->import('BackendUser', 'User'); // Store the keyword if (\Input::post('FORM_SUBMIT') == 'item_selector') { $this->Session->set($this->getSearchSessionKey(), \Input::post('keyword')); $this->reload(); } $tree = ''; $this->getPathNodes(); $for = $this->Session->get($this->getSearchSessionKey()); $arrIds = array(); // Search for a specific item if ($for != '' && $this->searchField) { // The keyword must not start with a wildcard if (strncmp($for, '*', 1) === 0) { $for = substr($for, 1); } $objRoot = $this->Database->prepare("SELECT id FROM " . $this->foreignTable . " WHERE CAST(" . $this->searchField . " AS CHAR) REGEXP ?")->execute($for); if ($objRoot->numRows > 0) { // Respect existing limitations if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['rootNodes'])) { $arrRoot = array(); while ($objRoot->next()) { // Predefined node set if (count(array_intersect($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['rootNodes'], $this->Database->getParentRecords($objRoot->id, $this->foreignTable))) > 0) { $arrRoot[] = $objRoot->id; } } $arrIds = $arrRoot; } else { $arrIds = $objRoot->fetchEach('id'); } } // Build the tree foreach ($arrIds as $id) { $tree .= $this->renderItemTree($id, -20, true); } } else { $strNode = $this->Session->get($this->getPickerSessionKey()); // Unset the node if it is not within the predefined node set if ($strNode > 0 && is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['rootNodes'])) { if (!in_array($strNode, $this->Database->getChildRecords($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['rootNodes'], $this->foreignTable))) { $this->Session->remove($this->getPickerSessionKey()); } } // Set a new node if (isset($_GET['node'])) { $this->Session->set($this->getPickerSessionKey(), \Input::get('node')); \Controller::redirect(preg_replace('/&node=[^&]*/', '', \Environment::get('request'))); } $intNode = $this->Session->get($this->getPickerSessionKey()); // Add breadcrumb menu if ($intNode) { $arrIds = array(); $arrLinks = array(); // Generate breadcrumb trail if ($intNode) { $intId = $intNode; do { $objItem = $this->Database->prepare("SELECT * FROM " . $this->foreignTable . " WHERE id=?")->limit(1)->execute($intId); if ($objItem->numRows < 1) { // Currently selected item does not exist if ($intId == $intNode) { $this->Session->set($this->getPickerSessionKey(), 0); return; } break; } $arrIds[] = $intId; // No link for the active item if ($objItem->id == $intNode) { $arrLinks[] = TreePickerHelper::generateItemLabel($objItem, $this->foreignTable, $this->objDca, $this->titleField); } else { $arrLinks[] = '<a href="' . \Controller::addToUrl('node=' . $objItem->id) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '">' . TreePickerHelper::generateItemLabel($objItem, $this->foreignTable, $this->objDca, $this->titleField) . '</a>'; } $intId = $objItem->pid; } while ($intId > 0); } // Limit tree $GLOBALS['TL_DCA'][$this->foreignTable]['list']['sorting']['root'] = array($intNode); // Add root link $arrLinks[] = \Image::getHtml($GLOBALS['TL_DCA'][$this->foreignTable]['list']['sorting']['icon'] ?: 'iconPLAIN.gif') . ' <a href="' . \Controller::addToUrl('node=0') . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['selectAllNodes']) . '">' . $GLOBALS['TL_LANG']['MSC']['filterAll'] . '</a>'; $arrLinks = array_reverse($arrLinks); // Insert breadcrumb menu $GLOBALS['TL_DCA'][$this->foreignTable]['list']['sorting']['breadcrumb'] .= ' <ul id="tl_breadcrumb"> <li>' . implode(' > </li><li>', $arrLinks) . '</li> </ul>'; } // Root nodes (breadcrumb menu) if (!empty($GLOBALS['TL_DCA'][$this->foreignTable]['list']['sorting']['root'])) { $tree = $this->renderItemTree($GLOBALS['TL_DCA'][$this->foreignTable]['list']['sorting']['root'][0], -20); } elseif (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['rootNodes'])) { foreach ($this->eliminateNestedPages($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['rootNodes'], $this->foreignTable) as $node) { $tree .= $this->renderItemTree($node, -20); } } else { $objItem = $this->Database->prepare("SELECT id FROM " . $this->foreignTable . " WHERE pid=? ORDER BY sorting")->execute(0); while ($objItem->next()) { $tree .= $this->renderItemTree($objItem->id, -20); } } } // Select all checkboxes if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['fieldType'] == 'checkbox') { $strReset = "\n" . ' <li class="tl_folder"><div class="tl_left"> </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"> </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'][$this->foreignTable]['list']['sorting']['icon'] ?: 'iconPLAIN.gif') . ' ' . ($GLOBALS['TL_DCA'][$this->foreignTable]['config']['label'] ?: $GLOBALS['TL_CONFIG']['websiteTitle']) . '</div> <div class="tl_right"> </div><div style="clear:both"></div></li><li class="parent" id="' . $this->strId . '_parent"><ul>' . $tree . $strReset . ' </ul></li></ul>'; }