From 0009e1d47486ba161f3bf681b8fad211cac46d6d Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 16 Jun 2019 22:42:28 +0300 Subject: [PATCH 01/28] Flextype Site Plugin: fixes and refactoring #154 --- site/plugins/site/bootstrap.php | 8 ++------ site/plugins/site/dependencies.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 site/plugins/site/dependencies.php diff --git a/site/plugins/site/bootstrap.php b/site/plugins/site/bootstrap.php index 7025f462..a59a1990 100644 --- a/site/plugins/site/bootstrap.php +++ b/site/plugins/site/bootstrap.php @@ -11,9 +11,5 @@ $loader = require_once $autoload; // Include routes include_once 'routes/web.php'; -/** - * Add site controller to Flextype container - */ -$flextype['SiteController'] = function($container) { - return new SiteController($container); -}; +// Include dependencies +include_once 'dependencies.php'; diff --git a/site/plugins/site/dependencies.php b/site/plugins/site/dependencies.php new file mode 100644 index 00000000..887ccc6a --- /dev/null +++ b/site/plugins/site/dependencies.php @@ -0,0 +1,10 @@ + Date: Sun, 16 Jun 2019 22:58:55 +0300 Subject: [PATCH 02/28] Flextype Site Plugin: fixes and refactoring #154 --- .../site/app/Controllers/SiteController.php | 10 ++++++ site/plugins/site/bootstrap.php | 36 +++++++++++++++---- site/plugins/site/dependencies.php | 10 ++++++ site/plugins/site/routes/web.php | 10 ++++++ 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/site/plugins/site/app/Controllers/SiteController.php b/site/plugins/site/app/Controllers/SiteController.php index 159ac121..0805495d 100644 --- a/site/plugins/site/app/Controllers/SiteController.php +++ b/site/plugins/site/app/Controllers/SiteController.php @@ -1,5 +1,15 @@ + * @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; diff --git a/site/plugins/site/bootstrap.php b/site/plugins/site/bootstrap.php index a59a1990..1c744dd1 100644 --- a/site/plugins/site/bootstrap.php +++ b/site/plugins/site/bootstrap.php @@ -1,15 +1,39 @@ + * @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; -// Ensure vendor libraries exist -!is_file($autoload = __DIR__ . '/vendor/autoload.php') and exit("Please run: composer install"); +/** + * Ensure vendor libraries exist + */ +!is_file($site_autoload = __DIR__ . '/vendor/autoload.php') and exit("Please run: composer install"); -// Register The Auto Loader -$loader = require_once $autoload; +/** + * Register The Auto Loader + * + * Composer provides a convenient, automatically generated class loader for + * our application. We just need to utilize it! We'll simply require it + * into the script here so that we don't have to worry about manual + * loading any of our classes later on. It feels nice to relax. + * Register The Auto Loader + */ +$site_loader = require_once $site_autoload; -// Include routes +/** + * Include web routes + */ include_once 'routes/web.php'; -// Include dependencies +/** + * Include dependencies + */ include_once 'dependencies.php'; diff --git a/site/plugins/site/dependencies.php b/site/plugins/site/dependencies.php index 887ccc6a..4579874f 100644 --- a/site/plugins/site/dependencies.php +++ b/site/plugins/site/dependencies.php @@ -1,5 +1,15 @@ + * @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; /** diff --git a/site/plugins/site/routes/web.php b/site/plugins/site/routes/web.php index 094152c0..ce717f23 100644 --- a/site/plugins/site/routes/web.php +++ b/site/plugins/site/routes/web.php @@ -1,5 +1,15 @@ + * @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; $app->get('{uri:.+}', 'SiteController:index')->setName('site.index'); From a2169c49fdad9434683f53a259393e6b39d41c68 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 16 Jun 2019 23:04:59 +0300 Subject: [PATCH 03/28] Flextype Admin Plugin: fixes and refactoring #154 --- site/plugins/admin/bootstrap.php | 92 ++++++++--------------------- site/plugins/admin/dependencies.php | 69 ++++++++++++++++++++++ site/plugins/admin/settings.json | 3 +- 3 files changed, 97 insertions(+), 67 deletions(-) create mode 100644 site/plugins/admin/dependencies.php diff --git a/site/plugins/admin/bootstrap.php b/site/plugins/admin/bootstrap.php index d985f021..077be02b 100755 --- a/site/plugins/admin/bootstrap.php +++ b/site/plugins/admin/bootstrap.php @@ -1,7 +1,5 @@ getPath()); +/** + * Set base admin route + */ +$admin_route = $flextype->registry->get('plugins.admin.route'); -// Set base admin route -$admin_route = 'admin'; +/** + * Ensure vendor libraries exist + */ +!is_file($admin_autoload = __DIR__ . '/vendor/autoload.php') and exit("Please run: composer install"); -// Ensure vendor libraries exist -!is_file($autoload = __DIR__ . '/vendor/autoload.php') and exit("Please run: composer install"); +/** + * Register The Auto Loader + * + * Composer provides a convenient, automatically generated class loader for + * our application. We just need to utilize it! We'll simply require it + * into the script here so that we don't have to worry about manual + * loading any of our classes later on. It feels nice to relax. + * Register The Auto Loader + */ +$admin_loader = require_once $admin_autoload; -// Register The Auto Loader -$loader = require_once $autoload; - -// Include routes +/** + * Include web routes + */ include_once 'routes/web.php'; -// Set Default Admin locale -I18n::$locale = $flextype->registry->get('settings.locale'); - -// Add Admin Navigation -$flextype->registry->set('admin_navigation.content.entries', ['title' => '' . __('admin_entries'), 'link' => $flextype->router->pathFor('admin.entries.index'), 'attributes' => ['class' => 'nav-link']]); -$flextype->registry->set('admin_navigation.extends.fieldsets', ['title' => '' . __('admin_fieldsets'), 'link' => $flextype->router->pathFor('admin.fieldsets.index'), 'attributes' => ['class' => 'nav-link']]); -$flextype->registry->set('admin_navigation.extends.templates', ['title' => '' . __('admin_templates'), 'link' => $flextype->router->pathFor('admin.templates.index'), 'attributes' => ['class' => 'nav-link']]); -$flextype->registry->set('admin_navigation.extends.snippets', ['title' => '' . __('admin_snippets'), 'link' => $flextype->router->pathFor('admin.snippets.index'), 'attributes' => ['class' => 'nav-link']]); -$flextype->registry->set('admin_navigation.extends.plugins', ['title' => '' . __('admin_plugins'), 'link' => $flextype->router->pathFor('admin.plugins.index'), 'attributes' => ['class' => 'nav-link']]); -$flextype->registry->set('admin_navigation.settings.settings', ['title' => '' . __('admin_settings'), 'link' => $flextype->router->pathFor('admin.settings.index'), 'attributes' => ['class' => 'nav-link']]); -$flextype->registry->set('admin_navigation.settings.infomation', ['title' => '' . __('admin_information'), 'link' => $flextype->router->pathFor('admin.information.index'), 'attributes' => ['class' => 'nav-link']]); -$flextype->registry->set('admin_navigation.help.docs', ['title' => '' . __('admin_documentation'), 'link' => 'http://flextype.org/en/documentation', 'attributes' => ['class' => 'nav-link', 'target' => '_blank']]); - -// Add Global Vars Admin Twig Extension -$flextype->view->addExtension(new GlobalVarsAdminTwigExtension($flextype)); - -$flextype['DashboardController'] = function ($container) { - return new DashboardController($container); -}; - -$flextype['SettingsController'] = function ($container) { - return new SettingsController($container); -}; - -$flextype['InformationController'] = function ($container) { - return new InformationController($container); -}; - -$flextype['PluginsController'] = function ($container) { - return new PluginsController($container); -}; - -$flextype['EntriesController'] = function ($container) { - return new EntriesController($container); -}; - -$flextype['FieldsetsController'] = function ($container) { - return new FieldsetsController($container); -}; - -$flextype['SnippetsController'] = function ($container) { - return new SnippetsController($container); -}; - -$flextype['TemplatesController'] = function ($container) { - return new TemplatesController($container); -}; - -$flextype['UsersController'] = function ($container) { - return new UsersController($container); -}; +/** + * Include dependencies + */ +include_once 'dependencies.php'; diff --git a/site/plugins/admin/dependencies.php b/site/plugins/admin/dependencies.php new file mode 100644 index 00000000..b432a577 --- /dev/null +++ b/site/plugins/admin/dependencies.php @@ -0,0 +1,69 @@ + + * @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\I18n\I18n; +use function Flextype\Component\I18n\__; + +// Set Default Admin locale +I18n::$locale = $flextype->registry->get('settings.locale'); + +// Add Admin Navigation +$flextype->registry->set('admin_navigation.content.entries', ['title' => '' . __('admin_entries'), 'link' => $flextype->router->pathFor('admin.entries.index'), 'attributes' => ['class' => 'nav-link']]); +$flextype->registry->set('admin_navigation.extends.fieldsets', ['title' => '' . __('admin_fieldsets'), 'link' => $flextype->router->pathFor('admin.fieldsets.index'), 'attributes' => ['class' => 'nav-link']]); +$flextype->registry->set('admin_navigation.extends.templates', ['title' => '' . __('admin_templates'), 'link' => $flextype->router->pathFor('admin.templates.index'), 'attributes' => ['class' => 'nav-link']]); +$flextype->registry->set('admin_navigation.extends.snippets', ['title' => '' . __('admin_snippets'), 'link' => $flextype->router->pathFor('admin.snippets.index'), 'attributes' => ['class' => 'nav-link']]); +$flextype->registry->set('admin_navigation.extends.plugins', ['title' => '' . __('admin_plugins'), 'link' => $flextype->router->pathFor('admin.plugins.index'), 'attributes' => ['class' => 'nav-link']]); +$flextype->registry->set('admin_navigation.settings.settings', ['title' => '' . __('admin_settings'), 'link' => $flextype->router->pathFor('admin.settings.index'), 'attributes' => ['class' => 'nav-link']]); +$flextype->registry->set('admin_navigation.settings.infomation', ['title' => '' . __('admin_information'), 'link' => $flextype->router->pathFor('admin.information.index'), 'attributes' => ['class' => 'nav-link']]); +$flextype->registry->set('admin_navigation.help.docs', ['title' => '' . __('admin_documentation'), 'link' => 'http://flextype.org/en/documentation', 'attributes' => ['class' => 'nav-link', 'target' => '_blank']]); + +// Add Global Vars Admin Twig Extension +$flextype->view->addExtension(new GlobalVarsAdminTwigExtension($flextype)); + +$flextype['DashboardController'] = function ($container) { + return new DashboardController($container); +}; + +$flextype['SettingsController'] = function ($container) { + return new SettingsController($container); +}; + +$flextype['InformationController'] = function ($container) { + return new InformationController($container); +}; + +$flextype['PluginsController'] = function ($container) { + return new PluginsController($container); +}; + +$flextype['EntriesController'] = function ($container) { + return new EntriesController($container); +}; + +$flextype['FieldsetsController'] = function ($container) { + return new FieldsetsController($container); +}; + +$flextype['SnippetsController'] = function ($container) { + return new SnippetsController($container); +}; + +$flextype['TemplatesController'] = function ($container) { + return new TemplatesController($container); +}; + +$flextype['UsersController'] = function ($container) { + return new UsersController($container); +}; diff --git a/site/plugins/admin/settings.json b/site/plugins/admin/settings.json index 60e7e096..db7e2d83 100644 --- a/site/plugins/admin/settings.json +++ b/site/plugins/admin/settings.json @@ -1,3 +1,4 @@ { - "enabled": true + "enabled": true, + "route": "admin" } From 0f790653ba73a14fc9e696bb9077116d6e633a98 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 16 Jun 2019 23:13:04 +0300 Subject: [PATCH 04/28] CHANGELOG UPDATES --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0837ee..6dfa583e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [0.9.1] - 2019-06-XX +### Added +- Flextype Admin Panel: new setting `route` added to customize admin base route. + +### Changed +- Flextype Site: code refactoring +- Flextype Admin Panel: code refactoring + ## [0.9.0] - 2019-06-14 ### Added - Flextype Core: Slim Framework Integration! From cd1faa5066e855f81717f2cf72d3b505bdf405ef Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 16 Jun 2019 23:13:29 +0300 Subject: [PATCH 05/28] Flextype Core: fixes and refactoring #154 --- flextype/routes/web.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/flextype/routes/web.php b/flextype/routes/web.php index b8db77d9..112bd494 100644 --- a/flextype/routes/web.php +++ b/flextype/routes/web.php @@ -1,5 +1,15 @@ + * @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 Psr\Http\Message\ResponseInterface as Response; From 8e0f2803e631ecbf444fe35f23ff1e0fc1baaeaa Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 16 Jun 2019 23:29:57 +0300 Subject: [PATCH 06/28] Flextype Core: GlobalVarsTwigExtension - new global constant `PATH_FIELDSETS` added #154 --- flextype/twig/GlobalVarsTwigExtension.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flextype/twig/GlobalVarsTwigExtension.php b/flextype/twig/GlobalVarsTwigExtension.php index 9d7ba101..8c50b742 100644 --- a/flextype/twig/GlobalVarsTwigExtension.php +++ b/flextype/twig/GlobalVarsTwigExtension.php @@ -12,8 +12,6 @@ namespace Flextype; -use Flextype\Component\Session\Session; - class GlobalVarsTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface { /** @@ -37,6 +35,7 @@ class GlobalVarsTwigExtension extends \Twig_Extension implements \Twig_Extension 'PATH_THEMES' => PATH['themes'], 'PATH_ENTRIES' => PATH['entries'], 'PATH_SNIPPETS' => PATH['snippets'], + 'PATH_FIELDSETS' => PATH['fieldsets'], 'PATH_CONFIG_DEFAULT' => PATH['config']['default'], 'PATH_CONFIG_SITE' => PATH['config']['site'], 'PATH_CACHE' => PATH['cache'], From da2003f9f8004f090aadb30a4506f8931f5f4612 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 16 Jun 2019 23:30:44 +0300 Subject: [PATCH 07/28] CHANGELOG UPDATES --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dfa583e..eb9081c8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## [0.9.1] - 2019-06-XX ### Added - Flextype Admin Panel: new setting `route` added to customize admin base route. +- Flextype Core: GlobalVarsTwigExtension - new global constant `PATH_FIELDSETS` added. ### Changed - Flextype Site: code refactoring From 1fda6445497585bb0a04f7acab8c71a820dbd10d Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 17 Jun 2019 12:55:28 +0300 Subject: [PATCH 08/28] Flextype Core: Entries API #154 #162 #161 - method fetchALL() issue with fetching entries recursively. - remove unused Shortcodes code from method fetch() --- flextype/core/Entries.php | 57 +++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/flextype/core/Entries.php b/flextype/core/Entries.php index 6c0610b8..28546c78 100755 --- a/flextype/core/Entries.php +++ b/flextype/core/Entries.php @@ -44,17 +44,13 @@ class Entries $entry_file = $this->_file_location($id); if (Filesystem::has($entry_file)) { + + // Create unique entry cache_id $cache_id = md5('entry' . $entry_file . ((Filesystem::getTimestamp($entry_file) === false) ? '' : Filesystem::getTimestamp($entry_file))); // Try to get the entry from cache if ($this->flextype['cache']->contains($cache_id)) { if ($entry_decoded = $this->flextype['cache']->fetch($cache_id)) { - - // Apply Shortcodes for each entry fields - foreach ($entry_decoded as $key => $_entry_decoded) { - $entry_decoded[$key] = $_entry_decoded;//$this->flextype['shortcodes']->process($_entry_decoded); - } - return $entry_decoded; } else { return false; @@ -67,14 +63,10 @@ class Entries $entry_decoded['date'] = $entry_decoded['date'] ?? date($this->flextype['registry']->get('settings.date_format'), Filesystem::getTimestamp($entry_file)); $entry_decoded['slug'] = $entry_decoded['slug'] ?? ltrim(rtrim($id, '/'), '/'); - // Save to cache + // Save decoded entry content into the cache $this->flextype['cache']->save($cache_id, $entry_decoded); - // Apply Shortcodes for each entry fields - foreach ($entry_decoded as $key => $_entry_decoded) { - $entry_decoded[$key] = $_entry_decoded;//$this->flextype['shortcodes']->process($_entry_decoded); - } - + // Return decoded entry return $entry_decoded; } else { return false; @@ -97,23 +89,24 @@ class Entries * @param string $order_type Order type: DESC or ASC * @param int $offset Offset * @param int $length Length + * @param bool $recursive Whether to list recursively. * @return array The entries */ - public function fetchAll(string $id, string $order_by = 'date', string $order_type = 'DESC', int $offset = null, int $length = null) : array + public function fetchAll(string $id, string $order_by = 'date', string $order_type = 'DESC', int $offset = null, int $length = null, bool $recursive = false) : array { - // Entries array where founded entries will stored + // Set empty entries array where founded entries will stored $entries = []; - // Сache id + // Set empty cache id for the entries $cache_id = ''; - // Entries path + // Get entries path $entries_path = $this->_dir_location($id); // Get entries list - $entries_list = Filesystem::listContents($entries_path); + $entries_list = Filesystem::listContents($entries_path, $recursive); - // Create entries cached id + // Create unique entries cache_id foreach ($entries_list as $current_entry) { if (strpos($current_entry['path'], $id . '/entry.json') !== false) { // ignore ... @@ -124,6 +117,8 @@ class Entries } } + // If the entries exist at a specific cache_id, + // then we take them from the cache otherwise we look for them. if ($this->flextype['cache']->contains($cache_id)) { $entries = $this->flextype['cache']->fetch($cache_id); } else { @@ -133,24 +128,38 @@ class Entries if (strpos($current_entry['path'], $id . '/entry.json') !== false) { // ignore ... } else { + // We are checking... + // Whether the requested entry is a director and whether the file entry.json is in this directory. if ($current_entry['type'] == 'dir' && Filesystem::has($current_entry['path'] . '/entry.json')) { - $entries[$current_entry['dirname']] = $this->fetch($id . '/' . $current_entry['dirname']); + + // Get entry uid + // 1. Remove entries path + // 2. Remove left and right slashes + $uid = ltrim(rtrim(str_replace(PATH['entries'], '', $current_entry['path']), '/'), '/'); + + // For each founded entry we should create $entries array. + $entries[$uid] = $this->fetch($uid); } } } + // Save entries into the cache $this->flextype['cache']->save($cache_id, $entries); } - // Sort and Slice entries if $raw === false + // If count of the entries more then 0 then sort and slice them. if (count($entries) > 0) { + + // Sort entries $entries = Arr::sort($entries, $order_by, $order_type); + // Slice entries if ($offset !== null && $length !== null) { $entries = array_slice($entries, $offset, $length); } } - + + // Return entries return $entries; } @@ -171,7 +180,7 @@ class Entries * Update entry * * @access public - * @param string $id Entry + * @param string $id Entry * @param array $data Data * @return bool */ @@ -190,7 +199,7 @@ class Entries * Create entry * * @access public - * @param string $id Entry id + * @param string $id Entry id * @param array $data Data * @return bool */ @@ -203,6 +212,8 @@ class Entries // Try to create directory for new entry if (Filesystem::createDir($entry_dir)) { + + // Entry file path $entry_file = $entry_dir . '/entry.json'; // Check if new entry file exists From d6fd1512dfe3e996f658d4e7849960a73751372f Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 17 Jun 2019 13:06:56 +0300 Subject: [PATCH 09/28] Flextype Core: Entries API #154 #162 #161 - method fetchALL() issue with fetching entries recursively. - remove unused Shortcodes code from method fetch() --- flextype/twig/EntriesTwigExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flextype/twig/EntriesTwigExtension.php b/flextype/twig/EntriesTwigExtension.php index 4a265b62..821e41cc 100644 --- a/flextype/twig/EntriesTwigExtension.php +++ b/flextype/twig/EntriesTwigExtension.php @@ -45,8 +45,8 @@ class EntriesTwigExtension extends \Twig_Extension return $this->flextype['entries']->fetch($entry); } - public 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, bool $recursive = false) : array { - return $this->flextype['entries']->fetchAll($entry, $order_by, $order_type, $offset, $length); + return $this->flextype['entries']->fetchAll($entry, $order_by, $order_type, $offset, $length, $recursive); } } From f05d6a9171365ace09c8901e28f1a4068fb9b8f9 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 17 Jun 2019 13:40:19 +0300 Subject: [PATCH 10/28] CHANGELOG UPDATES --- CHANGELOG.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb9081c8..ad1554d3 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,17 @@ ## [0.9.1] - 2019-06-XX ### Added -- Flextype Admin Panel: new setting `route` added to customize admin base route. -- Flextype Core: GlobalVarsTwigExtension - new global constant `PATH_FIELDSETS` added. +- Flextype Admin Panel: new setting `route` added to customize admin base route. #154 +- Flextype Core: GlobalVarsTwigExtension - new global constant `PATH_FIELDSETS` added. #154 + +### Fixed +- Flextype Core: Entries API - method fetchALL() issue with fetching entries recursively. #154 #161 ### Changed -- Flextype Site: code refactoring -- Flextype Admin Panel: code refactoring +- Flextype Site: code refactoring #154 +- Flextype Admin Panel: code refactoring #154 + +### Removed +- Flextype Core: Entries API - remove unused Shortcodes code from method fetch() #162 ## [0.9.0] - 2019-06-14 ### Added @@ -57,7 +63,6 @@ - Flextype Core: Flextype Error Handler Component removed. - Flextype Core: Flextype Event Component removed. - ## [0.8.3] - 2019-01-16 ### Added - Admin Panel: New Gorgeous Light Theme for Admin panel! From a9a5d9ee2e52c0db8c3a6047ef8b7430e9dbfde0 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 00:57:05 +0300 Subject: [PATCH 11/28] Flextype Core: Entries API #154 - public property $entry added. - public property $entries added. - new event onEntryAfterInitialized added. - new event onEntriesAfterInitialized added. --- flextype/core/Entries.php | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/flextype/core/Entries.php b/flextype/core/Entries.php index 28546c78..5171c9ff 100755 --- a/flextype/core/Entries.php +++ b/flextype/core/Entries.php @@ -17,8 +17,26 @@ use Flextype\Component\Filesystem\Filesystem; class Entries { + /** + * Current entry data array + * + * @var array + * @access public + */ + public $entry = []; + + /** + * Current entries data array + * + * @var array + * @access public + */ + public $entries = []; + /** * Flextype Dependency Container + * + * @access private */ private $flextype; @@ -66,8 +84,14 @@ class Entries // Save decoded entry content into the cache $this->flextype['cache']->save($cache_id, $entry_decoded); - // Return decoded entry - return $entry_decoded; + // Set entry + $this->entry = $entry_decoded; + + // Run event onEntryAfterInitialized + $this->flextype['emitter']->emit('onEntryAfterInitialized'); + + // Return entry + return $this->entry; } else { return false; } @@ -158,9 +182,15 @@ class Entries $entries = array_slice($entries, $offset, $length); } } - + + // Set entries + $this->entries = $entries; + + // Run event onEntriesAfterInitialized + $this->flextype['emitter']->emit('onEntriesAfterInitialized'); + // Return entries - return $entries; + return $this->entries; } /** From 464c97c73b8ff5c8c604f4bdc3453ec7a94be03a Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 00:59:43 +0300 Subject: [PATCH 12/28] CHANGELOG UPDATES --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad1554d3..2bba1ba7 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### Added - Flextype Admin Panel: new setting `route` added to customize admin base route. #154 - Flextype Core: GlobalVarsTwigExtension - new global constant `PATH_FIELDSETS` added. #154 +- Flextype Core: Entries API - public property $entry added. #154 +- Flextype Core: Entries API - public property $entries added. #154 +- Flextype Core: Entries API - new event onEntryAfterInitialized added. #154 +- Flextype Core: Entries API - new event onEntriesAfterInitialized added. #154 ### Fixed - Flextype Core: Entries API - method fetchALL() issue with fetching entries recursively. #154 #161 From 40f1df822fd2b51d58f84f40dfc05e24eb77b131 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 09:59:02 +0300 Subject: [PATCH 13/28] Flextype Site Plugin: #154 - public property $entry added. - new event onSiteEntryAfterInitialized added. --- .../site/app/Controllers/SiteController.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/site/plugins/site/app/Controllers/SiteController.php b/site/plugins/site/app/Controllers/SiteController.php index 0805495d..ced230e5 100644 --- a/site/plugins/site/app/Controllers/SiteController.php +++ b/site/plugins/site/app/Controllers/SiteController.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 Flextype\Component\Arr\Arr; @@ -18,6 +18,14 @@ use Psr\Http\Message\ServerRequestInterface as Request; class SiteController extends Controller { + /** + * Current entry data array + * + * @var array + * @access private + */ + public $entry = []; + /** * Index page * @@ -70,12 +78,19 @@ class SiteController extends Controller $is_entry_not_found = true; } - $path = 'themes/' . $this->registry->get('settings.theme') . '/' . (empty($entry['template']) ? 'templates/default' : 'templates/' . $entry['template']) . '.html'; + // Set entry + $this->entry = $entry; + + // Run event onSiteEntryAfterInitialized + $this->emitter->emit('onSiteEntryAfterInitialized'); + + // Set template path for current entry + $path = 'themes/' . $this->registry->get('settings.theme') . '/' . (empty($this->entry['template']) ? 'templates/default' : 'templates/' . $this->entry['template']) . '.html'; if ($is_entry_not_found) { - return $this->view->render($response->withStatus(404), $path, ['entry' => $entry]); + return $this->view->render($response->withStatus(404), $path, ['entry' => $this->entry]); } else { - return $this->view->render($response, $path, ['entry' => $entry]); + return $this->view->render($response, $path, ['entry' => $this->entry]); } } From 8afa617b52a83f6858cbefeb40eccf74e1679bbd Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 10:00:40 +0300 Subject: [PATCH 14/28] CHANGELOG UPDATES --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bba1ba7..fe0e2d13 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,15 @@ - Flextype Core: Entries API - public property $entries added. #154 - Flextype Core: Entries API - new event onEntryAfterInitialized added. #154 - Flextype Core: Entries API - new event onEntriesAfterInitialized added. #154 +- Flextype Site Plugin: public property $entry added. #154 +- Flextype Site Plugin: new event onSiteEntryAfterInitialized added.#154 ### Fixed -- Flextype Core: Entries API - method fetchALL() issue with fetching entries recursively. #154 #161 +- Flextype Core: Entries API - fetchALL() issue with fetching entries recursively fixed. #154 #161 ### Changed -- Flextype Site: code refactoring #154 -- Flextype Admin Panel: code refactoring #154 +- Flextype Site: code refactoring. #154 +- Flextype Admin Panel: code refactoring. #154 ### Removed - Flextype Core: Entries API - remove unused Shortcodes code from method fetch() #162 From 824cb273b6bbc3c752b0b48e0efa1d1d35b2eb74 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 11:58:42 +0300 Subject: [PATCH 15/28] CHANGELOG UPDATES --- CHANGELOG.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe0e2d13..abf5f8e3 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,22 +2,22 @@ ### Added - Flextype Admin Panel: new setting `route` added to customize admin base route. #154 - Flextype Core: GlobalVarsTwigExtension - new global constant `PATH_FIELDSETS` added. #154 -- Flextype Core: Entries API - public property $entry added. #154 -- Flextype Core: Entries API - public property $entries added. #154 -- Flextype Core: Entries API - new event onEntryAfterInitialized added. #154 -- Flextype Core: Entries API - new event onEntriesAfterInitialized added. #154 -- Flextype Site Plugin: public property $entry added. #154 -- Flextype Site Plugin: new event onSiteEntryAfterInitialized added.#154 +- Flextype Core: Entries API - public property `$entry` added. #154 +- Flextype Core: Entries API - public property `$entries` added. #154 +- Flextype Core: Entries API - new event `onEntryAfterInitialized` added. #154 +- Flextype Core: Entries API - new event `onEntriesAfterInitialized` added. #154 +- Flextype Site Plugin: public property `$entry` added. #154 +- Flextype Site Plugin: new event `onSiteEntryAfterInitialized` added.#154 ### Fixed -- Flextype Core: Entries API - fetchALL() issue with fetching entries recursively fixed. #154 #161 +- Flextype Core: Entries API - `fetchALL()` issue with fetching entries recursively fixed. #154 #161 ### Changed - Flextype Site: code refactoring. #154 - Flextype Admin Panel: code refactoring. #154 ### Removed -- Flextype Core: Entries API - remove unused Shortcodes code from method fetch() #162 +- Flextype Core: Entries API - remove unused Shortcodes code from method `fetch()` #162 ## [0.9.0] - 2019-06-14 ### Added From d6763c408ff79eb8243d073bd0da1b6291bf2717 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 12:01:08 +0300 Subject: [PATCH 16/28] CHANGELOG UPDATES --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abf5f8e3..052bd7e7 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - Flextype Core: Entries API - new event `onEntryAfterInitialized` added. #154 - Flextype Core: Entries API - new event `onEntriesAfterInitialized` added. #154 - Flextype Site Plugin: public property `$entry` added. #154 -- Flextype Site Plugin: new event `onSiteEntryAfterInitialized` added.#154 +- Flextype Site Plugin: new event `onSiteEntryAfterInitialized` added. #154 ### Fixed - Flextype Core: Entries API - `fetchALL()` issue with fetching entries recursively fixed. #154 #161 From becccdac068a0c5f61acc5d221fc53ea6fc56016 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 15:36:58 +0300 Subject: [PATCH 17/28] Flextype Core: Shortcodes - SiteUrlShortcode removed. #154 --- flextype/shortcodes/SiteUrlShortcode.php | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 flextype/shortcodes/SiteUrlShortcode.php diff --git a/flextype/shortcodes/SiteUrlShortcode.php b/flextype/shortcodes/SiteUrlShortcode.php deleted file mode 100644 index 974b8e3b..00000000 --- a/flextype/shortcodes/SiteUrlShortcode.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @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 Thunder\Shortcode\ShortcodeFacade; -use Thunder\Shortcode\Shortcode\ShortcodeInterface; - -// Shortcode: [site_url] -$flextype['shortcodes']->addHandler('site_url', function () { - return \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER))->getBaseUrl(); -}); From 841f0061692944f40661b459e50b6a44fac345e6 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 15:37:13 +0300 Subject: [PATCH 18/28] Flextype Core: Shortcodes - BaseUrlShortcode added. #154 --- flextype/shortcodes/BaseUrlShortcode.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 flextype/shortcodes/BaseUrlShortcode.php diff --git a/flextype/shortcodes/BaseUrlShortcode.php b/flextype/shortcodes/BaseUrlShortcode.php new file mode 100644 index 00000000..d3dcb99e --- /dev/null +++ b/flextype/shortcodes/BaseUrlShortcode.php @@ -0,0 +1,21 @@ + + * @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 Thunder\Shortcode\ShortcodeFacade; +use Thunder\Shortcode\Shortcode\ShortcodeInterface; + +// Shortcode: [base_url] +$flextype['shortcodes']->addHandler('base_url', function () { + return \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER))->getBaseUrl(); +}); From ae5d9e34a984a3a32806c8c1a8d3553b293ccf8a Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 15:38:20 +0300 Subject: [PATCH 19/28] Flextype Core: Shortcodes - EntriesShortcode added. #154 --- flextype/shortcodes/EntriesShortcode.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 flextype/shortcodes/EntriesShortcode.php diff --git a/flextype/shortcodes/EntriesShortcode.php b/flextype/shortcodes/EntriesShortcode.php new file mode 100644 index 00000000..0df8022e --- /dev/null +++ b/flextype/shortcodes/EntriesShortcode.php @@ -0,0 +1,22 @@ + + * @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 Thunder\Shortcode\ShortcodeFacade; +use Thunder\Shortcode\Shortcode\ShortcodeInterface; +use Flextype\Component\Arr\Arr; + +// Shortcode: [entries_fetch id="entry-id" field="field-name" default="default-value"] +$flextype['shortcodes']->addHandler('entries_fetch', function (ShortcodeInterface $s) use ($flextype) { + return Arr::get($flextype['entries']->fetch($s->getParameter('id')), $s->getParameter('field'), $s->getParameter('default')); +}); From fcb4310f30bf29c30c224c1d217bc55ffc907932 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 15:47:56 +0300 Subject: [PATCH 20/28] Flextype Core: Snippets API #154 - added ability to access $flextype and $app inside snippets. - display() method removed. - exec() method added. - _display_snippet() method removed. - _exec_snippet() method added. - from now we will set prefix bind_ for all variables. - [snippets] shortcode removed. - [snppets_fetch] shortcode added. - SnippetsTwigExtension: snippets_exec() added. - SnippetsTwigExtension: snippet removed. --- flextype/core/Snippets.php | 42 +++++++++++++++-------- flextype/dependencies.php | 4 +-- flextype/shortcodes/SnippetsShortcode.php | 4 +-- flextype/twig/SnippetsTwigExtension.php | 6 ++-- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/flextype/core/Snippets.php b/flextype/core/Snippets.php index ad53c7fe..de98b067 100644 --- a/flextype/core/Snippets.php +++ b/flextype/core/Snippets.php @@ -21,27 +21,33 @@ class Snippets */ private $flextype; + /** + * Flextype Application + */ + private $app; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct($flextype, $app) { $this->flextype = $flextype; + $this->app = $app; } /** - * Get snippet + * Exec snippet * * @access public * @param string $id Snippet id * @return string|bool Returns the contents of the output buffer and end output buffering. * If output buffering isn't active then FALSE is returned. */ - public function display(string $id) + public function exec(string $id) { - return $this->_display_snippet(['fetch' => $id]); + return $this->_exec_snippet(['id' => $id]); } /** @@ -93,7 +99,7 @@ class Snippets } /** - * Rename snippet. + * Rename snippet * * @access public * @param string $id Snippet id @@ -182,23 +188,23 @@ class Snippets } /** - * Helper private method _display_snippet + * Helper private method _exec_snippet * * @access private * @param array $vars Vars * @return string|bool Returns the contents of the output buffer and end output buffering. * If output buffering isn't active then FALSE is returned. */ - private function _display_snippet(array $vars) + private function _exec_snippet(array $vars) { - // Extracst attributes - extract($vars); + // Extracts vars and set prefix bind_ for all of them + extract($vars, EXTR_PREFIX_ALL, 'bind'); - // Get snippet name - $name = (isset($fetch)) ? (string) $fetch : ''; + // Get snippet id + $snippet_id = (string) $bind_id ?? ''; - // Define snippet path - $snippet_file = $this->_file_location($name); + // Define snippet file path + $snippet_file = $this->_file_location($snippet_id); // Process snippet if (Filesystem::has($snippet_file)) { @@ -206,13 +212,19 @@ class Snippets // Turn on output buffering ob_start(); - // Include view file + // Re-init $flextype for snippets + $flextype = $this->flextype; + + // Re-init $app for snippets + $app = $this->app; + + // Include snippet file include $snippet_file; // Output... return ob_get_clean(); } else { - throw new \RuntimeException("Snippet {$name} does not exist."); + throw new \RuntimeException("Snippet {$snippet_id} does not exist."); } } diff --git a/flextype/dependencies.php b/flextype/dependencies.php index 478b167b..492c7183 100644 --- a/flextype/dependencies.php +++ b/flextype/dependencies.php @@ -140,8 +140,8 @@ $flextype['fieldsets'] = function ($container) use ($flextype) { /** * Add snippets service to Flextype container */ -$flextype['snippets'] = function ($container) use ($flextype) { - return new Snippets($flextype); +$flextype['snippets'] = function ($container) use ($flextype, $app) { + return new Snippets($flextype, $app); }; /** diff --git a/flextype/shortcodes/SnippetsShortcode.php b/flextype/shortcodes/SnippetsShortcode.php index f4754fa0..0990f878 100644 --- a/flextype/shortcodes/SnippetsShortcode.php +++ b/flextype/shortcodes/SnippetsShortcode.php @@ -15,7 +15,7 @@ namespace Flextype; use Thunder\Shortcode\ShortcodeFacade; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -// Shortcode: [snippets fetch=snippet-name] +// Shortcode: [snippets_fetch id="snippet-name"] $flextype['shortcodes']->addHandler('snippets', function (ShortcodeInterface $s) use ($flextype) { - return $flextype['snippets']->display($s->getParameter('fetch')); + return $flextype['snippets']->exec($s->getParameter('id')); }); diff --git a/flextype/twig/SnippetsTwigExtension.php b/flextype/twig/SnippetsTwigExtension.php index 88dc21f5..4ef42fa1 100644 --- a/flextype/twig/SnippetsTwigExtension.php +++ b/flextype/twig/SnippetsTwigExtension.php @@ -35,12 +35,12 @@ class SnippetsTwigExtension extends \Twig_Extension public function getFunctions() { return [ - new \Twig_SimpleFunction('snippet', [$this, 'snippet']) + new \Twig_SimpleFunction('snippets_exec', [$this, 'exec']) ]; } - public function snippet(string $id) + public function exec(string $id) { - return $this->flextype['snippets']->display($id); + return $this->flextype['snippets']->exec($id); } } From de756b456fd4677a6f434ff3a7da396683e8e2a0 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 15:50:59 +0300 Subject: [PATCH 21/28] Flextype Core: Snippets API #154 - added ability to access $flextype and $app inside snippets. - display() method removed. - exec() method added. - _display_snippet() method removed. - _exec_snippet() method added. - from now we will set prefix bind_ for all variables. - [snippets] shortcode removed. - [snppets_fetch] shortcode added. - SnippetsTwigExtension: snippets_exec() added. - SnippetsTwigExtension: snippet removed. --- flextype/shortcodes/SnippetsShortcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flextype/shortcodes/SnippetsShortcode.php b/flextype/shortcodes/SnippetsShortcode.php index 0990f878..2cf14b86 100644 --- a/flextype/shortcodes/SnippetsShortcode.php +++ b/flextype/shortcodes/SnippetsShortcode.php @@ -16,6 +16,6 @@ use Thunder\Shortcode\ShortcodeFacade; use Thunder\Shortcode\Shortcode\ShortcodeInterface; // Shortcode: [snippets_fetch id="snippet-name"] -$flextype['shortcodes']->addHandler('snippets', function (ShortcodeInterface $s) use ($flextype) { +$flextype['shortcodes']->addHandler('snippets_fetch', function (ShortcodeInterface $s) use ($flextype) { return $flextype['snippets']->exec($s->getParameter('id')); }); From e537c022ffbd7ba1c9d7554f58c4768f4816de95 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 18 Jun 2019 16:14:10 +0300 Subject: [PATCH 22/28] Flextype Admin Plugin: Snippets fixes #154 --- .../plugins/admin/views/templates/extends/snippets/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/plugins/admin/views/templates/extends/snippets/index.html b/site/plugins/admin/views/templates/extends/snippets/index.html index cb78f88f..76833215 100644 --- a/site/plugins/admin/views/templates/extends/snippets/index.html +++ b/site/plugins/admin/views/templates/extends/snippets/index.html @@ -64,7 +64,7 @@