This commit is contained in:
Flummi 2024-03-29 17:30:25 +01:00
parent 7619856ef2
commit 9b0ff69205
6 changed files with 19 additions and 17 deletions

View File

@ -1,6 +1,4 @@
<?php <?php
$config = require_once __DIR__ . '/../config.php';
$db = new PDO( $db = new PDO(
$config->sql->dsn, $config->sql->dsn,
$config->sql->user, $config->sql->user,
@ -10,4 +8,3 @@ $db = new PDO(
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
] ]
); );
?>

View File

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
$_page = isset($_GET['p']) ? $_GET['p'] : ''; $_page = isset($_GET['p']) ? $_GET['p'] : '';
$routes = [ $routes = [
@ -9,6 +11,7 @@ $routes = [
]; ];
ob_start(); ob_start();
require_once __DIR__ . "/../pages/{$routes[array_key_exists($_page, $routes)?$_page:'default']}.php"; require_once __DIR__ . "/../pages/{$routes[array_key_exists($_page, $routes)?$_page:'default']}.php";
$_content = ob_get_contents(); $_content = ob_get_contents();

View File

@ -1,8 +1,6 @@
<?php <?php
class tpl { class tpl {
static $blocks = array(); static $blocks = array();
static $views_path = '/home/users/flumm/www/dev.fwtrash.de/views/';
static $cache_path = '/home/users/flumm/tmp/';
static function view($file, $data = array()) { static function view($file, $data = array()) {
$cached_file = self::cache($file); $cached_file = self::cache($file);
@ -12,9 +10,10 @@ class tpl {
} }
static function cache($file) { static function cache($file) {
if(!file_exists(self::$cache_path)) global $config;
mkdir(self::$cache_path, 0744); if(!file_exists($config->env->cache))
$cached_file = self::$cache_path . str_replace(array('/', '.html'), array('_', ''), $file . '.php'); mkdir($config->env->cache, 0744);
$cached_file = $config->env->cache . str_replace(array('/', '.html'), array('_', ''), $file . '.php');
if(!file_exists($cached_file) || filemtime($cached_file) < filemtime($file)) { if(!file_exists($cached_file) || filemtime($cached_file) < filemtime($file)) {
$code = self::includeFiles($file); $code = self::includeFiles($file);
$code = self::compileCode($code); $code = self::compileCode($code);
@ -33,7 +32,8 @@ class tpl {
} }
static function includeFiles($file) { static function includeFiles($file) {
$code = file_get_contents(self::$views_path . $file); global $config;
$code = file_get_contents($config->env->views . $file);
preg_match_all('/{% ?(extends|include) ?\'?(.*?)\'? ?%}/i', $code, $matches, PREG_SET_ORDER); preg_match_all('/{% ?(extends|include) ?\'?(.*?)\'? ?%}/i', $code, $matches, PREG_SET_ORDER);
foreach($matches as $value) foreach($matches as $value)
$code = str_replace($value[0], self::includeFiles($value[2]), $code); $code = str_replace($value[0], self::includeFiles($value[2]), $code);
@ -72,4 +72,3 @@ class tpl {
return preg_replace('/{% ?yield ?(.*?) ?%}/i', '', $code); return preg_replace('/{% ?yield ?(.*?) ?%}/i', '', $code);
} }
} }
?>

View File

@ -1,9 +1,6 @@
<?php <?php
session_start(); require_once __DIR__ . '/config.php';
require_once __DIR__ . '/inc/db.inc.php';
error_reporting(0);
ini_set('display_errors', 0);
require_once __DIR__ . '/inc/tpl.class.php'; require_once __DIR__ . '/inc/tpl.class.php';
require_once __DIR__ . '/inc/router.inc.php'; require_once __DIR__ . '/inc/router.inc.php';
@ -15,7 +12,8 @@ if(!@$tpl->debug) {
tpl::view($tpl->file, tpl::view($tpl->file,
array_merge([ array_merge([
'page' => $_page, 'page' => $_page,
'generated' => $generated 'generated' => $generated,
'basepath' => $config->env->basepath
], ],
gettype($tpl->data) !== 'string' ? $tpl->data : []) gettype($tpl->data) !== 'string' ? $tpl->data : [])
); );

View File

@ -1,2 +1,7 @@
<?php <?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once '../index.php'; require_once '../index.php';

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<base href="https://fwtrash.de/"> <base href="{{ $basepath ?? "https://fwtrash.de" }}">
<title>{% yield title %}</title> <title>{% yield title %}</title>
<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="./css/style.css"> <link rel="stylesheet" type="text/css" href="./css/style.css">