From 94f0bb0f56723e540355cef1cacf51ddf1056a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20=C3=85str=C3=B6m?= Date: Sat, 7 Sep 2019 14:26:50 +0200 Subject: [PATCH 001/287] One viewport is enough. --- resources/stubs/addons/resources/views/partials/metadata.twig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resources/stubs/addons/resources/views/partials/metadata.twig b/resources/stubs/addons/resources/views/partials/metadata.twig index 97fdf2816..1a398c843 100644 --- a/resources/stubs/addons/resources/views/partials/metadata.twig +++ b/resources/stubs/addons/resources/views/partials/metadata.twig @@ -4,7 +4,7 @@ Any other head element should come *after* these tags. #} - + @@ -15,7 +15,6 @@ - {{ template.includes.render('meta')|raw }} From 109186838d200696f7c01e93bec3b21415cd3a6d Mon Sep 17 00:00:00 2001 From: edster Date: Thu, 24 Oct 2019 13:37:43 -0700 Subject: [PATCH 002/287] Add docs on how to extend the ajax form data. Add docs on how to extend the ajax form data. --- docs/en/07.ui/01.forms/02.configuration/07.ajax.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/en/07.ui/01.forms/02.configuration/07.ajax.md b/docs/en/07.ui/01.forms/02.configuration/07.ajax.md index f954612a6..34f04d06c 100644 --- a/docs/en/07.ui/01.forms/02.configuration/07.ajax.md +++ b/docs/en/07.ui/01.forms/02.configuration/07.ajax.md @@ -20,6 +20,11 @@ You can also flag forms as ajax on the fly. $builder->setAjax(true); ``` +## Custom Data + +You can easily add custom data to the JSON response by adding `public function onJsonResponse($data){}` to your form builder. This will allow you to modify the array before it being set in the form response. + + Ajax forms are designed to be included in a modal by default but you can configure it to display using options or however you like. > **In Development:** The Ajax API is still being developed. While ajax forms are usable, more robust JSON response information is still missing.{.note} From 1e48164ca700cff8885bfbddc8c507e33e34a6a1 Mon Sep 17 00:00:00 2001 From: Michal Haracewiat Date: Fri, 25 Oct 2019 12:55:31 +0200 Subject: [PATCH 003/287] Fix the point default Script attends to load wrong config option. Assuming the dot (.) is a defualt value. --- src/Support/Currency.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Support/Currency.php b/src/Support/Currency.php index 27d5ff736..a26b73046 100644 --- a/src/Support/Currency.php +++ b/src/Support/Currency.php @@ -40,7 +40,7 @@ public function format($number, $currency = null, array $options = []) $point = array_get( $options, 'point', - config('streams::currencies.supported.' . $currency . '.point' . '.') + config('streams::currencies.supported.' . $currency . '.point', '.') ); $prefix = null; @@ -80,7 +80,7 @@ public function normalize($number, $currency = null, array $options = []) $point = array_get( $options, 'point', - config('streams::currencies.supported.' . $currency . '.point' . '.') + config('streams::currencies.supported.' . $currency . '.point', '.') ); return number_format(floor(($number * 100)) / 100, $decimals, $point, $separator); From 1d61b84acb1119cbc126d8bf17426961cb9cc83e Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Mon, 28 Oct 2019 14:01:34 -0500 Subject: [PATCH 004/287] Add ID support to field type attributes. --- docs/en/01.prologue/02.change-log.md | 5 +++++ resources/views/form/partials/wrapper.twig | 6 ++---- src/Addon/FieldType/FieldType.php | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/en/01.prologue/02.change-log.md b/docs/en/01.prologue/02.change-log.md index f87b9ea5c..ef725bc80 100644 --- a/docs/en/01.prologue/02.change-log.md +++ b/docs/en/01.prologue/02.change-log.md @@ -29,6 +29,11 @@ Features that are deprecated will generally be removed in the next `minor` updat ## Releases +### [1.6.179] - 2019-10-28 +#### Added +- Added IDs to default field type attributes. + + ### [1.6.178] - 2019-10-22 #### Fixed - Fix custom error message field prefixes: https://github.com/anomalylabs/streams-platform/pull/673 diff --git a/resources/views/form/partials/wrapper.twig b/resources/views/form/partials/wrapper.twig index b095ed5db..ed9076b16 100644 --- a/resources/views/form/partials/wrapper.twig +++ b/resources/views/form/partials/wrapper.twig @@ -1,6 +1,4 @@ -
{% if field_type.object.label != false and field_type.config.disable_label != true %} -
{% endif %} @@ -35,7 +35,7 @@ {% for message in message_pull('warning') %} - {{ trans(message)|markdown }} + {{ trans(message) }} {% endfor %} {% endif %} @@ -49,7 +49,7 @@ {% for message in message_pull('error') %} - {{ trans(message)|markdown }} + {{ trans(message) }} {% endfor %} {% endif %} diff --git a/src/StreamsPlugin.php b/src/StreamsPlugin.php index c2d531de8..e1d7d908a 100644 --- a/src/StreamsPlugin.php +++ b/src/StreamsPlugin.php @@ -15,7 +15,6 @@ use Anomaly\Streams\Platform\Support\Decorator; use Anomaly\Streams\Platform\Support\Length; use Anomaly\Streams\Platform\Support\Locale; -use Anomaly\Streams\Platform\Support\Markdown; use Anomaly\Streams\Platform\Support\Str; use Anomaly\Streams\Platform\Support\Template; use Anomaly\Streams\Platform\Support\Value; @@ -716,13 +715,6 @@ function () { ); } ), - new \Twig_SimpleFilter( - 'markdown', - function ($content) { - return (new Markdown())->parse($content); - }, - ['is_safe' => ['html']] - ), new \Twig_SimpleFilter( 'str_*', function ($name) { diff --git a/src/Support/Markdown.php b/src/Support/Markdown.php index 964e0b15b..1c404d1ef 100644 --- a/src/Support/Markdown.php +++ b/src/Support/Markdown.php @@ -7,80 +7,7 @@ * @author PyroCMS, Inc. * @author Ryan Thompson */ -class Markdown extends \ParsedownExtra +class Markdown { - /** - * Custom attributes on block quotes. - * - * @param $line - * @return array - */ - protected function blockQuote($line) - { - $quote = parent::blockQuote($line); - - if (!isset($quote['element']['text'][0])) { - return $quote; - } - - if (preg_match( - '/[ #]*{(' . $this->regexAttribute . '+)}[ ]*$/', - $quote['element']['text'][0], - $matches, - PREG_OFFSET_CAPTURE - )) { - - if (!isset($matches[1][0])) { - return $quote; - } - - $attributeString = $matches[1][0]; - - $quote['element']['attributes'] = $this->parseAttributeData($attributeString); - - $quote['element']['text'][0] = substr($quote['element']['text'][0], 0, $matches[0][1]); - } - - return $quote; - } - - /** - * Custom attributes on block quotes. - * - * @param $excerpt - * @return array - */ - protected function inlineLink($excerpt) - { - try { - $link = parent::inlineLink($excerpt); - } catch (\ErrorException $e) { - return; - } - - if (!isset($link['element']['text'][0])) { - return $link; - } - - if (preg_match( - '/[ #]*{(' . $this->regexAttribute . '+)}[ ]*$/', - $link['element']['text'][0], - $matches, - PREG_OFFSET_CAPTURE - )) { - - if (!isset($matches[1][0])) { - return $link; - } - - $attributeString = $matches[1][0]; - - $link['element']['attributes'] = $this->parseAttributeData($attributeString); - - $link['element']['text'][0] = substr($link['element']['text'][0], 0, $matches[0][1]); - } - - return $link; - } } From f720925ba0cdeb055b1413fafbb30025a3772fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20AKDO=C4=9EAN?= <39536659+spektra2147@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:41:10 +0300 Subject: [PATCH 265/287] Update composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index ab9fa7c93..d97cea9c8 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,6 @@ "laravel/scout": "^10.0", "doctrine/dbal": "^3.7", "intervention/image": "^2.7.0", - "twig/twig": "^2.10", "linkorb/jsmin-php": "^1.0.0", "robclancy/presenter": "^1.3.0", "nicmart/string-template": "^0.1.3", From 0e62b461d72332ce57823ffb8b9b8b56735d44d9 Mon Sep 17 00:00:00 2001 From: Fatih Alp Date: Thu, 21 Dec 2023 13:13:23 +0300 Subject: [PATCH 266/287] Fatih --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ab9fa7c93..f4a8d24a1 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "laravel/scout": "^10.0", "doctrine/dbal": "^3.7", "intervention/image": "^2.7.0", - "twig/twig": "^2.10", + "twig/twig": "*", "linkorb/jsmin-php": "^1.0.0", "robclancy/presenter": "^1.3.0", "nicmart/string-template": "^0.1.3", From fcfd182593a3b616544645520a479efd61080472 Mon Sep 17 00:00:00 2001 From: spektra2147 Date: Thu, 21 Dec 2023 17:10:20 +0300 Subject: [PATCH 267/287] mailcoach-error --- addons/anomaly/test-plugin/src/TestPlugin.php | 10 +- resources/stubs/addons/plugin.stub | 10 +- src/Addon/AddonIntegrator.php | 3 +- src/Addon/FieldType/FieldTypePlugin.php | 3 +- src/Addon/Plugin/Plugin.php | 14 +- src/Asset/Asset.php | 11 +- src/StreamsPlugin.php | 136 +++++++++--------- src/View/Support/CompressHtmlNode.php | 9 +- src/View/Support/CompressHtmlTokenParser.php | 18 +-- src/View/Twig/Bridge.php | 21 +-- src/View/Twig/Compiler.php | 16 +-- src/View/Twig/Engine.php | 16 +-- src/View/Twig/Globals.php | 7 +- src/View/Twig/OriginalLoader.php | 21 +-- src/View/Twig/Template.php | 2 +- 15 files changed, 153 insertions(+), 144 deletions(-) diff --git a/addons/anomaly/test-plugin/src/TestPlugin.php b/addons/anomaly/test-plugin/src/TestPlugin.php index d5949f6d9..28e537291 100644 --- a/addons/anomaly/test-plugin/src/TestPlugin.php +++ b/addons/anomaly/test-plugin/src/TestPlugin.php @@ -1,8 +1,8 @@ functions, 'fieldGroup']), + new TwigFunction('field_group', [$this->functions, 'fieldGroup']), ]; } } diff --git a/src/Addon/Plugin/Plugin.php b/src/Addon/Plugin/Plugin.php index b4e51fe6e..df83a3fae 100644 --- a/src/Addon/Plugin/Plugin.php +++ b/src/Addon/Plugin/Plugin.php @@ -1,9 +1,9 @@ * @author Ryan Thompson */ -class Plugin extends Addon implements Twig_ExtensionInterface +class Plugin extends Addon implements Extension\ExtensionInterface { /** @@ -30,9 +30,9 @@ public function getName() * * This is where you can load some file that contains filter functions for instance. * - * @param Twig_Environment $environment The current Twig_Environment instance + * @param Environment $environment The current Twig\Environment instance */ - public function initRuntime(Twig_Environment $environment) + public function initRuntime(Environment $environment) { } @@ -49,7 +49,7 @@ public function getTokenParsers() /** * Returns the node visitor instances to add to the existing list. * - * @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances + * @return NodeVisitorInterface[] An array of NodeVisitorInterface instances */ public function getNodeVisitors() { diff --git a/src/Asset/Asset.php b/src/Asset/Asset.php index 21321cd98..3b109e6a3 100644 --- a/src/Asset/Asset.php +++ b/src/Asset/Asset.php @@ -10,6 +10,7 @@ use Anomaly\Streams\Platform\Support\Template; use Anomaly\Streams\Platform\Application\Application; use Anomaly\Streams\Platform\Addon\Theme\ThemeCollection; +use Twig\Lexer; /** * Class Asset @@ -547,11 +548,11 @@ protected function publish($path, $collection, $additionalFilters) if (Str::contains($collection, public_path())) { return; } - + $hint = $this->paths->hint($collection); $filters = $this->collectionFilters($collection, $additionalFilters); // Returns combined filter flags - + /** * Get the concatenated content * of the asset collection. @@ -565,11 +566,11 @@ protected function publish($path, $collection, $additionalFilters) $twig = resolve('twig'); $twig->setLexer( - new \Twig_Lexer($twig, [ + new Lexer($twig, [ 'tag_comment' => ['{^', '^}'] ]) ); - + try { $contents = (string) render($contents); } catch (\Exception $e) { @@ -582,7 +583,7 @@ protected function publish($path, $collection, $additionalFilters) } $twig->setLexer( - new \Twig_Lexer($twig, [ + new Lexer($twig, [ 'tag_comment' => ['{#', '#}'] ]) ); diff --git a/src/StreamsPlugin.php b/src/StreamsPlugin.php index e1d7d908a..bcf40a489 100644 --- a/src/StreamsPlugin.php +++ b/src/StreamsPlugin.php @@ -35,6 +35,8 @@ use Illuminate\Support\Arr; use Jenssegers\Agent\Agent; use Symfony\Component\Yaml\Yaml; +use Twig\TwigFilter; +use Twig\TwigFunction; /** * Class StreamsPlugin @@ -54,7 +56,7 @@ class StreamsPlugin extends Plugin public function getFunctions() { return [ - new \Twig_SimpleFunction( + new TwigFunction( 'stream', function ($namespace, $slug = null) { return (new Decorator())->decorate( @@ -62,7 +64,7 @@ function ($namespace, $slug = null) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'streams', function ($namespace) { return (new Decorator())->decorate( @@ -70,7 +72,7 @@ function ($namespace) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'entry', function ($namespace, $stream = null) { return (new Decorator())->decorate( @@ -78,7 +80,7 @@ function ($namespace, $stream = null) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'entries', function ($namespace, $stream = null) { return (new Decorator())->decorate( @@ -86,7 +88,7 @@ function ($namespace, $stream = null) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'query', function ($model = null) { return (new Decorator())->decorate( @@ -94,7 +96,7 @@ function ($model = null) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'img', function ($image) { return dispatch_sync(new MakeImageInstance($image, 'img')); @@ -103,7 +105,7 @@ function ($image) { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'table', function () { $arguments = func_get_args(); @@ -125,7 +127,7 @@ function () { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'form', function () { $arguments = func_get_args(); @@ -148,7 +150,7 @@ function () { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'form_*', function ($name) { return call_user_func_array([app('form'), camel_case($name)], array_slice(func_get_args(), 1)); @@ -157,7 +159,7 @@ function ($name) { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'html_*', function ($name) { return call_user_func_array([app('html'), camel_case($name)], array_slice(func_get_args(), 1)); @@ -166,13 +168,13 @@ function ($name) { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'array_*', function ($name) { return call_user_func_array([app(Arr::class), camel_case($name)], array_slice(func_get_args(), 1)); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'icon', function ($type, $class = null) { return (new Decorator())->decorate(dispatch_sync(new GetIcon($type, $class))); @@ -181,7 +183,7 @@ function ($type, $class = null) { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'view', function ($view, array $data = []) { return dispatch_sync(new GetView($view, $data))->render(); @@ -190,7 +192,7 @@ function ($view, array $data = []) { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'template', function ($key = null, $default = null) { @@ -204,7 +206,7 @@ function ($key = null, $default = null) { return $template->get($key, $default); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'buttons', function ($buttons) { return dispatch_sync(new GetButtons($buttons))->render(); @@ -213,7 +215,7 @@ function ($buttons) { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'constants', function () { return dispatch_sync(new GetConstants())->render(); @@ -222,73 +224,73 @@ function () { 'is_safe' => ['html'], ] ), - new \Twig_SimpleFunction( + new TwigFunction( 'env', function ($key, $default = null) { return env($key, $default); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'length', function ($length, $unit = null) { return new Length($length, $unit); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'carbon', function ($time = null, $timezone = null) { return new Carbon($time, $timezone); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'decorate', function ($value) { return (new Decorator())->decorate($value); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'request_time', function ($decimal = 2) { return dispatch_sync(new GetElapsedTime($decimal)); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'memory_usage', function ($precision = 1) { return dispatch_sync(new GetMemoryUsage($precision)); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'layout', function ($layout, $default = 'default') { return dispatch_sync(new GetLayoutName($layout, $default)); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'request', function () { return request(func_get_args() ?: null); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'request_*', function ($name) { return call_user_func_array([request(), camel_case($name)], array_slice(func_get_args(), 1)); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'trans', function ($key, array $parameters = [], $locale = null) { return dispatch_sync(new GetTranslatedString($key, $parameters, $locale)); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'locale', function ($locale = null) { return (new Locale($locale)); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'str_*', function ($name) { return call_user_func_array( @@ -297,7 +299,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'url_*', function ($name) { return call_user_func_array( @@ -306,7 +308,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'route_*', function ($name) { return call_user_func_array( @@ -315,7 +317,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'asset_*', function ($name) { return call_user_func_array( @@ -324,7 +326,7 @@ function ($name) { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'currency_*', function ($name) { return call_user_func_array( @@ -333,7 +335,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'value', function () { return call_user_func_array( @@ -342,7 +344,7 @@ function () { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'yaml', function ($input) { @@ -353,13 +355,13 @@ function ($input) { return app(Yaml::class)->parse($input); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'addon', function ($identifier) { return (new Decorator())->decorate(app(AddonCollection::class)->get($identifier)); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'addons', function ($type = null) { @@ -372,19 +374,19 @@ function ($type = null) { return (new Decorator())->decorate($addons); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'breadcrumb', function () { return app(BreadcrumbCollection::class); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'favicons', function ($source) { return view('streams::partials.favicons', compact('source')); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'gravatar', function ($email, array $parameters = []) { return app(Image::class)->make( @@ -395,13 +397,13 @@ function ($email, array $parameters = []) { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'cookie', function ($key, $default = null) { return Arr::get($_COOKIE, $key, $default); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'csrf_*', function ($name) { @@ -417,7 +419,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'input_get', function () { return call_user_func_array( @@ -426,7 +428,7 @@ function () { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'asset', function () { return call_user_func_array( @@ -435,7 +437,7 @@ function () { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'action', function () { return call_user_func_array( @@ -444,7 +446,7 @@ function () { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'url', function () { @@ -458,7 +460,7 @@ function () { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'route', function () { return call_user_func_array( @@ -467,7 +469,7 @@ function () { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'route_has', function () { return call_user_func_array( @@ -476,7 +478,7 @@ function () { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'secure_url', function () { return call_user_func_array( @@ -485,7 +487,7 @@ function () { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'secure_asset', function () { return call_user_func_array( @@ -494,7 +496,7 @@ function () { ); }, ['is_safe' => ['html']] ), - new \Twig_SimpleFunction( + new TwigFunction( 'config', function () { return call_user_func_array( @@ -503,7 +505,7 @@ function () { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'config_*', function ($name) { @@ -517,7 +519,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'cache', function () { return call_user_func_array( @@ -526,7 +528,7 @@ function () { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'cache_*', function ($name) { @@ -540,7 +542,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'auth_*', function ($name) { @@ -554,7 +556,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'trans_*', function ($name) { @@ -572,7 +574,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'message_*', function ($name) { @@ -590,7 +592,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'session', function () { return call_user_func_array( @@ -599,7 +601,7 @@ function () { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'parse', function () { return call_user_func_array( @@ -608,7 +610,7 @@ function () { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'session_*', function ($name) { @@ -622,7 +624,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'agent_*', function ($name) { @@ -650,7 +652,7 @@ function ($name) { ); } ), - new \Twig_SimpleFunction( + new TwigFunction( 'app', function () { return call_user_func_array( @@ -670,7 +672,7 @@ function () { public function getFilters() { return [ - new \Twig_SimpleFilter( + new TwigFilter( 'camel_case', function () { return call_user_func_array( @@ -679,7 +681,7 @@ function () { ); } ), - new \Twig_SimpleFilter( + new TwigFilter( 'snake_case', function () { return call_user_func_array( @@ -688,7 +690,7 @@ function () { ); } ), - new \Twig_SimpleFilter( + new TwigFilter( 'studly_case', function () { return call_user_func_array( @@ -697,7 +699,7 @@ function () { ); } ), - new \Twig_SimpleFilter( + new TwigFilter( 'humanize', function () { return call_user_func_array( @@ -706,7 +708,7 @@ function () { ); } ), - new \Twig_SimpleFilter( + new TwigFilter( 'parse', function () { return call_user_func_array( @@ -715,7 +717,7 @@ function () { ); } ), - new \Twig_SimpleFilter( + new TwigFilter( 'str_*', function ($name) { return call_user_func_array( diff --git a/src/View/Support/CompressHtmlNode.php b/src/View/Support/CompressHtmlNode.php index b0b6f1718..745d88e6f 100644 --- a/src/View/Support/CompressHtmlNode.php +++ b/src/View/Support/CompressHtmlNode.php @@ -1,6 +1,7 @@ * @author PyroCMS, Inc. */ -class CompressHtmlNode extends Twig_Node +class CompressHtmlNode extends Node { /** @@ -33,9 +34,9 @@ public function __construct(array $nodes = [], array $attributes = [], $line_num /** * Compile the node. * - * @param \Twig_Compiler $compiler + * @param Compiler $compiler */ - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/src/View/Support/CompressHtmlTokenParser.php b/src/View/Support/CompressHtmlTokenParser.php index 77b983f48..06b42f927 100644 --- a/src/View/Support/CompressHtmlTokenParser.php +++ b/src/View/Support/CompressHtmlTokenParser.php @@ -1,7 +1,7 @@ * @author PyroCMS, Inc. */ -class CompressHtmlTokenParser extends Twig_TokenParser +class CompressHtmlTokenParser extends AbstractTokenParser { /** * Parse the token. * - * @param Twig_Token $token + * @param Token $token * @return CompressHtmlNode */ - public function parse(Twig_Token $token) + public function parse(Token $token) { $line_number = $token->getLine(); $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideHtmlCompressEnd'], true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $nodes = ['content' => $body]; @@ -54,10 +54,10 @@ public function getTag() /** * Get the closing tag decision. * - * @param Twig_Token $token + * @param Token $token * @return bool */ - public function decideHtmlCompressEnd(Twig_Token $token) + public function decideHtmlCompressEnd(Token $token) { return $token->test('endhtmlcompress'); } diff --git a/src/View/Twig/Bridge.php b/src/View/Twig/Bridge.php index 38f2778a3..aa1816d3a 100644 --- a/src/View/Twig/Bridge.php +++ b/src/View/Twig/Bridge.php @@ -13,14 +13,15 @@ use Illuminate\Contracts\Container\Container; use Illuminate\View\ViewFinderInterface; use InvalidArgumentException; -use Twig_Environment; -use Twig_Error; -use Twig_LoaderInterface; +use Twig\Environment; +use Twig\Error\Error; +use Twig\Loader\LoaderInterface; +use Twig\Template; /** * Bridge functions between Laravel & Twig */ -class Bridge extends Twig_Environment +class Bridge extends Environment { /** @@ -36,7 +37,7 @@ class Bridge extends Twig_Environment /** * {@inheritdoc} */ - public function __construct(Twig_LoaderInterface $loader, $options = [], Container $app = null) + public function __construct(LoaderInterface $loader, $options = [], Container $app = null) { // Twig 2.0 doesn't support `true` anymore if (isset($options['autoescape']) && $options['autoescape'] === true) { @@ -70,9 +71,9 @@ public function setApplication(Container $app) $this->app = $app; } - public function loadTemplate($name, $index = null) + public function loadTemplate(string $cls, string $name, int $index = null): Template { - $template = parent::loadTemplate($name, $index); + $template = parent::loadTemplate($cls, $name, $index); $template->setName($this->normalizeName($name)); @@ -96,7 +97,7 @@ public function lint($file) try { $this->parse($this->tokenize($template, $file)); - } catch (Twig_Error $e) { + } catch (Error $e) { return false; } @@ -126,14 +127,14 @@ public function mergeShared(array $context) /** * Normalize a view name. * - * @param string $name + * @param string $name * * @return string */ protected function normalizeName($name) { $extension = '.' . $this->app['twig.extension']; - $length = strlen($extension); + $length = strlen($extension); if (substr($name, -$length, $length) === $extension) { $name = substr($name, 0, -$length); diff --git a/src/View/Twig/Compiler.php b/src/View/Twig/Compiler.php index bbd7ea275..54452f1a6 100644 --- a/src/View/Twig/Compiler.php +++ b/src/View/Twig/Compiler.php @@ -10,8 +10,8 @@ */ use Illuminate\View\Compilers\CompilerInterface; -use Twig_Environment; -use Twig_Error_Loader; +use Twig\Environment; +use Twig\Error\LoaderError; use Exception; use InvalidArgumentException; @@ -21,16 +21,16 @@ class Compiler implements CompilerInterface { /** - * @var \Twig_Environment + * @var Environment */ protected $twig; /** * Create a new instance of the Twig compiler. * - * @param \Twig_Environment $twig + * @param Environment $twig */ - public function __construct(Twig_Environment $twig) + public function __construct(Environment $twig) { $this->twig = $twig; } @@ -38,7 +38,7 @@ public function __construct(Twig_Environment $twig) /** * Returns the instance of Twig used to render the template. * - * @return \Twig_Environment + * @return Environment */ public function getTwig() { @@ -84,14 +84,14 @@ public function compile($path) * Compile the view at the given path. * * @param $path - * @return \Twig_Template + * @return \Twig\Template */ public function load($path) { // Load template try { $template = $this->twig->loadTemplate($path); - } catch (Twig_Error_Loader $e) { + } catch (LoaderError $e) { throw new InvalidArgumentException("Error loading $path: ". $e->getMessage(), $e->getCode(), $e); } diff --git a/src/View/Twig/Engine.php b/src/View/Twig/Engine.php index c0f3ab5f4..51c570a2b 100644 --- a/src/View/Twig/Engine.php +++ b/src/View/Twig/Engine.php @@ -10,8 +10,8 @@ */ use Illuminate\View\Engines\CompilerEngine; -use Twig_Error; -use Twig_Error_Loader; +use Twig\Error\Error; +use Twig\Error\LoaderError; use ErrorException; /** @@ -76,7 +76,7 @@ public function setGlobalData(array $globalData) * @param string $path Full file path to Twig template. * @param array $data * - * @throws \Twig_Error|\ErrorException When unable to load the requested path. + * @throws Error|\ErrorException When unable to load the requested path. * * @return string */ @@ -86,7 +86,7 @@ public function get($path, array $data = []) try { $content = $this->compiler->load($path)->render($data); - } catch (Twig_Error $ex) { + } catch (Error $ex) { $this->handleTwigError($ex); } @@ -96,11 +96,11 @@ public function get($path, array $data = []) /** * Handle a TwigError exception. * - * @param \Twig_Error $ex + * @param Error $ex * - * @throws \Twig_Error|\ErrorException + * @throws Error|\ErrorException */ - protected function handleTwigError(Twig_Error $ex) + protected function handleTwigError(Error $ex) { $context = $ex->getSourceContext(); @@ -117,7 +117,7 @@ protected function handleTwigError(Twig_Error $ex) // Attempt to locate full path to file try { $file = $this->loader->findTemplate($templateFile); - } catch (Twig_Error_Loader $exception) { + } catch (LoaderError $exception) { // Unable to load template } } diff --git a/src/View/Twig/Globals.php b/src/View/Twig/Globals.php index 1f81b164d..0ee56d961 100644 --- a/src/View/Twig/Globals.php +++ b/src/View/Twig/Globals.php @@ -1,5 +1,8 @@ cache[$name] = $this->finder->find($name); } catch (InvalidArgumentException $ex) { - throw new Twig_Error_Loader($ex->getMessage()); + throw new LoaderError($ex->getMessage()); } return $this->cache[$name]; @@ -103,7 +104,7 @@ public function exists($name) { try { $this->findTemplate($name); - } catch (Twig_Error_Loader $exception) { + } catch (LoaderError $exception) { return false; } @@ -113,17 +114,17 @@ public function exists($name) /** * {@inheritdoc} */ - public function getSourceContext($name) + public function getSourceContext($name): Source { $path = $this->findTemplate($name); - return new \Twig_Source($this->files->get($path), $name, $path); + return new Source($this->files->get($path), $name, $path); } /** * {@inheritdoc} */ - public function getCacheKey($name) + public function getCacheKey($name): string { return $this->findTemplate($name); } @@ -131,7 +132,7 @@ public function getCacheKey($name) /** * {@inheritdoc} */ - public function isFresh($name, $time) + public function isFresh($name, $time): bool { return $this->files->lastModified($this->findTemplate($name)) <= $time; } diff --git a/src/View/Twig/Template.php b/src/View/Twig/Template.php index 8a1b1af81..ff8285bac 100644 --- a/src/View/Twig/Template.php +++ b/src/View/Twig/Template.php @@ -15,7 +15,7 @@ /** * Default base class for compiled templates. */ -abstract class Template extends Twig_Template +abstract class Template extends \Twig\Template { /** From bfdeb70439161ded4f9761e17414e6a23f579d7d Mon Sep 17 00:00:00 2001 From: Fatih Alp Date: Sun, 24 Dec 2023 00:48:52 +0300 Subject: [PATCH 268/287] Twig 3.x Update Test (v3.8.0) --- resources/config/twig.php | 6 +- resources/views/buttons/buttons.twig | 117 +++++----- resources/views/form/partials/controls.twig | 19 +- resources/views/form/partials/tabs.twig | 18 +- src/Http/Middleware/PoweredBy.php | 5 - src/View/Twig/Bridge.php | 69 +----- src/View/Twig/Compiler.php | 26 ++- src/View/Twig/Engine.php | 18 +- src/View/Twig/Globals.php | 23 +- src/View/Twig/Loader.php | 47 +++- src/View/Twig/OriginalLoader.php | 16 +- src/View/Twig/Template.php | 133 ----------- src/View/ViewServiceProvider.php | 241 ++++++++++---------- 13 files changed, 292 insertions(+), 446 deletions(-) delete mode 100644 src/View/Twig/Template.php diff --git a/resources/config/twig.php b/resources/config/twig.php index b7cde82ac..9c082cd26 100644 --- a/resources/config/twig.php +++ b/resources/config/twig.php @@ -43,11 +43,7 @@ // The charset used by the templates. // default: utf-8 'charset' => 'utf-8', - - // The base template class to use for generated templates. - // default: TwigBridge\Twig\Template - 'base_template_class' => '\Anomaly\Streams\Platform\View\Twig\Template', - + // An absolute path where to store the compiled templates, or false to disable caching. If null // then the cache file path is used. // default: cache file storage path diff --git a/resources/views/buttons/buttons.twig b/resources/views/buttons/buttons.twig index ff16c3ceb..c196c62d1 100644 --- a/resources/views/buttons/buttons.twig +++ b/resources/views/buttons/buttons.twig @@ -1,69 +1,70 @@ -{% for button in buttons %} +{#{% for button in buttons %}#} +{# #}{# TODO TEST ONLY -- REVERT #} - {# Render normal buttons. #} - {% if button.dropdown is empty and not button.parent %} +{# #}{# Render normal buttons. #} +{# {% if button.dropdown is empty and not button.parent %}#} - {# Render normal buttons as an anchor #} - <{{ button.tag ?: 'a' }} class="btn btn-{{ button.size }} btn-{{ button.type }} {{ button.disabled ? 'disabled' }} {{ button.class }}" {{ button.disabled ? 'disabled' }} {{ html_attributes(button.attributes) }}> - {{ button.icon ? icon(button.icon)|raw }} - {{ trans(button.text)|raw }} - +{# #}{# Render normal buttons as an anchor #} +{# <{{ button.tag ?: 'a' }} class="btn btn-{{ button.size }} btn-{{ button.type }} {{ button.disabled ? 'disabled' }} {{ button.class }}" {{ button.disabled ? 'disabled' }} {{ html_attributes(button.attributes) }}>#} +{# {{ button.icon ? icon(button.icon)|raw }}#} +{# {{ trans(button.text)|raw }}#} +{# #} - {% endif %} +{# {% endif %}#} - {# Render dropdown type buttons. #} - {% if button.dropdown %} -
+{# #}{# Render dropdown type buttons. #} +{# {% if button.dropdown %}#} +{#
#} - {% if button.attributes.href %} - - {{ button.icon ? icon(button.icon)|raw }} - {{ trans(button.text)|raw }} - +{# {% if button.attributes.href %}#} +{# #} +{# {{ button.icon ? icon(button.icon)|raw }}#} +{# {{ trans(button.text)|raw }}#} +{# #} - - {{ icon('fa fa-caret-down') }} - - {% else %} - - {{ button.icon ? icon(button.icon)|raw }} - {{ trans(button.text)|raw }} - - {% endif %} +{# #} +{# {{ icon('fa fa-caret-down') }}#} +{# #} +{# {% else %}#} +{# #} +{# {{ button.icon ? icon(button.icon)|raw }}#} +{# {{ trans(button.text)|raw }}#} +{# #} +{# {% endif %}#} - {# Render the actual dropdown links #} -
- {% endif %} +{# #} +{# {% else %}#} +{# #} +{# {% endif %}#} +{# {% endfor %}#} +{# #} +{#
#} +{# {% endif %}#} -{% endfor %} +{#{% endfor %}#} diff --git a/resources/views/form/partials/controls.twig b/resources/views/form/partials/controls.twig index 9b6dfd7cd..7d5313735 100644 --- a/resources/views/form/partials/controls.twig +++ b/resources/views/form/partials/controls.twig @@ -1,15 +1,16 @@
+ {# TODO TEST ONLY -- REVERT #} - {% if not form.options.read_only %} -
- {{ buttons(form.actions)|raw }} -
- {% endif %} - -
- {{ buttons(form.buttons)|raw }} -
+{# {% if not form.options.read_only %}#} +{#
#} +{# {{ buttons(form.actions)|raw }}#} +{#
#} +{# {% endif %}#} +{# #} +{#
#} +{# {{ buttons(form.buttons)|raw }}#} +{#
#}
diff --git a/resources/views/form/partials/tabs.twig b/resources/views/form/partials/tabs.twig index ad7870aa5..23ca85dd2 100644 --- a/resources/views/form/partials/tabs.twig +++ b/resources/views/form/partials/tabs.twig @@ -1,14 +1,12 @@
diff --git a/src/Http/Middleware/PoweredBy.php b/src/Http/Middleware/PoweredBy.php index 94766812c..f398a726c 100644 --- a/src/Http/Middleware/PoweredBy.php +++ b/src/Http/Middleware/PoweredBy.php @@ -25,11 +25,6 @@ public function handle(Request $request, Closure $next) /* @var \Illuminate\Http\Response $response */ $response = $next($request); - $response->headers->set( - 'X-Streams-Distribution', - config('streams::distribution.name') . '-' . config('streams::distribution.version') - ); - return $response; } } diff --git a/src/View/Twig/Bridge.php b/src/View/Twig/Bridge.php index aa1816d3a..8a8cde1c4 100644 --- a/src/View/Twig/Bridge.php +++ b/src/View/Twig/Bridge.php @@ -7,23 +7,20 @@ * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. - */ - + */ use Illuminate\Contracts\Container\Container; -use Illuminate\View\ViewFinderInterface; use InvalidArgumentException; use Twig\Environment; use Twig\Error\Error; use Twig\Loader\LoaderInterface; -use Twig\Template; +use Twig\Source; /** * Bridge functions between Laravel & Twig */ class Bridge extends Environment { - /** * @var string TwigBridge version */ @@ -71,15 +68,6 @@ public function setApplication(Container $app) $this->app = $app; } - public function loadTemplate(string $cls, string $name, int $index = null): Template - { - $template = parent::loadTemplate($cls, $name, $index); - - $template->setName($this->normalizeName($name)); - - return $template; - } - /** * Lint (check) the syntax of a file on the view paths. * @@ -89,9 +77,11 @@ public function loadTemplate(string $cls, string $name, int $index = null): Temp */ public function lint($file) { - $template = $this->app['twig.loader.viewfinder']->getSource($file); + /** @var Source $template */ + $template = $this->app['twig.loader.viewfinder']->getSourceContext($file); - if (!$template) { + $code = trim($template->getCode()); + if (empty($code)) { throw new InvalidArgumentException('Unable to find file: ' . $file); } @@ -103,51 +93,4 @@ public function lint($file) return true; } - - /** - * Merges a context with the shared variables, same as mergeGlobals() - * - * @param array $context An array representing the context - * - * @return array The context merged with the globals - */ - public function mergeShared(array $context) - { - // we don't use array_merge as the context being generally - // bigger than globals, this code is faster. - foreach ($this->app['view']->getShared() as $key => $value) { - if (!array_key_exists($key, $context)) { - $context[$key] = $value; - } - } - - return $context; - } - - /** - * Normalize a view name. - * - * @param string $name - * - * @return string - */ - protected function normalizeName($name) - { - $extension = '.' . $this->app['twig.extension']; - $length = strlen($extension); - - if (substr($name, -$length, $length) === $extension) { - $name = substr($name, 0, -$length); - } - - // Normalize namespace and delimiters - $delimiter = ViewFinderInterface::HINT_PATH_DELIMITER; - if (strpos($name, $delimiter) === false) { - return str_replace('/', '.', $name); - } - - list($namespace, $name) = explode($delimiter, $name); - - return $namespace . $delimiter . str_replace('/', '.', $name); - } } diff --git a/src/View/Twig/Compiler.php b/src/View/Twig/Compiler.php index 54452f1a6..fb13483fa 100644 --- a/src/View/Twig/Compiler.php +++ b/src/View/Twig/Compiler.php @@ -1,4 +1,4 @@ -twig->loadTemplate($path); - } catch (LoaderError $e) { + $tmplWrapper = $this->twig->load($path); + } catch (Exception $e) { throw new InvalidArgumentException("Error loading $path: ". $e->getMessage(), $e->getCode(), $e); } - - if ($template instanceof Template) { + if ($tmplWrapper instanceof Template) { // Events are already fired by the View Environment $template->setFiredEvents(true); } - return $template; + return $tmplWrapper; } } diff --git a/src/View/Twig/Engine.php b/src/View/Twig/Engine.php index 51c570a2b..3ce0f85c3 100644 --- a/src/View/Twig/Engine.php +++ b/src/View/Twig/Engine.php @@ -14,6 +14,11 @@ use Twig\Error\LoaderError; use ErrorException; + +use Twig\Loader\LoaderInterface; +//use TwigBridge\Twig\Loader; +use Anomaly\Streams\Platform\View\Twig\OriginalLoader; + /** * View engine for Twig files. */ @@ -29,18 +34,18 @@ class Engine extends CompilerEngine /** * Used to find the file that has failed. * - * @var Loader + * @var \TwigBridge\Twig\Loader */ protected $loader = []; /** * Create a new Twig view engine instance. * - * @param Compiler $compiler - * @param Loader $loader + * @param \TwigBridge\Engine\Compiler $compiler + * @param \TwigBridge\Twig\Loader $loader * @param array $globalData */ - public function __construct(Compiler $compiler, Loader $loader, array $globalData = []) + public function __construct(Compiler $compiler, OriginalLoader $loader, array $globalData = []) { parent::__construct($compiler); @@ -116,7 +121,10 @@ protected function handleTwigError(Error $ex) } elseif ($templateFile) { // Attempt to locate full path to file try { - $file = $this->loader->findTemplate($templateFile); + if ($this->loader instanceof Loader) { + //Outside of unit test, we should be able to load the file + $file = $this->loader->findTemplate($templateFile); + } } catch (LoaderError $exception) { // Unable to load template } diff --git a/src/View/Twig/Globals.php b/src/View/Twig/Globals.php index 0ee56d961..5b2d0afa2 100644 --- a/src/View/Twig/Globals.php +++ b/src/View/Twig/Globals.php @@ -1,25 +1,18 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. + * Add 'app' and all global variables shared through View::share */ +class Globals extends AbstractExtension implements GlobalsInterface +{ -if (version_compare(Environment::VERSION, '1.23.0') === -1) { - interface Globals + public function getGlobals(): array { - - } -} else { - interface Globals extends GlobalsInterface - { - + $globals = app('view')->getShared(); + $globals['app'] = app(); + return $globals; } } diff --git a/src/View/Twig/Loader.php b/src/View/Twig/Loader.php index b4f7872cb..c4be2aa04 100644 --- a/src/View/Twig/Loader.php +++ b/src/View/Twig/Loader.php @@ -167,13 +167,54 @@ public function __construct( */ public function findTemplate($name) { - $overload = $this->getOverloadPath($name); + if ($this->files->exists($name)) { + return $name; + } + + $name = $this->normalizeName($name); - $name = $overload ?: $name; + if (isset($this->cache[$name])) { + return $this->cache[$name]; + } + + try { + $this->cache[$name] = $this->finder->find($name); + } catch (InvalidArgumentException $ex) { + throw new LoaderError($ex->getMessage()); + } - return parent::findTemplate($name); + return $this->cache[$name]; } + /** + * Normalize the Twig template name to a name the ViewFinder can use + * + * @param string $name Template file name. + * @return string The parsed name + */ + protected function normalizeName($name) + { + if ($this->files->extension($name) === $this->extension) { + $name = substr($name, 0, - (strlen($this->extension) + 1)); + } + + return $name; + } + + /** + * {@inheritdoc} + */ + public function exists($name) + { + try { + $this->findTemplate($name); + } catch (LoaderError $exception) { + return false; + } + + return true; + } + /** * Gets the overload path. * diff --git a/src/View/Twig/OriginalLoader.php b/src/View/Twig/OriginalLoader.php index 5256eac23..90b6057ab 100644 --- a/src/View/Twig/OriginalLoader.php +++ b/src/View/Twig/OriginalLoader.php @@ -9,11 +9,13 @@ * file that was distributed with this source code. */ -use Twig\Error\LoaderError; -use Twig\Loader\LoaderInterface; -use InvalidArgumentException; +// namespace TwigBridge\Twig; + use Illuminate\Filesystem\Filesystem; use Illuminate\View\ViewFinderInterface; +use InvalidArgumentException; +use Twig\Error\LoaderError; +use Twig\Loader\LoaderInterface; use Twig\Source; /** @@ -114,7 +116,7 @@ public function exists($name) /** * {@inheritdoc} */ - public function getSourceContext($name): Source + public function getSourceContext(String $name): Source { $path = $this->findTemplate($name); @@ -124,7 +126,7 @@ public function getSourceContext($name): Source /** * {@inheritdoc} */ - public function getCacheKey($name): string + public function getCacheKey(string $name): string { return $this->findTemplate($name); } @@ -132,8 +134,8 @@ public function getCacheKey($name): string /** * {@inheritdoc} */ - public function isFresh($name, $time): bool + public function isFresh(string $name, int $time): bool { return $this->files->lastModified($this->findTemplate($name)) <= $time; } -} +} \ No newline at end of file diff --git a/src/View/Twig/Template.php b/src/View/Twig/Template.php deleted file mode 100644 index ff8285bac..000000000 --- a/src/View/Twig/Template.php +++ /dev/null @@ -1,133 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Illuminate\View\View; -use Twig_Template; - -/** - * Default base class for compiled templates. - */ -abstract class Template extends \Twig\Template -{ - - /** - * @var bool Have the creator/composer events fired. - */ - protected $firedEvents = false; - - protected $name = null; - - /** - * {@inheritdoc} - */ - public function display(array $context, array $blocks = []) - { - if (!isset($context['__env'])) { - $context = $this->env->mergeShared($context); - } - - if ($this->shouldFireEvents()) { - $context = $this->fireEvents($context); - } - - parent::display($context, $blocks); - } - - /** - * Fire the creator/composer events and return the modified context. - * - * @param $context Old context. - * - * @return array New context if __env is passed in, else the passed in context is returned. - */ - public function fireEvents($context) - { - if (!isset($context['__env'])) { - return $context; - } - - /** @var \Illuminate\View\Factory $factory */ - $env = $context['__env']; - $viewName = $this->name ?: $this->getTemplateName(); - - $view = new View( - $env, - $env->getEngineResolver()->resolve('twig'), - $viewName, - null, - $context - ); - $env->callCreator($view); - $env->callComposer($view); - - return $view->getData(); - } - - /** - * Set the name of this template, as called by the developer. - */ - public function setName($name) - { - $this->name = $name; - } - - - /** - * Determine whether events should fire for this view. - * - * @return bool - */ - public function shouldFireEvents() - { - return !$this->firedEvents; - } - - /** - * Set the firedEvents flag, to make sure composers/creators only fire once. - * - * @param bool $fired - * - * @return void - */ - public function setFiredEvents($fired = true) - { - $this->firedEvents = $fired; - } - - /** - * {@inheritdoc} - */ - protected function getAttribute( - $object, - $item, - array $arguments = [], - $type = Twig_Template::ANY_CALL, - $isDefinedTest = false, - $ignoreStrictCheck = false - ) { - // We need to handle accessing attributes on an Eloquent instance differently - if (Twig_Template::METHOD_CALL !== $type and is_a($object, 'Illuminate\Database\Eloquent\Model')) { - // We can't easily find out if an attribute actually exists, so return true - if ($isDefinedTest) { - return true; - } - - if ($this->env->hasExtension('sandbox')) { - $this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item); - } - - // Call the attribute, the Model object does the rest of the magic - return $object->$item; - } else { - return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); - } - } -} diff --git a/src/View/ViewServiceProvider.php b/src/View/ViewServiceProvider.php index d3a3d8814..5f17997c6 100644 --- a/src/View/ViewServiceProvider.php +++ b/src/View/ViewServiceProvider.php @@ -1,27 +1,43 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ -use Anomaly\Streams\Platform\View\Twig\Bridge; use Anomaly\Streams\Platform\View\Twig\Compiler; +use InvalidArgumentException; +use Twig\Environment; +use Twig\Lexer; +use Twig\Extension\DebugExtension; +use Twig\Extension\ExtensionInterface; +use Twig\Extension\EscaperExtension; +use Twig\Loader\ArrayLoader; +use Twig\Loader\ChainLoader; use Anomaly\Streams\Platform\View\Twig\Engine; +use Anomaly\Streams\Platform\View\Twig\Bridge; use Anomaly\Streams\Platform\View\Twig\Loader; -use InvalidArgumentException; -use Twig_Loader_Array; -use Twig_Loader_Chain; - +use Anomaly\Streams\Platform\View\Twig\OriginalLoader; /** - * Class ViewServiceProvider + * Bootstrap Laravel twig. * - * This is adopted from https://github.com/rcrowe/TwigBridge + * You need to include this `ServiceProvider` in your app.php file: * - * @link http://pyrocms.com/ - * @author PyroCMS, Inc. - * @author Ryan Thompson + * + * 'providers' => [ + * 'twig\ServiceProvider' + * ]; + * */ class ViewServiceProvider extends \Illuminate\View\ViewServiceProvider { - /** - * Register the service. + * {@inheritdoc} */ public function register() { @@ -33,7 +49,7 @@ public function register() } /** - * Boot the service. + * {@inheritdoc} */ public function boot() { @@ -41,6 +57,16 @@ public function boot() $this->registerExtension(); } + /** + * Check if we are running Lumen or not. + * + * @return bool + */ + protected function isLumen() + { + return strpos($this->app->version(), 'Lumen') !== false; + } + /** * Check if we are running on PHP 7. * @@ -84,26 +110,17 @@ function () { */ protected function registerCommands() { - $this->app->bindIf( - 'command.twig', - function () { - return new Command\TwigBridge; - } - ); + $this->app->bindIf('command.twig', function () { + return new Command\twig; + }); - $this->app->bindIf( - 'command.twig.clean', - function () { - return new Command\Clean; - } - ); + $this->app->bindIf('command.twig.clean', function () { + return new Command\Clean; + }); - $this->app->bindIf( - 'command.twig.lint', - function () { - return new Command\Lint; - } - ); + $this->app->bindIf('command.twig.lint', function () { + return new Command\Lint; + }); $this->commands( 'command.twig', @@ -119,49 +136,40 @@ function () { */ protected function registerOptions() { - $this->app->bindIf( - 'twig.extension', - function () { - return $this->app['config']->get('twig.twig.extension'); - } - ); + $this->app->bindIf('twig.extension', function () { + return $this->app['config']->get('twig.twig.extension'); + }); - $this->app->bindIf( - 'twig.options', - function () { - $options = $this->app['config']->get('twig.twig.environment', []); - // Check whether we have the cache path set - if (!isset($options['cache']) || is_null($options['cache'])) { - // No cache path set for Twig, lets set to the Laravel views storage folder - $options['cache'] = storage_path('framework/views/twig'); - } + $this->app->bindIf('twig.options', function () { + $options = $this->app['config']->get('twig.twig.environment', []); - return $options; + // Check whether we have the cache path set + if (! isset($options['cache']) || is_null($options['cache'])) { + // No cache path set for Twig, lets set to the Laravel views storage folder + $options['cache'] = storage_path('framework/views/twig'); } - ); - $this->app->bindIf( - 'twig.extensions', - function () { - $load = $this->app['config']->get('twig.extensions.enabled', []); - // Is debug enabled? - // If so enable debug extension - $options = $this->app['twig.options']; - $isDebug = (bool)(isset($options['debug'])) ? $options['debug'] : false; - if ($isDebug) { - array_unshift($load, 'Twig_Extension_Debug'); - } + return $options; + }); - return $load; - } - ); + $this->app->bindIf('twig.extensions', function () { + $load = $this->app['config']->get('twig.extensions.enabled', []); - $this->app->bindIf( - 'twig.lexer', - function () { - return null; + // Is debug enabled? + // If so enable debug extension + $options = $this->app['twig.options']; + $isDebug = (bool) (isset($options['debug'])) ? $options['debug'] : false; + + if ($isDebug) { + array_unshift($load, DebugExtension::class); } - ); + + return $load; + }); + + $this->app->bindIf('twig.lexer', function () { + return null; + }); } /** @@ -172,43 +180,29 @@ function () { protected function registerLoaders() { // The array used in the ArrayLoader - $this->app->bindIf( - 'twig.templates', - function () { - return []; - } - ); + $this->app->bindIf('twig.templates', function () { + return []; + }); - $this->app->bindIf( - 'twig.loader.array', - function ($app) { - return new Twig_Loader_Array($app['twig.templates']); - } - ); + $this->app->bindIf('twig.loader.array', function ($app) { + return new ArrayLoader($app['twig.templates']); + }); - $this->app->bindIf( - 'twig.loader.viewfinder', - function ($app) { - return $app->make( - Loader::class, - [ - 'files' => $app['files'], - 'finder' => $app['view']->getFinder(), - 'extension' => $app['twig.extension'], - ] - ); - } - ); + $this->app->bindIf('twig.loader.viewfinder', function () { + return new OriginalLoader( + $this->app['files'], + $this->app['view']->getFinder(), + $this->app['twig.extension'] + ); + }); $this->app->bindIf( 'twig.loader', function () { - return new Twig_Loader_Chain( - [ - $this->app['twig.loader.array'], - $this->app['twig.loader.viewfinder'], - ] - ); + return new ChainLoader([ + $this->app['twig.loader.array'], + $this->app['twig.loader.viewfinder'], + ]); }, true ); @@ -225,13 +219,17 @@ protected function registerEngine() 'twig', function () { $extensions = $this->app['twig.extensions']; - $lexer = $this->app['twig.lexer']; - $twig = new Bridge( + $lexer = $this->app['twig.lexer']; + $twig = new Bridge( $this->app['twig.loader'], $this->app['twig.options'], $this->app ); + foreach ($this->app['config']->get('twig.twig.safe_classes', []) as $safeClass => $strategy) { + $twig->getExtension(EscaperExtension::class)->addSafeClass($safeClass, $strategy); + } + // Instantiate and add extensions foreach ($extensions as $extension) { // Get an instance of the extension @@ -246,13 +244,15 @@ function () { } } elseif (is_callable($extension)) { $extension = $extension($this->app, $twig); - } elseif (!is_a($extension, 'Twig_Extension')) { + } elseif (! is_a($extension, ExtensionInterface::class)) { throw new InvalidArgumentException('Incorrect extension type'); } + $twig->addExtension($extension); } + // Set lexer - if (is_a($lexer, 'Twig_LexerInterface')) { + if (is_a($lexer, Lexer::class)) { $twig->setLexer($lexer); } @@ -260,24 +260,21 @@ function () { }, true ); - $this->app->alias('twig', 'Twig_Environment'); + + $this->app->alias('twig', Environment::class); $this->app->alias('twig', Bridge::class); - $this->app->bindIf( - 'twig.compiler', - function () { - return new Compiler($this->app['twig']); - } - ); - $this->app->bindIf( - 'twig.engine', - function () { - return new Engine( - $this->app['twig.compiler'], - $this->app['twig.loader.viewfinder'], - $this->app['config']->get('twig.twig.globals', []) - ); - } - ); + + $this->app->bindIf('twig.compiler', function () { + return new Compiler($this->app['twig']); + }); + + $this->app->bindIf('twig.engine', function () { + return new Engine( + $this->app['twig.compiler'], + $this->app['twig.loader.viewfinder'], + $this->app['config']->get('twig.twig.globals', []) + ); + }); } /** @@ -287,8 +284,8 @@ function () { */ protected function registerAliases() { - if (!$this->isRunningOnPhp7() and !class_exists('TwigBridge\Extension\Laravel\String')) { - class_alias('TwigBridge\Extension\Laravel\Str', 'TwigBridge\Extension\Laravel\String'); + if (! $this->isRunningOnPhp7() and ! class_exists('twig\Extension\Laravel\String')) { + class_alias('twig\Extension\Laravel\Str', 'twig\Extension\Laravel\String'); } } From 8780ae9504911e9df052301706c17c671c762094 Mon Sep 17 00:00:00 2001 From: Fatih Alp Date: Sun, 24 Dec 2023 19:46:29 +0300 Subject: [PATCH 269/287] Twig fix --- resources/views/buttons/buttons.twig | 117 ++++++++++---------- resources/views/form/partials/controls.twig | 18 +-- 2 files changed, 67 insertions(+), 68 deletions(-) diff --git a/resources/views/buttons/buttons.twig b/resources/views/buttons/buttons.twig index c196c62d1..8e6430ed7 100644 --- a/resources/views/buttons/buttons.twig +++ b/resources/views/buttons/buttons.twig @@ -1,70 +1,69 @@ -{#{% for button in buttons %}#} -{# #}{# TODO TEST ONLY -- REVERT #} +{% for button in buttons %} -{# #}{# Render normal buttons. #} -{# {% if button.dropdown is empty and not button.parent %}#} + {# Render normal buttons. #} + {% if button.dropdown is empty and not button.parent %} -{# #}{# Render normal buttons as an anchor #} -{# <{{ button.tag ?: 'a' }} class="btn btn-{{ button.size }} btn-{{ button.type }} {{ button.disabled ? 'disabled' }} {{ button.class }}" {{ button.disabled ? 'disabled' }} {{ html_attributes(button.attributes) }}>#} -{# {{ button.icon ? icon(button.icon)|raw }}#} -{# {{ trans(button.text)|raw }}#} -{# #} + {# Render normal buttons as an anchor #} + <{{ button.tag ?: 'a' }} class="btn btn-{{ button.size }} btn-{{ button.type }} {{ button.disabled ? 'disabled' }} {{ button.class }}" {{ button.disabled ? 'disabled' }} {{ html_attributes(button.attributes) }}> + {{ button.icon ? icon(button.icon)|raw }} + {{ trans(button.text)|raw }} + -{# {% endif %}#} + {% endif %} -{# #}{# Render dropdown type buttons. #} -{# {% if button.dropdown %}#} -{#
#} + {# Render dropdown type buttons. #} + {% if button.dropdown %} +
-{# {% if button.attributes.href %}#} -{# #} -{# {{ button.icon ? icon(button.icon)|raw }}#} -{# {{ trans(button.text)|raw }}#} -{# #} + {% if button.attributes.href %} + + {{ button.icon ? icon(button.icon)|raw }} + {{ trans(button.text)|raw }} + -{# #} -{# {{ icon('fa fa-caret-down') }}#} -{# #} -{# {% else %}#} -{# #} -{# {{ button.icon ? icon(button.icon)|raw }}#} -{# {{ trans(button.text)|raw }}#} -{# #} -{# {% endif %}#} + + {{ icon('fa fa-caret-down') }} + + {% else %} + + {{ button.icon ? icon(button.icon)|raw }} + {{ trans(button.text)|raw }} + + {% endif %} -{# #}{# Render the actual dropdown links #} -{#
#} -{# {% endif %}#} + + {% else %} + + {% endif %} + {% endfor %} + +
+ {% endif %} -{#{% endfor %}#} +{% endfor %} diff --git a/resources/views/form/partials/controls.twig b/resources/views/form/partials/controls.twig index 7d5313735..62b2947dd 100644 --- a/resources/views/form/partials/controls.twig +++ b/resources/views/form/partials/controls.twig @@ -2,15 +2,15 @@
{# TODO TEST ONLY -- REVERT #} -{# {% if not form.options.read_only %}#} -{#
#} -{# {{ buttons(form.actions)|raw }}#} -{#
#} -{# {% endif %}#} -{# #} -{#
#} -{# {{ buttons(form.buttons)|raw }}#} -{#
#} + {% if not form.options.read_only %} +
+ {{ buttons(form.actions)|raw }} +
+ {% endif %} + +
+ {{ buttons(form.buttons)|raw }} +
From 05b26dc56d301271e969945edfc2afa66226a7ea Mon Sep 17 00:00:00 2001 From: Fatih Alp Date: Mon, 25 Dec 2023 19:01:11 +0300 Subject: [PATCH 270/287] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f4a8d24a1..e223fcbad 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "visiosoft/streams-platform", + "name": "purepanel/streams-platform", "description": "A powerful, inclusive, modular PHP application engine built lovingly for Laravel.", "authors": [ { From 25d3697fc64190fb16449cc16b6e2378fa2b83e1 Mon Sep 17 00:00:00 2001 From: Fatih Alp Date: Mon, 25 Dec 2023 20:01:02 +0300 Subject: [PATCH 271/287] Remove HTTPCache, ProxySession, VerifyCsrfToken middleware --- composer.json | 2 +- src/Application/Console/Refresh.php | 2 +- src/Artisan/ArtisanServiceProvider.php | 3 +- src/Entry/Command/PurgeHttpCache.php | 74 ------- src/Entry/EntryObserver.php | 7 +- src/Http/Command/ClearHttpCache.php | 27 --- src/Http/Command/PurgeHttpCache.php | 46 ---- src/Http/Console/Warm.php | 78 ------- src/Http/Controller/BaseController.php | 12 +- src/Http/Controller/ResourceController.php | 8 - src/Http/Kernel.php | 6 +- src/Http/Middleware/HttpCache.php | 238 --------------------- src/Http/Middleware/ProxySession.php | 42 ---- src/Http/Middleware/VerifyCsrfToken.php | 102 --------- 14 files changed, 11 insertions(+), 636 deletions(-) delete mode 100644 src/Entry/Command/PurgeHttpCache.php delete mode 100644 src/Http/Command/ClearHttpCache.php delete mode 100644 src/Http/Command/PurgeHttpCache.php delete mode 100644 src/Http/Console/Warm.php delete mode 100644 src/Http/Middleware/HttpCache.php delete mode 100644 src/Http/Middleware/ProxySession.php delete mode 100644 src/Http/Middleware/VerifyCsrfToken.php diff --git a/composer.json b/composer.json index e223fcbad..f4a8d24a1 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "purepanel/streams-platform", + "name": "visiosoft/streams-platform", "description": "A powerful, inclusive, modular PHP application engine built lovingly for Laravel.", "authors": [ { diff --git a/src/Application/Console/Refresh.php b/src/Application/Console/Refresh.php index 4a72326f7..45941ce1c 100644 --- a/src/Application/Console/Refresh.php +++ b/src/Application/Console/Refresh.php @@ -40,7 +40,7 @@ public function handle(Kernel $console, Filesystem $files) /** * Clear the various caches. */ - $console->call('httpcache:clear', []); + // $console->call('httpcache:clear', []); $this->info('HTTP cache cleared.'); diff --git a/src/Artisan/ArtisanServiceProvider.php b/src/Artisan/ArtisanServiceProvider.php index 10c654aef..e199ee6dc 100644 --- a/src/Artisan/ArtisanServiceProvider.php +++ b/src/Artisan/ArtisanServiceProvider.php @@ -26,8 +26,7 @@ class ArtisanServiceProvider extends \Illuminate\Foundation\Providers\ArtisanSer protected $streamsCommands = [ // Cache Commands - \Anomaly\Streams\Platform\Http\Console\Warm::class, - + // \Anomaly\Streams\Platform\Http\Console\Warm::class, // Asset Commands \Anomaly\Streams\Platform\Asset\Console\Clear::class, diff --git a/src/Entry/Command/PurgeHttpCache.php b/src/Entry/Command/PurgeHttpCache.php deleted file mode 100644 index 456974f28..000000000 --- a/src/Entry/Command/PurgeHttpCache.php +++ /dev/null @@ -1,74 +0,0 @@ - - * @author Ryan Thompson - */ -class PurgeHttpCache -{ - - /** - * The entry object. - * - * @var EntryInterface - */ - protected $entry; - - /** - * Create a new PurgeHttpCache instance. - * - * @param EloquentModel $entry - */ - public function __construct(EntryInterface $entry) - { - $this->entry = $entry; - } - - /** - * Handle the command. - */ - public function handle() - { - if (!env('INSTALLED') || PHP_SAPI == 'cli' || !config('streams::httpcache.enabled')) { - return; - } - - /** - * In some very special and fancy - * situations this might not happen. - * - * So let's just try it. - * - * @var HttpCache $cache - */ - try { - $cache = app(HttpCache::class); - } catch (\Exception $exception) { - - \Log::error($exception->getMessage() . 'in [' . __CLASS__ . ']'); - - return; - } - - array_map( - function ($route) use ($cache) { - $cache->purge(parse_url($route, PHP_URL_PATH)); - }, - array_filter( - [ - $this->entry->route('view'), - $this->entry->route('index'), - $this->entry->route('preview'), - ] - ) - ); - } - -} diff --git a/src/Entry/EntryObserver.php b/src/Entry/EntryObserver.php index 2014a2a8b..4702d1fbd 100644 --- a/src/Entry/EntryObserver.php +++ b/src/Entry/EntryObserver.php @@ -1,7 +1,6 @@ flushCache(); - - dispatch_sync(new PurgeHttpCache($entry)); - + $entry->fireFieldTypeEvents('entry_updated'); $this->events->dispatch(new EntryWasUpdated($entry)); diff --git a/src/Http/Command/ClearHttpCache.php b/src/Http/Command/ClearHttpCache.php deleted file mode 100644 index e8b00ac62..000000000 --- a/src/Http/Command/ClearHttpCache.php +++ /dev/null @@ -1,27 +0,0 @@ - - * @author Ryan Thompson - */ -class ClearHttpCache -{ - - /** - * Handle the command. - * - * @param Filesystem $files - * @internal param Container $container - */ - public function handle(Filesystem $files) - { - foreach ($files->directories(config('httpcache.cache_dir', storage_path('httpcache'))) as $directory) { - $files->deleteDirectory($directory); - } - } -} diff --git a/src/Http/Command/PurgeHttpCache.php b/src/Http/Command/PurgeHttpCache.php deleted file mode 100644 index eadd60736..000000000 --- a/src/Http/Command/PurgeHttpCache.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @author Ryan Thompson - */ -class PurgeHttpCache -{ - - /** - * The path to purge. - * - * @var string - */ - protected $path; - - /** - * Create a new PurgeHttpCache instance. - * - * @param string $path - */ - public function __construct($path) - { - $this->path = $path; - } - - /** - * Handle the command. - */ - public function handle() - { - if (!env('INSTALLED') || PHP_SAPI == 'cli' || !config('streams::httpcache.enabled')) { - return; - } - - /* @var HttpCache $cache */ - $cache = app(HttpCache::class); - - $cache->purge(parse_url($this->path, PHP_URL_PATH)); - } -} diff --git a/src/Http/Console/Warm.php b/src/Http/Console/Warm.php deleted file mode 100644 index 58757f6fd..000000000 --- a/src/Http/Console/Warm.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @author Ryan Thompson - */ -class Warm extends Command -{ - - /** - * The command name. - * - * @var string - */ - protected $name = 'httpcache:warm'; - - /** - * Handle the command. - */ - public function handle() - { - if (config('streams::httpcache.enabled', false) === false) { - - $this->error('HTTP cache is not enabled.'); - - return; - } - - if ($this->option('clear')) { - $this->call('httpcache:clear'); - } - - $sleep = $this->option('sleep'); - - $sitemaps = simplexml_load_string(file_get_contents(config('app.url') . '/sitemap.xml')); - - foreach ($sitemaps as $sitemap) { - - if ($sleep) { - sleep($sleep); - } - - $this->info('Warming: ' . (string)$sitemap->loc); - - $items = simplexml_load_string(file_get_contents((string)$sitemap->loc)); - - foreach ($items as $item) { - - if ($sleep) { - sleep($sleep); - } - - file_get_contents((string)$item->loc); - - $this->info('Cached: ' . (string)$item->loc); - } - } - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['sleep', null, InputOption::VALUE_OPTIONAL, 'The wait time between each request.'], - ['clear', null, InputOption::VALUE_NONE, 'Clear cache before warming.'], - ]; - } -} diff --git a/src/Http/Controller/BaseController.php b/src/Http/Controller/BaseController.php index 0885962aa..21c2779a6 100644 --- a/src/Http/Controller/BaseController.php +++ b/src/Http/Controller/BaseController.php @@ -5,12 +5,10 @@ use Anomaly\Streams\Platform\Http\Middleware\ApplicationReady; use Anomaly\Streams\Platform\Http\Middleware\CheckLocale; use Anomaly\Streams\Platform\Http\Middleware\ForceSsl; -use Anomaly\Streams\Platform\Http\Middleware\HttpCache; use Anomaly\Streams\Platform\Http\Middleware\MiddlewareCollection; use Anomaly\Streams\Platform\Http\Middleware\PoweredBy; use Anomaly\Streams\Platform\Http\Middleware\PrefixDomain; use Anomaly\Streams\Platform\Http\Middleware\SetLocale; -use Anomaly\Streams\Platform\Http\Middleware\VerifyCsrfToken; use Anomaly\Streams\Platform\Message\MessageBag; use Anomaly\Streams\Platform\Routing\UrlGenerator; use Anomaly\Streams\Platform\Traits\FiresCallbacks; @@ -135,11 +133,10 @@ public function __construct() $this->route = $this->request->route(); event(new Response($this)); + + // $this->middleware(PoweredBy::class); - $this->middleware(PoweredBy::class); - - $this->middleware(VerifyCsrfToken::class); - + // $this->middleware(VerifyCsrfToken::class); $this->middleware(ForceSsl::class); $this->middleware(PrefixDomain::class); @@ -150,8 +147,7 @@ public function __construct() foreach (app(MiddlewareCollection::class) as $middleware) { $this->middleware($middleware); } - - $this->middleware(HttpCache::class); + // $this->middleware(HttpCache::class); } /** diff --git a/src/Http/Controller/ResourceController.php b/src/Http/Controller/ResourceController.php index 00ba5141f..60bfe328d 100644 --- a/src/Http/Controller/ResourceController.php +++ b/src/Http/Controller/ResourceController.php @@ -18,13 +18,5 @@ class ResourceController extends PublicController public function __construct() { parent::__construct(); - - // No CSRF protection. - $this->middleware = array_filter( - $this->middleware, - function ($item) { - return $item['middleware'] != VerifyCsrfToken::class; - } - ); } } diff --git a/src/Http/Kernel.php b/src/Http/Kernel.php index fd9237943..837ad4bd9 100644 --- a/src/Http/Kernel.php +++ b/src/Http/Kernel.php @@ -26,7 +26,7 @@ class Kernel extends \Illuminate\Foundation\Http\Kernel \Illuminate\View\Middleware\ShareErrorsFromSession::class, \Illuminate\Cookie\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, - \Anomaly\Streams\Platform\Http\Middleware\ProxySession::class, + // \Anomaly\Streams\Platform\Http\Middleware\ProxySession::class, /** * This needs work yet. Currently the CacheRequests * cause circular issues OR drop sessions if not @@ -57,8 +57,6 @@ class Kernel extends \Illuminate\Foundation\Http\Kernel */ protected $middlewareGroups = [ 'web' => [ - //\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class, - \Anomaly\Streams\Platform\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, ], 'api' => [ @@ -104,7 +102,7 @@ public function __construct(Application $app, Router $router) * @param array $middleware */ public function addMiddlewareGroup($group, $middleware = []) { - + $this->middlewareGroups[$group] = $middleware; $this->syncMiddlewareToRouter(); diff --git a/src/Http/Middleware/HttpCache.php b/src/Http/Middleware/HttpCache.php deleted file mode 100644 index fffaf954a..000000000 --- a/src/Http/Middleware/HttpCache.php +++ /dev/null @@ -1,238 +0,0 @@ - - * @author Ryan Thompson - */ -class HttpCache -{ - - /** - * System excluded. - * - * @var array - */ - protected $excluded = [ - '/admin', - '/admin/*', - '/streams/*-field_type/*', - '/streams/*-extension/*', - '/streams/*-module/*', - '/entry/handle/*', - '/form/handle/*', - '/locks/touch', - '/locks/release', - '/logout*', - ]; - - /** - * The agent utility. - * - * @var Agent - */ - protected $agent; - - /** - * The session store. - * - * @var Store - */ - protected $session; - - /** - * The message bag. - * - * @var MessageBag - */ - protected $messages; - - /** - * Create a new PoweredBy instance. - * - * @param Agent $agent - * @param Store $session - * @param MessageBag $messages - */ - public function __construct(Agent $agent, Store $session, MessageBag $messages) - { - $this->agent = $agent; - $this->session = $session; - $this->messages = $messages; - } - - /** - * Handle the command. - * - * @param Request $request - * @param \Closure $next - * @return mixed - */ - public function handle(Request $request, \Closure $next) - { - /* @var Response $response */ - $response = $next($request); - - /* @var Route $route */ - $route = $request->route(); - - /** - * Don't cache the admin. - * And skip the rest. - */ - if ($request->segment(1) == 'admin') { - return $response->setTtl(0); - } - - /** - * Don't cache if redirect is desired. - */ - if ($response instanceof RedirectResponse) { - return $response->setTtl(0); - } - - /** - * Don't cache if the route - * is dictating 0 ttl. - */ - if ($route->getAction('ttl') === 0) { - return $response->setTtl(0); - } - - /** - * Don't cache if HTTP cache - * is disabled in the route. - */ - if ($route->getAction('httpcache') === false) { - return $response->setTtl(0); - } - - /** - * Same thing.. no need for prefixing. - * @deprecated in 1.6 removing in 1.7 - */ - if ($route->getAction('streams::httpcache') === false) { - return $response->setTtl(0); - } - - /** - * Don't cache if HTTP cache - * is disabled in the system. - */ - if (config('streams::httpcache.enabled', false) === false) { - return $response->setTtl(0); - } - - /** - * Don't let BOTs generate cache files. - */ - if (config('streams::httpcache.allow_bots', false) === false && $this->agent->isRobot()) { - return $response->setTtl(0); - } - - /** - * Don't cache if we have session indicators! - * - * This could happen if a form attempts caching - * directly after a bad submit / failed validation. - */ - if ( - $this->session->get('_flash.new') || - $this->session->get('_flash.old') || - $this->messages->has('info') || - $this->messages->has('error') || - $this->messages->has('success') || - $this->messages->has('warning') - ) { - $response->setTtl(0); - } - - /** - * Determine the default TTL value. - */ - $default = $route->getAction('ttl') ?: config('streams::httpcache.ttl', 3600); - - /** - * Exclude these paths from caching - * based on partial / exact URI. - */ - $excluded = config('streams::httpcache.excluded', []); - - if (is_string($excluded)) { - $excluded = array_map( - function ($line) { - return trim($line); - }, - explode("\n", $excluded) - ); - } - - // Merge system excluded routes. - $excluded = array_merge((array) $excluded, $this->excluded); - - foreach ($excluded as $path) { - if (str_is($path, $request->getPathInfo())) { - $response->setTtl(0); - } - } - - /** - * Define timeout rules based on - * partial / exact URI matching. - */ - $rules = config('streams::httpcache.rules', []); - - if (is_string($rules)) { - $rules = array_map( - function ($line) { - return trim($line); - }, - explode("\n", $rules) - ); - } - - foreach ((array) $rules as $rule) { - - $parts = explode(' ', $rule); - - $path = array_shift($parts); - $ttl = array_shift($parts); - - if ($ttl === null) { - $ttl = $default; - } - - if (str_is($path, $request->getPathInfo())) { - $response->setTtl($ttl); - } - } - - /** - * Set the TTL based on the original TTL or the route - * action OR the config and lastly a default value. - */ - if ($response->getTtl() === null) { - $response->setTtl($default); - } - - /** - * If the response has a TTL then - * let's flush the flash messages. - */ - if ($response->getTtl()) { - $this->messages->flush(); - } - - return $response; - } -} diff --git a/src/Http/Middleware/ProxySession.php b/src/Http/Middleware/ProxySession.php deleted file mode 100644 index e57d80c8a..000000000 --- a/src/Http/Middleware/ProxySession.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @author Ryan Thompson - */ -class ProxySession -{ - - /** - * Push the user check state to cookie - * so that the services like HTTPCACHE - * can keep up with activity within the - * CMS which is generally bypassed early. - * - * @param Request $request - * @param Closure $next - * @return bool|\Illuminate\Http\RedirectResponse|mixed|string - */ - public function handle(Request $request, Closure $next) - { - $check = auth()->check(); - - $response = $next($request); - - if (method_exists($response, 'withCookie')) { - return $response->withCookie( - cookie('session_proxy', $check, $check ? config('session.lifetime', 120) : -1, null, null, $request->isSecure()) - ); - } - - return $response; - } -} diff --git a/src/Http/Middleware/VerifyCsrfToken.php b/src/Http/Middleware/VerifyCsrfToken.php deleted file mode 100644 index 558562388..000000000 --- a/src/Http/Middleware/VerifyCsrfToken.php +++ /dev/null @@ -1,102 +0,0 @@ - - * @author Ryan Thompson - */ -class VerifyCsrfToken extends \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken -{ - /** - * The route instance. - * - * @var Route - */ - protected $route; - - /** - * The message bar. - * - * @var MessageBag - */ - protected $messages; - - /** - * The redirector utility. - * - * @var Redirector - */ - protected $redirector; - - /** - * Create a new middleware instance. - * - * @param \Illuminate\Foundation\Application $app - * @param \Illuminate\Contracts\Encryption\Encrypter $encrypter - * @param MessageBag $messages - * @param Redirector $redirector - */ - public function __construct( - Route $route, - Application $app, - Encrypter $encrypter, - MessageBag $messages, - Redirector $redirector - ) { - parent::__construct($app, $encrypter); - - $this->except = config('streams::security.csrf.except', []); - $this->route = $route; - $this->messages = $messages; - $this->redirector = $redirector; - } - - /** - * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed - * - * @throws \Illuminate\Session\TokenMismatchException - */ - public function handle($request, Closure $next) - { - if ($this->shouldPassThrough()) { - return $this->addCookieToResponse($request, $next($request)); - } - - try { - return parent::handle($request, $next); - } catch (TokenMismatchException $exception) { - $this->messages->error('streams::message.csrf_token_mismatch'); - } - - return $this->redirector->back(302); - } - - /** - * If the route disabled the - * CSRF then we can skip it. - * - * @return bool - */ - public function shouldPassThrough() - { - if (array_get($this->route->getAction(), 'csrf') === false) { - return true; - } - - return false; - } -} From 58b3648eb157a21b5c3053a67d042ccfc2441055 Mon Sep 17 00:00:00 2001 From: emrullahardc Date: Thu, 1 Feb 2024 13:00:59 +0300 Subject: [PATCH 272/287] Addon Uninstall Bug Fix addon uninstall bug fix --- src/Database/Migration/MigrationRepository.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Database/Migration/MigrationRepository.php b/src/Database/Migration/MigrationRepository.php index cf012e1f2..afbc10b76 100644 --- a/src/Database/Migration/MigrationRepository.php +++ b/src/Database/Migration/MigrationRepository.php @@ -49,4 +49,15 @@ public function setMigrator(Migrator $migrator) return $this; } + + /** + * Remove a migration from the log. + * + * @param object $migration + * @return void + */ + public function delete($migration) + { + $this->table()->where('migration','LIKE', '%'.$migration->getAddon()->getNamespace().'%')->delete(); + } } From 2ecf85b194f86142a9d279826228f340df7900b4 Mon Sep 17 00:00:00 2001 From: emrullahardc Date: Thu, 22 Feb 2024 18:34:30 +0300 Subject: [PATCH 273/287] ORDERABLE COLUMN LANG FIX @spektra2147 --- src/Model/EloquentQueryBuilder.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index 9bdddc876..26f352e0e 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -313,7 +313,7 @@ protected function orderByDefault() } $this - ->translate() + ->translate(null, false) ->orderBy($model->getTranslationsTableName() . '.' . $model->getTitleName(), 'ASC'); } elseif ($model->getTitleName() && $model->getTitleName() !== 'id') { $query->orderBy($model->getTitleName(), 'ASC'); @@ -327,7 +327,7 @@ protected function orderByDefault() * * @param null $locale */ - public function translate($locale = null) + public function translate($locale = null, $getAllColumns = true) { /* @var EntryModel|EloquentModel $model */ $model = $this->getModel(); @@ -341,8 +341,9 @@ public function translate($locale = null) ); } - $this->query->addSelect( - [$model->getTableName() . '.*'] + + if ($getAllColumns){ + $this->query->addSelect( + [$model->getTableName() . '.*'] + array_map( function ($column) use ($model) { return $model->getTranslationTableName() . '.' . $column; @@ -360,7 +361,8 @@ function ($column) use ($model) { ] ) ) - ); + ); + } /** * removed to prevent data repeatation( getTranslationsTableName() ) From 34dcf6cbf230254836749b9667167e4ecc23fbf8 Mon Sep 17 00:00:00 2001 From: emrullahardc Date: Mon, 26 Feb 2024 11:46:00 +0300 Subject: [PATCH 274/287] Revert "ORDERABLE COLUMN LANG FIX" This reverts commit 2ecf85b194f86142a9d279826228f340df7900b4. --- src/Model/EloquentQueryBuilder.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index 26f352e0e..9bdddc876 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -313,7 +313,7 @@ protected function orderByDefault() } $this - ->translate(null, false) + ->translate() ->orderBy($model->getTranslationsTableName() . '.' . $model->getTitleName(), 'ASC'); } elseif ($model->getTitleName() && $model->getTitleName() !== 'id') { $query->orderBy($model->getTitleName(), 'ASC'); @@ -327,7 +327,7 @@ protected function orderByDefault() * * @param null $locale */ - public function translate($locale = null, $getAllColumns = true) + public function translate($locale = null) { /* @var EntryModel|EloquentModel $model */ $model = $this->getModel(); @@ -341,9 +341,8 @@ public function translate($locale = null, $getAllColumns = true) ); } - if ($getAllColumns){ - $this->query->addSelect( - [$model->getTableName() . '.*'] + + $this->query->addSelect( + [$model->getTableName() . '.*'] + array_map( function ($column) use ($model) { return $model->getTranslationTableName() . '.' . $column; @@ -361,8 +360,7 @@ function ($column) use ($model) { ] ) ) - ); - } + ); /** * removed to prevent data repeatation( getTranslationsTableName() ) From 90e9bf766ca21b586b667eaa3bd2717adcfeb711 Mon Sep 17 00:00:00 2001 From: spektra2147 Date: Mon, 26 Feb 2024 14:42:37 +0300 Subject: [PATCH 275/287] added select isSelect for order --- src/Model/EloquentQueryBuilder.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index 9bdddc876..d0813f829 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -49,14 +49,14 @@ class EloquentQueryBuilder extends Builder /** * Execute the query as a "select" statement. * - * @param array $columns + * @param array $columns * @return \Illuminate\Database\Eloquent\Collection|static[] */ public function get($columns = ['*']) { $key = $this->getCacheKey(); - $ttl = $this->model->ttl(); + $ttl = $this->model->ttl(); $collection = $this->model->getCacheCollectionKey(); $enabled = config('streams::database.cache', false); @@ -190,8 +190,8 @@ public function getCacheKey() $name = $this->model->getConnectionName(); return $this->model->getCacheCollectionKey() . ':' . md5( - $name . $this->toSql() . serialize($this->getBindings()) - ); + $name . $this->toSql() . serialize($this->getBindings()) + ); } /** @@ -234,7 +234,7 @@ public function cache($ttl = null) /** * Get fresh models / disable cache * - * @param boolean $fresh + * @param boolean $fresh * @return object */ public function fresh($fresh = true) @@ -249,7 +249,7 @@ public function fresh($fresh = true) /** * Update a record in the database. * - * @param array $values + * @param array $values * @return int */ public function update(array $values) @@ -340,9 +340,9 @@ public function translate($locale = null) $model->getTranslationsTableName() . '.entry_id' ); } - - $this->query->addSelect( - [$model->getTableName() . '.*'] + + if (!count($this->query->getColumns())) { + $this->query->addSelect( + [$model->getTableName() . '.*'] + array_map( function ($column) use ($model) { return $model->getTranslationTableName() . '.' . $column; @@ -360,7 +360,8 @@ function ($column) use ($model) { ] ) ) - ); + ); + } /** * removed to prevent data repeatation( getTranslationsTableName() ) @@ -374,8 +375,8 @@ function ($column) use ($model) { $this->query->where( function (\Illuminate\Database\Query\Builder $query) use ($model, $locale) { $query->where($model->getTranslationsTableName() . '.locale', $locale ?: config('app.locale'));//active language - $query->orWhere($model->getTranslationsTableName() . '.locale',setting_value('streams::default_locale'));//or default setting language - $query->orWhere($model->getTranslationsTableName() . '.locale','en');//or default module language + $query->orWhere($model->getTranslationsTableName() . '.locale', setting_value('streams::default_locale'));//or default setting language + $query->orWhere($model->getTranslationsTableName() . '.locale', 'en');//or default module language } ); From aac655227175be2201db6349494e32a565423e58 Mon Sep 17 00:00:00 2001 From: spektra2147 Date: Mon, 26 Feb 2024 14:46:15 +0300 Subject: [PATCH 276/287] added select translatable column --- src/Model/EloquentQueryBuilder.php | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index 9bdddc876..cbd4cf64e 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -382,6 +382,47 @@ function (\Illuminate\Database\Query\Builder $query) use ($model, $locale) { return $this; } + /** + * @param $columns + * @return EloquentQueryBuilder + * If there is a select and one of the added columns is a translatable column, + * translatable must be added to the query. Because when select is added, + * translatable columns are disabled and it is necessary to add it again. + */ + public function select($columns = ['*']) + { + if (is_array($columns)) { + $model = $this->getModel(); + + $translatableColumns = array_diff( + $this->getConnection()->getSchemaBuilder()->getColumnListing($model->getTranslationTableName()), + [ + 'id', + 'entry_id', + 'created_at', + 'created_by_id', + 'updated_at', + 'updated_by_id', + 'sort_order', + ] + ); + + $translatable = false; + foreach ($columns as $column) { + if (in_array($column, $translatableColumns)) { + $translatable = true; + break; + } + } + + if ($translatable) { + $this->translate(null); + } + } + + return parent::select($columns); + } + /** * Select the default columns. * From 2e7c0859232f1d4506787d4c9217dc490f6e3d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20AKDO=C4=9EAN?= <39536659+spektra2147@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:04:16 +0300 Subject: [PATCH 277/287] Update EloquentQueryBuilder.php --- src/Model/EloquentQueryBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index cbd4cf64e..82278c9a6 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -416,7 +416,7 @@ public function select($columns = ['*']) } if ($translatable) { - $this->translate(null); + $this->translate(); } } From a1ca3e784ecb283278a6a4cff559f6b5d847ad83 Mon Sep 17 00:00:00 2001 From: spektra2147 Date: Mon, 26 Feb 2024 15:09:08 +0300 Subject: [PATCH 278/287] lang fix --- src/Model/EloquentQueryBuilder.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index b1406d08b..0a99a5b96 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -368,18 +368,6 @@ function ($column) use ($model) { */ $this->query->groupBy([$model->getTableName() . '.id']); - /** - * Grab either what matches or null because - * that should cover every parent record. - */ - $this->query->where( - function (\Illuminate\Database\Query\Builder $query) use ($model, $locale) { - $query->where($model->getTranslationsTableName() . '.locale', $locale ?: config('app.locale'));//active language - $query->orWhere($model->getTranslationsTableName() . '.locale', setting_value('streams::default_locale'));//or default setting language - $query->orWhere($model->getTranslationsTableName() . '.locale', 'en');//or default module language - } - ); - return $this; } From 5cf80974e6a60a4a8f1299836d47d8229f0ab25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20AKDO=C4=9EAN?= <39536659+spektra2147@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:04:10 +0300 Subject: [PATCH 279/287] check Translatable stream --- src/Model/EloquentQueryBuilder.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index b1406d08b..161429527 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -392,8 +392,9 @@ function (\Illuminate\Database\Query\Builder $query) use ($model, $locale) { */ public function select($columns = ['*']) { - if (is_array($columns)) { - $model = $this->getModel(); + $model = $this->getModel(); + + if (is_array($columns) && $model->getStream()->isTranslatable()) { $translatableColumns = array_diff( $this->getConnection()->getSchemaBuilder()->getColumnListing($model->getTranslationTableName()), @@ -408,6 +409,7 @@ public function select($columns = ['*']) ] ); + $translatable = false; foreach ($columns as $column) { if (in_array($column, $translatableColumns)) { From 61ab0e4e0e63791258db2fc93614199b5b98d64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20AKDO=C4=9EAN?= <39536659+spektra2147@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:39:41 +0300 Subject: [PATCH 280/287] removed licence --- src/Installer/Console/Install.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Installer/Console/Install.php b/src/Installer/Console/Install.php index 334e2eaca..f379b2534 100644 --- a/src/Installer/Console/Install.php +++ b/src/Installer/Console/Install.php @@ -15,7 +15,6 @@ use Anomaly\Streams\Platform\Installer\Console\Command\SetOtherData; use Anomaly\Streams\Platform\Installer\Console\Command\RunInstallers; use Anomaly\Streams\Platform\Application\Command\WriteEnvironmentFile; -use Anomaly\Streams\Platform\Installer\Console\Command\ConfirmLicense; use Anomaly\Streams\Platform\Installer\Console\Command\SetStreamsData; use Anomaly\Streams\Platform\Application\Command\InitializeApplication; use Anomaly\Streams\Platform\Application\Command\ReloadEnvironmentFile; @@ -46,7 +45,6 @@ public function handle(AddonManager $manager) if (!$this->option('ready')) { - dispatch_sync(new ConfirmLicense($this)); dispatch_sync(new SetStreamsData($data)); dispatch_sync(new SetDatabaseData($data, $this)); dispatch_sync(new SetApplicationData($data, $this)); From 4d306403c01bf0365e473643cf3e470b8925bd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20AKDO=C4=9EAN?= <39536659+spektra2147@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:40:04 +0300 Subject: [PATCH 281/287] Delete src/Installer/Console/Command/ConfirmLicense.php --- .../Console/Command/ConfirmLicense.php | 46 ------------------- 1 file changed, 46 deletions(-) delete mode 100644 src/Installer/Console/Command/ConfirmLicense.php diff --git a/src/Installer/Console/Command/ConfirmLicense.php b/src/Installer/Console/Command/ConfirmLicense.php deleted file mode 100644 index af7ef5b4e..000000000 --- a/src/Installer/Console/Command/ConfirmLicense.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @author Ryan Thompson - */ -class ConfirmLicense -{ - - /** - * The console command. - * - * @var Command - */ - protected $command; - - /** - * Create a new ConfirmLicense instance. - * - * @param Command $command - */ - public function __construct(Command $command) - { - $this->command = $command; - } - - /** - * Handle the command. - */ - public function handle() - { - $this->command->info(strip_tags((new \Parsedown())->parse(file_get_contents(base_path('LICENSE.md'))))); - - if (!$this->command->confirm('Do you agree to the provided license and terms of service?')) { - - $this->command->error('You must agree to the license and terms of service before continuing.'); - - exit; - } - } -} From a879261cd667ff23bf70db70facf2f92e8fd0e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20AKDO=C4=9EAN?= <39536659+spektra2147@users.noreply.github.com> Date: Tue, 19 Mar 2024 14:11:21 +0300 Subject: [PATCH 282/287] fix parameters --- src/Model/EloquentQueryBuilder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index bf558c9ca..ffbcdfc94 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -380,6 +380,8 @@ function ($column) use ($model) { */ public function select($columns = ['*']) { + $columns = is_array($columns) ? $columns : func_get_args(); + $model = $this->getModel(); if (is_array($columns) && $model->getStream()->isTranslatable()) { From 2ecba793543301a007b4fe9ed9c797ae8719fd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20AKDO=C4=9EAN?= <39536659+spektra2147@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:35:54 +0300 Subject: [PATCH 283/287] fix addon reinstall --- src/Model/EloquentQueryBuilder.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Model/EloquentQueryBuilder.php b/src/Model/EloquentQueryBuilder.php index ffbcdfc94..f0a5d8945 100644 --- a/src/Model/EloquentQueryBuilder.php +++ b/src/Model/EloquentQueryBuilder.php @@ -384,7 +384,11 @@ public function select($columns = ['*']) $model = $this->getModel(); - if (is_array($columns) && $model->getStream()->isTranslatable()) { + if ( + is_array($columns) && + method_exists($model, 'getStream') && + $model->getStream() && + $model->getStream()->isTranslatable()) { $translatableColumns = array_diff( $this->getConnection()->getSchemaBuilder()->getColumnListing($model->getTranslationTableName()), From e82067af1cb0a952504736743fa41d55293dec37 Mon Sep 17 00:00:00 2001 From: emrullahardc Date: Mon, 3 Jun 2024 14:36:33 +0300 Subject: [PATCH 284/287] submenus added --- .../Component/Navigation/NavigationBuilder.php | 17 +++++++++++++++-- .../Component/Navigation/NavigationHandler.php | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php b/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php index b9d387877..d59f26b23 100644 --- a/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php +++ b/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php @@ -45,12 +45,25 @@ public function __construct(NavigationInput $input, NavigationFactory $factory) */ public function build(ControlPanelBuilder $builder) { + $controlPanel = $builder->getControlPanel(); $this->input->read($builder); - foreach ($builder->getNavigation() as $link) { - $controlPanel->addNavigationLink($this->factory->make($link)); + if (!empty($link['sections'])) { + foreach ($link['sections'] as $key => $section) { + $tmpLink = $link; + if (isset($section['href'])) { + $tmpLink['attributes']['href'] = $section['href']; + } else { + $tmpLink['attributes']['href'] .= "/" . $key; + } + $tmpLink['title'] = $tmpLink['slug'] . "::section." . $key . ".title"; + $controlPanel->addNavigationLink($this->factory->make($tmpLink)); + } + }else{ + $controlPanel->addNavigationLink($this->factory->make($link)); + } } } } diff --git a/src/Ui/ControlPanel/Component/Navigation/NavigationHandler.php b/src/Ui/ControlPanel/Component/Navigation/NavigationHandler.php index 22a51977e..51a5b390b 100644 --- a/src/Ui/ControlPanel/Component/Navigation/NavigationHandler.php +++ b/src/Ui/ControlPanel/Component/Navigation/NavigationHandler.php @@ -40,6 +40,7 @@ function (Module $module) { 'icon' => $module->getIcon(), 'title' => $module->getTitle(), 'slug' => $module->getNamespace(), + 'sections' => $module->getSections(), 'href' => 'admin/' . $module->getSlug(), ]; }, From 27fcff5858f834f8e4dcaab270e68e52adcc5b96 Mon Sep 17 00:00:00 2001 From: emrullahardc Date: Mon, 3 Jun 2024 19:50:03 +0300 Subject: [PATCH 285/287] sectionlink renamed --- .../Navigation/NavigationBuilder.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php b/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php index d59f26b23..8e8c0484b 100644 --- a/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php +++ b/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php @@ -29,12 +29,12 @@ class NavigationBuilder /** * Create a new NavigationBuilder instance. * - * @param NavigationInput $input + * @param NavigationInput $input * @param NavigationFactory $factory */ public function __construct(NavigationInput $input, NavigationFactory $factory) { - $this->input = $input; + $this->input = $input; $this->factory = $factory; } @@ -52,16 +52,19 @@ public function build(ControlPanelBuilder $builder) foreach ($builder->getNavigation() as $link) { if (!empty($link['sections'])) { foreach ($link['sections'] as $key => $section) { - $tmpLink = $link; + $sectionLink = $link; if (isset($section['href'])) { - $tmpLink['attributes']['href'] = $section['href']; + $sectionLink['attributes']['href'] = $section['href']; } else { - $tmpLink['attributes']['href'] .= "/" . $key; + $sectionLink['attributes']['href'] .= "/" . $key; } - $tmpLink['title'] = $tmpLink['slug'] . "::section." . $key . ".title"; - $controlPanel->addNavigationLink($this->factory->make($tmpLink)); + $sectionLink['title'] = $sectionLink['slug'] . "::section." . $key . ".title"; + if (empty($sectionLink['title'])) { + + } + $controlPanel->addNavigationLink($this->factory->make($sectionLink)); } - }else{ + } else { $controlPanel->addNavigationLink($this->factory->make($link)); } } From fbf3a7adb0e3f0c0bdf6bd9e08aa25753fc565af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20AKDO=C4=9EAN?= <39536659+spektra2147@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:20:02 +0300 Subject: [PATCH 286/287] Revert "submenus added" --- .../Navigation/NavigationBuilder.php | 24 ++++--------------- .../Navigation/NavigationHandler.php | 1 - 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php b/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php index 8e8c0484b..b9d387877 100644 --- a/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php +++ b/src/Ui/ControlPanel/Component/Navigation/NavigationBuilder.php @@ -29,12 +29,12 @@ class NavigationBuilder /** * Create a new NavigationBuilder instance. * - * @param NavigationInput $input + * @param NavigationInput $input * @param NavigationFactory $factory */ public function __construct(NavigationInput $input, NavigationFactory $factory) { - $this->input = $input; + $this->input = $input; $this->factory = $factory; } @@ -45,28 +45,12 @@ public function __construct(NavigationInput $input, NavigationFactory $factory) */ public function build(ControlPanelBuilder $builder) { - $controlPanel = $builder->getControlPanel(); $this->input->read($builder); - foreach ($builder->getNavigation() as $link) { - if (!empty($link['sections'])) { - foreach ($link['sections'] as $key => $section) { - $sectionLink = $link; - if (isset($section['href'])) { - $sectionLink['attributes']['href'] = $section['href']; - } else { - $sectionLink['attributes']['href'] .= "/" . $key; - } - $sectionLink['title'] = $sectionLink['slug'] . "::section." . $key . ".title"; - if (empty($sectionLink['title'])) { - } - $controlPanel->addNavigationLink($this->factory->make($sectionLink)); - } - } else { - $controlPanel->addNavigationLink($this->factory->make($link)); - } + foreach ($builder->getNavigation() as $link) { + $controlPanel->addNavigationLink($this->factory->make($link)); } } } diff --git a/src/Ui/ControlPanel/Component/Navigation/NavigationHandler.php b/src/Ui/ControlPanel/Component/Navigation/NavigationHandler.php index 51a5b390b..22a51977e 100644 --- a/src/Ui/ControlPanel/Component/Navigation/NavigationHandler.php +++ b/src/Ui/ControlPanel/Component/Navigation/NavigationHandler.php @@ -40,7 +40,6 @@ function (Module $module) { 'icon' => $module->getIcon(), 'title' => $module->getTitle(), 'slug' => $module->getNamespace(), - 'sections' => $module->getSections(), 'href' => 'admin/' . $module->getSlug(), ]; }, From 8a5d5a981075d069b05ebf4de5ed6133af26d488 Mon Sep 17 00:00:00 2001 From: Fatih Alp Date: Mon, 15 Jul 2024 13:00:07 +0300 Subject: [PATCH 287/287] Update AddonManager.php --- src/Addon/AddonManager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Addon/AddonManager.php b/src/Addon/AddonManager.php index e96f94fdc..3ff0f707c 100644 --- a/src/Addon/AddonManager.php +++ b/src/Addon/AddonManager.php @@ -333,6 +333,10 @@ protected function getAddonNamespace($path) if (!class_exists($class)) { $composer_namespace = dispatch_sync(new GetNamespaceWithComposer($path)); + if(empty($composer_namespace)) { + die($path. ' ' . $composer_namespace . ' not found'); + } + list($vendor, $type, $slug) = explode('.', $composer_namespace); $class = studly_case($vendor) . '\\' . studly_case($slug) . studly_case($type) . '\\' . studly_case(