From 027dbcf6fadc15e6d8123a157cc52212e8700f0c Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 27 Apr 2018 15:40:03 -0600 Subject: [PATCH 1/5] Added `Uri::post()` and `Uri::getConentType()` --- system/src/Grav/Common/Uri.php | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 70164226c2..412a3abd5a 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -49,6 +49,8 @@ class Uri protected $root; protected $root_path; protected $uri; + protected $content_type; + protected $post; /** * Uri constructor. @@ -1235,6 +1237,55 @@ protected function reset() $this->url = $this->base . $this->uri; } + /** + * Get's post from either $_POST or JSON response object + * By default returns all data, or can return a single item + * + * @param string $element + * @param string $filter_type + * @return array|mixed|null + */ + public function post($element = null, $filter_type = null) + { + if (!$this->post) { + $content_type = $this->getContentType(); + if ($content_type == 'application/json') { + $json = file_get_contents('php://input'); + $this->post = json_decode($json, true); + } elseif (!empty($_POST)) { + $this->post = (array)$_POST; + } + } + + if ($this->post && !is_null($element)) { + $item = Utils::getDotNotation($this->post, $element); + if ($filter_type) { + $item = filter_var($item, $filter_type); + } + return $item; + } + + return $this->post; + } + + /** + * Get content type from request + * + * @param bool $short + * @return null|string + */ + private function getContentType($short = true) + { + if (isset($_SERVER['CONTENT_TYPE'])) { + $content_type = $_SERVER['CONTENT_TYPE']; + if ($short) { + return Utils::substrToString($content_type,';'); + } + return $content_type; + } + return null; + } + /** * Get the base URI with port if needed * From d4ec2a25d4b4148583ef7d080ac25efe8cf92801 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 28 Apr 2018 19:24:14 +0200 Subject: [PATCH 2/5] Add default configuration for images (#1979) This patch allows configuring image processing instructions for all images. A use case is generating a fixed set of sizes (derivatives) for all images, without having to specify them in the content markdown. Example configuration in user/config/system.yaml: images: defaults: derivatives: "[300,600,1200]" --- system/src/Grav/Common/Helpers/Excerpts.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system/src/Grav/Common/Helpers/Excerpts.php b/system/src/Grav/Common/Helpers/Excerpts.php index d774bcf463..3561bc365c 100644 --- a/system/src/Grav/Common/Helpers/Excerpts.php +++ b/system/src/Grav/Common/Helpers/Excerpts.php @@ -294,6 +294,15 @@ public static function processMediaActions($medium, $url) if (Grav::instance()['config']->get('system.images.auto_fix_orientation')) { $actions[] = ['method' => 'fixOrientation', 'params' => '']; } + $defaults = Grav::instance()['config']->get('system.images.defaults'); + if (is_array($defaults) && count($defaults)) { + foreach ($defaults as $method => $params) { + $actions[] = [ + 'method' => $method, + 'params' => $params, + ]; + } + } // loop through actions for the image and call them foreach ($actions as $action) { From 40ba5e910656f641aceae8405ce21af3fbf8f543 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sat, 28 Apr 2018 14:24:43 -0300 Subject: [PATCH 3/5] Use dedicated PHPUnit assertions (#1990) Signed-off-by: Gabriel Caruso --- tests/unit/Grav/Common/AssetsTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index 0d3197410c..a54b88a4aa 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -499,49 +499,49 @@ public function testReset() { $this->assets->addInlineJs('alert("test")'); $this->assets->reset(); - $this->assertSame(0, count((array) $this->assets->js())); + $this->assertCount(0, (array) $this->assets->js()); $this->assets->addAsyncJs('jquery'); $this->assets->reset(); - $this->assertSame(0, count((array) $this->assets->js())); + $this->assertCount(0, (array) $this->assets->js()); $this->assets->addInlineCss('body { color: black }'); $this->assets->reset(); - $this->assertSame(0, count((array) $this->assets->css())); + $this->assertCount(0, (array) $this->assets->css()); $this->assets->add('/system/assets/debugger.css', null, true); $this->assets->reset(); - $this->assertSame(0, count((array) $this->assets->css())); + $this->assertCount(0, (array) $this->assets->css()); } public function testResetJs() { $this->assets->addInlineJs('alert("test")'); $this->assets->resetJs(); - $this->assertSame(0, count((array) $this->assets->js())); + $this->assertCount(0, (array) $this->assets->js()); $this->assets->addAsyncJs('jquery'); $this->assets->resetJs(); - $this->assertSame(0, count((array) $this->assets->js())); + $this->assertCount(0, (array) $this->assets->js()); } public function testResetCss() { - $this->assertSame(0, count((array) $this->assets->js())); + $this->assertCount(0, (array) $this->assets->js()); $this->assets->addInlineCss('body { color: black }'); $this->assets->resetCss(); - $this->assertSame(0, count((array) $this->assets->css())); + $this->assertCount(0, (array) $this->assets->css()); $this->assets->add('/system/assets/debugger.css', null, true); $this->assets->resetCss(); - $this->assertSame(0, count((array) $this->assets->css())); + $this->assertCount(0, (array) $this->assets->css()); } public function testAddDirCss() From 4ab0a601ad85060cca2625c0d0773ffb262d2e3e Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sat, 28 Apr 2018 14:25:41 -0300 Subject: [PATCH 4/5] Use array_key_exists instead of in_array + array_keys (#1991) --- system/src/Grav/Console/Gpm/InstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index 3281fd923a..d7e932e4ec 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -182,7 +182,7 @@ protected function serve() //We're done installing dependencies. Install the actual packages foreach ($this->data as $data) { foreach ($data as $package_name => $package) { - if (in_array($package_name, array_keys($dependencies))) { + if (array_key_exists($package_name, $dependencies)) { $this->output->writeln("Package " . $package_name . " already installed as dependency"); } else { $is_valid_destination = Installer::isValidDestination($this->destination . DS . $package->install_path); From 40b475ecb988d358042ae0d33576fbce4ccda381 Mon Sep 17 00:00:00 2001 From: Dmitry Yakovlev Date: Sat, 28 Apr 2018 20:29:28 +0300 Subject: [PATCH 5/5] Fix hardcoded string (#1993) Fix hard-coded string "Modular Setup" to improve internationalization. Needs new string PLUGIN_ADMIN.MODULAR_SETUP in Admin plugin language file. --- system/blueprints/pages/modular.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/blueprints/pages/modular.yaml b/system/blueprints/pages/modular.yaml index 21ecb71810..94f56506a4 100644 --- a/system/blueprints/pages/modular.yaml +++ b/system/blueprints/pages/modular.yaml @@ -13,7 +13,7 @@ form: modular_title: type: spacer - title: Modular Setup + title: PLUGIN_ADMIN.MODULAR_SETUP header.content.items: type: text