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

Flextype Slim Integration - Commit with last code updates and research.

This commit is contained in:
Awilum
2019-02-23 23:18:57 +03:00
parent a8bd83cd28
commit bc3027d56c
40 changed files with 6941 additions and 785 deletions

View File

@@ -39,7 +39,9 @@
"flextype-components/token" : "1.2.0",
"flextype-components/view" : "1.1.1",
"flextype-components/text" : "1.1.2",
"league/glide": "^1.4"
"league/glide": "^1.4",
"slim/slim": "^3.0",
"slim/twig-view": "^2.4"
},
"autoload": {
"classmap": [

1842
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -97,7 +97,7 @@ class Cache
Cache::$now = time();
// Create cache key to allow invalidate all cache on configuration changes.
Cache::$key = (Registry::get('settings.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . Flextype::VERSION);
Cache::$key = (Registry::get('settings.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . 'Flextype::VERSION');
// Get Cache Driver
Cache::$driver = Cache::getCacheDriver();

View File

@@ -19,6 +19,13 @@ use Flextype\Component\Registry\Registry;
class Entries
{
private $flextype;
public function __construct($flextype)
{
$this->flextype = $flextype;
}
/**
* Fetch entry
*
@@ -26,8 +33,9 @@ class Entries
* @param string $entry Entry
* @return array|false The entry contents or false on failure.
*/
public static function fetch(string $entry)
public function fetch(string $entry)
{
$entry_file = Entries::_file_location($entry);
if (Filesystem::has($entry_file)) {
@@ -53,7 +61,7 @@ class Entries
// Apply Shortcodes for each entry fields
foreach ($entry_decoded as $key => $_entry_decoded) {
$entry_decoded[$key] = Shortcodes::process($_entry_decoded);
$entry_decoded[$key] = $this->flextype['shortcodes']->process($_entry_decoded);
}
// Save to cache
@@ -84,7 +92,7 @@ class Entries
* @param int $length Length
* @return array The entries
*/
public static function fetchAll(string $entry, string $order_by = 'date', string $order_type = 'DESC', int $offset = null, int $length = null) : array
public function fetchAll(string $entry, string $order_by = 'date', string $order_type = 'DESC', int $offset = null, int $length = null) : array
{
// Entries array where founded entries will stored
$entries = [];
@@ -93,7 +101,7 @@ class Entries
$cache_id = '';
// Entries path
$entries_path = Entries::_dir_location($entry);
$entries_path = $this->_dir_location($entry);
// Get entries list
$entries_list = Filesystem::listContents($entries_path);
@@ -119,7 +127,7 @@ class Entries
// ignore ...
} else {
if ($current_entry['type'] == 'dir' && Filesystem::has($current_entry['path'] . '/entry.yaml')) {
$entries[$current_entry['dirname']] = Entries::fetch($entry . '/' . $current_entry['dirname']);
$entries[$current_entry['dirname']] = $this->fetch($entry . '/' . $current_entry['dirname']);
}
}
}
@@ -148,9 +156,9 @@ class Entries
* @param string $new_entry New entry
* @return bool True on success, false on failure.
*/
public static function rename(string $entry, string $new_entry) : bool
public function rename(string $entry, string $new_entry) : bool
{
return rename(Entries::_dir_location($entry), Entries::_dir_location($new_entry));
return rename($this->_dir_location($entry), $this->_dir_location($new_entry));
}
/**
@@ -161,9 +169,9 @@ class Entries
* @param array $data Data
* @return bool
*/
public static function update(string $entry, array $data) : bool
public function update(string $entry, array $data) : bool
{
$entry_file = Entries::_file_location($entry);
$entry_file = $this->_file_location($entry);
if (Filesystem::has($entry_file)) {
return Filesystem::write($entry_file, YamlParser::encode($data));
@@ -180,9 +188,9 @@ class Entries
* @param array $data Data
* @return bool
*/
public static function create(string $entry, array $data) : bool
public function create(string $entry, array $data) : bool
{
$entry_dir = Entries::_dir_location($entry);
$entry_dir = $this->_dir_location($entry);
// Check if new entry directory exists
if (!Filesystem::has($entry_dir)) {
@@ -213,9 +221,9 @@ class Entries
* @param string $entry Entry
* @return bool True on success, false on failure.
*/
public static function delete(string $entry) : bool
public function delete(string $entry) : bool
{
return Filesystem::deleteDir(Entries::_dir_location($entry));
return Filesystem::deleteDir($this->_dir_location($entry));
}
/**
@@ -227,9 +235,9 @@ class Entries
* @param bool $recursive Recursive copy entries.
* @return bool True on success, false on failure.
*/
public static function copy(string $entry, string $new_entry, bool $recursive = false) : bool
public function copy(string $entry, string $new_entry, bool $recursive = false) : bool
{
return Filesystem::copy(Entries::_dir_location($entry), Entries::_dir_location($new_entry), $recursive);
return Filesystem::copy($this->_dir_location($entry), $this->_dir_location($new_entry), $recursive);
}
/**
@@ -239,9 +247,9 @@ class Entries
* @param string $entry Entry
* @return bool
*/
public static function has(string $entry) : bool
public function has(string $entry) : bool
{
return Filesystem::has(Entries::_file_location($entry));
return Filesystem::has($this->_file_location($entry));
}
/**
@@ -251,7 +259,7 @@ class Entries
* @param string $name Name
* @return string
*/
private static function _file_location(string $name) : string
private function _file_location(string $name) : string
{
return PATH['entries'] . '/' . $name . '/entry.yaml';
}
@@ -263,7 +271,7 @@ class Entries
* @param string $name Name
* @return string
*/
private static function _dir_location(string $name) : string
private function _dir_location(string $name) : string
{
return PATH['entries'] . '/' . $name;
}

View File

@@ -17,177 +17,195 @@ use Flextype\Component\Session\Session;
use Flextype\Component\ErrorHandler\ErrorHandler;
use Flextype\Component\Registry\Registry;
use Flextype\Component\Filesystem\Filesystem;
use Thunder\Shortcode\ShortcodeFacade;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
use Slim\Http\Request;
use Slim\Http\Response;
class Flextype
{
/**
* The version of Flextype
*
* @var string
*/
const VERSION = '0.8.3';
/**
* The version of Flextype
*
* @var string
*/
// const VERSION = '0.8.3';
/**
* An instance of the Flextype class
*
* @var object
* @access private
*/
private static $instance = null;
/**
* Private clone method to enforce singleton behavior.
*
* @access private
*/
private function __clone()
{
// Set empty settings array
Registry::set('settings', []);
// Set settings files path
$default_settings_file_path = PATH['config']['default'] . '/settings.yaml';
$site_settings_file_path = PATH['config']['site'] . '/settings.yaml';
// Set settings if Flextype settings and Site settings config files exist
if (Filesystem::has($default_settings_file_path) && Filesystem::has($site_settings_file_path)) {
if (($content = Filesystem::read($default_settings_file_path)) === false) {
throw new \RuntimeException('Load file: ' . $default_settings_file_path . ' - failed!');
} else {
$default_settings = YamlParser::decode($content);
}
/**
* Private wakeup method to enforce singleton behavior.
*
* @access private
*/
private function __wakeup()
{
if (($content = Filesystem::read($site_settings_file_path)) === false) {
throw new \RuntimeException('Load file: ' . $site_settings_file_path . ' - failed!');
} else {
$site_settings = YamlParser::decode($content);
}
/**
* Private construct method to enforce singleton behavior.
*
* @access private
*/
private function __construct()
{
Flextype::init();
}
// Merge settings
$settings = array_replace_recursive($default_settings, $site_settings);
/**
* Init Flextype Application
*
* @access private
*/
private static function init() : void
{
// Turn on output buffering
ob_start();
// Set Flextype config
Flextype::setConfig();
// Set internal encoding
function_exists('mb_language') and mb_language('uni');
function_exists('mb_regex_encoding') and mb_regex_encoding(Registry::get('settings.charset'));
function_exists('mb_internal_encoding') and mb_internal_encoding(Registry::get('settings.charset'));
// Set error handler
Flextype::setErrorHandler();
// Set default timezone
date_default_timezone_set(Registry::get('settings.timezone'));
// Start the session
Session::start();
// Get Cache Instance
Cache::getInstance();
// Init Shortcodes
Shortcodes::getInstance();
// Get Images Instance
Images::getInstance();
// Get Themes Instance
Themes::getInstance();
// Get Plugins Instance
Plugins::getInstance();
// Get Site Instance
Site::getInstance();
// Flush (send) the output buffer and turn off output buffering
ob_end_flush();
}
/**
* Set error handler
*
* @access private
*/
private static function setErrorHandler() : void
{
// Display Errors
if (Registry::get('settings.errors.display')) {
define('DEVELOPMENT', true);
error_reporting(-1);
} else {
define('DEVELOPMENT', false);
error_reporting(0);
}
// Create directory for logs
!Filesystem::has(LOGS_PATH) and Filesystem::createDir(LOGS_PATH);
// Set Error handler
set_error_handler('Flextype\Component\ErrorHandler\ErrorHandler::error');
register_shutdown_function('Flextype\Component\ErrorHandler\ErrorHandler::fatal');
set_exception_handler('Flextype\Component\ErrorHandler\ErrorHandler::exception');
}
/**
* Set config
*
* @access private
*/
private static function setConfig() : void
{
// Set empty settings array
Registry::set('settings', []);
// Set settings files path
$default_settings_file_path = PATH['config']['default'] . '/settings.yaml';
$site_settings_file_path = PATH['config']['site'] . '/settings.yaml';
// Set settings if Flextype settings and Site settings config files exist
if (Filesystem::has($default_settings_file_path) && Filesystem::has($site_settings_file_path)) {
if (($content = Filesystem::read($default_settings_file_path)) === false) {
throw new \RuntimeException('Load file: ' . $default_settings_file_path . ' - failed!');
} else {
$default_settings = YamlParser::decode($content);
}
if (($content = Filesystem::read($site_settings_file_path)) === false) {
throw new \RuntimeException('Load file: ' . $site_settings_file_path . ' - failed!');
} else {
$site_settings = YamlParser::decode($content);
}
// Merge settings
$settings = array_replace_recursive($default_settings, $site_settings);
// Set settings
Registry::set('settings', $settings);
} else {
throw new \RuntimeException("Flextype settings and Site settings config files does not exist.");
}
}
/**
* Get the Flextype instance.
*
* @access public
* @return object
*/
public static function getInstance()
{
if (is_null(Flextype::$instance)) {
Flextype::$instance = new self;
}
return Flextype::$instance;
}
// Set settings
Registry::set('settings', $settings);
} else {
throw new \RuntimeException("Flextype settings and Site settings config files does not exist.");
}
// Set internal encoding
function_exists('mb_language') and mb_language('uni');
function_exists('mb_regex_encoding') and mb_regex_encoding(Registry::get('settings.charset'));
function_exists('mb_internal_encoding') and mb_internal_encoding(Registry::get('settings.charset'));
/**
* Set error handler
*
* @access private
*/
// Display Errors
if (Registry::get('settings.errors.display')) {
//define('DEVELOPMENT', true);
error_reporting(-1);
} else {
//define('DEVELOPMENT', false);
error_reporting(0);
}
// Create directory for logs
!Filesystem::has(LOGS_PATH) and Filesystem::createDir(LOGS_PATH);
// Set Error handler
//set_error_handler('Flextype\Component\ErrorHandler\ErrorHandler::error');
//register_shutdown_function('Flextype\Component\ErrorHandler\ErrorHandler::fatal');
//set_exception_handler('Flextype\Component\ErrorHandler\ErrorHandler::exception');
// Set default timezone
date_default_timezone_set(Registry::get('settings.timezone'));
// Start the session
Session::start();
// Get Cache Instance
Cache::getInstance();
// Get Themes Instance
Themes::getInstance();
// Create and configure Slim app
$config = ['settings' => [
'displayErrorDetails' => true,
'addContentLengthHeader' => false,
]];
$app = new \Slim\App($config);
// DIC configuration
$flextype = $app->getContainer();
$flextype['images'] = function($container) {
// Set source filesystem
$source = new \League\Flysystem\Filesystem(
new \League\Flysystem\Adapter\Local(PATH['entries'])
);
// Set cache filesystem
$cache = new \League\Flysystem\Filesystem(
new \League\Flysystem\Adapter\Local(PATH['cache'] . '/glide')
);
// Set watermarks filesystem
$watermarks = new \League\Flysystem\Filesystem(
new \League\Flysystem\Adapter\Local(PATH['site'] . '/watermarks')
);
// Set image manager
$imageManager = new \Intervention\Image\ImageManager([
'driver' => 'gd',
]);
// Set manipulators
$manipulators = [
new \League\Glide\Manipulators\Orientation(),
new \League\Glide\Manipulators\Crop(),
new \League\Glide\Manipulators\Size(2000*2000),
new \League\Glide\Manipulators\Brightness(),
new \League\Glide\Manipulators\Contrast(),
new \League\Glide\Manipulators\Gamma(),
new \League\Glide\Manipulators\Sharpen(),
new \League\Glide\Manipulators\Filter(),
new \League\Glide\Manipulators\Blur(),
new \League\Glide\Manipulators\Pixelate(),
new \League\Glide\Manipulators\Watermark($watermarks),
new \League\Glide\Manipulators\Background(),
new \League\Glide\Manipulators\Border(),
new \League\Glide\Manipulators\Encode(),
];
// Set API
$api = new \League\Glide\Api\Api($imageManager, $manipulators);
// Setup Glide server
$server = new \League\Glide\Server(
$source,
$cache,
$api
);
return new \League\Glide\Server(
$source,
$cache,
$api
);
};
$flextype['shortcodes'] = function($container) {
return new ShortcodeFacade();
};
// Get Default Shortocdes List
$shortcodes_list = Filesystem::listContents(ROOT_DIR . '/flextype/shortcodes');
// Include default shortcodes
foreach ($shortcodes_list as $shortcode) {
include_once $shortcode['path'];
}
$flextype['entries'] = function($container) {
return new Entries($container);
};
// Register Twig View helper
$flextype['view'] = function ($container) {
$view = new \Slim\Views\Twig(PATH['site'], [
'cache' => false
]);
// Instantiate and add Slim specific extension
$router = $container->get('router');
$uri = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER));
$view->addExtension(new \Slim\Views\TwigExtension($router, $uri));
$view->addExtension(new EntriesTwigExtension());
$view->addExtension(new RegistryTwigExtension());
return $view;
};
// Get Plugins Instance
$plugins = new Plugins($flextype, $app);
// Run app
$app->run();

View File

@@ -1,187 +0,0 @@
<?php
/**
* @package Flextype
*
* @author Sergey Romanenko <hello@romanenko.digital>
* @link http://romanenko.digital
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flextype;
use Flextype\Component\Http\Http;
use Flextype\Component\Html\Html;
class Images
{
/**
* An instance of the Images class
*
* @var object
*/
private static $instance = null;
/**
* Images Server
*
* @var
*/
protected static $server;
/**
* Private clone method to enforce singleton behavior.
*
* @access private
*/
private function __clone()
{
}
/**
* Private wakeup method to enforce singleton behavior.
*
* @access private
*/
private function __wakeup()
{
}
/**
* Private construct method to enforce singleton behavior.
*
* @access private
*/
private function __construct()
{
Images::init();
}
/**
* Init Images
*
* @access private
* @return void
*/
private static function init() : void
{
// Set source filesystem
$source = new \League\Flysystem\Filesystem(
new \League\Flysystem\Adapter\Local(PATH['entries'])
);
// Set cache filesystem
$cache = new \League\Flysystem\Filesystem(
new \League\Flysystem\Adapter\Local(PATH['cache'] . '/glide')
);
// Set watermarks filesystem
$watermarks = new \League\Flysystem\Filesystem(
new \League\Flysystem\Adapter\Local(PATH['site'] . '/watermarks')
);
// Set image manager
$imageManager = new \Intervention\Image\ImageManager([
'driver' => 'gd',
]);
// Set manipulators
$manipulators = [
new \League\Glide\Manipulators\Orientation(),
new \League\Glide\Manipulators\Crop(),
new \League\Glide\Manipulators\Size(2000*2000),
new \League\Glide\Manipulators\Brightness(),
new \League\Glide\Manipulators\Contrast(),
new \League\Glide\Manipulators\Gamma(),
new \League\Glide\Manipulators\Sharpen(),
new \League\Glide\Manipulators\Filter(),
new \League\Glide\Manipulators\Blur(),
new \League\Glide\Manipulators\Pixelate(),
new \League\Glide\Manipulators\Watermark($watermarks),
new \League\Glide\Manipulators\Background(),
new \League\Glide\Manipulators\Border(),
new \League\Glide\Manipulators\Encode(),
];
// Set API
$api = new \League\Glide\Api\Api($imageManager, $manipulators);
// Setup Glide server
$server = new \League\Glide\Server(
$source,
$cache,
$api
);
Images::$server = $server;
}
/**
* Fetch image url
*
* Images::fetchImageUrl('page-name/image.jpg', [w => '200']);
* http://glide.thephpleague.com/1.0/api/quick-reference/
*
* @access public
* @param string $path Image path
* @param array $params Image params
* @return string
*/
public static function fetchImageUrl(string $path, array $params) : string
{
if (file_exists(PATH['entries'] . '/' . $path)) {
return Http::getBaseUrl() . '/site/cache/glide/' . Images::$server->makeImage($path, $params);
} else {
return "File {$path} does not exist.";
}
}
/**
* Fetch image
*
* Images::fetchImage('page-name/image.jpg', [w => '200']);
* http://glide.thephpleague.com/1.0/api/quick-reference/
*
* @access public
* @param string $path Image path
* @param array $params Image params
* @param array $attributes Image html attributes
* @return string
*/
public static function fetchImage(string $path, array $params, array $attributes = []) : string
{
if (file_exists(PATH['entries'] . '/' . $path)) {
return '<img ' . Html::attributes($attributes) . ' src="' . Images::getImageUrl($path, $params) . '">';
} else {
return "File {$path} does not exist.";
}
}
/**
* Returns server variable
*
* @access public
* @return object
*/
public static function server()
{
return Images::$server;
}
/**
* Get the Image instance.
*
* @access public
* @return object
*/
public static function getInstance()
{
if (is_null(Images::$instance)) {
Images::$instance = new self;
}
return Images::$instance;
}
}

View File

@@ -192,32 +192,15 @@ class Plugins
'zu' => ['name' => 'Zulu', 'nativeName' => 'isiZulu']
];
/**
* Private clone method to enforce singleton behavior.
*
* @access private
*/
private function __clone()
{
}
/**
* Private wakeup method to enforce singleton behavior.
*
* @access private
*/
private function __wakeup()
{
}
/**
* Private construct method to enforce singleton behavior.
*
* @access private
*/
private function __construct()
public function __construct($flextype, $app)
{
Plugins::init();
Plugins::init($flextype, $app);
}
/**
@@ -226,7 +209,7 @@ class Plugins
* @access private
* @return void
*/
private static function init() : void
private static function init($flextype, $app) : void
{
// Set empty plugins item
Registry::set('plugins', []);
@@ -281,7 +264,7 @@ class Plugins
Plugins::createPluginsDictionary($plugins_list);
Plugins::includeEnabledPlugins();
Plugins::includeEnabledPlugins($flextype, $app);
Event::dispatch('onPluginsInitialized');
}
@@ -347,7 +330,7 @@ class Plugins
* @access protected
* @return void
*/
protected static function includeEnabledPlugins() : void
protected static function includeEnabledPlugins($flextype, $app) : void
{
if (is_array(Registry::get('plugins')) && count(Registry::get('plugins')) > 0) {
foreach (Registry::get('plugins') as $plugin_name => $plugin) {
@@ -368,19 +351,4 @@ class Plugins
{
return Plugins::$locales;
}
/**
* Get the Plugins instance.
*
* @access public
* @return object
*/
public static function getInstance()
{
if (is_null(Plugins::$instance)) {
Plugins::$instance = new self;
}
return Plugins::$instance;
}
}

View File

@@ -1,140 +0,0 @@
<?php
/**
* @package Flextype
*
* @author Sergey Romanenko <hello@romanenko.digital>
* @link http://romanenko.digital
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flextype;
use Flextype\Component\Event\Event;
use Flextype\Component\Filesystem\Filesystem;
use Thunder\Shortcode\ShortcodeFacade;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
class Shortcodes {
/**
* An instance of the Shortcodes class
*
* @var object
* @access private
*/
private static $instance = null;
/**
* Shortcode object
*
* @var object
* @access private
*/
private static $shortcode = null;
/**
* Private clone method to enforce singleton behavior.
*
* @access private
*/
private function __clone()
{
}
/**
* Private wakeup method to enforce singleton behavior.
*
* @access private
*/
private function __wakeup()
{
}
/**
* Private construct method to enforce singleton behavior.
*
* @access private
*/
private function __construct()
{
Shortcodes::init();
}
/**
* Init Shortcodes
*
* @access private
* @return void
*/
private static function init() : void
{
// Create Shortcode Parser object
Shortcodes::$shortcode = new ShortcodeFacade();
// Add Default Shorcodes!
Shortcodes::addDefaultShortcodes();
// Event: Shortcodes initialized
Event::dispatch('onShortcodesInitialized');
}
/**
* Returns $shortcode object
*
* @access public
* @return object
*/
public static function shortcode() : ShortcodeFacade
{
return Shortcodes::$shortcode;
}
/**
* Process shortcodes
*
* $content = Shortcodes::proccess($content);
*
* @access public
* @param string $content Content to parse
* @return string
*/
public static function process(string $content) : string
{
return Shortcodes::shortcode()->process($content);
}
/**
* Add default shortcodes!
*
* @access private
* @return void
*/
private static function addDefaultShortcodes() : void
{
// Get Default Shortocdes List
$shortcodes_list = Filesystem::listContents(ROOT_DIR . '/flextype/shortcodes');
// Include default shortcodes
foreach ($shortcodes_list as $shortcode) {
include_once $shortcode['path'];
}
}
/**
* Get the Shortcodes instance.
*
* @access public
* @return object
*/
public static function getInstance()
{
if (is_null(Shortcodes::$instance)) {
Shortcodes::$instance = new self;
}
return Shortcodes::$instance;
}
}

View File

@@ -1,217 +0,0 @@
<?php
/**
* @package Flextype
*
* @author Sergey Romanenko <hello@romanenko.digital>
* @link http://romanenko.digital
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flextype;
use Flextype\Component\Arr\Arr;
use Flextype\Component\Http\Http;
use Flextype\Component\Event\Event;
use Flextype\Component\Registry\Registry;
class Site
{
/**
* An instance of the Site class
*
* @var object
* @access private
*/
private static $instance = null;
/**
* Current site entry data array
*
* @var array
* @access private
*/
private static $entry = [];
/**
* Private clone method to enforce singleton behavior.
*
* @access private
*/
private function __clone()
{
}
/**
* Private wakeup method to enforce singleton behavior.
*
* @access private
*/
private function __wakeup()
{
}
/**
* Private construct method to enforce singleton behavior.
*
* @access private
*/
private function __construct()
{
Site::init();
}
/**
* Init Entry
*
* @access private
* @return void
*/
private static function init() : void
{
Site::processCurrentPage();
}
/**
* Process Current Page
*
* @access private
* @return void
*/
private static function processCurrentPage() : void
{
// Event: The entry is not processed and not sent to the display.
Event::dispatch('onCurrentEntryBeforeProcessed');
// Get uri
$uri = Http::getUriString();
// If uri is empty then it is main page else use entry uri
if ($uri === '') {
$entry_uri = Registry::get('settings.entries.main');
} else {
$entry_uri = $uri;
}
// Get entry body
$entry_body = Entries::fetch($entry_uri);
// If entry body is not false
if ($entry_body) {
// Get 404 page if entry is not published
if (isset($entry_body['visibility']) && ($entry_body['visibility'] === 'draft' || $entry_body['visibility'] === 'hidden')) {
$entry = Site::getError404Page();
} else {
$entry = $entry_body;
}
} else {
$entry = Site::getError404Page();
}
// Set current requested entry data to global $entry array
Site::$entry = $entry;
// Event: The entry has been fully processed and not sent to the display.
Event::dispatch('onCurrentEntryBeforeDisplayed');
// Display entry for current requested url
Site::displayCurrentPage();
// Event: The entry has been fully processed and sent to the display.
Event::dispatch('onCurrentEntryAfterProcessed');
}
/**
* Get Error404 entry
*
* @return array
*/
private static function getError404Page() : array
{
Http::setResponseStatus(404);
$entry = [];
$entry['title'] = Registry::get('settings.entries.error404.title');
$entry['description'] = Registry::get('settings.entries.error404.description');
$entry['content'] = Registry::get('settings.entries.error404.content');
$entry['template'] = Registry::get('settings.entries.error404.template');
return $entry;
}
/**
* Get current entry
*
* $entry = Site::getCurrentEntry();
*
* @access public
* @return array
*/
public static function getCurrentEntry() : array
{
return Site::$entry;
}
/**
* Update current entry
*
* Site::updateCurrentEntry(['title' => "New Title"]);
*
* @access public
* @param array $data Data
* @return void
*/
public static function updateCurrentEntry(array $data) : void
{
Site::$entry = $data;
}
/**
* Update current entry field
*
* Site::updateCurrentEntryField('title', "New Title");
*
* @access public
* @param string $path Array path
* @param mixed $value Value to set
* @return void
*/
public static function updateCurrentEntryField(string $path, $value) : void
{
Arr::set(Site::$entry, $path, $value);
}
/**
* Display Current Page
*
* @access private
* @return void
*/
private static function displayCurrentPage() : void
{
Http::setRequestHeaders('Content-Type: text/html; charset=' . Registry::get('settings.charset'));
Themes::view(empty(Site::$entry['template']) ? 'templates/default' : 'templates/' . Site::$entry['template'])
->assign('entry', Site::$entry, true)
->display();
}
/**
* Get the Content instance.
*
* @access public
* @return object
*/
public static function getInstance()
{
if (is_null(Site::$instance)) {
Site::$instance = new self;
}
return Site::$instance;
}
}

View File

@@ -61,7 +61,7 @@ entries:
#
# - display: Display errors or not.
errors:
display: false
display: true
# Cache
#
@@ -95,7 +95,7 @@ errors:
#
# - sqlite3.table SQLite3 Table
cache:
enabled: true
enabled: false
prefix: flextype
driver: auto
lifetime: 604800

View File

@@ -12,13 +12,15 @@
namespace Flextype;
use Flextype\Component\Http\Http;
use Thunder\Shortcode\ShortcodeFacade;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Images
// Shortcode: [images path="home/image.jpg"]
// Result: Display image
Shortcodes::shortcode()->addHandler('images', function(ShortcodeInterface $s) {
$flextype['shortcodes']->addHandler('images', function(ShortcodeInterface $s) use ($flextype, $app) {
$params = [];
$attributes = [];
@@ -57,5 +59,5 @@ Shortcodes::shortcode()->addHandler('images', function(ShortcodeInterface $s) {
($s->getParameter('id')) and $attributes['id'] = $s->getParameter('id');
($s->getParameter('alt')) and $attributes['alt'] = $s->getParameter('alt');
return Images::fetchImage($s->getParameter('path'), $params, $attributes);
return Http::getBaseUrl() . '/site/cache/glide/' . $flextype['images']->makeImage($s->getParameter('path'), $params);
});

View File

@@ -12,13 +12,15 @@
namespace Flextype;
use Flextype\Component\Http\Http;
use Thunder\Shortcode\ShortcodeFacade;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Images
// Shortcode: [images_url path="home/image.jpg"]
// Result: Display image url
Shortcodes::shortcode()->addHandler('images_url', function(ShortcodeInterface $s) {
$flextype['shortcodes']->addHandler('images_url', function(ShortcodeInterface $s) {
$params = [];
// API
@@ -50,5 +52,5 @@ Shortcodes::shortcode()->addHandler('images_url', function(ShortcodeInterface $s
($s->getParameter('q')) and $params['q'] = $s->getParameter('q');
($s->getParameter('fm')) and $params['fm'] = $s->getParameter('fm');
return Images::fetchImageUrl($s->getParameter('path'), $params);
return Http::getBaseUrl() . '/site/cache/glide/' . $flextype['images']->makeImage($s->getParameter('path'), $params);
});

View File

@@ -17,6 +17,6 @@ use Thunder\Shortcode\ShortcodeFacade;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Shortcode: [site_url]
Shortcodes::shortcode()->addHandler('site_url', function() {
$flextype['shortcodes']->addHandler('site_url', function() {
return Http::getBaseUrl();
});

View File

@@ -17,6 +17,6 @@ use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Snippets
// Shortcode: [snippets fetch=snippet-name]
Shortcodes::shortcode()->addHandler('snippets', function(ShortcodeInterface $s) {
$flextype['shortcodes']->addHandler('snippets', function(ShortcodeInterface $s) {
return Snippets::get($s->getParameter('fetch'));
});

View File

@@ -0,0 +1,30 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Twig-View
* @copyright Copyright (c) 2011-2015 Josh Lockhart
* @license https://github.com/slimphp/Twig-View/blob/master/LICENSE.md (MIT License)
*/
namespace Flextype;
class EntriesTwigExtension extends \Twig_Extension
{
public function getFunctions()
{
return [
new \Twig_SimpleFunction('entries_fetch', array($this, 'fetch')),
new \Twig_SimpleFunction('entries_fetch_all', array($this, 'fetchAll')),
];
}
public function fetch(string $entry)
{
return Entries::fetch($entry);
}
public function fetchAll(string $entry, string $order_by = 'date', string $order_type = 'DESC', int $offset = null, int $length = null) : array
{
return Entries::fetchAll($entry, $order_by, $order_type, $offset, $length);
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Twig-View
* @copyright Copyright (c) 2011-2015 Josh Lockhart
* @license https://github.com/slimphp/Twig-View/blob/master/LICENSE.md (MIT License)
*/
namespace Flextype;
class RegistryTwigExtension extends \Twig_Extension
{
public function getFunctions()
{
return [
new \Twig_SimpleFunction('registry_get', array($this, 'get')),
new \Twig_SimpleFunction('registry_exists', array($this, 'exists')),
];
}
public function get($name)
{
return Registry::get($name);
}
public function exists(string $name) : bool
{
return Registry::exists($name);
}
}

View File

@@ -44,4 +44,4 @@ version_compare($ver = PHP_VERSION, $req = FLEXTYPE_MINIMUM_PHP, '<') and exit(s
$loader = require_once $autoload;
// Get Flextype Instance
$flextype = Flextype::getInstance();
include 'flextype/Flextype.php';

View File

@@ -1,15 +1,22 @@
title: Home
template: home
fieldset: default
visibility: visible
content: |
<h1 style="text-align: center;">
Welcome!
</h1>
<p style="text-align: center;" class="lead">
Welcome to your new Flextype powered website.
Welcome to your new Flextype powered website. [site_url]
[images path="about/lilia.jpg"]
<br>
Flextype is succesfully installed, you can start editing the content and customising your site in <a href="./admin">Admin panel</a>.
</p>
<br>
<p style="text-align: center;">Latest blog posts:</p>
template: home
fieldset: default
visibility: visible
date: 'February 20 2019 11:06:46'
description: ''
menu_item_title: ''
menu_item_url: ''
menu_item_target: blank
menu_item_order: ''

View File

@@ -0,0 +1,24 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Twig-View
* @copyright Copyright (c) 2011-2015 Josh Lockhart
* @license https://github.com/slimphp/Twig-View/blob/master/LICENSE.md (MIT License)
*/
namespace Flextype;
class ATwigExtension extends \Twig_Extension
{
public function getFunctions()
{
return [
new \Twig_SimpleFunction('a', array($this, 'a')),
];
}
public function a()
{
return 'aaa';
}
}

25
site/plugins/a/a.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace Flextype;
use Slim\Http\Request;
use Slim\Http\Response;
use Flextype\Component\Arr\Arr;
use Flextype\Component\Event\Event;
use Flextype\Component\Registry\Registry;
include 'ATwigExtension.php';
// Define app routes
//Flextype::router()->get('/test', function (Request $request, Response $response, array $args) {
// return 'test';
//});
//Flextype::container()['view']->addExtension(new ATwigExtension());
echo '@@@';
//Flextype::flextype()->version();

10
site/plugins/a/a.yaml Executable file
View File

@@ -0,0 +1,10 @@
name: Site
version: 0.0.0
description: "Site plugin for Flextype"
author:
name: Sergey Romanenko
email: awilum@yandex.ru
url: http://flextype.org
homepage: https://github.com/flextype-plugins/admin
bugs: https://github.com/flextype-plugins/admin/issues
license: MIT

View File

@@ -0,0 +1 @@
enabled: true

4613
site/plugins/admin/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -42,9 +42,9 @@ Themes::view('admin/views/partials/navbar')
->assign('entry', $entry)
->display();
Themes::view('admin/views/partials/content-start')->display();
EntriesManager::displayEntryForm($fieldset, $entry);
Themes::view('admin/views/partials/content-end')->display();
Themes::view('admin/views/partials/footer')->display();
?>
<?= FieldsetsManager::fetchForm($fieldset, $entry) ?>
<?php Themes::view('admin/views/partials/content-end')->display() ?>
<?php Themes::view('admin/views/partials/footer')->display() ?>

View File

@@ -0,0 +1 @@
enabled: true

View File

@@ -0,0 +1,68 @@
<?php
namespace Flextype;
use Slim\Http\Request;
use Slim\Http\Response;
use Flextype\Component\Arr\Arr;
use Flextype\Component\Event\Event;
use Flextype\Component\Registry\Registry;
// Define app routes
$app->get('{uri:.+}', function (Request $request, Response $response, array $args) {
// Get uri
$uri = $args['uri'];
// If uri is empty then it is main page else use entry uri
if ($uri === '/') {
$entry_uri = Registry::get('settings.entries.main');
} else {
$entry_uri = ltrim($uri, '/');
}
// Get entry body
$entry_body = $this->get('entries')->fetch($entry_uri);
// If entry body is not false
if ($entry_body) {
// Get 404 page if entry is not published
if (isset($entry_body['visibility']) && ($entry_body['visibility'] === 'draft' || $entry_body['visibility'] === 'hidden')) {
//Http::setResponseStatus(404);
$entry['title'] = Registry::get('settings.entries.error404.title');
$entry['description'] = Registry::get('settings.entries.error404.description');
$entry['content'] = Registry::get('settings.entries.error404.content');
$entry['template'] = Registry::get('settings.entries.error404.template');
//$response->withStatus(404);
} else {
$entry = $entry_body;
}
} else {
//Http::setResponseStatus(404);
//$response->withStatus(404);
$entry['title'] = Registry::get('settings.entries.error404.title');
$entry['description'] = Registry::get('settings.entries.error404.description');
$entry['content'] = Registry::get('settings.entries.error404.content');
$entry['template'] = Registry::get('settings.entries.error404.template');
}
// Set current requested entry data to global $entry array
$entry = $entry;
$path = 'themes/' . Registry::get('settings.theme') . '/' . (empty($entry['template']) ? 'templates/default' : 'templates/' . $entry['template']) . '.twig';
return $this->view->render($response,
$path, [
'entry' => $entry,
'registry' => Registry::registry()
]);
});

10
site/plugins/site/site.yaml Executable file
View File

@@ -0,0 +1,10 @@
name: Site
version: 0.0.0
description: "Site plugin for Flextype"
author:
name: Sergey Romanenko
email: awilum@yandex.ru
url: http://flextype.org
homepage: https://github.com/flextype-plugins/admin
bugs: https://github.com/flextype-plugins/admin/issues
license: MIT

View File

@@ -0,0 +1,3 @@
{{ test }}
{{ entries_fetch('home')['title'] }}
@ {{ current_path() }} @

View File

@@ -0,0 +1,10 @@
{% extends "partials/base.twig" %}
{% block title %}{{ entry.title }}{% endblock %}
{% block content %}
<h1>{{ entry.title }}</h1>
<p class="important">
{{ entry.content }}
</p>
{% endblock %}

View File

@@ -0,0 +1,8 @@
{% extends "themes/default/templates/partials/base.twig" %}
{% block title %}{{ entry.title }}{% endblock %}
{% block content %}
<h1>{{ entry.title }}</h1>
{{ entry.content|raw }}
{% endblock %}

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
{% block head %}
<meta charset="utf-8" />
<title>{% if entry.title %}{{ entry.title|e('html') }} | {% endif %}{{ registry.settings.title|e('html') }}</title>
{% endblock %}
</head>
<body>
<div id="content">{% block content %}{% endblock %}</div>
<div id="footer">
{% block footer %}
&copy; Copyright 2011 by <a href="http://domain.invalid/">you</a>.
{% endblock %}
</div>
</body>
</html>