comparison Options.inc.php @ 135:2fe6713ccd64

Added functionality for storing an internal Url.
author Tom Fredrik Blenning <bfg@bfgconsult.no>
date Mon, 23 Jan 2023 00:16:26 +0100
parents b6b4a58c7625
children
comparison
equal deleted inserted replaced
134:b6b4a58c7625 135:2fe6713ccd64
22 private $cache; 22 private $cache;
23 private $urlParams = array(); 23 private $urlParams = array();
24 private $basePath; 24 private $basePath;
25 private $flagUrl; 25 private $flagUrl;
26 private $baseUrl; 26 private $baseUrl;
27 private $internalUrl;
27 private $cacheable = Cacheable::YES; 28 private $cacheable = Cacheable::YES;
28 29
29 /** 30 /**
30 * Gets the default language 31 * Gets the default language
31 * 32 *
84 85
85 return "//" . $_SERVER['HTTP_HOST'] . $base; 86 return "//" . $_SERVER['HTTP_HOST'] . $base;
86 } 87 }
87 88
88 /** 89 /**
90 * Get the internal url, or if non set, use external
91 *
92 * @return the internal url
93 */
94 function getInternalUrl()
95 {
96 if ($this->internalUrl)
97 return $this->internalUrl;
98 else
99 return $this->getBaseUrl();
100 }
101
102 /**
103 * Get the internal url, or if non set, use external
104 *
105 * @return the internal url
106 */
107 function getInternalFromExternal($location, $baseUrl)
108 {
109 if ($this->internalUrl && str_starts_with($location, $baseUrl)) {
110 $str=substr($location, strlen($baseUrl));
111 return $this->getInternalUrl().$str;
112 }
113 return $location;
114 }
115
116 /**
89 * Replaces placeholder variables, with actual values. 117 * Replaces placeholder variables, with actual values.
90 * 118 *
91 * Currently supported values: 119 * Currently supported values:
92 * @li \%HOST\% 120 * @li \%HOST\%
93 * 121 *
107 */ 135 */
108 function setBaseUrl($baseUrl) 136 function setBaseUrl($baseUrl)
109 { 137 {
110 $baseUrl = self::replacePlaceholders($baseUrl); 138 $baseUrl = self::replacePlaceholders($baseUrl);
111 $this->baseUrl = $baseUrl; 139 $this->baseUrl = $baseUrl;
140 }
141
142 /**
143 * Sets the internal url which can be used if the server is hosted
144 * behind a proxy
145 *
146 * @param $internalUrl url accessible by internal network
147 */
148 function setInternalUrl($internalUrl)
149 {
150 $this->internalUrl = $internalUrl;
112 } 151 }
113 152
114 /** 153 /**
115 * Sets the url for the flag script 154 * Sets the url for the flag script
116 * 155 *
282 } 321 }
283 elseif ($id == "flagUrl") { 322 elseif ($id == "flagUrl") {
284 $value = $param->getAttribute("value"); 323 $value = $param->getAttribute("value");
285 if($value) 324 if($value)
286 $this->setFlagUrl($value); 325 $this->setFlagUrl($value);
326 }
327 elseif ($id == "internalUrl") {
328 $value = $param->getAttribute("value");
329 if($value)
330 $this->setInternalUrl($value);
287 } 331 }
288 else { 332 else {
289 warn("Invalid option: ${id}"); 333 warn("Invalid option: ${id}");
290 } 334 }
291 //We need to iterate in the opposite direction when removing, 335 //We need to iterate in the opposite direction when removing,