Skip to content

Commit 3d0142a

Browse files
committed
use foreach instead to allow $uri/$params to be accessible from within plugins
1 parent 09e1dd2 commit 3d0142a

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

index.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
* @license MIT public license
77
*/
88

9-
set_exception_handler(fn() => exit('<style>body{font-family:monospace;color:#fff;font-size:2em;background:#444;padding:5em;text-align:center}</style>
9+
set_exception_handler(fn() => exit('<style>body{font-family:monospace;color:#fff;font-size:2em;background:#444;padding:5em;text-align:center}</style>
1010
<p>⚠<br>Something went wrong while showing this page<br>Contact the site admin for assistance</p>'));
11-
require 'config.php';
12-
date_default_timezone_set($timezone ?? 'America/New_York');
13-
$uri = parse_url(rtrim($_SERVER['REQUEST_URI'], '/') ?: '/', PHP_URL_PATH);
14-
$params = [];
15-
array_map(fn($p) => @include "plugins/$p/$p.php", $plugins);
16-
if (
17-
!($res = $routes[$uri] ?? current(array_filter($routes, function ($k) use (&$params, $uri) {
18-
return preg_match('#^' . preg_replace('#:(\w+)#', '(?<$1>[\w\@\#\%\&\+\=\_\-]+)', $k) . '$#', $uri, $m)
19-
? $params = $m : false; }, ARRAY_FILTER_USE_KEY)) ?? false)
20-
)
21-
[http_response_code(404), $res = end($routes)];
22-
ob_start();
23-
(is_array($res) ? extract($res) : $page = $res);
24-
$page = "pages/$page";
25-
$meta ??= [];
26-
include $layout === false ? $page : "layouts/$layout.php";
27-
ob_end_flush();
11+
require 'config.php';
12+
date_default_timezone_set($timezone ?? 'America/New_York');
13+
$uri = parse_url(rtrim($_SERVER['REQUEST_URI'], '/') ?: '/', PHP_URL_PATH);
14+
$params = [];
15+
foreach ($plugins as $p)
16+
@include "plugins/$p/$p.php";
17+
if (
18+
!($res = $routes[$uri] ?? current(array_filter($routes, function ($k) use (&$params, $uri) {
19+
return preg_match('#^' . preg_replace('#:(\w+)#', '(?<$1>[\w\@\#\%\&\+\=\_\-]+)', $k) . '$#', $uri, $m)
20+
? $params = $m : false; }, ARRAY_FILTER_USE_KEY)) ?? false)
21+
)
22+
[http_response_code(404), $res = end($routes)];
23+
ob_start();
24+
(is_array($res) ? extract($res) : $page = $res);
25+
$page = "pages/$page";
26+
$meta ??= [];
27+
include $layout === false ? $page : "layouts/$layout.php";
28+
ob_end_flush();

0 commit comments

Comments
 (0)