Skip to content

Commit

Permalink
v2.3.0: Add Kirby 4 and Kirby 5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Jan 22, 2025
1 parent 0e3695e commit 2a8db16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
25 changes: 16 additions & 9 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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';

Expand All @@ -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;
}
}

0 comments on commit 2a8db16

Please sign in to comment.