diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-09-03 14:51:41 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-09-12 21:39:01 +0200 |
commit | 650a5f09cbeb1c1bef19810c6cc504c06d5b7e87 (patch) | |
tree | 6be70f1658128246e57d39c73e1bc3b13e992de1 /application | |
parent | e809908f9e593b2cec11f72849caa1dae6394451 (diff) | |
download | Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.tar.gz Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.tar.zst Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.zip |
Add manual configuration for root URL
This new setting under 'general.root_url' allows to override automatic discovery of Shaarli instance's URL.
Fixes #1339
Diffstat (limited to 'application')
-rw-r--r-- | application/feed/FeedBuilder.php | 6 | ||||
-rw-r--r-- | application/http/HttpUtils.php | 8 |
2 files changed, 9 insertions, 5 deletions
diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php index 3653c32f..f6def630 100644 --- a/application/feed/FeedBuilder.php +++ b/application/feed/FeedBuilder.php | |||
@@ -122,9 +122,9 @@ class FeedBuilder | |||
122 | $data['language'] = $this->getTypeLanguage($feedType); | 122 | $data['language'] = $this->getTypeLanguage($feedType); |
123 | $data['last_update'] = $this->getLatestDateFormatted($feedType); | 123 | $data['last_update'] = $this->getLatestDateFormatted($feedType); |
124 | $data['show_dates'] = !$this->hideDates || $this->isLoggedIn; | 124 | $data['show_dates'] = !$this->hideDates || $this->isLoggedIn; |
125 | // Remove leading slash from REQUEST_URI. | 125 | // Remove leading path from REQUEST_URI (already contained in $pageaddr). |
126 | $data['self_link'] = escape(server_url($this->serverInfo)) | 126 | $requestUri = preg_replace('#(.*?/)(feed.*)#', '$2', escape($this->serverInfo['REQUEST_URI'])); |
127 | . escape($this->serverInfo['REQUEST_URI']); | 127 | $data['self_link'] = $pageaddr . $requestUri; |
128 | $data['index_url'] = $pageaddr; | 128 | $data['index_url'] = $pageaddr; |
129 | $data['usepermalinks'] = $this->usePermalinks === true; | 129 | $data['usepermalinks'] = $this->usePermalinks === true; |
130 | $data['links'] = $linkDisplayed; | 130 | $data['links'] = $linkDisplayed; |
diff --git a/application/http/HttpUtils.php b/application/http/HttpUtils.php index 4fc4e3dc..9f414073 100644 --- a/application/http/HttpUtils.php +++ b/application/http/HttpUtils.php | |||
@@ -369,7 +369,11 @@ function server_url($server) | |||
369 | */ | 369 | */ |
370 | function index_url($server) | 370 | function index_url($server) |
371 | { | 371 | { |
372 | $scriptname = $server['SCRIPT_NAME'] ?? ''; | 372 | if (defined('SHAARLI_ROOT_URL') && null !== SHAARLI_ROOT_URL) { |
373 | return rtrim(SHAARLI_ROOT_URL, '/') . '/'; | ||
374 | } | ||
375 | |||
376 | $scriptname = !empty($server['SCRIPT_NAME']) ? $server['SCRIPT_NAME'] : '/'; | ||
373 | if (endsWith($scriptname, 'index.php')) { | 377 | if (endsWith($scriptname, 'index.php')) { |
374 | $scriptname = substr($scriptname, 0, -9); | 378 | $scriptname = substr($scriptname, 0, -9); |
375 | } | 379 | } |
@@ -392,7 +396,7 @@ function page_url($server) | |||
392 | $scriptname = substr($scriptname, 0, -9); | 396 | $scriptname = substr($scriptname, 0, -9); |
393 | } | 397 | } |
394 | 398 | ||
395 | $route = ltrim($server['REQUEST_URI'] ?? '', $scriptname); | 399 | $route = preg_replace('@^' . $scriptname . '@', '', $server['REQUEST_URI'] ?? ''); |
396 | if (! empty($server['QUERY_STRING'])) { | 400 | if (! empty($server['QUERY_STRING'])) { |
397 | return index_url($server) . $route . '?' . $server['QUERY_STRING']; | 401 | return index_url($server) . $route . '?' . $server['QUERY_STRING']; |
398 | } | 402 | } |