respeced class imports to follow psr-4 standard
This commit is contained in:
parent
79fbc2437f
commit
fd4ff2ea52
5 changed files with 167 additions and 144 deletions
2
.prettierignore
Normal file
2
.prettierignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.php
|
||||
*.inc.php
|
|
@ -1,4 +1,9 @@
|
|||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"engine\\": "engine"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"twig/twig": "^3.0"
|
||||
}
|
||||
|
|
16
engine/StartKit.php
Normal file
16
engine/StartKit.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace engine;
|
||||
|
||||
class StartKit
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$settings = json_decode(file_get_contents("./package.json"), true);
|
||||
$theme = $settings["config"]["current_theme"];
|
||||
new ThemeEngine(
|
||||
"src/themes/theme-" . $theme,
|
||||
"/src/themes/theme-" . $theme . "/" . $theme
|
||||
);
|
||||
}
|
||||
}
|
141
engine/ThemeEngine.php
Normal file
141
engine/ThemeEngine.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
namespace engine;
|
||||
|
||||
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);
|
||||
$this->themeFolder = $path[4];
|
||||
$this->settings = json_decode(
|
||||
file_get_contents("./data/settings.json"),
|
||||
true
|
||||
);
|
||||
$this->posts = json_decode(file_get_contents("./data/posts.json"), true);
|
||||
$this->archives = json_decode(
|
||||
file_get_contents("./data/archives.json"),
|
||||
true
|
||||
);
|
||||
$this->loader = new \Twig\Loader\FilesystemLoader(
|
||||
$themePath . "/" . $path[4]
|
||||
);
|
||||
$this->twig = new \Twig\Environment($this->loader, []);
|
||||
$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",
|
||||
];
|
||||
|
||||
$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)]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($fileList as $file) {
|
||||
$item = trim($file);
|
||||
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
||||
if ($item != null || $item != "") {
|
||||
array_push($files, ["file" => $item, "type" => trim($ext)]);
|
||||
}
|
||||
}
|
||||
|
||||
$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"];
|
||||
|
||||
$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,
|
||||
];
|
||||
break;
|
||||
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,
|
||||
];
|
||||
break;
|
||||
case "/tags":
|
||||
$tags = $this->settings["tag_list"];
|
||||
$template = $this->themeFolder . "/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,
|
||||
];
|
||||
break;
|
||||
case "/archive":
|
||||
$archive = $this->archives;
|
||||
$template = $this->themeFolder . "/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,
|
||||
];
|
||||
break;
|
||||
default:
|
||||
http_response_code(404);
|
||||
require __DIR__ . "/views/404.php";
|
||||
break;
|
||||
}
|
||||
|
||||
echo $this->twig->render($template, $pageOptions);
|
||||
}
|
||||
}
|
143
index.php
143
index.php
|
@ -1,148 +1,7 @@
|
|||
<?php
|
||||
|
||||
require "vendor/autoload.php";
|
||||
class StartKit
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$settings = json_decode(file_get_contents("./package.json"), true);
|
||||
$theme = $settings["config"]["current_theme"];
|
||||
new ThemeEngine(
|
||||
"src/themes/theme-" . $theme,
|
||||
"/src/themes/theme-" . $theme . "/" . $theme
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ThemeEngine
|
||||
{
|
||||
public $data = [];
|
||||
public $loader;
|
||||
public $twig;
|
||||
public function __construct(string $themePath, string $themeAssetPath)
|
||||
{
|
||||
$this->themePath = $themePath;
|
||||
$this->themeAssetPath = $themeAssetPath;
|
||||
$path = explode("/", $themeAssetPath);
|
||||
$this->themeFolder = $path[4];
|
||||
$this->settings = json_decode(file_get_contents("./data/settings.json"), true);
|
||||
$this->posts = json_decode(file_get_contents("./data/posts.json"), true);
|
||||
$this->archives = json_decode(file_get_contents("./data/archives.json"), true);
|
||||
$this->loader = new \Twig\Loader\FilesystemLoader(
|
||||
$themePath . "/" . $path[4]
|
||||
);
|
||||
$this->twig = new \Twig\Environment($this->loader, []);
|
||||
$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",
|
||||
];
|
||||
|
||||
$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)]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($fileList as $file) {
|
||||
$item = trim($file);
|
||||
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
||||
if ($item != null || $item != "") {
|
||||
array_push($files, ["file" => $item, "type" => trim($ext)]);
|
||||
}
|
||||
}
|
||||
|
||||
$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"];
|
||||
|
||||
$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,
|
||||
];
|
||||
break;
|
||||
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,
|
||||
];
|
||||
break;
|
||||
case "/tags":
|
||||
$tags = $this->settings["tag_list"];
|
||||
$template = $this->themeFolder . "/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,
|
||||
];
|
||||
break;
|
||||
case "/archive":
|
||||
$archive = $this->archives;
|
||||
$template = $this->themeFolder . "/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,
|
||||
];
|
||||
break;
|
||||
default:
|
||||
http_response_code(404);
|
||||
require __DIR__ . "/views/404.php";
|
||||
break;
|
||||
}
|
||||
|
||||
echo $this->twig->render($template, $pageOptions);
|
||||
}
|
||||
}
|
||||
use engine\StartKit as StartKit;
|
||||
|
||||
new StartKit();
|
||||
|
|
Loading…
Reference in a new issue