|
|
|
@ -7,132 +7,151 @@ class ThemeEngine
|
|
|
|
|
public $data = [];
|
|
|
|
|
public $loader;
|
|
|
|
|
public $twig;
|
|
|
|
|
|
|
|
|
|
public function __construct(string $themePath, string $themeAssetPath)
|
|
|
|
|
{
|
|
|
|
|
$var = [];
|
|
|
|
|
$this->themePath = $themePath;
|
|
|
|
|
$this->themeAssetPath = $themeAssetPath;
|
|
|
|
|
$path = explode("/", $themeAssetPath);
|
|
|
|
|
$path = explode('/', $themeAssetPath);
|
|
|
|
|
$this->themeFolder = $path[4];
|
|
|
|
|
$this->settings = json_decode(
|
|
|
|
|
file_get_contents("./data/settings.json"),
|
|
|
|
|
file_get_contents('./data/settings.json'),
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$this->posts = json_decode(file_get_contents("./data/posts.json"), true);
|
|
|
|
|
$this->posts = json_decode(file_get_contents('./data/posts.json'), true);
|
|
|
|
|
$this->archives = json_decode(
|
|
|
|
|
file_get_contents("./data/archives.json"),
|
|
|
|
|
file_get_contents('./data/archives.json'),
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$this->loader = new \Twig\Loader\FilesystemLoader(
|
|
|
|
|
$themePath . "/" . $path[4]
|
|
|
|
|
$themePath.'/'.$path[4]
|
|
|
|
|
);
|
|
|
|
|
$this->twig = new \Twig\Environment($this->loader, []);
|
|
|
|
|
$this->router($_SERVER["REQUEST_URI"]);
|
|
|
|
|
$this->router($_SERVER['REQUEST_URI']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function router(string $request)
|
|
|
|
|
{
|
|
|
|
|
$pageInfo = [
|
|
|
|
|
"keywords" => $this->settings["keywords"],
|
|
|
|
|
"description" => $this->settings["description"],
|
|
|
|
|
"image" => $this->themeAssetPath . "/assets/images/global/default-bg.jpg",
|
|
|
|
|
'keywords' => $this->settings['keywords'],
|
|
|
|
|
'description' => $this->settings['description'],
|
|
|
|
|
'image' => $this->themeAssetPath.'/assets/images/global/default-bg.jpg',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$featureList = explode(",", $this->posts["feature"]);
|
|
|
|
|
$fileList = explode(",", $this->posts["files"]);
|
|
|
|
|
$featureList = explode(',', $this->posts['feature']);
|
|
|
|
|
$fileList = explode(',', $this->posts['files']);
|
|
|
|
|
|
|
|
|
|
$images = [];
|
|
|
|
|
$files = [];
|
|
|
|
|
foreach ($featureList as $file) {
|
|
|
|
|
$item = trim($file);
|
|
|
|
|
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
|
|
|
|
if ($item != null || $item != "") {
|
|
|
|
|
array_push($images, ["file" => $item, "type" => trim($ext)]);
|
|
|
|
|
if ($item != null || $item != '') {
|
|
|
|
|
array_push($images, ['file' => $item, 'type' => trim($ext)]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($fileList as $file) {
|
|
|
|
|
$item = trim($file);
|
|
|
|
|
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
|
|
|
|
if ($item != null || $item != "") {
|
|
|
|
|
array_push($files, ["file" => $item, "type" => trim($ext)]);
|
|
|
|
|
if ($item != null || $item != '') {
|
|
|
|
|
array_push($files, ['file' => $item, 'type' => trim($ext)]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$menu = $this->settings["menu"];
|
|
|
|
|
$menu = $this->settings['menu'];
|
|
|
|
|
switch ($request) {
|
|
|
|
|
case "/":
|
|
|
|
|
$recent = $this->posts["recent_posts"];
|
|
|
|
|
$featured = $this->posts["featured_posts"];
|
|
|
|
|
$template = "index.twig";
|
|
|
|
|
$content = $this->posts["index-content"];
|
|
|
|
|
case '/':
|
|
|
|
|
$recent = $this->posts['recent_posts'];
|
|
|
|
|
$featured = $this->posts['featured_posts'];
|
|
|
|
|
$template = 'index.twig';
|
|
|
|
|
$content = $this->posts['index-content'];
|
|
|
|
|
|
|
|
|
|
$pageOptions = [
|
|
|
|
|
"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,
|
|
|
|
|
'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,
|
|
|
|
|
];
|
|
|
|
|
break;
|
|
|
|
|
case "/page":
|
|
|
|
|
$content = $this->posts["content"];
|
|
|
|
|
$meta = $this->posts["meta"];
|
|
|
|
|
$template = $request . ".twig";
|
|
|
|
|
case '/page':
|
|
|
|
|
$content = $this->posts['content'];
|
|
|
|
|
$meta = $this->posts['meta'];
|
|
|
|
|
$template = $request.'.twig';
|
|
|
|
|
$pageOptions = [
|
|
|
|
|
"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,
|
|
|
|
|
'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,
|
|
|
|
|
];
|
|
|
|
|
break;
|
|
|
|
|
case "/tags":
|
|
|
|
|
$tags = $this->settings["tag_list"];
|
|
|
|
|
$template = $this->themeFolder . "/tags.twig";
|
|
|
|
|
case '/tags':
|
|
|
|
|
$tags = $this->settings['tag_list'];
|
|
|
|
|
$template = 'tags.twig';
|
|
|
|
|
$pageOptions = [
|
|
|
|
|
"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,
|
|
|
|
|
'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,
|
|
|
|
|
'media' => $images,
|
|
|
|
|
'files' => $files,
|
|
|
|
|
];
|
|
|
|
|
break;
|
|
|
|
|
case "/archive":
|
|
|
|
|
case '/archive':
|
|
|
|
|
$archive = $this->archives;
|
|
|
|
|
$template = $this->themeFolder . "/archive.twig";
|
|
|
|
|
$template = 'archive.twig';
|
|
|
|
|
$pageOptions = [
|
|
|
|
|
"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,
|
|
|
|
|
"info" => $pageInfo,
|
|
|
|
|
"menu" => $menu,
|
|
|
|
|
'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,
|
|
|
|
|
'media' => $images,
|
|
|
|
|
'files' => $files,
|
|
|
|
|
];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
http_response_code(404);
|
|
|
|
|
require __DIR__ . "/views/404.php";
|
|
|
|
|
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
|
|
|
|
// throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
|
|
|
|
|
$error = $errstr;
|
|
|
|
|
});
|
|
|
|
|
$template = 'error.twig';
|
|
|
|
|
$pageOptions = [
|
|
|
|
|
'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,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|