2024-03-14 19:39:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
2024-03-14 19:39:43 +01:00
|
|
|
class RenderService
|
|
|
|
{
|
2024-03-14 23:58:11 +01:00
|
|
|
private $sort;
|
|
|
|
private $settings;
|
2024-03-18 23:14:17 +01:00
|
|
|
private $contents;
|
2024-03-14 23:58:11 +01:00
|
|
|
private $pageInfo;
|
|
|
|
private $menu;
|
|
|
|
private $background;
|
2024-03-18 23:14:17 +01:00
|
|
|
private $theme;
|
2024-03-14 23:58:11 +01:00
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
public function __construct(
|
|
|
|
SortingService $sortingService,
|
|
|
|
SettingsService $settingsService,
|
|
|
|
ContentService $contentService
|
|
|
|
) {
|
2024-03-14 23:58:11 +01:00
|
|
|
$this->sort = $sortingService;
|
|
|
|
$this->settings = $settingsService;
|
2024-03-18 23:14:17 +01:00
|
|
|
$this->contents = $contentService;
|
|
|
|
$this->theme = $this->settings->getGlobal()['theme'];
|
2024-03-14 23:58:11 +01:00
|
|
|
}
|
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
public function archive()
|
2024-03-14 19:39:43 +01:00
|
|
|
{
|
2024-03-18 23:14:17 +01:00
|
|
|
$template = $this->theme . '.archive';
|
|
|
|
$data = $this->sort->archive();
|
|
|
|
$pageData = [
|
|
|
|
'theme' => $this->theme, // 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))]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$location = '../public/archive.html';
|
|
|
|
File::put(
|
|
|
|
$location,
|
|
|
|
view($template)
|
|
|
|
->with($pageData)
|
|
|
|
->render()
|
|
|
|
);
|
|
|
|
}
|
2024-03-14 23:58:11 +01:00
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
public function tags()
|
|
|
|
{
|
|
|
|
$data = $this->sort->tags();
|
|
|
|
foreach ($data['tags'] as $item) {
|
|
|
|
//$template = 'tags.twig';
|
|
|
|
$template = $this->theme . '.tags';
|
|
|
|
$pageData = [
|
|
|
|
'theme' => $this->theme, // for theme kit
|
|
|
|
'title' => 'Pages Tagged as ' . $item['tag_name'],
|
|
|
|
'dynamicRender' => $data['info']['dynamicRender'],
|
|
|
|
'info' => $data['info'],
|
|
|
|
'menu' => $data['info']['menu'],
|
|
|
|
'pages' => $item['pages'],
|
|
|
|
'media' => [
|
|
|
|
['file' => $data['info']['image'],
|
|
|
|
'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))]
|
|
|
|
],
|
|
|
|
];
|
2024-03-14 23:58:11 +01:00
|
|
|
|
|
|
|
$location = '../public/tags/' . $item['slug'] . '.html';
|
|
|
|
|
|
|
|
if (!is_dir('../public/tags')) {
|
|
|
|
mkdir('../public/tags', 0755, true);
|
|
|
|
}
|
|
|
|
|
2024-03-18 23:14:17 +01:00
|
|
|
File::put(
|
|
|
|
$location,
|
|
|
|
view($template)
|
|
|
|
->with($pageData)
|
|
|
|
->render()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function pages()
|
|
|
|
{
|
|
|
|
$pages = $this->contents->loadAllPages();
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
$template;
|
|
|
|
$page['layout'] == 'index' ?
|
|
|
|
$template = $this->theme . '.index' :
|
|
|
|
$template = $this->theme . '.page';
|
|
|
|
|
|
|
|
$data = $this->sort->page($page);
|
|
|
|
$pageData = [
|
|
|
|
"theme" => $this->theme,
|
|
|
|
"status" => false,
|
|
|
|
"title" => $data['title'],
|
|
|
|
"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'],
|
|
|
|
];
|
|
|
|
|
|
|
|
if (str_contains($page['layout'], 'index')) {
|
|
|
|
$location = '../public/index.html';
|
2024-03-14 23:58:11 +01:00
|
|
|
} else {
|
2024-03-18 23:14:17 +01:00
|
|
|
// if page is a menu item, render the page on public root
|
|
|
|
if ($page['menu'] == 'true') {
|
|
|
|
$location = '../public/' . $page['slug'] . '.html';
|
|
|
|
} else {
|
|
|
|
$dir = '../public/' . $page['path'];
|
|
|
|
if (!is_dir($dir)) {
|
|
|
|
mkdir($dir, 0755, true);
|
|
|
|
}
|
|
|
|
$location = '../public/' . $page['path'] . '/' . $page['slug'] . '.html';
|
|
|
|
}
|
2024-03-14 23:58:11 +01:00
|
|
|
}
|
2024-03-18 23:14:17 +01:00
|
|
|
File::put($location, view($template)->with($pageData)->render());
|
2024-03-14 23:58:11 +01:00
|
|
|
}
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
|
|
|
}
|