This commit is contained in:
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
$config = require_once __DIR__ . '/../config.php';
$db = new PDO(
$config->sql->dsn,
$config->sql->user,
@ -10,4 +8,3 @@ $db = new PDO(
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
]
);
?>

View File

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

View File

@ -1,8 +1,6 @@
<?php
class tpl {
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()) {
$cached_file = self::cache($file);
@ -12,9 +10,10 @@ class tpl {
}
static function cache($file) {
if(!file_exists(self::$cache_path))
mkdir(self::$cache_path, 0744);
$cached_file = self::$cache_path . str_replace(array('/', '.html'), array('_', ''), $file . '.php');
global $config;
if(!file_exists($config->env->cache))
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)) {
$code = self::includeFiles($file);
$code = self::compileCode($code);
@ -33,7 +32,8 @@ class tpl {
}
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);
foreach($matches as $value)
$code = str_replace($value[0], self::includeFiles($value[2]), $code);
@ -72,4 +72,3 @@ class tpl {
return preg_replace('/{% ?yield ?(.*?) ?%}/i', '', $code);
}
}
?>