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

Merge branch 'dev'

# Conflicts:
#	flextype/Content.php
This commit is contained in:
Awilum
2018-11-16 00:17:00 +03:00
18 changed files with 159 additions and 117 deletions

19
.gitignore vendored
View File

@@ -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/*

View File

@@ -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

8
CONTRIBUTING.md Normal file
View File

@@ -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)

View File

@@ -1,5 +1,5 @@
# Flextype
![Version](https://img.shields.io/badge/version-0.6.1-brightgreen.svg?style=flat-square)
![Version](https://img.shields.io/badge/version-0.7.0-brightgreen.svg?style=flat-square)
![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
Flextype is Open Source, fast and flexible file-based Content Management System.

View File

@@ -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": [

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

@@ -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();

View File

@@ -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.");
}
}
/**

View File

@@ -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);
}
}
}

View File

@@ -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;
}

View File

@@ -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: ''

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: false
cache:
enabled: true
prefix: flextype
driver: auto
lifetime: 604800

8
site/pages/404/page.html Executable file → Normal file
View File

@@ -1,7 +1,5 @@
---
title: Error 404
robots: noindex,nofollow
title: 'Error 404'
---
<h2>Error 404</h2>
<p>We're sorry but the page you are looking for doesn't appear to exist!</p>
<h2>Error 404</h2>
<p>We're sorry but the page you are looking for doesn't appear to exist!</p>

16
site/pages/home/page.html Executable file → Normal file
View File

@@ -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
---
<h2>Flextype is succesfully installed!</h2>
<p>You can start editing the content and customising your site.</p>
@@ -16,14 +17,13 @@ template: default
<p>
1. Launch your text editor and paste this sample text:
<code>
<pre>
---
</code></p><pre><code>---
title: My New Page
---
&lt;h1&gt;My New Page!&lt;/h1&gt;
&lt;p&gt;This is the body of &lt;b&gt;My New Page&lt;/b&gt;&lt;/p&gt;
</pre>
<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>
<p>That is it!</p>

View File

@@ -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

View File

@@ -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

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 } } ?>