diff --git a/.gitignore b/.gitignore index 7c245f24..a6bcec47 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,14 @@ -.idea -.DS_Store -composer.phar -composer.lock -vendor +# Composer +.composer +vendor/* +!*/vendor/* + +# OS Generated +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db +*.swp + +# phpstorm +.idea/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ef35a91..d0c03bcb 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +# Flextype 0.7.0, 2018-11-16 +* Update Symfony YAML to 4.1.1 +* Update Text Component to 1.1.0 +* Update Session Component to 1.1.1 +* Update Doctrine Cache to 1.8.0 +* Update I18n Component to 1.1.0 +* Update Token Component to 1.2.0 +* Content: field 'published' changed to 'visibility' +* Plugins: from now no need to add plugin names manually to the site.yaml +* Plugins: added ability to load plugins settings.yaml file +* Plugins: from now plugins configurations stored in the plugin-name/settings.yaml file +* Add system.yaml config file and use it for system configurations +* Themes: added ability to load themes settings.yaml file +* Themes: from now themes configurations stored in the theme-name/settings.yaml file + # Flextype 0.6.1, 2018-06-17 * Fixed issue with not found pages status code * Fixed Singleton classes and methods visibility changed from protected to private diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..d0697d95 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,8 @@ +## CONTRIBUTE +Flextype is an open source project and community contributions are essential to its growing and success. Contributing to the Flextype is easy and you can give as little or as much time as you want. +* Help on the [Forum.](http://forum.flextype.org) +* Develop a new plugin. +* Create a new theme. +* Find and [report issues.](https://github.com/flextype/flextype/issues) +* Link back to [Flextype](http://flextype.org). +* [Donate to keep Flextype free.](http://flextype.org/about/sponsors) diff --git a/README.md b/README.md index dec80de6..55c65358 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Flextype - +  Flextype is Open Source, fast and flexible file-based Content Management System. diff --git a/composer.json b/composer.json index 410b9caa..ad2b0de4 100755 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ }, "require": { "php": ">=7.1.3", - "doctrine/cache": "1.7.1", - "symfony/yaml": "4.1.0", + "doctrine/cache": "1.8.0", + "symfony/yaml": "4.1.1", "thunderer/shortcode": "0.6.5", "flextype-components/arr" : "1.2.3", "flextype-components/assets" : "1.0.1", @@ -29,15 +29,16 @@ "flextype-components/errorhandler" : "1.0.4", "flextype-components/filesystem" : "1.1.1", "flextype-components/form" : "1.0.1", - "flextype-components/i18n" : "1.0.1", + "flextype-components/i18n" : "1.1.1", "flextype-components/http" : "1.1.1", "flextype-components/html" : "1.0.0", "flextype-components/number" : "1.0.0", "flextype-components/notification" : "1.0.1", "flextype-components/registry" : "1.1.0", - "flextype-components/token" : "1.1.0", + "flextype-components/session" : "1.1.1", + "flextype-components/token" : "1.2.0", "flextype-components/view" : "1.1.1", - "flextype-components/text" : "1.0.2" + "flextype-components/text" : "1.1.0" }, "autoload": { "classmap": [ 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 df545c61..3238e876 100755 --- a/flextype/Content.php +++ b/flextype/Content.php @@ -92,6 +92,9 @@ class Content // Init Parsers Content::initParsers(); + // Event: The page has been not loaded. + Event::dispatch('onCurrentPageBeforeLoaded'); + // Set current requested page data to global $page array Content::$page = Content::getPage(Http::getUriString()); @@ -147,7 +150,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'; } @@ -183,7 +186,7 @@ class Content $page = Content::processPage($file_path); // Get 404 page if page is not published - if (isset($page['visibility']) && $page['visibility'] === 'visible') { + if (isset($page['visibility']) && $page['visibility'] === 'draft') { if (Filesystem::fileExists($file_path = PATH['pages'] . '/404/page.html')) { $page = Content::processPage($file_path); Http::setResponseStatus(404); @@ -344,7 +347,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 +358,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 +431,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..283d022c 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -22,7 +22,7 @@ class Flextype * * @var string */ - const VERSION = '0.6.1'; + const VERSION = '0.7.0'; /** * An instance of the Flextype class @@ -70,14 +70,15 @@ 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 +107,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 +140,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 41b1a4a4..bddf718c 100755 --- a/flextype/Plugins.php +++ b/flextype/Plugins.php @@ -97,27 +97,24 @@ 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 if (is_array($plugins_list) && count($plugins_list) > 0) { // Go through... foreach ($plugins_list as $plugin) { - if (Filesystem::fileExists($_plugin = PATH['plugins'] . '/' . $plugin . '/' . $plugin . '.yaml')) { - $_plugins_cache_id .= filemtime($_plugin); + if (Filesystem::fileExists($_plugin_settings = PATH['plugins'] . '/' . $plugin . '/settings.yaml') and + Filesystem::fileExists($_plugin_config = PATH['plugins'] . '/' . $plugin . '/'. $plugin .'.yaml')) { + $_plugins_cache_id .= filemtime($_plugin_settings) . filemtime($_plugin_config); } } @@ -135,11 +132,15 @@ class Plugins // Go through... foreach ($plugins_list as $plugin) { - if (Filesystem::fileExists($_plugin_manifest = PATH['plugins'] . '/' . $plugin . '/' . $plugin . '.yaml')) { - $plugin_manifest = Yaml::parseFile($_plugin_manifest); + if (Filesystem::fileExists($_plugin_settings = PATH['plugins'] . '/' . $plugin . '/settings.yaml')) { + $plugin_settings = Yaml::parseFile($_plugin_settings); } - $_plugins_config[basename($_plugin_manifest, '.yaml')] = $plugin_manifest; + if (Filesystem::fileExists($_plugin_config = PATH['plugins'] . '/' . $plugin . '/'. $plugin. '.yaml')) { + $plugin_config = Yaml::parseFile($_plugin_config); + } + + $_plugins_config[basename($_plugin_config, '.yaml')] = array_merge($plugin_settings, $plugin_config); } Registry::set('plugins', $_plugins_config); @@ -153,7 +154,7 @@ class Plugins foreach ($plugins_list as $plugin) { $language_file = PATH['plugins'] . '/' . $plugin . '/languages/' . $locale . '.yaml'; if (Filesystem::fileExists($language_file)) { - I18n::add($plugin, $locale, Yaml::parseFile($language_file)); + I18n::add(Yaml::parseFile($language_file), $locale); } } } diff --git a/flextype/Themes.php b/flextype/Themes.php index 0d6c2d3f..70b7ef9b 100644 --- a/flextype/Themes.php +++ b/flextype/Themes.php @@ -63,22 +63,26 @@ 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', []); // Create Unique Cache ID for Theme - $theme_cache_id = md5('theme' . PATH['themes'] . $theme); + $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 if (Cache::contains($theme_cache_id)) { - Registry::set('themes.'.Registry::get('site.theme'), Cache::fetch($theme_cache_id)); + Registry::set('themes.'.Registry::get('system.theme'), Cache::fetch($theme_cache_id)); } 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); - Cache::save($theme_cache_id, $theme_manifest); + 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); + Cache::save($theme_cache_id, $_theme); } } } @@ -95,8 +99,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 c6297180..25f8af62 100755 --- a/site/config/site.yaml +++ b/site/config/site.yaml @@ -1,32 +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 - -plugins: - -locale: "en" - -pages: - main: home - -errors: - display: false - -cache: - enabled: true - 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..91d621be --- /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: false + +cache: + enabled: true + prefix: flextype + driver: auto + lifetime: 604800 diff --git a/site/pages/404/page.html b/site/pages/404/page.html old mode 100755 new mode 100644 index dbdf48ba..e3d5c48b --- a/site/pages/404/page.html +++ b/site/pages/404/page.html @@ -1,7 +1,5 @@ --- -title: Error 404 -robots: noindex,nofollow +title: 'Error 404' --- - -
We're sorry but the page you are looking for doesn't appear to exist!
+We're sorry but the page you are looking for doesn't appear to exist!
diff --git a/site/pages/home/page.html b/site/pages/home/page.html old mode 100755 new mode 100644 index dc2e4cb0..63bd4602 --- a/site/pages/home/page.html +++ b/site/pages/home/page.html @@ -1,9 +1,10 @@ --- title: Welcome -description: Flextype is a simple and light-weighted Content Management System +description: 'Flextype is a simple and light-weighted Content Management System' +date: 'June 27 2018 14:54:22.' +visibility: visible template: default --- -You can start editing the content and customising your site.
@@ -16,14 +17,13 @@ template: default
1. Launch your text editor and paste this sample text:
-
----
+
---
title: My New Page
---
-<h1>My New Page!</h1>
-<p>This is the body of <b>My New Page</b></p>
-
+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/settings.yaml b/site/themes/simple/settings.yaml new file mode 100755 index 00000000..d50eff62 --- /dev/null +++ b/site/themes/simple/settings.yaml @@ -0,0 +1,10 @@ +name: Simple +version: 1.0.0 +description: Simple theme for Flextype +author: + name: Sergey Romanenko + email: awilum@yandex.ru + url: https://github.com/Awilum +homepage: https://github.com/flextype/flextype +bugs: https://github.com/flextype/flextype/issues +license: MIT diff --git a/site/themes/simple/simple.yaml b/site/themes/simple/simple.yaml index 2bbba5f1..d4ca9418 100755 --- a/site/themes/simple/simple.yaml +++ b/site/themes/simple/simple.yaml @@ -1,13 +1 @@ -name: Simple -version: 1.0.0 -description: Simple theme for Flextype -author: - name: Sergey Romanenko - email: awilum@yandex.ru - url: https://github.com/Awilum -homepage: https://github.com/flextype/flextype -bugs: https://github.com/flextype/flextype/issues -license: MIT - -# Theme settings enabled: true 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}; ?> - +