diff --git a/composer.json b/composer.json index cd49614..1ddc43e 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,12 @@ { "name": "afbora/kirby-loader", "description": "Plugins loader from multiple roots for Kirby", - "keywords": [], - "version": "2.2.0", + "keywords": [ + "kirby3", + "kirby4", + "kirby5" + ], + "version": "2.3.0", "type": "kirby-plugin", "license": "MIT", "homepage": "https://github.com/afbora/kirby-loader", diff --git a/src/Loader.php b/src/Loader.php index 1542b60..fb67bf4 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -46,9 +46,12 @@ protected function pluginsLoader(string $root): void } } - protected function readDir(string $root = null): bool + protected function readDir(?string $root = null): bool { - if (empty($root) === true|| in_array(substr(basename($root), 0, 1), ['.', '..']) === true) { + if ( + $root === null || + in_array(substr(basename($root), 0, 1), ['.', '..']) === true + ) { return false; } @@ -58,7 +61,7 @@ protected function readDir(string $root = null): bool $dirname = basename($root); - $entry = $root . DIRECTORY_SEPARATOR . 'index.php'; + $entry = $root . DIRECTORY_SEPARATOR . 'index.php'; $script = $root . DIRECTORY_SEPARATOR . 'index.js'; $styles = $root . DIRECTORY_SEPARATOR . 'index.css'; @@ -74,14 +77,18 @@ protected function readDir(string $root = null): bool return true; } - protected function getRootPath(string $root = null): string + protected function getRootPath(?string $root = null): string { - $index = kirby()->root(); - - if (is_dir($root) === false && strpos($root, $index) === false) { - $root = $index . DIRECTORY_SEPARATOR . ltrim($root, DIRECTORY_SEPARATOR); + $baseRoot = App::instance()->root(); + + if ( + $root !== null && + is_dir($root) === false && + strpos($root, $baseRoot) === false + ) { + return $baseRoot . DIRECTORY_SEPARATOR . ltrim($root, DIRECTORY_SEPARATOR); } - return $root; + return $baseRoot; } }