mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
Merge remote-tracking branch 'origin/dev'
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
# Flextype 0.4.1, 2018-05-20
|
||||
* Fixing issues with cache for getPages() method.
|
||||
* Fixing issues with processPage() method.
|
||||
* Fixing issues with all public methods in Cache class, from now all methods are static.
|
||||
* Setting site.pages.flush_cache was removed from site.yaml file.
|
||||
|
||||
# Flextype 0.4.0, 2018-05-16
|
||||
* Using SCSS for Simple theme
|
||||
* Using Flextype Form Component
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Flextype
|
||||

|
||||

|
||||
[](https://github.com/flextype/flextype/blob/master/LICENSE.txt)
|
||||
|
||||
Flextype is next generation of Legendary Monstra Engine it is also Open Source, fast and flexible file-based Content Management System. That's Easy to install, upgrade and use. Flextype provides amazing API's for plugins, themes and core developers! Content in Flextype is just a simple files written with markdown syntax in pages folder. You simply create markdown files in the pages folder and that becomes a page.
|
||||
|
@@ -69,7 +69,7 @@ class Cache
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
static::init();
|
||||
Cache::init();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,16 +81,16 @@ class Cache
|
||||
protected static function init() : void
|
||||
{
|
||||
// Set current time
|
||||
static::$now = time();
|
||||
Cache::$now = time();
|
||||
|
||||
// Create cache key to allow invalidate all cache on configuration changes.
|
||||
static::$key = (Registry::get('site.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . Flextype::VERSION);
|
||||
Cache::$key = (Registry::get('site.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . Flextype::VERSION);
|
||||
|
||||
// Get Cache Driver
|
||||
static::$driver = static::getCacheDriver();
|
||||
Cache::$driver = Cache::getCacheDriver();
|
||||
|
||||
// Set the cache namespace to our unique key
|
||||
static::$driver->setNamespace(static::$key);
|
||||
Cache::$driver->setNamespace(Cache::$key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,7 +181,7 @@ class Cache
|
||||
*/
|
||||
public static function driver()
|
||||
{
|
||||
return static::$driver;
|
||||
return Cache::$driver;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,7 +192,7 @@ class Cache
|
||||
*/
|
||||
public static function getKey() : string
|
||||
{
|
||||
return static::$key;
|
||||
return Cache::$key;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,10 +202,25 @@ class Cache
|
||||
* @param string $id The id of the cache entry to fetch.
|
||||
* @return mixed The cached data or FALSE, if no cache entry exists for the given id.
|
||||
*/
|
||||
public function fetch(string $id)
|
||||
public static function fetch(string $id)
|
||||
{
|
||||
if (Registry::get('site.cache.enabled')) {
|
||||
return static::$driver->fetch($id);
|
||||
return Cache::$driver->fetch($id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean state of whether or not the item exists in the cache based on id key
|
||||
*
|
||||
* @param string $id the id of the cached data entry
|
||||
* @return bool true if the cached items exists
|
||||
*/
|
||||
public static function contains($id)
|
||||
{
|
||||
if (Registry::get('site.cache.enabled')) {
|
||||
return Cache::$driver->contains(($id));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -221,13 +236,13 @@ class Cache
|
||||
* If zero (the default), the entry never expires (although it may be deleted from the cache
|
||||
* to make place for other entries).
|
||||
*/
|
||||
public function save(string $id, $data, $lifetime = null)
|
||||
public static function save(string $id, $data, $lifetime = null)
|
||||
{
|
||||
if (Registry::get('site.cache.enabled')) {
|
||||
if ($lifetime === null) {
|
||||
$lifetime = static::getLifetime();
|
||||
$lifetime = Cache::getLifetime();
|
||||
}
|
||||
static::$driver->save($id, $data, $lifetime);
|
||||
Cache::$driver->save($id, $data, $lifetime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,10 +273,10 @@ class Cache
|
||||
return;
|
||||
}
|
||||
|
||||
$interval = $future - static::$now;
|
||||
$interval = $future - Cache::$now;
|
||||
|
||||
if ($interval > 0 && $interval < static::getLifetime()) {
|
||||
static::$lifetime = $interval;
|
||||
if ($interval > 0 && $interval < Cache::getLifetime()) {
|
||||
Cache::$lifetime = $interval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,11 +288,11 @@ class Cache
|
||||
*/
|
||||
public static function getLifetime()
|
||||
{
|
||||
if (static::$lifetime === null) {
|
||||
static::$lifetime = Registry::get('site.cache.lifetime') ?: 604800;
|
||||
if (Cache::$lifetime === null) {
|
||||
Cache::$lifetime = Registry::get('site.cache.lifetime') ?: 604800;
|
||||
}
|
||||
|
||||
return static::$lifetime;
|
||||
return Cache::$lifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -59,7 +59,7 @@ class Content
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
static::init();
|
||||
Content::init();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,8 +147,8 @@ class Content
|
||||
}
|
||||
|
||||
// Try to get page from cache
|
||||
if (Cache::driver()->contains($page_cache_id)) {
|
||||
return Cache::driver()->fetch($page_cache_id);
|
||||
if (Cache::contains($page_cache_id)) {
|
||||
return Cache::fetch($page_cache_id);
|
||||
} else {
|
||||
|
||||
// Get 404 page if page file is not exists
|
||||
@@ -182,7 +182,7 @@ class Content
|
||||
}
|
||||
}
|
||||
|
||||
Cache::driver()->save($page_cache_id, Content::$page);
|
||||
Cache::save($page_cache_id, Content::$page);
|
||||
return Content::$page;
|
||||
}
|
||||
}
|
||||
@@ -209,34 +209,52 @@ class Content
|
||||
$file_path = PATH['pages'] . '/' . $url;
|
||||
}
|
||||
|
||||
// Page cache id
|
||||
$pages_cache_id = md5('pages' . $file_path . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length);
|
||||
// Pages array where founded pages will stored
|
||||
$pages = [];
|
||||
|
||||
// Try to get pages from cache
|
||||
if (Cache::driver()->contains($pages_cache_id)) {
|
||||
return Cache::driver()->fetch($pages_cache_id);
|
||||
} else {
|
||||
// Pages cache id
|
||||
$pages_cache_id = '';
|
||||
|
||||
// Pages array where founded pages will stored
|
||||
$pages = [];
|
||||
// Get pages for $url
|
||||
// If $url is empty then we want to have a list of pages for /pages dir.
|
||||
if ($url === '') {
|
||||
|
||||
// Get pages for $url
|
||||
// If $url is empty then we want to have a list of pages for /pages dir.
|
||||
if ($url === '') {
|
||||
// Get pages list
|
||||
$pages_list = Filesystem::getFilesList($file_path , 'md');
|
||||
|
||||
// Get pages list
|
||||
$pages_list = Filesystem::getFilesList($file_path , 'md');
|
||||
// Create pages cached id
|
||||
foreach ($pages_list as $key => $page) {
|
||||
$pages_cache_id .= md5('pages' . $page . filemtime($page) . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length);
|
||||
}
|
||||
|
||||
if (Cache::contains($pages_cache_id)) {
|
||||
$pages = Cache::fetch($pages_cache_id);
|
||||
} else {
|
||||
// Create pages array from pages list
|
||||
foreach ($pages_list as $key => $page) {
|
||||
$pages[$key] = Content::processPage($page, $raw);
|
||||
}
|
||||
|
||||
Cache::save($pages_cache_id, $pages);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Get pages list
|
||||
$pages_list = Filesystem::getFilesList($file_path, 'md');
|
||||
|
||||
// Create pages cached id
|
||||
foreach ($pages_list as $key => $page) {
|
||||
if (strpos($page, $url . '/page.md') !== false) {
|
||||
// ignore ...
|
||||
} else {
|
||||
$pages_cache_id .= md5('pages' . $page . filemtime($page) . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length);
|
||||
}
|
||||
}
|
||||
|
||||
if (Cache::contains($pages_cache_id)) {
|
||||
$pages = Cache::fetch($pages_cache_id);
|
||||
} else {
|
||||
|
||||
// Get pages list
|
||||
$pages_list = Filesystem::getFilesList($file_path, 'md');
|
||||
|
||||
// Create pages array from pages list and ignore current requested page
|
||||
foreach ($pages_list as $key => $page) {
|
||||
if (strpos($page, $url . '/page.md') !== false) {
|
||||
@@ -246,22 +264,22 @@ class Content
|
||||
}
|
||||
}
|
||||
|
||||
Cache::save($pages_cache_id, $pages);
|
||||
}
|
||||
|
||||
// Sort and Slice pages if $raw === false
|
||||
if (!$raw) {
|
||||
$pages = Arr::sort($pages, $order_by, $order_type);
|
||||
|
||||
if ($offset !== null && $length !== null) {
|
||||
$pages = array_slice($pages, $offset, $length);
|
||||
}
|
||||
}
|
||||
|
||||
Cache::driver()->save($pages_cache_id, $pages);
|
||||
|
||||
// Return pages array
|
||||
return $pages;
|
||||
}
|
||||
|
||||
// Sort and Slice pages if $raw === false
|
||||
if (!$raw) {
|
||||
$pages = Arr::sort($pages, $order_by, $order_type);
|
||||
|
||||
if ($offset !== null && $length !== null) {
|
||||
$pages = array_slice($pages, $offset, $length);
|
||||
}
|
||||
}
|
||||
|
||||
// Return pages array
|
||||
return $pages;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,8 +304,8 @@ class Content
|
||||
}
|
||||
|
||||
// Try to get block from cache
|
||||
if (Cache::driver()->contains($block_cache_id)) {
|
||||
return Cache::driver()->fetch($block_cache_id);
|
||||
if (Cache::contains($block_cache_id)) {
|
||||
return Cache::fetch($block_cache_id);
|
||||
} else {
|
||||
if (Filesystem::fileExists($block_path)) {
|
||||
|
||||
@@ -297,7 +315,7 @@ class Content
|
||||
$content = Content::processContent($content);
|
||||
}
|
||||
|
||||
Cache::driver()->save($block_cache_id, $content);
|
||||
Cache::save($block_cache_id, $content);
|
||||
return $content;
|
||||
} else {
|
||||
throw new \RuntimeException("Block does not exist.");
|
||||
@@ -367,7 +385,7 @@ class Content
|
||||
$_page['slug'] = str_replace(Http::getBaseUrl(), '', $url);
|
||||
|
||||
// Create page date item
|
||||
$_page['date'] = $result_page['date'] ?? date(Registry::get('site.date_format'), filemtime($file_path));
|
||||
$_page['date'] = $_page['date'] ?? date(Registry::get('site.date_format'), filemtime($file_path));
|
||||
|
||||
// Create page content item with $page_content
|
||||
$_page['content'] = Content::processContent($page_content);
|
||||
|
@@ -40,7 +40,7 @@ class Flextype
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION = '0.4.0';
|
||||
const VERSION = '0.4.1';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -49,7 +49,7 @@ class Flextype
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
static::init();
|
||||
Flextype::init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -71,7 +71,7 @@ class Plugins
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
static::init();
|
||||
Plugins::init();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,6 +95,7 @@ class Plugins
|
||||
// Set empty plugins item
|
||||
Registry::set('plugins', []);
|
||||
|
||||
|
||||
// If Plugins List isnt empty then create plugin cache ID
|
||||
if (is_array($plugins_list) && count($plugins_list) > 0) {
|
||||
|
||||
@@ -109,8 +110,8 @@ class Plugins
|
||||
$plugins_cache_id = md5('plugins' . PATH['plugins'] . '/' . $_plugins_cache_id);
|
||||
|
||||
// Get plugins list from cache or scan plugins folder and create new plugins cache item
|
||||
if (Cache::driver()->contains($plugins_cache_id)) {
|
||||
Registry::set('plugins', Cache::driver()->fetch($plugins_cache_id));
|
||||
if (Cache::contains($plugins_cache_id)) {
|
||||
Registry::set('plugins', Cache::fetch($plugins_cache_id));
|
||||
} else {
|
||||
|
||||
// If Plugins List isnt empty
|
||||
@@ -127,13 +128,13 @@ class Plugins
|
||||
}
|
||||
|
||||
Registry::set('plugins', $_plugins_config);
|
||||
Cache::driver()->save($plugins_cache_id, $_plugins_config);
|
||||
Cache::save($plugins_cache_id, $_plugins_config);
|
||||
}
|
||||
}
|
||||
|
||||
// Create Dictionary
|
||||
if (is_array($plugins_list) && count($plugins_list) > 0) {
|
||||
foreach (static::$locales as $locale => $locale_title) {
|
||||
foreach (Plugins::$locales as $locale => $locale_title) {
|
||||
foreach ($plugins_list as $plugin) {
|
||||
$language_file = PATH['plugins'] . '/' . $plugin . '/languages/' . $locale . '.yaml';
|
||||
if (Filesystem::fileExists($language_file)) {
|
||||
|
@@ -31,7 +31,7 @@ class Themes
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
static::init();
|
||||
Themes::init();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,13 +58,13 @@ class Themes
|
||||
$theme_cache_id = md5('theme' . PATH['themes'] . $theme);
|
||||
|
||||
// Get Theme mafifest file and write to site.themes array
|
||||
if (Cache::driver()->contains($theme_cache_id)) {
|
||||
Registry::set('themes.'.Registry::get('site.theme'), Cache::driver()->fetch($theme_cache_id));
|
||||
if (Cache::contains($theme_cache_id)) {
|
||||
Registry::set('themes.'.Registry::get('site.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::driver()->save($theme_cache_id, $theme_manifest);
|
||||
Cache::save($theme_cache_id, $theme_manifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ plugins:
|
||||
locale: "en"
|
||||
|
||||
pages:
|
||||
flush_cache: false
|
||||
main: home
|
||||
|
||||
errors:
|
||||
|
Reference in New Issue
Block a user