public static function getReferer($blnEncodeAmpersands = false, $strTable = null)
{
/** @var SessionInterface $objSession */
$objSession = static::getContainer()->get('session');
$ref = \Input::get('ref');
$key = \Input::get('popup') ? 'popupReferer' : 'referer';
$session = $objSession->get($key);
// Unique referer ID
if ($ref && isset($session[$ref])) {
$session = $session[$ref];
} elseif (TL_MODE == 'BE' && is_array($session)) {
$session = end($session);
}
// Use a specific referer
if ($strTable != '' && isset($session[$strTable]) && \Input::get('act') != 'select') {
$session['current'] = $session[$strTable];
}
// Remove parameters helper
$cleanUrl = function ($url, $params = array('rt', 'ref')) {
if ($url == '' || strpos($url, '?') === false) {
return $url;
}
list($path, $query) = explode('?', $url, 2);
/** @var Query $queryObj */
$queryObj = new Query($query);
$queryObj = $queryObj->without($params);
return $path . $queryObj->getUriComponent();
};
// Determine current or last
$strUrl = $cleanUrl($session['current']) != $cleanUrl(\Environment::get('request')) ? $session['current'] : $session['last'];
// Remove the "toggle" and "toggle all" parameters
$return = $cleanUrl($strUrl, array('tg', 'ptg'));
// Fallback to the generic referer in the front end
if ($return == '' && TL_MODE == 'FE') {
$return = \Environment::get('httpReferer');
}
// Fallback to the current URL if there is no referer
if ($return == '') {
$return = TL_MODE == 'BE' ? 'contao/main.php' : \Environment::get('url');
}
// Do not urldecode here!
return ampersand($return, $blnEncodeAmpersands);
}