downgrade to kirby v3
This commit is contained in:
@@ -38,6 +38,9 @@ class Home
|
||||
* It will go through the entire menu and
|
||||
* take the first area which is not disabled
|
||||
* or locked in other ways
|
||||
*
|
||||
* @param \Kirby\Cms\User $user
|
||||
* @return string
|
||||
*/
|
||||
public static function alternative(User $user): string
|
||||
{
|
||||
@@ -50,8 +53,7 @@ class Home
|
||||
|
||||
// needed to create a proper menu
|
||||
$areas = Panel::areas();
|
||||
$menu = new Menu($areas, $permissions->toArray());
|
||||
$menu = $menu->entries();
|
||||
$menu = View::menu($areas, $permissions->toArray());
|
||||
|
||||
// go through the menu and search for the first
|
||||
// available view we can go to
|
||||
@@ -66,16 +68,11 @@ class Home
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip buttons that don't open a link
|
||||
// (but e.g. a dialog)
|
||||
if (isset($menuItem['link']) === false) {
|
||||
// skip the logout button
|
||||
if ($menuItem['id'] === 'logout') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip the logout button
|
||||
if ($menuItem['link'] === 'logout') {
|
||||
continue;
|
||||
}
|
||||
|
||||
return Panel::url($menuItem['link']);
|
||||
}
|
||||
@@ -88,6 +85,10 @@ class Home
|
||||
* panel path. This is quite tricky, because we
|
||||
* need to call a trimmed down router to check
|
||||
* for available routes and their firewall status.
|
||||
*
|
||||
* @param \Kirby\Cms\User
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasAccess(User $user, string $path): bool
|
||||
{
|
||||
@@ -106,10 +107,9 @@ class Home
|
||||
// create a dummy router to check if we can access this route at all
|
||||
try {
|
||||
return Router::execute($path, 'GET', $routes, function ($route) use ($user) {
|
||||
$attrs = $route->attributes();
|
||||
$auth = $attrs['auth'] ?? true;
|
||||
$areaId = $attrs['area'] ?? null;
|
||||
$type = $attrs['type'] ?? 'view';
|
||||
$auth = $route->attributes()['auth'] ?? true;
|
||||
$areaId = $route->attributes()['area'] ?? null;
|
||||
$type = $route->attributes()['type'] ?? 'view';
|
||||
|
||||
// only allow redirects to views
|
||||
if ($type !== 'view') {
|
||||
@@ -124,7 +124,7 @@ class Home
|
||||
// check the firewall
|
||||
return Panel::hasAccess($user, $areaId);
|
||||
});
|
||||
} catch (Throwable) {
|
||||
} catch (Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -134,28 +134,35 @@ class Home
|
||||
* as the index URL of the Kirby installation.
|
||||
* This is used to block external URLs to third-party
|
||||
* domains as redirect options.
|
||||
*
|
||||
* @param \Kirby\Http\Uri $uri
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasValidDomain(Uri $uri): bool
|
||||
{
|
||||
$rootUrl = App::instance()->site()->url();
|
||||
$rootUri = new Uri($rootUrl);
|
||||
return $uri->domain() === $rootUri->domain();
|
||||
return $uri->domain() === (new Uri($rootUrl))->domain();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given URL is a Panel Url
|
||||
* Checks if the given URL is a Panel Url.
|
||||
*
|
||||
* @param string $url
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPanelUrl(string $url): bool
|
||||
{
|
||||
$panel = App::instance()->url('panel');
|
||||
return Str::startsWith($url, $panel);
|
||||
return Str::startsWith($url, App::instance()->url('panel'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path after /panel/ which can then
|
||||
* be used in the router or to find a matching view
|
||||
*
|
||||
* @param string $url
|
||||
* @return string|null
|
||||
*/
|
||||
public static function panelPath(string $url): string|null
|
||||
public static function panelPath(string $url): ?string
|
||||
{
|
||||
$after = Str::after($url, App::instance()->url('panel'));
|
||||
return trim($after, '/');
|
||||
@@ -166,16 +173,16 @@ class Home
|
||||
* before the last logout. We take this Url if possible
|
||||
* to redirect the user back to the last point where they
|
||||
* left before they got logged out.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function remembered(): string|null
|
||||
public static function remembered(): ?string
|
||||
{
|
||||
// check for a stored path after login
|
||||
if ($remembered = App::instance()->session()->pull('panel.path')) {
|
||||
// convert the result to an absolute URL if available
|
||||
return Panel::url($remembered);
|
||||
}
|
||||
$remembered = App::instance()->session()->pull('panel.path');
|
||||
|
||||
return null;
|
||||
// convert the result to an absolute URL if available
|
||||
return $remembered ? Panel::url($remembered) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,6 +206,8 @@ class Home
|
||||
* Afterwards, we also check for permissions before the redirect happens
|
||||
* to avoid redirects to inaccessible Panel views. In such a case
|
||||
* the next best accessible view is picked from the menu.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function url(): string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user