Compare commits

..

No commits in common. "65f0758e829259bda1e924586a1420eaefc14523" and "fd835dd05863007b409d4afa74862d60cb85f4ca" have entirely different histories.

5 changed files with 36 additions and 87 deletions

View File

@ -1,13 +1,5 @@
<?php
// Logs plugin bootstrap
// (here we add any plugin autoloader, if needed)
// List here all the controllers in "/controllers/" that we need as pages
$GLOBALS['plugin_controllers']['logs'] = [
'logs'
];
// Logger plugin bootstrap
register_hook('logger.system_init', function(array $context) {
// Load plugin-specific LoggerFactory class
@ -19,6 +11,12 @@ register_hook('logger.system_init', function(array $context) {
$GLOBALS['user_IP'] = $userIP;
});
// Add to allowed URLs
register_hook('filter_allowed_urls', function($urls) {
$urls[] = 'logs';
return $urls;
});
// Configuration for top menu injection
define('LOGS_MAIN_MENU_SECTION', 'main'); // section of the top menu
define('LOGS_MAIN_MENU_POSITION', 20); // lower = earlier in menu

View File

@ -1,6 +1,6 @@
{
"name": "Logger Plugin",
"version": "1.0.1",
"version": "1.0.0",
"enabled": true,
"description": "Initializes logging system via LoggerFactory"
}

View File

@ -1,12 +1,10 @@
<?php
// Register plugin bootstrap
// (here we add any plugin autoloader, if needed)
// List here all the controllers in "/controllers/" that we need as pages
$GLOBALS['plugin_controllers']['register'] = [
'register'
];
// Add to allowed URLs
register_hook('filter_allowed_urls', function($urls) {
$urls[] = 'register';
return $urls;
});
// Add to publicly accessible pages
register_hook('filter_public_pages', function($pages) {

View File

@ -1,6 +1,6 @@
{
"name": "Registration Plugin",
"version": "1.0.1",
"version": "1.0.0",
"enabled": true,
"description": "Provides registration functionality as a plugin."
}

View File

@ -11,11 +11,6 @@
* Version: 0.4
*/
// error reporting, comment out in production
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
// Preparing plugins and hooks
// Initialize HookDispatcher and plugin system
require_once __DIR__ . '/../app/core/HookDispatcher.php';
@ -23,18 +18,6 @@ require_once __DIR__ . '/../app/core/PluginManager.php';
use App\Core\HookDispatcher;
use App\Core\PluginManager;
// Global allowed URLs registration
register_hook('filter_allowed_urls', function($urls) {
if (isset($GLOBALS['plugin_controllers']) && is_array($GLOBALS['plugin_controllers'])) {
foreach ($GLOBALS['plugin_controllers'] as $controllers) {
foreach ($controllers as $ctrl) {
$urls[] = $ctrl;
}
}
}
return $urls;
});
// Hook registration and dispatch helpers
function register_hook(string $hook, callable $callback): void {
HookDispatcher::register($hook, $callback);
@ -98,6 +81,11 @@ $system_messages = [];
require '../app/includes/errors.php';
// error reporting, comment out in production
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// list of available pages
// edit accordingly, add 'pages/PAGE.php'
$allowed_urls = [
@ -107,8 +95,9 @@ $allowed_urls = [
'profile','credentials','config','security',
'settings',
'status',
'help','about',
'help',
'login','logout',
'about',
];
// Let plugins filter/extend allowed_urls
@ -226,6 +215,7 @@ if ($page == 'logout') {
include '../app/templates/page-footer.php';
} else {
// if user is logged in, we need user details and rights
if ($validSession) {
// If by error a logged in user requests the login page
@ -251,69 +241,32 @@ if ($page == 'logout') {
}
// --- Plugin loading logic for all enabled plugins ---
// Ensure all enabled plugin bootstraps are loaded before mapping controllers
$plugin_controllers = [];
foreach ($GLOBALS['enabled_plugins'] as $plugin_name => $plugin_info) {
$bootstrap_path = $plugin_info['path'] . '/bootstrap.php';
if (file_exists($bootstrap_path)) {
require_once $bootstrap_path;
}
}
// Plugin controller mapping logic (we add each controller listed in bootstrap as a page)
$mapped_plugin_controllers = [];
foreach ($GLOBALS['enabled_plugins'] as $plugin_name => $plugin_info) {
if (isset($GLOBALS['plugin_controllers'][$plugin_name])) {
foreach ($GLOBALS['plugin_controllers'][$plugin_name] as $plugin_page) {
$controller_path = $plugin_info['path'] . '/controllers/' . $plugin_page . '.php';
if (file_exists($controller_path)) {
$mapped_plugin_controllers[$plugin_page] = $controller_path;
}
}
$controller_path = $plugin_info['path'] . '/controllers/' . $plugin_name . '.php';
if (file_exists($controller_path)) {
$plugin_controllers[$plugin_name] = $controller_path;
}
}
// page building
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
if ($validSession) {
include '../app/templates/page-sidebar.php';
}
if (in_array($page, $allowed_urls)) {
// The page is in allowed URLs
if (isset($mapped_plugin_controllers[$page]) && file_exists($mapped_plugin_controllers[$page])) {
// The page is from a plugin controller
if (defined('PLUGIN_PAGE_DIRECT_OUTPUT') && PLUGIN_PAGE_DIRECT_OUTPUT === true) {
// Barebone page controller, we don't output anything extra
include $mapped_plugin_controllers[$page];
ob_end_flush();
exit;
} else {
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
if ($validSession) {
include '../app/templates/page-sidebar.php';
}
include $mapped_plugin_controllers[$page];
include '../app/templates/page-footer.php';
}
// all normal pages
if (isset($plugin_controllers[$page])) {
include $plugin_controllers[$page];
} else {
// The page is from a core controller
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
if ($validSession) {
include '../app/templates/page-sidebar.php';
}
if (file_exists("../app/pages/{$page}.php")) {
include "../app/pages/{$page}.php";
} else {
include '../app/templates/error-notfound.php';
}
include '../app/templates/page-footer.php';
include "../app/pages/{$page}.php";
}
} else {
// The page is not in allowed URLs
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
if ($validSession) {
include '../app/templates/page-sidebar.php';
}
// the page is not in allowed urls, loading "not found" page
include '../app/templates/error-notfound.php';
include '../app/templates/page-footer.php';
}
include '../app/templates/page-footer.php';
}
// flush the output buffer and show the page