mirror of
https://github.com/flextype/flextype.git
synced 2025-08-05 04:37:43 +02:00
refactor(core): code formating and refactoring
This commit is contained in:
@@ -44,7 +44,7 @@ version_compare($ver = PHP_VERSION, $req = FLEXTYPE_MINIMUM_PHP, '<') and exit(s
|
||||
/**
|
||||
* Ensure vendor libraries exist
|
||||
*/
|
||||
! is_file($flextype_autoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: <i>composer install</i> for flextype');
|
||||
! is_file($flextypeAutoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: <i>composer install</i> for flextype');
|
||||
|
||||
/**
|
||||
* Register The Auto Loader
|
||||
@@ -55,7 +55,7 @@ version_compare($ver = PHP_VERSION, $req = FLEXTYPE_MINIMUM_PHP, '<') and exit(s
|
||||
* loading any of our classes later on. It feels nice to relax.
|
||||
* Register The Auto Loader
|
||||
*/
|
||||
$flextype_loader = require_once $flextype_autoload;
|
||||
$flextypeLoader = require_once $flextypeAutoload;
|
||||
|
||||
/**
|
||||
* Bootstraps the Flextype
|
||||
|
@@ -15,59 +15,38 @@ if (flextype('registry')->get('flextype.settings.entries.fields.parsers.enabled'
|
||||
|
||||
function processParsersField(): void
|
||||
{
|
||||
if (flextype('entries')->getStorage('fetch.data.cache.enabled') === null) {
|
||||
if (flextype('entries')->getStorage('fetch.data.cache.enabled') == null) {
|
||||
$cache = false;
|
||||
} else {
|
||||
$cache = (bool) flextype('entries')->getStorage('fetch.data.cache.enabled');
|
||||
}
|
||||
|
||||
if (flextype('entries')->getStorage('fetch.data.parsers') === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (flextype('entries')->getStorage('fetch.data.parsers') as $parser_name => $parser_data) {
|
||||
if (! in_array($parser_name, ['markdown', 'shortcode'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flextype('entries')->getStorage('fetch.data.parsers.' . $parser_name . '.enabled') !== true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flextype('entries')->getStorage('fetch.data.parsers.' . $parser_name . '.fields') === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! is_array(flextype('entries')->getStorage('fetch.data.parsers.' . $parser_name . '.fields'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (flextype('entries')->getStorage('fetch.data.parsers.' . $parser_name . '.fields') as $field) {
|
||||
if (in_array($field, flextype('registry')->get('flextype.settings.entries.fields'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($parser_name === 'markdown') {
|
||||
if (arrays(flextype('entries')->getStorage('fetch.data'))->has($field)) {
|
||||
flextype('entries')->setStorage(
|
||||
'fetch.data.' . $field,
|
||||
flextype('markdown')->parse(flextype('entries')->getStorage('fetch.data.' . $field), $cache)
|
||||
);
|
||||
if (flextype('entries')->getStorage('fetch.data.parsers') != null) {
|
||||
foreach (flextype('entries')->getStorage('fetch.data.parsers') as $parserName => $parserData) {
|
||||
if (in_array($parserName, ['markdown', 'shortcode'])) {
|
||||
if (flextype('entries')->getStorage('fetch.data.parsers.'.$parserName.'.enabled') === true) {
|
||||
if (flextype('entries')->getStorage('fetch.data.parsers.'.$parserName.'.fields') != null) {
|
||||
if (is_array(flextype('entries')->getStorage('fetch.data.parsers.'.$parserName.'.fields'))) {
|
||||
foreach (flextype('entries')->getStorage('fetch.data.parsers.'.$parserName.'.fields') as $field) {
|
||||
if (! in_array($field, flextype('registry')->get('flextype.settings.entries.fields'))) {
|
||||
if ($parserName == 'markdown') {
|
||||
if (arrays(flextype('entries')->getStorage('fetch.data'))->has($field)) {
|
||||
flextype('entries')->setStorage('fetch.data.'.$field,
|
||||
flextype('markdown')->parse(flextype('entries')->getStorage('fetch.data.'.$field), $cache));
|
||||
}
|
||||
}
|
||||
if ($parserName == 'shortcode') {
|
||||
if (arrays(flextype('entries')->getStorage('fetch.data'))->has($field)) {
|
||||
flextype('entries')->setStorage('fetch.data.'.$field,
|
||||
flextype('shortcode')->process(flextype('entries')->getStorage('fetch.data.'.$field), $cache));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($parser_name !== 'shortcode') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! arrays(flextype('entries')->getStorage('fetch.data'))->has($field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
flextype('entries')->setStorage(
|
||||
'fetch.data.' . $field,
|
||||
flextype('shortcode')->process(flextype('entries')->getStorage('fetch.data.' . $field), $cache)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,12 +14,12 @@ if (! function_exists('flextype')) {
|
||||
* Get the available Flextype Application instance
|
||||
* or try to get Dependency Injection Container if $container is not null.
|
||||
*/
|
||||
function flextype($container_name = null, $container = [])
|
||||
function flextype($containerName = null, $container = [])
|
||||
{
|
||||
if (is_null($container_name)) {
|
||||
if (is_null($containerName)) {
|
||||
return Flextype::getInstance($container);
|
||||
}
|
||||
|
||||
return Flextype::getInstance($container)->container($container_name);
|
||||
return Flextype::getInstance($container)->container($containerName);
|
||||
}
|
||||
}
|
||||
|
@@ -62,27 +62,27 @@ class MediaFiles
|
||||
*/
|
||||
public function upload(array $file, string $folder)
|
||||
{
|
||||
$upload_folder = PATH['project'] . '/uploads/' . $folder . '/';
|
||||
$upload_metadata_folder = PATH['project'] . '/uploads/.meta/' . $folder . '/';
|
||||
$uploadFolder = PATH['project'] . '/uploads/' . $folder . '/';
|
||||
$uploadMetadataFolder = PATH['project'] . '/uploads/.meta/' . $folder . '/';
|
||||
|
||||
if (! filesystem()->directory($upload_folder)->exists()) {
|
||||
filesystem()->directory($upload_folder)->create(0755, true);
|
||||
if (! filesystem()->directory($uploadFolder)->exists()) {
|
||||
filesystem()->directory($uploadFolder)->create(0755, true);
|
||||
}
|
||||
|
||||
if (! filesystem()->directory($upload_metadata_folder)->exists()) {
|
||||
filesystem()->directory($upload_metadata_folder)->create(0755, true);
|
||||
if (! filesystem()->directory($uploadMetadataFolder)->exists()) {
|
||||
filesystem()->directory($uploadMetadataFolder)->create(0755, true);
|
||||
}
|
||||
|
||||
$accept_file_types = flextype('registry')->get('flextype.settings.media.accept_file_types');
|
||||
$max_file_size = flextype('registry')->get('flextype.settings.media.max_file_size');
|
||||
$safe_names = flextype('registry')->get('flextype.settings.media.safe_names');
|
||||
$max_image_width = flextype('registry')->get('flextype.settings.media.max_image_width');
|
||||
$max_image_height = flextype('registry')->get('flextype.settings.media.max_image_height');
|
||||
$acceptFileTypes = flextype('registry')->get('flextype.settings.media.accept_file_types');
|
||||
$maxFileSize = flextype('registry')->get('flextype.settings.media.max_file_size');
|
||||
$safeNames = flextype('registry')->get('flextype.settings.media.safe_names');
|
||||
$maxImageWidth = flextype('registry')->get('flextype.settings.media.max_image_width');
|
||||
$maxImageHeight = flextype('registry')->get('flextype.settings.media.max_image_height');
|
||||
|
||||
$exact = false;
|
||||
$chmod = 0644;
|
||||
$filename = null;
|
||||
$exif_data = [];
|
||||
$exifData = [];
|
||||
|
||||
// Tests if a successful upload has been made.
|
||||
if (
|
||||
@@ -100,16 +100,16 @@ class MediaFiles
|
||||
and isset($file['size'])
|
||||
) {
|
||||
// Test if an uploaded file is an allowed file type, by extension.
|
||||
if (strpos($accept_file_types, strtolower(pathinfo($file['name'], PATHINFO_EXTENSION))) !== false) {
|
||||
if (strpos($acceptFileTypes, strtolower(pathinfo($file['name'], PATHINFO_EXTENSION))) !== false) {
|
||||
// Validation rule to test if an uploaded file is allowed by file size.
|
||||
if (
|
||||
($file['error'] !== UPLOAD_ERR_INI_SIZE)
|
||||
and ($file['error'] === UPLOAD_ERR_OK)
|
||||
and ($file['size'] <= $max_file_size)
|
||||
and ($file['size'] <= $maxFileSize)
|
||||
) {
|
||||
// Validation rule to test if an upload is an image and, optionally, is the correct size.
|
||||
if (in_array(mime_content_type($file['tmp_name']), ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'])) {
|
||||
if ($this->validateImage($file, $max_image_width, $max_image_height, $exact) === false) {
|
||||
if ($this->validateImage($file, $maxImageWidth, $maxImageHeight, $exact) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -124,17 +124,17 @@ class MediaFiles
|
||||
$filename = $file['name'];
|
||||
}
|
||||
|
||||
if ($safe_names === true) {
|
||||
if ($safeNames === true) {
|
||||
// Remove spaces from the filename
|
||||
$filename = flextype('slugify')->slugify(pathinfo($filename)['filename']) . '.' . pathinfo($filename)['extension'];
|
||||
}
|
||||
|
||||
if (! is_dir($upload_folder) or ! is_writable(realpath($upload_folder))) {
|
||||
throw new RuntimeException("Directory {$upload_folder} must be writable");
|
||||
if (! is_dir($uploadFolder) or ! is_writable(realpath($uploadFolder))) {
|
||||
throw new RuntimeException("Directory {$uploadFolder} must be writable");
|
||||
}
|
||||
|
||||
// Make the filename into a complete path
|
||||
$filename = realpath($upload_folder) . DIRECTORY_SEPARATOR . $filename;
|
||||
$filename = realpath($uploadFolder) . DIRECTORY_SEPARATOR . $filename;
|
||||
if (move_uploaded_file($file['tmp_name'], $filename)) {
|
||||
// Set permissions on filename
|
||||
chmod($filename, $chmod);
|
||||
@@ -167,13 +167,13 @@ class MediaFiles
|
||||
// destroy
|
||||
$img->destroy();
|
||||
|
||||
$exif_data = [];
|
||||
$exifData = [];
|
||||
|
||||
try {
|
||||
$headers = @exif_read_data($filename);
|
||||
if ($headers !== false) {
|
||||
foreach ($headers['COMPUTED'] as $header => $value) {
|
||||
$exif_data[$header] = $value;
|
||||
$exifData[$header] = $value;
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
@@ -187,11 +187,11 @@ class MediaFiles
|
||||
'type' => mime_content_type($filename),
|
||||
'filesize' => filesystem()->file($filename)->size(),
|
||||
'uploaded_on' => time(),
|
||||
'exif' => $exif_data,
|
||||
'exif' => $exifData,
|
||||
];
|
||||
|
||||
filesystem()
|
||||
->file($upload_metadata_folder . basename($filename) . '.yaml')
|
||||
->file($uploadMetadataFolder . basename($filename) . '.yaml')
|
||||
->put(flextype('yaml')->encode($metadata));
|
||||
|
||||
// Return new file path
|
||||
@@ -228,12 +228,12 @@ class MediaFiles
|
||||
$result['url'] = 'project/uploads/' . $path;
|
||||
|
||||
if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') {
|
||||
$full_url = flextype('registry')->get('flextype.settings.url');
|
||||
$fullUrl = flextype('registry')->get('flextype.settings.url');
|
||||
} else {
|
||||
$full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
|
||||
$fullUrl = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
|
||||
}
|
||||
|
||||
$result['full_url'] = $full_url . '/project/uploads/' . $path;
|
||||
$result['full_url'] = $fullUrl . '/project/uploads/' . $path;
|
||||
}
|
||||
|
||||
$result = filter($result, $options);
|
||||
@@ -264,12 +264,12 @@ class MediaFiles
|
||||
$result[$basename]['url'] = 'project/uploads/' . $path . '/' . $basename;
|
||||
|
||||
if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') {
|
||||
$full_url = flextype('registry')->get('flextype.settings.url');
|
||||
$fullUrl = flextype('registry')->get('flextype.settings.url');
|
||||
} else {
|
||||
$full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
|
||||
$fullUrl = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
|
||||
}
|
||||
|
||||
$result[$basename]['full_url'] = $full_url . '/project/uploads/' . $path . '/' . $basename;
|
||||
$result[$basename]['full_url'] = $fullUrl . '/project/uploads/' . $path . '/' . $basename;
|
||||
}
|
||||
|
||||
$result = filter($result, $options);
|
||||
@@ -281,17 +281,17 @@ class MediaFiles
|
||||
* Move file
|
||||
*
|
||||
* @param string $id Unique identifier of the file.
|
||||
* @param string $new_id New Unique identifier of the file.
|
||||
* @param string $newID New Unique identifier of the file.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function move(string $id, string $new_id): bool
|
||||
public function move(string $id, string $newID): bool
|
||||
{
|
||||
if (! filesystem()->file($this->getFileLocation($new_id))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists()) {
|
||||
return filesystem()->file($this->getFileLocation($id))->move($this->getFileLocation($new_id)) &&
|
||||
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->move(flextype('media_files_meta')->getFileMetaLocation($new_id));
|
||||
if (! filesystem()->file($this->getFileLocation($newID))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($newID))->exists()) {
|
||||
return filesystem()->file($this->getFileLocation($id))->move($this->getFileLocation($newID)) &&
|
||||
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->move(flextype('media_files_meta')->getFileMetaLocation($newID));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -331,20 +331,20 @@ class MediaFiles
|
||||
* Copy file
|
||||
*
|
||||
* @param string $id Unique identifier of the file.
|
||||
* @param string $new_id New Unique identifier of the file.
|
||||
* @param string $newID New Unique identifier of the file.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function copy(string $id, string $new_id): bool
|
||||
public function copy(string $id, string $newID): bool
|
||||
{
|
||||
if (! filesystem()->file($this->getFileLocation($new_id))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists()) {
|
||||
filesystem()->file($this->getFileLocation($id))->copy($this->getFileLocation($new_id));
|
||||
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->copy(flextype('media_files_meta')->getFileMetaLocation($new_id));
|
||||
if (! filesystem()->file($this->getFileLocation($newID))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($newID))->exists()) {
|
||||
filesystem()->file($this->getFileLocation($id))->copy($this->getFileLocation($newID));
|
||||
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->copy(flextype('media_files_meta')->getFileMetaLocation($newID));
|
||||
|
||||
return filesystem()->file($this->getFileLocation($new_id))->exists() &&
|
||||
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists();
|
||||
return filesystem()->file($this->getFileLocation($newID))->exists() &&
|
||||
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($newID))->exists();
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -367,7 +367,7 @@ class MediaFiles
|
||||
/**
|
||||
* Validate Image
|
||||
*/
|
||||
protected function validateImage($file, $max_image_width, $max_image_height, $exact)
|
||||
protected function validateImage($file, $maxImageWidth, $maxImageHeight, $exact)
|
||||
{
|
||||
try {
|
||||
// Get the width and height from the uploaded image
|
||||
@@ -381,22 +381,22 @@ class MediaFiles
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $max_image_width) {
|
||||
if (! $maxImageWidth) {
|
||||
// No limit, use the image width
|
||||
$max_image_width = $width;
|
||||
$maxImageWidth = $width;
|
||||
}
|
||||
|
||||
if (! $max_image_height) {
|
||||
if (! $maxImageHeight) {
|
||||
// No limit, use the image height
|
||||
$max_image_height = $height;
|
||||
$maxImageHeight = $height;
|
||||
}
|
||||
|
||||
if ($exact) {
|
||||
// Check if dimensions match exactly
|
||||
return $width === $max_image_width and $height === $max_image_height;
|
||||
return $width === $maxImageWidth and $height === $maxImageHeight;
|
||||
}
|
||||
|
||||
// Check if size is within maximum dimensions
|
||||
return $width <= $max_image_width and $height <= $max_image_height;
|
||||
return $width <= $maxImageWidth and $height <= $maxImageHeight;
|
||||
}
|
||||
}
|
||||
|
@@ -32,12 +32,12 @@ class MediaFilesMeta
|
||||
*/
|
||||
public function update(string $id, string $field, string $value): bool
|
||||
{
|
||||
$file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
|
||||
$fileData = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
|
||||
|
||||
if (arrays($file_data)->has($field)) {
|
||||
$file_data = arrays($file_data)->set($field, $value);
|
||||
if (arrays($fileData)->has($field)) {
|
||||
$fileData = arrays($fileData)->set($field, $value);
|
||||
|
||||
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
|
||||
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($fileData->toArray()));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -56,12 +56,12 @@ class MediaFilesMeta
|
||||
*/
|
||||
public function add(string $id, string $field, string $value): bool
|
||||
{
|
||||
$file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
|
||||
$fileData = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
|
||||
|
||||
if (! arrays($file_data)->has($field)) {
|
||||
$file_data = arrays($file_data)->set($field, $value);
|
||||
if (! arrays($fileData)->has($field)) {
|
||||
$fileData = arrays($fileData)->set($field, $value);
|
||||
|
||||
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
|
||||
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($fileData->toArray()));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -79,12 +79,12 @@ class MediaFilesMeta
|
||||
*/
|
||||
public function delete(string $id, string $field): bool
|
||||
{
|
||||
$file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
|
||||
$fileData = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
|
||||
|
||||
if (arrays($file_data)->has($field)) {
|
||||
$file_data = arrays($file_data)->delete($field);
|
||||
if (arrays($fileData)->has($field)) {
|
||||
$fileData = arrays($fileData)->delete($field);
|
||||
|
||||
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
|
||||
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($fileData->toArray()));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@@ -42,12 +42,12 @@ class MediaFolders
|
||||
$result['url'] = 'project/uploads/' . $path;
|
||||
|
||||
if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') {
|
||||
$full_url = flextype('registry')->get('flextype.settings.url');
|
||||
$fullUrl = flextype('registry')->get('flextype.settings.url');
|
||||
} else {
|
||||
$full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
|
||||
$fullUrl = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
|
||||
}
|
||||
|
||||
$result['full_url'] = $full_url . '/project/uploads/' . $path;
|
||||
$result['full_url'] = $fullUrl . '/project/uploads/' . $path;
|
||||
}
|
||||
|
||||
$result = filter($result, $options);
|
||||
@@ -102,20 +102,20 @@ class MediaFolders
|
||||
* Move folder
|
||||
*
|
||||
* @param string $id Unique identifier of the folder.
|
||||
* @param string $new_id New Unique identifier of the folder.
|
||||
* @param string $newID New Unique identifier of the folder.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function move(string $id, string $new_id): bool
|
||||
public function move(string $id, string $newID): bool
|
||||
{
|
||||
if (
|
||||
(filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)
|
||||
(filesystem()->directory($this->getDirectoryLocation($newID))->exists() === false &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($newID))->exists() === false)
|
||||
) {
|
||||
return filesystem()->directory($this->getDirectoryLocation($id))->move($this->getDirectoryLocation($new_id)) &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->move(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id));
|
||||
return filesystem()->directory($this->getDirectoryLocation($id))->move($this->getDirectoryLocation($newID)) &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->move(flextype('media_folders_meta')->getDirectoryMetaLocation($newID));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -125,27 +125,27 @@ class MediaFolders
|
||||
* Copy folder
|
||||
*
|
||||
* @param string $id Unique identifier of the folder.
|
||||
* @param string $new_id New Unique identifier of the folder.
|
||||
* @param string $newID New Unique identifier of the folder.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function copy(string $id, string $new_id): bool
|
||||
public function copy(string $id, string $newID): bool
|
||||
{
|
||||
if (
|
||||
(filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)
|
||||
(filesystem()->directory($this->getDirectoryLocation($newID))->exists() === false &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($newID))->exists() === false)
|
||||
) {
|
||||
filesystem()
|
||||
->directory($this->getDirectoryLocation($id))
|
||||
->copy($this->getDirectoryLocation($new_id));
|
||||
->copy($this->getDirectoryLocation($newID));
|
||||
filesystem()
|
||||
->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))
|
||||
->copy(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id));
|
||||
->copy(flextype('media_folders_meta')->getDirectoryMetaLocation($newID));
|
||||
|
||||
return filesystem()->directory($this->getDirectoryLocation($new_id))->exists() &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists();
|
||||
return filesystem()->directory($this->getDirectoryLocation($newID))->exists() &&
|
||||
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($newID))->exists();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@@ -72,82 +72,82 @@ class Plugins
|
||||
$locale = flextype('registry')->get('flextype.settings.locale');
|
||||
|
||||
// Get plugins list
|
||||
$plugins_list = $this->getPluginsList();
|
||||
$pluginsList = $this->getPluginsList();
|
||||
|
||||
// Get plugins Cache ID
|
||||
$plugins_cache_id = $this->getPluginsCacheID($plugins_list);
|
||||
$pluginsCacheID = $this->getPluginsCacheID($pluginsList);
|
||||
|
||||
// If Plugins List isnt empty then continue
|
||||
if (count($plugins_list) <= 0) {
|
||||
if (count($pluginsList) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get plugins from cache or scan plugins folder and create new plugins cache item
|
||||
if (flextype('cache')->has($plugins_cache_id)) {
|
||||
flextype('registry')->set('plugins', flextype('cache')->get($plugins_cache_id));
|
||||
if (flextype('cache')->has($pluginsCacheID)) {
|
||||
flextype('registry')->set('plugins', flextype('cache')->get($pluginsCacheID));
|
||||
|
||||
if (flextype('cache')->has($locale)) {
|
||||
I18n::add(flextype('cache')->get($locale), $locale);
|
||||
} else {
|
||||
// Save plugins dictionary
|
||||
$dictionary = $this->getPluginsDictionary($plugins_list, $locale);
|
||||
$dictionary = $this->getPluginsDictionary($pluginsList, $locale);
|
||||
flextype('cache')->set($locale, $dictionary[$locale]);
|
||||
}
|
||||
} else {
|
||||
// Init plugin configs
|
||||
$plugins = [];
|
||||
$default_plugin_settings = [];
|
||||
$project_plugin_settings = [];
|
||||
$default_plugin_manifest = [];
|
||||
$defaultPluginSettings = [];
|
||||
$projectPluginSettings = [];
|
||||
$defaultPluginManifest = [];
|
||||
|
||||
// Go through...
|
||||
foreach ($plugins_list as $plugin) {
|
||||
foreach ($pluginsList as $plugin) {
|
||||
// Set plugin settings directory
|
||||
$project_plugin_settings_dir = PATH['project'] . '/config/plugins/' . $plugin['dirname'];
|
||||
$projectPluginSettingsDir = PATH['project'] . '/config/plugins/' . $plugin['dirname'];
|
||||
|
||||
// Set default plugin settings and manifest files
|
||||
$default_plugin_settings_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml';
|
||||
$default_plugin_manifest_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml';
|
||||
$defaultPluginSettingsFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml';
|
||||
$defaultPluginManifestFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml';
|
||||
|
||||
// Set project plugin settings file
|
||||
$project_plugin_settings_file = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml';
|
||||
$projectPluginSettingsFile = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml';
|
||||
|
||||
// Create project plugin settings directory
|
||||
! filesystem()->directory($project_plugin_settings_dir)->exists() and filesystem()->directory($project_plugin_settings_dir)->create(0755, true);
|
||||
! filesystem()->directory($projectPluginSettingsDir)->exists() and filesystem()->directory($projectPluginSettingsDir)->create(0755, true);
|
||||
|
||||
// Check if default plugin settings file exists
|
||||
if (! filesystem()->file($default_plugin_settings_file)->exists()) {
|
||||
if (! filesystem()->file($defaultPluginSettingsFile)->exists()) {
|
||||
throw new RuntimeException('Load ' . $plugin['dirname'] . ' plugin settings - failed!');
|
||||
}
|
||||
|
||||
// Get default plugin settings content
|
||||
$default_plugin_settings_file_content = filesystem()->file($default_plugin_settings_file)->get();
|
||||
$default_plugin_settings = flextype('yaml')->decode($default_plugin_settings_file_content);
|
||||
$defaultPluginSettingsFileContent = filesystem()->file($defaultPluginSettingsFile)->get();
|
||||
$defaultPluginSettings = flextype('yaml')->decode($defaultPluginSettingsFileContent);
|
||||
|
||||
// Create project plugin settings file
|
||||
! filesystem()->file($project_plugin_settings_file)->exists() and filesystem()->file($project_plugin_settings_file)->put($default_plugin_settings_file_content);
|
||||
! filesystem()->file($projectPluginSettingsFile)->exists() and filesystem()->file($projectPluginSettingsFile)->put($defaultPluginSettingsFileContent);
|
||||
|
||||
// Get project plugin settings content
|
||||
$project_plugin_settings_file_content = filesystem()->file($project_plugin_settings_file)->get();
|
||||
$projectPluginSettingsFileContent = filesystem()->file($projectPluginSettingsFile)->get();
|
||||
|
||||
if (trim($project_plugin_settings_file_content) === '') {
|
||||
$project_plugin_settings = [];
|
||||
if (trim($projectPluginSettingsFileContent) === '') {
|
||||
$projectPluginSettings = [];
|
||||
} else {
|
||||
$project_plugin_settings = flextype('yaml')->decode($project_plugin_settings_file_content);
|
||||
$projectPluginSettings = flextype('yaml')->decode($projectPluginSettingsFileContent);
|
||||
}
|
||||
|
||||
// Check if default plugin manifest file exists
|
||||
if (! filesystem()->file($default_plugin_manifest_file)->exists()) {
|
||||
if (! filesystem()->file($defaultPluginManifestFile)->exists()) {
|
||||
throw new RuntimeException('Load ' . $plugin['dirname'] . ' plugin manifest - failed!');
|
||||
}
|
||||
|
||||
// Get default plugin manifest content
|
||||
$default_plugin_manifest_file_content = filesystem()->file($default_plugin_manifest_file)->get();
|
||||
$default_plugin_manifest = flextype('yaml')->decode($default_plugin_manifest_file_content);
|
||||
$defaultPluginManifestFileContent = filesystem()->file($defaultPluginManifestFile)->get();
|
||||
$defaultPluginManifest = flextype('yaml')->decode($defaultPluginManifestFileContent);
|
||||
|
||||
// Merge plugin settings and manifest data
|
||||
$plugins[$plugin['dirname']]['manifest'] = $default_plugin_manifest;
|
||||
$plugins[$plugin['dirname']]['settings'] = array_replace_recursive($default_plugin_settings, $project_plugin_settings);
|
||||
$plugins[$plugin['dirname']]['manifest'] = $defaultPluginManifest;
|
||||
$plugins[$plugin['dirname']]['settings'] = array_replace_recursive($defaultPluginSettings, $projectPluginSettings);
|
||||
|
||||
// Check if is not set plugin priority
|
||||
if (! isset($plugins[$plugin['dirname']]['settings']['priority'])) {
|
||||
@@ -163,8 +163,8 @@ class Plugins
|
||||
$plugins = arrays($plugins)->sortBy('_priority', 'DESC')->toArray();
|
||||
|
||||
// ... and delete tmp _priority field for sorting
|
||||
foreach ($plugins as $plugin_name => $plugin_data) {
|
||||
$plugins[$plugin_name] = arrays($plugins)->delete($plugin_name . '._priority')->toArray();
|
||||
foreach ($plugins as $pluginName => $pluginData) {
|
||||
$plugins[$pluginName] = arrays($plugins)->delete($pluginName . '._priority')->toArray();
|
||||
}
|
||||
|
||||
// Get Valid Plugins Dependencies
|
||||
@@ -172,10 +172,10 @@ class Plugins
|
||||
|
||||
// Save plugins list
|
||||
flextype('registry')->set('plugins', $plugins);
|
||||
flextype('cache')->set($plugins_cache_id, $plugins);
|
||||
flextype('cache')->set($pluginsCacheID, $plugins);
|
||||
|
||||
// Save plugins dictionary
|
||||
$dictionary = $this->getPluginsDictionary($plugins_list, $locale);
|
||||
$dictionary = $this->getPluginsDictionary($pluginsList, $locale);
|
||||
flextype('cache')->set($locale, $dictionary[$locale]);
|
||||
}
|
||||
|
||||
@@ -187,21 +187,21 @@ class Plugins
|
||||
/**
|
||||
* Get plugins dictionary
|
||||
*
|
||||
* @param array $plugins_list Plugins list
|
||||
* @param array $pluginsList Plugins list
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
public function getPluginsDictionary(array $plugins_list, string $locale): array
|
||||
public function getPluginsDictionary(array $pluginsList, string $locale): array
|
||||
{
|
||||
foreach ($plugins_list as $plugin) {
|
||||
$language_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/lang/' . $locale . '.yaml';
|
||||
foreach ($pluginsList as $plugin) {
|
||||
$languageFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/lang/' . $locale . '.yaml';
|
||||
|
||||
if (! filesystem()->file($language_file)->exists()) {
|
||||
if (! filesystem()->file($languageFile)->exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($content = filesystem()->file($language_file)->get()) === false) {
|
||||
throw new RuntimeException('Load file: ' . $language_file . ' - failed!');
|
||||
if (($content = filesystem()->file($languageFile)->get()) === false) {
|
||||
throw new RuntimeException('Load file: ' . $languageFile . ' - failed!');
|
||||
}
|
||||
|
||||
$translates = flextype('yaml')->decode($content);
|
||||
@@ -215,32 +215,32 @@ class Plugins
|
||||
/**
|
||||
* Get plugins Cache ID
|
||||
*
|
||||
* @param array $plugins_list Plugins list
|
||||
* @param array $pluginsList Plugins list
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
public function getPluginsCacheID(array $plugins_list): string
|
||||
public function getPluginsCacheID(array $pluginsList): string
|
||||
{
|
||||
// Plugin cache id
|
||||
$_plugins_cache_id = '';
|
||||
$_pluginsCacheID = '';
|
||||
|
||||
// Go through...
|
||||
if (is_array($plugins_list) && count($plugins_list) > 0) {
|
||||
foreach ($plugins_list as $plugin) {
|
||||
$default_plugin_settings_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml';
|
||||
$default_plugin_manifest_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml';
|
||||
$project_plugin_settings_file = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml';
|
||||
if (is_array($pluginsList) && count($pluginsList) > 0) {
|
||||
foreach ($pluginsList as $plugin) {
|
||||
$defaultPluginSettingsFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml';
|
||||
$defaultPluginManifestFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml';
|
||||
$projectPluginSettingsFile = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml';
|
||||
|
||||
$f1 = filesystem()->file($default_plugin_settings_file)->exists() ? filemtime($default_plugin_settings_file) : '';
|
||||
$f2 = filesystem()->file($default_plugin_manifest_file)->exists() ? filemtime($default_plugin_manifest_file) : '';
|
||||
$f3 = filesystem()->file($project_plugin_settings_file)->exists() ? filemtime($project_plugin_settings_file) : '';
|
||||
$f1 = filesystem()->file($defaultPluginSettingsFile)->exists() ? filemtime($defaultPluginSettingsFile) : '';
|
||||
$f2 = filesystem()->file($defaultPluginManifestFile)->exists() ? filemtime($defaultPluginManifestFile) : '';
|
||||
$f3 = filesystem()->file($projectPluginSettingsFile)->exists() ? filemtime($projectPluginSettingsFile) : '';
|
||||
|
||||
$_plugins_cache_id .= $f1 . $f2 . $f3;
|
||||
$_pluginsCacheID .= $f1 . $f2 . $f3;
|
||||
}
|
||||
}
|
||||
|
||||
// Create Unique Cache ID for Plugins
|
||||
return md5('plugins' . PATH['project'] . '/plugins/' . $_plugins_cache_id);
|
||||
return md5('plugins' . PATH['project'] . '/plugins/' . $_pluginsCacheID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,33 +253,33 @@ class Plugins
|
||||
public function getValidPluginsDependencies(array $plugins): array
|
||||
{
|
||||
// Set verified plugins array
|
||||
$verified_plugins = [];
|
||||
$verifiedPlugins = [];
|
||||
|
||||
// Set non verfied plugins
|
||||
$non_verified_plugins = $plugins;
|
||||
$nonVerifiedPlugins = $plugins;
|
||||
|
||||
// Go through plugins list and verify them.
|
||||
foreach ($plugins as $plugin_name => &$plugin_data) {
|
||||
foreach ($plugins as $pluginName => &$pluginData) {
|
||||
// Set verified true by default
|
||||
$verified = true;
|
||||
|
||||
// If there is any dependencies for this plugin
|
||||
if (isset($plugin_data['manifest']['dependencies'])) {
|
||||
if (isset($pluginData['manifest']['dependencies'])) {
|
||||
// Go through plugin dependencies
|
||||
foreach ($plugin_data['manifest']['dependencies'] as $dependency => $constraints) {
|
||||
foreach ($pluginData['manifest']['dependencies'] as $dependency => $constraints) {
|
||||
// Verify flextype version
|
||||
if ($dependency === 'flextype') {
|
||||
if (! Semver::satisfies(flextype('registry')->get('flextype.manifest.version'), $constraints)) {
|
||||
$verified = false;
|
||||
|
||||
// Remove plugin where it is require this dependency
|
||||
foreach ($plugins as $_plugin_name => $_plugin_data) {
|
||||
if (! $_plugin_data['manifest']['dependencies'][$plugin_name]) {
|
||||
foreach ($plugins as $_plugin_name => $_pluginData) {
|
||||
if (! $_pluginData['manifest']['dependencies'][$pluginName]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($plugins[$_plugin_name]);
|
||||
unset($verified_plugins[$_plugin_name]);
|
||||
unset($verifiedPlugins[$_plugin_name]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -288,13 +288,13 @@ class Plugins
|
||||
$verified = false;
|
||||
|
||||
// Remove plugin where it is require this dependency
|
||||
foreach ($plugins as $_plugin_name => $_plugin_data) {
|
||||
if (! $_plugin_data['manifest']['dependencies'][$plugin_name]) {
|
||||
foreach ($plugins as $_plugin_name => $_pluginData) {
|
||||
if (! $_pluginData['manifest']['dependencies'][$pluginName]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($plugins[$_plugin_name]);
|
||||
unset($verified_plugins[$_plugin_name]);
|
||||
unset($verifiedPlugins[$_plugin_name]);
|
||||
}
|
||||
} else {
|
||||
$version = $plugins[$dependency]['manifest']['version'];
|
||||
@@ -302,13 +302,13 @@ class Plugins
|
||||
$verified = false;
|
||||
|
||||
// Remove plugin where it is require this dependency
|
||||
foreach ($plugins as $_plugin_name => $_plugin_data) {
|
||||
if (! $_plugin_data['manifest']['dependencies'][$plugin_name]) {
|
||||
foreach ($plugins as $_plugin_name => $_pluginData) {
|
||||
if (! $_pluginData['manifest']['dependencies'][$pluginName]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($plugins[$_plugin_name]);
|
||||
unset($verified_plugins[$_plugin_name]);
|
||||
unset($verifiedPlugins[$_plugin_name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -321,16 +321,16 @@ class Plugins
|
||||
continue;
|
||||
}
|
||||
|
||||
$verified_plugins[$plugin_name] = $plugin_data;
|
||||
$verifiedPlugins[$pluginName] = $pluginData;
|
||||
}
|
||||
|
||||
// Show alert if dependencies are not installed properly
|
||||
$diff = array_diff_key($non_verified_plugins, $verified_plugins);
|
||||
$diff = array_diff_key($nonVerifiedPlugins, $verifiedPlugins);
|
||||
if (count($diff) > 0) {
|
||||
echo '<b>Dependencies need to be installed properly for this plugins:</b>';
|
||||
echo '<ul>';
|
||||
foreach ($diff as $plugin_name => $plugin_data) {
|
||||
echo '<li>' . $plugin_name . '</li>';
|
||||
foreach ($diff as $pluginName => $pluginData) {
|
||||
echo '<li>' . $pluginName . '</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
@@ -338,7 +338,7 @@ class Plugins
|
||||
}
|
||||
|
||||
// Return verified plugins list
|
||||
return $verified_plugins;
|
||||
return $verifiedPlugins;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,16 +351,16 @@ class Plugins
|
||||
public function getPluginsList(): array
|
||||
{
|
||||
// Get Plugins List
|
||||
$plugins_list = [];
|
||||
$pluginsList = [];
|
||||
|
||||
if (filesystem()->directory(PATH['project'] . '/plugins/')->exists()) {
|
||||
foreach (filesystem()->find()->in(PATH['project'] . '/plugins/')->directories()->depth(0) as $plugin) {
|
||||
$plugins_list[$plugin->getBasename()]['dirname'] = $plugin->getBasename();
|
||||
$plugins_list[$plugin->getBasename()]['pathname'] = $plugin->getPathname();
|
||||
$pluginsList[$plugin->getBasename()]['dirname'] = $plugin->getBasename();
|
||||
$pluginsList[$plugin->getBasename()]['pathname'] = $plugin->getPathname();
|
||||
}
|
||||
}
|
||||
|
||||
return $plugins_list;
|
||||
return $pluginsList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,12 +374,12 @@ class Plugins
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (flextype('registry')->get('plugins') as $plugin_name => $plugin) {
|
||||
if (! flextype('registry')->get('plugins.' . $plugin_name . '.settings.enabled')) {
|
||||
foreach (flextype('registry')->get('plugins') as $pluginName => $plugin) {
|
||||
if (! flextype('registry')->get('plugins.' . $pluginName . '.settings.enabled')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
include_once PATH['project'] . '/plugins/' . $plugin_name . '/bootstrap.php';
|
||||
include_once PATH['project'] . '/plugins/' . $pluginName . '/bootstrap.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,11 +15,11 @@ if (! function_exists('find')) {
|
||||
*
|
||||
* @param string $path Path.
|
||||
* @param array $options Options array.
|
||||
* @param string $search_in Search in 'files' or 'directories'. Default is 'files'.
|
||||
* @param string $searchIn Search in 'files' or 'directories'. Default is 'files'.
|
||||
*
|
||||
* @return Symfony\Component\Finder<Finder>
|
||||
*/
|
||||
function find(string $path = '', array $options = [], string $search_in = 'files'): Finder
|
||||
function find(string $path = '', array $options = [], string $searchIn = 'files'): Finder
|
||||
{
|
||||
$find = filesystem()->find()->in($path);
|
||||
|
||||
@@ -36,6 +36,6 @@ if (! function_exists('find')) {
|
||||
isset($options['sort_by']) && $options['sort_by'] === 'mtime' and $find->sortByModifiedTime();
|
||||
isset($options['sort_by']) && $options['sort_by'] === 'ctime' and $find->sortByChangedTime();
|
||||
|
||||
return $search_in === 'directories' ? $find->directories() : $find->files();
|
||||
return $searchIn === 'directories' ? $find->directories() : $find->files();
|
||||
}
|
||||
}
|
||||
|
@@ -52,8 +52,8 @@ class Markdown
|
||||
if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) {
|
||||
$key = $this->getCacheID($input);
|
||||
|
||||
if ($data_from_cache = flextype('cache')->get($key)) {
|
||||
return $data_from_cache;
|
||||
if ($dataFromCache = flextype('cache')->get($key)) {
|
||||
return $dataFromCache;
|
||||
}
|
||||
|
||||
$data = $this->_parse($input);
|
||||
|
@@ -90,8 +90,8 @@ class Shortcode
|
||||
if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) {
|
||||
$key = $this->getCacheID($input);
|
||||
|
||||
if ($data_from_cache = flextype('cache')->get($key)) {
|
||||
return $data_from_cache;
|
||||
if ($dataFromCache = flextype('cache')->get($key)) {
|
||||
return $dataFromCache;
|
||||
}
|
||||
|
||||
$data = $this->shortcode->process($input);
|
||||
|
@@ -48,8 +48,8 @@ class Frontmatter
|
||||
if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) {
|
||||
$key = $this->getCacheID($input);
|
||||
|
||||
if ($data_from_cache = flextype('cache')->get($key)) {
|
||||
return $data_from_cache;
|
||||
if ($dataFromCache = flextype('cache')->get($key)) {
|
||||
return $dataFromCache;
|
||||
}
|
||||
|
||||
$data = $this->_decode($input);
|
||||
|
@@ -62,8 +62,8 @@ class Json
|
||||
if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) {
|
||||
$key = $this->getCacheID($input);
|
||||
|
||||
if ($data_from_cache = flextype('cache')->get($key)) {
|
||||
return $data_from_cache;
|
||||
if ($dataFromCache = flextype('cache')->get($key)) {
|
||||
return $dataFromCache;
|
||||
}
|
||||
|
||||
$data = $this->_decode($input, $assoc, $depth, $flags);
|
||||
|
@@ -78,8 +78,8 @@ class Yaml
|
||||
if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) {
|
||||
$key = $this->getCacheID($input);
|
||||
|
||||
if ($data_from_cache = flextype('cache')->get($key)) {
|
||||
return $data_from_cache;
|
||||
if ($dataFromCache = flextype('cache')->get($key)) {
|
||||
return $dataFromCache;
|
||||
}
|
||||
|
||||
$data = $this->_decode($input, $flags);
|
||||
|
@@ -147,13 +147,13 @@ date_default_timezone_set(flextype('registry')->get('flextype.settings.timezone'
|
||||
*/
|
||||
$shortcodes = flextype('registry')->get('flextype.settings.shortcode.shortcodes');
|
||||
|
||||
foreach ($shortcodes as $shortcode_name => $shortcode) {
|
||||
$shortcode_file_path = ROOT_DIR . '/src/flextype/Support/Parsers/Shortcodes/' . str_replace('_', '', ucwords($shortcode_name, '_')) . 'Shortcode.php';
|
||||
if (! file_exists($shortcode_file_path)) {
|
||||
foreach ($shortcodes as $shortcodeName => $shortcode) {
|
||||
$shortcodeFilePath = ROOT_DIR . '/src/flextype/Support/Parsers/Shortcodes/' . str_replace('_', '', ucwords($shortcodeName, '_')) . 'Shortcode.php';
|
||||
if (! file_exists($shortcodeFilePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
include_once $shortcode_file_path;
|
||||
include_once $shortcodeFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,15 +161,15 @@ foreach ($shortcodes as $shortcode_name => $shortcode) {
|
||||
*
|
||||
* Load Flextype Entries fields from directory /flextype/Foundation/Entries/Fields/ based on flextype.settings.entries.fields array
|
||||
*/
|
||||
$entry_fields = flextype('registry')->get('flextype.settings.entries.fields');
|
||||
$entryFields = flextype('registry')->get('flextype.settings.entries.fields');
|
||||
|
||||
foreach ($entry_fields as $field_name => $field) {
|
||||
$entry_field_file_path = ROOT_DIR . '/src/flextype/Foundation/Entries/Fields/' . str_replace('_', '', ucwords($field_name, '_')) . 'Field.php';
|
||||
if (! file_exists($entry_field_file_path)) {
|
||||
foreach ($entryFields as $fieldName => $field) {
|
||||
$entryFieldFilePath = ROOT_DIR . '/src/flextype/Foundation/Entries/Fields/' . str_replace('_', '', ucwords($fieldName, '_')) . 'Field.php';
|
||||
if (! file_exists($entryFieldFilePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
include_once $entry_field_file_path;
|
||||
include_once $entryFieldFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -113,16 +113,16 @@ flextype()->container()['slugify'] = static function () {
|
||||
|
||||
|
||||
flextype()->container()['cache'] = static function () {
|
||||
$driver_name = flextype('registry')->get('flextype.settings.cache.driver');
|
||||
$driverName = flextype('registry')->get('flextype.settings.cache.driver');
|
||||
|
||||
$config = [];
|
||||
|
||||
function getDriverConfig(string $driver_name): array
|
||||
function getDriverConfig(string $driverName): array
|
||||
{
|
||||
$config = [];
|
||||
|
||||
foreach (flextype('registry')->get('flextype.settings.cache.drivers.' . $driver_name) as $key => $value) {
|
||||
if ($key === 'path' && in_array($driver_name, ['files', 'sqlite', 'leveldb'])) {
|
||||
foreach (flextype('registry')->get('flextype.settings.cache.drivers.' . $driverName) as $key => $value) {
|
||||
if ($key === 'path' && in_array($driverName, ['files', 'sqlite', 'leveldb'])) {
|
||||
$config['path'] = ! empty($value) ? PATH['tmp'] . '/' . $value : sys_get_temp_dir();
|
||||
} else {
|
||||
$config[strings($key)->camel()->toString()] = $value;
|
||||
@@ -132,93 +132,93 @@ flextype()->container()['cache'] = static function () {
|
||||
return $config;
|
||||
}
|
||||
|
||||
if (! $driver_name || $driver_name === 'auto') {
|
||||
if (! $driverName || $driverName === 'auto') {
|
||||
if (extension_loaded('apcu')) {
|
||||
$driver_name = 'apcu';
|
||||
$driverName = 'apcu';
|
||||
} elseif (extension_loaded('wincache')) {
|
||||
$driver_name = 'wincache';
|
||||
$driverName = 'wincache';
|
||||
} else {
|
||||
$driver_name = 'files';
|
||||
$driverName = 'files';
|
||||
}
|
||||
}
|
||||
|
||||
if (flextype('registry')->get('flextype.settings.cache.enabled') === false) {
|
||||
$driver_name = 'devnull';
|
||||
$driverName = 'devnull';
|
||||
}
|
||||
|
||||
switch ($driver_name) {
|
||||
switch ($driverName) {
|
||||
case 'apcu':
|
||||
$config = new Config(getDriverConfig($driver_name));
|
||||
$config = new Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'cassandra':
|
||||
$config = new \Phpfastcache\Drivers\Cassandra\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Cassandra\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'cookie':
|
||||
$config = new \Phpfastcache\Drivers\Cookie\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Cookie\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'couchbase':
|
||||
$config = new \Phpfastcache\Drivers\Couchbase\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Couchbase\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'couchdb':
|
||||
$config = new \Phpfastcache\Drivers\Couchdb\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Couchdb\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'devfalse':
|
||||
$config = new \Phpfastcache\Drivers\Devfalse\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Devfalse\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'devnull':
|
||||
$config = new \Phpfastcache\Drivers\Devnull\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Devnull\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'devtrue':
|
||||
$config = new \Phpfastcache\Drivers\Devtrue\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Devtrue\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'files':
|
||||
$config = new \Phpfastcache\Drivers\Files\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Files\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'leveldb':
|
||||
$config = new \Phpfastcache\Drivers\Leveldb\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Leveldb\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'memcache':
|
||||
$config = new \Phpfastcache\Drivers\Memcache\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Memcache\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'memcached':
|
||||
$config = new \Phpfastcache\Drivers\Memcached\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Memcached\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'memstatic':
|
||||
$config = new \Phpfastcache\Drivers\Memstatic\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Memstatic\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'mongodb':
|
||||
$config = new \Phpfastcache\Drivers\Mongodb\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Mongodb\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'predis':
|
||||
$config = new \Phpfastcache\Drivers\Predis\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Predis\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'redis':
|
||||
$config = new \Phpfastcache\Drivers\Redis\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Redis\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'riak':
|
||||
$config = new \Phpfastcache\Drivers\Riak\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Riak\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'sqlite':
|
||||
$config = new \Phpfastcache\Drivers\Sqlite\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Sqlite\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'ssdb':
|
||||
$config = new \Phpfastcache\Drivers\Ssdb\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Ssdb\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'wincache':
|
||||
$config = new \Phpfastcache\Drivers\Wincache\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Wincache\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'zenddisk':
|
||||
$config = new \Phpfastcache\Drivers\Zenddisk\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Zenddisk\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
case 'zendshm':
|
||||
$config = new \Phpfastcache\Drivers\Zendshm\Config(getDriverConfig($driver_name));
|
||||
$config = new \Phpfastcache\Drivers\Zendshm\Config(getDriverConfig($driverName));
|
||||
break;
|
||||
default:
|
||||
// code...
|
||||
break;
|
||||
}
|
||||
|
||||
return new Cache($driver_name, $config);
|
||||
return new Cache($driverName, $config);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -4,68 +4,68 @@ declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
|
||||
|
||||
$flextype_manifest_file_path = ROOT_DIR . '/src/flextype/flextype.yaml';
|
||||
$default_flextype_settings_file_path = ROOT_DIR . '/src/flextype/settings.yaml';
|
||||
$custom_flextype_settings_file_path = PATH['project'] . '/config/flextype/settings.yaml';
|
||||
$preflight_flextype_path = PATH['tmp'] . '/preflight/flextype/';
|
||||
$custom_flextype_settings_path = PATH['project'] . '/config/flextype/';
|
||||
$flextypeManifestFilePath = ROOT_DIR . '/src/flextype/flextype.yaml';
|
||||
$defaultFlextypeSettingsFilePath = ROOT_DIR . '/src/flextype/settings.yaml';
|
||||
$customFlextypeSettingsFilePath = PATH['project'] . '/config/flextype/settings.yaml';
|
||||
$preflightFlextypePath = PATH['tmp'] . '/preflight/flextype/';
|
||||
$customFlextypeSettingsPath = PATH['project'] . '/config/flextype/';
|
||||
|
||||
! filesystem()->directory($preflight_flextype_path)->exists() and filesystem()->directory($preflight_flextype_path)->create(0755, true);
|
||||
! filesystem()->directory($custom_flextype_settings_path)->exists() and filesystem()->directory($custom_flextype_settings_path)->create(0755, true);
|
||||
! filesystem()->directory($preflightFlextypePath)->exists() and filesystem()->directory($preflightFlextypePath)->create(0755, true);
|
||||
! filesystem()->directory($customFlextypeSettingsPath)->exists() and filesystem()->directory($customFlextypeSettingsPath)->create(0755, true);
|
||||
|
||||
$f1 = file_exists($flextype_manifest_file_path) ? filemtime($flextype_manifest_file_path) : '';
|
||||
$f2 = file_exists($default_flextype_settings_file_path) ? filemtime($default_flextype_settings_file_path) : '';
|
||||
$f3 = file_exists($custom_flextype_settings_file_path) ? filemtime($custom_flextype_settings_file_path) : '';
|
||||
$f1 = file_exists($flextypeManifestFilePath) ? filemtime($flextypeManifestFilePath) : '';
|
||||
$f2 = file_exists($defaultFlextypeSettingsFilePath) ? filemtime($defaultFlextypeSettingsFilePath) : '';
|
||||
$f3 = file_exists($customFlextypeSettingsFilePath) ? filemtime($customFlextypeSettingsFilePath) : '';
|
||||
|
||||
// Create Unique Cache ID
|
||||
$cache_id = md5($flextype_manifest_file_path . $default_flextype_settings_file_path . $custom_flextype_settings_file_path . $f1 . $f2 . $f3);
|
||||
$cacheID = md5($flextypeManifestFilePath . $defaultFlextypeSettingsFilePath . $customFlextypeSettingsFilePath . $f1 . $f2 . $f3);
|
||||
|
||||
if (filesystem()->file($preflight_flextype_path . '/' . $cache_id . '.txt')->exists()) {
|
||||
$flextype_data = unserialize(filesystem()->file($preflight_flextype_path . '/' . $cache_id . '.txt')->get());
|
||||
if (filesystem()->file($preflightFlextypePath . '/' . $cacheID . '.txt')->exists()) {
|
||||
$flextypeData = unserialize(filesystem()->file($preflightFlextypePath . '/' . $cacheID . '.txt')->get());
|
||||
} else {
|
||||
// Set settings if Flextype Default settings config files exist
|
||||
if (! filesystem()->file($default_flextype_settings_file_path)->exists()) {
|
||||
if (! filesystem()->file($defaultFlextypeSettingsFilePath)->exists()) {
|
||||
throw new RuntimeException('Flextype Default settings config file does not exist.');
|
||||
}
|
||||
|
||||
if (($default_flextype_settings_content = filesystem()->file($default_flextype_settings_file_path)->get()) === false) {
|
||||
throw new RuntimeException('Load file: ' . $default_flextype_settings_file_path . ' - failed!');
|
||||
if (($defaultFlextypeSettingsContent = filesystem()->file($defaultFlextypeSettingsFilePath)->get()) === false) {
|
||||
throw new RuntimeException('Load file: ' . $defaultFlextypeSettingsFilePath . ' - failed!');
|
||||
} else {
|
||||
if (trim($default_flextype_settings_content) === '') {
|
||||
$default_flextype_settings['settings'] = [];
|
||||
if (trim($defaultFlextypeSettingsContent) === '') {
|
||||
$defaultFlextypeSettings['settings'] = [];
|
||||
} else {
|
||||
$default_flextype_settings['settings'] = SymfonyYaml::parse($default_flextype_settings_content);
|
||||
$defaultFlextypeSettings['settings'] = SymfonyYaml::parse($defaultFlextypeSettingsContent);
|
||||
}
|
||||
}
|
||||
|
||||
// Create flextype custom settings file
|
||||
! filesystem()->file($custom_flextype_settings_file_path)->exists() and filesystem()->file($custom_flextype_settings_file_path)->put($default_flextype_settings_content);
|
||||
! filesystem()->file($customFlextypeSettingsFilePath)->exists() and filesystem()->file($customFlextypeSettingsFilePath)->put($defaultFlextypeSettingsContent);
|
||||
|
||||
if (($custom_flextype_settings_content = filesystem()->file($custom_flextype_settings_file_path)->get()) === false) {
|
||||
throw new RuntimeException('Load file: ' . $custom_flextype_settings_file_path . ' - failed!');
|
||||
if (($customFlextypeSettingsContent = filesystem()->file($customFlextypeSettingsFilePath)->get()) === false) {
|
||||
throw new RuntimeException('Load file: ' . $customFlextypeSettingsFilePath . ' - failed!');
|
||||
} else {
|
||||
if (trim($custom_flextype_settings_content) === '') {
|
||||
$custom_flextype_settings['settings'] = [];
|
||||
if (trim($customFlextypeSettingsContent) === '') {
|
||||
$customFlextypeSettings['settings'] = [];
|
||||
} else {
|
||||
$custom_flextype_settings['settings'] = SymfonyYaml::parse($custom_flextype_settings_content);
|
||||
$customFlextypeSettings['settings'] = SymfonyYaml::parse($customFlextypeSettingsContent);
|
||||
}
|
||||
}
|
||||
|
||||
if (($flextype_manifest_content = filesystem()->file($flextype_manifest_file_path)->get()) === false) {
|
||||
throw new RuntimeException('Load file: ' . $flextype_manifest_file_path . ' - failed!');
|
||||
if (($flextypeManifestContent = filesystem()->file($flextypeManifestFilePath)->get()) === false) {
|
||||
throw new RuntimeException('Load file: ' . $flextypeManifestFilePath . ' - failed!');
|
||||
} else {
|
||||
if (trim($flextype_manifest_content) === '') {
|
||||
$flextype_manifest['manifest'] = [];
|
||||
if (trim($flextypeManifestContent) === '') {
|
||||
$flextypeManifest['manifest'] = [];
|
||||
} else {
|
||||
$flextype_manifest['manifest'] = SymfonyYaml::parse($flextype_manifest_content);
|
||||
$flextypeManifest['manifest'] = SymfonyYaml::parse($flextypeManifestContent);
|
||||
}
|
||||
}
|
||||
|
||||
// Merge flextype default settings with custom project settings.
|
||||
$flextype_data = array_replace_recursive($default_flextype_settings, $custom_flextype_settings, $flextype_manifest);
|
||||
$flextypeData = array_replace_recursive($defaultFlextypeSettings, $customFlextypeSettings, $flextypeManifest);
|
||||
|
||||
filesystem()->file($preflight_flextype_path . $cache_id . '.txt')->put(serialize($flextype_data));
|
||||
filesystem()->file($preflightFlextypePath . $cacheID . '.txt')->put(serialize($flextypeData));
|
||||
}
|
||||
|
||||
// Store flextype merged data in the flextype registry.
|
||||
$registry->set('flextype', $flextype_data);
|
||||
$registry->set('flextype', $flextypeData);
|
||||
|
Reference in New Issue
Block a user