diff --git a/CHANGELOG.md b/CHANGELOG.md
index a05b253f..401beac3 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/LICENSE.txt b/LICENSE.txt
index a34d214f..3f865be1 100755
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -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
diff --git a/composer.json b/composer.json
index 7b8bc640..3171b847 100755
--- a/composer.json
+++ b/composer.json
@@ -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"
]
}
}
diff --git a/flextype/Cache.php b/flextype/Cache.php
index 78952a23..184157f6 100755
--- a/flextype/Cache.php
+++ b/flextype/Cache.php
@@ -1,4 +1,4 @@
-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
*
- *
- * Cache::init();
- *
- *
* @access public
* @return object
*/
diff --git a/flextype/Config.php b/flextype/Config.php
index ae493e28..bc59abaf 100755
--- a/flextype/Config.php
+++ b/flextype/Config.php
@@ -1,7 +1,4 @@
-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
*
- *
- * $config = Config::getConfig();
- *
- *
* @access public
* @return array
*/
@@ -99,10 +97,6 @@ class Config
/**
* Initialize Flextype Config
*
- *
- * Config::init();
- *
- *
* @access public
*/
public static function init()
diff --git a/flextype/Events.php b/flextype/Events.php
index b2949c1d..6457660b 100644
--- a/flextype/Events.php
+++ b/flextype/Events.php
@@ -1,6 +1,4 @@
-
- * Filter::dispatch('content', $content);
- *
- *
* @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
*
- *
- * Filter::add('content', 'replacer');
- *
- * function replacer($content) {
- * return preg_replace(array('/\[b\](.*?)\[\/b\]/ms'), array('\1'), $content);
- * }
- *
- *
* @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.
diff --git a/flextype/Flextype.php b/flextype/Flextype.php
index 3b229e1f..76838c33 100755
--- a/flextype/Flextype.php
+++ b/flextype/Flextype.php
@@ -1,20 +1,22 @@
-
+ * @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
- * @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
*
- *
- * Rawium::init();
- *
- *
* @access public
* @return object
*/
diff --git a/flextype/I18n.php b/flextype/I18n.php
index e1fc26a6..bc29e985 100644
--- a/flextype/I18n.php
+++ b/flextype/I18n.php
@@ -1,6 +1,4 @@
-
- * I18n::init();
- *
- *
* @access public
* @return object
*/
diff --git a/flextype/Markdown.php b/flextype/Markdown.php
index 4b7165ea..ad4a6c27 100644
--- a/flextype/Markdown.php
+++ b/flextype/Markdown.php
@@ -1,6 +1,4 @@
-
- * $content = Markdown::parse($content);
- *
- *
* @access public
* @param string $content Content to parse
* @return string Formatted content
diff --git a/flextype/Pages.php b/flextype/Pages.php
index f17d12ed..6bb6d7ea 100755
--- a/flextype/Pages.php
+++ b/flextype/Pages.php
@@ -1,10 +1,4 @@
-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
*
- *
- * Pages::init();
- *
- *
* @access public
* @return object
*/
diff --git a/flextype/Plugins.php b/flextype/Plugins.php
index e5b9f0c2..34e89c6e 100755
--- a/flextype/Plugins.php
+++ b/flextype/Plugins.php
@@ -1,6 +1,4 @@
-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
*
- *
- * Plugins::init();
- *
- *
* @access public
* @return object
*/
diff --git a/flextype/Shortcodes.php b/flextype/Shortcodes.php
index 746f3269..1d12ddb5 100644
--- a/flextype/Shortcodes.php
+++ b/flextype/Shortcodes.php
@@ -1,4 +1,4 @@
-addHandler('site_url', function() {
+ return Url::getBase();
+ });
}
/**
- * Remove all registered shortcodes.
- *
- *
- * Shortcode::clear();
- *
+ * 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();
}
}
diff --git a/flextype/Templates.php b/flextype/Templates.php
index 4ddfbc68..35a154ca 100644
--- a/flextype/Templates.php
+++ b/flextype/Templates.php
@@ -1,4 +1,4 @@
-exists($template_path)) {
+ if (Flextype::filesystem()->exists($template_path)) {
include $template_path;
} else {
throw new RuntimeException("Template {$template_name} does not exist.");
diff --git a/flextype/Themes.php b/flextype/Themes.php
index 7b01da29..5478ab8e 100644
--- a/flextype/Themes.php
+++ b/flextype/Themes.php
@@ -1,6 +1,4 @@
-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
*
- *
- * Themes::init();
- *
- *
* @access public
* @return object
*/
diff --git a/flextype/boot/defines.php b/flextype/boot/defines.php
index 6de5b395..b76a107c 100755
--- a/flextype/boot/defines.php
+++ b/flextype/boot/defines.php
@@ -1,4 +1,4 @@
-
- * @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('');
-});
diff --git a/flextype/boot/shortcodes.php b/flextype/boot/shortcodes.php
deleted file mode 100644
index 89bf6521..00000000
--- a/flextype/boot/shortcodes.php
+++ /dev/null
@@ -1,18 +0,0 @@
-
- * @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();
-});
diff --git a/index.php b/index.php
index e441a51f..b4acda43 100755
--- a/index.php
+++ b/index.php
@@ -1,4 +1,4 @@
-