fipamo/app/Http/Controllers/Theming/ThemeController.php
ro ba2e75b186
converted index template to blade
started the front end template conversion with the index page
2024-03-14 20:03:46 -06:00

127 lines
4.5 KiB
PHP

<?php
namespace App\Http\Controllers\Theming;
use App\Http\Controllers\Controller;
use App\Interfaces\PageRepositoryInterface;
use App\Services\AuthService;
use App\Services\ThemeService;
use App\Services\SortingService;
class ThemeController extends Controller
{
protected PageRepositoryInterface $pages;
protected AuthService $auth;
protected ThemeService $themes;
protected SortingService $sort;
public function __construct(
PageRepositoryInterface $pageRepository,
AuthService $authService,
ThemeService $themeService,
SortingService $sortService,
) {
$this->pages = $pageRepository;
$this->auth = $authService;
$this->themes = $themeService;
$this->sort = $sortService;
$theme = $this->themes->getCurrentTheme();
$themeTestImagePath = '../public/theme/images/global/';
$themeTestCSSPath = '../public/theme/css/theme/';
$themeTestScriptsPath = '../public/theme/scripts/theme/';
//TODO: Create assset service class to handle moving theme assets around
//move assets to public for testing
foreach (
new \DirectoryIterator('../content/themes/' . $theme . '/assets/images/global/') as $file
) {
if ($file->isDot()) {
continue;
}
//make theme directory if not present
if (!is_dir($themeTestImagePath)) {
mkdir($themeTestImagePath, 0755, true);
}
if (!is_file($themeTestImagePath . $file->getFileName())) {
copy(
'../content/themes/' .
$theme .
'/assets/images/global/' .
$file->getFileName(),
$themeTestImagePath . $file->getFileName()
);
} else {
//image is already there, so chill
}
//print $file->getFilename() . "\n";
}
//clear test theme css and script directories
$styles = glob($themeTestCSSPath . '*'); // get all file names
foreach ($styles as $file) { // iterate files
if (is_file($file)) {
unlink($file); // delete file
}
}
$scripts = glob($themeTestScriptsPath . '*'); // get all file names
foreach ($scripts as $file) { // iterate files
if (is_file($file)) {
unlink($file); // delete file
}
}
//
//copy theme assets to public
$newcss = glob('../content/themes/' . $theme . '/assets/css/*');
if (!is_dir($themeTestCSSPath)) {
mkdir($themeTestCSSPath, 0755, true);
}
foreach ($newcss as $file) { // iterate files
if (is_file($file)) {
$path = explode('/', $file);
copy($file, $themeTestCSSPath . $path[6]);
}
}
$newjs = glob('../content/themes/' . $theme . '/assets/scripts/*');
if (!is_dir($themeTestScriptsPath)) {
mkdir($themeTestScriptsPath, 0755, true);
}
foreach ($newjs as $file) { // iterate files
if (is_file($file)) {
$path = explode('/', $file);
copy($file, $themeTestScriptsPath . $path[6]);
}
}
}
public function getView($view = 'index')
{
$template = 'fipamo-default-v2.index';
switch ($view) {
case "page":
$template = 'fipamo-default-v2.page';
break;
}
if ($this->auth::status()) {
$page = $this->pages->getById('58E3D3DA-E7E4-4396-B4E5-0C30781C2F19')->first();
$data = $this->sort->page($page);
return view($template, [
"debug" => "true",
"theme" => 'fipamo-default-v2',
"status" => $this->auth::status(),
"title" => "THEME PAGE",
"menu" => $data['menu'],
"page" => $page,
"info" => $data['info'],
"media" => $data['media'],
"content" => $data['content'],
"recent" => $data['recent'],
"feature" => $data['featured'],
"dynamicRender" => $data['dynamicRender'],
]);
} else {
return redirect('dashboard/start');
}
}
}