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

Merge pull request #12 from flextype/dev

Merge with Dev
This commit is contained in:
Sergey Romanenko
2018-03-23 02:20:49 +03:00
committed by GitHub
20 changed files with 178 additions and 236 deletions

View File

@@ -1,2 +1,9 @@
# Flextype 0.2.0, 2018-03-23
* Thunderer Shortcode Framework - added
* Cache Flextype::VERSION for cache key - added
* flextype/boot/shortcodes.php - removed
* flextype/boot/events.php - removed
* Code cleanup and refactoring #5
# Flextype 0.1.0, 2018-03-21
* Initial Release

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2018 Flextype Content Management
Copyright (c) 2018 Flextype
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,8 +1,8 @@
{
"name": "flextype/flextype",
"type": "library",
"type": "project",
"description": "Flextype is Modern Open Source Flat-File Content Management System",
"keywords": ["Flextype", "php", "cms", "flat-file", "markdown"],
"keywords": ["Flextype", "php", "cms", "flat-file cms", "flat cms", "flatfile cms", "markdown"],
"homepage": "http://flextype.org",
"license": "MIT",
"authors": [
@@ -23,6 +23,7 @@
"symfony/yaml": "4.0.4",
"symfony/filesystem": "4.0.4",
"symfony/finder": "4.0.4",
"thunderer/shortcode": "0.6.5",
"force/session" : "*",
"force/arr" : "*",
"force/http" : "*",
@@ -35,9 +36,7 @@
"flextype"
],
"files": [
"flextype/boot/defines.php",
"flextype/boot/shortcodes.php",
"flextype/boot/events.php"
"flextype/boot/defines.php"
]
}
}

View File

@@ -1,4 +1,4 @@
<?php namespace Flextype;
<?php
/**
* @package Flextype
@@ -10,6 +10,8 @@
* file that was distributed with this source code.
*/
namespace Flextype;
class Cache
{
/**
@@ -18,30 +20,35 @@ class Cache
* @var object
*/
protected static $instance = null;
/**
* Unique cache key
*
* @var string Cache key.
*/
protected static $key;
/**
* Lifetime
*
* @var int Lifetime.
*/
protected static $lifetime;
/**
* Current time
*
* @var int Current time.
*/
protected static $now;
/**
* Cache Driver
*
* @var DoctrineCache
*/
protected static $driver;
/**
* Protected clone method to enforce singleton behavior.
*
@@ -63,7 +70,7 @@ class Cache
static::$now = time();
// Cache key allows us to invalidate all cache on configuration changes.
static::$key = (Config::get('site.cache.prefix') ? Config::get('site.cache.prefix') : 'flextype') . '-' . md5(ROOT_DIR);
static::$key = (Config::get('site.cache.prefix') ? Config::get('site.cache.prefix') : 'flextype') . '-' . md5(ROOT_DIR . Flextype::VERSION);
// Get Cache Driver
static::$driver = static::getCacheDriver();
@@ -118,7 +125,7 @@ class Cache
break;
default:
// Create doctrine cache directory if its not exists
!Flextype::$filesystem->exists($cache_directory = CACHE_PATH . '/doctrine/') and Flextype::$filesystem->mkdir($cache_directory);
!Flextype::filesystem()->exists($cache_directory = CACHE_PATH . '/doctrine/') and Flextype::filesystem()->mkdir($cache_directory);
$driver = new \Doctrine\Common\Cache\FilesystemCache($cache_directory);
break;
}
@@ -182,13 +189,13 @@ class Cache
static::$driver->save($id, $data, $lifetime);
}
}
/**
* Clear Cache
*/
public static function clear()
{
Flextype::$filesystem->remove(CACHE_PATH . '/doctrine/');
Flextype::filesystem()->remove(CACHE_PATH . '/doctrine/');
}
/**
@@ -225,10 +232,6 @@ class Cache
/**
* Initialize Flextype Cache
*
* <code>
* Cache::init();
* </code>
*
* @access public
* @return object
*/

View File

@@ -1,7 +1,4 @@
<?php namespace Flextype;
use Arr;
use Symfony\Component\Yaml\Yaml;
<?php
/**
* @package Flextype
@@ -13,6 +10,11 @@ use Symfony\Component\Yaml\Yaml;
* file that was distributed with this source code.
*/
namespace Flextype;
use Arr;
use Symfony\Component\Yaml\Yaml;
class Config
{
@@ -49,7 +51,7 @@ class Config
*/
protected function __construct()
{
if (Flextype::$filesystem->exists($site_config = CONFIG_PATH . '/' . 'site.yml')) {
if (Flextype::filesystem()->exists($site_config = CONFIG_PATH . '/' . 'site.yml')) {
static::$config['site'] = Yaml::parse(file_get_contents($site_config));
} else {
throw new RuntimeException("Flextype site config file does not exist.");
@@ -84,10 +86,6 @@ class Config
/**
* Get config array
*
* <code>
* $config = Config::getConfig();
* </code>
*
* @access public
* @return array
*/
@@ -99,10 +97,6 @@ class Config
/**
* Initialize Flextype Config
*
* <code>
* Config::init();
* </code>
*
* @access public
*/
public static function init()

View File

@@ -1,6 +1,4 @@
<?php namespace Flextype;
use Arr;
<?php
/**
* @package Flextype
@@ -11,6 +9,10 @@ use Arr;
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flextype;
use Arr;
class Events
{

View File

@@ -1,4 +1,4 @@
<?php namespace Flextype;
<?php
/**
* @package Flextype
@@ -10,6 +10,8 @@
* file that was distributed with this source code.
*/
namespace Flextype;
class Filters
{
@@ -40,10 +42,6 @@ class Filters
/**
* Dispatch filters
*
* <code>
* Filter::dispatch('content', $content);
* </code>
*
* @access public
* @param string $filter_name The name of the filter hook.
* @param mixed $value The value on which the filters hooked.
@@ -83,14 +81,6 @@ class Filters
/**
* Add filter
*
* <code>
* Filter::add('content', 'replacer');
*
* function replacer($content) {
* return preg_replace(array('/\[b\](.*?)\[\/b\]/ms'), array('<strong>\1</strong>'), $content);
* }
* </code>
*
* @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.

View File

@@ -1,20 +1,22 @@
<?php namespace Flextype;
<?php
/**
* @package Flextype
*
* @author Romanenko Sergey / Awilum <awilum@yandex.ru>
* @link http://flextype.org
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flextype;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Url;
use Session;
/**
* @package Flextype
*
* @author Romanenko Sergey / Awilum <awilum@yandex.ru>
* @link http://flextype.org
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Flextype
{
/**
@@ -26,7 +28,7 @@ class Flextype
protected static $instance = null;
/**
* Filesystem
* Filesystem object
*
* @var object
* @access public
@@ -34,7 +36,7 @@ class Flextype
public static $filesystem = null;
/**
* Finder
* Finder object
*
* @var object
* @access public
@@ -56,7 +58,7 @@ class Flextype
*
* @var string
*/
const VERSION = '0.1.0';
const VERSION = '0.2.0';
/**
* Constructor.
@@ -65,8 +67,20 @@ class Flextype
*/
protected function __construct()
{
static::app();
}
/**
* Application.
*
* @access protected
*/
protected static function app()
{
// Init Finder
static::$finder = new Finder();
// Init Filesystem
static::$filesystem = new Filesystem();
// Init Config
@@ -106,26 +120,47 @@ class Flextype
// Init I18n
I18n::init();
// Init Shortcodes
Shortcodes::init();
// Init Themes
Themes::init();
// Init Plugins
Plugins::init();
// Render current page
// Init Pages
Pages::init();
// Flush (send) the output buffer and turn off output buffering
ob_end_flush();
}
/**
* Returns filesystem object
*
* @access public
* @return object
*/
public static function filesystem()
{
return static::$filesystem;
}
/**
* Returns finder object
*
* @access public
* @return object
*/
public static function finder()
{
return static::$finder;
}
/**
* Initialize Flextype Application
*
* <code>
* Rawium::init();
* </code>
*
* @access public
* @return object
*/

View File

@@ -1,6 +1,4 @@
<?php namespace Flextype;
use Symfony\Component\Yaml\Yaml;
<?php
/**
* @package Flextype
@@ -12,6 +10,10 @@ use Symfony\Component\Yaml\Yaml;
* file that was distributed with this source code.
*/
namespace Flextype;
use Symfony\Component\Yaml\Yaml;
class I18n
{
/**
@@ -131,10 +133,6 @@ class I18n
/**
* Initialize Flextype I18n
*
* <code>
* I18n::init();
* </code>
*
* @access public
* @return object
*/

View File

@@ -1,6 +1,4 @@
<?php namespace Flextype;
use ParsedownExtra;
<?php
/**
* @package Flextype
@@ -12,6 +10,10 @@ use ParsedownExtra;
* file that was distributed with this source code.
*/
namespace Flextype;
use ParsedownExtra;
class Markdown
{
/**
@@ -25,10 +27,6 @@ class Markdown
/**
* Markdown parser
*
* <code>
* $content = Markdown::parse($content);
* </code>
*
* @access public
* @param string $content Content to parse
* @return string Formatted content

View File

@@ -1,10 +1,4 @@
<?php namespace Flextype;
use Arr;
use Url;
use Response;
use Shortcode;
use Symfony\Component\Yaml\Yaml;
<?php
/**
* @package Flextype
@@ -16,6 +10,13 @@ use Symfony\Component\Yaml\Yaml;
* file that was distributed with this source code.
*/
namespace Flextype;
use Arr;
use Url;
use Response;
use Symfony\Component\Yaml\Yaml;
class Pages
{
/**
@@ -74,7 +75,7 @@ class Pages
}
// Get 404 page if file not exists
if (Flextype::$filesystem->exists($file)) {
if (Flextype::filesystem()->exists($file)) {
$file = $file;
} else {
$file = PAGES_PATH . '/404/index.md';
@@ -94,7 +95,7 @@ class Pages
$site_theme = Config::get('site.theme');
$template_path = THEMES_PATH . '/' . $site_theme . '/' . $template_name . $template_ext;
if (Flextype::$filesystem->exists($template_path)) {
if (Flextype::filesystem()->exists($template_path)) {
include $template_path;
} else {
throw new RuntimeException("Template {$template_name} does not exist.");
@@ -109,7 +110,7 @@ class Pages
$page = trim(file_get_contents($file));
$page = explode('---', $page, 3);
$frontmatter = Shortcodes::parse($page[1]);
$frontmatter = Shortcodes::driver()->process($page[1]);
$result_page = Yaml::parse($frontmatter);
// Get page url
@@ -154,11 +155,11 @@ class Pages
}
/**
* Parse Cntent
* Parse Content
*/
public static function parseContent(string $content) : string
{
$content = Shortcodes::parse($content);
$content = Shortcodes::driver()->process($content);
$content = Markdown::parse($content);
return $content;
@@ -170,7 +171,7 @@ class Pages
public static function getPages($url = '', $raw = false, $order_by = 'title', $order_type = 'DESC', $limit = null)
{
// Get pages list for current $url
$pages_list = Flextype::$finder->files()->name('*.md')->in(PAGES_PATH . '/' . $url);
$pages_list = Flextype::finder()->files()->name('*.md')->in(PAGES_PATH . '/' . $url);
// Go trough pages list
foreach ($pages_list as $key => $page) {
@@ -196,10 +197,6 @@ class Pages
/**
* Initialize Flextype Pages
*
* <code>
* Pages::init();
* </code>
*
* @access public
* @return object
*/

View File

@@ -1,6 +1,4 @@
<?php namespace Flextype;
use Symfony\Component\Yaml\Yaml;
<?php
/**
* @package Flextype
@@ -12,6 +10,10 @@ use Symfony\Component\Yaml\Yaml;
* file that was distributed with this source code.
*/
namespace Flextype;
use Symfony\Component\Yaml\Yaml;
class Plugins
{
/**
@@ -43,7 +45,7 @@ class Plugins
// Go through...
foreach ($plugins_list as $plugin) {
if (Flextype::$filesystem->exists($_plugin = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
if (Flextype::filesystem()->exists($_plugin = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
$plugins_cache_id .= filemtime($_plugin);
}
}
@@ -63,7 +65,7 @@ class Plugins
// Go through...
foreach ($plugins_list as $plugin) {
if (Flextype::$filesystem->exists($_plugin_manifest = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
if (Flextype::filesystem()->exists($_plugin_manifest = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) {
$plugin_manifest = Yaml::parseFile($_plugin_manifest);
}
@@ -90,10 +92,6 @@ class Plugins
/**
* Initialize Flextype Plugins
*
* <code>
* Plugins::init();
* </code>
*
* @access public
* @return object
*/

View File

@@ -1,4 +1,4 @@
<?php namespace Flextype;
<?php
/**
* @package Flextype
@@ -10,15 +10,27 @@
* file that was distributed with this source code.
*/
namespace Flextype;
use Thunder\Shortcode\ShortcodeFacade;
use Url;
class Shortcodes
{
/**
* Shortcode tags array
* An instance of the Shortcodes class
*
* @var shortcode_tags
* @var object
*/
protected static $shortcode_tags = [];
protected static $instance = null;
/**
* ShortcodeFacade Driver
*
* @var ShortcodeFacade
*/
protected static $driver;
/**
* Protected constructor since this is a static class.
@@ -27,105 +39,44 @@ class Shortcodes
*/
protected function __construct()
{
// Nothing here
// Set driver
static::$driver = new ShortcodeFacade();
// Register Default Shortcodes
static::registerDefaultShortcodes();
}
/**
* Add new shortcode
* Returns driver variable
*
* @param string $shortcode Shortcode tag to be searched in content.
* @param string $callback_function The callback function to replace the shortcode with.
* @access public
* @return object
*/
public static function add(string $shortcode, $callback_function)
public static function driver()
{
// Add new shortcode
if (is_callable($callback_function)) {
static::$shortcode_tags[$shortcode] = $callback_function;
}
return static::$driver;
}
/**
* Remove a specific registered shortcode.
* Register default shortcodes
*
* @param string $shortcode Shortcode tag.
* @access protected
*/
public static function delete(string $shortcode)
protected static function registerDefaultShortcodes()
{
// Delete shortcode
if (static::exists($shortcode)) {
unset(static::$shortcode_tags[$shortcode]);
}
static::driver()->addHandler('site_url', function() {
return Url::getBase();
});
}
/**
* Remove all registered shortcodes.
*
* <code>
* Shortcode::clear();
* </code>
* Initialize Flextype Shortcodes
*
* @access public
* @return object
*/
public static function clear()
public static function init()
{
static::$shortcode_tags = array();
}
/**
* Check if a shortcode has been registered.
*
* @param string $shortcode Shortcode tag.
*/
public static function exists(string $shortcode)
{
// Check shortcode
return array_key_exists($shortcode, static::$shortcode_tags);
}
/**
* Parse a string, and replace any registered shortcodes within it with the result of the mapped callback.
*
* @param string $content Content
* @return string
*/
public static function parse(string $content)
{
if (! static::$shortcode_tags) {
return $content;
}
$shortcodes = implode('|', array_map('preg_quote', array_keys(static::$shortcode_tags)));
$pattern = "/(.?)\{([$shortcodes]+)(.*?)(\/)?\}(?(4)|(?:(.+?)\{\/\s*\\2\s*\}))?(.?)/s";
return preg_replace_callback($pattern, 'static::_handle', $content);
}
/**
* _handle()
*/
protected static function _handle($matches)
{
$prefix = $matches[1];
$suffix = $matches[6];
$shortcode = $matches[2];
// Allow for escaping shortcodes by enclosing them in {{shortcode}}
if ($prefix == '{' && $suffix == '}') {
return substr($matches[0], 1, -1);
}
$attributes = array(); // Parse attributes into into this array.
if (preg_match_all('/(\w+) *= *(?:([\'"])(.*?)\\2|([^ "\'>]+))/', $matches[3], $match, PREG_SET_ORDER)) {
foreach ($match as $attribute) {
if (! empty($attribute[4])) {
$attributes[strtolower($attribute[1])] = $attribute[4];
} elseif (! empty($attribute[3])) {
$attributes[strtolower($attribute[1])] = $attribute[3];
}
}
}
// Check if this shortcode realy exists then call user function else return empty string
return (isset(static::$shortcode_tags[$shortcode])) ? $prefix . call_user_func(static::$shortcode_tags[$shortcode], $attributes, $matches[5], $shortcode) . $suffix : '';
return !isset(self::$instance) and self::$instance = new Shortcodes();
}
}

View File

@@ -1,4 +1,4 @@
<?php namespace Flextype;
<?php
/**
* @package Flextype
@@ -10,6 +10,8 @@
* file that was distributed with this source code.
*/
namespace Flextype;
class Templates
{
@@ -38,7 +40,7 @@ class Templates
$template_path = THEMES_PATH . '/' . Config::get('site.theme') . '/' . $template_name . $template_ext;
if (Flextype::$filesystem->exists($template_path)) {
if (Flextype::filesystem()->exists($template_path)) {
include $template_path;
} else {
throw new RuntimeException("Template {$template_name} does not exist.");

View File

@@ -1,6 +1,4 @@
<?php namespace Flextype;
use Symfony\Component\Yaml\Yaml;
<?php
/**
* @package Flextype
@@ -12,6 +10,10 @@ use Symfony\Component\Yaml\Yaml;
* file that was distributed with this source code.
*/
namespace Flextype;
use Symfony\Component\Yaml\Yaml;
class Themes
{
/**
@@ -35,7 +37,7 @@ class Themes
// Get current theme
$theme = Config::get('site.theme');
if (Flextype::$filesystem->exists($theme_manifest_file = THEMES_PATH . '/' . $theme . '/' . $theme . '.yml')) {
if (Flextype::filesystem()->exists($theme_manifest_file = THEMES_PATH . '/' . $theme . '/' . $theme . '.yml')) {
$theme_manifest = Yaml::parseFile($theme_manifest_file);
Config::set('themes.'.Config::get('site.theme'), $theme_manifest);
}
@@ -44,10 +46,6 @@ class Themes
/**
* Initialize Flextype Themes
*
* <code>
* Themes::init();
* </code>
*
* @access public
* @return object
*/

View File

@@ -1,4 +1,4 @@
<?php namespace Flextype;
<?php
/**
* @package Flextype
@@ -10,6 +10,8 @@
* file that was distributed with this source code.
*/
namespace Flextype;
// Define the path to the root directory (without trailing slash).
define('ROOT_DIR', str_replace(DIRECTORY_SEPARATOR, '/', getcwd()));

View File

@@ -1,16 +0,0 @@
<?php namespace Flextype;
/**
* @package Flextype
*
* @author Sergey Romanenko <awilum@yandex.ru>
* @link http://flextype.org
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Set Flextype Meta Generator
Events::addListener('onThemeMeta', function () {
echo('<meta name="generator" content="Powered by Flextype" />');
});

View File

@@ -1,18 +0,0 @@
<?php namespace Flextype;
use Url;
/**
* @package Flextype
*
* @author Sergey Romanenko <awilum@yandex.ru>
* @link http://flextype.org
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Add {site_url} shortcode
Shortcodes::add('site_url', function () {
return Url::getBase();
});

View File

@@ -1,4 +1,4 @@
<?php namespace Flextype;
<?php
/**
* @package Flextype
@@ -10,6 +10,8 @@
* file that was distributed with this source code.
*/
namespace Flextype;
// Define the application minimum supported PHP version.
define('FLEXTYPE_MINIMUM_PHP', '7.1.3');

View File

@@ -24,6 +24,6 @@ Creating a new page is very simple in Flextype.
This is the body of **My New Page**
```
2. Save this file in the `/site/pages/my-new-page/` folder as `index.md` and its will be available by this url: {site_url}/my-new-page
2. Save this file in the `/site/pages/my-new-page/` folder as `index.md` and its will be available by this url: [site_url]/my-new-page
That is it!