Skip to content
Snippets Groups Projects
Commit 3bb85582 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch 'F13562ConfigDefaultBaseUrlNewPlace' into 'develop'

B13562. Place to set default from baseUrl is now changed from DatabaseUpdate...

See merge request !384
parents 9c3389ff 1d03a278
No related branches found
No related tags found
2 merge requests!403Button is seperated in own div with class row and col-md-12. Now it will be...,!384B13562. Place to set default from baseUrl is now changed from DatabaseUpdate...
Pipeline #6654 failed
......@@ -669,5 +669,43 @@ class OnString {
}
return $value;
}
/*
* Check the given $url for ending with a index.php or a query or an anker.
* If one of them found: remove it.
* Return cleaned $url
*/
public static function urlStripFile($url) {
if ($url == '') {
return '';
}
// Take care all %dd are replaced by real characters
$url = urldecode($url);
// Explode to examine last part
$arr = explode('/', $url);
$last = count($arr) - 1;
if ($arr[$last] == '') {
unset($arr[$last]);
$last--;
}
if ($last < 1) {
return $url;
}
// Last component starts with 'index.php' or contains a '?' or '#' - that's likely not to be a part of baserurl
if (0 == strcmp('index.php', substr($arr[$last], 0, 9)) ||
strpos($arr[$last], '?') !== false || strpos($arr[$last], '#') !== false) {
unset($arr[$last]);
}
return implode('/', $arr);
}
}
......@@ -15,6 +15,7 @@ use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\OnString;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Typo3\T3Handler;
/**
* Class Config
......@@ -98,6 +99,14 @@ class Config {
$config = array_merge($configT3qfq, $config);
}
// Set default from baseUrl if not given
if ($config[SYSTEM_BASE_URL] === '') {
$config[SYSTEM_BASE_URL] = OnString::urlStripFile($_SERVER["SCRIPT_URI"]);
T3Handler::updateT3QfqConfig(SYSTEM_BASE_URL, $config[SYSTEM_BASE_URL]); // Legacy behaviour.
}
$config = self::renameConfigElements($config);
$config = self::setDefaults($config);
self::checkDeprecated($config);
......
......@@ -295,4 +295,25 @@ class OnStringTest extends TestCase {
$this->assertEquals('SELECT', OnString::removeLeadingBrace(" ( ( SELECT"));
}
public function testUrlStripFile() {
$this->assertEquals('', OnString::urlStripFile(""));
$this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com"));
$this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/index.php"));
$this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/index.php?id=100"));
$this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/?id=100"));
$this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/#new"));
$this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/help#new"));
$this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/index.php?help#new"));
$this->assertEquals('http://www.example.com', OnString::urlStripFile("http://www.example.com/help#new"));
$this->assertEquals('http://www.example.com:9090', OnString::urlStripFile("http://www.example.com:9090/help#new"));
$this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub"));
$this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/"));
$this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/?id=1"));
$this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/index.php"));
$this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/index.php?id=1"));
$this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/index.php?id=1#freak"));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment