mirror of
https://github.com/flextype/flextype.git
synced 2025-08-23 05:16:03 +02:00
- next round of code improvements
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -12,8 +11,18 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Doctrine\Common\Cache as DoctrineCache;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use \Doctrine\Common\Cache as DoctrineCache;
|
||||
use Memcached;
|
||||
use Redis;
|
||||
use RedisException;
|
||||
use SQLite3;
|
||||
use function clearstatcache;
|
||||
use function extension_loaded;
|
||||
use function function_exists;
|
||||
use function md5;
|
||||
use function opcache_reset;
|
||||
use function time;
|
||||
|
||||
class Cache
|
||||
{
|
||||
@@ -60,7 +69,7 @@ class Cache
|
||||
$this->flextype = $flextype;
|
||||
|
||||
// Create Cache Directory
|
||||
!Filesystem::has(PATH['cache']) and Filesystem::createDir(PATH['cache']);
|
||||
! Filesystem::has(PATH['cache']) and Filesystem::createDir(PATH['cache']);
|
||||
|
||||
// Set current time
|
||||
$this->now = time();
|
||||
@@ -79,9 +88,8 @@ class Cache
|
||||
* Get Cache Driver
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getCacheDriver()
|
||||
public function getCacheDriver() : object
|
||||
{
|
||||
// Try to set default cache driver name
|
||||
$driver_name = $this->setDefaultCacheDriverName($this->flextype['registry']->get('settings.cache.driver'));
|
||||
@@ -94,29 +102,29 @@ class Cache
|
||||
{
|
||||
switch ($driver_name) {
|
||||
case 'apcu':
|
||||
$driver = $this->setApcuCacheDriver();
|
||||
break;
|
||||
$driver = $this->setApcuCacheDriver();
|
||||
break;
|
||||
case 'array':
|
||||
$driver = $this->setArrayCacheDriver();
|
||||
break;
|
||||
break;
|
||||
case 'wincache':
|
||||
$driver = $this->setWinCacheDriver();
|
||||
break;
|
||||
$driver = $this->setWinCacheDriver();
|
||||
break;
|
||||
case 'memcached':
|
||||
$driver = $this->setMemcachedCacheDriver();
|
||||
break;
|
||||
break;
|
||||
case 'sqlite3':
|
||||
$driver = $this->setSQLite3CacheDriver();
|
||||
break;
|
||||
break;
|
||||
case 'zend':
|
||||
$driver = $this->setZendDataCacheDriver();
|
||||
break;
|
||||
break;
|
||||
case 'redis':
|
||||
$driver = $this->setRedisCacheDriver();
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$driver = $this->setFilesystemCacheDriver();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
return $driver;
|
||||
@@ -129,9 +137,7 @@ class Cache
|
||||
*/
|
||||
protected function setZendDataCacheDriver()
|
||||
{
|
||||
$driver = new DoctrineCache\ZendDataCache();
|
||||
|
||||
return $driver;
|
||||
return new DoctrineCache\ZendDataCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,12 +152,11 @@ class Cache
|
||||
$cache_directory = PATH['cache'] . '/doctrine/';
|
||||
|
||||
// Create doctrine cache directory if its not exists
|
||||
!Filesystem::has($cache_directory) and Filesystem::createDir($cache_directory);
|
||||
! Filesystem::has($cache_directory) and Filesystem::createDir($cache_directory);
|
||||
|
||||
$db = new \SQLite3($cache_directory . $this->flextype['registry']->get('settings.cache.sqlite3.database', 'flextype') . '.db');
|
||||
$driver = new DoctrineCache\SQLite3Cache($db, $this->flextype['registry']->get('settings.cache.sqlite3.table', 'flextype'));
|
||||
$db = new SQLite3($cache_directory . $this->flextype['registry']->get('settings.cache.sqlite3.database', 'flextype') . '.db');
|
||||
|
||||
return $driver;
|
||||
return new DoctrineCache\SQLite3Cache($db, $this->flextype['registry']->get('settings.cache.sqlite3.table', 'flextype'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +166,7 @@ class Cache
|
||||
*/
|
||||
protected function setMemcachedCacheDriver()
|
||||
{
|
||||
$memcached = new \Memcached();
|
||||
$memcached = new Memcached();
|
||||
$memcached->addServer(
|
||||
$this->flextype['registry']->get('settings.cache.memcached.server', 'localhost'),
|
||||
$this->flextype['registry']->get('settings.cache.memcache.port', 11211)
|
||||
@@ -181,21 +186,18 @@ class Cache
|
||||
*/
|
||||
protected function setWinCacheDriver()
|
||||
{
|
||||
$driver = new DoctrineCache\WinCacheCache();
|
||||
|
||||
return $driver;
|
||||
return new DoctrineCache\WinCacheCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* The ArrayCache driver stores the cache data in PHPs memory and is not persisted anywhere.
|
||||
* This can be useful for caching things in memory for a single process when you don't need the cache to be persistent across processes.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function setArrayCacheDriver()
|
||||
{
|
||||
$driver = new DoctrineCache\ArrayCache();
|
||||
|
||||
return $driver;
|
||||
return new DoctrineCache\ArrayCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,9 +208,7 @@ class Cache
|
||||
*/
|
||||
protected function setApcuCacheDriver()
|
||||
{
|
||||
$driver = new DoctrineCache\ApcuCache();
|
||||
|
||||
return $driver;
|
||||
return new DoctrineCache\ApcuCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +219,7 @@ class Cache
|
||||
*/
|
||||
protected function setRedisCacheDriver()
|
||||
{
|
||||
$redis = new \Redis();
|
||||
$redis = new Redis();
|
||||
$socket = $this->flextype['registry']->get('settings.cache.redis.socket', false);
|
||||
$password = $this->flextype['registry']->get('settings.cache.redis.password', false);
|
||||
|
||||
@@ -233,8 +233,8 @@ class Cache
|
||||
}
|
||||
|
||||
// Authenticate with password if set
|
||||
if ($password && !$redis->auth($password)) {
|
||||
throw new \RedisException('Redis authentication failed');
|
||||
if ($password && ! $redis->auth($password)) {
|
||||
throw new RedisException('Redis authentication failed');
|
||||
}
|
||||
|
||||
$driver = new DoctrineCache\RedisCache();
|
||||
@@ -254,22 +254,21 @@ class Cache
|
||||
$cache_directory = PATH['cache'] . '/doctrine/';
|
||||
|
||||
// Create doctrine cache directory if its not exists
|
||||
!Filesystem::has($cache_directory) and Filesystem::createDir($cache_directory);
|
||||
$driver = new DoctrineCache\FilesystemCache($cache_directory);
|
||||
! Filesystem::has($cache_directory) and Filesystem::createDir($cache_directory);
|
||||
|
||||
return $driver;
|
||||
return new DoctrineCache\FilesystemCache($cache_directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Default Cache Driver Name
|
||||
*
|
||||
* @access protected
|
||||
* @param string $driver_name Driver name.
|
||||
* @return string
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function setDefaultCacheDriverName(string $driver_name)
|
||||
protected function setDefaultCacheDriverName(string $driver_name) : string
|
||||
{
|
||||
if (!$driver_name || $driver_name == 'auto') {
|
||||
if (! $driver_name || $driver_name === 'auto') {
|
||||
if (extension_loaded('apcu')) {
|
||||
$driver_name = 'apcu';
|
||||
} elseif (extension_loaded('wincache')) {
|
||||
@@ -286,9 +285,8 @@ class Cache
|
||||
* Returns driver variable
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function driver()
|
||||
public function driver() : object
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
@@ -297,7 +295,6 @@ class Cache
|
||||
* Get cache key.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getKey() : string
|
||||
{
|
||||
@@ -307,52 +304,58 @@ class Cache
|
||||
/**
|
||||
* Fetches an entry from the cache.
|
||||
*
|
||||
* @access public
|
||||
* @param string $id The id of the cache entry to fetch.
|
||||
*
|
||||
* @return mixed The cached data or FALSE, if no cache entry exists for the given id.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetch(string $id)
|
||||
{
|
||||
if ($this->flextype['registry']->get('settings.cache.enabled')) {
|
||||
return $this->driver->fetch($id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean state of whether or not the item exists in the cache based on id key
|
||||
*
|
||||
* @param string $id the id of the cached data entry
|
||||
* @param string $id the id of the cached data entry
|
||||
*
|
||||
* @return bool true if the cached items exists
|
||||
*/
|
||||
public function contains($id)
|
||||
public function contains(string $id) : bool
|
||||
{
|
||||
if ($this->flextype['registry']->get('settings.cache.enabled')) {
|
||||
return $this->driver->contains($id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts data into the cache.
|
||||
*
|
||||
* @access public
|
||||
* @param string $id The cache id.
|
||||
* @param mixed $data The cache entry/data.
|
||||
* @param int $lifetime The lifetime in number of seconds for this cache entry.
|
||||
* If zero (the default), the entry never expires (although it may be deleted from the cache
|
||||
* to make place for other entries).
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function save(string $id, $data, $lifetime = null)
|
||||
public function save(string $id, $data, ?int $lifetime = null) : void
|
||||
{
|
||||
if ($this->flextype['registry']->get('settings.cache.enabled')) {
|
||||
if ($lifetime === null) {
|
||||
$lifetime = $this->getLifetime();
|
||||
}
|
||||
$this->driver->save($id, $data, $lifetime);
|
||||
if (! $this->flextype['registry']->get('settings.cache.enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($lifetime === null) {
|
||||
$lifetime = $this->getLifetime();
|
||||
}
|
||||
$this->driver->save($id, $data, $lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,27 +391,31 @@ class Cache
|
||||
/**
|
||||
* Set the cache lifetime.
|
||||
*
|
||||
* @access public
|
||||
* @param int $future timestamp
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setLifetime(int $future)
|
||||
public function setLifetime(int $future) : void
|
||||
{
|
||||
if (!$future) {
|
||||
if (! $future) {
|
||||
return;
|
||||
}
|
||||
|
||||
$interval = $future-$this->now;
|
||||
|
||||
if ($interval > 0 && $interval < $this->getLifetime()) {
|
||||
$this->lifetime = $interval;
|
||||
if ($interval <= 0 || $interval >= $this->getLifetime()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->lifetime = $interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the cache lifetime (in seconds)
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getLifetime()
|
||||
{
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -12,11 +11,16 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use function ltrim;
|
||||
use function md5;
|
||||
use function rename;
|
||||
use function rtrim;
|
||||
use function str_replace;
|
||||
use function strpos;
|
||||
|
||||
class Entries
|
||||
{
|
||||
@@ -56,9 +60,11 @@ class Entries
|
||||
/**
|
||||
* Fetch single entry
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Entry ID
|
||||
*
|
||||
* @return array|false The entry contents or false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetch(string $id)
|
||||
{
|
||||
@@ -67,7 +73,6 @@ class Entries
|
||||
|
||||
// If requested entry founded then process it
|
||||
if (Filesystem::has($entry_file)) {
|
||||
|
||||
// Create unique entry cache_id
|
||||
// Entry Cache ID = entry + entry file + entry file time stamp
|
||||
if ($timestamp = Filesystem::getTimestamp($entry_file)) {
|
||||
@@ -78,71 +83,65 @@ class Entries
|
||||
|
||||
// Try to get the requested entry from cache
|
||||
if ($this->flextype['cache']->contains($entry_cache_id)) {
|
||||
|
||||
// Try to fetch requested entry from the cache
|
||||
if ($entry = $this->flextype['cache']->fetch($entry_cache_id)) {
|
||||
|
||||
// Run event onEntryAfterInitialized
|
||||
$this->flextype['emitter']->emit('onEntryAfterInitialized');
|
||||
|
||||
// Return entry
|
||||
return $entry;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
// else Try to get requested entry from the filesystem
|
||||
} else {
|
||||
|
||||
// Try to get requested entry body content
|
||||
if ($entry_body = Filesystem::read($entry_file)) {
|
||||
|
||||
// Try to decode requested entry body content
|
||||
if ($entry_decoded = JsonParser::decode($entry_body)) {
|
||||
|
||||
//
|
||||
// Add predefined entry items
|
||||
//
|
||||
|
||||
// Entry Date
|
||||
$entry_decoded['published_at'] = $entry_decoded['published_at'] ? $entry_decoded['published_at'] : Filesystem::getTimestamp($entry_file);
|
||||
$entry_decoded['created_at'] = $entry_decoded['created_at'] ? $entry_decoded['created_at'] : Filesystem::getTimestamp($entry_file);
|
||||
|
||||
// Entry Timestamp
|
||||
$entry_decoded['modified_at'] = Filesystem::getTimestamp($entry_file);
|
||||
|
||||
// Entry Slug
|
||||
$entry_decoded['slug'] = $entry_decoded['slug'] ?? ltrim(rtrim($id, '/'), '/');
|
||||
|
||||
// Save decoded entry content into the cache
|
||||
$this->flextype['cache']->save($entry_cache_id, $entry_decoded);
|
||||
|
||||
// Set entry to the Entry class property $entry
|
||||
$this->entry = $entry_decoded;
|
||||
|
||||
// Run event onEntryAfterInitialized
|
||||
$this->flextype['emitter']->emit('onEntryAfterInitialized');
|
||||
|
||||
// Return entry from the Entry class property $entry
|
||||
return $this->entry;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Try to get requested entry body content
|
||||
if ($entry_body = Filesystem::read($entry_file)) {
|
||||
// Try to decode requested entry body content
|
||||
if ($entry_decoded = JsonParser::decode($entry_body)) {
|
||||
// Add predefined entry items
|
||||
// Entry Date
|
||||
$entry_decoded['published_at'] = $entry_decoded['published_at'] ? $entry_decoded['published_at'] : Filesystem::getTimestamp($entry_file);
|
||||
$entry_decoded['created_at'] = $entry_decoded['created_at'] ? $entry_decoded['created_at'] : Filesystem::getTimestamp($entry_file);
|
||||
|
||||
// Entry Timestamp
|
||||
$entry_decoded['modified_at'] = Filesystem::getTimestamp($entry_file);
|
||||
|
||||
// Entry Slug
|
||||
$entry_decoded['slug'] = $entry_decoded['slug'] ?? ltrim(rtrim($id, '/'), '/');
|
||||
|
||||
// Save decoded entry content into the cache
|
||||
$this->flextype['cache']->save($entry_cache_id, $entry_decoded);
|
||||
|
||||
// Set entry to the Entry class property $entry
|
||||
$this->entry = $entry_decoded;
|
||||
|
||||
// Run event onEntryAfterInitialized
|
||||
$this->flextype['emitter']->emit('onEntryAfterInitialized');
|
||||
|
||||
// Return entry from the Entry class property $entry
|
||||
return $this->entry;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch entries collection
|
||||
*
|
||||
* @access public
|
||||
* @param array $args Query arguments
|
||||
*
|
||||
* @return array The entries
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetchAll(string $id, array $args = []) : array
|
||||
{
|
||||
@@ -151,44 +150,44 @@ class Entries
|
||||
|
||||
// Set Expression
|
||||
$expression = [
|
||||
'=' => Comparison::EQ,
|
||||
'<>' => Comparison::NEQ,
|
||||
'<' => Comparison::LT,
|
||||
'<=' => Comparison::LTE,
|
||||
'>' => Comparison::GT,
|
||||
'>=' => Comparison::GTE,
|
||||
'is' => Comparison::IS,
|
||||
'in' => Comparison::IN,
|
||||
'nin' => Comparison::NIN,
|
||||
'contains' => Comparison::CONTAINS,
|
||||
'member_of' => Comparison::MEMBER_OF,
|
||||
'start_with' => Comparison::STARTS_WITH,
|
||||
'ends_with' => Comparison::ENDS_WITH,
|
||||
];
|
||||
'=' => Comparison::EQ,
|
||||
'<>' => Comparison::NEQ,
|
||||
'<' => Comparison::LT,
|
||||
'<=' => Comparison::LTE,
|
||||
'>' => Comparison::GT,
|
||||
'>=' => Comparison::GTE,
|
||||
'is' => Comparison::IS,
|
||||
'in' => Comparison::IN,
|
||||
'nin' => Comparison::NIN,
|
||||
'contains' => Comparison::CONTAINS,
|
||||
'member_of' => Comparison::MEMBER_OF,
|
||||
'start_with' => Comparison::STARTS_WITH,
|
||||
'ends_with' => Comparison::ENDS_WITH,
|
||||
];
|
||||
|
||||
// Set Direction
|
||||
$direction = [
|
||||
'asc' => Criteria::ASC,
|
||||
'desc' => Criteria::DESC
|
||||
'desc' => Criteria::DESC,
|
||||
];
|
||||
|
||||
// Bind: entry id
|
||||
$bind_id = $id;
|
||||
|
||||
// Bind: recursive
|
||||
$bind_recursive = (isset($args['recursive'])) ? $args['recursive'] : false;
|
||||
$bind_recursive = $args['recursive'] ?? false;
|
||||
|
||||
// Bind: set first result
|
||||
$bind_set_first_result = (isset($args['set_first_result'])) ? $args['set_first_result'] : false;
|
||||
$bind_set_first_result = $args['set_first_result'] ?? false;
|
||||
|
||||
// Bind: set max result
|
||||
$bind_set_max_result = (isset($args['set_max_result'])) ? $args['set_max_result'] : false;
|
||||
$bind_set_max_result = $args['set_max_result'] ?? false;
|
||||
|
||||
// Bind: where
|
||||
if (isset($args['where']['key']) && isset($args['where']['expr']) && isset($args['where']['value'])) {
|
||||
$bind_where = [];
|
||||
$bind_where['where']['key'] = $args['where']['key'];
|
||||
$bind_where['where']['expr'] = $expression[$args['where']['expr']];
|
||||
$bind_where = [];
|
||||
$bind_where['where']['key'] = $args['where']['key'];
|
||||
$bind_where['where']['expr'] = $expression[$args['where']['expr']];
|
||||
$bind_where['where']['value'] = $args['where']['value'];
|
||||
} else {
|
||||
$bind_where = false;
|
||||
@@ -196,9 +195,9 @@ class Entries
|
||||
|
||||
// Bind: and where
|
||||
if (isset($args['and_where']['key']) && isset($args['and_where']['expr']) && isset($args['and_where']['value'])) {
|
||||
$bind_and_where = [];
|
||||
$bind_and_where['and_where']['key'] = $args['and_where']['key'];
|
||||
$bind_and_where['and_where']['expr'] = $expression[$args['and_where']['expr']];
|
||||
$bind_and_where = [];
|
||||
$bind_and_where['and_where']['key'] = $args['and_where']['key'];
|
||||
$bind_and_where['and_where']['expr'] = $expression[$args['and_where']['expr']];
|
||||
$bind_and_where['and_where']['value'] = $args['and_where']['value'];
|
||||
} else {
|
||||
$bind_and_where = false;
|
||||
@@ -206,9 +205,9 @@ class Entries
|
||||
|
||||
// Bind: or where
|
||||
if (isset($args['or_where']['key']) && isset($args['or_where']['expr']) && isset($args['or_where']['value'])) {
|
||||
$bind_or_where = [];
|
||||
$bind_or_where['or_where']['key'] = $args['or_where']['key'];
|
||||
$bind_or_where['or_where']['expr'] = $expression[$args['or_where']['expr']];
|
||||
$bind_or_where = [];
|
||||
$bind_or_where['or_where']['key'] = $args['or_where']['key'];
|
||||
$bind_or_where['or_where']['expr'] = $expression[$args['or_where']['expr']];
|
||||
$bind_or_where['or_where']['value'] = $args['or_where']['value'];
|
||||
} else {
|
||||
$bind_or_where = false;
|
||||
@@ -216,8 +215,8 @@ class Entries
|
||||
|
||||
// Bind: order by
|
||||
if (isset($args['order_by']['field']) && isset($args['order_by']['direction'])) {
|
||||
$bind_order_by = [];
|
||||
$bind_order_by['order_by']['field'] = $args['order_by']['field'];
|
||||
$bind_order_by = [];
|
||||
$bind_order_by['order_by']['field'] = $args['order_by']['field'];
|
||||
$bind_order_by['order_by']['direction'] = $args['order_by']['direction'];
|
||||
} else {
|
||||
$bind_order_by = false;
|
||||
@@ -237,7 +236,7 @@ class Entries
|
||||
if (strpos($current_entry['path'], $bind_id . '/entry.json') !== false) {
|
||||
// ignore ...
|
||||
} else {
|
||||
if ($current_entry['type'] == 'dir' && Filesystem::has($current_entry['path'] . '/entry.json')) {
|
||||
if ($current_entry['type'] === 'dir' && Filesystem::has($current_entry['path'] . '/entry.json')) {
|
||||
if ($timestamp = Filesystem::getTimestamp($current_entry['path'] . '/entry.json')) {
|
||||
$_entries_ids .= 'entry:' . ltrim(rtrim(str_replace(PATH['entries'], '', $current_entry['path']), '/'), '/') . ' timestamp:' . $timestamp;
|
||||
} else {
|
||||
@@ -250,28 +249,26 @@ class Entries
|
||||
// Create unique entries $cache_id
|
||||
$cache_id = md5($_entries_ids .
|
||||
$bind_id .
|
||||
(($bind_recursive) ? 'true' : 'false') .
|
||||
(($bind_set_max_result) ? $bind_set_max_result : 'false') .
|
||||
(($bind_set_first_result) ? $bind_set_first_result : 'false') .
|
||||
(($bind_where['where']['key']) ? $bind_where['where']['key'] : 'false') .
|
||||
(($bind_where['where']['expr']) ? $bind_where['where']['expr'] : 'false') .
|
||||
(($bind_where['where']['value']) ? $bind_where['where']['value'] : 'false') .
|
||||
(($bind_and_where['and_where']['key']) ? $bind_and_where['and_where']['key'] : 'false') .
|
||||
(($bind_and_where['and_where']['expr']) ? $bind_and_where['and_where']['expr'] : 'false') .
|
||||
(($bind_and_where['and_where']['value']) ? $bind_and_where['and_where']['value'] : 'false') .
|
||||
(($bind_or_where['or_where']['key']) ? $bind_or_where['or_where']['key'] : 'false') .
|
||||
(($bind_or_where['or_where']['expr']) ? $bind_or_where['or_where']['expr'] : 'false') .
|
||||
(($bind_or_where['or_where']['value']) ? $bind_or_where['or_where']['value'] : 'false') .
|
||||
(($bind_order_by['order_by']['field']) ? $bind_order_by['order_by']['field'] : 'false') .
|
||||
(($bind_order_by['order_by']['direction']) ? $bind_order_by['order_by']['direction'] : 'false')
|
||||
);
|
||||
($bind_recursive ? 'true' : 'false') .
|
||||
($bind_set_max_result ? $bind_set_max_result : 'false') .
|
||||
($bind_set_first_result ? $bind_set_first_result : 'false') .
|
||||
($bind_where['where']['key'] ? $bind_where['where']['key'] : 'false') .
|
||||
($bind_where['where']['expr'] ? $bind_where['where']['expr'] : 'false') .
|
||||
($bind_where['where']['value'] ? $bind_where['where']['value'] : 'false') .
|
||||
($bind_and_where['and_where']['key'] ? $bind_and_where['and_where']['key'] : 'false') .
|
||||
($bind_and_where['and_where']['expr'] ? $bind_and_where['and_where']['expr'] : 'false') .
|
||||
($bind_and_where['and_where']['value'] ? $bind_and_where['and_where']['value'] : 'false') .
|
||||
($bind_or_where['or_where']['key'] ? $bind_or_where['or_where']['key'] : 'false') .
|
||||
($bind_or_where['or_where']['expr'] ? $bind_or_where['or_where']['expr'] : 'false') .
|
||||
($bind_or_where['or_where']['value'] ? $bind_or_where['or_where']['value'] : 'false') .
|
||||
($bind_order_by['order_by']['field'] ? $bind_order_by['order_by']['field'] : 'false') .
|
||||
($bind_order_by['order_by']['direction'] ? $bind_order_by['order_by']['direction'] : 'false'));
|
||||
|
||||
// If requested entries exist with 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 {
|
||||
|
||||
// Create entries array from entries list and ignore current requested entry
|
||||
foreach ($entries_list as $current_entry) {
|
||||
if (strpos($current_entry['path'], $bind_id . '/entry.json') !== false) {
|
||||
@@ -279,8 +276,7 @@ class Entries
|
||||
} 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')) {
|
||||
|
||||
if ($current_entry['type'] === 'dir' && Filesystem::has($current_entry['path'] . '/entry.json')) {
|
||||
// Get entry uid
|
||||
// 1. Remove entries path
|
||||
// 2. Remove left and right slashes
|
||||
@@ -357,10 +353,12 @@ class Entries
|
||||
/**
|
||||
* Rename entry.
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Entry id
|
||||
* @param string $new_id New entry id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function rename(string $id, string $new_id) : bool
|
||||
{
|
||||
@@ -370,10 +368,10 @@ class Entries
|
||||
/**
|
||||
* Update entry
|
||||
*
|
||||
* @param string $id Entry
|
||||
* @param array $data Data
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Entry
|
||||
* @param array $data Data
|
||||
* @return bool
|
||||
*/
|
||||
public function update(string $id, array $data) : bool
|
||||
{
|
||||
@@ -381,52 +379,52 @@ class Entries
|
||||
|
||||
if (Filesystem::has($entry_file)) {
|
||||
return Filesystem::write($entry_file, JsonParser::encode($data));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create entry
|
||||
*
|
||||
* @param string $id Entry id
|
||||
* @param array $data Data
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Entry id
|
||||
* @param array $data Data
|
||||
* @return bool
|
||||
*/
|
||||
public function create(string $id, array $data) : bool
|
||||
{
|
||||
$entry_dir = $this->_dir_location($id);
|
||||
|
||||
// Check if new entry directory exists
|
||||
if (!Filesystem::has($entry_dir)) {
|
||||
|
||||
if (! Filesystem::has($entry_dir)) {
|
||||
// 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
|
||||
if (!Filesystem::has($entry_file)) {
|
||||
if (! Filesystem::has($entry_file)) {
|
||||
return Filesystem::write($entry_file, JsonParser::encode($data));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete entry.
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Entry id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function delete(string $id) : bool
|
||||
{
|
||||
@@ -436,13 +434,15 @@ class Entries
|
||||
/**
|
||||
* Copy entry(s)
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Entry id
|
||||
* @param string $new_id New entry id
|
||||
* @param bool $recursive Recursive copy entries.
|
||||
* @param string $id Entry id
|
||||
* @param string $new_id New entry id
|
||||
* @param bool $recursive Recursive copy entries.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function copy(string $id, string $new_id, bool $recursive = false)
|
||||
public function copy(string $id, string $new_id, bool $recursive = false) : bool
|
||||
{
|
||||
return Filesystem::copy($this->_dir_location($id), $this->_dir_location($new_id), $recursive);
|
||||
}
|
||||
@@ -450,9 +450,9 @@ class Entries
|
||||
/**
|
||||
* Check whether entry exists.
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Entry
|
||||
* @return bool
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function has(string $id) : bool
|
||||
{
|
||||
@@ -462,9 +462,9 @@ class Entries
|
||||
/**
|
||||
* Helper method _file_location
|
||||
*
|
||||
* @access private
|
||||
* @param string $id Entry id
|
||||
* @return string
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _file_location(string $id) : string
|
||||
{
|
||||
@@ -474,9 +474,9 @@ class Entries
|
||||
/**
|
||||
* Helper method _dir_location
|
||||
*
|
||||
* @access private
|
||||
* @param string $id Entry id
|
||||
* @return string
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _dir_location(string $id) : string
|
||||
{
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -13,6 +12,8 @@
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use function count;
|
||||
use function rename;
|
||||
|
||||
class Fieldsets
|
||||
{
|
||||
@@ -34,9 +35,11 @@ class Fieldsets
|
||||
/**
|
||||
* Fetch fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Fieldset id
|
||||
*
|
||||
* @return array|false The entry contents or false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetch(string $id)
|
||||
{
|
||||
@@ -46,22 +49,23 @@ class Fieldsets
|
||||
if ($fieldset_body = Filesystem::read($fieldset_file)) {
|
||||
if ($fieldset_decoded = JsonParser::decode($fieldset_body)) {
|
||||
return $fieldset_decoded;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all fieldsets
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetchAll() : array
|
||||
{
|
||||
@@ -74,10 +78,12 @@ class Fieldsets
|
||||
// If there is any fieldsets file then go...
|
||||
if (count($_fieldsets) > 0) {
|
||||
foreach ($_fieldsets as $fieldset) {
|
||||
if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'json') {
|
||||
$fieldset_content = JsonParser::decode(Filesystem::read($fieldset['path']));
|
||||
$fieldsets[$fieldset['basename']] = $fieldset_content['title'];
|
||||
if ($fieldset['type'] !== 'file' || $fieldset['extension'] !== 'json') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldset_content = JsonParser::decode(Filesystem::read($fieldset['path']));
|
||||
$fieldsets[$fieldset['basename']] = $fieldset_content['title'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,10 +94,12 @@ class Fieldsets
|
||||
/**
|
||||
* Rename fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Fieldset id
|
||||
* @param string $new_id New fieldset id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function rename(string $id, string $new_id) : bool
|
||||
{
|
||||
@@ -101,10 +109,12 @@ class Fieldsets
|
||||
/**
|
||||
* Update fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Fieldset id
|
||||
* @param array $data Fieldset data to save
|
||||
* @param string $id Fieldset id
|
||||
* @param array $data Fieldset data to save
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function update(string $id, array $data) : bool
|
||||
{
|
||||
@@ -112,36 +122,40 @@ class Fieldsets
|
||||
|
||||
if (Filesystem::has($fieldset_file)) {
|
||||
return Filesystem::write($fieldset_file, JsonParser::encode($data));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Fieldset id
|
||||
* @param array $data Fieldset data to save
|
||||
* @param string $id Fieldset id
|
||||
* @param array $data Fieldset data to save
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function create(string $id, array $data) : bool
|
||||
{
|
||||
$fieldset_file = $this->_file_location($id);
|
||||
|
||||
if (!Filesystem::has($fieldset_file)) {
|
||||
if (! Filesystem::has($fieldset_file)) {
|
||||
return Filesystem::write($fieldset_file, JsonParser::encode($data));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Fieldset id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function delete(string $id) : bool
|
||||
{
|
||||
@@ -151,10 +165,12 @@ class Fieldsets
|
||||
/**
|
||||
* Copy fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Fieldset id
|
||||
* @param string $new_id New fieldset id
|
||||
* @param string $id Fieldset id
|
||||
* @param string $new_id New fieldset id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function copy(string $id, string $new_id) : bool
|
||||
{
|
||||
@@ -164,9 +180,11 @@ class Fieldsets
|
||||
/**
|
||||
* Check whether fieldset exists.
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Fieldset id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function has(string $id) : bool
|
||||
{
|
||||
@@ -177,7 +195,6 @@ class Fieldsets
|
||||
* Helper method _dir_location
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function _dir_location() : string
|
||||
{
|
||||
@@ -187,9 +204,9 @@ class Fieldsets
|
||||
/**
|
||||
* Helper method _file_location
|
||||
*
|
||||
* @access private
|
||||
* @param string $id Fieldsets id
|
||||
* @return string
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _file_location(string $id) : string
|
||||
{
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -12,9 +11,15 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\I18n\I18n;
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use RuntimeException;
|
||||
use function array_merge;
|
||||
use function count;
|
||||
use function filemtime;
|
||||
use function is_array;
|
||||
use function md5;
|
||||
|
||||
class Plugins
|
||||
{
|
||||
@@ -38,7 +43,7 @@ class Plugins
|
||||
public function __construct($flextype, $app)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
$this->locales = JsonParser::decode(Filesystem::read(ROOT_DIR . '/flextype/config/locales.json'));
|
||||
$this->locales = JsonParser::decode(Filesystem::read(ROOT_DIR . '/flextype/config/locales.json'));
|
||||
}
|
||||
|
||||
public function getLocales()
|
||||
@@ -50,7 +55,6 @@ class Plugins
|
||||
* Init Plugins
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
public function init($flextype, $app) : void
|
||||
{
|
||||
@@ -59,96 +63,103 @@ class Plugins
|
||||
|
||||
// Get Plugins List
|
||||
$_plugins_list = Filesystem::listContents(PATH['plugins']);
|
||||
$plugins_list = [];
|
||||
$plugins_list = [];
|
||||
|
||||
foreach($_plugins_list as $plugin) {
|
||||
if ($plugin['type'] == 'dir') {
|
||||
$plugins_list[] = $plugin;
|
||||
foreach ($_plugins_list as $plugin) {
|
||||
if ($plugin['type'] !== 'dir') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$plugins_list[] = $plugin;
|
||||
}
|
||||
|
||||
// Get plugins cache ID
|
||||
$plugins_cache_id = $this->getPluginsCacheID($plugins_list);
|
||||
|
||||
// If Plugins List isnt empty then create plugin cache ID
|
||||
if (is_array($plugins_list) && count($plugins_list) > 0) {
|
||||
if (! is_array($plugins_list) || count($plugins_list) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get plugins list from cache or scan plugins folder and create new plugins cache item
|
||||
if ($this->flextype['cache']->contains($plugins_cache_id)) {
|
||||
$this->flextype['registry']->set('plugins', $this->flextype['cache']->fetch($plugins_cache_id));
|
||||
} else {
|
||||
// Get plugins list from cache or scan plugins folder and create new plugins cache item
|
||||
if ($this->flextype['cache']->contains($plugins_cache_id)) {
|
||||
$this->flextype['registry']->set('plugins', $this->flextype['cache']->fetch($plugins_cache_id));
|
||||
} else {
|
||||
// If Plugins List isnt empty
|
||||
if (is_array($plugins_list) && count($plugins_list) > 0) {
|
||||
// Init plugin configs
|
||||
$_plugins_config = [];
|
||||
$plugin_settings = [];
|
||||
$plugin_config = [];
|
||||
|
||||
// If Plugins List isnt empty
|
||||
if (is_array($plugins_list) && count($plugins_list) > 0) {
|
||||
|
||||
// Init plugin configs
|
||||
$_plugins_config = [];
|
||||
$plugin_settings = [];
|
||||
$plugin_config = [];
|
||||
|
||||
// Go through...
|
||||
foreach ($plugins_list as $plugin) {
|
||||
if (Filesystem::has($_plugin_settings = PATH['plugins'] . '/' . $plugin['dirname'] . '/settings.json')) {
|
||||
if (($content = Filesystem::read($_plugin_settings)) === false) {
|
||||
throw new \RuntimeException('Load file: ' . $_plugin_settings . ' - failed!');
|
||||
} else {
|
||||
$plugin_settings = JsonParser::decode($content);
|
||||
}
|
||||
// Go through...
|
||||
foreach ($plugins_list as $plugin) {
|
||||
if (Filesystem::has($_plugin_settings = PATH['plugins'] . '/' . $plugin['dirname'] . '/settings.json')) {
|
||||
if (($content = Filesystem::read($_plugin_settings)) === false) {
|
||||
throw new RuntimeException('Load file: ' . $_plugin_settings . ' - failed!');
|
||||
}
|
||||
|
||||
if (Filesystem::has($_plugin_config = PATH['plugins'] . '/' . $plugin['dirname'] . '/plugin.json')) {
|
||||
if (($content = Filesystem::read($_plugin_config)) === false) {
|
||||
throw new \RuntimeException('Load file: ' . $_plugin_config . ' - failed!');
|
||||
} else {
|
||||
$plugin_config = JsonParser::decode($content);
|
||||
}
|
||||
}
|
||||
|
||||
$_plugins_config[$plugin['dirname']] = array_merge($plugin_settings, $plugin_config);
|
||||
|
||||
// Set default plugin priority 0
|
||||
if (!isset($_plugins_config[$plugin['dirname']]['priority'])) {
|
||||
$_plugins_config[$plugin['dirname']]['priority'] = 0;
|
||||
}
|
||||
$plugin_settings = JsonParser::decode($content);
|
||||
}
|
||||
|
||||
// Sort plugins list by priority.
|
||||
$_plugins_config = Arr::sort($_plugins_config, 'priority', 'DESC');
|
||||
if (Filesystem::has($_plugin_config = PATH['plugins'] . '/' . $plugin['dirname'] . '/plugin.json')) {
|
||||
if (($content = Filesystem::read($_plugin_config)) === false) {
|
||||
throw new RuntimeException('Load file: ' . $_plugin_config . ' - failed!');
|
||||
}
|
||||
|
||||
$this->flextype['registry']->set('plugins', $_plugins_config);
|
||||
$this->flextype['cache']->save($plugins_cache_id, $_plugins_config);
|
||||
$plugin_config = JsonParser::decode($content);
|
||||
}
|
||||
|
||||
$_plugins_config[$plugin['dirname']] = array_merge($plugin_settings, $plugin_config);
|
||||
|
||||
// Set default plugin priority 0
|
||||
if (isset($_plugins_config[$plugin['dirname']]['priority'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$_plugins_config[$plugin['dirname']]['priority'] = 0;
|
||||
}
|
||||
|
||||
// Sort plugins list by priority.
|
||||
$_plugins_config = Arr::sort($_plugins_config, 'priority', 'DESC');
|
||||
|
||||
$this->flextype['registry']->set('plugins', $_plugins_config);
|
||||
$this->flextype['cache']->save($plugins_cache_id, $_plugins_config);
|
||||
}
|
||||
|
||||
$this->createPluginsDictionary($plugins_list);
|
||||
|
||||
$this->includeEnabledPlugins($flextype, $app);
|
||||
|
||||
$this->flextype['emitter']->emit('onPluginsInitialized');
|
||||
}
|
||||
|
||||
$this->createPluginsDictionary($plugins_list);
|
||||
|
||||
$this->includeEnabledPlugins($flextype, $app);
|
||||
|
||||
$this->flextype['emitter']->emit('onPluginsInitialized');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create plugins dictionary
|
||||
*
|
||||
* @param array $plugins_list Plugins list
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
private function createPluginsDictionary(array $plugins_list) : void
|
||||
{
|
||||
if (is_array($plugins_list) && count($plugins_list) > 0) {
|
||||
foreach ($this->locales as $locale => $locale_title) {
|
||||
foreach ($plugins_list as $plugin) {
|
||||
$language_file = PATH['plugins'] . '/' . $plugin['dirname'] . '/lang/' . $locale . '.json';
|
||||
if (Filesystem::has($language_file)) {
|
||||
if (($content = Filesystem::read($language_file)) === false) {
|
||||
throw new \RuntimeException('Load file: ' . $language_file . ' - failed!');
|
||||
} else {
|
||||
I18n::add(JsonParser::decode($content), $locale);
|
||||
}
|
||||
}
|
||||
if (! is_array($plugins_list) || count($plugins_list) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->locales as $locale => $locale_title) {
|
||||
foreach ($plugins_list as $plugin) {
|
||||
$language_file = PATH['plugins'] . '/' . $plugin['dirname'] . '/lang/' . $locale . '.json';
|
||||
if (! Filesystem::has($language_file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($content = Filesystem::read($language_file)) === false) {
|
||||
throw new RuntimeException('Load file: ' . $language_file . ' - failed!');
|
||||
}
|
||||
|
||||
I18n::add(JsonParser::decode($content), $locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,8 +168,8 @@ class Plugins
|
||||
* Get plugins cache ID
|
||||
*
|
||||
* @param array $plugins_list Plugins list
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
private function getPluginsCacheID(array $plugins_list) : string
|
||||
{
|
||||
@@ -168,10 +179,12 @@ class Plugins
|
||||
// Go through...
|
||||
if (is_array($plugins_list) && count($plugins_list) > 0) {
|
||||
foreach ($plugins_list as $plugin) {
|
||||
if (Filesystem::has($_plugin_settings = PATH['plugins'] . '/' . $plugin['dirname'] . '/settings.json') and
|
||||
Filesystem::has($_plugin_config = PATH['plugins'] . '/' . $plugin['dirname'] . '/plugin.json')) {
|
||||
$_plugins_cache_id .= filemtime($_plugin_settings) . filemtime($_plugin_config);
|
||||
if (! Filesystem::has($_plugin_settings = PATH['plugins'] . '/' . $plugin['dirname'] . '/settings.json') or
|
||||
! Filesystem::has($_plugin_config = PATH['plugins'] . '/' . $plugin['dirname'] . '/plugin.json')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$_plugins_cache_id .= filemtime($_plugin_settings) . filemtime($_plugin_config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,16 +199,19 @@ class Plugins
|
||||
* Include enabled plugins
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
private function includeEnabledPlugins($flextype, $app) : void
|
||||
{
|
||||
if (is_array($this->flextype['registry']->get('plugins')) && count($this->flextype['registry']->get('plugins')) > 0) {
|
||||
foreach ($this->flextype['registry']->get('plugins') as $plugin_name => $plugin) {
|
||||
if ($this->flextype['registry']->get('plugins.' . $plugin_name . '.enabled')) {
|
||||
include_once PATH['plugins'] . '/' . $plugin_name . '/bootstrap.php';
|
||||
}
|
||||
if (! is_array($this->flextype['registry']->get('plugins')) || count($this->flextype['registry']->get('plugins')) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->flextype['registry']->get('plugins') as $plugin_name => $plugin) {
|
||||
if (! $this->flextype['registry']->get('plugins.' . $plugin_name . '.enabled')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
include_once PATH['plugins'] . '/' . $plugin_name . '/bootstrap.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -13,6 +12,13 @@
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use RuntimeException;
|
||||
use const EXTR_PREFIX_ALL;
|
||||
use function count;
|
||||
use function extract;
|
||||
use function ob_get_clean;
|
||||
use function ob_start;
|
||||
use function rename;
|
||||
|
||||
class Snippets
|
||||
{
|
||||
@@ -34,16 +40,18 @@ class Snippets
|
||||
public function __construct($flextype, $app)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
$this->app = $app;
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec snippet
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
* @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.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function exec(string $id)
|
||||
{
|
||||
@@ -53,9 +61,11 @@ class Snippets
|
||||
/**
|
||||
* Fetch snippet
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
*
|
||||
* @return string|false The snippet contents or false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetch(string $id)
|
||||
{
|
||||
@@ -64,19 +74,20 @@ class Snippets
|
||||
if (Filesystem::has($snippet_file)) {
|
||||
if ($snippet_body = Filesystem::read($snippet_file)) {
|
||||
return $snippet_body;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Snippets
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function fetchAll() : array
|
||||
{
|
||||
@@ -88,9 +99,11 @@ class Snippets
|
||||
// If there is any snippets file then go...
|
||||
if (count($_snippets) > 0) {
|
||||
foreach ($_snippets as $snippet) {
|
||||
if ($snippet['type'] == 'file' && $snippet['extension'] == 'php') {
|
||||
$snippets[$snippet['basename']] = $snippet['basename'];
|
||||
if ($snippet['type'] !== 'file' || $snippet['extension'] !== 'php') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$snippets[$snippet['basename']] = $snippet['basename'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,10 +114,12 @@ class Snippets
|
||||
/**
|
||||
* Rename snippet
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
* @param string $new_id New snippet id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function rename(string $id, string $new_id) : bool
|
||||
{
|
||||
@@ -114,10 +129,12 @@ class Snippets
|
||||
/**
|
||||
* Update Snippet
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
* @param string $data Data
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function update(string $id, string $data) : bool
|
||||
{
|
||||
@@ -125,37 +142,41 @@ class Snippets
|
||||
|
||||
if (Filesystem::has($snippet_file)) {
|
||||
return Filesystem::write($snippet_file, $data);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create snippet
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
* @param string $data Data
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function create(string $id, string $data = '') : bool
|
||||
{
|
||||
$snippet_file = $this->_file_location($id);
|
||||
|
||||
// Check if new entry file exists
|
||||
if (!Filesystem::has($snippet_file)) {
|
||||
if (! Filesystem::has($snippet_file)) {
|
||||
return Filesystem::write($snippet_file, $data);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete snippet.
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function delete(string $id) : bool
|
||||
{
|
||||
@@ -165,10 +186,12 @@ class Snippets
|
||||
/**
|
||||
* Copy snippet
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
* @param string $new_id New snippet id
|
||||
* @param string $id Snippet id
|
||||
* @param string $new_id New snippet id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function copy(string $id, string $new_id) : bool
|
||||
{
|
||||
@@ -178,9 +201,11 @@ class Snippets
|
||||
/**
|
||||
* Check whether snippet exists.
|
||||
*
|
||||
* @access public
|
||||
* @param string $id Snippet id
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function has(string $id) : bool
|
||||
{
|
||||
@@ -190,10 +215,12 @@ class Snippets
|
||||
/**
|
||||
* Helper private method _exec_snippet
|
||||
*
|
||||
* @access private
|
||||
* @param array $vars Vars
|
||||
* @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.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _exec_snippet(array $vars)
|
||||
{
|
||||
@@ -208,7 +235,6 @@ class Snippets
|
||||
|
||||
// Process snippet
|
||||
if (Filesystem::has($snippet_file)) {
|
||||
|
||||
// Turn on output buffering
|
||||
ob_start();
|
||||
|
||||
@@ -223,17 +249,17 @@ class Snippets
|
||||
|
||||
// Output...
|
||||
return ob_get_clean();
|
||||
} else {
|
||||
throw new \RuntimeException("Snippet {$snippet_id} does not exist.");
|
||||
}
|
||||
|
||||
throw new RuntimeException("Snippet {$snippet_id} does not exist.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method _file_location
|
||||
*
|
||||
* @access private
|
||||
* @param string $id Snippet id
|
||||
* @return string
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _file_location(string $id) : string
|
||||
{
|
||||
@@ -244,7 +270,6 @@ class Snippets
|
||||
* Helper method _dir_location
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function _dir_location() : string
|
||||
{
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -13,6 +12,12 @@
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use RuntimeException;
|
||||
use function array_merge;
|
||||
use function count;
|
||||
use function filemtime;
|
||||
use function is_array;
|
||||
use function md5;
|
||||
|
||||
class Themes
|
||||
{
|
||||
@@ -34,7 +39,7 @@ class Themes
|
||||
/**
|
||||
* Init themes
|
||||
*/
|
||||
public function init($flextype, $app)
|
||||
public function init($flextype, $app) : void
|
||||
{
|
||||
// Set empty themes list item
|
||||
$this->flextype['registry']->set('themes', []);
|
||||
@@ -44,7 +49,6 @@ class Themes
|
||||
|
||||
// If themes list isnt empty then create themes cache ID and go through the themes list...
|
||||
if (is_array($themes_list) && count($themes_list) > 0) {
|
||||
|
||||
// Get themes cache ID
|
||||
$themes_cache_id = $this->getThemesCacheID($themes_list);
|
||||
|
||||
@@ -52,31 +56,29 @@ class Themes
|
||||
if ($this->flextype['cache']->contains($themes_cache_id)) {
|
||||
$this->flextype['registry']->set('themes', $this->flextype['cache']->fetch($themes_cache_id));
|
||||
} else {
|
||||
|
||||
// Go through the themes list...
|
||||
foreach ($themes_list as $theme) {
|
||||
|
||||
// Get theme settings
|
||||
if (Filesystem::has($theme_settings_file = PATH['themes'] . '/' . $theme['dirname'] . '/settings.json')) {
|
||||
if (($content = Filesystem::read($theme_settings_file)) === false) {
|
||||
throw new \RuntimeException('Load file: ' . $theme_settings_file . ' - failed!');
|
||||
} else {
|
||||
$theme_settings = JsonParser::decode($content);
|
||||
}
|
||||
foreach ($themes_list as $theme) {
|
||||
// Get theme settings
|
||||
if (Filesystem::has($theme_settings_file = PATH['themes'] . '/' . $theme['dirname'] . '/settings.json')) {
|
||||
if (($content = Filesystem::read($theme_settings_file)) === false) {
|
||||
throw new RuntimeException('Load file: ' . $theme_settings_file . ' - failed!');
|
||||
}
|
||||
|
||||
// Get theme manifest
|
||||
if (Filesystem::has($theme_manifest_file = PATH['themes'] . '/' . $theme['dirname'] . '/theme.json')) {
|
||||
if (($content = Filesystem::read($theme_manifest_file)) === false) {
|
||||
throw new \RuntimeException('Load file: ' . $theme_manifest_file . ' - failed!');
|
||||
} else {
|
||||
$theme_manifest = JsonParser::decode($content);
|
||||
}
|
||||
}
|
||||
|
||||
$themes[$theme['dirname']] = array_merge($theme_settings, $theme_manifest);
|
||||
$theme_settings = JsonParser::decode($content);
|
||||
}
|
||||
|
||||
// Get theme manifest
|
||||
if (Filesystem::has($theme_manifest_file = PATH['themes'] . '/' . $theme['dirname'] . '/theme.json')) {
|
||||
if (($content = Filesystem::read($theme_manifest_file)) === false) {
|
||||
throw new RuntimeException('Load file: ' . $theme_manifest_file . ' - failed!');
|
||||
}
|
||||
|
||||
$theme_manifest = JsonParser::decode($content);
|
||||
}
|
||||
|
||||
$themes[$theme['dirname']] = array_merge($theme_settings, $theme_manifest);
|
||||
}
|
||||
|
||||
// Save parsed themes list in the registry themes
|
||||
$this->flextype['registry']->set('themes', $themes);
|
||||
|
||||
@@ -89,13 +91,12 @@ class Themes
|
||||
$this->flextype['emitter']->emit('onThemesInitialized');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get themes cache ID
|
||||
*
|
||||
* @param array $themes_list Themes list
|
||||
*
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
private function getThemesCacheID(array $themes_list) : string
|
||||
{
|
||||
@@ -105,10 +106,12 @@ class Themes
|
||||
// Go through themes list...
|
||||
if (is_array($themes_list) && count($themes_list) > 0) {
|
||||
foreach ($themes_list as $theme) {
|
||||
if (Filesystem::has($_themes_settings = PATH['themes'] . '/' . $theme['dirname'] . '/settings.json') and
|
||||
Filesystem::has($_themes_manifest = PATH['themes'] . '/' . $theme['dirname'] . '/plugin.json')) {
|
||||
$_themes_cache_id .= filemtime($_themes_settings) . filemtime($_themes_manifest);
|
||||
if (! Filesystem::has($_themes_settings = PATH['themes'] . '/' . $theme['dirname'] . '/settings.json') or
|
||||
! Filesystem::has($_themes_manifest = PATH['themes'] . '/' . $theme['dirname'] . '/plugin.json')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$_themes_cache_id .= filemtime($_themes_settings) . filemtime($_themes_manifest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,12 +122,12 @@ class Themes
|
||||
return $themes_cache_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of themes
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getThemes() : array
|
||||
{
|
||||
@@ -135,10 +138,12 @@ class Themes
|
||||
$_themes_list = Filesystem::listContents(PATH['themes']);
|
||||
|
||||
// Go through founded themes
|
||||
foreach($_themes_list as $theme) {
|
||||
if ($theme['type'] == 'dir' && Filesystem::has($theme['path'] . '/' . 'theme.json')) {
|
||||
$themes_list[] = $theme;
|
||||
foreach ($_themes_list as $theme) {
|
||||
if ($theme['type'] !== 'dir' || ! Filesystem::has($theme['path'] . '/' . 'theme.json')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$themes_list[] = $theme;
|
||||
}
|
||||
|
||||
return $themes_list;
|
||||
@@ -147,9 +152,11 @@ class Themes
|
||||
/**
|
||||
* Get partials for theme
|
||||
*
|
||||
* @access public
|
||||
* @param string $theme Theme id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getPartials(string $theme) : array
|
||||
{
|
||||
@@ -162,9 +169,11 @@ class Themes
|
||||
// If there is any partials file then go...
|
||||
if (count($_partials_list) > 0) {
|
||||
foreach ($_partials_list as $partial) {
|
||||
if ($partial['type'] == 'file' && $partial['extension'] == 'html') {
|
||||
$partials_list[] = $partial;
|
||||
if ($partial['type'] !== 'file' || $partial['extension'] !== 'html') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$partials_list[] = $partial;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,9 +184,11 @@ class Themes
|
||||
/**
|
||||
* Get templates for theme
|
||||
*
|
||||
* @access public
|
||||
* @param string $theme Theme id
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getTemplates(string $theme) : array
|
||||
{
|
||||
@@ -190,9 +201,11 @@ class Themes
|
||||
// If there is any template file then go...
|
||||
if (count($_templates_list) > 0) {
|
||||
foreach ($_templates_list as $template) {
|
||||
if ($template['type'] == 'file' && $template['extension'] == 'html') {
|
||||
$templates_list[] = $template;
|
||||
if ($template['type'] !== 'file' || $template['extension'] !== 'html') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$templates_list[] = $template;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -12,10 +11,10 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Thunder\Shortcode\ShortcodeFacade;
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
use Slim\Http\Environment;
|
||||
use Slim\Http\Uri;
|
||||
|
||||
// Shortcode: [base_url]
|
||||
$flextype['shortcodes']->addHandler('base_url', function () {
|
||||
return \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER))->getBaseUrl();
|
||||
$flextype['shortcodes']->addHandler('base_url', static function () {
|
||||
return Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
|
||||
});
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -12,11 +11,10 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Thunder\Shortcode\ShortcodeFacade;
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
|
||||
// Shortcode: [entries_fetch id="entry-id" field="field-name" default="default-value"]
|
||||
$flextype['shortcodes']->addHandler('entries_fetch', function (ShortcodeInterface $s) use ($flextype) {
|
||||
$flextype['shortcodes']->addHandler('entries_fetch', static function (ShortcodeInterface $s) use ($flextype) {
|
||||
return Arr::get($flextype['entries']->fetch($s->getParameter('id')), $s->getParameter('field'), $s->getParameter('default'));
|
||||
});
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -12,10 +11,9 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Thunder\Shortcode\ShortcodeFacade;
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
|
||||
// Shortcode: [registry_get name="item-name" default="default-value"]
|
||||
$flextype['shortcodes']->addHandler('registry_get', function (ShortcodeInterface $s) use ($flextype) {
|
||||
$flextype['shortcodes']->addHandler('registry_get', static function (ShortcodeInterface $s) use ($flextype) {
|
||||
return $flextype['registry']->get($s->getParameter('name'), $s->getParameter('default'));
|
||||
});
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -12,10 +11,9 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Thunder\Shortcode\ShortcodeFacade;
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
|
||||
// Shortcode: [snippets_exec id="snippet-name"]
|
||||
$flextype['shortcodes']->addHandler('snippets_exec', function (ShortcodeInterface $s) use ($flextype) {
|
||||
$flextype['shortcodes']->addHandler('snippets_exec', static function (ShortcodeInterface $s) use ($flextype) {
|
||||
return $flextype['snippets']->exec($s->getParameter('id'));
|
||||
});
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
@@ -15,8 +17,6 @@ class DashboardController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
|
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use Flextype\Component\Text\Text;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Respect\Validation\Validator as v;
|
||||
use function date;
|
||||
use function Flextype\Component\I18n\__;
|
||||
|
||||
/**
|
||||
* @property View $view
|
||||
@@ -22,23 +24,23 @@ class FieldsetsController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/fieldsets/index.html',
|
||||
[
|
||||
'menu_item' => 'fieldsets',
|
||||
'fieldsets_list' => $this->fieldsets->fetchAll(),
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
'title' => __('admin_fieldsets'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'fieldsets_add' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.add'),
|
||||
'title' => __('admin_create_new_fieldset'),
|
||||
'attributes' => ['class' => 'float-right btn']
|
||||
]
|
||||
]
|
||||
]
|
||||
'menu_item' => 'fieldsets',
|
||||
'fieldsets_list' => $this->fieldsets->fetchAll(),
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
'title' => __('admin_fieldsets'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'fieldsets_add' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.add'),
|
||||
'title' => __('admin_create_new_fieldset'),
|
||||
'attributes' => ['class' => 'float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,21 +50,21 @@ class FieldsetsController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/fieldsets/add.html',
|
||||
[
|
||||
'menu_item' => 'fieldsets',
|
||||
'fieldsets_list' => $this->fieldsets->fetchAll(),
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
'title' => __('admin_fieldsets'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'fieldsets_add' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.add'),
|
||||
'title' => __('admin_create_new_fieldset'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
]
|
||||
],
|
||||
]
|
||||
'menu_item' => 'fieldsets',
|
||||
'fieldsets_list' => $this->fieldsets->fetchAll(),
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
'title' => __('admin_fieldsets'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'fieldsets_add' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.add'),
|
||||
'title' => __('admin_create_new_fieldset'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,7 +75,7 @@ class FieldsetsController extends Controller
|
||||
Arr::delete($data, 'csrf_name');
|
||||
Arr::delete($data, 'csrf_value');
|
||||
|
||||
$id = $this->slugify->slugify($data['id']);
|
||||
$id = $this->slugify->slugify($data['id']);
|
||||
$data = ['title' => $data['title']];
|
||||
|
||||
if ($this->fieldsets->create($id, $data)) {
|
||||
@@ -91,39 +93,38 @@ class FieldsetsController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/fieldsets/edit.html',
|
||||
[
|
||||
'menu_item' => 'fieldsets',
|
||||
'id' => $request->getQueryParams()['id'],
|
||||
'data' => JsonParser::encode($this->fieldsets->fetch($request->getQueryParams()['id'])),
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
'title' => __('admin_fieldsets'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'fieldsets_editor' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.edit') . '?id=' . $request->getQueryParams()['id'],
|
||||
'title' => __('admin_editor'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'save_entry' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn']
|
||||
],
|
||||
]
|
||||
]
|
||||
'menu_item' => 'fieldsets',
|
||||
'id' => $request->getQueryParams()['id'],
|
||||
'data' => JsonParser::encode($this->fieldsets->fetch($request->getQueryParams()['id'])),
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
'title' => __('admin_fieldsets'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'fieldsets_editor' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.edit') . '?id=' . $request->getQueryParams()['id'],
|
||||
'title' => __('admin_editor'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'save_entry' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function editProcess($request, $response)
|
||||
{
|
||||
$id = $request->getParsedBody()['id'];
|
||||
$id = $request->getParsedBody()['id'];
|
||||
$data = $request->getParsedBody()['data'];
|
||||
|
||||
if (v::json()->validate($data)) {
|
||||
|
||||
if ($this->fieldsets->update($request->getParsedBody()['id'], JsonParser::decode($data))) {
|
||||
$this->flash->addMessage('success', __('admin_message_fieldset_saved'));
|
||||
} else {
|
||||
@@ -131,11 +132,11 @@ class FieldsetsController extends Controller
|
||||
}
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.fieldsets.edit') . '?id=' . $id);
|
||||
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_json_invalid'));
|
||||
return $response->withRedirect($this->router->pathFor('admin.fieldsets.edit') . '?id=' . $id);
|
||||
}
|
||||
|
||||
$this->flash->addMessage('error', __('admin_message_json_invalid'));
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.fieldsets.edit') . '?id=' . $id);
|
||||
}
|
||||
|
||||
public function rename($request, $response)
|
||||
@@ -144,21 +145,21 @@ class FieldsetsController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/fieldsets/rename.html',
|
||||
[
|
||||
'menu_item' => 'fieldsets',
|
||||
'id' => $request->getQueryParams()['id'],
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
'title' => __('admin_fieldsets'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'fieldsets_rename' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.rename') . '?id=' . $request->getQueryParams()['id'],
|
||||
'title' => __('admin_rename'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
]
|
||||
'menu_item' => 'fieldsets',
|
||||
'id' => $request->getQueryParams()['id'],
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
'title' => __('admin_fieldsets'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'fieldsets_rename' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.rename') . '?id=' . $request->getQueryParams()['id'],
|
||||
'title' => __('admin_rename'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -186,7 +187,7 @@ class FieldsetsController extends Controller
|
||||
|
||||
public function duplicateProcess($request, $response)
|
||||
{
|
||||
if ($this->fieldsets->copy($request->getParsedBody()['fieldset-id'], $request->getParsedBody()['fieldset-id'] . '-duplicate-' . date("Ymd_His"))) {
|
||||
if ($this->fieldsets->copy($request->getParsedBody()['fieldset-id'], $request->getParsedBody()['fieldset-id'] . '-duplicate-' . date('Ymd_His'))) {
|
||||
$this->flash->addMessage('success', __('admin_message_fieldset_duplicated'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_fieldset_was_not_duplicated'));
|
||||
|
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Date\Date;
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function Flextype\Component\I18n\__;
|
||||
|
||||
/**
|
||||
* @property View $view
|
||||
@@ -22,8 +23,6 @@ class PluginsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -31,23 +30,23 @@ class PluginsController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/plugins/index.html',
|
||||
[
|
||||
'plugins_list' => $this->registry->get('plugins'),
|
||||
'menu_item' => 'plugins',
|
||||
'links' => [
|
||||
'plugins' => [
|
||||
'link' => $this->router->pathFor('admin.plugins.index'),
|
||||
'title' => __('admin_plugins'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'plugins_get_more' => [
|
||||
'link' => 'https://github.com/flextype/plugins',
|
||||
'title' => __('admin_get_more_plugins'),
|
||||
'attributes' => ['class' => 'float-right btn', 'target' => '_blank']
|
||||
],
|
||||
]
|
||||
]
|
||||
'plugins_list' => $this->registry->get('plugins'),
|
||||
'menu_item' => 'plugins',
|
||||
'links' => [
|
||||
'plugins' => [
|
||||
'link' => $this->router->pathFor('admin.plugins.index'),
|
||||
'title' => __('admin_plugins'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'plugins_get_more' => [
|
||||
'link' => 'https://github.com/flextype/plugins',
|
||||
'title' => __('admin_get_more_plugins'),
|
||||
'attributes' => ['class' => 'float-right btn', 'target' => '_blank'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -56,8 +55,6 @@ class PluginsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function pluginStatusProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -66,7 +63,7 @@ class PluginsController extends Controller
|
||||
|
||||
// Update settings
|
||||
$plugin_settings = JsonParser::decode(Filesystem::read(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.json'));
|
||||
Arr::set($plugin_settings, 'enabled', ($data['plugin-status'] == 'true' ? true : false));
|
||||
Arr::set($plugin_settings, 'enabled', ($data['plugin-status'] === 'true'));
|
||||
Filesystem::write(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.json', JsonParser::encode($plugin_settings));
|
||||
|
||||
// Clear doctrine cache
|
||||
|
@@ -1,13 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Date\Date;
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Flextype\Component\Date\Date;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function array_merge;
|
||||
use function Flextype\Component\I18n\__;
|
||||
|
||||
/**
|
||||
* @property View $view
|
||||
@@ -25,8 +28,6 @@ class SettingsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -37,71 +38,81 @@ class SettingsController extends Controller
|
||||
|
||||
$themes = [];
|
||||
foreach (Filesystem::listContents(PATH['themes']) as $theme) {
|
||||
if ($theme['type'] == 'dir' && Filesystem::has($theme['path'] . '/' . 'theme.json')) {
|
||||
$themes[$theme['dirname']] = $theme['dirname'];
|
||||
if ($theme['type'] !== 'dir' || ! Filesystem::has($theme['path'] . '/' . 'theme.json')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$themes[$theme['dirname']] = $theme['dirname'];
|
||||
}
|
||||
|
||||
$available_locales = Filesystem::listContents(PATH['plugins'] . '/admin/lang/');
|
||||
$system_locales = $this->plugins->getLocales();
|
||||
$locales = [];
|
||||
$system_locales = $this->plugins->getLocales();
|
||||
$locales = [];
|
||||
foreach ($available_locales as $locale) {
|
||||
if ($locale['type'] == 'file' && $locale['extension'] == 'json') {
|
||||
$locales[$locale['basename']] = $system_locales[$locale['basename']]['nativeName'];
|
||||
if ($locale['type'] !== 'file' || $locale['extension'] !== 'json') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$locales[$locale['basename']] = $system_locales[$locale['basename']]['nativeName'];
|
||||
}
|
||||
|
||||
$cache_driver = ['auto' => 'Auto Detect',
|
||||
'file' => 'File',
|
||||
'apcu' => 'APCu',
|
||||
'wincache' => 'WinCache',
|
||||
'memcached' => 'Memcached',
|
||||
'redis' => 'Redis',
|
||||
'sqlite3' => 'SQLite3',
|
||||
'zend' => 'Zend',
|
||||
'array' => 'Array'];
|
||||
$cache_driver = [
|
||||
'auto' => 'Auto Detect',
|
||||
'file' => 'File',
|
||||
'apcu' => 'APCu',
|
||||
'wincache' => 'WinCache',
|
||||
'memcached' => 'Memcached',
|
||||
'redis' => 'Redis',
|
||||
'sqlite3' => 'SQLite3',
|
||||
'zend' => 'Zend',
|
||||
'array' => 'Array',
|
||||
];
|
||||
|
||||
$image_driver = ['gd' => 'gd',
|
||||
'imagick' => 'imagick'];
|
||||
$image_driver = [
|
||||
'gd' => 'gd',
|
||||
'imagick' => 'imagick',
|
||||
];
|
||||
|
||||
$whoops_editor = ['emacs' => 'Emacs',
|
||||
'idea' => 'IDEA',
|
||||
'macvim' => 'MacVim',
|
||||
'phpstorm' => 'PhpStorm (macOS only)',
|
||||
'sublime' => 'Sublime Text',
|
||||
'textmate' => 'Textmate',
|
||||
'xdebug' => 'xDebug',
|
||||
'vscode' => 'VSCode',
|
||||
'atom' => 'Atom',
|
||||
'espresso' => 'Espresso'];
|
||||
$whoops_editor = [
|
||||
'emacs' => 'Emacs',
|
||||
'idea' => 'IDEA',
|
||||
'macvim' => 'MacVim',
|
||||
'phpstorm' => 'PhpStorm (macOS only)',
|
||||
'sublime' => 'Sublime Text',
|
||||
'textmate' => 'Textmate',
|
||||
'xdebug' => 'xDebug',
|
||||
'vscode' => 'VSCode',
|
||||
'atom' => 'Atom',
|
||||
'espresso' => 'Espresso',
|
||||
];
|
||||
|
||||
return $this->view->render(
|
||||
$response,
|
||||
'plugins/admin/views/templates/system/settings/index.html',
|
||||
[
|
||||
'timezones' => Date::timezones(),
|
||||
'cache_driver' => $cache_driver,
|
||||
'locales' => $locales,
|
||||
'entries' => $entries,
|
||||
'themes' => $themes,
|
||||
'image_driver' => $image_driver,
|
||||
'whoops_editor' => $whoops_editor,
|
||||
'menu_item' => 'settings',
|
||||
'links' => [
|
||||
'settings' => [
|
||||
'link' => $this->router->pathFor('admin.settings.index'),
|
||||
'title' => __('admin_settings'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
]
|
||||
],
|
||||
'buttons' => [
|
||||
'save' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn']
|
||||
]
|
||||
]
|
||||
]
|
||||
'timezones' => Date::timezones(),
|
||||
'cache_driver' => $cache_driver,
|
||||
'locales' => $locales,
|
||||
'entries' => $entries,
|
||||
'themes' => $themes,
|
||||
'image_driver' => $image_driver,
|
||||
'whoops_editor' => $whoops_editor,
|
||||
'menu_item' => 'settings',
|
||||
'links' => [
|
||||
'settings' => [
|
||||
'link' => $this->router->pathFor('admin.settings.index'),
|
||||
'title' => __('admin_settings'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'save' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -110,8 +121,6 @@ class SettingsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function updateSettingsProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -121,12 +130,12 @@ class SettingsController extends Controller
|
||||
Arr::delete($data, 'csrf_value');
|
||||
Arr::delete($data, 'action');
|
||||
|
||||
Arr::set($data, 'errors.display', ($data['errors']['display'] == '1' ? true : false));
|
||||
Arr::set($data, 'cache.enabled', ($data['cache']['enabled'] == '1' ? true : false));
|
||||
Arr::set($data, 'slugify.lowercase_after_regexp', ($data['slugify']['lowercase_after_regexp'] == '1' ? true : false));
|
||||
Arr::set($data, 'slugify.strip_tags', ($data['slugify']['strip_tags'] == '1' ? true : false));
|
||||
Arr::set($data, 'slugify.trim', ($data['slugify']['trim'] == '1' ? true : false));
|
||||
Arr::set($data, 'slugify.lowercase', ($data['slugify']['lowercase'] == '1' ? true : false));
|
||||
Arr::set($data, 'errors.display', ($data['errors']['display'] === '1'));
|
||||
Arr::set($data, 'cache.enabled', ($data['cache']['enabled'] === '1'));
|
||||
Arr::set($data, 'slugify.lowercase_after_regexp', ($data['slugify']['lowercase_after_regexp'] === '1'));
|
||||
Arr::set($data, 'slugify.strip_tags', ($data['slugify']['strip_tags'] === '1'));
|
||||
Arr::set($data, 'slugify.trim', ($data['slugify']['trim'] === '1'));
|
||||
Arr::set($data, 'slugify.lowercase', ($data['slugify']['lowercase'] === '1'));
|
||||
Arr::set($data, 'cache.lifetime', (int) $data['cache']['lifetime']);
|
||||
Arr::set($data, 'entries.media.upload_images_quality', (int) $data['entries']['media']['upload_images_quality']);
|
||||
Arr::set($data, 'entries.media.upload_images_width', (int) $data['entries']['media']['upload_images_width']);
|
||||
@@ -140,5 +149,4 @@ class SettingsController extends Controller
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.settings.index'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Text\Text;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function date;
|
||||
use function Flextype\Component\I18n\__;
|
||||
|
||||
/**
|
||||
* @property View $view
|
||||
@@ -22,8 +23,6 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -31,23 +30,23 @@ class SnippetsController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/snippets/index.html',
|
||||
[
|
||||
'menu_item' => 'snippets',
|
||||
'snippets_list' => $this->snippets->fetchAll(),
|
||||
'links' => [
|
||||
'snippets' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.index'),
|
||||
'title' => __('admin_snippets'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'snippets_create' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.add'),
|
||||
'title' => __('admin_create_new_snippet'),
|
||||
'attributes' => ['class' => 'float-right btn']
|
||||
],
|
||||
]
|
||||
]
|
||||
'menu_item' => 'snippets',
|
||||
'snippets_list' => $this->snippets->fetchAll(),
|
||||
'links' => [
|
||||
'snippets' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.index'),
|
||||
'title' => __('admin_snippets'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'snippets_create' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.add'),
|
||||
'title' => __('admin_create_new_snippet'),
|
||||
'attributes' => ['class' => 'float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -56,8 +55,6 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function add(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -65,20 +62,20 @@ class SnippetsController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/snippets/add.html',
|
||||
[
|
||||
'menu_item' => 'snippets',
|
||||
'links' => [
|
||||
'snippets' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.index'),
|
||||
'title' => __('admin_snippets'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'snippets_rename' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.add'),
|
||||
'title' => __('admin_create_new_snippet'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
]
|
||||
]
|
||||
'menu_item' => 'snippets',
|
||||
'links' => [
|
||||
'snippets' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.index'),
|
||||
'title' => __('admin_snippets'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'snippets_rename' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.add'),
|
||||
'title' => __('admin_create_new_snippet'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,14 +84,12 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function addProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['id']);
|
||||
|
||||
if ($this->snippets->create($id, "")) {
|
||||
if ($this->snippets->create($id, '')) {
|
||||
$this->flash->addMessage('success', __('admin_message_snippet_created'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_snippet_was_not_created'));
|
||||
@@ -108,8 +103,6 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -119,29 +112,29 @@ class SnippetsController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/snippets/edit.html',
|
||||
[
|
||||
'menu_item' => 'snippets',
|
||||
'id' => $id,
|
||||
'data' => $this->snippets->fetch($id),
|
||||
'links' => [
|
||||
'snippets' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.index'),
|
||||
'title' => __('admin_snippets'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'snippets_editor' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.edit') . '?id=' . $id,
|
||||
'title' => __('admin_editor'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'save_snippet' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn']
|
||||
]
|
||||
'menu_item' => 'snippets',
|
||||
'id' => $id,
|
||||
'data' => $this->snippets->fetch($id),
|
||||
'links' => [
|
||||
'snippets' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.index'),
|
||||
'title' => __('admin_snippets'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'snippets_editor' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.edit') . '?id=' . $id,
|
||||
'title' => __('admin_editor'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'save_snippet' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -150,12 +143,10 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function editProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$id = $request->getParsedBody()['id'];
|
||||
$id = $request->getParsedBody()['id'];
|
||||
$data = $request->getParsedBody()['data'];
|
||||
|
||||
if ($this->snippets->update($id, $data)) {
|
||||
@@ -172,31 +163,28 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function rename(Request $request, Response $response) : Response
|
||||
{
|
||||
|
||||
return $this->view->render(
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/snippets/rename.html',
|
||||
[
|
||||
'menu_item' => 'snippets',
|
||||
'id_current' => $request->getQueryParams()['id'],
|
||||
'links' => [
|
||||
'snippets' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.index'),
|
||||
'title' => __('admin_snippets'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'snippets_rename' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.rename') . '?id=' . $request->getQueryParams()['id'],
|
||||
'title' => __('admin_rename'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
]
|
||||
]
|
||||
'menu_item' => 'snippets',
|
||||
'id_current' => $request->getQueryParams()['id'],
|
||||
'links' => [
|
||||
'snippets' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.index'),
|
||||
'title' => __('admin_snippets'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'snippets_rename' => [
|
||||
'link' => $this->router->pathFor('admin.snippets.rename') . '?id=' . $request->getQueryParams()['id'],
|
||||
'title' => __('admin_rename'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -205,12 +193,10 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function renameProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['id']);
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['id']);
|
||||
$id_current = $request->getParsedBody()['id_current'];
|
||||
|
||||
if ($this->snippets->rename(
|
||||
@@ -231,8 +217,6 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function deleteProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -252,14 +236,12 @@ class SnippetsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function duplicateProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$id = $request->getParsedBody()['snippet-id'];
|
||||
|
||||
if ($this->snippets->copy($id, $id . '-duplicate-' . date("Ymd_His"))) {
|
||||
if ($this->snippets->copy($id, $id . '-duplicate-' . date('Ymd_His'))) {
|
||||
$this->flash->addMessage('success', __('admin_message_snippet_duplicated'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_snippet_was_not_duplicated'));
|
||||
|
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Text\Text;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function date;
|
||||
use function Flextype\Component\I18n\__;
|
||||
|
||||
/**
|
||||
* @property View $view
|
||||
@@ -23,8 +25,6 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -35,30 +35,30 @@ class TemplatesController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/themes/templates/index.html',
|
||||
[
|
||||
'menu_item' => 'themes',
|
||||
'theme' => $theme,
|
||||
'templates_list' => $this->themes->getTemplates($theme),
|
||||
'partials_list' => $this->themes->getPartials($theme),
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'templates_create' => [
|
||||
'link' => $this->router->pathFor('admin.templates.add') . '?theme=' . $theme,
|
||||
'title' => __('admin_create_new_template'),
|
||||
'attributes' => ['class' => 'float-right btn']
|
||||
],
|
||||
]
|
||||
]
|
||||
'menu_item' => 'themes',
|
||||
'theme' => $theme,
|
||||
'templates_list' => $this->themes->getTemplates($theme),
|
||||
'partials_list' => $this->themes->getPartials($theme),
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'templates_create' => [
|
||||
'link' => $this->router->pathFor('admin.templates.add') . '?theme=' . $theme,
|
||||
'title' => __('admin_create_new_template'),
|
||||
'attributes' => ['class' => 'float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,8 +67,6 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function add(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -79,26 +77,26 @@ class TemplatesController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/themes/templates/add.html',
|
||||
[
|
||||
'menu_item' => 'themes',
|
||||
'theme' => $theme,
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'templates_add' => [
|
||||
'link' => $this->router->pathFor('admin.templates.add') . '?theme=' . $theme,
|
||||
'title' => __('admin_create_new_template'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
]
|
||||
]
|
||||
'menu_item' => 'themes',
|
||||
'theme' => $theme,
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'templates_add' => [
|
||||
'link' => $this->router->pathFor('admin.templates.add') . '?theme=' . $theme,
|
||||
'title' => __('admin_create_new_template'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -107,29 +105,27 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function addProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$type = $request->getParsedBody()['type'];
|
||||
$type = $request->getParsedBody()['type'];
|
||||
$theme = $request->getParsedBody()['theme'];
|
||||
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['id']) . '.html';
|
||||
|
||||
$file = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $id;
|
||||
|
||||
if (!Filesystem::has($file)) {
|
||||
if (! Filesystem::has($file)) {
|
||||
if (Filesystem::write(
|
||||
$file,
|
||||
""
|
||||
''
|
||||
)) {
|
||||
$this->flash->addMessage('success', __('admin_message_'.$type.'_created'));
|
||||
$this->flash->addMessage('success', __('admin_message_' . $type . '_created'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_created'));
|
||||
$this->flash->addMessage('error', __('admin_message_' . $type . '_was_not_created'));
|
||||
}
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_created'));
|
||||
$this->flash->addMessage('error', __('admin_message_' . $type . '_was_not_created'));
|
||||
}
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.templates.index') . '?theme=' . $theme);
|
||||
@@ -140,49 +136,47 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(Request $request, Response $response) : Response
|
||||
{
|
||||
// Get type and theme from request query params
|
||||
$type = $request->getQueryParams()['type'];
|
||||
$type = $request->getQueryParams()['type'];
|
||||
$theme = $request->getQueryParams()['theme'];
|
||||
|
||||
return $this->view->render(
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/themes/templates/edit.html',
|
||||
[
|
||||
'menu_item' => 'themes',
|
||||
'theme' => $theme,
|
||||
'id' => $request->getQueryParams()['id'],
|
||||
'data' => Filesystem::read(PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getQueryParams()['id'] . '.html'),
|
||||
'type' => (($request->getQueryParams()['type'] && $request->getQueryParams()['type'] == 'partial') ? 'partial' : 'template'),
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'templates_editor' => [
|
||||
'link' => $this->router->pathFor('admin.templates.edit') . '?id=' . $request->getQueryParams()['id'] . '&type=' . (($request->getQueryParams()['type'] && $request->getQueryParams()['type'] == 'partial') ? 'partial' : 'template') . '&theme=' . $theme,
|
||||
'title' => __('admin_editor'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'save_template' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn']
|
||||
]
|
||||
'menu_item' => 'themes',
|
||||
'theme' => $theme,
|
||||
'id' => $request->getQueryParams()['id'],
|
||||
'data' => Filesystem::read(PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getQueryParams()['id'] . '.html'),
|
||||
'type' => ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template'),
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'templates_editor' => [
|
||||
'link' => $this->router->pathFor('admin.templates.edit') . '?id=' . $request->getQueryParams()['id'] . '&type=' . ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template') . '&theme=' . $theme,
|
||||
'title' => __('admin_editor'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'save_template' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -191,15 +185,13 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function editProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
// Get theme and type and id from request query params
|
||||
$theme = $request->getParsedBody()['theme'];
|
||||
$id = $request->getParsedBody()['id'];
|
||||
$type = $request->getParsedBody()['type'];
|
||||
$id = $request->getParsedBody()['id'];
|
||||
$type = $request->getParsedBody()['type'];
|
||||
|
||||
if (Filesystem::write(PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html', $request->getParsedBody()['data'])) {
|
||||
$this->flash->addMessage('success', __('admin_message_' . $type . '_saved'));
|
||||
@@ -215,8 +207,6 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function rename(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -227,29 +217,29 @@ class TemplatesController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/themes/templates/rename.html',
|
||||
[
|
||||
'menu_item' => 'themes',
|
||||
'theme' => $theme,
|
||||
'types' => ['partial' => __('admin_partial'), 'template' => __('admin_template')],
|
||||
'id_current' => $request->getQueryParams()['id'],
|
||||
'type_current' => (($request->getQueryParams()['type'] && $request->getQueryParams()['type'] == 'partial') ? 'partial' : 'template'),
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'templates_rename' => [
|
||||
'link' => $this->router->pathFor('admin.templates.rename') . '?id=' . $request->getQueryParams()['id'] . '&type=' . (($request->getQueryParams()['type'] && $request->getQueryParams()['type'] == 'partial') ? 'partial' : 'template') . '&theme=' . $theme,
|
||||
'title' => __('admin_rename'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
]
|
||||
]
|
||||
'menu_item' => 'themes',
|
||||
'theme' => $theme,
|
||||
'types' => ['partial' => __('admin_partial'), 'template' => __('admin_template')],
|
||||
'id_current' => $request->getQueryParams()['id'],
|
||||
'type_current' => ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template'),
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'templates' => [
|
||||
'link' => $this->router->pathFor('admin.templates.index') . '?theme=' . $theme,
|
||||
'title' => __('admin_templates'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'templates_rename' => [
|
||||
'link' => $this->router->pathFor('admin.templates.rename') . '?id=' . $request->getQueryParams()['id'] . '&type=' . ($request->getQueryParams()['type'] && $request->getQueryParams()['type'] === 'partial' ? 'partial' : 'template') . '&theme=' . $theme,
|
||||
'title' => __('admin_rename'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -258,27 +248,25 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function renameProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
// Get theme and type from request query params
|
||||
$theme = $request->getParsedBody()['theme'];
|
||||
$type = $request->getParsedBody()['type_current'];
|
||||
$type = $request->getParsedBody()['type_current'];
|
||||
|
||||
if (!Filesystem::has(PATH['themes'] . '/' . $this->registry->get('settings.theme') . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html')) {
|
||||
if (! Filesystem::has(PATH['themes'] . '/' . $this->registry->get('settings.theme') . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html')) {
|
||||
if (Filesystem::rename(
|
||||
PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()['id_current'] . '.html',
|
||||
PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()['id'] . '.html'
|
||||
)
|
||||
) {
|
||||
$this->flash->addMessage('success', __('admin_message_'.$type.'_renamed'));
|
||||
$this->flash->addMessage('success', __('admin_message_' . $type . '_renamed'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_renamed'));
|
||||
$this->flash->addMessage('error', __('admin_message_' . $type . '_was_not_renamed'));
|
||||
}
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_renamed'));
|
||||
$this->flash->addMessage('error', __('admin_message_' . $type . '_was_not_renamed'));
|
||||
}
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.templates.index') . '?theme=' . $theme);
|
||||
@@ -289,14 +277,12 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function deleteProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
// Get theme and type from request query params
|
||||
$theme = $request->getParsedBody()['theme'];
|
||||
$type = $request->getParsedBody()['type'];
|
||||
$type = $request->getParsedBody()['type'];
|
||||
|
||||
$file_path = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()[$type . '-id'] . '.html';
|
||||
|
||||
@@ -314,17 +300,15 @@ class TemplatesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function duplicateProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
// Get theme and type from request query params
|
||||
$theme = $request->getParsedBody()['theme'];
|
||||
$type = $request->getParsedBody()['type'];
|
||||
$type = $request->getParsedBody()['type'];
|
||||
|
||||
$file_path = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()[$type . '-id'] . '.html';
|
||||
$file_path_new = PATH['themes'] . '/' . $theme. '/' . $this->_type_location($type) . $request->getParsedBody()[$type . '-id'] . '-duplicate-' . date("Ymd_His") . '.html';
|
||||
$file_path = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()[$type . '-id'] . '.html';
|
||||
$file_path_new = PATH['themes'] . '/' . $theme . '/' . $this->_type_location($type) . $request->getParsedBody()[$type . '-id'] . '-duplicate-' . date('Ymd_His') . '.html';
|
||||
|
||||
if (Filesystem::copy($file_path, $file_path_new)) {
|
||||
$this->flash->addMessage('success', __('admin_message_' . $type . '_duplicated'));
|
||||
@@ -337,7 +321,7 @@ class TemplatesController extends Controller
|
||||
|
||||
private function _type_location($type)
|
||||
{
|
||||
if ($type == 'partial') {
|
||||
if ($type === 'partial') {
|
||||
$_type = '/templates/partials/';
|
||||
} else {
|
||||
$_type = '/templates/';
|
||||
|
@@ -1,13 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Text\Text;
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function count;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* @property View $view
|
||||
@@ -22,8 +25,6 @@ class ThemesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -31,22 +32,22 @@ class ThemesController extends Controller
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/themes/index.html',
|
||||
[
|
||||
'menu_item' => 'themes',
|
||||
'themes_list' => $this->registry->get('themes'),
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'themes_get_more' => [
|
||||
'link' => 'https://github.com/flextype/themes',
|
||||
'title' => __('admin_get_more_themes'),
|
||||
'attributes' => ['class' => 'float-right btn', 'target' => '_blank']
|
||||
],
|
||||
]
|
||||
'menu_item' => 'themes',
|
||||
'themes_list' => $this->registry->get('themes'),
|
||||
'links' => [
|
||||
'themes' => [
|
||||
'link' => $this->router->pathFor('admin.themes.index'),
|
||||
'title' => __('admin_themes'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'themes_get_more' => [
|
||||
'link' => 'https://github.com/flextype/themes',
|
||||
'title' => __('admin_get_more_themes'),
|
||||
'attributes' => ['class' => 'float-right btn', 'target' => '_blank'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -56,8 +57,6 @@ class ThemesController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function activateProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -66,7 +65,7 @@ class ThemesController extends Controller
|
||||
|
||||
// Update current theme settings
|
||||
$theme_settings = JsonParser::decode(Filesystem::read(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.json'));
|
||||
Arr::set($theme_settings, 'enabled', ($data['theme-status'] == 'true' ? true : false));
|
||||
Arr::set($theme_settings, 'enabled', ($data['theme-status'] === 'true'));
|
||||
Filesystem::write(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.json', JsonParser::encode($theme_settings));
|
||||
|
||||
// Get themes list
|
||||
@@ -75,13 +74,17 @@ class ThemesController extends Controller
|
||||
// Deactivate all others themes
|
||||
if (is_array($themes_list) && count($themes_list) > 0) {
|
||||
foreach ($themes_list as $theme) {
|
||||
if ($theme['dirname'] !== $data['theme-id']) {
|
||||
if (Filesystem::has($theme_settings_file = PATH['themes'] . '/' . $theme['dirname'] . '/settings.json')) {
|
||||
$theme_settings = JsonParser::decode(Filesystem::read($theme_settings_file));
|
||||
Arr::set($theme_settings, 'enabled', false);
|
||||
Filesystem::write($theme_settings_file, JsonParser::encode($theme_settings));
|
||||
}
|
||||
if ($theme['dirname'] === $data['theme-id']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! Filesystem::has($theme_settings_file = PATH['themes'] . '/' . $theme['dirname'] . '/settings.json')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$theme_settings = JsonParser::decode(Filesystem::read($theme_settings_file));
|
||||
Arr::set($theme_settings, 'enabled', false);
|
||||
Filesystem::write($theme_settings_file, JsonParser::encode($theme_settings));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use FilesystemIterator;
|
||||
use Flextype\Component\Number\Number;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use function array_merge;
|
||||
use function file_exists;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use function getenv;
|
||||
use function is_array;
|
||||
use function php_sapi_name;
|
||||
use function php_uname;
|
||||
use function realpath;
|
||||
|
||||
/**
|
||||
* @property View $view
|
||||
@@ -20,8 +31,6 @@ class ToolsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -33,8 +42,6 @@ class ToolsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function information(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -44,25 +51,25 @@ class ToolsController extends Controller
|
||||
[
|
||||
'menu_item' => 'tools',
|
||||
'php_uname' => php_uname(),
|
||||
'webserver' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : @getenv('SERVER_SOFTWARE'),
|
||||
'webserver' => $_SERVER['SERVER_SOFTWARE'] ?? @getenv('SERVER_SOFTWARE'),
|
||||
'php_sapi_name' => php_sapi_name(),
|
||||
'links' => [
|
||||
'information' => [
|
||||
'link' => $this->router->pathFor('admin.tools.index'),
|
||||
'title' => __('admin_information'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
'cache' => [
|
||||
'link' => $this->router->pathFor('admin.tools.cache'),
|
||||
'title' => __('admin_cache'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'registry' => [
|
||||
'link' => $this->router->pathFor('admin.tools.registry'),
|
||||
'title' => __('admin_registry'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
]
|
||||
'information' => [
|
||||
'link' => $this->router->pathFor('admin.tools.index'),
|
||||
'title' => __('admin_information'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
'cache' => [
|
||||
'link' => $this->router->pathFor('admin.tools.cache'),
|
||||
'title' => __('admin_cache'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'registry' => [
|
||||
'link' => $this->router->pathFor('admin.tools.registry'),
|
||||
'title' => __('admin_registry'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -72,8 +79,6 @@ class ToolsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function cache(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -86,43 +91,40 @@ class ToolsController extends Controller
|
||||
'glide_size' => Number::byteFormat($this->getDirectorySize(PATH['cache'] . '/glide')),
|
||||
'twig_size' => Number::byteFormat($this->getDirectorySize(PATH['cache'] . '/twig')),
|
||||
'links' => [
|
||||
'information' => [
|
||||
'link' => $this->router->pathFor('admin.tools.index'),
|
||||
'title' => __('admin_information'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'cache' => [
|
||||
'link' => $this->router->pathFor('admin.tools.cache'),
|
||||
'title' => __('admin_cache'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
'registry' => [
|
||||
'link' => $this->router->pathFor('admin.tools.registry'),
|
||||
'title' => __('admin_registry'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
],
|
||||
'information' => [
|
||||
'link' => $this->router->pathFor('admin.tools.index'),
|
||||
'title' => __('admin_information'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'cache' => [
|
||||
'link' => $this->router->pathFor('admin.tools.cache'),
|
||||
'title' => __('admin_cache'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
'registry' => [
|
||||
'link' => $this->router->pathFor('admin.tools.registry'),
|
||||
'title' => __('admin_registry'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'tools_clear_cache' => [
|
||||
'type' => 'action',
|
||||
'id' => 'clear-cache-all',
|
||||
'link' => $this->router->pathFor('admin.tools.clearCacheAllProcess'),
|
||||
'title' => __('admin_clear_cache_all'),
|
||||
'attributes' => ['class' => 'float-right btn']
|
||||
]
|
||||
]
|
||||
'attributes' => ['class' => 'float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Information page
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function registry(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -133,22 +135,22 @@ class ToolsController extends Controller
|
||||
'menu_item' => 'tools',
|
||||
'registry_dump' => $this->dotArray($this->registry->dump()),
|
||||
'links' => [
|
||||
'information' => [
|
||||
'link' => $this->router->pathFor('admin.tools.index'),
|
||||
'title' => __('admin_information'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'cache' => [
|
||||
'link' => $this->router->pathFor('admin.tools.cache'),
|
||||
'title' => __('admin_cache'),
|
||||
'attributes' => ['class' => 'navbar-item']
|
||||
],
|
||||
'registry' => [
|
||||
'link' => $this->router->pathFor('admin.tools.registry'),
|
||||
'title' => __('admin_registry'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
],
|
||||
]
|
||||
'information' => [
|
||||
'link' => $this->router->pathFor('admin.tools.index'),
|
||||
'title' => __('admin_information'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'cache' => [
|
||||
'link' => $this->router->pathFor('admin.tools.cache'),
|
||||
'title' => __('admin_cache'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'registry' => [
|
||||
'link' => $this->router->pathFor('admin.tools.registry'),
|
||||
'title' => __('admin_registry'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -158,8 +160,6 @@ class ToolsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function clearCacheProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -177,8 +177,6 @@ class ToolsController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function clearCacheAllProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -198,14 +196,13 @@ class ToolsController extends Controller
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value) && ! empty($value)) {
|
||||
$results = array_merge($results, $this->dotArray($value, $prepend.$key.'.'));
|
||||
$results = array_merge($results, $this->dotArray($value, $prepend . $key . '.'));
|
||||
} else {
|
||||
$results[$prepend.$key] = $value;
|
||||
$results[$prepend . $key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,12 +211,13 @@ class ToolsController extends Controller
|
||||
private function getDirectorySize($path)
|
||||
{
|
||||
$bytestotal = 0;
|
||||
$path = realpath($path);
|
||||
if($path!==false && $path!='' && file_exists($path)){
|
||||
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object){
|
||||
$path = realpath($path);
|
||||
if ($path!==false && $path!=='' && file_exists($path)) {
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
|
||||
$bytestotal += $object->getSize();
|
||||
}
|
||||
}
|
||||
|
||||
return $bytestotal;
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Session\Session;
|
||||
use Flextype\Component\Text\Text;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
|
||||
use const PASSWORD_BCRYPT;
|
||||
use function count;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use function password_hash;
|
||||
use function password_verify;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* @property View $view
|
||||
@@ -32,25 +37,23 @@ class UsersController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function login(Request $request, Response $response) : Response
|
||||
{
|
||||
$users = $this->getUsers();
|
||||
|
||||
if ((Session::exists('role') && Session::get('role') == 'admin')) {
|
||||
if ((Session::exists('role') && Session::get('role') === 'admin')) {
|
||||
return $response->withRedirect($this->router->pathFor('admin.entries.index'));
|
||||
} else {
|
||||
if (count($users) > 0) {
|
||||
return $this->container->get('view')->render(
|
||||
$response,
|
||||
'plugins/admin/views/templates/users/login.html'
|
||||
);
|
||||
} else {
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.installation'));
|
||||
}
|
||||
}
|
||||
|
||||
if (count($users) > 0) {
|
||||
return $this->container->get('view')->render(
|
||||
$response,
|
||||
'plugins/admin/views/templates/users/login.html'
|
||||
);
|
||||
}
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.installation'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,8 +61,6 @@ class UsersController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function loginProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -71,15 +72,18 @@ class UsersController extends Controller
|
||||
Session::set('username', $user_file['username']);
|
||||
Session::set('role', $user_file['role']);
|
||||
Session::set('uuid', $user_file['uuid']);
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.entries.index'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_wrong_username_password'));
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.login'));
|
||||
}
|
||||
} else {
|
||||
|
||||
$this->flash->addMessage('error', __('admin_message_wrong_username_password'));
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.login'));
|
||||
}
|
||||
|
||||
$this->flash->addMessage('error', __('admin_message_wrong_username_password'));
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.login'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +91,6 @@ class UsersController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function installation(Request $request, Response $response) : Response
|
||||
{
|
||||
@@ -96,16 +98,16 @@ class UsersController extends Controller
|
||||
|
||||
if (count($users) > 0) {
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.login'));
|
||||
} else {
|
||||
if ((Session::exists('role') && Session::get('role') == 'admin')) {
|
||||
return $response->withRedirect($this->router->pathFor('admin.entries.index'));
|
||||
} else {
|
||||
return $this->view->render(
|
||||
$response,
|
||||
'plugins/admin/views/templates/users/installation.html'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ((Session::exists('role') && Session::get('role') === 'admin')) {
|
||||
return $response->withRedirect($this->router->pathFor('admin.entries.index'));
|
||||
}
|
||||
|
||||
return $this->view->render(
|
||||
$response,
|
||||
'plugins/admin/views/templates/users/installation.html'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,33 +115,32 @@ class UsersController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function installationProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
// Get POST data
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
if (!Filesystem::has($_user_file = PATH['site'] . '/accounts/' . $this->slugify->slugify($data['username']) . '.json')) {
|
||||
if (! Filesystem::has($_user_file = PATH['site'] . '/accounts/' . $this->slugify->slugify($data['username']) . '.json')) {
|
||||
Filesystem::createDir(PATH['site'] . '/accounts/');
|
||||
if (Filesystem::write(
|
||||
PATH['site'] . '/accounts/' . $data['username'] . '.json',
|
||||
JsonParser::encode(['username' => $this->slugify->slugify($data['username']),
|
||||
'hashed_password' => password_hash($data['password'], PASSWORD_BCRYPT),
|
||||
'email' => $data['email'],
|
||||
'role' => 'admin',
|
||||
'state' => 'enabled',
|
||||
'uuid' => Uuid::uuid4()
|
||||
])
|
||||
JsonParser::encode([
|
||||
'username' => $this->slugify->slugify($data['username']),
|
||||
'hashed_password' => password_hash($data['password'], PASSWORD_BCRYPT),
|
||||
'email' => $data['email'],
|
||||
'role' => 'admin',
|
||||
'state' => 'enabled',
|
||||
'uuid' => Uuid::uuid4(),
|
||||
])
|
||||
)) {
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.login'));
|
||||
} else {
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.installation'));
|
||||
}
|
||||
} else {
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.installation'));
|
||||
}
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.installation'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,12 +148,11 @@ class UsersController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function logoutProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
Session::destroy();
|
||||
|
||||
return $response->withRedirect($this->router->pathFor('admin.users.login'));
|
||||
}
|
||||
|
||||
@@ -169,10 +169,12 @@ class UsersController extends Controller
|
||||
// Users
|
||||
$users = [];
|
||||
|
||||
foreach($users_list as $user) {
|
||||
if ($user['type'] == 'file' && $user['extension'] == 'json') {
|
||||
$users[$user['basename']] = $user;
|
||||
foreach ($users_list as $user) {
|
||||
if ($user['type'] !== 'file' || $user['extension'] !== 'json') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$users[$user['basename']] = $user;
|
||||
}
|
||||
|
||||
return $users;
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -21,19 +20,16 @@ use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
*/
|
||||
class AuthMiddleware extends Middleware
|
||||
{
|
||||
|
||||
/**
|
||||
* __invoke
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
* @param callable $next Next middleware
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response, $next) : Response
|
||||
public function __invoke(Request $request, Response $response, callable $next) : Response
|
||||
{
|
||||
if (Session::exists('role') && Session::get('role') == 'admin') {
|
||||
if (Session::exists('role') && Session::get('role') === 'admin') {
|
||||
$response = $next($request, $response);
|
||||
} else {
|
||||
$response = $response->withRedirect($this->router->pathFor('admin.users.login'));
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Romanenko Sergey <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
@@ -12,9 +11,9 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use function ltrim;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
@@ -31,70 +30,64 @@ class SiteController extends Controller
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
* @param array $args Args
|
||||
* @return Response
|
||||
* @param array $args Args
|
||||
*/
|
||||
public function index(Request $request, Response $response, array $args) {
|
||||
public function index(Request $request, Response $response, array $args) : Response
|
||||
{
|
||||
// Get Query Params
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
// Get Query Params
|
||||
$query = $request->getQueryParams();
|
||||
// Get uri
|
||||
$uri = $args['uri'];
|
||||
|
||||
// Get uri
|
||||
$uri = $args['uri'];
|
||||
// If uri is empty then it is main page else use entry uri
|
||||
if ($uri === '/') {
|
||||
$entry_uri = $this->registry->get('settings.entries.main');
|
||||
} else {
|
||||
$entry_uri = ltrim($uri, '/');
|
||||
}
|
||||
|
||||
// If uri is empty then it is main page else use entry uri
|
||||
if ($uri === '/') {
|
||||
$entry_uri = $this->registry->get('settings.entries.main');
|
||||
} else {
|
||||
$entry_uri = ltrim($uri, '/');
|
||||
}
|
||||
// Get entry body
|
||||
$entry_body = $this->entries->fetch($entry_uri);
|
||||
|
||||
// Get entry body
|
||||
$entry_body = $this->entries->fetch($entry_uri);
|
||||
// is entry not found
|
||||
$is_entry_not_found = false;
|
||||
|
||||
// is entry not found
|
||||
$is_entry_not_found = false;
|
||||
// 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['title'] = $this->registry->get('settings.entries.error404.title');
|
||||
$entry['description'] = $this->registry->get('settings.entries.error404.description');
|
||||
$entry['content'] = $this->registry->get('settings.entries.error404.content');
|
||||
$entry['template'] = $this->registry->get('settings.entries.error404.template');
|
||||
|
||||
// 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['title'] = $this->registry->get('settings.entries.error404.title');
|
||||
$entry['description'] = $this->registry->get('settings.entries.error404.description');
|
||||
$entry['content'] = $this->registry->get('settings.entries.error404.content');
|
||||
$entry['template'] = $this->registry->get('settings.entries.error404.template');
|
||||
|
||||
$is_entry_not_found = true;
|
||||
|
||||
} else {
|
||||
$entry = $entry_body;
|
||||
}
|
||||
} else {
|
||||
|
||||
$entry['title'] = $this->registry->get('settings.entries.error404.title');
|
||||
$entry['description'] = $this->registry->get('settings.entries.error404.description');
|
||||
$entry['content'] = $this->registry->get('settings.entries.error404.content');
|
||||
$entry['template'] = $this->registry->get('settings.entries.error404.template');
|
||||
$is_entry_not_found = true;
|
||||
} else {
|
||||
$entry = $entry_body;
|
||||
}
|
||||
} else {
|
||||
$entry['title'] = $this->registry->get('settings.entries.error404.title');
|
||||
$entry['description'] = $this->registry->get('settings.entries.error404.description');
|
||||
$entry['content'] = $this->registry->get('settings.entries.error404.content');
|
||||
$entry['template'] = $this->registry->get('settings.entries.error404.template');
|
||||
|
||||
$is_entry_not_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Set entry
|
||||
$this->entry = $entry;
|
||||
// Set entry
|
||||
$this->entry = $entry;
|
||||
|
||||
// Run event onSiteEntryAfterInitialized
|
||||
$this->emitter->emit('onSiteEntryAfterInitialized');
|
||||
// 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';
|
||||
// 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' => $this->entry]);
|
||||
} else {
|
||||
return $this->view->render($response, $path, ['entry' => $this->entry, 'page' => ($query['page']) ?? '']);
|
||||
}
|
||||
}
|
||||
if ($is_entry_not_found) {
|
||||
return $this->view->render($response->withStatus(404), $path, ['entry' => $this->entry]);
|
||||
}
|
||||
|
||||
return $this->view->render($response, $path, ['entry' => $this->entry, 'page' => $query['page'] ?? '']);
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Romanenko Sergey <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 function is_file;
|
||||
|
||||
/**
|
||||
* Ensure vendor libraries exist
|
||||
*/
|
||||
!is_file($site_autoload = __DIR__ . '/vendor/autoload.php') and exit("Please run: <i>composer install</i>");
|
||||
! is_file($site_autoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: <i>composer install</i>');
|
||||
|
||||
/**
|
||||
* Register The Auto Loader
|
||||
|
@@ -1,20 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Romanenko Sergey <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;
|
||||
|
||||
/**
|
||||
* Add site controller to Flextype container
|
||||
*/
|
||||
$flextype['SiteController'] = function($container) {
|
||||
$flextype['SiteController'] = static function ($container) {
|
||||
return new SiteController($container);
|
||||
};
|
||||
|
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Romanenko Sergey <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
|
Reference in New Issue
Block a user