19 Commits

Author SHA1 Message Date
nick 4484f88d8d Changed variables. 2026-07-04 07:43:33 -07:00
nick 7ee47a0b1e moving away from gross globals 2026-07-03 21:05:39 -07:00
nick 230476e8e5 Claude redid the router 2026-06-30 01:35:55 -07:00
nick d5871ed8e7 minor updates 2026-06-16 19:00:30 -07:00
nick ad6e07c76d fixed css and changed timezone 2026-05-04 11:30:14 -07:00
nick 06310d9eb9 Updated readme and composer 2026-05-03 13:27:30 -07:00
nick f679d0b20e safety fix 2026-02-07 17:26:26 -08:00
nick 9feccf9eaa tabs and draft working 2026-01-26 21:55:22 -08:00
nick 14ec6b7e7a fixed matomo to be in the master twig template. 2026-01-22 15:40:46 -08:00
nick 42a828a778 edit page template 2026-01-12 19:00:03 -08:00
nick 81c239f043 added matomo 2026-01-09 12:41:55 -08:00
nick 0d91b61bd0 control panel head changes 2025-12-22 18:32:35 -08:00
nick fd9a71c4d6 added page to the front end 2025-12-16 05:35:56 -08:00
nick 71413283c8 added humans and robots 2025-12-15 09:54:57 -08:00
nick a32956b4a2 added coming soon page 2025-12-15 09:28:09 -08:00
nick 7bf3dc6610 added coming soon page 2025-12-15 09:27:56 -08:00
nick 7b064eb6da morning changes 2025-12-15 06:14:07 -08:00
nick 934e134941 ready to test new layout 2025-12-14 03:45:07 -08:00
nick 6f410b5d0e added logs to docker 2025-12-07 23:10:32 -08:00
72 changed files with 1367 additions and 348 deletions
+66
View File
@@ -0,0 +1,66 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## What this is
Novaconium is a PHP 8.1+ micro-framework distributed as a Composer package (`4lt/novaconium`, PSR-4 autoloaded under the `Novaconium\` namespace from `src/`). This repo *is* the framework itself — there is no "app" here to run directly. Consuming projects `composer require` it and copy `skeleton/novaconium/` into their own project to get an `App/` directory (config, controllers, views, routes) plus a `public/` entrypoint.
Because of this, most of the interesting behavior lives in two places:
- `src/` — the framework runtime (bootstrap, router, session, db, etc.)
- `controllers/` + `views/` + `twig/` — the framework's own built-in admin panel ("NOVACONIUM" control panel routes), shipped so consuming apps get login/dashboard/page-editing/messages for free.
`skeleton/` is what gets copied into a new consuming project — treat it as a template, not live framework code.
## Development
There is no local PHP/Composer install expected — Composer, PHP/Apache, and Sass all run in Docker containers (see `docs/docker.md`, `docs/Composer.md`, `docs/Sass.md`). There is no test suite or linter configured in this repo.
Compiling Sass (from repo root):
```bash
docker run --rm -v "$(pwd):/usr/src/app" -w /usr/src/app sass-container --style=compressed sass/novaconium.sass skeleton/novaconium/public/css/novaconium.css
```
For iterating against a real consuming project without re-running `composer require` on every change, use the fake autoloader dev pattern in `docs/Dev-Fake_autoload.md` (registers a `spl_autoload_register` shim pointing at a manually cloned copy of this repo under the app's `vendor/4lt/novaconium`).
## Request lifecycle
Entry point in a consuming app is `App/public/index.php` (see `skeleton/novaconium/public/index.php`), which:
1. Defines `BASEPATH` (app root) and `FRAMEWORKPATH` (`BASEPATH/vendor/4lt/novaconium`) — these two constants are used everywhere in `src/` to resolve app vs. framework paths, and are assumed to already be defined by the time any framework code runs.
2. Requires Composer's autoloader, then `FRAMEWORKPATH/src/novaconium.php` (the bootstrap).
3. Calls the global `makeitso()` at the very end.
`src/novaconium.php` (the bootstrap) runs in this order and wires up several **globals** that framework code and app controllers rely on implicitly (`$config`, `$log`, `$data`, `$session`, `$messages`, `$db`, `$post`, `$redirect`, `$router`):
1. Loads `App/config.php` (falls back to the skeleton's default config if the app hasn't created one).
2. Loads `src/functions.php` (global helpers: `dd()`, `makeitso()`) and `src/twig.php` (global `view()` helper).
3. Creates `$log` (`Novaconium\Logger`), `$session` (`Novaconium\Session`), `$messages` (`Novaconium\MessageHandler`, seeded from flashed session messages), `$db` (`Novaconium\Database`, only if `config['database']['host']` is set), `$post` (`Novaconium\Post`, only if `$_POST` is non-empty), `$redirect` (`Novaconium\Redirect`).
4. Builds `$router` (`Novaconium\Router`), whose constructor resolves the matched controller file, then immediately `require`s it — so the matched controller file executes inline, still inside bootstrap, with all the globals above already in scope.
Controllers are plain PHP scripts (not classes) that use the ambient globals directly (e.g. `$session->get(...)`, `$messages->error(...)`, `$post->get(...)`, `$db->getRow(...)`) and typically end by calling the global `view($templateName, $data)` or setting `$redirect->url(...)` followed by `makeitso()` to end the request (writes session, closes DB, performs any pending redirect, flashes messages, then `exit`).
## Router (`src/Router.php`)
Full behavioral spec is in `docs/Router.md` — read it before touching routing logic, since several quirks are **intentionally preserved for backward compatibility**, not bugs:
- Only the *first* `{param}` in a route pattern is ever extracted; subsequent params in the same pattern are ignored.
- For parameterized routes, the first route whose static prefix + segment count matches wins, even if that route has no handler for the current HTTP method — the router does not keep searching for a better match.
- No wildcard/optional-segment support; segment counts must match exactly.
Routes are plain associative arrays keyed by path, mapping `get`/`post` to a controller string (see `config/routes.php` for the framework's own admin routes, `skeleton/novaconium/App/routes.php` for the app-level shape). `App/routes.php` routes are merged with (and can override) framework routes. Controller strings prefixed with `NOVACONIUM` resolve against `FRAMEWORKPATH/controllers/`; everything else resolves against `BASEPATH/App/controllers/`. Unresolved routes/files fall back to the app's `404.php`, then the framework's `controllers/404.php`.
## Views (Twig)
`view($name, $data)` (`src/twig.php`) loads templates from `App/views/` by default, with two additional Twig namespaces registered: `@novaconium``FRAMEWORKPATH/twig` (layout partials: `master.html.twig`, `nav.html.twig`, `head.html.twig`, etc.) and `@novacore``FRAMEWORKPATH/views` (the framework's built-in admin pages: dashboard, pages, messages, settings). Apps can override any framework template by placing a same-named file under `App/templates/` (`override` namespace). The framework's own controllers render via the `@novacore/...` namespace (e.g. `view('@novacore/dashboard', $data)`).
## Other framework primitives (all under `src/`, namespace `Novaconium`)
- `Database` — thin `mysqli` wrapper (`query`, `getRow`, `getRows`); always uses prepared statements but binds every parameter as a string type.
- `Session` — thin `$_SESSION` wrapper; auto-initializes `token`/`messages`/`formData`/`errors` keys; `flash()` reads-then-deletes.
- `MessageHandler` — categorized flash messages (`error`/`warning`/`notice`/`success`), persisted across requests via `$session`.
- `Post` — sanitizes `$_POST` via `FILTER_SANITIZE_FULL_SPECIAL_CHARS` on construction; access via `$post->get($key)`.
- `Redirect` — buffers a target URL/status; only the *last* `url()` call before `makeitso()` takes effect; actual `header()` redirect happens inside `makeitso()`.
- `Logger` — level-gated file logger (`DEBUG`/`INFO`/`WARNING`/`ERROR`/`NONE`), configured via `config['logfile']`/`config['loglevel']`.
- `src/Services/` — newer, thinner service classes (`Auth`, `TagManager`) alongside the older top-level `src/` classes; check here first before adding new cross-cutting logic.
## Configuration
App-level config lives in `App/config.php` (see `docs/ConfigurationFile.md` and `skeleton/novaconium/App/config.php` for the shape): `database` (mysqli connection), `base_url`, `secure_key` (used to pepper password hashes via `hash_hmac('sha3-512', ...)`, see `controllers/authenticate.php`), `logfile`, `loglevel`, plus optional `matomo_url`/`matomo_id`/`fonts` passed straight into Twig's global `$data`.
+14 -7
View File
@@ -6,13 +6,20 @@ NovaconiumPHP is a high-performance PHP framework designed with inspiration from
Pronounced: Noh-vah-koh-nee-um
Packagist: https://packagist.org/packages/4lt/novaconium
Master Repo: https://git.4lt.ca/4lt/novaconium
* Packagist: https://packagist.org/packages/4lt/novaconium
* Master Repo: https://git.4lt.ca/4lt/novaconium
## Getting Started
Novaconium is heavly influenced by docker, but you can use composer outside of docker.
You can [learn more about how novaconium works with composer](https://git.4lt.ca/4lt/novaconium/src/branch/master/docs/Install-Composer-On-Debian.md).
Novaconium is designed to be developed primarily using Docker. Instead of relying on tools installed directly on your system, common development tasks are executed inside containers:
* Composer runs inside a Docker container rather than on your host machine
* Apache / PHP are served from containers instead of your local environment
* Sass compilation is also handled within a container
As long as you have Docker installed, you can use the full development environment without installing additional dependencies on your system.
You can [learn more about how novaconium works with composer](https://git.4lt.ca/4lt/novaconium/src/branch/master/docs/Composer.md).
```bash
PROJECTNAME=novaproject;
@@ -24,9 +31,9 @@ docker run --rm --interactive --tty --volume ./novaconium/:/app composer:latest
cp -R novaconium/vendor/4lt/novaconium/skeleton/. .;
# Edit .env
# pwgen -cnsB1v 12 root password
# pwgen -cnsB1v 12 mysql user password (need in both config and env)
# pwgen -cnsB1v 64 framework key (need in config)
# pwgen -cnsB1v 12 # root password
# pwgen -cnsB1v 12 # mysql user password (need in both config and env)
# pwgen -cnsB1v 64 # framework key (need in config)
# Edit novaconium/App/config.php
docker compose up -d
+6 -3
View File
@@ -8,11 +8,14 @@ $framework_routes = [
],
'/novaconium/login' => [
'post' => 'NOVACONIUM/authenticate',
'get' => 'NOVACONIUM/login'
'get' => 'NOVACONIUM/auth/login'
],
'/novaconium/dashboard' => [
'get' => 'NOVACONIUM/dashboard'
],
'/novaconium/settings' => [
'get' => 'NOVACONIUM/settings'
],
'/novaconium/pages' => [
'get' => 'NOVACONIUM/pages'
],
@@ -38,8 +41,8 @@ $framework_routes = [
'post' => 'NOVACONIUM/message_save'
],
'/novaconium/logout' => [
'post' => 'NOVACONIUM/logout',
'get' => 'NOVACONIUM/logout'
'post' => 'NOVACONIUM/auth/logout',
'get' => 'NOVACONIUM/auth/logout'
],
'/novaconium/sitemap.xml' => [
'get' => 'NOVACONIUM/sitemap'
+11
View File
@@ -0,0 +1,11 @@
<?php
$ctx->withData([
'title' => 'Novaconium Login Page',
'pageclass' => 'novaconium'
]);
// Don't come here if logged in
if ($ctx->session->get('username')) {
$ctx->redirect->url('/novaconium/dashboard');
makeitso();
}
view('@novacore/auth/login');
+5
View File
@@ -0,0 +1,5 @@
<?php
$ctx->session->kill();
$ctx->log->info("Logout - Logout Success - " . ($_SERVER['REMOTE_ADDR'] ?? 'unknown'));
$ctx->redirect->url('/');
makeitso();
+24 -24
View File
@@ -8,63 +8,63 @@ $url_fail = '/novaconium/login';
// Don't go further if already logged in
if ( !empty($session->get('username')) ) {
$redirect->url($url_success);
if ( !empty($ctx->session->get('username')) ) {
$ctx->redirect->url($url_success);
makeitso();
}
// Make sure Session Token is correct
if ($session->get('token') != $post->get('token')) {
$messages->addMessage('error', "Invalid Session.");
$log->error("Login Authentication - Invalid Session Token");
if ($ctx->session->get('token') != $ctx->post->get('token')) {
$ctx->messages->addMessage('error', "Invalid Session.");
$ctx->log->error("Login Authentication - Invalid Session Token");
}
// Handle Username
$rawUsername = $post->get('username', null);
$rawUsername = $ctx->post->get('username', null);
$cleanUsername = $v->clean($rawUsername); // Clean the input
$username = strtolower($cleanUsername); // Convert to lowercase
if (!$username) {
$messages->addMessage('error', "No Username given.");
$ctx->messages->addMessage('error', "No Username given.");
}
// Handle Password
$password = $v->clean($post->get('password', null));
$password = $v->clean($ctx->post->get('password', null));
if ( empty($password) ) {
$messages->addMessage('error', "Password Empty.");
$ctx->messages->addMessage('error', "Password Empty.");
}
/*************************************************************************************************************
* Query Database
************************************************************************************************************/
if ($messages->count('error') === 0) {
if ($ctx->messages->count('error') === 0) {
$query = "SELECT id, username, email, password, blocked FROM users WHERE username = ? OR email = ?";
$matched = $db->getRow($query, [$username, $username]);
$matched = $ctx->db->getRow($query, [$username, $username]);
if (empty($matched)) {
$messages->addMessage('error', "User or Password incorrect.");
$log->warning("Login Authentication - Login Error, user doesn't exist");
$ctx->messages->addMessage('error', "User or Password incorrect.");
$ctx->log->warning("Login Authentication - Login Error, user doesn't exist");
}
}
if ($messages->count('error') === 0) {
if ($ctx->messages->count('error') === 0) {
// Re-apply pepper
$peppered = hash_hmac('sha3-512', $password, $config['secure_key']);
$peppered = hash_hmac('sha3-512', $password, $ctx->config['secure_key']);
// Verify hashed password
if (!password_verify($peppered, $matched['password'])) {
$messages->addMessage('error', "User or Password incorrect.");
$log->warning("Login Authentication - Login Error, password wrong");
$ctx->messages->addMessage('error', "User or Password incorrect.");
$ctx->log->warning("Login Authentication - Login Error, password wrong");
}
}
// Process Login or Redirect
if ($messages->count('error') === 0) {
if ($ctx->messages->count('error') === 0) {
$query = "SELECT groupName FROM user_groups WHERE user_id = ?";
$groups = $db->getRow($query, [$matched['id']]);
$session->set('username', $cleanUsername);
$session->set('group', $groups['groupName']);
$redirect->url($url_success);
$log->info("Login Authentication - Login Success");
$groups = $ctx->db->getRow($query, [$matched['id']]);
$ctx->session->set('username', $cleanUsername);
$ctx->session->set('group', $groups['groupName']);
$ctx->redirect->url($url_success);
$ctx->log->info("Login Authentication - Login Success");
} else {
$redirect->url($url_fail);
$ctx->redirect->url($url_fail);
}
+9
View File
@@ -0,0 +1,9 @@
<?php
$ctx->withData([
'title' => 'Coming Soon',
'heading' => 'Coming Soon',
'countdown' => true,
'launch_date' => '2026-01-01T00:00:00'
]);
view('@novacore/coming-soon', $ctx->data);
+7 -7
View File
@@ -6,10 +6,10 @@ use Nickyeoman\Validation;
$validate = new Validation\Validate();
$valid = true;
$p = $post->all();
$p = $ctx->post->all();
// Check secure key
if (empty($p['secure_key']) || $p['secure_key'] !== $config['secure_key']) {
if (empty($p['secure_key']) || $p['secure_key'] !== $ctx->config['secure_key']) {
$valid = false;
}
@@ -31,7 +31,7 @@ if (empty($p['password'])) {
$valid = false;
} else {
// Use pepper + Argon2id
$peppered = hash_hmac('sha3-512', $p['password'], $config['secure_key']);
$peppered = hash_hmac('sha3-512', $p['password'], $ctx->config['secure_key']);
$hashed_password = password_hash($peppered, PASSWORD_ARGON2ID);
}
@@ -45,16 +45,16 @@ if ($valid) {
EOSQL;
$params = [$name, $hashed_password, $p['email']];
$db->query($query, $params);
$userid = $db->lastid();
$ctx->db->query($query, $params);
$userid = $ctx->db->lastid();
// Assign admin group
$groupInsertQuery = <<<EOSQL
INSERT INTO `user_groups` (`user_id`, `groupName`) VALUES (?, ?);
EOSQL;
$db->query($groupInsertQuery, [$userid, 'admin']);
$ctx->db->query($groupInsertQuery, [$userid, 'admin']);
}
// Always redirect at end
$redirect->url('/novaconium');
$ctx->redirect->url('/novaconium');
+7 -6
View File
@@ -1,13 +1,14 @@
<?php
$data = array_merge($data, [
$ctx->withData([
'title' => 'Novaconium Dashboard Page',
'pageclass' => 'novaconium'
'pageclass' => 'novaconium',
'pageid' => 'controlPanel'
]);
if ( empty($session->get('username'))) {
$redirect->url('/novaconium/login');
$messages->error('You are not loggedin');
if ( empty($ctx->session->get('username'))) {
$ctx->redirect->url('/novaconium/login');
$ctx->messages->error('You are not loggedin');
makeitso();
}
view('@novacore/dashboard', $data);
view('@novacore/dashboard', $ctx->data);
+11 -10
View File
@@ -1,20 +1,21 @@
<?php
$data = array_merge($data, [
$ctx->withData([
'title' => 'Novaconium Edit Page',
'pageclass' => 'novaconium',
'pageid' => 'controlPanel',
'editor' => 'ace'
]);
// Check if logged in
if (empty($session->get('username'))) {
$messages->error('You are not logged in');
$redirect->url('/novaconium/login');
if (empty($ctx->session->get('username'))) {
$ctx->messages->error('You are not logged in');
$ctx->redirect->url('/novaconium/login');
makeitso();
}
// Get page ID from router parameters
$pageid = $router->parameters['id'] ?? null;
$pageid = $ctx->router->parameters['id'] ?? null;
if (!empty($pageid)) {
// Existing page: fetch from database
@@ -50,23 +51,23 @@ WHERE p.id = ?
GROUP BY p.id;
EOSQL;
$data['rows'] = $db->getRow($query, [$pageid]);
$ctx->data['rows'] = $ctx->db->getRow($query, [$pageid]);
// If no row is found, treat as new page
if (!$data['rows']) {
if (!$ctx->data['rows']) {
$pageid = null;
}
}
if (empty($pageid)) {
// New page: set default values for all fields
$data['rows'] = [
$ctx->data['rows'] = [
'id' => 'newpage',
'title' => '',
'heading' => '',
'description' => '',
'keywords' => '',
'author' => $session->get('username') ?? '',
'author' => $ctx->session->get('username') ?? '',
'slug' => '',
'path' => '',
'intro' => '',
@@ -81,4 +82,4 @@ if (empty($pageid)) {
}
// Render the edit page view
view('@novacore/editpage/index', $data);
view('@novacore/editpage/index', $ctx->data);
+31 -30
View File
@@ -1,21 +1,22 @@
<?php
$data = [
$ctx->data = [
'secure_key' => false,
'gen_key' => NULL,
'users_created' => false,
'empty_users' => false,
'show_login' => false,
'token' => $session->get('token'),
'token' => $ctx->session->get('token'),
'pageclass' => 'novaconium',
'title' => 'Novaconium Admin'
];
// Check if SECURE KEY is Set in
if ($config['secure_key'] !== null && strlen($config['secure_key']) === 64) {
$data['secure_key'] = true;
if ($ctx->config['secure_key'] !== null && strlen($ctx->config['secure_key']) === 64) {
$ctx->data['secure_key'] = true;
} else {
$data['gen_key'] = substr(bin2hex(random_bytes(32)), 0, 64);
$log->warn('secure_key not detected');
$ctx->data['gen_key'] = substr(bin2hex(random_bytes(32)), 0, 64);
$ctx->log->warn('secure_key not detected');
}
// Check if user table exists
@@ -25,7 +26,7 @@ FROM information_schema.tables
WHERE table_schema = DATABASE()
AND TABLE_NAME = 'users';
EOSQL;
$result = $db->query($query);
$result = $ctx->db->query($query);
if ($result->num_rows === 0) {
$query = <<<EOSQL
@@ -45,9 +46,9 @@ if ($result->num_rows === 0) {
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
EOSQL;
$db->query($query);
$data['users_created'] = true;
$log->info('Users Table Created');
$ctx->db->query($query);
$ctx->data['users_created'] = true;
$ctx->log->info('Users Table Created');
}
@@ -58,7 +59,7 @@ FROM information_schema.tables
WHERE table_schema = DATABASE()
AND TABLE_NAME = 'user_groups';
EOSQL;
$result = $db->query($query);
$result = $ctx->db->query($query);
if ($result->num_rows === 0) {
$query = <<<EOSQL
@@ -71,8 +72,8 @@ if ($result->num_rows === 0) {
EOSQL;
$db->query($query);
$log->info('User_groups Table Created');
$ctx->db->query($query);
$ctx->log->info('User_groups Table Created');
}
@@ -83,7 +84,7 @@ FROM information_schema.tables
WHERE table_schema = DATABASE()
AND TABLE_NAME = 'pages';
EOSQL;
$result = $db->query($query);
$result = $ctx->db->query($query);
if ($result->num_rows === 0) {
$query = <<<EOSQL
@@ -108,8 +109,8 @@ if ($result->num_rows === 0) {
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
EOSQL;
$db->query($query);
$log->info('Pages Table Created');
$ctx->db->query($query);
$ctx->log->info('Pages Table Created');
}
// Check ContactForm Table
@@ -119,7 +120,7 @@ FROM information_schema.tables
WHERE table_schema = DATABASE()
AND TABLE_NAME = 'contactForm';
EOSQL;
$result = $db->query($query);
$result = $ctx->db->query($query);
if ($result->num_rows === 0) {
$query = <<<EOSQL
@@ -134,20 +135,20 @@ if ($result->num_rows === 0) {
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
EOSQL;
$db->query($query);
$log->info('ContactForm Table Created');
$ctx->db->query($query);
$ctx->log->info('ContactForm Table Created');
}
// Check if a user exists
$result = $db->query("SELECT COUNT(*) as total FROM users");
$result = $ctx->db->query("SELECT COUNT(*) as total FROM users");
$row = $result->fetch_assoc();
if ($row['total'] < 1) {
$data['empty_users'] = true;
$ctx->data['empty_users'] = true;
} else {
$log->info('Init Run complete, all sql tables exist with a user.');
$ctx->log->info('Init Run complete, all sql tables exist with a user.');
// Everything is working, send them to login page
$redirect->url('/novaconium/login');
$ctx->redirect->url('/novaconium/login');
makeitso();
}
@@ -158,7 +159,7 @@ FROM information_schema.tables
WHERE table_schema = DATABASE()
AND TABLE_NAME = 'tags';
EOSQL;
$result = $db->query($query);
$result = $ctx->db->query($query);
if ($result->num_rows === 0) {
$query = <<<EOSQL
CREATE TABLE IF NOT EXISTS `tags` (
@@ -169,8 +170,8 @@ CREATE TABLE IF NOT EXISTS `tags` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
EOSQL;
$db->query($query);
$log->info('Tags Table Created');
$ctx->db->query($query);
$ctx->log->info('Tags Table Created');
}
// Check Page Tags Junction Table (after tags table)
@@ -180,7 +181,7 @@ FROM information_schema.tables
WHERE table_schema = DATABASE()
AND TABLE_NAME = 'page_tags';
EOSQL;
$result = $db->query($query);
$result = $ctx->db->query($query);
if ($result->num_rows === 0) {
$query = <<<EOSQL
CREATE TABLE IF NOT EXISTS `page_tags` (
@@ -194,8 +195,8 @@ CREATE TABLE IF NOT EXISTS `page_tags` (
FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
EOSQL;
$db->query($query);
$log->info('Page Tags Junction Table Created');
$ctx->db->query($query);
$ctx->log->info('Page Tags Junction Table Created');
}
view('@novacore/init', $data);
view('@novacore/init', $ctx->data);
-9
View File
@@ -1,9 +0,0 @@
<?php
$data['title'] = 'Novaconium Login Page';
// Don't come here if logged in
if ($session->get('username')) {
$redirect->url('/novaconium/dashboard');
makeitso();
}
view('@novacore/login');
-5
View File
@@ -1,5 +0,0 @@
<?php
$session->kill();
$log->info("Logout - Logout Success - " . $_SERVER['REMOTE_ADDR']);
$redirect->url('/');
makeitso();
+7 -7
View File
@@ -1,15 +1,15 @@
<?php
if ( empty($session->get('username'))) {
$redirect->url('/novaconium/login');
$messages->error('You are not loggedin');
if ( empty($ctx->session->get('username'))) {
$ctx->redirect->url('/novaconium/login');
$ctx->messages->error('You are not loggedin');
makeitso();
}
$messageid = $router->parameters['id'];
$messageid = $ctx->router->parameters['id'];
$query="DELETE FROM contactForm WHERE `contactForm`.`id` = ?";
$db->query($query, [$messageid]);
$ctx->db->query($query, [$messageid]);
$redirect->url('/novaconium/messages');
$messages->notice("Removed Message $messageid");
$ctx->redirect->url('/novaconium/messages');
$ctx->messages->notice("Removed Message $messageid");
makeitso();
+8 -8
View File
@@ -1,19 +1,19 @@
<?php
$data = array_merge($data, [
$ctx->withData([
'title' => 'Novaconium Message Page',
'pageclass' => 'novaconium'
]);
if ( empty($session->get('username'))) {
$redirect->url('/novaconium/login');
$messages->error('You are not loggedin');
if ( empty($ctx->session->get('username'))) {
$ctx->redirect->url('/novaconium/login');
$ctx->messages->error('You are not loggedin');
makeitso();
}
$messageid = $router->parameters['id'];
$query = "SELECT id, name, email, message, created, unread FROM contactForm WHERE id = '$messageid'";
$messageid = $ctx->router->parameters['id'];
$query = "SELECT id, name, email, message, created, unread FROM contactForm WHERE id = ?";
$data['themessage'] = $db->getRow($query);
$ctx->withData(['themessage' => $ctx->db->getRow($query, [$messageid])]);
view('@novacore/editmessage', $data);
view('@novacore/editmessage', $ctx->data);
+20 -20
View File
@@ -5,33 +5,33 @@ use Nickyeoman\Validation;
$v = new Nickyeoman\Validation\Validate();
$url_success = '/novaconium/messages';
$url_error = '/novaconium/messages/edit/' . $post->get('id'); // Redirect back to the message edit form on error
$url_error = '/novaconium/messages/edit/' . $ctx->post->get('id'); // Redirect back to the message edit form on error
// Check if logged in
if (empty($session->get('username'))) {
$messages->error('You are not logged in');
$redirect->url('/novaconium/login');
if (empty($ctx->session->get('username'))) {
$ctx->messages->error('You are not logged in');
$ctx->redirect->url('/novaconium/login');
makeitso();
}
// Check CSRF token
if ($session->get('token') != $post->get('token')) {
$messages->error('Invalid token');
$redirect->url($url_success);
if ($ctx->session->get('token') != $ctx->post->get('token')) {
$ctx->messages->error('Invalid token');
$ctx->redirect->url($url_success);
makeitso();
}
// Get POST data
$id = $post->get('id');
$name = $post->get('name');
$email = $post->get('email');
$message = $post->get('message');
$unread = !empty($post->get('unread')) ? 1 : 0;
$id = $ctx->post->get('id');
$name = $ctx->post->get('name');
$email = $ctx->post->get('email');
$message = $ctx->post->get('message');
$unread = !empty($ctx->post->get('unread')) ? 1 : 0;
// Validate required fields
if (empty($id) || empty($message) || empty($email)) {
$messages->error('One of the required fields was empty.');
$redirect->url($url_error);
$ctx->messages->error('One of the required fields was empty.');
$ctx->redirect->url($url_error);
makeitso();
}
@@ -43,15 +43,15 @@ try {
$params = [$name, $email, $message, $unread, $id];
$db->query($query, $params);
$ctx->db->query($query, $params);
$messages->notice('Message updated successfully');
$ctx->messages->notice('Message updated successfully');
} catch (Exception $e) {
$messages->error('Error updating message: ' . $e->getMessage());
$redirect->url($url_error);
} catch (\Exception $e) {
$ctx->messages->error('Error updating message: ' . $e->getMessage());
$ctx->redirect->url($url_error);
makeitso();
}
// Redirect to success page
$redirect->url($url_success);
$ctx->redirect->url($url_success);
+9 -8
View File
@@ -1,21 +1,22 @@
<?php
$data = array_merge($data, [
$ctx->withData([
'title' => 'Novaconium Messages',
'pageclass' => 'novaconium'
'pageclass' => 'novaconium',
'pageid' => 'controlPanel'
]);
if ( empty($session->get('username'))) {
$redirect->url('/novaconium/login');
$messages->error('You are not loggedin');
if ( empty($ctx->session->get('username'))) {
$ctx->redirect->url('/novaconium/login');
$ctx->messages->error('You are not loggedin');
makeitso();
}
// Get the pages
$query = "SELECT id, name, email, LEFT(message, 40) AS message, created, unread FROM contactForm";
$matched = $db->getRows($query);
$matched = $ctx->db->getRows($query);
$data['messages'] = $matched;
$ctx->withData(['messages' => $matched]);
view('@novacore/messages', $data);
view('@novacore/messages', $ctx->data);
+9 -8
View File
@@ -1,20 +1,21 @@
<?php
$data = array_merge($data, [
$ctx->withData([
'title' => 'Novaconium Pages',
'pageclass' => 'novaconium'
'pageclass' => 'novaconium',
'pageid' => 'controlPanel'
]);
if ( empty($session->get('username'))) {
$redirect->url('/novaconium/login');
$messages->error('You are not loggedin');
if ( empty($ctx->session->get('username'))) {
$ctx->redirect->url('/novaconium/login');
$ctx->messages->error('You are not loggedin');
makeitso();
}
// Get the pages
$query = "SELECT id, title, created, updated, draft FROM pages";
$matched = $db->getRows($query);
$matched = $ctx->db->getRows($query);
$data['pages'] = $matched;
$ctx->withData(['pages' => $matched]);
view('@novacore/pages', $data);
view('@novacore/pages', $ctx->data);
+2 -2
View File
@@ -10,7 +10,7 @@ $pt = '@novacore/samples'; //Define the view directory
//$pt = 'samples'; //drop the core for your project
//Grab the slug
$slug = $router->parameters['slug'];
$slug = $ctx->router->parameters['slug'];
//build path
$tmpl = $pt . '/' . $slug;
@@ -26,7 +26,7 @@ if (strpos($pt, '@novacore') !== false) {
$possibleFile = $baseDir . '/' . $slug . '.html.twig'; // add .twig extension if needed
if (is_file($possibleFile) && is_readable($possibleFile)) {
view($tmpl, $data);
view($tmpl, $ctx->data);
} else {
http_response_code('404');
header("Content-Type: text/html");
+34 -34
View File
@@ -5,44 +5,44 @@ use Novaconium\Services\TagManager;
$v = new Nickyeoman\Validation\Validate();
$url_error = '/novaconium/page/edit/' . $post->get('id'); // fallback for errors
$url_error = '/novaconium/page/edit/' . $ctx->post->get('id'); // fallback for errors
// -------------------------
// Check login
// -------------------------
if (empty($session->get('username'))) {
$messages->error('You are not logged in');
$redirect->url('/novaconium/login');
if (empty($ctx->session->get('username'))) {
$ctx->messages->error('You are not logged in');
$ctx->redirect->url('/novaconium/login');
makeitso();
}
// -------------------------
// Check CSRF token
// -------------------------
if ($session->get('token') != $post->get('token')) {
$messages->error('Invalid Token');
$redirect->url('/novaconium/pages');
if ($ctx->session->get('token') != $ctx->post->get('token')) {
$ctx->messages->error('Invalid Token');
$ctx->redirect->url('/novaconium/pages');
makeitso();
}
// -------------------------
// Gather POST data
// -------------------------
$id = $post->get('id');
$title = $_POST['title'] ?? '';
$heading = $_POST['heading'] ?? '';
$description = $_POST['description'] ?? '';
$keywords = $_POST['keywords'] ?? '';
$author = $_POST['author'] ?? '';
$slug = $_POST['slug'] ?? '';
$path = $_POST['path'] ?? null;
$intro = $_POST['intro'] ?? '';
$body = $_POST['body'] ?? '';
$notes = $_POST['notes'] ?? '';
$draft = !empty($post->get('draft')) ? 1 : 0;
$changefreq = $_POST['changefreq'] ?? 'monthly';
$priority = $_POST['priority'] ?? 0.0;
$tags_json = $_POST['tags_json'] ?? '[]';
$id = $ctx->post->get('id');
$title = $ctx->post->get('title', '');
$heading = $ctx->post->get('heading', '');
$description = $ctx->post->get('description', '');
$keywords = $ctx->post->get('keywords', '');
$author = $ctx->post->get('author', '');
$slug = $ctx->post->get('slug', '');
$path = $ctx->post->get('path');
$intro = $ctx->post->get('intro', '');
$body = $ctx->post->get('body', '');
$notes = $ctx->post->get('notes', '');
$draft = !empty($ctx->post->get('draft')) ? 1 : 0;
$changefreq = $ctx->post->get('changefreq', 'monthly');
$priority = $ctx->post->get('priority', 0.0);
$tags_json = $ctx->post->get('tags_json', '[]');
// -------------------------
// Decode & sanitize tags
@@ -57,13 +57,13 @@ $tags = array_unique($tags);
// Validate required fields
// -------------------------
if (empty($title) || empty($slug) || empty($body)) {
$messages->error('Title, Slug, and Body are required.');
$redirect->url($url_error);
$ctx->messages->error('Title, Slug, and Body are required.');
$ctx->redirect->url($url_error);
makeitso();
}
try {
$tagManager = new TagManager();
$tagManager = new TagManager($ctx->db);
if ($id == 'newpage') {
// -------------------------
@@ -79,9 +79,9 @@ try {
$slug, $path, $intro, $body, $notes,
$draft, $changefreq, $priority
];
$db->query($query, $params);
$id = $db->lastid;
$messages->notice('Page Created');
$ctx->db->query($query, $params);
$id = $ctx->db->lastid;
$ctx->messages->notice('Page Created');
} else {
// -------------------------
@@ -97,8 +97,8 @@ try {
$slug, $path, $intro, $body, $notes,
$draft, $changefreq, $priority, $id
];
$db->query($query, $params);
$messages->notice('Page Updated');
$ctx->db->query($query, $params);
$ctx->messages->notice('Page Updated');
}
// -------------------------
@@ -106,11 +106,11 @@ try {
// -------------------------
$tagManager->setTagsForPage($id, $tags);
} catch (Exception $e) {
$messages->error($e->getMessage());
$redirect->url($url_error);
} catch (\Exception $e) {
$ctx->messages->error($e->getMessage());
$ctx->redirect->url($url_error);
makeitso();
}
// Redirect back to edit page
$redirect->url('/novaconium/page/edit/' . $id);
$ctx->redirect->url('/novaconium/page/edit/' . $id);
+15
View File
@@ -0,0 +1,15 @@
<?php
$ctx->withData([
'title' => 'Novaconium Settings',
'pageclass' => 'novaconium',
'pageid' => 'controlPanel'
]);
if ( empty($ctx->session->get('username'))) {
$ctx->redirect->url('/novaconium/login');
$ctx->messages->error('You are not loggedin');
makeitso();
}
view('@novacore/settings', $ctx->data);
+3 -3
View File
@@ -10,7 +10,7 @@ $query=<<<EOSQL
AND draft = 0
ORDER BY updated DESC;
EOSQL;
$thepages = $db->getRows($query);
$thepages = $ctx->db->getRows($query);
// Start the view
echo '<?xml version="1.0" encoding="UTF-8"?>';
@@ -25,9 +25,9 @@ if ( ! empty($thepages) ) {
echo "<url>";
if ( empty($v['path']) )
echo "<loc>" . $config['base_url'] . '/page/' . $v['slug'] . "</loc>";
echo "<loc>" . $ctx->config['base_url'] . '/page/' . $v['slug'] . "</loc>";
else
echo "<loc>" . $config['base_url'] . $v['path'] . "</loc>";
echo "<loc>" . $ctx->config['base_url'] . $v['path'] . "</loc>";
echo "<lastmod>" . $date . "</lastmod>";
echo "<changefreq>" . $v['changefreq'] . "</changefreq>";
+1 -1
View File
@@ -8,7 +8,7 @@ Update novaconium with composer in docker: ```docker run --rm --interactive --tt
## Install Composer natively on Debian
Assuming you have nala installed:
Assuming you have nala installed (otherwise use apt-get):
```bash
sudo nala install curl php-cli php-mbstring git unzip
+101
View File
@@ -0,0 +1,101 @@
# Router
`Novaconium\Router` resolves the current HTTP request to a controller file, based on a route table defined in PHP config files. It supports exact-match routes and simple parameterized routes (e.g. `/users/{id}`).
## How it works
On construction, the router runs through this pipeline:
1. **Load routes** — merges framework-level routes with app-level routes.
2. **Prepare path** — normalizes `REQUEST_URI` into a clean path string.
3. **Prepare query** — parses the query string into an array.
4. **Determine request type**`get` or `post`.
5. **Find controller** — matches the path against the route table.
6. **Resolve controller file** — turns the matched controller string into an actual file path, falling back to a 404 controller if needed.
## Properties
| Property | Type | Description |
|---|---|---|
| `$routes` | array | Combined route table (framework + app routes), keyed by path pattern. |
| `$query` | array | Parsed query string parameters. |
| `$path` | string | Normalized request path. |
| `$controller` | string | Resolved controller identifier (e.g. `Users/show` or `NOVACONIUM/Errors`). |
| `$controllerPath` | string | Absolute file path to the controller. |
| `$parameters` | array | Named parameters extracted from a parameterized route match. |
| `$requestType` | string | `'get'` or `'post'`. |
## Route table format
Routes are defined as an associative array, keyed by URL path. Each entry maps HTTP methods to a controller string:
```php
$routes = [
'/' => [
'get' => 'Home/index',
],
'/users/{id}' => [
'get' => 'Users/show',
],
'/login' => [
'get' => 'Auth/loginForm',
'post' => 'Auth/login',
],
];
```
Controller strings starting with `NOVACONIUM` are resolved against the framework's controller directory (e.g. `NOVACONIUM/Errors``FRAMEWORKPATH/controllers/Errors.php`); all other controller strings are resolved against the app's controller directory (`BASEPATH/App/controllers/`).
## Matching behavior
### 1. Exact match
The router first checks for an exact match between `$this->path` and a key in `$this->routes`. If found, and the current request type has a handler defined, that controller is returned immediately.
### 2. Parameterized match
If no exact match is found, the router scans the route table for patterns containing `{`. For each candidate:
- The **static prefix** of the pattern (everything before the first `{`) must prefix-match the current path.
- The pattern and the path must have the **same number of `/`-separated segments**.
The first route pattern satisfying both conditions is treated as the match — the router does not keep searching for a "better" match after this point, even if the matched route turns out to have no handler for the current request method (see [Known quirks](#known-quirks) below).
Once a candidate route is selected, the router walks its segments looking for the first `{param}` segment, extracts the corresponding path segment into `$this->parameters[paramName]`, and returns immediately with the controller for the current request type.
### 3. No match
If neither an exact nor a parameterized match is found, `$this->controller` is set to `'404'`, and `setRouteFile()` will fail to find a corresponding controller file, triggering the 404 fallback described below.
## Controller file resolution (`setRouteFile`)
Given the resolved `$this->controller` string:
1. If it starts with `NOVACONIUM`, look in `FRAMEWORKPATH/controllers/`.
2. Otherwise, look in `BASEPATH/App/controllers/`.
3. If the file exists, use it.
4. If not, fall back to `BASEPATH/App/controllers/404.php` if it exists.
5. Otherwise, fall back to the framework's built-in `FRAMEWORKPATH/controllers/404.php`.
## Known quirks
These behaviors exist in the current implementation and are preserved intentionally for backward compatibility — they're documented here so they aren't mistaken for bugs during future changes.
- **Only the first `{param}` in a route pattern is captured.** If a route pattern has multiple parameters (e.g. `/users/{id}/posts/{postId}`), only `id` is extracted into `$this->parameters`; `postId` is never processed, because the matching loop returns as soon as it finds the first parameter segment.
- **The first prefix+segment-count match wins, even without a method handler.** If a parameterized route's static prefix and segment count match the request, but that route has no handler defined for the current request type (e.g. the route only defines `get` but the request is `post`), the router still commits to that route and returns `null` as the controller (which then falls through to the 404 controller). It does **not** continue searching for another route that might have a valid handler.
- **No support for trailing wildcard or optional segments.** Segment counts must match exactly between the pattern and the path; there's no support for `*` or optional `{param?}` style segments.
## Debugging
Call `$router->debug()` to dump the resolved path, controller path, extracted parameters, and full route table as an HTML table, then halt execution via `die()`. Intended for development use only.
## Example
```php
$router = new \Novaconium\Router();
include $router->controllerPath;
// Inside the controller, access route parameters via:
$router->parameters['id'];
```
+10
View File
@@ -21,3 +21,13 @@ Compressed:
docker run --rm -v "$(pwd):/usr/src/app" -w /usr/src/app sass-container --style=compressed sass/novaconium.sass skeleton/novaconium/public/css/novaconium.css
```
Dev:
```bash
docker run --rm \
-v "$(pwd)/sass:/usr/src/sass" \
-v "/home/nick/tmp/novaproject/novaconium/public/css:/usr/src/css" \
-w /usr/src \
sass-container \
sass sass/novaconium.sass css/novaconium.css --no-source-map --style=compressed
```
+94
View File
@@ -0,0 +1,94 @@
body#coming-soon
display: flex
justify-content: center
align-items: center
height: 100%
padding: 1rem
box-sizing: border-box
margin: 0
text-align: center
color: #eee
font-family: 'Segoe UI', Roboto, sans-serif
background-size: cover
background-repeat: no-repeat
background-position: center center
background-attachment: fixed
.container
max-width: 600px
background-color: rgba(30, 30, 30, 0.89)
padding: 2rem
border-radius: 8px
box-shadow: 0 0 20px rgba(0,0,0,0.5)
h1
font-size: 3rem
margin-bottom: 1rem
animation: pulse 1.5s infinite
p
font-size: 1.2rem
opacity: 0.85
margin-bottom: 1.5rem
.countdown
font-size: 2rem
font-weight: bold
margin: 1rem 0 2rem 0
form.newsletter
display: flex
flex-direction: column
gap: 0.5rem
margin-top: 1rem
input[type="email"]
padding: 0.5rem
font-size: 1rem
border: 1px solid #666
border-radius: 4px
background: rgba(255,255,255,0.05)
color: #eee
button
padding: 0.5rem
font-size: 1rem
border: 1px solid #1e90ff
border-radius: 4px
background: #1e90ff
color: #fff
cursor: pointer
transition: background 0.2s
&:hover
background: #1565c0
.social-icons
margin-top: 2rem
display: flex
justify-content: center
gap: 1rem
a
display: inline-flex
align-items: center
justify-content: center
width: 40px
height: 40px
font-size: 1.5rem
color: #eee
text-decoration: none
transition: color 0.2s
&:hover
color: #1e90ff
i
font-style: normal
@keyframes pulse
0%, 100%
opacity: 0.8
50%
opacity: 1
+4
View File
@@ -0,0 +1,4 @@
body#controlPanel
footer
padding: 1rem
+8
View File
@@ -0,0 +1,8 @@
body#controlPanel
header
padding: 0
h1#biglogo
padding: 10px 0 0 0
margin: 0
+11
View File
@@ -0,0 +1,11 @@
body#controlPanel
div#panel
main#content
flex: 1
padding: 20px 40px
min-width: 0
background-color: #0b0b0bd6
border-left: 2px solid #104910
+22
View File
@@ -0,0 +1,22 @@
@use '../abstracts' as *
body#controlPanel
div#panel
div#cp-menu
background-color: #000
width: 360px
padding: 0
white-space: nowrap
ul#cp-nav
list-style: none
margin: 0
padding: 20px 0 0 0
li a
display: block
border-bottom: 1px solid $border-light
padding: 4px 10px
&:hover
background-color: #222
+5
View File
@@ -0,0 +1,5 @@
body#controlPanel
div#panel
display: flex
flex-direction: row
+10
View File
@@ -0,0 +1,10 @@
@forward 'header';
@forward 'panel';
@forward 'menu';
@forward 'main';
@forward 'footer';
body#controlPanel
h1
font-family: "VT323", "Courier New", "SF Mono", "Fira Code", Consolas, monospace
font-size: 48px
+1 -1
View File
@@ -3,7 +3,7 @@
@use '../abstracts' as *
@use 'sass:color' // For color.adjust()non-deprecated color tweaks
body.novaconium
body#controlPanel
// Simplified tab styling: Square borders, no rounds
.tab-container
margin: space('lg') auto
+1 -1
View File
@@ -74,7 +74,7 @@ body.novaconium
display: inline-flex
align-items: center
background: color.adjust($accent-light, $alpha: -0.2)
color: $accent-light
color: #fff
padding: space('xs') space('sm')
border-radius: 4px
font-size: 12px
+2
View File
@@ -2,3 +2,5 @@
@use 'abstracts' as *
@use 'base' as *
@use 'framework' as *
@use 'controlPanel' as *
@use 'coming-soon' as *
+2 -8
View File
@@ -1,14 +1,13 @@
# Sample Docker Compose
services:
corxn:
image: 4lights/corxn:6.0.0
image: 4lights/corxn:8.5.3
ports:
- "8000:80"
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
- ./novaconium:/data
- ./data/logs:/var/log/apache2 # Optional Logs
- "./logs:/data/logs"
restart: unless-stopped
networks:
- internal
@@ -28,8 +27,6 @@ services:
MYSQL_USER: novaconium
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
- ./data/db:/var/lib/mysql
networks:
- internal
@@ -48,9 +45,6 @@ services:
- PMA_USER=root
- PMA_PASSWORD=${MYSQL_ROOT_PASSWORD}
- UPLOAD_LIMIT=200M
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
networks:
proxy:
+3 -1
View File
@@ -10,6 +10,8 @@ $config = [
'base_url' => 'http://localhost:8000',
'secure_key' => '', //64 alphanumeric characters
'logfile' => '/logs/novaconium.log',
'loglevel' => 'ERROR', // 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'NONE'
'loglevel' => 'ERROR', // 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'NONE',
'matomo_url' => 'matomo.4lt.ca',
'matomo_id' => '0',
'fonts' => 'https://fonts.googleapis.com/css2?family=VT323:wght@400&family=Fira+Code:wght@400;500&display=swap&family=Material+Icons:wght@400;500&display=swap'
];
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
header('Content-Type: text/plain; charset=UTF-8');
header('Cache-Control: public, max-age=604800');
echo <<<TXT
/*
* This humans.txt was generated by the framework.
* You may edit or remove it without affecting your site.
*/
/* FRAMEWORK */
Built With: Novaconium PHP
repo: https://git.4lt.ca/4lt/novaconium
Human: Nick Yeoman
url: https://www.nickyeoman.com/
Occupation: Linux Systems Administrator / Software Framework Author
Location: Canada
/* SITE */
Built with: Novaconium PHP
Runs on: CORXN Container
Optimized for: Humans
/* META */
There are four lights.
TXT;
@@ -1,2 +1,7 @@
<?php
$ctx->withData([
'title' => 'Welcome to Novaconium Index Page',
'pageclass' => 'novaconium'
]);
view('index');
@@ -0,0 +1,32 @@
<?php
$slug = $ctx->router->parameters['slug'];
$query=<<<EOSQL
SELECT
id,
title,
heading,
description,
keywords,
author,
body,
created,
updated
FROM pages
WHERE slug = ?
EOSQL;
$page = $ctx->db->getRow($query, [$slug]);
if(!$page) {
http_response_code('404');
header("Content-Type: text/html");
view('404');
exit;
}
$ctx->withData(array_merge($page, [
'menuActive' => 'blog',
'pageid' => 'page',
'permissionsGroup' => $ctx->session->get('group')
]));
view('page', $ctx->data);
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
// Send proper headers
header('Content-Type: text/plain; charset=UTF-8');
header('Cache-Control: public, max-age=604800');
// Use $config['base_url'] as-is
$baseUrl = $ctx->config['base_url'];
echo <<<TXT
# robots.txt for sites powered by Novaconium framework
User-agent: *
Disallow: /novaconium/
Sitemap: {$baseUrl}/sitemap.xml
TXT;
+9
View File
@@ -2,5 +2,14 @@
$routes = [
'/' => [
'get' => 'index'
],
'/robots.txt' => [
'get' => 'robots'
],
'/humans.txt' => [
'get' => 'humans'
],
'/page/{slug}' => [
'get' => 'page'
]
];
@@ -0,0 +1,11 @@
{% extends '@novaconium/master.html.twig' %}
{% block content %}
<h1>{{ title }}</h1>
<div class="page-meta">
{% if updated is not empty %}
<span class="page-updated">Last Updated: {{ updated | date("M\\. jS Y \\a\\t g:ia") }}</span>
{% endif %}
</div>
{{ body | raw}}
{% endblock %}
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
{"version":3,"sourceRoot":"","sources":["../../../../sass/abstracts/_variables.sass","../../../../sass/base/_reset.sass","../../../../sass/base/_background.sass","../../../../sass/framework/_main.sass","../../../../sass/framework/_ui.sass","../../../../sass/framework/_forms.sass","../../../../sass/framework/_login_form.sass","../../../../sass/framework/_logo.sass","../../../../sass/framework/_tabs.sass","../../../../sass/framework/_edit_page.sass","../../../../sass/framework/_tooltip.sass","../../../../sass/framework/_ace.sass","../../../../sass/framework/_tags.sass"],"names":[],"mappings":"CAoEA,MACE,0BACA,8BACA,+BACA,mCACA,iCACA,oCACA,qCACA,qCACA,kCACA,yCACA,8CC1EF,EACE,sBAEF,KACE,eACA,gBACA,uBACA,iBDWQ,aCVR,MDYW,KCVb,KACE,SACA,UACA,YDgBW,kCCfX,iBDIQ,aCHR,MDKW,KCJX,iBAGF,kBACE,gBACA,gBACA,gBACA,qBAEF,GACE,iBAEF,GACE,eAEF,GACE,kBAEF,GACE,iBAEF,GACE,kBAEF,GACE,eAGF,EACE,eAEF,MACE,kBAEF,SACE,gBAEF,KACE,kBAGF,EACE,MDnCa,eCoCb,qBACA,sCACA,iCAEA,gBACE,oBDzCW,eC0CX,aAGJ,MACE,eACA,mBAEF,GACE,oBAGF,WACE,aACA,iBACA,qCACA,kCACA,MD7DW,KCgEb,cACE,YDvDU,uDCwDV,iBACA,oCACA,qBACA,kBAEF,IACE,aACA,YACA,cACA,oCACA,kBACA,SACE,gBACA,UAGJ,MACE,WACA,yBACA,aAEF,MACE,cACA,gBACA,2CAEF,GACE,gBAGF,6BACE,oBACA,kBACA,oCACA,MDpGW,KCqGX,oCACA,kBACA,aAEA,qDACE,aACA,aDxGW,eCyGX,wCAEJ,OACE,eACA,qCAEA,gBACE,WACA,mBAGJ,IACE,eACA,YACA,kBAEF,OACE,aAGF,GACE,YACA,WACA,oCACA,aAGF,gBACE,iCACA,mBAGF,aACE,KACE,2BACA,uBAEJ,YACE,8BACA,MDnJW,KCsJb,kBACE,8BACA,MDxJW,KEtBb,gBACI,sBACA,0uKCEF,iCACE,aACA,UACA,uBACA,uBACA,mBAGF,wBACE,aACA,cACA,aACA,SACA,iBHGM,aGFN,gCAEF,2BACE,YACA,cACA,gBACA,UACA,oBACA,iBHNM,aGON,gCAEF,4BACE,6CAEA,uCACE,mBAEJ,2BACE,cACA,mBACA,qBACA,MHjBS,KGmBT,kEACE,oCACA,MHlBS,eGmBT,kBAGJ,0BACE,iCACE,sBACA,mBAEF,iDACE,WACA,gBACA,cAEF,yBACE,gBCtDJ,qBACE,2EACA,kBACA,gCACA,MJcS,KIbT,qBACA,kBACA,sCACA,sCAGF,uBACE,kBAGF,+EACE,mBACA,YACA,eACA,kBACA,iBAEF,0BACE,oCACA,qBACA,4BAEF,2BACE,sCACA,uBACA,8BAEF,0BACE,gCACA,MJdS,iBIeT,kCACA,gBACA,mBAGF,6BACE,WACA,sCAEA,gEACE,sCACA,gBAEF,gCACE,qCACA,MJ/BS,iBIgCT,gBClDF,uDACE,mBAEA,0EACE,WACA,gBAEJ,2DACE,kBAGF,gOAIE,gCACA,sCACA,WACA,cACA,kBACA,2EAEA,wPACE,aLHO,eKIP,2CACA,aAEJ,gEACE,aLRS,eKWX,+DACE,iBLZS,eKaT,mBACA,YACA,mBACA,kBACA,eACA,2EAEA,0IACE,sBACA,sCAGJ,6CACE,ML3BO,iBK6BT,6CACE,ML7BS,eK+BT,mDACE,MLlCO,iBKmCP,0BCzDR,uBAEE,UAIA,+HAGE,WACA,gBACA,aACA,mBACA,sBACA,eACA,sCACA,kBACA,WNEM,aMDN,MNGS,6CMCT,uUACA,4BACA,gCACA,qBACA,kBAEF,4CACE,iVACA,4BACA,gCACA,qBACA,kBAEF,2CACE,WNZW,eMaX,aNbW,eMcX,eACA,0BAEA,iDACE,WNlBS,eMmBT,uCAGF,kDACE,aACA,kBCnDJ,yBACE,kBACA,qBACA,eACA,gBACA,gBAEA,iCACE,WACA,kBACA,MACA,OACA,QACA,SACA,gJACA,0BACA,WACA,oBAGF,gCACE,WACA,kBACA,MACA,OACA,QACA,WACA,qEACA,YACA,kCAEF,+BACE,cACA,kCACA,iBACA,gBACA,WACA,oBACA,gBACA,yBAGA,yFACA,mDAEF,8BACE,cACA,kCACA,iBACA,gBACA,WACA,qBACA,iBACA,0EACA,mDAIA,qCACE,8BAEN,gBACE,GACE,SACF,KACE,UAEJ,kBACE,QACE,uBACF,IACE,+BACF,IACE,gCACF,IACE,8BACF,IACE,gCCvEJ,+BACE,mBACA,WRcM,aQZR,yBACE,aACA,iBRWQ,eQVR,6CAEF,4BACE,mBACA,WRMQ,eQLR,sCACA,mBACA,eACA,eACA,gBACA,kBACA,WACA,YRSQ,uDQPR,kCACE,iCAEF,wCACE,iBAEF,mCACE,iBRZI,aQaJ,uCACA,MRTS,eQUT,iBAEJ,6BACE,aACA,eACA,iBRpBM,aQqBN,MRnBS,KQoBT,YAEA,oCACE,cC5CN,iBACI,gBAEA,wBACI,WACA,iBACA,aAEJ,qBACI,gBACA,oBCRN,yBACE,kBACA,qBACA,YACA,eACA,MViBW,eUhBX,mBACA,QAEA,sCACE,kBACA,YACA,iBVMM,eULN,MVMO,KULP,gBACA,gBACA,cACA,eACA,aACA,UACA,uBACA,eACA,oCACA,oBAEA,6CACE,WACA,kBACA,SACA,UACA,iBACA,mBACA,sEAEJ,4CACE,mBACA,UAGJ,8BACE,kBACA,aC1CJ,kBACE,WACA,iBAEF,YACE,aACA,gCACA,YXuBU,uDWpBV,wBACE,qCACA,kCACA,iDAEF,0BACE,mCAEF,8CACE,oCAGF,6CACE,yCCtBF,+BACE,kBACA,SACA,OACA,QACA,iBACA,gBACA,WZWQ,eYVR,sCACA,gBACA,0BACA,gBACA,SACA,UACA,WACA,UACA,kBACA,uBAEA,mDACE,UACA,mBAEF,kCACE,qBACA,eACA,MZPO,KYQP,eACA,sCAEA,mFAEE,8BACA,MZXO,eYaT,6CACE,mBAEN,4BACE,kBAGF,4BACE,aACA,eACA,WACA,mBACA,sCACA,eACA,WZ/BQ,eYgCR,gBACA,cAEA,kCACE,YACA,yBACA,MZrCO,KYsCP,YZ5BM,uDY6BN,eACA,OACA,gBACA,aAEA,+CACE,MZ3CK,iBY6CX,0BACE,oBACA,mBACA,8BACA,MZhDW,eYiDX,qBACA,kBACA,eACA,gBACA,gBACA,uBACA,mBAEA,sCACE,gBACA,YACA,cACA,eACA,mBACA,eACA,UACA,cAEA,4CACE,WAWN,2EACE","file":"novaconium.css"}
+1 -13
View File
@@ -1,22 +1,10 @@
<?php
/**
* Novaconium Framework Entry Point
*
* This is the main entry point for the Novaconium framework.
* It sets up the environment, loads necessary components,
* and runs the application.
*
* @package Novaconium
* @author Nick Yeoman <dev@4lt.ca>
*/
// Enable error reporting for development environments
// error_reporting(E_ALL);
// ini_set('display_errors', 1);
// Define the base path where the website is running from
define('BASEPATH', dirname(__DIR__, 1));
define('BASEPATH', dirname(__DIR__));
// Load Composer's autoload file to handle class autoloading
require BASEPATH . '/vendor/autoload.php';
+185
View File
@@ -0,0 +1,185 @@
// /js/tabs.js
// Tab switching
function switchTab(tabId, button) {
const contents = document.querySelectorAll('.tab-content');
contents.forEach(content => content.classList.remove('active'));
const buttons = document.querySelectorAll('.tab-button');
buttons.forEach(b => b.classList.remove('active'));
document.getElementById(tabId).classList.add('active');
button.classList.add('active');
if (tabId === 'content6') {
setTimeout(initTags, 0);
}
}
// Tags Init (with custom dropdown autocomplete)
let tagsListeners = [];
function initTags() {
const tagsInput = document.getElementById('tags-input');
const tagsField = document.getElementById('tags');
const hiddenTags = document.getElementById('tags_json');
const dropdown = document.getElementById('tags-dropdown');
if (!tagsInput || !tagsField || !hiddenTags || !dropdown) {
console.warn('Tags elements missing');
return;
}
// Remove old listeners
tagsListeners.forEach(ls => ls());
tagsListeners = [];
let tags = [];
let existingTags = [];
try {
tags = JSON.parse(tagsInput.dataset.tags || '[]');
existingTags = JSON.parse(tagsInput.dataset.existingTags || '[]');
} catch (e) {
console.warn('JSON error:', e);
}
let selectedIndex = -1;
function renderTags() {
tagsInput.innerHTML = '';
tags.forEach((tag, index) => {
const chip = document.createElement('span');
chip.className = 'tag-chip';
chip.innerHTML = `${tag} <button type="button" class="tag-remove">&times;</button>`;
chip.querySelector('.tag-remove').onclick = () => {
tags.splice(index, 1);
renderTags();
hiddenTags.value = JSON.stringify(tags);
};
tagsInput.appendChild(chip);
});
tagsInput.appendChild(tagsField);
tagsInput.appendChild(dropdown);
hiddenTags.value = JSON.stringify(tags);
}
function updateDropdown() {
const value = tagsField.value.toLowerCase().trim();
dropdown.innerHTML = '';
dropdown.setAttribute('aria-expanded', value ? 'true' : 'false');
selectedIndex = -1;
if (!value) return;
const matches = existingTags
.filter(tag => tag.toLowerCase().startsWith(value) && !tags.includes(tag.toLowerCase()))
.slice(0, 10);
matches.forEach((tag, index) => {
const li = document.createElement('li');
li.textContent = tag;
li.setAttribute('role', 'option');
li.onclick = () => selectTag(tag);
li.onmouseover = () => { selectedIndex = index; updateHighlight(); };
dropdown.appendChild(li);
});
if (matches.length) dropdown.parentElement.classList.add('has-dropdown');
else dropdown.parentElement.classList.remove('has-dropdown');
}
function updateHighlight() {
dropdown.querySelectorAll('li').forEach((li, index) => {
li.classList.toggle('selected', index === selectedIndex);
});
}
function selectTag(tag) {
addTag(tag, true);
tagsField.value = '';
dropdown.setAttribute('aria-expanded', 'false');
}
function addTag(inputValue, refocus = false) {
const tag = inputValue.trim().toLowerCase().replace(/[^\w-]/g, '');
if (tag && tag.length > 0 && tag.length <= 50 && !tags.includes(tag)) {
tags.push(tag);
renderTags();
if (refocus) tagsField.focus();
}
tagsField.value = '';
updateDropdown();
}
const keydownListener = (e) => {
if (dropdown.getAttribute('aria-expanded') === 'true') {
if (e.key === 'ArrowDown') {
e.preventDefault();
selectedIndex = Math.min(selectedIndex + 1, dropdown.querySelectorAll('li').length - 1);
updateHighlight();
dropdown.querySelector(`li:nth-child(${selectedIndex + 1})`)?.scrollIntoView({ block: 'nearest' });
} else if (e.key === 'ArrowUp') {
e.preventDefault();
selectedIndex = Math.max(selectedIndex - 1, 0);
updateHighlight();
dropdown.querySelector(`li:nth-child(${selectedIndex + 1})`)?.scrollIntoView({ block: 'nearest' });
} else if ((e.key === 'Enter' || e.key === 'Tab') && selectedIndex >= 0) {
e.preventDefault();
const selected = dropdown.querySelector(`li:nth-child(${selectedIndex + 1})`)?.textContent;
if (selected) selectTag(selected);
} else if (e.key === 'Escape') {
e.preventDefault();
tagsField.blur();
}
}
if (!dropdown.getAttribute('aria-expanded') === 'true' || selectedIndex < 0) {
if (e.key === 'Enter' || e.key === ',') {
e.preventDefault();
addTag(tagsField.value, true);
} else if (e.key === 'Tab') {
e.preventDefault();
if (tagsField.value.trim()) addTag(tagsField.value, true);
}
}
};
tagsField.addEventListener('keydown', keydownListener);
tagsListeners.push(() => tagsField.removeEventListener('keydown', keydownListener));
const inputListener = () => updateDropdown();
tagsField.addEventListener('input', inputListener);
tagsListeners.push(() => tagsField.removeEventListener('input', inputListener));
const blurListener = () => {
setTimeout(() => dropdown.setAttribute('aria-expanded', 'false'), 150);
if (tagsField.value.trim()) addTag(tagsField.value);
};
tagsField.addEventListener('blur', blurListener);
tagsListeners.push(() => tagsField.removeEventListener('blur', blurListener));
renderTags();
}
// Init on load and observe tab changes
document.addEventListener('DOMContentLoaded', () => {
const tagsTab = document.getElementById('content6');
if (tagsTab?.classList.contains('active')) {
initTags();
}
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
const target = mutation.target;
if (target.id === 'content6' && target.classList.contains('active')) {
initTags();
}
}
});
});
observer.observe(document.body, { subtree: true, attributes: true });
});
// Export switchTab for external use if needed
window.switchTab = switchTab;
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace Novaconium;
final class Context
{
public function __construct(
public array $config,
public Logger $log,
public Session $session,
public MessageHandler $messages,
public ?Database $db,
public ?Post $post,
public Redirect $redirect,
public Router $router,
public array $data = [],
) {}
/**
* Merge additional values into the Twig data array.
*/
public function withData(array $more): static
{
$this->data = array_merge($this->data, $more);
return $this;
}
}
+5 -5
View File
@@ -25,7 +25,7 @@ class Database {
// Prepare the SQL statement
$stmt = $this->conn->prepare($query);
if (!$stmt) {
throw new Exception("Query preparation failed: " . $this->conn->error);
throw new \Exception("Query preparation failed: " . $this->conn->error);
}
// Bind parameters if needed
@@ -37,7 +37,7 @@ class Database {
// Execute the statement
if (!$stmt->execute()) {
$stmt->close();
throw new Exception("Query execution failed: " . $stmt->error);
throw new \Exception("Query execution failed: " . $stmt->error);
}
// Save last insert id if it's an INSERT query
@@ -70,7 +70,7 @@ class Database {
// Prepare the SQL statement
$stmt = $this->conn->prepare($query);
if (!$stmt) {
throw new Exception("Query preparation failed: " . $this->conn->error);
throw new \Exception("Query preparation failed: " . $this->conn->error);
}
// Bind parameters
@@ -82,7 +82,7 @@ class Database {
// Execute the statement
if (!$stmt->execute()) {
$stmt->close();
throw new Exception("Query execution failed: " . $stmt->error);
throw new \Exception("Query execution failed: " . $stmt->error);
}
// Get result
@@ -92,7 +92,7 @@ class Database {
$stmt->close();
return $row;
} catch (Exception $e) {
} catch (\Exception $e) {
echo "An error occurred: " . $e->getMessage();
return null;
}
+1 -1
View File
@@ -21,7 +21,7 @@ class MessageHandler {
// Add a message of a specific type
public function addMessage($type, $message) {
if (!isset($this->messages[$type])) {
throw new Exception("Invalid message type: $type");
throw new \Exception("Invalid message type: $type");
}
$this->messages[$type][] = $message;
}
+139 -75
View File
@@ -1,5 +1,6 @@
<?php
namespace Novaconium;
class Router {
public $routes = [];
public $query = [];
@@ -10,120 +11,185 @@ class Router {
public $requestType = 'get';
public function __construct() {
$this->routes = $this->loadRoutes();
$this->path = $this->preparePath();
$this->query = $this->prepareQuery();
$this->requestType = $this->getRequestType();
$this->controller = $this->findController();
$this->controllerPath = $this->setRouteFile();
$this->routes = $this->loadRoutes();
$this->path = $this->preparePath();
$this->query = $this->prepareQuery();
$this->requestType = $this->getRequestType();
$this->controller = $this->findController();
$this->controllerPath = $this->setRouteFile();
}
/**
* Merge framework routes with app-defined routes (app routes can override framework routes).
*/
private function loadRoutes() {
require_once( \FRAMEWORKPATH . '/config/routes.php');
// Check if Path exists
if (file_exists(\BASEPATH . '/App/routes.php')) {
require_once( \BASEPATH . '/App/routes.php');
}
$routes = array_merge((array)$routes, (array)$framework_routes);
require_once(\FRAMEWORKPATH . '/config/routes.php');
return $routes;
if (file_exists(\BASEPATH . '/App/routes.php')) {
require_once(\BASEPATH . '/App/routes.php');
}
return array_merge((array)$routes, (array)$framework_routes);
}
/**
* Normalize the request path: strip query string, trailing slash, and anything after "&".
*/
private function preparePath() {
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
//homepage
if ($path === '/') {
return $path;
}
// remove empty directory path
$path = rtrim($path, '/'); // remove trailing slash
//remove anything after and including ampersand
$path = rtrim($path, '/');
$path = preg_replace('/&.+$/', '', $path);
return $path;
}
private function prepareQuery() {
$parsedUri = parse_url($_SERVER['REQUEST_URI']);
$parsedUri = parse_url($_SERVER['REQUEST_URI']);
$queryArray = [];
if (isset($parsedUri['query'])) {
parse_str($parsedUri['query'], $queryArray);
}
return $queryArray;
}
private function getRequestType() {
// is the requewst a get or post?
if (empty($_POST)) {
return 'get';
} else {
return 'post';
}
return empty($_POST) ? 'get' : 'post';
}
/**
* Resolve the current path to a controller string.
* First tries an exact match, then falls back to matching parameterized
* routes like "/users/{id}".
*/
private function findController() {
// one to one match
if (array_key_exists($this->path, $this->routes)) {
if (!empty($this->routes[$this->path][$this->requestType])) {
return $this->routes[$this->path][$this->requestType];
}
$exactMatch = $this->findExactMatch();
if ($exactMatch !== null) {
return $exactMatch;
}
foreach ($this->routes as $key => $value) {
// Check if key contains a curly bracket, if not continue. We already checked above.
if (!strpos($key, '{')) continue;
// Remove everything after the curly bracket, from key
$keyPath = substr($key, 0, strpos($key, '{'));
//see if keyPath matches the first characters of $this->path, only the first characters have to match
if (strpos($this->path, $keyPath) === 0) {
// We have a potential match. Now check if the parameter count is equal
$keyParams = explode('/', $key);
$pathParams = explode('/', $this->path);
$keyParamCount = count($keyParams);
$pathParamCount = count($pathParams);
if ($keyParamCount === $pathParamCount) {
for ($i=0; $i < $pathParamCount; $i++) {
if (strpos($keyParams[$i], '{') !== false) {
$keyParams[$i] = substr($keyParams[$i], 1, -1);
$this->parameters[$keyParams[$i]] = $pathParams[$i];
return $this->routes[$key][$this->requestType];
}
}
}
}
$paramMatch = $this->findParameterizedMatch();
if ($paramMatch !== null) {
return $paramMatch;
}
return '404';
}
// checks if the file exists, sets file path
private function setRouteFile() {
if (str_starts_with($this->controller, 'NOVACONIUM')) {
$trimmed = substr($this->controller, strlen('NOVACONIUM/'));
$cp = \FRAMEWORKPATH . '/controllers/' . $trimmed . '.php';
} else {
$cp = \BASEPATH . '/App/controllers/' . $this->controller . '.php';
private function findExactMatch() {
if (array_key_exists($this->path, $this->routes)
&& !empty($this->routes[$this->path][$this->requestType])
) {
return $this->routes[$this->path][$this->requestType];
}
if (file_exists($cp)) {
return $cp;
} else {
//Check if 404 exits
if (file_exists( \BASEPATH . '/App/controllers/404.php')) {
return \BASEPATH . '/App/controllers/404.php';
} else {
return \FRAMEWORKPATH . '/controllers/404.php';
return null;
}
/**
* Loop over parameterized routes (those containing "{") looking for the
* first one whose static prefix matches the path AND whose segment count
* matches. As soon as such a route is found, control is handed off to
* extractControllerFromMatch(), which returns immediately (even with a
* `null` controller) -- this mirrors the original code's behavior of
* stopping the search on the first prefix+segment-count match, rather
* than continuing on to try other candidate routes.
*/
private function findParameterizedMatch() {
foreach ($this->routes as $routePattern => $methods) {
// Only parameterized routes (containing "{") are relevant here;
// plain routes were already checked in findExactMatch().
if (strpos($routePattern, '{') === false) {
continue;
}
if (!$this->routeMatchesPath($routePattern)) {
continue;
}
if (!$this->segmentCountsMatch($routePattern)) {
continue;
}
// Original behavior: once we find a route with a matching prefix
// and segment count, we commit to it -- even if it turns out
// there's no handler for the current request method.
return $this->extractControllerFromMatch($routePattern, $methods);
}
return null;
}
/**
* Quick check: does the static portion of the route pattern (everything
* before the first "{") prefix-match the current path?
*/
private function routeMatchesPath($routePattern) {
$staticPrefix = substr($routePattern, 0, strpos($routePattern, '{'));
return strpos($this->path, $staticPrefix) === 0;
}
private function segmentCountsMatch($routePattern) {
$patternSegments = explode('/', $routePattern);
$pathSegments = explode('/', $this->path);
return count($patternSegments) === count($pathSegments);
}
/**
* Extracts named parameters into $this->parameters and returns the
* controller for the current request type (or null if that method
* isn't defined for this route).
*
* Matches the original quirk: only the FIRST "{param}" segment found
* gets added to $this->parameters, and the method returns right away --
* any additional "{param}" segments later in the pattern are never
* processed. This is preserved as-is rather than "fixed", since
* behavior should stay unchanged.
*/
private function extractControllerFromMatch($routePattern, $methods) {
$patternSegments = explode('/', $routePattern);
$pathSegments = explode('/', $this->path);
foreach ($patternSegments as $i => $segment) {
if (strpos($segment, '{') !== false) {
$paramName = substr($segment, 1, -1); // strip { }
$this->parameters[$paramName] = $pathSegments[$i];
return $methods[$this->requestType] ?? null;
}
}
return null;
}
/**
* Resolve the controller string to an actual file path, falling back to a 404 controller.
*/
private function setRouteFile() {
if (str_starts_with($this->controller, 'NOVACONIUM')) {
$trimmed = substr($this->controller, strlen('NOVACONIUM/'));
$controllerPath = \FRAMEWORKPATH . '/controllers/' . $trimmed . '.php';
} else {
$controllerPath = \BASEPATH . '/App/controllers/' . $this->controller . '.php';
}
if (file_exists($controllerPath)) {
return $controllerPath;
}
if (file_exists(\BASEPATH . '/App/controllers/404.php')) {
return \BASEPATH . '/App/controllers/404.php';
}
return \FRAMEWORKPATH . '/controllers/404.php';
}
public function debug() {
@@ -137,6 +203,4 @@ class Router {
die();
}
}
+4 -3
View File
@@ -2,14 +2,15 @@
namespace Novaconium\Services;
use Novaconium\Database;
class TagManager
{
protected $db;
public function __construct()
public function __construct(?Database $db = null)
{
global $db;
$this->db = $db;
$this->db = $db ?? ($GLOBALS['ctx']->db ?? null) ?? ($GLOBALS['db'] ?? null);
}
/**
+12 -1
View File
@@ -24,7 +24,18 @@ function dd(...$vars): void {
* connection if configured, and performs a redirect.
*/
function makeitso(): void {
global $session, $db, $redirect, $config, $messages, $log;
global $session, $db, $redirect, $config, $messages, $log, $ctx;
// Prefer $ctx when available; its service properties are the same
// object instances as the bare globals, so this is behavior-neutral.
if (isset($ctx)) {
$session = $ctx->session;
$db = $ctx->db;
$redirect = $ctx->redirect;
$config = $ctx->config;
$messages = $ctx->messages;
$log = $ctx->log;
}
// ------------------------------
// Close database if configured
+31 -7
View File
@@ -1,5 +1,17 @@
<?php
use Novaconium\Logger;
use Novaconium\Session;
use Novaconium\MessageHandler;
use Novaconium\Database;
use Novaconium\Post;
use Novaconium\Redirect;
use Novaconium\Router;
use Novaconium\Context;
$db = null;
$post = null;
// --- Load Config ---
if (file_exists(\BASEPATH . '/App/config.php')) {
require_once \BASEPATH . '/App/config.php';
@@ -11,43 +23,55 @@ require_once \FRAMEWORKPATH . '/src/functions.php';
require_once \FRAMEWORKPATH . '/src/twig.php';
// --- Logging ---
use Novaconium\Logger;
$log = new Logger(\BASEPATH . $config['logfile'], $config['loglevel']);
// --- Twig Data Array ---
$data = [];
$data['fonts'] = $config['fonts'] ?? [];
$data['matomo_url'] = $config['matomo_url'] ?? '';
$data['matomo_id'] = $config['matomo_id'] ?? '0';
// --- Session ---
use Novaconium\Session;
$session = new Session();
$data['token'] = $session->get('token');
$data['username'] = $session->get('username');
// --- Messages ---
use Novaconium\MessageHandler;
$messages = new MessageHandler($session->flash('messages'));
foreach (['error', 'notice'] as $key) {
$data[$key] = $messages->showMessages($key);
}
// --- Database ---
use Novaconium\Database;
if (!empty($config['database']['host'])) {
$db = new Database($config['database']);
}
// --- POST Wrapper ---
use Novaconium\Post;
if (!empty($_POST)) {
$post = new Post($_POST);
}
// --- Redirect Handler ---
use Novaconium\Redirect;
$redirect = new Redirect();
// --- Router ---
use Novaconium\Router;
$router = new Router();
// --- Typed Context ---
// Bundles the globals above into one typed object. The bare globals are
// left in place (same object instances) so existing plain-script
// controllers keep working unmodified; new controllers can use $ctx.
$ctx = new Context(
config: $config,
log: $log,
session: $session,
messages: $messages,
db: $db,
post: $post,
redirect: $redirect,
router: $router,
data: $data,
);
require_once $router->controllerPath;
+9 -2
View File
@@ -15,13 +15,20 @@ use Twig\Loader\FilesystemLoader;
*/
function view(string $name = '', array $moreData = []): bool
{
global $config, $data;
global $config, $data, $ctx;
if (!is_array($data)) {
$data = [];
}
if (!empty($moreData)) {
// Reconcile the bare $data global with $ctx->data: either style of
// controller ($data = array_merge($data, [...]) or $ctx->withData([...]))
// ends up folded in here, regardless of which one was used.
if (isset($ctx)) {
$data = array_merge($data, $ctx->data, $moreData);
$ctx->data = $data;
$config = $ctx->config;
} elseif (!empty($moreData)) {
$data = array_merge($data, $moreData);
}
+71
View File
@@ -0,0 +1,71 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ title | default('Coming Soon') }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/novaconium.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
body {
background: url("{{ bg_image | default('https://w.wallhaven.cc/full/5y/wallhaven-5yymk9.jpg') }}") no-repeat center center fixed;
background-size: cover;
}
</style>
</head>
<body id="coming-soon">
<div class="container">
<h1>{{ heading | default('Coming Soon') }}</h1>
{% block content %}{% endblock %}
{% if countdown %}
<div class="countdown" id="countdown"></div>
{% endif %}
{# TODO: listmonk #}
<form class="newsletter" action="#" method="post">
<label for="email">Subscribe to our newsletter:</label>
<input type="email" id="email" name="email" placeholder="Your email address" required>
<button type="submit">Subscribe</button>
</form>
{# Social media icons using Font Awesome #}
<div class="social-icons">
{% block social %}{% endblock %}
</div>
</div>
{% if countdown %}
<script>
{% if countdown %}
{% set default_launch = "now"|date_modify("+30 days")|date("Y-m-d\TH:i:s") %}
const launchDate = new Date('{{ launch_date | default(default_launch) }}').getTime();
const countdownEl = document.getElementById('countdown');
function updateCountdown() {
const now = new Date().getTime();
const distance = launchDate - now;
if (distance <= 0) {
countdownEl.innerText = 'Launched!';
return;
}
const days = Math.floor(distance / (1000*60*60*24));
const hours = Math.floor((distance % (1000*60*60*24)) / (1000*60*60));
const mins = Math.floor((distance % (1000*60*60)) / (1000*60));
const secs = Math.floor((distance % (1000*60)) / 1000);
countdownEl.innerText = `${days}d ${hours}h ${mins}m ${secs}s`;
}
updateCountdown();
setInterval(updateCountdown, 1000);
{% endif %}
</script>
{% endif %}
</body>
</html>
+44
View File
@@ -0,0 +1,44 @@
<!doctype html>
<html class="no-js" lang="en">
<head>
{% include ['@novaconium/cp/head.html.twig'] %}
</head>
<body id="{{ pageid | default('pageid') }}" class="{{ pageclass | default('pageclass') }}" >
{# Page Header #}
<header>
<h1 id="biglogo"><span class="main">Novaconium</span></h1>
</header>
<!-- Main Content Of The Page -->
<div id="panel" class="container">
{% include ['@novaconium/cp/menu.html.twig'] %}
<main id="content">
{% block content %}{% endblock %}
</main>
</div>
{# Page Footer #}
<footer>
<div class="copyright">&copy; {{ 'now' | date('Y') }} Novaconium</div>
</footer>
{% if editor == 'ace' %}
{% include '@novaconium/javascript/page-edit.html.twig' %}
{% include '@novaconium/javascript/ace.html.twig' %}
{% endif %}
{% if debug is not empty %}
<div id="debug">
<h2>Debugging Information</h2>
{{ debug|raw }}
</div>
{% endif %}
</body></html>
+60
View File
@@ -0,0 +1,60 @@
{# =============================================================================
<HEAD>
=============================================================================
#}
<meta charset="utf-8">
<title>{{ title | default('Welcome To Novaconium') }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
{# SEO & METADATA #}
<meta name="generator" content="Novaconium" />
<meta name="description" content="{{ description | default('No description given') }}">
<meta name="keywords" content="{{ keywords | default('website') }}">
<meta name="author" content="{{ author | default('anonymous') }}">
{# DARK MODE & THEME HINTS #}
<meta name="color-scheme" content="dark">
<meta name="theme-color" content="#000000">
{# OPEN GRAPH (OG) FOR SOCIAL SHARING #}
<meta property="og:title" content="{{ title | default('Welcome') }}">
<meta property="og:type" content="website">
<meta property="og:url" content="{{ app_url | default(request.scheme ~ '://' ~ request.host) }}">
<meta property="og:image" content="{{ og_image | default('/icon.png') }}">
{# PWA & FAVICONS #}
<link rel="manifest" href="site.webmanifest">
<link rel="apple-touch-icon" href="/icon.png">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
{# GOOGLE FONTS (CDN VIA PRECONNECT) #}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="{{ fonts | default('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=Roboto+Mono&family=Source+Code+Pro&family=Lato&family=Poppins&family=Material+Icons&family=Material+Icons+Outlined&family=VT323:wght@400&family=Fira+Code:wght@400;500&display=swap') }}"
rel="stylesheet"
>
{% if editor == 'ace' %}
<!-- ACE Editor -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/ace.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/mode-html.min.js"></script> {# HTML syntax #}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/theme-tomorrow_night.min.js"></script> {# Dark theme #}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/ext-language_tools.min.js"></script> {# Autocomplete #}
<!-- END ACE Editor -->
{% endif %}
{# highlight.js #}
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/ir-black.min.css">
<script src="/js/tabs.js"></script>
{# STYLESHEET #}
<link rel="stylesheet" href="/css/novaconium.css">
+9
View File
@@ -0,0 +1,9 @@
<div id="cp-menu">
<ul id="cp-nav">
<li><a href="/novaconium/dashboard">Dashboard</a></li>
<li><a href="/novaconium/pages">Pages</a></li>
<li><a href="/novaconium/messages">Messages</a></li>
<li><a href="/novaconium/settings">Settings</a></li>
<li><a href="/novaconium/logout">Logout</a></li>
</ul>
</div>
+1 -7
View File
@@ -1,11 +1,5 @@
<!--
What goes very last on the page.
right before the /body
like javascript
or analytics
such as javascript
-->
{% include '@novaconium/javascript/page-edit.html.twig' %}
{% if editor == 'ace' %}
{% include '@novaconium/javascript/ace.html.twig' %}
{% endif %}
+1 -3
View File
@@ -1,3 +1 @@
<!--
What goes in the footer html tag
-->
<div class="copyright">&copy; {{ 'now' | date('Y') }} Novaconium</div>
+1 -16
View File
@@ -39,22 +39,7 @@
>
{# STYLESHEET #}
{% if pageclass == "novaconium" %}
<link rel="stylesheet" href="/css/novaconium.css">
{% else %}
<link rel="stylesheet" href="/css/main.css">
{% endif %}
{% if editor == 'ace' %}
<!-- ACE Editor -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/ace.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/mode-html.min.js"></script> {# HTML syntax #}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/theme-tomorrow_night.min.js"></script> {# Dark theme #}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.35.2/ext-language_tools.min.js"></script> {# Autocomplete #}
<!-- END ACE Editor -->
{% endif %}
<link rel="stylesheet" href="/css/novaconium.css">
{# highlight.js #}
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
+28
View File
@@ -60,4 +60,32 @@
{% endif %}
{% include ['@override/foot.html.twig', '@novaconium/foot.html.twig'] %}
{% if matomo_id > 0 %}
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
{% if is_404 %}
_paq.push([
'setDocumentTitle',
'404 / Not Found - ' + document.location.pathname
]);
{% endif %}
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u = "//{{ matomo_url|trim('/') }}/";
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', {{ matomo_id }}]);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
})();
</script>
<!-- End Matomo Code -->
{% endif %}
</body></html>
+1
View File
@@ -1,3 +1,4 @@
{% set is_404 = status_code is defined and status_code == 404 %}
{% extends '@novaconium/master.html.twig' %}
{% block content %}
+32
View File
@@ -0,0 +1,32 @@
{% extends '@novaconium/coming-soon/index.html.twig' %}
{% set bg_image = "https://i.4lt.ca/4lt/waterBubbles.webp" %}
{% set default_launch = "now"|date_modify("+30 days")|date("Y-m-d\TH:i:s") %}
{% block content %}
<p>Our website is under construction. Were working hard to bring you a better experience.</p>
<p>Stay tuned for updates!</p>
{% endblock %}
{% block social %}
<a href="mailto:you@example.com" title="Email">
<i class="fa-solid fa-envelope"></i>
</a>
<a href="tel:+1234567890" title="Phone">
<i class="fa-solid fa-phone"></i>
</a>
<a href="#" title="Twitter">
<i class="fab fa-twitter"></i>
</a>
<a href="#" title="Facebook">
<i class="fab fa-facebook-f"></i>
</a>
<a href="#" title="Instagram">
<i class="fab fa-instagram"></i>
</a>
{% endblock %}
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends '@novaconium/master.html.twig' %}
{% extends '@novaconium/cp/control-panel.html.twig' %}
{% block content %}
<h1>{{title}}</h1>
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends '@novaconium/master.html.twig' %}
{% extends '@novaconium/cp/control-panel.html.twig' %}
{% block content %}
<h2>Edit Page - {{ title }}</h2>
+13
View File
@@ -14,3 +14,16 @@
<div id="body-editor" class="ace-editor"></div> {# Ace mounts here #}
</div>
</div>
<div class="form-group">
<label for="draft">
<input
type="checkbox"
id="draft"
name="draft"
value="1"
{% if rows.draft|default(false) %}checked{% endif %}
>
Save as draft
</label>
</div>
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends '@novaconium/master.html.twig' %}
{% extends '@novaconium/cp/control-panel.html.twig' %}
{% block content %}
<h1>{{title}}</h1>
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends '@novaconium/master.html.twig' %}
{% extends '@novaconium/cp/control-panel.html.twig' %}
{% block content %}
<h1>{{title}}</h1>
+6
View File
@@ -0,0 +1,6 @@
{% extends '@novaconium/cp/control-panel.html.twig' %}
{% block content %}
<h1>{{title}}</h1>
<p>Settings will go here.</p>
{% endblock %}