Safe way to get the panel url?

For my Notifier Plugin I wrote a PHP-function that got the active URI-scheme for the panel.

The output was matched to the folder-preference in the config-file, so the plugin “knew” the panel-dir was active…

config.php


function activeDIR($url)
  {
substr($url,-1) != '/'?$url.= '/':$url = $url;
$path = parse_url($url, PHP_URL_PATH);
$pathTrimmed = trim($path, '/');
$pathTokens = explode('/', $pathTrimmed);

  if (substr($path, -1) !== '/')
    {
  array_pop($pathTokens);
    }

return end($pathTokens);
  }

if(c::get('kirbyNotifierPanel') == activeDIR($_SERVER['REQUEST_URI']))
{
/* panel is active */
}