mirror of
https://github.com/flextype/flextype.git
synced 2025-08-15 09:34:14 +02:00
Merge remote-tracking branch 'origin/dev'
This commit is contained in:
@@ -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
|
||||
|
@@ -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.
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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(
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
@@ -58,7 +57,7 @@ class Flextype
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION = '0.2.0';
|
||||
const VERSION = '0.2.1';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -20,7 +20,7 @@ class Markdown
|
||||
* Parsedown Extra Object
|
||||
*
|
||||
* @var object
|
||||
* @access protected
|
||||
* @access protected
|
||||
*/
|
||||
protected static $markdown;
|
||||
|
||||
|
@@ -36,7 +36,7 @@ class Pages
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Flextype $flextype
|
||||
* @access protected
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
@@ -55,10 +55,12 @@ class Pages
|
||||
|
||||
/**
|
||||
* Page finder
|
||||
*
|
||||
* @param string $url
|
||||
* @param bool $url_abs
|
||||
*/
|
||||
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
|
||||
if ($url_abs) {
|
||||
if ($url) {
|
||||
@@ -88,7 +90,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 +107,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 +120,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;
|
||||
|
||||
@@ -127,8 +134,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;
|
||||
}
|
||||
|
||||
@@ -156,6 +168,9 @@ class Pages
|
||||
|
||||
/**
|
||||
* Parse Content
|
||||
*
|
||||
* @param $content Сontent to parse
|
||||
* @return string
|
||||
*/
|
||||
public static function parseContent(string $content) : string
|
||||
{
|
||||
@@ -168,29 +183,49 @@ class Pages
|
||||
/**
|
||||
* Get Pages
|
||||
*/
|
||||
public static function getPages($url = '', $raw = false, $order_by = 'title', $order_type = 'DESC', $limit = null)
|
||||
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 array where founded pages will stored
|
||||
$pages = [];
|
||||
|
||||
// Go trough pages list
|
||||
foreach ($pages_list as $key => $page) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,6 @@ class Plugins
|
||||
* Init Plugins
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
|
@@ -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();
|
||||
|
@@ -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 <strong>PHP %s</strong> 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: <i>composer install</i>");
|
||||
|
||||
// Register the auto-loader.
|
||||
// Register The Auto Loader
|
||||
$loader = require_once $autoload;
|
||||
|
||||
// Initialize Flextype Application
|
||||
// Init Flextype
|
||||
Flextype::init();
|
||||
|
@@ -8,6 +8,7 @@ author:
|
||||
email: ""
|
||||
|
||||
timezone: UTC
|
||||
date_format: "F d Y H:i:s."
|
||||
charset: UTF-8
|
||||
|
||||
theme: default
|
||||
|
Reference in New Issue
Block a user