mirror of
https://github.com/flextype/flextype.git
synced 2025-08-18 02:41:27 +02:00
Settings - cleanup and refactoring
This commit is contained in:
@@ -94,7 +94,7 @@ class Cache
|
||||
Cache::$now = time();
|
||||
|
||||
// Create cache key to allow invalidate all cache on configuration changes.
|
||||
Cache::$key = (Registry::get('system.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . Flextype::VERSION);
|
||||
Cache::$key = (Registry::get('settings.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . Flextype::VERSION);
|
||||
|
||||
// Get Cache Driver
|
||||
Cache::$driver = Cache::getCacheDriver();
|
||||
@@ -111,7 +111,7 @@ class Cache
|
||||
*/
|
||||
public static function getCacheDriver()
|
||||
{
|
||||
$driver_name = Registry::get('system.cache.driver');
|
||||
$driver_name = Registry::get('settings.cache.driver');
|
||||
|
||||
if (!$driver_name || $driver_name == 'auto') {
|
||||
if (extension_loaded('apcu')) {
|
||||
@@ -143,8 +143,8 @@ class Cache
|
||||
case 'memcache':
|
||||
$memcache = new \Memcache();
|
||||
$memcache->connect(
|
||||
Registry::get('system.cache.memcache.server', 'localhost'),
|
||||
Registry::get('system.cache.memcache.port', 11211)
|
||||
Registry::get('settings.cache.memcache.server', 'localhost'),
|
||||
Registry::get('settings.cache.memcache.port', 11211)
|
||||
);
|
||||
$driver = new DoctrineCache\MemcacheCache();
|
||||
$driver->setMemcache($memcache);
|
||||
@@ -152,23 +152,23 @@ class Cache
|
||||
case 'memcached':
|
||||
$memcached = new \Memcached();
|
||||
$memcached->addServer(
|
||||
Registry::get('system.cache.memcached.server', 'localhost'),
|
||||
Registry::get('system.cache.memcache.port', 11211)
|
||||
Registry::get('settings.cache.memcached.server', 'localhost'),
|
||||
Registry::get('settings.cache.memcache.port', 11211)
|
||||
);
|
||||
$driver = new DoctrineCache\MemcachedCache();
|
||||
$driver->setMemcached($memcached);
|
||||
break;
|
||||
case 'redis':
|
||||
$redis = new \Redis();
|
||||
$socket = Registry::get('system.cache.redis.socket', false);
|
||||
$password = Registry::get('system.cache.redis.password', false);
|
||||
$socket = Registry::get('settings.cache.redis.socket', false);
|
||||
$password = Registry::get('settings.cache.redis.password', false);
|
||||
|
||||
if ($socket) {
|
||||
$redis->connect($socket);
|
||||
} else {
|
||||
$redis->connect(
|
||||
Registry::get('system.cache.redis.server', 'localhost'),
|
||||
Registry::get('system.cache.redis.port', 6379)
|
||||
Registry::get('settings.cache.redis.server', 'localhost'),
|
||||
Registry::get('settings.cache.redis.port', 6379)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ class Cache
|
||||
*/
|
||||
public static function fetch(string $id)
|
||||
{
|
||||
if (Registry::get('system.cache.enabled')) {
|
||||
if (Registry::get('settings.cache.enabled')) {
|
||||
return Cache::$driver->fetch($id);
|
||||
} else {
|
||||
return false;
|
||||
@@ -235,7 +235,7 @@ class Cache
|
||||
*/
|
||||
public static function contains($id)
|
||||
{
|
||||
if (Registry::get('system.cache.enabled')) {
|
||||
if (Registry::get('settings.cache.enabled')) {
|
||||
return Cache::$driver->contains(($id));
|
||||
} else {
|
||||
return false;
|
||||
@@ -254,7 +254,7 @@ class Cache
|
||||
*/
|
||||
public static function save(string $id, $data, $lifetime = null)
|
||||
{
|
||||
if (Registry::get('system.cache.enabled')) {
|
||||
if (Registry::get('settings.cache.enabled')) {
|
||||
if ($lifetime === null) {
|
||||
$lifetime = Cache::getLifetime();
|
||||
}
|
||||
@@ -305,7 +305,7 @@ class Cache
|
||||
public static function getLifetime()
|
||||
{
|
||||
if (Cache::$lifetime === null) {
|
||||
Cache::$lifetime = Registry::get('system.cache.lifetime') ?: 604800;
|
||||
Cache::$lifetime = Registry::get('settings.cache.lifetime') ?: 604800;
|
||||
}
|
||||
|
||||
return Cache::$lifetime;
|
||||
|
@@ -158,7 +158,7 @@ class Content
|
||||
{
|
||||
// if $url is empty then set path for defined main page
|
||||
if ($url === '') {
|
||||
$file_path = PATH['pages'] . '/' . Registry::get('system.pages.main') . '/page.html';
|
||||
$file_path = PATH['pages'] . '/' . Registry::get('settings.pages.main') . '/page.html';
|
||||
} else {
|
||||
$file_path = PATH['pages'] . '/' . $url . '/page.html';
|
||||
}
|
||||
@@ -354,7 +354,7 @@ class Content
|
||||
$url = str_replace('//', '/', $url);
|
||||
$url = str_replace('http:/', 'http://', $url);
|
||||
$url = str_replace('https:/', 'https://', $url);
|
||||
$url = str_replace('/'.Registry::get('system.pages.main'), '', $url);
|
||||
$url = str_replace('/'.Registry::get('settings.pages.main'), '', $url);
|
||||
$url = rtrim($url, '/');
|
||||
$_page['url'] = $url;
|
||||
|
||||
@@ -365,7 +365,7 @@ class Content
|
||||
$_page['slug'] = str_replace(Http::getBaseUrl(), '', $url);
|
||||
|
||||
// Create page date item
|
||||
$_page['date'] = $_page['date'] ?? date(Registry::get('system.date_format'), filemtime($file_path));
|
||||
$_page['date'] = $_page['date'] ?? date(Registry::get('settings.date_format'), filemtime($file_path));
|
||||
|
||||
// Create page content item with $page_content
|
||||
if ($ignore_content) {
|
||||
@@ -442,7 +442,7 @@ class Content
|
||||
*/
|
||||
private static function displayCurrentPage() : void
|
||||
{
|
||||
Http::setRequestHeaders('Content-Type: text/html; charset='.Registry::get('system.charset'));
|
||||
Http::setRequestHeaders('Content-Type: text/html; charset='.Registry::get('settings.charset'));
|
||||
Themes::view(empty(Content::$page['template']) ? 'templates/default' : 'templates/' . Content::$page['template'])
|
||||
->assign('page', Content::$page, true)
|
||||
->display();
|
||||
|
@@ -74,18 +74,18 @@ class Flextype
|
||||
// Turn on output buffering
|
||||
ob_start();
|
||||
|
||||
Flextype::setSiteConfig();
|
||||
Flextype::setConfig();
|
||||
|
||||
// Set internal encoding
|
||||
function_exists('mb_language') and mb_language('uni');
|
||||
function_exists('mb_regex_encoding') and mb_regex_encoding(Registry::get('system.charset'));
|
||||
function_exists('mb_internal_encoding') and mb_internal_encoding(Registry::get('system.charset'));
|
||||
function_exists('mb_regex_encoding') and mb_regex_encoding(Registry::get('settings.charset'));
|
||||
function_exists('mb_internal_encoding') and mb_internal_encoding(Registry::get('settings.charset'));
|
||||
|
||||
// Set error handler
|
||||
Flextype::setErrorHandler();
|
||||
|
||||
// Set default timezone
|
||||
date_default_timezone_set(Registry::get('system.timezone'));
|
||||
date_default_timezone_set(Registry::get('settings.timezone'));
|
||||
|
||||
// Start the session
|
||||
Session::start();
|
||||
@@ -114,7 +114,7 @@ class Flextype
|
||||
private static function setErrorHandler() : void
|
||||
{
|
||||
// Display Errors
|
||||
if (Registry::get('system.errors.display')) {
|
||||
if (Registry::get('settings.errors.display')) {
|
||||
define('DEVELOPMENT', true);
|
||||
error_reporting(-1);
|
||||
} else {
|
||||
@@ -132,30 +132,20 @@ class Flextype
|
||||
}
|
||||
|
||||
/**
|
||||
* Set site config
|
||||
* Set config
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private static function setSiteConfig() : void
|
||||
private static function setConfig() : void
|
||||
{
|
||||
// Set empty site item
|
||||
Registry::set('site', []);
|
||||
Registry::set('settings', []);
|
||||
|
||||
// Set site items if site config exists
|
||||
if (Filesystem::fileExists($site_config = PATH['config'] . '/' . 'site.yaml')) {
|
||||
Registry::set('site', Yaml::parseFile($site_config));
|
||||
// Set settings items if settings config exists
|
||||
if (Filesystem::fileExists($settings_config = PATH['config'] . '/' . 'settings.yaml')) {
|
||||
Registry::set('settings', Yaml::parseFile($settings_config));
|
||||
} else {
|
||||
throw new \RuntimeException("Flextype site config file does not exist.");
|
||||
}
|
||||
|
||||
// Set empty system item
|
||||
Registry::set('system', []);
|
||||
|
||||
// Set site items if system config exists
|
||||
if (Filesystem::fileExists($system_config = PATH['config'] . '/' . 'system.yaml')) {
|
||||
Registry::set('system', Yaml::parseFile($system_config));
|
||||
} else {
|
||||
throw new \RuntimeException("Flextype system config file does not exist.");
|
||||
throw new \RuntimeException("Flextype settings config file does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -69,7 +69,7 @@ class Themes
|
||||
$theme_cache_id = '';
|
||||
|
||||
// Get current theme
|
||||
$theme = Registry::get('system.theme');
|
||||
$theme = Registry::get('settings.theme');
|
||||
|
||||
// Set empty themes items
|
||||
Registry::set('themes', []);
|
||||
@@ -78,16 +78,16 @@ class Themes
|
||||
$theme_cache_id = md5('theme' . filemtime(PATH['themes'] .'/'. $theme . '/' . 'settings.yaml') .
|
||||
filemtime(PATH['themes'] .'/'. $theme . '/' . $theme . '.yaml'));
|
||||
|
||||
// Get Theme mafifest file and write to site.themes array
|
||||
// Get Theme mafifest file and write to settings.themes array
|
||||
if (Cache::contains($theme_cache_id)) {
|
||||
Registry::set('themes.'.Registry::get('system.theme'), Cache::fetch($theme_cache_id));
|
||||
Registry::set('themes.'.Registry::get('settings.theme'), Cache::fetch($theme_cache_id));
|
||||
} else {
|
||||
if (Filesystem::fileExists($theme_settings = PATH['themes'] . '/' . $theme . '/' . 'settings.yaml') and
|
||||
Filesystem::fileExists($theme_config = PATH['themes'] . '/' . $theme . '/' . $theme . '.yaml')) {
|
||||
$theme_settings = Yaml::parseFile($theme_settings);
|
||||
$theme_config = Yaml::parseFile($theme_config);
|
||||
$_theme = array_merge($theme_settings, $theme_config);
|
||||
Registry::set('themes.'.Registry::get('system.theme'), $_theme);
|
||||
Registry::set('themes.'.Registry::get('settings.theme'), $_theme);
|
||||
Cache::save($theme_cache_id, $_theme);
|
||||
}
|
||||
}
|
||||
@@ -105,8 +105,8 @@ class Themes
|
||||
{
|
||||
// Set view file
|
||||
// From current theme folder or from plugin folder
|
||||
if (Filesystem::fileExists(PATH['themes'] . '/' . Registry::get('system.theme') . '/views/' . $template . View::$view_ext)) {
|
||||
$template = PATH['themes'] . '/' . Registry::get('system.theme') . '/views/' . $template;
|
||||
if (Filesystem::fileExists(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $template . View::$view_ext)) {
|
||||
$template = PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $template;
|
||||
} else {
|
||||
$template = PATH['plugins'] . '/' . $template;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class Themes
|
||||
$templates = [];
|
||||
|
||||
// Get templates files
|
||||
$_templates = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('system.theme') . '/views/templates/', 'php');
|
||||
$_templates = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/templates/', 'php');
|
||||
|
||||
// If there is any template file then go...
|
||||
if (count($_templates) > 0) {
|
||||
@@ -153,7 +153,7 @@ class Themes
|
||||
$blueprints = [];
|
||||
|
||||
// Get blueprints files
|
||||
$_blueprints = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('system.theme') . '/blueprints/', 'yaml');
|
||||
$_blueprints = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('settings.theme') . '/blueprints/', 'yaml');
|
||||
|
||||
// If there is any template file then go...
|
||||
if (count($_blueprints) > 0) {
|
||||
|
@@ -3,23 +3,23 @@
|
||||
use Flextype\Component\{Event\Event, Http\Http, Registry\Registry, Assets\Assets, Text\Text, Html\Html};
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="<?php echo Registry::get('system.locale'); ?>">
|
||||
<html lang="<?php echo Registry::get('settings.locale'); ?>">
|
||||
<head>
|
||||
<meta charset="<?php echo Text::lowercase(Registry::get('system.charset')); ?>">
|
||||
<meta charset="<?php echo Text::lowercase(Registry::get('settings.charset')); ?>">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="<?php echo (isset($page['description']) ? Html::toText($page['description']) : Html::toText(Registry::get('site.description'))); ?>">
|
||||
<meta name="keywords" content="<?php echo (isset($page['keywords']) ? $page['keywords'] : Registry::get('site.keywords')); ?>">
|
||||
<meta name="robots" content="<?php echo (isset($page['robots']) ? $page['robots'] : Registry::get('site.robots')); ?>">
|
||||
<meta name="description" content="<?php echo (isset($page['description']) ? Html::toText($page['description']) : Html::toText(Registry::get('settings.description'))); ?>">
|
||||
<meta name="keywords" content="<?php echo (isset($page['keywords']) ? $page['keywords'] : Registry::get('settings.keywords')); ?>">
|
||||
<meta name="robots" content="<?php echo (isset($page['robots']) ? $page['robots'] : Registry::get('settings.robots')); ?>">
|
||||
<meta name="generator" content="Powered by Flextype <?php echo Flextype::VERSION; ?>" />
|
||||
|
||||
<?php Event::dispatch('onThemeMeta'); ?>
|
||||
|
||||
<title><?php echo Html::toText($page['title']); ?> | <?php echo Html::toText(Registry::get('site.title')); ?></title>
|
||||
<title><?php echo Html::toText($page['title']); ?> | <?php echo Html::toText(Registry::get('settings.title')); ?></title>
|
||||
|
||||
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,700' rel='stylesheet' type='text/css'>
|
||||
|
||||
<?php Assets::add('css', Http::getBaseUrl() . '/site/themes/' . Registry::get('system.theme') . '/assets/dist/css/bootstrap.min.css', 'site', 1); ?>
|
||||
<?php Assets::add('css', Http::getBaseUrl() . '/site/themes/' . Registry::get('system.theme') . '/assets/dist/css/simple.min.css', 'site', 2); ?>
|
||||
<?php Assets::add('css', Http::getBaseUrl() . '/site/themes/' . Registry::get('settings.theme') . '/assets/dist/css/bootstrap.min.css', 'site', 1); ?>
|
||||
<?php Assets::add('css', Http::getBaseUrl() . '/site/themes/' . Registry::get('settings.theme') . '/assets/dist/css/simple.min.css', 'site', 2); ?>
|
||||
<?php foreach (Assets::get('css', 'site') as $assets_by_priorities) { foreach ($assets_by_priorities as $assets) { ?>
|
||||
<link href="<?php echo $assets['asset']; ?>" rel="stylesheet">
|
||||
<?php } } ?>
|
||||
|
@@ -4,7 +4,7 @@
|
||||
?>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white border-bottom box-shadow">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="<?php echo Http::getBaseUrl(); ?>"><?php echo Registry::get('site.title'); ?></a>
|
||||
<a class="navbar-brand" href="<?php echo Http::getBaseUrl(); ?>"><?php echo Registry::get('settings.title'); ?></a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
@@ -2,7 +2,7 @@
|
||||
namespace Flextype;
|
||||
use Flextype\Component\{Event\Event, Http\Http, Registry\Registry, Assets\Assets};
|
||||
?>
|
||||
<?php Assets::add('js', Http::getBaseUrl() . '/site/themes/' . Registry::get('system.theme') . '/assets/dist/js/simple.min.js', 'site', 1); ?>
|
||||
<?php Assets::add('js', Http::getBaseUrl() . '/site/themes/' . Registry::get('settings.theme') . '/assets/dist/js/simple.min.js', 'site', 1); ?>
|
||||
<?php foreach (Assets::get('js', 'site') as $assets_by_priorities) { foreach ($assets_by_priorities as $assets) { ?>
|
||||
<script src="<?php echo $assets['asset']; ?>"></script>
|
||||
<?php } } ?>
|
||||
|
Reference in New Issue
Block a user