ro
37120efe18
When testing themes, the script wasn't moving all assets that were in subdirectories of the theme css folder, so that's been fixed so it moves everything when testing a theme and rendering the site there was also an issue with saving settings options because the script was referencing email data that was no longer being provided from the front end, so it was erroring out trying to save it. those references have been removed so it's smooth sailing
108 lines
3.8 KiB
PHP
108 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Assets;
|
|
|
|
use App\Services\Data\ThemeService;
|
|
|
|
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->themeImagePath = '../public/assets/images/global/';
|
|
$this->themeCSSPath = '../public/assets/css/theme/';
|
|
$this->themeScriptsPath = '../public/assets/scripts/theme/';
|
|
$this->themes = $themeService;
|
|
$this->currentTheme = $this->themes->getCurrentTheme();
|
|
}
|
|
|
|
public function getCurrentTheme()
|
|
{
|
|
return $this->currentTheme;
|
|
}
|
|
|
|
public function moveToTheme($live = false)
|
|
{
|
|
$imagePath = '';
|
|
$cssPath = '';
|
|
$scriptPath = '';
|
|
($live) ? $imagePath = $this->themeImagePath : $imagePath = $this->themeTestImagePath;
|
|
($live) ? $cssPath = $this->themeCSSPath : $cssPath = $this->themeTestCSSPath;
|
|
($live) ? $scriptPath = $this->themeScriptsPath : $scriptPath = $this->themeTestScriptsPath;
|
|
//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($imagePath)) {
|
|
mkdir($imagePath, 0755, true);
|
|
}
|
|
|
|
if (!is_file($imagePath . $file->getFileName())) {
|
|
copy(
|
|
'../content/themes/' .
|
|
$this->currentTheme .
|
|
'/assets/images/global/' .
|
|
$file->getFileName(),
|
|
$imagePath . $file->getFileName()
|
|
);
|
|
} else {
|
|
//image is already there, so chill
|
|
}
|
|
}
|
|
//clear test theme css and script directories
|
|
$styles = glob($cssPath . '*'); // get all file names
|
|
foreach ($styles as $file) { // iterate files
|
|
if (is_file($file)) {
|
|
unlink($file); // delete file
|
|
}
|
|
}
|
|
$scripts = glob($scriptPath . '*'); // 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($cssPath)) {
|
|
mkdir($cssPath, 0755, true);
|
|
}
|
|
foreach ($newcss as $file) { // iterate files
|
|
if (is_file($file)) {
|
|
$path = explode('/', $file);
|
|
copy($file, $cssPath . $path[6]);
|
|
} else {
|
|
// if there is a type/font folder, move it
|
|
$typePath = explode('/', $file);
|
|
if (is_dir($cssPath . $typePath[6])) {
|
|
delete_directory($cssPath . $typePath[6]);
|
|
}
|
|
rename($file, $cssPath . $typePath[6]);
|
|
}
|
|
}
|
|
$newjs = glob('../content/themes/' . $this->currentTheme . '/assets/scripts/*');
|
|
if (!is_dir($scriptPath)) {
|
|
mkdir($scriptPath, 0755, true);
|
|
}
|
|
foreach ($newjs as $file) { // iterate files
|
|
if (is_file($file)) {
|
|
$path = explode('/', $file);
|
|
copy($file, $scriptPath . $path[6]);
|
|
}
|
|
}
|
|
}
|
|
}
|