# HG changeset patch # User Tom Fredrik Blenning # Date 1674429386 -3600 # Node ID 2fe6713ccd64fe93b34311d855579bbd375cba21 # Parent b6b4a58c762596207c7a8233f199bb737772d295 Added functionality for storing an internal Url. diff -r b6b4a58c7625 -r 2fe6713ccd64 Options.inc.php --- a/Options.inc.php Sun Jan 22 19:22:00 2023 +0100 +++ b/Options.inc.php Mon Jan 23 00:16:26 2023 +0100 @@ -24,6 +24,7 @@ private $basePath; private $flagUrl; private $baseUrl; + private $internalUrl; private $cacheable = Cacheable::YES; /** @@ -86,6 +87,33 @@ } /** + * Get the internal url, or if non set, use external + * + * @return the internal url + */ + function getInternalUrl() + { + if ($this->internalUrl) + return $this->internalUrl; + else + return $this->getBaseUrl(); + } + + /** + * Get the internal url, or if non set, use external + * + * @return the internal url + */ + function getInternalFromExternal($location, $baseUrl) + { + if ($this->internalUrl && str_starts_with($location, $baseUrl)) { + $str=substr($location, strlen($baseUrl)); + return $this->getInternalUrl().$str; + } + return $location; + } + + /** * Replaces placeholder variables, with actual values. * * Currently supported values: @@ -112,6 +140,17 @@ } /** + * Sets the internal url which can be used if the server is hosted + * behind a proxy + * + * @param $internalUrl url accessible by internal network + */ + function setInternalUrl($internalUrl) + { + $this->internalUrl = $internalUrl; + } + + /** * Sets the url for the flag script * * @param $flagUrl for flag script @@ -285,6 +324,11 @@ if($value) $this->setFlagUrl($value); } + elseif ($id == "internalUrl") { + $value = $param->getAttribute("value"); + if($value) + $this->setInternalUrl($value); + } else { warn("Invalid option: ${id}"); }