created asset service class to handle file moving
theme controller was getting top heavy, so an asset service class was plugged in to handle moving assets around for theme testing and eventually to production when HTML rendering is set up
This commit is contained in:
parent
4eed4489f4
commit
efb2e4f0bd
4 changed files with 120 additions and 82 deletions
|
@ -5,110 +5,46 @@ 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;
|
||||
use App\Services\AssetService;
|
||||
|
||||
class ThemeController extends Controller
|
||||
{
|
||||
protected PageRepositoryInterface $pages;
|
||||
protected AuthService $auth;
|
||||
protected ThemeService $themes;
|
||||
protected AssetService $assets;
|
||||
protected SortingService $sort;
|
||||
|
||||
public function __construct(
|
||||
PageRepositoryInterface $pageRepository,
|
||||
AuthService $authService,
|
||||
ThemeService $themeService,
|
||||
AssetService $assetService,
|
||||
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]);
|
||||
}
|
||||
}
|
||||
$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 = 'fipamo-default-v2.index' :
|
||||
$template = 'fipamo-default-v2.page';
|
||||
$page = $this->pages->getById('09E5A362-BA31-4AE2-9DEE-C93DFBE005C3')->first();
|
||||
$template = $currentTheme . '.index' :
|
||||
$template = $currentTheme . '.page';
|
||||
$page = $this->pages->getById('09E5A362-BA31-4AE2-9DEE-C93DFBE005C3');
|
||||
$data = $this->sort->page($page);
|
||||
$pageData = [
|
||||
"debug" => "true",
|
||||
"theme" => 'fipamo-default-v2',
|
||||
"theme" => $currentTheme,
|
||||
"status" => $this->auth::status(),
|
||||
"title" => "THEME PAGE",
|
||||
"meta" => $data['meta'],
|
||||
|
@ -124,11 +60,11 @@ class ThemeController extends Controller
|
|||
];
|
||||
break;
|
||||
case "tags":
|
||||
$template = 'fipamo-default-v2.tags';
|
||||
$template = $currentTheme . '.tags';
|
||||
$data = $this->sort->tags();
|
||||
$pageData = [
|
||||
'debug' => true, // for theme kit
|
||||
'theme' => 'fipamo-default-v2', // for theme kit
|
||||
'theme' => $currentTheme, // for theme kit
|
||||
'title' => 'Pages Tagged as Tag',
|
||||
'dynamicRender' => $data['info']['dynamicRender'],
|
||||
'tags' => $data['info']['tags'][3]['pages'],
|
||||
|
@ -142,11 +78,11 @@ class ThemeController extends Controller
|
|||
break;
|
||||
case "archives":
|
||||
case "archive":
|
||||
$template = 'fipamo-default-v2.archive';
|
||||
$template = $currentTheme . '.archive';
|
||||
$data = $this->sort->archive();
|
||||
$pageData = [
|
||||
'debug' => true, // for theme kit
|
||||
'theme' => 'fipamo-default-v2', // for theme kit
|
||||
'theme' => $currentTheme, // for theme kit
|
||||
'title' => 'Archives',
|
||||
'dynamicRender' => $data['info']['dynamicRender'],
|
||||
'archive' => $data['archive'],
|
||||
|
|
|
@ -15,6 +15,7 @@ use App\Services\StringService;
|
|||
use App\Services\FileUploadService;
|
||||
use App\Services\RenderService;
|
||||
use App\Services\SortingService;
|
||||
use App\Services\AssetService;
|
||||
|
||||
class FipamoServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
@ -74,6 +75,14 @@ class FipamoServiceProvider extends ServiceProvider
|
|||
new StringService(),
|
||||
);
|
||||
});
|
||||
|
||||
$this->app->bind(AssetService::class, function ($app) {
|
||||
return new AssetService(
|
||||
new ThemeService(
|
||||
new SettingsService(new DocService())
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
92
app/Services/AssetService.php
Normal file
92
app/Services/AssetService.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class AssetService
|
||||
{
|
||||
protected $themeTestImagePath;
|
||||
protected $themeTestCSSPath;
|
||||
protected $themeTestScriptsPath;
|
||||
protected $themes;
|
||||
protected $currentTheme;
|
||||
|
||||
public function __construct(ThemeService $themeService)
|
||||
{
|
||||
$this->themeTestImagePath = '../public/theme/images/global/';
|
||||
$this->themeTestCSSPath = '../public/theme/css/theme/';
|
||||
$this->themeTestScriptsPath = '../public/theme/scripts/theme/';
|
||||
$this->themes = $themeService;
|
||||
$this->currentTheme = $this->themes->getCurrentTheme();
|
||||
}
|
||||
|
||||
public function getCurrentTheme()
|
||||
{
|
||||
return $this->currentTheme;
|
||||
}
|
||||
|
||||
public function moveToTheme()
|
||||
{
|
||||
//get current theme
|
||||
foreach (
|
||||
new \DirectoryIterator('../content/themes/' . $this->currentTheme . '/assets/images/global/') as $file
|
||||
) {
|
||||
if ($file->isDot()) {
|
||||
continue;
|
||||
}
|
||||
//make theme directory if not present
|
||||
if (!is_dir($this->themeTestImagePath)) {
|
||||
mkdir($this->themeTestImagePath, 0755, true);
|
||||
}
|
||||
|
||||
if (!is_file($this->themeTestImagePath . $file->getFileName())) {
|
||||
copy(
|
||||
'../content/themes/' .
|
||||
$this->currentTheme .
|
||||
'/assets/images/global/' .
|
||||
$file->getFileName(),
|
||||
$this->themeTestImagePath . $file->getFileName()
|
||||
);
|
||||
} else {
|
||||
//image is already there, so chill
|
||||
}
|
||||
//print $file->getFilename() . "\n";
|
||||
}
|
||||
//clear test theme css and script directories
|
||||
$styles = glob($this->themeTestCSSPath . '*'); // get all file names
|
||||
foreach ($styles as $file) { // iterate files
|
||||
if (is_file($file)) {
|
||||
unlink($file); // delete file
|
||||
}
|
||||
}
|
||||
$scripts = glob($this->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/' . $this->currentTheme . '/assets/css/*');
|
||||
if (!is_dir($this->themeTestCSSPath)) {
|
||||
mkdir($this->themeTestCSSPath, 0755, true);
|
||||
}
|
||||
foreach ($newcss as $file) { // iterate files
|
||||
if (is_file($file)) {
|
||||
$path = explode('/', $file);
|
||||
copy($file, $this->themeTestCSSPath . $path[6]);
|
||||
}
|
||||
}
|
||||
$newjs = glob('../content/themes/' . $this->currentTheme . '/assets/scripts/*');
|
||||
if (!is_dir($this->themeTestScriptsPath)) {
|
||||
mkdir($this->themeTestScriptsPath, 0755, true);
|
||||
}
|
||||
foreach ($newjs as $file) { // iterate files
|
||||
if (is_file($file)) {
|
||||
$path = explode('/', $file);
|
||||
copy($file, $this->themeTestScriptsPath . $path[6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<meta property="og:image" content="{{$info["image"]}}"/>
|
||||
<meta name="twitter:image" content="{{$info["image"]}}"/>
|
||||
<link rel="shortcut icon" href="/favicon.png" type="image/x-icon">
|
||||
<link rel="stylesheet" type="text/css" href="{{ $assetPath."css/theme/start.css" }}">
|
||||
</head>
|
||||
<body>
|
||||
|
|
Loading…
Reference in a new issue