2024-03-06 17:27:41 +01:00
|
|
|
<?php
|
|
|
|
|
2024-05-13 06:14:53 +02:00
|
|
|
namespace App\Services\Data;
|
2024-03-06 17:27:41 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 23:58:11 +01:00
|
|
|
public function getCurrentTheme()
|
|
|
|
{
|
|
|
|
return $this->settings->getGlobal()['theme'];
|
|
|
|
}
|
|
|
|
|
2024-03-06 17:27:41 +01:00
|
|
|
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;
|
2024-03-15 22:18:10 +01:00
|
|
|
$files = array_filter(glob("$folder/*blade.php"), 'is_file');
|
2024-03-06 17:27:41 +01:00
|
|
|
$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;
|
2024-03-15 22:18:10 +01:00
|
|
|
$files = array_filter(glob("$folder/*blade.php"), 'is_file');
|
2024-03-06 17:27:41 +01:00
|
|
|
$views = [];
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$path = explode('/', $file);
|
|
|
|
$fileName = $path[4];
|
|
|
|
if (str_contains($fileName, 'page')) {
|
|
|
|
$page = explode('.', $fileName);
|
|
|
|
$views[] = $page[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $views;
|
|
|
|
}
|
|
|
|
}
|