1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-13 00:24:15 +02:00

Flextype Core: Themes - fixes.

This commit is contained in:
Awilum
2019-05-22 11:47:04 +03:00
parent 25b09c1f02
commit 48dae3810e
2 changed files with 30 additions and 11 deletions

View File

@@ -16,34 +16,46 @@ use Flextype\Component\Filesystem\Filesystem;
class Themes
{
/**
* Flextype Dependency Container
*/
private $flextype;
/**
* Private construct method to enforce singleton behavior.
*
* @access private
*/
public function __construct()
public function __construct($flextype)
{
$this->flextype = $flextype;
$this->init($flextype, $app);
}
public function init($flextype, $app)
{
// Get current theme
$theme = Registry::get('settings.theme');
$theme = $this->flextype['registry']->get('settings.theme');
// Set empty themes items
Registry::set('themes', []);
$this->flextype['registry']->set('themes', []);
// Create Unique Cache ID for Theme
$theme_cache_id = md5('theme' . filemtime(PATH['themes'] . '/' . $theme . '/' . 'settings.json') .
filemtime(PATH['themes'] . '/' . $theme . '/' . $theme . '.json'));
// Get Theme mafifest file and write to settings.themes array
if (Cache::contains($theme_cache_id)) {
Registry::set('themes.' . Registry::get('settings.theme'), Cache::fetch($theme_cache_id));
if ($this->flextype['cache']->contains($theme_cache_id)) {
$this->flextype['registry']->set('themes.' . $this->flextype['registry']->get('settings.theme'), $this->flextype['cache']->fetch($theme_cache_id));
} else {
if (Filesystem::has($theme_settings = PATH['themes'] . '/' . $theme . '/' . 'settings.json') and
Filesystem::has($theme_config = PATH['themes'] . '/' . $theme . '/' . $theme . '.json')) {
$theme_settings = JsonParser::decode(Filesystem::read($theme_settings));
$theme_config = JsonParser::decode(Filesystem::read($theme_config));
$_theme = array_merge($theme_settings, $theme_config);
Registry::set('themes.' . Registry::get('settings.theme'), $_theme);
Cache::save($theme_cache_id, $_theme);
$this->flextype['registry']->set('themes.' . $this->flextype['registry']->get('settings.theme'), $_theme);
$this->flextype['cache']->save($theme_cache_id, $_theme);
}
}
}
@@ -60,12 +72,12 @@ class Themes
$partials = [];
// Get partials files
$_partials = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/partials/');
$_partials = Filesystem::listContents(PATH['themes'] . '/' . $this->flextype['registry']->get('settings.theme') . '/views/partials/');
// If there is any partials file then go...
if (count($_partials) > 0) {
foreach ($_partials as $partial) {
if ($partial['type'] == 'file' && $partial['extension'] == 'php') {
if ($partial['type'] == 'file' && $partial['extension'] == 'html') {
$partials[$partial['basename']] = $partial['basename'];
}
}
@@ -86,12 +98,12 @@ class Themes
$templates = [];
// Get templates files
$_templates = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/templates/');
$_templates = Filesystem::listContents(PATH['themes'] . '/' . $this->flextype['registry']->get('settings.theme') . '/views/templates/');
// If there is any template file then go...
if (count($_templates) > 0) {
foreach ($_templates as $template) {
if ($template['type'] == 'file' && $template['extension'] == 'php') {
if ($template['type'] == 'file' && $template['extension'] == 'html') {
$templates[$template['basename']] = $template['basename'];
}
}

View File

@@ -320,6 +320,13 @@ $app->get('/image/{path:.+}', function (Request $request, Response $response, ar
return $flextype['images']->getImageResponse($args['path'], $_GET);
});
/**
* Add themes service to Flextype container
*/
$flextype['themes'] = function($container) use ($flextype, $app) {
return new Themes($flextype, $app);
};
/**
* Add plugins service to Flextype container
*/