From ceb0d7a62de02d49933c0e756b2458223d762ab8 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 29 Jun 2018 23:38:47 +0300 Subject: [PATCH] Add system.yaml config file and use for system configurations --- flextype/Cache.php | 28 ++++++------- flextype/Content.php | 8 ++-- flextype/Flextype.php | 18 +++++++-- flextype/Plugins.php | 7 +--- flextype/Themes.php | 8 ++-- site/config/site.yaml | 35 +++------------- site/config/system.yaml | 19 +++++++++ site/pages/home/page.html | 47 ++++++++++++---------- site/themes/simple/views/partials/head.php | 8 ++-- site/themes/simple/views/partials/tail.php | 2 +- 10 files changed, 92 insertions(+), 88 deletions(-) create mode 100755 site/config/system.yaml diff --git a/flextype/Cache.php b/flextype/Cache.php index 3828b44b..8aac452c 100755 --- a/flextype/Cache.php +++ b/flextype/Cache.php @@ -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; diff --git a/flextype/Content.php b/flextype/Content.php index f69bd433..ff6c6845 100755 --- a/flextype/Content.php +++ b/flextype/Content.php @@ -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(); diff --git a/flextype/Flextype.php b/flextype/Flextype.php index 9b3f2da2..24963855 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -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."); + } } /** diff --git a/flextype/Plugins.php b/flextype/Plugins.php index f38c4464..23b0eace 100755 --- a/flextype/Plugins.php +++ b/flextype/Plugins.php @@ -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 diff --git a/flextype/Themes.php b/flextype/Themes.php index 0d6c2d3f..f3f0e3ba 100644 --- a/flextype/Themes.php +++ b/flextype/Themes.php @@ -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; } diff --git a/site/config/site.yaml b/site/config/site.yaml index 8951af89..25f8af62 100755 --- a/site/config/site.yaml +++ b/site/config/site.yaml @@ -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: '' diff --git a/site/config/system.yaml b/site/config/system.yaml new file mode 100755 index 00000000..0a536010 --- /dev/null +++ b/site/config/system.yaml @@ -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 diff --git a/site/pages/home/page.html b/site/pages/home/page.html index d61b8f35..2c28fcdb 100644 --- a/site/pages/home/page.html +++ b/site/pages/home/page.html @@ -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 --- -

Flextype is succesfully installed!

-

You can start editing the content and customising your site.

- -

Edit this Page

-

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.

- -

Create a New page

-

Creating a new page is very simple in Flextype.

- -

-1. Launch your text editor and paste this sample text: - -

---
-title: My New Page
----
-

My New Page!

-

This is the body of My New Page

-
- -2. Save this file in the /site/pages/my-new-page/ folder as page.md and its will be available by this url: http://your_site_url/my-new-page -

-

That is it!

+

Flextype is succesfully installed!

+

You can start editing the content and customising your site.

+ +

Edit this Page

+

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.

dasd

Asda

+ +

Create a New page

+

Creating a new page is very simple in Flextype.

+ +

+1. Launch your text editor and paste this sample text: + +

---
+title: My New Page
+---
+

My New Page!

+

This is the body of My New Page

+
+ +2. Save this file in the /site/pages/my-new-page/ folder as page.md and its will be available by this url: http://your_site_url/my-new-page +

+

That is it!

diff --git a/site/themes/simple/views/partials/head.php b/site/themes/simple/views/partials/head.php index c34b83bb..6bc0ef18 100755 --- a/site/themes/simple/views/partials/head.php +++ b/site/themes/simple/views/partials/head.php @@ -3,9 +3,9 @@ use Flextype\Component\{Event\Event, Http\Http, Registry\Registry, Assets\Assets, Text\Text, Html\Html}; ?> - + - + @@ -18,8 +18,8 @@ - - + + diff --git a/site/themes/simple/views/partials/tail.php b/site/themes/simple/views/partials/tail.php index 7d11daba..cb406a38 100755 --- a/site/themes/simple/views/partials/tail.php +++ b/site/themes/simple/views/partials/tail.php @@ -2,7 +2,7 @@ namespace Flextype; use Flextype\Component\{Event\Event, Http\Http, Registry\Registry, Assets\Assets}; ?> - +