2022-03-18 22:04:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace engine;
|
|
|
|
|
|
|
|
class ThemeEngine
|
|
|
|
{
|
|
|
|
public $data = [];
|
|
|
|
public $loader;
|
|
|
|
public $twig;
|
2022-03-20 22:58:27 +01:00
|
|
|
|
2022-03-18 22:04:48 +01:00
|
|
|
public function __construct(string $themePath, string $themeAssetPath)
|
|
|
|
{
|
2022-10-21 22:35:12 +02:00
|
|
|
$var = [];
|
|
|
|
$this->themePath = $themePath;
|
2022-03-18 22:04:48 +01:00
|
|
|
$this->themeAssetPath = $themeAssetPath;
|
2022-10-21 22:35:12 +02:00
|
|
|
$path = explode('/', $themeAssetPath);
|
|
|
|
$this->themeFolder = $path[4];
|
|
|
|
$this->settings = json_decode(
|
2022-03-20 22:58:27 +01:00
|
|
|
file_get_contents('./data/settings.json'),
|
2022-03-18 22:04:48 +01:00
|
|
|
true
|
|
|
|
);
|
2022-10-21 22:35:12 +02:00
|
|
|
$this->posts = json_decode(file_get_contents('./data/posts.json'), true);
|
2022-03-18 22:04:48 +01:00
|
|
|
$this->archives = json_decode(
|
2022-03-20 22:58:27 +01:00
|
|
|
file_get_contents('./data/archives.json'),
|
2022-03-18 22:04:48 +01:00
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->loader = new \Twig\Loader\FilesystemLoader(
|
2022-10-21 22:35:12 +02:00
|
|
|
$themePath . '/' . $path[4]
|
2022-03-18 22:04:48 +01:00
|
|
|
);
|
|
|
|
$this->twig = new \Twig\Environment($this->loader, []);
|
2022-03-20 22:58:27 +01:00
|
|
|
$this->router($_SERVER['REQUEST_URI']);
|
2022-03-18 22:04:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function router(string $request)
|
|
|
|
{
|
|
|
|
$pageInfo = [
|
2022-10-21 22:35:12 +02:00
|
|
|
'keywords' => $this->settings['keywords'],
|
|
|
|
'description' => $this->settings['description'],
|
|
|
|
'image' => $this->themeAssetPath . '/assets/images/global/default-bg.jpg',
|
2022-03-18 22:04:48 +01:00
|
|
|
];
|
|
|
|
|
2022-03-20 22:58:27 +01:00
|
|
|
$featureList = explode(',', $this->posts['feature']);
|
2022-10-21 22:35:12 +02:00
|
|
|
$fileList = explode(',', $this->posts['files']);
|
2022-03-18 22:04:48 +01:00
|
|
|
|
|
|
|
$images = [];
|
2022-10-21 22:35:12 +02:00
|
|
|
$files = [];
|
2022-03-18 22:04:48 +01:00
|
|
|
foreach ($featureList as $file) {
|
|
|
|
$item = trim($file);
|
2022-10-21 22:35:12 +02:00
|
|
|
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
2022-03-20 22:58:27 +01:00
|
|
|
if ($item != null || $item != '') {
|
|
|
|
array_push($images, ['file' => $item, 'type' => trim($ext)]);
|
2022-03-18 22:04:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($fileList as $file) {
|
|
|
|
$item = trim($file);
|
2022-10-21 22:35:12 +02:00
|
|
|
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
2022-03-20 22:58:27 +01:00
|
|
|
if ($item != null || $item != '') {
|
|
|
|
array_push($files, ['file' => $item, 'type' => trim($ext)]);
|
2022-03-18 22:04:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-20 22:58:27 +01:00
|
|
|
$menu = $this->settings['menu'];
|
2022-03-18 22:04:48 +01:00
|
|
|
switch ($request) {
|
2022-03-20 22:58:27 +01:00
|
|
|
case '/':
|
2022-10-21 22:35:12 +02:00
|
|
|
$recent = $this->posts['recent_posts'];
|
2022-03-20 22:58:27 +01:00
|
|
|
$featured = $this->posts['featured_posts'];
|
|
|
|
$template = 'index.twig';
|
2022-10-21 22:35:12 +02:00
|
|
|
$content = $this->posts['index-content-no-image'];
|
2022-03-18 22:04:48 +01:00
|
|
|
|
|
|
|
$pageOptions = [
|
2022-10-21 22:35:12 +02:00
|
|
|
'debug' => true, // for theme kit
|
|
|
|
'theme' => $this->themeFolder, // for theme kit
|
|
|
|
'title' => 'This is Fipamo',
|
|
|
|
'dynamicRender' => $this->settings['dynamicRender'],
|
|
|
|
'background' => $this->themeAssetPath . '/assets/images/global/default-bg.jpg',
|
|
|
|
'recent' => $recent,
|
|
|
|
'featured' => $featured,
|
|
|
|
'info' => $pageInfo,
|
|
|
|
'menu' => $menu,
|
|
|
|
'content' => $content,
|
|
|
|
'media' => $images,
|
|
|
|
'files' => $files,
|
2022-03-18 22:04:48 +01:00
|
|
|
];
|
|
|
|
break;
|
2022-03-20 22:58:27 +01:00
|
|
|
case '/page':
|
2022-10-21 22:35:12 +02:00
|
|
|
$content = $this->posts['content'];
|
|
|
|
$meta = $this->posts['meta'];
|
|
|
|
$template = $request . '.twig';
|
2022-03-18 22:04:48 +01:00
|
|
|
$pageOptions = [
|
2022-10-21 22:35:12 +02:00
|
|
|
'debug' => true, // for theme kit
|
|
|
|
'theme' => $this->themeFolder, // for theme kit
|
|
|
|
'title' => 'Page Title',
|
|
|
|
'dynamicRender' => $this->settings['dynamicRender'],
|
|
|
|
'background' => $this->themeAssetPath . '/assets/images/global/default-bg.jpg',
|
|
|
|
'content' => $content,
|
|
|
|
'meta' => $meta,
|
|
|
|
'info' => $pageInfo,
|
|
|
|
'menu' => $menu,
|
|
|
|
'media' => $images,
|
|
|
|
'files' => $files,
|
2022-03-18 22:04:48 +01:00
|
|
|
];
|
|
|
|
break;
|
2022-03-20 22:58:27 +01:00
|
|
|
case '/tags':
|
2022-10-21 22:35:12 +02:00
|
|
|
$tags = $this->settings['tag_list'];
|
|
|
|
$template = 'tags.twig';
|
2022-03-18 22:04:48 +01:00
|
|
|
$pageOptions = [
|
2022-10-21 22:35:12 +02:00
|
|
|
'debug' => true, // for theme kit
|
|
|
|
'theme' => $this->themeFolder, // for theme kit
|
|
|
|
'title' => 'Pages Tagged as Tag',
|
|
|
|
'dynamicRender' => $this->settings['dynamicRender'],
|
|
|
|
'background' => $this->themeAssetPath . '/assets/images/global/default-bg.jpg',
|
|
|
|
'tag_list' => $tags,
|
|
|
|
'info' => $pageInfo,
|
|
|
|
'menu' => $menu,
|
2022-03-18 22:04:48 +01:00
|
|
|
];
|
|
|
|
break;
|
2022-03-20 22:58:27 +01:00
|
|
|
case '/archive':
|
2022-10-21 22:35:12 +02:00
|
|
|
$archive = $this->archives;
|
|
|
|
$template = 'archive.twig';
|
2022-03-18 22:04:48 +01:00
|
|
|
$pageOptions = [
|
2022-10-21 22:35:12 +02:00
|
|
|
'debug' => true, // for theme kit
|
|
|
|
'theme' => $this->themeFolder, // for theme kit
|
|
|
|
'title' => 'Archive',
|
|
|
|
'dynamicRender' => $this->settings['dynamicRender'],
|
|
|
|
'background' => $this->themeAssetPath . '/assets/images/global/default-bg.jpg',
|
|
|
|
'archives' => $archive['archives'],
|
|
|
|
'info' => $pageInfo,
|
|
|
|
'menu' => $menu,
|
2022-03-18 22:04:48 +01:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
default:
|
2022-03-20 22:58:27 +01:00
|
|
|
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
|
|
|
// throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
|
|
|
|
$error = $errstr;
|
|
|
|
});
|
2022-10-21 22:35:12 +02:00
|
|
|
$template = 'error.twig';
|
2022-03-20 22:58:27 +01:00
|
|
|
$pageOptions = [
|
2022-10-21 22:35:12 +02:00
|
|
|
'debug' => true, // for theme kit
|
|
|
|
'theme' => $this->themeFolder, // for theme kit
|
|
|
|
'title' => 'Uh oh',
|
|
|
|
'dynamicRender' => $this->settings['dynamicRender'],
|
|
|
|
'background' => $this->themeAssetPath . '/assets/images/global/default-bg.jpg',
|
|
|
|
'info' => $pageInfo,
|
|
|
|
'content' => "Uh Oh, so there's a problem.",
|
|
|
|
'menu' => $menu,
|
|
|
|
'media' => $images,
|
|
|
|
'files' => $files,
|
2022-03-20 22:58:27 +01:00
|
|
|
];
|
|
|
|
|
2022-03-18 22:04:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $this->twig->render($template, $pageOptions);
|
|
|
|
}
|
|
|
|
}
|