From 1f7006391bd5b3975176ad2c625d1a9891c274c6 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 23 Mar 2018 02:21:46 +0300 Subject: [PATCH 1/9] Flextype 0.2.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b0dbe5f..2b98c78c 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Flextype -![version](https://img.shields.io/badge/version-0.1.0-brightgreen.svg?style=flat-square "Version") +![version](https://img.shields.io/badge/version-0.2.0-brightgreen.svg?style=flat-square "Version") [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](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. From 371a61f11e00d48c2defd0d5c539bfbcd0086c90 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 25 Mar 2018 04:34:40 +0300 Subject: [PATCH 2/9] Code cleanup and refactoring #5 --- flextype/Config.php | 4 +-- flextype/Events.php | 5 +-- flextype/Filters.php | 71 ++++++++++++++++++++--------------------- flextype/Flextype.php | 17 +++++----- flextype/I18n.php | 2 +- flextype/Markdown.php | 2 +- flextype/Plugins.php | 1 - flextype/Shortcodes.php | 4 +-- 8 files changed, 52 insertions(+), 54 deletions(-) diff --git a/flextype/Config.php b/flextype/Config.php index bc59abaf..c1cbdef4 100755 --- a/flextype/Config.php +++ b/flextype/Config.php @@ -65,7 +65,7 @@ class Config * @param string $key Key * @param mixed $value Value */ - public static function set($key, $value) + public static function set($key, $value) : void { Arr::set(static::$config, $key, $value); } @@ -89,7 +89,7 @@ class Config * @access public * @return array */ - public static function getConfig() + public static function getConfig() : array { return static::$config; } diff --git a/flextype/Events.php b/flextype/Events.php index 6457660b..a4d0ffa4 100644 --- a/flextype/Events.php +++ b/flextype/Events.php @@ -9,7 +9,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - + namespace Flextype; use Arr; @@ -43,8 +43,9 @@ class Events * @param mixed $added_function Added function * @param integer $priority Priority. Default is 10 * @param array $args Arguments + * @return void */ - public static function addListener(string $event_name, $added_function, int $priority = 10, array $args = null) + public static function addListener(string $event_name, $added_function, int $priority = 10, array $args = null) : void { // Hooks a function on to a specific event. static::$events[] = array( diff --git a/flextype/Filters.php b/flextype/Filters.php index 3f05e863..6a80a2e8 100755 --- a/flextype/Filters.php +++ b/flextype/Filters.php @@ -28,7 +28,6 @@ class Filters */ protected static $filters = []; - /** * Protected constructor since this is a static class. * @@ -39,6 +38,41 @@ class Filters // Nothing here } + /** + * Add filter + * + * @access public + * @param string $filter_name The name of the filter to hook the $function_to_add to. + * @param string $function_to_add The name of the function to be called when the filter is applied. + * @param integer $priority Function to add priority - default is 10. + * @param integer $accepted_args The number of arguments the function accept default is 1. + * @return bool + */ + public static function addListener($filter_name, $function_to_add, $priority = 10, $accepted_args = 1) : bool + { + // Redefine arguments + $filter_name = (string) $filter_name; + $function_to_add = $function_to_add; + $priority = (int) $priority; + $accepted_args = (int) $accepted_args; + + // Check that we don't already have the same filter at the same priority. Thanks to WP :) + if (isset(static::$filters[$filter_name]["$priority"])) { + foreach (static::$filters[$filter_name]["$priority"] as $filter) { + if ($filter['function'] == $function_to_add) { + return true; + } + } + } + + static::$filters[$filter_name]["$priority"][] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); + + // Sort + ksort(static::$filters[$filter_name]["$priority"]); + + return true; + } + /** * Dispatch filters * @@ -77,39 +111,4 @@ class Filters return $value; } - - /** - * Add filter - * - * @access public - * @param string $filter_name The name of the filter to hook the $function_to_add to. - * @param string $function_to_add The name of the function to be called when the filter is applied. - * @param integer $priority Function to add priority - default is 10. - * @param integer $accepted_args The number of arguments the function accept default is 1. - * @return boolean - */ - public static function addListener($filter_name, $function_to_add, $priority = 10, $accepted_args = 1) - { - // Redefine arguments - $filter_name = (string) $filter_name; - $function_to_add = $function_to_add; - $priority = (int) $priority; - $accepted_args = (int) $accepted_args; - - // Check that we don't already have the same filter at the same priority. Thanks to WP :) - if (isset(static::$filters[$filter_name]["$priority"])) { - foreach (static::$filters[$filter_name]["$priority"] as $filter) { - if ($filter['function'] == $function_to_add) { - return true; - } - } - } - - static::$filters[$filter_name]["$priority"][] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); - - // Sort - ksort(static::$filters[$filter_name]["$priority"]); - - return true; - } } diff --git a/flextype/Flextype.php b/flextype/Flextype.php index 76838c33..c3ea1438 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -12,8 +12,7 @@ namespace Flextype; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Finder\Finder; +use Symfony\Component\{Filesystem\Filesystem, Finder\Finder}; use Url; use Session; @@ -30,7 +29,7 @@ class Flextype /** * Filesystem object * - * @var object + * @var Filesystem * @access public */ public static $filesystem = null; @@ -38,7 +37,7 @@ class Flextype /** * Finder object * - * @var object + * @var Finder * @access public */ public static $finder = null; @@ -75,7 +74,7 @@ class Flextype * * @access protected */ - protected static function app() + protected static function app() : void { // Init Finder static::$finder = new Finder(); @@ -140,9 +139,9 @@ class Flextype * Returns filesystem object * * @access public - * @return object + * @return Filesystem */ - public static function filesystem() + public static function filesystem() : Filesystem { return static::$filesystem; } @@ -151,9 +150,9 @@ class Flextype * Returns finder object * * @access public - * @return object + * @return Finder */ - public static function finder() + public static function finder() : Finder { return static::$finder; } diff --git a/flextype/I18n.php b/flextype/I18n.php index bc29e985..9f73cfc0 100644 --- a/flextype/I18n.php +++ b/flextype/I18n.php @@ -17,7 +17,7 @@ use Symfony\Component\Yaml\Yaml; class I18n { /** - * An instance of the Cache class + * An instance of the I18n class * * @var object */ diff --git a/flextype/Markdown.php b/flextype/Markdown.php index ad4a6c27..e57bc45d 100644 --- a/flextype/Markdown.php +++ b/flextype/Markdown.php @@ -20,7 +20,7 @@ class Markdown * Parsedown Extra Object * * @var object - * @access protected + * @access protected */ protected static $markdown; diff --git a/flextype/Plugins.php b/flextype/Plugins.php index 34e89c6e..66e74c9f 100755 --- a/flextype/Plugins.php +++ b/flextype/Plugins.php @@ -27,7 +27,6 @@ class Plugins * Init Plugins * * @access public - * @return mixed */ protected function __construct() { diff --git a/flextype/Shortcodes.php b/flextype/Shortcodes.php index 1d12ddb5..089b70a6 100644 --- a/flextype/Shortcodes.php +++ b/flextype/Shortcodes.php @@ -52,7 +52,7 @@ class Shortcodes * @access public * @return object */ - public static function driver() + public static function driver() : ShortcodeFacade { return static::$driver; } @@ -62,7 +62,7 @@ class Shortcodes * * @access protected */ - protected static function registerDefaultShortcodes() + protected static function registerDefaultShortcodes() : void { static::driver()->addHandler('site_url', function() { return Url::getBase(); From ce5869ab4c99c2c56456992cbb0f8c3a7fc2fa57 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 25 Mar 2018 04:40:06 +0300 Subject: [PATCH 3/9] Pages: getPages() - default order by date and null page array is fixed. parsefile() - get page url - fixed parseFile() - get page date and refactoring #5 --- flextype/Pages.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/flextype/Pages.php b/flextype/Pages.php index 6bb6d7ea..359d365c 100755 --- a/flextype/Pages.php +++ b/flextype/Pages.php @@ -56,7 +56,7 @@ class Pages /** * Page finder */ - public static function finder($url = '', $url_abs = false) + public static function finder(string $url = '', bool $url_abs = false) : string { // If url is empty that its a homepage @@ -88,7 +88,7 @@ class Pages /** * Render page */ - public static function renderPage($page) + public static function renderPage(array $page) { $template_ext = '.php'; $template_name = empty($page['template']) ? 'index' : $page['template']; @@ -105,7 +105,7 @@ class Pages /** * Page page file */ - public static function parseFile($file) + public static function parseFile(string $file) : array { $page = trim(file_get_contents($file)); $page = explode('---', $page, 3); @@ -118,6 +118,9 @@ class Pages $url = str_replace('index.md', '', $url); $url = str_replace('.md', '', $url); $url = str_replace('\\', '/', $url); + $url = str_replace('//', '/', $url); + $url = str_replace('http:/', 'http://', $url); + $url = str_replace('https:/', 'https://', $url); $url = rtrim($url, '/'); $result_page['url'] = $url; @@ -127,8 +130,13 @@ class Pages $url = rtrim($url, '/'); $result_page['slug'] = str_replace(Url::getBase(), '', $url); + // Set page date + $result_page['date'] = $result_page['date'] ?? date(Config::get('site.date_format'), filemtime($file)); + + // Set page content $result_page['content'] = $page[2]; + // Return page return $result_page; } @@ -136,7 +144,7 @@ class Pages /** * Get page */ - public static function getPage(string $url = '', bool $raw = false, bool $url_abs = false) + public static function getPage(string $url = '', bool $raw = false, bool $url_abs = false) : array { $file = static::finder($url, $url_abs); @@ -168,13 +176,17 @@ class Pages /** * Get Pages */ - public static function getPages($url = '', $raw = false, $order_by = 'title', $order_type = 'DESC', $limit = null) + public static function getPages($url = '', $raw = false, $order_by = 'date', $order_type = 'DESC', $limit = null) : array { // Get pages list for current $url $pages_list = Flextype::finder()->files()->name('*.md')->in(PAGES_PATH . '/' . $url); + // Pages + $pages = []; + // Go trough pages list foreach ($pages_list as $key => $page) { + $pages[$key] = static::getPage($page->getPathname(), $raw, true); if (strpos($page->getPathname(), $url.'/index.md') !== false) { } else { From d63863b6939ceed0651fa8a4172459cf6274a976 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 25 Mar 2018 04:41:25 +0300 Subject: [PATCH 4/9] Site config: date_format - added --- site/config/site.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/site/config/site.yml b/site/config/site.yml index 817a7492..9391eedd 100755 --- a/site/config/site.yml +++ b/site/config/site.yml @@ -8,6 +8,7 @@ author: email: "" timezone: UTC +date_format: "F d Y H:i:s." charset: UTF-8 theme: default From 6a442f2adb3b01b927ba62ba1813b1696fa8b37b Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 25 Mar 2018 16:50:32 +0300 Subject: [PATCH 5/9] Code cleanup and refactoring #5 --- index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index b4acda43..4ab0274a 100755 --- a/index.php +++ b/index.php @@ -18,11 +18,11 @@ define('FLEXTYPE_MINIMUM_PHP', '7.1.3'); // Check PHP Version version_compare($ver = PHP_VERSION, $req = FLEXTYPE_MINIMUM_PHP, '<') and exit(sprintf('You are running PHP %s, but Flextype needs at least PHP %s to run.', $ver, $req)); -// Ensure vendor libraries exist and Register The Auto Loader +// Ensure vendor libraries exist !is_file($autoload = __DIR__ . '/vendor/autoload.php') and exit("Please run: composer install"); -// Register the auto-loader. +// Register The Auto Loader $loader = require_once $autoload; -// Initialize Flextype Application +// Init Flextype Flextype::init(); From e6d2b4a76241f78ad5be4b0a27ef203409c69a20 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 26 Mar 2018 01:59:51 +0300 Subject: [PATCH 6/9] Pages: getPages() - fixes for pages sort and slice, fixes for getting pages list --- flextype/Pages.php | 50 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/flextype/Pages.php b/flextype/Pages.php index 359d365c..c5705f4e 100755 --- a/flextype/Pages.php +++ b/flextype/Pages.php @@ -58,7 +58,6 @@ class Pages */ public static function finder(string $url = '', bool $url_abs = false) : string { - // If url is empty that its a homepage if ($url_abs) { if ($url) { @@ -118,9 +117,11 @@ class Pages $url = str_replace('index.md', '', $url); $url = str_replace('.md', '', $url); $url = str_replace('\\', '/', $url); + $url = str_replace('///', '/', $url); $url = str_replace('//', '/', $url); $url = str_replace('http:/', 'http://', $url); $url = str_replace('https:/', 'https://', $url); + $url = str_replace('/'.Config::get('site.pages.main'), '', $url); $url = rtrim($url, '/'); $result_page['url'] = $url; @@ -144,7 +145,7 @@ class Pages /** * Get page */ - public static function getPage(string $url = '', bool $raw = false, bool $url_abs = false) : array + public static function getPage(string $url = '', bool $raw = false, bool $url_abs = false) { $file = static::finder($url, $url_abs); @@ -164,6 +165,9 @@ class Pages /** * Parse Content + * + * @param $content Сontent to parse + * @return string */ public static function parseContent(string $content) : string { @@ -176,33 +180,49 @@ class Pages /** * Get Pages */ - public static function getPages($url = '', $raw = false, $order_by = 'date', $order_type = 'DESC', $limit = null) : array + public static function getPages(string $url = '', bool $raw = false, string $order_by = 'date', string $order_type = 'DESC', int $offset = null, int $length = null) { - // Get pages list for current $url - $pages_list = Flextype::finder()->files()->name('*.md')->in(PAGES_PATH . '/' . $url); - - // Pages + // Pages array where founded pages will stored $pages = []; - // Go trough pages list - foreach ($pages_list as $key => $page) { - $pages[$key] = static::getPage($page->getPathname(), $raw, true); - if (strpos($page->getPathname(), $url.'/index.md') !== false) { + // Get pages for $url + // If $url is empty then we want to have a list of pages for /pages dir. + if ($url == '') { - } else { + // Get pages list + $pages_list = Flextype::finder()->files()->name('*.md')->in(PAGES_PATH); + + // Create pages array from pages list + foreach ($pages_list as $key => $page) { $pages[$key] = static::getPage($page->getPathname(), $raw, true); } + + } else { + + // Get pages list + $pages_list = Flextype::finder()->files()->name('*.md')->in(PAGES_PATH . '/' . $url); + + // Create pages array from pages list and ignore current requested page + foreach ($pages_list as $key => $page) { + if (strpos($page->getPathname(), $url.'/index.md') !== false) { + // ignore ... + } else { + $pages[$key] = static::getPage($page->getPathname(), $raw, true); + } + } + } - // Sort and Slice pages if !$raw + // Sort and Slice pages if $raw === false if (!$raw) { $pages = Arr::subvalSort($pages, $order_by, $order_type); - if ($limit != null) { - $pages = array_slice($_pages, null, $limit); + if ($offset !== null && $length !== null) { + $pages = array_slice($pages, $offset, $length); } } + // Return pages array return $pages; } From 643451ca2a7c8279cfbc7580a56cc2573178b278 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 26 Mar 2018 02:05:47 +0300 Subject: [PATCH 7/9] changelog updates --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 401beac3..d3d45e84 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# Flextype 0.2.1, 2018-03-26 +* date_format setting added to /site/config.site.yml +* Pages: Fixed bug with pages sort and slice in getPages() method +* Pages: Fixed bug with pages list for /pages folder +* Pages: Fixes for generating page url field +* Pages: Added ability to create date field automatically for pages if date field is not exists. +* Code cleanup and refactoring #5 + # Flextype 0.2.0, 2018-03-23 * Thunderer Shortcode Framework - added * Cache Flextype::VERSION for cache key - added From f1110182ee035676bc642b317202525a7807deb4 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 26 Mar 2018 12:41:46 +0300 Subject: [PATCH 8/9] Code cleanup and refactoring #5 --- flextype/Pages.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flextype/Pages.php b/flextype/Pages.php index c5705f4e..942a4468 100755 --- a/flextype/Pages.php +++ b/flextype/Pages.php @@ -36,7 +36,7 @@ class Pages /** * Constructor * - * @param Flextype $flextype + * @access protected */ protected function __construct() { @@ -55,6 +55,9 @@ class Pages /** * Page finder + * + * @param string $url + * @param bool $url_abs */ public static function finder(string $url = '', bool $url_abs = false) : string { From d567a1eb3a9ee55f49581c0efdcec9899017c34f Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 26 Mar 2018 12:45:45 +0300 Subject: [PATCH 9/9] Flextype 0.2.1 --- README.md | 2 +- flextype/Flextype.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2b98c78c..34488c50 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Flextype -![version](https://img.shields.io/badge/version-0.2.0-brightgreen.svg?style=flat-square "Version") +![version](https://img.shields.io/badge/version-0.2.1-brightgreen.svg?style=flat-square "Version") [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](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. diff --git a/flextype/Flextype.php b/flextype/Flextype.php index c3ea1438..761709a7 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -57,7 +57,7 @@ class Flextype * * @var string */ - const VERSION = '0.2.0'; + const VERSION = '0.2.1'; /** * Constructor.