# Core Classes ## CodePressCMS.php Main CMS class in `cms/core/class/CodePressCMS.php`: ```php $cms = new CodePressCMS(); $cms->init(); $cms->renderPage($pagePath); ``` Responsibilities: - Routing and page rendering - Breadcrumb generation (dynamic: Home > [subfolders] > [page]) - Loading guide pages (`getGuidePage()`) - Title extraction from H1 (`getTitleFromFile()`) - Display name processing (`formatDisplayName()`) ## ThemeManager.php Theme management in `cms/core/class/ThemeManager.php`: ```php $themeManager = new ThemeManager($config); $themeManager->getActiveTheme(); $themeManager->renderTwig($template, $data); $themeManager->compileCss($force); $themeManager->getCssUrl(); ``` Responsibilities: - Resolving the active theme from `config.json` - Loading `theme.json` (title, config.default_template, template mapping) - Building the Twig environment (rooted in the theme folder) - **SCSS compilation** — compiles `assets/scss/theme.scss` to `assets/css_compiled/theme.css` via scssphp - Resolving the layout to a `.twig` template (fallback to `config.default_template`) `getCssUrl()` priority: 1) `assets/css/theme.css` (manual), 2) `assets/css_compiled/theme.css` (compiled). ## PluginManager.php Plugin system in `cms/core/plugin/PluginManager.php`: ```php $pluginManager = new PluginManager($pluginsPath, $enabledPlugins); $pluginManager->getSidebarContent($allowedPlugins); $pluginManager->getPluginCssUrls(); $pluginManager->executeHook($name, $params); $pluginManager->getAdminMenuItems(); $pluginManager->handleAdminRoute($route); $pluginManager->getPluginType($pluginName); ``` Responsibilities: - Loading plugins from `plugins/` folders (only enabled plugins) - Plugin file: `.php` (NOT `plugin.php`) - Hooks and filters system (`doAction`, `applyFilters`) - Collecting sidebar content from content plugins (`getSidebarContent`) - Collecting plugin CSS URLs (`getPluginCssUrls`) - **Admin menu items** from system plugins (`getAdminMenuItems`) - **Admin routes** handled via system plugins (`handleAdminRoute`) - Determining the **plugin type** (`getPluginType` — `content` or `system`) - `isPluginViewable` — system plugins do not appear in the sidebar ## AdminAuth.php Authentication and RBAC in `admin/src/AdminAuth.php`: ```php $auth = new AdminAuth($appConfig); $auth->login($username, $password); $auth->logout(); $auth->hasPermission($route); $auth->verifyCsrf($token); ``` Constants: - `ROLE_PERMISSIONS` — Mapping of role → allowed route prefixes. `admin` has wildcard `*`. - `ROLE_LABELS` — Human-readable labels per role. Roles: | Role | Label | Permissions | |------|-------|-------------| | `admin` | Admin | Everything (`*`) | | `content-manager` | Content Manager | Content management, guide | | `bi-manager` | BI Manager | Statistics, logs, guide | | `site-admin` | Site Admin | Theme, plugins, statistics, logs, update, guide | Responsibilities: - Session-based authentication - bcrypt password hashing - CSRF tokens (`verifyCsrf`) - Brute-force lockout (login attempts tracking) - RBAC via `hasPermission($route)` — checks the route against `ROLE_PERMISSIONS` ## CMSAPI.php Plugin API in `cms/core/plugin/CMSAPI.php`: ```php $api = PluginManager::getAPI(); $config = $api->getConfig(); $page = $api->getPage($path); $content = $api->getContent(); ``` Provides read-only access for plugins to CMS data (config, pages, content).