From 66ab7a142d6ff9f9071da8b095d7e60b4ccb3a71 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 8 Jan 2021 23:01:37 +0300 Subject: [PATCH 01/31] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8dc1892..52fd1122 100755 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ However, the amount of effort needed to maintain and develop new features for th You can support it's ongoing development by being a project backer or a sponsor: * [Become a backer or sponsor on Patreon](https://www.patreon.com/awilum). -* [One-time donation via PayPal, QIWI, Sberbank, Yandex](https://flextype.org/en/one-time-donation) +* [One-time donation via PayPal, QIWI, Sberbank](https://flextype.org/en/one-time-donation) * [Visit our Sponsors & Backers page](https://flextype.org/en/sponsors) ### PLATFORM CONTRIBUTIONS From 929a787d23564f46e66f6ff478dd46063ec4d0b3 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 12 Jan 2021 14:41:26 +0300 Subject: [PATCH 02/31] feat(parsers): add commonmark instead of parsedown #540 --- composer.json | 3 +- src/flextype/Support/Parsers/Markdown.php | 48 +++++++++++++++-------- src/flextype/settings.yaml | 15 +++++-- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 8d9dc155..d432e293 100755 --- a/composer.json +++ b/composer.json @@ -52,8 +52,7 @@ "bnf/slim3-psr15": "^1.1.1", - "erusev/parsedown": "^1.7.3", - "erusev/parsedown-extra": "^0.7.1", + "league/commonmark": "^1.5.7", "thunderer/shortcode": "^0.7.4", diff --git a/src/flextype/Support/Parsers/Markdown.php b/src/flextype/Support/Parsers/Markdown.php index 958651b5..b8759cbc 100644 --- a/src/flextype/Support/Parsers/Markdown.php +++ b/src/flextype/Support/Parsers/Markdown.php @@ -9,8 +9,11 @@ declare(strict_types=1); namespace Flextype\Support\Parsers; -use Exception; -use ParsedownExtra; +use League\CommonMark\CommonMarkConverter; +use League\CommonMark\Environment; +use League\CommonMark\Extension\Attributes\AttributesExtension; +use League\CommonMark\Extension\Table\TableExtension; +use League\CommonMark\Extension\Strikethrough\StrikethroughExtension; use function flextype; use function strings; @@ -27,9 +30,14 @@ final class Markdown private static $instances = []; /** - * Markdown facade + * Markdown Environment */ - private $markdownFacade = null; + private $environment = null; + + /** + * Markdown Converter + */ + private $converter = null; /** * Markdown should not be cloneable. @@ -49,25 +57,31 @@ final class Markdown /** * Markdown construct - * - * @param */ protected function __construct() { - $this->markdownFacade = new ParsedownExtra(); - $this->markdownFacade->setBreaksEnabled(flextype('registry')->get('flextype.settings.parsers.markdown.auto_line_breaks')); - $this->markdownFacade->setUrlsLinked(flextype('registry')->get('flextype.settings.parsers.markdown.auto_url_links')); - $this->markdownFacade->setMarkupEscaped(flextype('registry')->get('flextype.settings.parsers.markdown.escape_markup')); + $config = flextype('registry')->get('flextype.settings.parsers.markdown'); + $this->environment = Environment::createCommonMarkEnvironment(); + $this->environment->addExtension(new AttributesExtension()); + $this->environment->addExtension(new TableExtension()); + $this->environment->addExtension(new StrikethroughExtension()); + $this->converter = new CommonMarkConverter($config, $this->environment); } /** - * Markdown facade - * - * @param + * Markdown Environment */ - public function facade(): ParsedownExtra + public function environment(): Environment { - return $this->markdownFacade; + return $this->environment; + } + + /** + * Markdown Converter + */ + public function converter(): CommonMarkConverter + { + return $this->converter; } /** @@ -102,13 +116,13 @@ final class Markdown return $dataFromCache; } - $data = $this->facade()->text($input); + $data = $this->converter()->convertToHtml($input); flextype('cache')->set($key, $data); return $data; } - return $this->facade()->text($input); + return $this->converter()->convertToHtml($input); } /** diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 13a94a3f..bb53a68c 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -350,9 +350,18 @@ image: # - shortcodes: Flextype Shortcodes to load. parsers: markdown: - auto_line_breaks: false - auto_url_links: false - escape_markup: false + renderer: + block_separator: "\n" + inner_separator: "\n" + soft_break: "\n" + enable_em: true + enable_strong: true + use_asterisk: true + use_underscore: true + unordered_list_markers: ['-', '*', '+'] + html_input: 'allow' + allow_unsafe_links: false + max_nesting_level: INF shortcode: shortcodes: entries: From ecbfc588cbd4b82c0294e585ce217340759ed511 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 12 Jan 2021 14:46:52 +0300 Subject: [PATCH 03/31] update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f78c7f6a..1eeebf69 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +# [0.9.16](https://github.com/flextype/flextype/compare/v0.9.15...v0.9.16) (2020-01-xx) + +### Features + +* **parsers** add commonmark instead of parsedown ([#540](https://github.com/flextype/flextype/issues/540)) + # [0.9.15](https://github.com/flextype/flextype/compare/v0.9.14...v0.9.15) (2020-01-03) From e34aa85be53ee9a011122daec18ac77f66a13ea7 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 12 Jan 2021 14:53:56 +0300 Subject: [PATCH 04/31] feat(parsers): add commonmark instead of parsedown #540 --- src/flextype/Support/Parsers/Markdown.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/flextype/Support/Parsers/Markdown.php b/src/flextype/Support/Parsers/Markdown.php index b8759cbc..556ad465 100644 --- a/src/flextype/Support/Parsers/Markdown.php +++ b/src/flextype/Support/Parsers/Markdown.php @@ -13,7 +13,6 @@ use League\CommonMark\CommonMarkConverter; use League\CommonMark\Environment; use League\CommonMark\Extension\Attributes\AttributesExtension; use League\CommonMark\Extension\Table\TableExtension; -use League\CommonMark\Extension\Strikethrough\StrikethroughExtension; use function flextype; use function strings; @@ -64,7 +63,6 @@ final class Markdown $this->environment = Environment::createCommonMarkEnvironment(); $this->environment->addExtension(new AttributesExtension()); $this->environment->addExtension(new TableExtension()); - $this->environment->addExtension(new StrikethroughExtension()); $this->converter = new CommonMarkConverter($config, $this->environment); } From 141dcc603bb6e868042f9dee952525533b62a0ca Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 12 Jan 2021 15:13:05 +0300 Subject: [PATCH 05/31] feat(parsers): add commonmark instead of parsedown #540 --- src/flextype/Support/Parsers/Markdown.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flextype/Support/Parsers/Markdown.php b/src/flextype/Support/Parsers/Markdown.php index 556ad465..375dc07d 100644 --- a/src/flextype/Support/Parsers/Markdown.php +++ b/src/flextype/Support/Parsers/Markdown.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace Flextype\Support\Parsers; +use Exception; use League\CommonMark\CommonMarkConverter; use League\CommonMark\Environment; use League\CommonMark\Extension\Attributes\AttributesExtension; From 533c9991d5c607617647368da049c9d2124e09b3 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 12 Jan 2021 15:21:38 +0300 Subject: [PATCH 06/31] feat(parsers): add commonmark instead of parsedown #540 --- tests/Foundation/Entries/Fields/ParsersFieldTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Foundation/Entries/Fields/ParsersFieldTest.php b/tests/Foundation/Entries/Fields/ParsersFieldTest.php index b7d92fcf..d8d44702 100644 --- a/tests/Foundation/Entries/Fields/ParsersFieldTest.php +++ b/tests/Foundation/Entries/Fields/ParsersFieldTest.php @@ -11,8 +11,8 @@ afterEach(function (): void { }); test('test ParsersField', function () { - flextype('entries')->create('foo', ['content' => '#Foo', 'parsers' => ['markdown' => ['enabled' => true, 'fields' => ['content']]]]); - $this->assertEquals('

Foo

', flextype('entries')->fetch('foo')['content']); + flextype('entries')->create('foo', ['content' => '# Foo', 'parsers' => ['markdown' => ['enabled' => true, 'fields' => ['content']]]]); + $this->assertEquals(trim('

Foo

'), trim(flextype('entries')->fetch('foo')['content'])); flextype('entries')->create('bar', ['content' => '[registry_get name="Bar" default="Zed"]', 'parsers' => ['shortcode' => ['enabled' => true, 'fields' => ['content']]]]); $this->assertEquals('Zed', flextype('entries')->fetch('bar')['content']); From f550e9753512cf6237149151f6f6ac841f2119b3 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 12 Jan 2021 18:18:31 +0300 Subject: [PATCH 07/31] feat(media): move images settings into media.images settings #541 --- src/flextype/Foundation/Media/MediaFiles.php | 22 +++++++++++--------- src/flextype/dependencies.php | 2 +- src/flextype/settings.yaml | 22 +++++++------------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/flextype/Foundation/Media/MediaFiles.php b/src/flextype/Foundation/Media/MediaFiles.php index 5f59c021..58287258 100644 --- a/src/flextype/Foundation/Media/MediaFiles.php +++ b/src/flextype/Foundation/Media/MediaFiles.php @@ -85,8 +85,8 @@ class MediaFiles $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'); + $maxImageWidth = flextype('registry')->get('flextype.settings.media.images.max_image_width'); + $maxImageHeight = flextype('registry')->get('flextype.settings.media.images.max_image_height'); $exact = false; $chmod = 0644; @@ -149,29 +149,30 @@ class MediaFiles chmod($filename, $chmod); if (in_array(mime_content_type($filename), ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'])) { + // open an image file $img = Image::make($filename); // now you are able to resize the instance - if (flextype('registry')->get('flextype.settings.media.image_width') > 0 && flextype('registry')->get('flextype.settings.media.image_height') > 0) { - $img->resize(flextype('registry')->get('flextype.settings.media.image_width'), flextype('registry')->get('flextype.settings.media.image_height'), static function ($constraint): void { + if (flextype('registry')->get('flextype.settings.media.images.image_width') > 0 && flextype('registry')->get('flextype.settings.media.images.image_height') > 0) { + $img->resize(flextype('registry')->get('flextype.settings.media.images.image_width'), flextype('registry')->get('flextype.settings.media.images.image_height'), static function ($constraint): void { $constraint->aspectRatio(); $constraint->upsize(); }); - } elseif (flextype('registry')->get('flextype.settings.media.image_width') > 0) { - $img->resize(flextype('registry')->get('flextype.settings.media.image_width'), null, static function ($constraint): void { + } elseif (flextype('registry')->get('flextype.settings.media.images.image_width') > 0) { + $img->resize(flextype('registry')->get('flextype.settings.media.images.image_width'), null, static function ($constraint): void { $constraint->aspectRatio(); $constraint->upsize(); }); - } elseif (flextype('registry')->get('flextype.settings.media.image_height') > 0) { - $img->resize(null, flextype('registry')->get('flextype.settings.media.image_height'), static function ($constraint): void { + } elseif (flextype('registry')->get('flextype.settings.media.images.image_height') > 0) { + $img->resize(null, flextype('registry')->get('flextype.settings.media.images.image_height'), static function ($constraint): void { $constraint->aspectRatio(); $constraint->upsize(); }); } // finally we save the image as a new file - $img->save($filename, flextype('registry')->get('flextype.settings.media.image_quality')); + $img->save($filename, flextype('registry')->get('flextype.settings.media.images.image_quality')); // destroy $img->destroy(); @@ -233,7 +234,8 @@ class MediaFiles isset($options['collection']) && strings($options['collection'])->isTrue() ) { - $result = []; + + $result = []; foreach (filesystem()->find()->files()->in(flextype('media')->folders()->meta()->getDirectoryMetaLocation($id)) as $file) { $basename = $file->getBasename('.' . $file->getExtension()); diff --git a/src/flextype/dependencies.php b/src/flextype/dependencies.php index 25980428..f79e0060 100644 --- a/src/flextype/dependencies.php +++ b/src/flextype/dependencies.php @@ -220,7 +220,7 @@ flextype()->container()['serializers'] = fn() => new Serializers(); */ flextype()->container()['images'] = static function () { // Get images settings - $imagesSettings = ['driver' => flextype('registry')->get('flextype.settings.image.driver')]; + $imagesSettings = ['driver' => flextype('registry')->get('flextype.settings.media.image.driver')]; // Set source filesystem $source = new Flysystem( diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index bb53a68c..94192852 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -333,18 +333,8 @@ slugify: lowercase_after_regexp: false strip_tags: false -# Image -# -# - driver: gd or imagick -image: - driver: gd - # Markdown # -# - markdown.auto_line_breaks: Enable automatic line breaks -# - markdown.auto_url_links: Enable automatic HTML links -# - markdown.escape_markup: Escape markup tags into entities -# # Shortcode # # - shortcodes: Flextype Shortcodes to load. @@ -418,11 +408,13 @@ media: accept_file_types: 'gif, jpg, jpeg, png, ico, zip, tgz, txt, md, doc, docx, pdf, epub, xls, xlsx, ppt, pptx, mp3, ogg, wav, m4a, mp4, m4v, ogv, wmv, avi, webm, svg' max_file_size: 8000000 safe_names: true - image_width: 1600 - image_height: 0 - image_quality: 70 - max_image_width: null - max_image_height: null + images: + driver: gd + image_width: 1600 + image_height: 0 + image_quality: 70 + max_image_width: null + max_image_height: null # Session # From 51117905ab1af089c04e30f4fb3d76e519a3d49f Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 00:31:08 +0300 Subject: [PATCH 08/31] feat(tests): add tests for dependencies --- tests/DependenciesTest.php | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/DependenciesTest.php diff --git a/tests/DependenciesTest.php b/tests/DependenciesTest.php new file mode 100644 index 00000000..5b6ded0b --- /dev/null +++ b/tests/DependenciesTest.php @@ -0,0 +1,7 @@ +assertInstanceOf(Atomastic\Session\Session::class, flextype()->container('session')); +}); From 54217ec81511bc3c6f308926bffded01773be9ea Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 11:05:03 +0300 Subject: [PATCH 09/31] refactor(media): fix PHPDoc @return for fetch() methods --- src/flextype/Foundation/Media/MediaFiles.php | 2 +- src/flextype/Foundation/Media/MediaFolders.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/flextype/Foundation/Media/MediaFiles.php b/src/flextype/Foundation/Media/MediaFiles.php index 58287258..06183f78 100644 --- a/src/flextype/Foundation/Media/MediaFiles.php +++ b/src/flextype/Foundation/Media/MediaFiles.php @@ -221,7 +221,7 @@ class MediaFiles * @param string $id The path to file. * @param array $options Options array. * - * @return self Returns instance of The Arrays class. + * @return Arrays Returns instance of The Arrays class. * * @access public */ diff --git a/src/flextype/Foundation/Media/MediaFolders.php b/src/flextype/Foundation/Media/MediaFolders.php index 22c8e698..1535031f 100644 --- a/src/flextype/Foundation/Media/MediaFolders.php +++ b/src/flextype/Foundation/Media/MediaFolders.php @@ -39,7 +39,7 @@ class MediaFolders * @param string $id The path to folder. * @param array $options Options array. * - * @return self Returns instance of The Arrays class. + * @return Arrays Returns instance of The Arrays class. * * @access public */ From 7960cf26087864ffd01b0bd8f97bbba35303372d Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 12:11:22 +0300 Subject: [PATCH 10/31] refactor(markdown): fix PHPDoc @param for getInstance() method --- src/flextype/Support/Parsers/Markdown.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/flextype/Support/Parsers/Markdown.php b/src/flextype/Support/Parsers/Markdown.php index 375dc07d..bb2c4c3b 100644 --- a/src/flextype/Support/Parsers/Markdown.php +++ b/src/flextype/Support/Parsers/Markdown.php @@ -85,8 +85,6 @@ final class Markdown /** * Returns Markdown Instance - * - * @param */ public static function getInstance(): Markdown { From 8731e89c04d2d39dd64168fdc48d93add6b0977c Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 12:15:12 +0300 Subject: [PATCH 11/31] refactor(markdown): fix PHPDoc @param for parse() method --- src/flextype/Support/Parsers/Markdown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flextype/Support/Parsers/Markdown.php b/src/flextype/Support/Parsers/Markdown.php index bb2c4c3b..490f4e9b 100644 --- a/src/flextype/Support/Parsers/Markdown.php +++ b/src/flextype/Support/Parsers/Markdown.php @@ -104,7 +104,7 @@ final class Markdown * * @return mixed The MARKDOWN converted to a PHP value */ - public function parse(string $input, bool $cache = true): string + public function parse(string $input, bool $cache = true) { if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) { $key = $this->getCacheID($input); From 8d500d9a087543207eb506635cb1e459c9370696 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 12:18:53 +0300 Subject: [PATCH 12/31] refactor(json): fix PHPDoc tag @return with type mixed is not subtype of native type string. --- src/flextype/Support/Serializers/Json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flextype/Support/Serializers/Json.php b/src/flextype/Support/Serializers/Json.php index 3944b8f1..673789e2 100644 --- a/src/flextype/Support/Serializers/Json.php +++ b/src/flextype/Support/Serializers/Json.php @@ -39,7 +39,7 @@ class Json * * @return mixed A JSON string representing the original PHP value */ - public function encode($input, int $options = 0, int $depth = 512): string + public function encode($input, int $options = 0, int $depth = 512) { $options = ($options & self::ESCAPE_UNICODE ? 0 : JSON_UNESCAPED_UNICODE) | JSON_UNESCAPED_SLASHES From 202ad75482f93f66347ba43b2028732c25acac06 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 12:20:06 +0300 Subject: [PATCH 13/31] refactor(json): fix PHPDoc tag @throws with type Flextype\Support\Serializers\ParseException is not subtype of Throwable --- src/flextype/Support/Serializers/Json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flextype/Support/Serializers/Json.php b/src/flextype/Support/Serializers/Json.php index 673789e2..4f43e9ce 100644 --- a/src/flextype/Support/Serializers/Json.php +++ b/src/flextype/Support/Serializers/Json.php @@ -66,7 +66,7 @@ class Json * * @return mixed The JSON converted to a PHP value * - * @throws ParseException If the JSON is not valid + * @throws RuntimeException If the JSON is not valid */ public function decode(string $input, bool $cache = true, bool $assoc = true, int $depth = 512, int $flags = 0) { From 084959dab42a8c726d03bee2d6988fac9d93c9bb Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 12:25:36 +0300 Subject: [PATCH 14/31] refactor(yaml): fix PHPDoc tag @throws with type Flextype\Support\Serializers\ParseException is not subtype of Throwable --- src/flextype/Support/Serializers/Yaml.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flextype/Support/Serializers/Yaml.php b/src/flextype/Support/Serializers/Yaml.php index 0b3ca84d..1f636c12 100644 --- a/src/flextype/Support/Serializers/Yaml.php +++ b/src/flextype/Support/Serializers/Yaml.php @@ -80,7 +80,7 @@ class Yaml * * @return mixed The YAML converted to a PHP value * - * @throws ParseException If the YAML is not valid + * @throws RuntimeException If the YAML is not valid */ public function decode(string $input, bool $cache = true, int $flags = 0): array { From cd0c37eff25a81c06bab0ecf17f9823aae189d92 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 12:26:30 +0300 Subject: [PATCH 15/31] refactor(yaml): fix PHPDoc tag @return with type mixed is not subtype of native type array. --- src/flextype/Support/Serializers/Yaml.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flextype/Support/Serializers/Yaml.php b/src/flextype/Support/Serializers/Yaml.php index 1f636c12..6280885f 100644 --- a/src/flextype/Support/Serializers/Yaml.php +++ b/src/flextype/Support/Serializers/Yaml.php @@ -82,7 +82,7 @@ class Yaml * * @throws RuntimeException If the YAML is not valid */ - public function decode(string $input, bool $cache = true, int $flags = 0): array + public function decode(string $input, bool $cache = true, int $flags = 0) { $decode = function (string $input, int $flags = 0) { // Try native PECL YAML PHP extension first if available. From 86a42ee2c35df36d0e144d8a77267e142642742f Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 13:42:53 +0300 Subject: [PATCH 16/31] refactor(phpstan): set level 3 --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index aa8255cc..9e85587b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 0 + level: 3 reportUnmatchedIgnoredErrors: false paths: - src From 5096c0d51355265ed561756b721ec5c71abeafac Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:12:35 +0300 Subject: [PATCH 17/31] feat(shortcodes): add new shortcode - media_files_fetch example: [media_files_fetch id="foo.txt" field="title" default="Bar"] --- .../Parsers/Shortcodes/MediaShortcode.php | 17 ++++++++++++++ src/flextype/settings.yaml | 2 ++ .../Parsers/Shortcodes/MediaShortcodeTest.php | 23 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/flextype/Support/Parsers/Shortcodes/MediaShortcode.php create mode 100644 tests/Support/Parsers/Shortcodes/MediaShortcodeTest.php diff --git a/src/flextype/Support/Parsers/Shortcodes/MediaShortcode.php b/src/flextype/Support/Parsers/Shortcodes/MediaShortcode.php new file mode 100644 index 00000000..0375212f --- /dev/null +++ b/src/flextype/Support/Parsers/Shortcodes/MediaShortcode.php @@ -0,0 +1,17 @@ +get('flextype.settings.parsers.shortcode.shortcodes.media.enabled')) { + flextype('parsers')->shortcode()->addHandler('media_files_fetch', static function (ShortcodeInterface $s) { + return arrays(flextype('media')->files()->fetch($s->getParameter('id')))->get($s->getParameter('field'), $s->getParameter('default')); + }); +} diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 94192852..c10e20e8 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -354,6 +354,8 @@ parsers: max_nesting_level: INF shortcode: shortcodes: + media: + enabled: true entries: enabled: true raw: diff --git a/tests/Support/Parsers/Shortcodes/MediaShortcodeTest.php b/tests/Support/Parsers/Shortcodes/MediaShortcodeTest.php new file mode 100644 index 00000000..6e4c1b79 --- /dev/null +++ b/tests/Support/Parsers/Shortcodes/MediaShortcodeTest.php @@ -0,0 +1,23 @@ +directory(PATH['project'] . '/media')->create(0755, true); + filesystem()->directory(PATH['project'] . '/media/.meta')->create(0755, true); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/media/.meta')->delete(); + filesystem()->directory(PATH['project'] . '/media')->delete(); +}); + +test('test media_files_fetch shortcode', function () { + filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo'); + filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('serializers')->yaml()->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []])); + filesystem()->file(PATH['project'] . '/media/bar.txt')->put('foo'); + filesystem()->file(PATH['project'] . '/media/.meta/bar.txt.yaml')->put(flextype('serializers')->yaml()->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []])); + + $this->assertEquals('Foo', flextype('parsers')->shortcode()->process('[media_files_fetch id="foo.txt" field="title"]')); + $this->assertEquals('Bar', flextype('parsers')->shortcode()->process('[media_files_fetch id="foo.txt" field="foo" default="Bar"]')); +}); From 7cd880a14dc31b367307dacdcfc1201ba3104645 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:21:03 +0300 Subject: [PATCH 18/31] update CHANGELOG.md --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eeebf69..e567eda5 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ ### Features * **parsers** add commonmark instead of parsedown ([#540](https://github.com/flextype/flextype/issues/540)) +* **shortcodes** add new shortcode - media_files_fetch + + example: + + ``` + [media_files_fetch id="foo.txt" field="title" default="Bar"] + ``` + +### Refactoring + +* **core** general code refactoring and improvements. # [0.9.15](https://github.com/flextype/flextype/compare/v0.9.14...v0.9.15) (2020-01-03) From 6e7b99c5e6c80aebe6a169bf4991e128e7c897da Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:22:57 +0300 Subject: [PATCH 19/31] feat(tests): remove tests for dependencies --- tests/DependenciesTest.php | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 tests/DependenciesTest.php diff --git a/tests/DependenciesTest.php b/tests/DependenciesTest.php deleted file mode 100644 index 5b6ded0b..00000000 --- a/tests/DependenciesTest.php +++ /dev/null @@ -1,7 +0,0 @@ -assertInstanceOf(Atomastic\Session\Session::class, flextype()->container('session')); -}); From 3a5ce4000226d950bfc4e2e190f85cb4de17b625 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:25:30 +0300 Subject: [PATCH 20/31] feat(composer): update phpfastcache/phpfastcache to 8.0.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d432e293..6b5765f3 100755 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "league/event": "^2.2.0", "league/glide": "^1.7.0", - "phpfastcache/phpfastcache": "^8.0.3", + "phpfastcache/phpfastcache": "^8.0.4", "respect/validation": "^2.1.0", "monolog/monolog": "^2.1.1", From b078cb2ba2c8fa7b5ab7202c8103709bf05be9dc Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:27:19 +0300 Subject: [PATCH 21/31] feat(composer): update monolog/monolog to 2.2.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6b5765f3..11c99b2b 100755 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "phpfastcache/phpfastcache": "^8.0.4", "respect/validation": "^2.1.0", - "monolog/monolog": "^2.1.1", + "monolog/monolog": "^2.2.0", "cocur/slugify": "^4.0.0", "ramsey/uuid": "^4.1.1", "symfony/yaml": "^5.2.0", From 0caf76e44af58b3b318f74be9b2ff930c9d33bb8 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:28:06 +0300 Subject: [PATCH 22/31] feat(composer): update symfony/yaml to 5.2.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 11c99b2b..c59937eb 100755 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "monolog/monolog": "^2.2.0", "cocur/slugify": "^4.0.0", "ramsey/uuid": "^4.1.1", - "symfony/yaml": "^5.2.0", + "symfony/yaml": "^5.2.1", "symfony/finder": "^5.2.0", "bnf/slim3-psr15": "^1.1.1", From 6beb2b8b7b1364da8b18d27b7beb0d8b86dace63 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:28:37 +0300 Subject: [PATCH 23/31] feat(composer): update symfony/finder to 5.2.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c59937eb..2fcb8876 100755 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "cocur/slugify": "^4.0.0", "ramsey/uuid": "^4.1.1", "symfony/yaml": "^5.2.1", - "symfony/finder": "^5.2.0", + "symfony/finder": "^5.2.1", "bnf/slim3-psr15": "^1.1.1", From 009d48c3b72c3ccfdb8ed11eb4196c71d3ec5690 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:30:10 +0300 Subject: [PATCH 24/31] feat(composer): update pestphp/pest to 1.0.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2fcb8876..c08bf8ee 100755 --- a/composer.json +++ b/composer.json @@ -77,7 +77,7 @@ }, "require-dev": { "doctrine/coding-standard": "8.1.0", - "pestphp/pest": "^0.3.3", + "pestphp/pest": "^1.0.0", "phpstan/phpstan": "^0.12.42", "symfony/var-dumper": "^5.1.5", "victorjonsson/markdowndocs": "^1.3.8" From 30a0dd5262ddbd208ca6732f378afb8a65133867 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:30:55 +0300 Subject: [PATCH 25/31] feat(composer): update phpstan/phpstan to 0.12.66 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c08bf8ee..0dbb1f3d 100755 --- a/composer.json +++ b/composer.json @@ -78,7 +78,7 @@ "require-dev": { "doctrine/coding-standard": "8.1.0", "pestphp/pest": "^1.0.0", - "phpstan/phpstan": "^0.12.42", + "phpstan/phpstan": "^0.12.66", "symfony/var-dumper": "^5.1.5", "victorjonsson/markdowndocs": "^1.3.8" } From cc9410ded29e225642f9c0b04dcf034924ddcd1c Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:31:26 +0300 Subject: [PATCH 26/31] feat(composer): update doctrine/coding-standard to 8.2.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0dbb1f3d..7d4f8483 100755 --- a/composer.json +++ b/composer.json @@ -76,7 +76,7 @@ ] }, "require-dev": { - "doctrine/coding-standard": "8.1.0", + "doctrine/coding-standard": "8.2.0", "pestphp/pest": "^1.0.0", "phpstan/phpstan": "^0.12.66", "symfony/var-dumper": "^5.1.5", From 9572d403f22f2cceb18bf0462dedd579155ae9a4 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 14:32:21 +0300 Subject: [PATCH 27/31] feat(composer): update symfony/var-dumper to 5.2.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7d4f8483..ec99f4df 100755 --- a/composer.json +++ b/composer.json @@ -79,7 +79,7 @@ "doctrine/coding-standard": "8.2.0", "pestphp/pest": "^1.0.0", "phpstan/phpstan": "^0.12.66", - "symfony/var-dumper": "^5.1.5", + "symfony/var-dumper": "^5.2.1", "victorjonsson/markdowndocs": "^1.3.8" } } From a21077678ea983f2ff5a8e4ee163ff4263fcb0d4 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 13 Jan 2021 17:05:39 +0300 Subject: [PATCH 28/31] refactor(plugins): fix PHPDoc @access --- src/flextype/Foundation/Plugins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/flextype/Foundation/Plugins.php b/src/flextype/Foundation/Plugins.php index 972b9c26..99a38eef 100755 --- a/src/flextype/Foundation/Plugins.php +++ b/src/flextype/Foundation/Plugins.php @@ -190,7 +190,7 @@ class Plugins * * @param array $pluginsList Plugins list * - * @access private + * @access public */ public function getPluginsDictionary(array $pluginsList, string $locale): array { @@ -218,7 +218,7 @@ class Plugins * * @param array $pluginsList Plugins list * - * @access private + * @access public */ public function getPluginsCacheID(array $pluginsList): string { From 9ee67bc3b383f4f7c5e57632e3e4f7c8eae5fd47 Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 14 Jan 2021 11:59:47 +0300 Subject: [PATCH 29/31] fix(bootstrap): fix include path for dependencies --- src/flextype/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flextype/bootstrap.php b/src/flextype/bootstrap.php index 61c0d870..c39e2fa7 100755 --- a/src/flextype/bootstrap.php +++ b/src/flextype/bootstrap.php @@ -103,7 +103,7 @@ if ($registry->get('flextype.settings.errors.display')) { /** * Include Dependencies */ -include_once 'dependencies.php'; +include_once ROOT_DIR . '/src/flextype/dependencies.php'; /** * Set session options before you start the session From 64518ee066bba3ad55c68946c8501f13a4b89882 Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 14 Jan 2021 12:01:08 +0300 Subject: [PATCH 30/31] update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e567eda5..3d9fd454 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ [media_files_fetch id="foo.txt" field="title" default="Bar"] ``` +### Bug Fixes + +* **bootstrap** fix include path for dependencies. + ### Refactoring * **core** general code refactoring and improvements. From 5d843641ccacb1d5356e54222814dd8740de4a07 Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 14 Jan 2021 22:49:43 +0300 Subject: [PATCH 31/31] Flextype 0.9.16 --- CHANGELOG.md | 4 ++-- src/flextype/Foundation/Flextype.php | 2 +- src/flextype/flextype.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d9fd454..f5428abe 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -# [0.9.16](https://github.com/flextype/flextype/compare/v0.9.15...v0.9.16) (2020-01-xx) +# [0.9.16](https://github.com/flextype/flextype/compare/v0.9.15...v0.9.16) (2020-01-14) ### Features @@ -9,7 +9,7 @@ example: ``` - [media_files_fetch id="foo.txt" field="title" default="Bar"] + [media_files_fetch id="entries/home/foo.txt" field="title" default="Bar"] ``` ### Bug Fixes diff --git a/src/flextype/Foundation/Flextype.php b/src/flextype/Foundation/Flextype.php index 7be6ee4f..fd570cec 100644 --- a/src/flextype/Foundation/Flextype.php +++ b/src/flextype/Foundation/Flextype.php @@ -22,7 +22,7 @@ final class Flextype extends App /** * Flextype version */ - public const VERSION = '0.9.15'; + public const VERSION = '0.9.16'; /** * The Flextype's instance is stored in a static field. This field is an diff --git a/src/flextype/flextype.yaml b/src/flextype/flextype.yaml index cd432d16..64889bc4 100644 --- a/src/flextype/flextype.yaml +++ b/src/flextype/flextype.yaml @@ -1,5 +1,5 @@ name: Flextype -version: 0.9.15 +version: 0.9.16 description: Hybrid Content Management System author: name: Sergey Romanenko