forked from projects/fipamo
ro
36d04c8f68
service classes are beginning to swell as there functionality is being fleshed out, so a new organizational structure was needed to make sure class sizes don't become too large and to increase site managability and legibilty as more features get added and the code base grows. data is for retrieving, managing site information, assets interact with external files and upkeep is for maintenance. some additional tweaks were also made to the options menu template to prep it for it's transition to a toolbar component
102 lines
3.5 KiB
PHP
102 lines
3.5 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
|
|
}
|
|
//print $file->getFilename() . "\n";
|
|
}
|
|
//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]);
|
|
}
|
|
}
|
|
$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]);
|
|
}
|
|
}
|
|
}
|
|
}
|