save
This commit is contained in:
parent
27df1a73b5
commit
a0cb5fb6b0
36 changed files with 1886 additions and 187 deletions
167
public/index.php
167
public/index.php
|
@ -4,6 +4,7 @@
|
|||
//
|
||||
use app\app;
|
||||
use app\controllers\account;
|
||||
use app\controllers\admin;
|
||||
use app\controllers\category;
|
||||
use app\controllers\cart;
|
||||
use app\controllers\checkout;
|
||||
|
@ -12,6 +13,7 @@ use app\controllers\lnurlp;
|
|||
use app\controllers\lost;
|
||||
use app\controllers\magic_link;
|
||||
use app\controllers\support;
|
||||
use app\controllers\transaction;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
|
@ -20,36 +22,6 @@ Dotenv\Dotenv::createImmutable(__DIR__ . '/../')->load();
|
|||
|
||||
// Start the session
|
||||
app::init_db();
|
||||
use app\models\addresses;
|
||||
use app\models\cart_items;
|
||||
use app\models\carts;
|
||||
use app\models\magic_links;
|
||||
use app\models\order_items;
|
||||
use app\models\orders;
|
||||
use app\models\products;
|
||||
use app\models\quote_items;
|
||||
use app\models\quotes;
|
||||
use app\models\subscriptions;
|
||||
use app\models\transactions;
|
||||
use app\models\user_addresses;
|
||||
use app\models\users;
|
||||
|
||||
if (!app::$db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='users'")->fetch()) {
|
||||
addresses::init();
|
||||
cart_items::init();
|
||||
carts::init();
|
||||
magic_links::init();
|
||||
order_items::init();
|
||||
orders::init();
|
||||
products::init();
|
||||
quote_items::init();
|
||||
quotes::init();
|
||||
subscriptions::init();
|
||||
transactions::init();
|
||||
user_addresses::init();
|
||||
users::init();
|
||||
}
|
||||
|
||||
session_start();
|
||||
session_regenerate_id(true); // prevent session fixation attacks
|
||||
|
||||
|
@ -63,76 +35,20 @@ if (!isset($_SESSION['fingerprint'])) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// these will be available to use in all twig templates
|
||||
$defaults = [
|
||||
'copyright_year' => date('Y'),
|
||||
'session' => $_SESSION,
|
||||
'http_host' => $_SERVER['HTTP_HOST'],
|
||||
'env' => $_ENV,
|
||||
'is_admin' => isset($_SESSION['user_id']) && $_SESSION['user_id'] == 1,
|
||||
// uses cookie-js to get the client's preferred theme
|
||||
// used to conditionally deliver image assets
|
||||
// or styles based on theme
|
||||
'theme' => isset($_COOKIE["theme"]) ? $_COOKIE["theme"] : 'light',
|
||||
// set your tailwind colors here for app themeing
|
||||
// the idea is to avoid using colors in your templates
|
||||
'colors' => [
|
||||
'header' => [
|
||||
'banner' => 'bg-gray-100 dark:bg-gray-600 text-gray-200 dark:text-gray-200',
|
||||
|
||||
],
|
||||
'anchor' => [
|
||||
'primary' => 'text-blue-400 dark:text-blue-200'
|
||||
],
|
||||
'body' => 'bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-300',
|
||||
'button' => [
|
||||
'primary' => 'border-blue-400 dark:border-blue-600 dark:hover:border-blue-800 bg-blue-400 dark:bg-blue-600 hover:bg-blue-600 hover:dark:bg-blue-800 text-white dark:text-white',
|
||||
'default' => 'hover:bg-gray-50 dark:hover:bg-gray-900'
|
||||
],
|
||||
'breadcrumb' => [
|
||||
'parent' => 'text-gray-300 dark:text-gray-400 hover:text-gray-400 dark:hover:text-gray-500',
|
||||
'seperator' => 'text-gray-200 dark:text-gray-200',
|
||||
'child' => 'text-gray-200 dark:text-gray-300'
|
||||
],
|
||||
'dropdown' => [
|
||||
'list' => 'bg-white dark:bg-blue-900 border-gray-600 dark:border-gray-300',
|
||||
'item' => 'hover:bg-gray-200 dark:hover:bg-gray-900'
|
||||
],
|
||||
'input' => 'text-gray-800 dark:text-gray-300 bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-500 focus:ring-blue-500',
|
||||
'error' => [
|
||||
'text' => 'text-red-600',
|
||||
'alert' => 'bg-red-100 text-gray-800 border-red-600'
|
||||
],
|
||||
'warning' => [
|
||||
'text' => 'text-yellow-400',
|
||||
'alert' => 'bg-yellow-100 text-gray-800 border-yellow-400'
|
||||
],
|
||||
'success' => [
|
||||
'text' => 'text-green-600',
|
||||
'alert' => 'bg-green-100 text-gray-800 border-green-600'
|
||||
],
|
||||
'info' => [
|
||||
'text' => 'text-blue-400',
|
||||
'alert' => 'bg-blue-200 text-gray-800 border-blue-400'
|
||||
],
|
||||
'modal' => [
|
||||
'content' => 'bg-white dark:bg-blue-900 border-gray-600 dark:border-gray-300',
|
||||
'shadow' => 'bg-black/70'
|
||||
],
|
||||
'nav' => [
|
||||
'bar' => 'bg-blue-400 dark:bg-blue-600 text-gray-200 dark:text-gray-200',
|
||||
'item' => 'hover:bg-blue-600 dark:hover:bg-blue-800 hover:text-gray-200 dark:hover:text-gray-300 text-white border-blue-400 dark:border-blue-600',
|
||||
'hovercontent' => 'bg-white dark:bg-slate-700 text-gray-800 dark:text-gray-300'
|
||||
],
|
||||
'rule' => 'border-gray-400 dark:border-gray-400',
|
||||
'text' => [
|
||||
'muted' => 'text-gray-400 dark:text-gray-300'
|
||||
],
|
||||
'toggle' => "bg-gray-300 peer-checked:bg-green-400 after:bg-white",
|
||||
'footer' => [
|
||||
"primary" => "bg-gray-200 dark:bg-slate-600 text-gray-500 dark:text-gray-300",
|
||||
"policy" => "bg-slate-400 dark:bg-slate-800 text-gray-200 dark:text-gray-400"
|
||||
],
|
||||
]
|
||||
'colors' => require dirname(__DIR__) . '/src/colors.php',
|
||||
];
|
||||
|
||||
// Setup a twig
|
||||
|
@ -147,29 +63,56 @@ if (str_starts_with(haystack: $route, needle: '/.well-known/lnurlp/')) {
|
|||
$route = '/lnurlp';
|
||||
}
|
||||
|
||||
$controller = match ($route) {
|
||||
'/' => home::index($defaults),
|
||||
'/account' => account::index($defaults),
|
||||
'/account/profile' => account::profile(),
|
||||
'/account/login' => account::login($defaults),
|
||||
'/account/email' => account::email(),
|
||||
'/account/logout' => account::logout(),
|
||||
'/magic-link' => magic_link::index(),
|
||||
'/account/returns' => account::returns($defaults),
|
||||
'/account/signup' => account::signup($defaults),
|
||||
'/account/billing' => account::billing($defaults),
|
||||
'/account/orders' => account::orders($defaults),
|
||||
'/account/shipping' => account::shipping($defaults),
|
||||
'/checkout/confirmed' => checkout::confirmed($defaults),
|
||||
'/checkout/review-pay' => checkout::review_pay($defaults),
|
||||
'/checkout/shipping-billing' => checkout::shipping_billing($defaults),
|
||||
'/support/ask' => support::index($defaults),
|
||||
'/support/bitcoin' => support::bitcoin($defaults),
|
||||
'/cart' => cart::index($defaults),
|
||||
'/lnurlp' => lnurlp::index(),
|
||||
// product categories
|
||||
'/power-meters' => category::power_meters($defaults),
|
||||
default => lost::index($defaults)
|
||||
// Combined regex to match multiple dynamic routes in one go
|
||||
if (preg_match('/^\/(transaction|user|order|product)\/([\w-]+)$/', $route, $matches)) {
|
||||
[$full, $type, $id] = $matches;
|
||||
$controllers = [
|
||||
'transaction' => fn($id) => transaction::view($defaults, $id),
|
||||
'user' => fn($id) => users::view($id),
|
||||
'order' => fn($id) => orders::view($id),
|
||||
'quote' => fn($id) => quotes::view($id),
|
||||
'product' => fn($id) => products::view($id),
|
||||
'subscription' => fn($id) => subscriptions::view($id),
|
||||
'cart' => fn($id) => cart::index($id),
|
||||
];
|
||||
|
||||
if (isset($controllers[$type])) {
|
||||
$controller = $controllers[$type]($id);
|
||||
}
|
||||
} else {
|
||||
$controller = match ($route) {
|
||||
'/' => home::index($defaults),
|
||||
'/account' => account::index($defaults),
|
||||
'/account/profile' => account::profile(),
|
||||
'/account/login' => account::login($defaults),
|
||||
'/account/email' => account::email(),
|
||||
'/account/logout' => account::logout(),
|
||||
'/account/returns' => account::returns($defaults),
|
||||
'/account/signup' => account::signup($defaults),
|
||||
'/account/billing' => account::billing($defaults),
|
||||
'/account/orders' => account::orders($defaults),
|
||||
'/account/shipping' => account::shipping($defaults),
|
||||
'/account/verify' => account::verify($defaults),
|
||||
'/admin' => $defaults['is_admin'] ? admin::index($defaults) : lost::index($defaults),
|
||||
'/admin/users' => $defaults['is_admin'] ? admin::users($defaults) : lost::index($defaults),
|
||||
'/admin/orders' => $defaults['is_admin'] ? admin::orders($defaults) : lost::index($defaults),
|
||||
'/admin/emails' => $defaults['is_admin'] ? admin::emails($defaults) : lost::index($defaults),
|
||||
'/admin/transactions' => $defaults['is_admin'] ? admin::transactions($defaults) : lost::index($defaults),
|
||||
'/admin/transactions/add' => $defaults['is_admin'] ? admin::transactions_add($defaults) : lost::index($defaults),
|
||||
'/admin/transactions/reset' => $defaults['is_admin'] ? admin::transactions_reset($defaults) : lost::index($defaults),
|
||||
'/admin/returns' => $defaults['is_admin'] ? admin::returns($defaults) : lost::index($defaults),
|
||||
'/magic-link' => magic_link::index(),
|
||||
'/checkout/confirmed' => checkout::confirmed($defaults),
|
||||
'/checkout/review-pay' => checkout::review_pay($defaults),
|
||||
'/checkout/shipping-billing' => checkout::shipping_billing($defaults),
|
||||
'/support/ask' => support::index($defaults),
|
||||
'/support/bitcoin' => support::bitcoin($defaults),
|
||||
'/cart' => cart::index($defaults),
|
||||
'/lnurlp' => lnurlp::index(),
|
||||
// product categories
|
||||
'/power-meters' => category::power_meters($defaults),
|
||||
default => lost::index($defaults)
|
||||
};
|
||||
};
|
||||
|
||||
// Clear alerts after rendering
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue