Skip to content

Commit 45549c5

Browse files
committed
Added check for existing folders
1 parent 8a63551 commit 45549c5

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Kirby Route Protect plugin
44

5-
A [Kirby](https://getkirby.com) plugin, protecting panel user from creating page URL in conflict with routes.
5+
A [Kirby](https://getkirby.com) plugin, protecting panel user from creating page URL in conflict with routes and existing folders.
66

77
**Version tested:** 3.9.0, 4.0.1, 5.0.4
88

@@ -26,6 +26,8 @@ The plugin automatically picks all routes in the project, both custom and Kirby
2626
],
2727
]
2828
];
29+
30+
As of `v1.2.0`, the plugin also checks for existing folders.
2931

3032

3133
## Disclaimer

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "andreasnymark/kirby-route-protect",
3-
"description": "Protect panel user from creating page URL in conflict with routes.",
3+
"description": "Protect panel user from creating page URL in conflict with routes and existing folders.",
44
"homepage": "https://github.com/andreasnymark/kirby-route-protect",
5-
"version": "1.1.0",
5+
"version": "1.2.0",
66
"license": "MIT",
77
"type": "kirby-plugin",
88
"authors": [

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'en' => [
1313
'andreasnymark.kirby-route-protect.array' => 'Protected route names needs to be in an array.',
1414
'andreasnymark.kirby-route-protect.protected' => 'The URL-appendix is protected or already in use.',
15+
'andreasnymark.kirby-route-protect.exists' => 'A folder already exists at this URL.',
1516
],
1617
],
1718
]);

route-protect.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
break;
2525
}
2626

27+
// check if a folder exists at this path
28+
$folderPath = kirby()->root( 'index' ) . '/' . $check;
29+
if ( Dir::exists( $folderPath ) ) {
30+
throw new Exception( t( 'andreasnymark.kirby-route-protect.exists', 'A folder already exists at this URL.' ) );
31+
}
32+
2733
// loop through all existing routes and store full patterns
2834
foreach ( kirby()->routes() as $route ) {
2935
$pattern = $route[ 'pattern' ];

0 commit comments

Comments
 (0)