1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-09 14:46:53 +02:00

Add system.yaml config file and use for system configurations

This commit is contained in:
Awilum
2018-06-29 23:38:47 +03:00
parent 69c21961a7
commit ceb0d7a62d
10 changed files with 92 additions and 88 deletions

View File

@@ -89,7 +89,7 @@ class Cache
Cache::$now = time();
// Create cache key to allow invalidate all cache on configuration changes.
Cache::$key = (Registry::get('site.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . Flextype::VERSION);
Cache::$key = (Registry::get('system.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . Flextype::VERSION);
// Get Cache Driver
Cache::$driver = Cache::getCacheDriver();
@@ -106,7 +106,7 @@ class Cache
*/
public static function getCacheDriver()
{
$driver_name = Registry::get('site.cache.driver');
$driver_name = Registry::get('system.cache.driver');
if (!$driver_name || $driver_name == 'auto') {
if (extension_loaded('apcu')) {
@@ -137,28 +137,28 @@ class Cache
break;
case 'memcache':
$memcache = new \Memcache();
$memcache->connect(Registry::get('site.cache.memcache.server', 'localhost'),
Registry::get('site.cache.memcache.port', 11211));
$memcache->connect(Registry::get('system.cache.memcache.server', 'localhost'),
Registry::get('system.cache.memcache.port', 11211));
$driver = new DoctrineCache\MemcacheCache();
$driver->setMemcache($memcache);
break;
case 'memcached':
$memcached = new \Memcached();
$memcached->addServer(Registry::get('site.cache.memcached.server', 'localhost'),
Registry::get('site.cache.memcache.port', 11211));
$memcached->addServer(Registry::get('system.cache.memcached.server', 'localhost'),
Registry::get('system.cache.memcache.port', 11211));
$driver = new DoctrineCache\MemcachedCache();
$driver->setMemcached($memcached);
break;
case 'redis':
$redis = new \Redis();
$socket = Registry::get('site.cache.redis.socket', false);
$password = Registry::get('site.cache.redis.password', false);
$socket = Registry::get('system.cache.redis.socket', false);
$password = Registry::get('system.cache.redis.password', false);
if ($socket) {
$redis->connect($socket);
} else {
$redis->connect(Registry::get('site.cache.redis.server', 'localhost'),
Registry::get('site.cache.redis.port', 6379));
$redis->connect(Registry::get('system.cache.redis.server', 'localhost'),
Registry::get('system.cache.redis.port', 6379));
}
// Authenticate with password if set
@@ -209,7 +209,7 @@ class Cache
*/
public static function fetch(string $id)
{
if (Registry::get('site.cache.enabled')) {
if (Registry::get('system.cache.enabled')) {
return Cache::$driver->fetch($id);
} else {
return false;
@@ -224,7 +224,7 @@ class Cache
*/
public static function contains($id)
{
if (Registry::get('site.cache.enabled')) {
if (Registry::get('system.cache.enabled')) {
return Cache::$driver->contains(($id));
} else {
return false;
@@ -243,7 +243,7 @@ class Cache
*/
public static function save(string $id, $data, $lifetime = null)
{
if (Registry::get('site.cache.enabled')) {
if (Registry::get('system.cache.enabled')) {
if ($lifetime === null) {
$lifetime = Cache::getLifetime();
}
@@ -294,7 +294,7 @@ class Cache
public static function getLifetime()
{
if (Cache::$lifetime === null) {
Cache::$lifetime = Registry::get('site.cache.lifetime') ?: 604800;
Cache::$lifetime = Registry::get('system.cache.lifetime') ?: 604800;
}
return Cache::$lifetime;

View File

@@ -147,7 +147,7 @@ class Content
{
// if $url is empty then set path for defined main page
if ($url === '') {
$file_path = PATH['pages'] . '/' . Registry::get('site.pages.main') . '/page.html';
$file_path = PATH['pages'] . '/' . Registry::get('system.pages.main') . '/page.html';
} else {
$file_path = PATH['pages'] . '/' . $url . '/page.html';
}
@@ -344,7 +344,7 @@ class Content
$url = str_replace('//', '/', $url);
$url = str_replace('http:/', 'http://', $url);
$url = str_replace('https:/', 'https://', $url);
$url = str_replace('/'.Registry::get('site.pages.main'), '', $url);
$url = str_replace('/'.Registry::get('system.pages.main'), '', $url);
$url = rtrim($url, '/');
$_page['url'] = $url;
@@ -355,7 +355,7 @@ class Content
$_page['slug'] = str_replace(Http::getBaseUrl(), '', $url);
// Create page date item
$_page['date'] = $_page['date'] ?? date(Registry::get('site.date_format'), filemtime($file_path));
$_page['date'] = $_page['date'] ?? date(Registry::get('system.date_format'), filemtime($file_path));
// Create page content item with $page_content
$_page['content'] = Content::processContent($page_content);
@@ -428,7 +428,7 @@ class Content
*/
private static function displayCurrentPage() : void
{
Http::setRequestHeaders('Content-Type: text/html; charset='.Registry::get('site.charset'));
Http::setRequestHeaders('Content-Type: text/html; charset='.Registry::get('system.charset'));
Themes::view(empty(Content::$page['template']) ? 'templates/default' : 'templates/' . Content::$page['template'])
->assign('page', Content::$page, true)
->display();

View File

@@ -70,14 +70,14 @@ class Flextype
// Set internal encoding
function_exists('mb_language') and mb_language('uni');
function_exists('mb_regex_encoding') and mb_regex_encoding(Registry::get('site.charset'));
function_exists('mb_internal_encoding') and mb_internal_encoding(Registry::get('site.charset'));
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'));
// Set error handler
Flextype::setErrorHandler();
// Set default timezone
date_default_timezone_set(Registry::get('site.timezone'));
date_default_timezone_set(Registry::get('system.timezone'));
// Start the session
Session::start();
@@ -106,7 +106,7 @@ class Flextype
private static function setErrorHandler() : void
{
// Display Errors
if (Registry::get('site.errors.display')) {
if (Registry::get('system.errors.display')) {
define('DEVELOPMENT', true);
error_reporting(-1);
} else {
@@ -139,6 +139,16 @@ class Flextype
} 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.");
}
}
/**

View File

@@ -97,19 +97,14 @@ class Plugins
*/
private static function init() : void
{
// Plugin manifest
$plugin_manifest = [];
// Plugin cache id
$plugins_cache_id = '';
$_plugins_cache_id = '';
// Get Plugins List
$plugins_list = Registry::get('site.plugins');
// Set empty plugins item
Registry::set('plugins', []);
// Get Plugins List
$plugins_list = Filesystem::getDirList(PATH['plugins']);
// If Plugins List isnt empty then create plugin cache ID

View File

@@ -63,7 +63,7 @@ class Themes
$theme_cache_id = '';
// Get current theme
$theme = Registry::get('site.theme');
$theme = Registry::get('system.theme');
// Set empty themes items
Registry::set('themes', []);
@@ -77,7 +77,7 @@ class Themes
} else {
if (Filesystem::fileExists($theme_manifest_file = PATH['themes'] . '/' . $theme . '/' . $theme . '.yaml')) {
$theme_manifest = Yaml::parseFile($theme_manifest_file);
Registry::set('themes.'.Registry::get('site.theme'), $theme_manifest);
Registry::set('themes.'.Registry::get('system.theme'), $theme_manifest);
Cache::save($theme_cache_id, $theme_manifest);
}
}
@@ -95,8 +95,8 @@ class Themes
{
// Set view file
// From current theme folder or from plugin folder
if (Filesystem::fileExists(PATH['themes'] . '/' . Registry::get('site.theme') . '/views/' . $template . View::$view_ext)) {
$template = PATH['themes'] . '/' . Registry::get('site.theme') . '/views/' . $template;
if (Filesystem::fileExists(PATH['themes'] . '/' . Registry::get('system.theme') . '/views/' . $template . View::$view_ext)) {
$template = PATH['themes'] . '/' . Registry::get('system.theme') . '/views/' . $template;
} else {
$template = PATH['plugins'] . '/' . $template;
}

View File

@@ -1,30 +1,7 @@
#
# Site configuration
#
title: "Flextype"
description: "The Best Open Source Flat-File Content Management System"
keywords: "flextype, php, cms, flat-file cms, flat cms, flatfile cms, html"
robots: "index, follow"
title: 'Flextype'
description: 'The Best Open Source Flat-File Content Management System'
keywords: 'flextype, php, cms, flat-file cms, flat cms, flatfile cms, html'
robots: 'index, follow'
author:
email: ""
timezone: UTC
date_format: "F d Y H:i:s."
charset: UTF-8
theme: simple
locale: "en"
pages:
main: home
errors:
display: true
cache:
enabled: false
prefix: flextype
driver: auto
lifetime: 604800
name: ''
email: ''

19
site/config/system.yaml Executable file
View File

@@ -0,0 +1,19 @@
timezone: UTC
date_format: 'F d Y H:i:s.'
charset: UTF-8
theme: simple
locale: 'en'
pages:
main: home
errors:
display: true
cache:
enabled: false
prefix: flextype
driver: auto
lifetime: 604800

View File

@@ -1,26 +1,29 @@
---
title: Welcome
description: 'Flextype is a simple and light-weighted Content Management System'
date: 'June 27 2018 14:54:22.'
visibility: visible
template: default
---
<h2>Flextype is succesfully installed!</h2>
<p>You can start editing the content and customising your site.</p>
<h3>Edit this Page</h3>
<p>To edit this page, simply go to the folder you installed Flextype, and then browse to the `/site/pages/home/` folder and open the `page.md` file in your editor.</p>
<h3>Create a New page</h3>
<p>Creating a new page is very simple in Flextype.</p>
<p>
1. Launch your text editor and paste this sample text:
<code>
</code></p><pre><code>---
title: My New Page
---
<h1>My New Page!</h1>
<p>This is the body of <b>My New Page</b></p>
</code></pre><code>
</code>
2. Save this file in the <code>/site/pages/my-new-page/</code> folder as <code>page.md</code> and its will be available by this url: http://your_site_url/my-new-page
<p></p>
<p>That is it!</p>
<h2>Flextype is succesfully installed!</h2>
<p>You can start editing the content and customising your site.</p>
<h3>Edit this Page</h3>
<p>To edit this page, simply go to the folder you installed Flextype, and then browse to the `/site/pages/home/` folder and open the `page.md` file in your editor.</p><p>dasd</p><p>Asda</p>
<h3>Create a New page</h3>
<p>Creating a new page is very simple in Flextype.</p>
<p>
1. Launch your text editor and paste this sample text:
<code>
</code></p><pre><code>---
title: My New Page
---
<h1>My New Page!</h1>
<p>This is the body of <b>My New Page</b></p>
</code></pre><code>
</code>
2. Save this file in the <code>/site/pages/my-new-page/</code> folder as <code>page.md</code> and its will be available by this url: http://your_site_url/my-new-page
<p></p>
<p>That is it!</p>

View File

@@ -3,9 +3,9 @@
use Flextype\Component\{Event\Event, Http\Http, Registry\Registry, Assets\Assets, Text\Text, Html\Html};
?>
<!doctype html>
<html lang="<?php echo Registry::get('site.locale'); ?>">
<html lang="<?php echo Registry::get('system.locale'); ?>">
<head>
<meta charset="<?php echo Text::lowercase(Registry::get('site.charset')); ?>">
<meta charset="<?php echo Text::lowercase(Registry::get('system.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')); ?>">
@@ -18,8 +18,8 @@
<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('site.theme') . '/assets/dist/css/bootstrap.min.css', 'site', 1); ?>
<?php Assets::add('css', Http::getBaseUrl() . '/site/themes/' . Registry::get('site.theme') . '/assets/dist/css/simple.min.css', 'site', 2); ?>
<?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 foreach (Assets::get('css', 'site') as $assets_by_priorities) { foreach ($assets_by_priorities as $assets) { ?>
<link href="<?php echo $assets['asset']; ?>" rel="stylesheet">
<?php } } ?>

View File

@@ -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('site.theme') . '/assets/dist/js/simple.min.js', 'site', 1); ?>
<?php Assets::add('js', Http::getBaseUrl() . '/site/themes/' . Registry::get('system.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 } } ?>