forked from projects/fipamo
ro
b527884c51
page editing was missing the selector to choose what template the page was using, so a theme class was created to handle retrieving and sorting what classes where avaiable in the themes directory still looking for twig files because themes haven't been converted over yet, but one step at a time
74 lines
2 KiB
PHP
74 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
class ThemeService
|
|
{
|
|
protected $themes = [];
|
|
protected $settings;
|
|
|
|
public function __construct(SettingsService $settingsService)
|
|
{
|
|
$this->settings = $settingsService;
|
|
$_themes = glob(env('THEMES_PATH') . '/*', 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($layout)
|
|
{
|
|
$views = [];
|
|
if (str_contains($layout, 'index')) {
|
|
$views = $this->findCustomIndex();
|
|
} else {
|
|
$views = $this->findCustomViews();
|
|
}
|
|
return $views;
|
|
}
|
|
|
|
public function findCustomIndex()
|
|
{
|
|
$currentTheme = $this->settings->getGlobal()['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, 'index')) {
|
|
$page = explode('.', $fileName);
|
|
$views[] = $page[0];
|
|
}
|
|
}
|
|
return $views;
|
|
}
|
|
|
|
public function findCustomViews()
|
|
{
|
|
$currentTheme = $this->settings->getGlobal()['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;
|
|
}
|
|
}
|