fipamo/app/Http/Controllers/Theming/ThemeController.php
ro a6b63ca551
implemented render engine
page rendering for tags, archives and markdown pages is now up and
running and being exported to html when requested.

currently it only works when saving a page, so now the settings page
needs to be plugged in so those features can be activated and toggled
through that UI

error checking will probably be added in the near future just in case
something unforeseen happens in the render process, resulting in the
site erroring out.
2024-03-18 16:14:17 -06:00

105 lines
4.1 KiB
PHP

<?php
namespace App\Http\Controllers\Theming;
use App\Http\Controllers\Controller;
use App\Interfaces\PageRepositoryInterface;
use App\Services\AuthService;
use App\Services\SortingService;
use App\Services\AssetService;
class ThemeController extends Controller
{
protected PageRepositoryInterface $pages;
protected AuthService $auth;
protected AssetService $assets;
protected SortingService $sort;
public function __construct(
PageRepositoryInterface $pageRepository,
AuthService $authService,
AssetService $assetService,
SortingService $sortService,
) {
$this->pages = $pageRepository;
$this->auth = $authService;
$this->assets = $assetService;
$this->sort = $sortService;
}
public function getView($view = 'index')
{
//move assets to theme testing dir
$this->assets->moveToTheme();
$currentTheme = $this->assets->getCurrentTheme();
$template;
$pageData = [];
switch ($view) {
case "index":
case "page":
$view == 'index' ?
$template = $currentTheme . '.index' :
$template = $currentTheme . '.page';
$page = $this->pages->getById('532E2250-F8CB-4E87-9782-8AFBEE88DD5E');
$data = $this->sort->page($page);
$pageData = [
"debug" => "true",
"theme" => $currentTheme,
"status" => $this->auth::status(),
"title" => "THEME PAGE",
"meta" => $data['meta'],
"menu" => $data['menu'],
"info" => $data['info'],
"media" => $data['media'],
"files" => $data['files'],
"content" => $data['content'],
"recent" => $data['recent'],
"feature" => $data['featured'],
"tags" => $data['tags'],
"dynamicRender" => $data['dynamicRender'],
];
break;
case "tags":
$template = $currentTheme . '.tags';
$data = $this->sort->tags();
$pageData = [
'debug' => true, // for theme kit
'theme' => $currentTheme, // for theme kit
'title' => 'Pages Tagged as Tag',
'dynamicRender' => $data['info']['dynamicRender'],
'$pages' => $data['info']['tags'][3]['pages'],
'info' => $data['info'],
'menu' => $data['info']['menu'],
'media' => [
['file' => $data['info']['image'],
'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))]
],
];
break;
case "archives":
case "archive":
$template = $currentTheme . '.archive';
$data = $this->sort->archive();
$pageData = [
'debug' => true, // for theme kit
'theme' => $currentTheme, // for theme kit
'title' => 'Archives',
'dynamicRender' => $data['info']['dynamicRender'],
'archive' => $data['archive'],
'info' => $data['info'],
'menu' => $data['info']['menu'],
'media' => [
['file' => $data['info']['image'],
'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))]
],
];
break;
}
if ($this->auth::status()) {
return view($template, $pageData);
} else {
return redirect('dashboard/start');
}
}
}