Skip to content

Commit 2a8db16

Browse files
committed
v2.3.0: Add Kirby 4 and Kirby 5 compatibility
1 parent 0e3695e commit 2a8db16

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "afbora/kirby-loader",
33
"description": "Plugins loader from multiple roots for Kirby",
4-
"keywords": [],
5-
"version": "2.2.0",
4+
"keywords": [
5+
"kirby3",
6+
"kirby4",
7+
"kirby5"
8+
],
9+
"version": "2.3.0",
610
"type": "kirby-plugin",
711
"license": "MIT",
812
"homepage": "https://github.com/afbora/kirby-loader",

src/Loader.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ protected function pluginsLoader(string $root): void
4646
}
4747
}
4848

49-
protected function readDir(string $root = null): bool
49+
protected function readDir(?string $root = null): bool
5050
{
51-
if (empty($root) === true|| in_array(substr(basename($root), 0, 1), ['.', '..']) === true) {
51+
if (
52+
$root === null ||
53+
in_array(substr(basename($root), 0, 1), ['.', '..']) === true
54+
) {
5255
return false;
5356
}
5457

@@ -58,7 +61,7 @@ protected function readDir(string $root = null): bool
5861

5962
$dirname = basename($root);
6063

61-
$entry = $root . DIRECTORY_SEPARATOR . 'index.php';
64+
$entry = $root . DIRECTORY_SEPARATOR . 'index.php';
6265
$script = $root . DIRECTORY_SEPARATOR . 'index.js';
6366
$styles = $root . DIRECTORY_SEPARATOR . 'index.css';
6467

@@ -74,14 +77,18 @@ protected function readDir(string $root = null): bool
7477
return true;
7578
}
7679

77-
protected function getRootPath(string $root = null): string
80+
protected function getRootPath(?string $root = null): string
7881
{
79-
$index = kirby()->root();
80-
81-
if (is_dir($root) === false && strpos($root, $index) === false) {
82-
$root = $index . DIRECTORY_SEPARATOR . ltrim($root, DIRECTORY_SEPARATOR);
82+
$baseRoot = App::instance()->root();
83+
84+
if (
85+
$root !== null &&
86+
is_dir($root) === false &&
87+
strpos($root, $baseRoot) === false
88+
) {
89+
return $baseRoot . DIRECTORY_SEPARATOR . ltrim($root, DIRECTORY_SEPARATOR);
8390
}
8491

85-
return $root;
92+
return $baseRoot;
8693
}
8794
}

0 commit comments

Comments
 (0)