created new Theme data class for theme stuff, added custom page view, added view select for page edit screen

This commit is contained in:
Ro 2021-11-17 16:59:53 -08:00
parent bbfe37597a
commit a8355b2da4
6 changed files with 91 additions and 16 deletions

View file

@ -12,6 +12,7 @@ include "../brain/data/Session.inc.php";
include "../brain/data/Member.inc.php"; include "../brain/data/Member.inc.php";
include "../brain/data/Auth.inc.php"; include "../brain/data/Auth.inc.php";
include "../brain/data/Render.inc.php"; include "../brain/data/Render.inc.php";
include "../brain/data/Themes.inc.php";
include "../brain/utility/StringTools.inc.php"; include "../brain/utility/StringTools.inc.php";
include "../brain/utility/FileUploader.inc.php"; include "../brain/utility/FileUploader.inc.php";
include "../brain/utility/DocTools.inc.php"; include "../brain/utility/DocTools.inc.php";

View file

@ -21,7 +21,7 @@ class DashControl
if (Session::active()) { if (Session::active()) {
$config = new Settings(); $config = new Settings();
$settings = $config->getSettings(); $settings = $config->getSettings();
$themes = $config->getThemes(); $themes = (new Themes())->getThemes(); //$config->getThemes();
$template = "dash/settings.twig"; $template = "dash/settings.twig";
$member = Session::get("member"); $member = Session::get("member");
$form_token = Session::get("form_token"); $form_token = Session::get("form_token");
@ -103,13 +103,14 @@ class DashControl
$mode = $args["third"]; $mode = $args["third"];
if ($mode == "edit") { if ($mode == "edit") {
$uuid = $args["fourth"]; $uuid = $args["fourth"];
$customPages = (new Themes())->getCustomViews();
$pageOptions = [ $pageOptions = [
"title" => "Fipamo | Edit Page", "title" => "Fipamo | Edit Page",
"page" => (new Book("../content/pages"))->findPageById($uuid), "page" => (new Book("../content/pages"))->findPageById($uuid),
"mode" => $mode, "mode" => $mode,
"token" => Session::get("form_token"), "token" => Session::get("form_token"),
"status" => Session::active(), "status" => Session::active(),
"views" => $customPages,
]; ];
} else { } else {
$pageOptions = [ $pageOptions = [

View file

@ -6,7 +6,6 @@ class Settings
{ {
private $folks; private $folks;
private static $tags; private static $tags;
private $themes = [];
private static $settings; private static $settings;
public function __construct() public function __construct()
@ -18,14 +17,6 @@ class Settings
file_get_contents("../config/settings.json"), file_get_contents("../config/settings.json"),
true true
); );
$_themes = glob("../content/themes/*", GLOB_ONLYDIR);
foreach ($_themes as $theme) {
array_push(
$this->themes,
json_decode(file_get_contents($theme . "/theme.json"), true)
);
}
} }
public static function sync($data) public static function sync($data)
@ -101,11 +92,6 @@ class Settings
DocTools::writeSettings("../config/settings.json", $settings); DocTools::writeSettings("../config/settings.json", $settings);
} }
public function getThemes()
{
return $this->themes;
}
public function getFolks($key = null) public function getFolks($key = null)
{ {
if (isset($key)) { if (isset($key)) {

41
brain/data/Themes.inc.php Normal file
View file

@ -0,0 +1,41 @@
<?php
class Themes
{
private $themes = [];
public function __construct()
{
$_themes = glob("../content/themes/*", GLOB_ONLYDIR);
foreach ($_themes as $theme) {
array_push(
$this->themes,
json_decode(file_get_contents($theme . "/theme.json"), true)
);
}
}
public function getThemes()
{
return $this->themes;
}
public function getCustomViews()
{
$settings = (new Settings())->getSettings();
$currentTheme = $settings["global"]["theme"];
$folder = "../content/themes/" . $currentTheme;
$files = array_filter(glob("$folder/*twig"), "is_file");
$views = [];
foreach ($files as $file) {
$path = explode("/", $file);
$fileName = $path[4];
if (str_contains($fileName, "page")) {
$page = explode(".", $fileName);
$views[] = $page[0];
}
}
return $views;
}
}

View file

@ -32,4 +32,15 @@
<use id="option-published-icon" xlink:href="/assets/images/global/sprite.svg#entypo-eye"/> <use id="option-published-icon" xlink:href="/assets/images/global/sprite.svg#entypo-eye"/>
</svg> </svg>
</button> </button>
<label>View Template</label>
<select>
{% for view in views %}
{% if view == page['layout'] %}
<option value={{ view }} selected>{{ view }}</option>
{% else %}
<option value={{ view }}>{{ view }}</option>
{% endif %}
{% endfor %}
</select>
</div> </div>

View file

@ -0,0 +1,35 @@
{% extends "fipamo-default/frame.twig" %}
{% block title %}
{{ title }}
{% endblock %}
{% block mainContent %}
<section>
<div class="page-title">
<span>{{title}}</span>
</div>
</section>
<article>
<div class="page">
<p>{{content | raw}}</p>
<div>
{{meta['who']}} dropped this {{ meta['when'] }}<br />
<strong>tags: </strong>
{% for tag in meta['tags'] %}
{% if dynamicRender is defined %}
{% if dynamicRender %}
<a href="{{ "/tags/"~tag.slug }}">{{ tag.label }}</a>
{% else %}
<a href="{{ "/tags/"~tag.slug~".html" }}">{{ tag.label }}</a>
{% endif %}
{% else %}
<a href="{{ "/tags/"~tag.slug~".html" }}">{{ tag.label }}</a>
{% endif %}
{% endfor %}
</div>
</div>
</article>
{% endblock %}