mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Started refactor of URL system to better extend Laravel
This commit is contained in:
parent
1e7df28238
commit
30da105812
@ -106,9 +106,7 @@ class LoginController extends Controller
|
||||
$this->ldapService->syncGroups($user, $request->get($this->username()));
|
||||
}
|
||||
|
||||
$path = session()->pull('url.intended', '/');
|
||||
$path = baseUrl($path, true);
|
||||
return redirect($path);
|
||||
return redirect()->intended('/');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Settings\Setting;
|
||||
use BookStack\Settings\SettingService;
|
||||
use BookStack\UrlGenerator;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@ -72,5 +73,10 @@ class AppServiceProvider extends ServiceProvider
|
||||
$this->app->singleton(SettingService::class, function ($app) {
|
||||
return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository'));
|
||||
});
|
||||
|
||||
$this->app->bind(
|
||||
\Illuminate\Contracts\Routing\UrlGenerator::class,
|
||||
UrlGenerator::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
58
app/UrlGenerator.php
Normal file
58
app/UrlGenerator.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace BookStack;
|
||||
|
||||
class UrlGenerator extends \Illuminate\Routing\UrlGenerator
|
||||
{
|
||||
|
||||
/**
|
||||
* Generate an absolute URL to the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param mixed $extra
|
||||
* @param bool|null $secure
|
||||
* @return string
|
||||
*/
|
||||
public function to($path, $extra = [], $secure = null)
|
||||
{
|
||||
$tail = implode('/', array_map(
|
||||
'rawurlencode', (array) $this->formatParameters($extra))
|
||||
);
|
||||
|
||||
$defaultRoot = $this->formatRoot($this->formatScheme($secure));
|
||||
|
||||
list($path, $query) = $this->extractQueryString($path);
|
||||
|
||||
return $this->formatWithBase(
|
||||
$defaultRoot, trim($path.'/'.$tail, '/')
|
||||
).$query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given URL segments into a single URL.
|
||||
*
|
||||
* @param string $defaultRoot
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function formatWithBase($defaultRoot, $path)
|
||||
{
|
||||
$isFullPath = strpos($path, 'http') === 0;
|
||||
$setBasePath = trim(config('app.url'), '/');
|
||||
|
||||
if ($isFullPath) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
if (! empty($setBasePath)) {
|
||||
$defaultRoot = $setBasePath;
|
||||
}
|
||||
|
||||
// TODO - Add mechanism to set path correctly for intended() and back() redirects
|
||||
// TODO - Update tests to align with new system
|
||||
// TODO - Clean up helpers and refactor their usage.
|
||||
|
||||
return trim($defaultRoot. '/' .$path, '/');
|
||||
}
|
||||
|
||||
}
|
@ -112,6 +112,7 @@ function setting($key = null, $default = false)
|
||||
*/
|
||||
function baseUrl($path, $forceAppDomain = false)
|
||||
{
|
||||
return url($path);
|
||||
$isFullUrl = strpos($path, 'http') === 0;
|
||||
if ($isFullUrl && !$forceAppDomain) {
|
||||
return $path;
|
||||
|
Loading…
Reference in New Issue
Block a user