dedupe BASE_URL / BASE_HREF

This commit is contained in:
Shish
2020-02-01 22:26:08 +00:00
parent e9ab6aa802
commit ce8da04d3a
5 changed files with 50 additions and 13 deletions

View File

@@ -31,6 +31,6 @@ _d("WH_SPLITS", 1); // int how many levels of subfolders to put in
_d("VERSION", '2.8-dev'); // string shimmie version
_d("TIMEZONE", null); // string timezone
_d("EXTRA_EXTS", ""); // string optional extra extensions
_d("BASE_URL", null); // string force a specific base URL (default is auto-detect)
_d("BASE_HREF", null); // string force a specific base URL (default is auto-detect)
_d("TRACE_FILE", null); // string file to log performance data into
_d("TRACE_THRESHOLD", 0.0); // float log pages which take more time than this many seconds

39
core/tests/urls.test.php Normal file
View File

@@ -0,0 +1,39 @@
<?php declare(strict_types=1);
require_once "core/urls.php";
class UrlsTest extends \PHPUnit\Framework\TestCase
{
public function test_make_link()
{
$this->assertEquals(
"/test/foo",
make_link("foo")
);
$this->assertEquals(
"/test/foo",
make_link("/foo")
);
}
public function test_make_http()
{
// relative to shimmie install
$this->assertEquals(
"http://<cli command>/test/foo",
make_http("foo")
);
// relative to web server
$this->assertEquals(
"http://<cli command>/foo",
make_http("/foo")
);
// absolute
$this->assertEquals(
"http://foo.com",
make_http("http://foo.com")
);
}
}

View File

@@ -34,12 +34,11 @@ function make_link(?string $page=null, ?string $query=null): string
$page = $config->get_string(SetupConfig::MAIN_PAGE);
}
if (!is_null(BASE_URL)) {
$base = BASE_URL;
} elseif (NICE_URLS || $config->get_bool('nice_urls', false)) {
$base = str_replace('/'.basename($_SERVER["SCRIPT_FILENAME"]), "", $_SERVER["PHP_SELF"]);
$install_dir = get_base_href();
if (NICE_URLS || $config->get_bool('nice_urls', false)) {
$base = $install_dir;
} else {
$base = "./".basename($_SERVER["SCRIPT_FILENAME"])."?q=";
$base = "$install_dir/index.php?q=";
}
if (is_null($query)) {