From c053a153fe9030db71591642389b57a915cae777 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 8 Mar 2016 14:32:44 -0700 Subject: [PATCH 1/5] Code analysis fixes --- system/src/Grav/Common/GPM/AbstractCollection.php | 1 - system/src/Grav/Common/GPM/Common/AbstractPackageCollection.php | 1 - system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 2 -- system/src/Grav/Common/Page/Media.php | 1 - system/src/Grav/Common/Page/Page.php | 1 - 5 files changed, 6 deletions(-) diff --git a/system/src/Grav/Common/GPM/AbstractCollection.php b/system/src/Grav/Common/GPM/AbstractCollection.php index 1b0ac3e7d..25e4e4125 100644 --- a/system/src/Grav/Common/GPM/AbstractCollection.php +++ b/system/src/Grav/Common/GPM/AbstractCollection.php @@ -1,7 +1,6 @@ Date: Tue, 8 Mar 2016 14:42:07 -0700 Subject: [PATCH 2/5] code analysis fixes --- system/src/Grav/Common/Backup/ZipBackup.php | 1 - system/src/Grav/Common/Data/Validation.php | 1 - system/src/Grav/Common/Data/ValidationException.php | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Backup/ZipBackup.php b/system/src/Grav/Common/Backup/ZipBackup.php index e69b4431f..ebafdacf3 100644 --- a/system/src/Grav/Common/Backup/ZipBackup.php +++ b/system/src/Grav/Common/Backup/ZipBackup.php @@ -2,7 +2,6 @@ namespace Grav\Common\Backup; use Grav\Common\Grav; -use Grav\Common\Filesystem\Folder; use Grav\Common\Inflector; /** diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index 03b57a472..270363ebc 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -2,7 +2,6 @@ namespace Grav\Common\Data; use Grav\Common\Grav; -use Grav\Common\GravTrait; use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Parser; diff --git a/system/src/Grav/Common/Data/ValidationException.php b/system/src/Grav/Common/Data/ValidationException.php index 20011cb8e..3b3584dfa 100644 --- a/system/src/Grav/Common/Data/ValidationException.php +++ b/system/src/Grav/Common/Data/ValidationException.php @@ -27,4 +27,4 @@ class ValidationException extends \RuntimeException { return $this->messages; } -} \ No newline at end of file +} From ba286cf8c5bfe66c1047ab1904417c142451e6bb Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 9 Mar 2016 19:54:55 -0700 Subject: [PATCH 3/5] minor vendor updates --- composer.lock | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/composer.lock b/composer.lock index abc0ccda8..d42505907 100644 --- a/composer.lock +++ b/composer.lock @@ -134,12 +134,12 @@ "source": { "type": "git", "url": "https://github.com/erusev/parsedown.git", - "reference": "94688f21cc5d8bc85f1783b4c8b98b3288d712cb" + "reference": "490a8f35a4163f59230f53c34f1fbb22a864c01e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/erusev/parsedown/zipball/94688f21cc5d8bc85f1783b4c8b98b3288d712cb", - "reference": "94688f21cc5d8bc85f1783b4c8b98b3288d712cb", + "url": "https://api.github.com/repos/erusev/parsedown/zipball/490a8f35a4163f59230f53c34f1fbb22a864c01e", + "reference": "490a8f35a4163f59230f53c34f1fbb22a864c01e", "shasum": "" }, "require": { @@ -168,7 +168,7 @@ "markdown", "parser" ], - "time": "2016-01-07 17:36:51" + "time": "2016-03-09 17:02:39" }, { "name": "erusev/parsedown-extra", @@ -802,16 +802,16 @@ }, { "name": "symfony/polyfill-iconv", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-iconv.git", - "reference": "be8627f0936f86fed0bec16fe79ebb4337299764" + "reference": "08e3b8768d785ba7f271ef94906d50f7efe72ce8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/be8627f0936f86fed0bec16fe79ebb4337299764", - "reference": "be8627f0936f86fed0bec16fe79ebb4337299764", + "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/08e3b8768d785ba7f271ef94906d50f7efe72ce8", + "reference": "08e3b8768d785ba7f271ef94906d50f7efe72ce8", "shasum": "" }, "require": { @@ -857,11 +857,11 @@ "portable", "shim" ], - "time": "2016-01-20 09:13:37" + "time": "2016-02-26 11:31:02" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", @@ -1386,16 +1386,16 @@ }, { "name": "guzzlehttp/promises", - "version": "1.0.3", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea" + "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/b1e1c0d55f8083c71eda2c28c12a228d708294ea", - "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea", + "url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8", + "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8", "shasum": "" }, "require": { @@ -1433,7 +1433,7 @@ "keywords": [ "promise" ], - "time": "2015-10-15 22:28:00" + "time": "2016-03-08 01:15:46" }, { "name": "guzzlehttp/psr7", From 0716f96d8dafd2fd65187cf0e7bdca76e8256349 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Wed, 9 Mar 2016 20:22:36 -0800 Subject: [PATCH 4/5] Added `json_decode` and `get_cookie` twig filters --- system/src/Grav/Common/Twig/TwigExtension.php | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php index a385bfe17..fb37f934c 100644 --- a/system/src/Grav/Common/Twig/TwigExtension.php +++ b/system/src/Grav/Common/Twig/TwigExtension.php @@ -25,9 +25,9 @@ class TwigExtension extends \Twig_Extension */ public function __construct() { - $this->grav = Grav::instance(); + $this->grav = Grav::instance(); $this->debugger = isset($this->grav['debugger']) ? $this->grav['debugger'] : null; - $this->config = $this->grav['config']; + $this->config = $this->grav['config']; } /** @@ -85,6 +85,7 @@ class TwigExtension extends \Twig_Extension new \Twig_SimpleFilter('ta', [$this, 'translateArray']), new \Twig_SimpleFilter('truncate', ['\Grav\Common\Utils', 'truncate']), new \Twig_SimpleFilter('truncate_html', ['\Grav\Common\Utils', 'truncateHTML']), + new \Twig_SimpleFilter('json_decode', [$this, 'jsonDecodeFilter']), ]; } @@ -111,8 +112,8 @@ class TwigExtension extends \Twig_Extension new \Twig_simpleFunction('t', [$this, 'translate']), new \Twig_simpleFunction('ta', [$this, 'translateArray']), new \Twig_SimpleFunction('url', [$this, 'urlFunc']), - - + new \Twig_SimpleFunction('json_decode', [$this, 'jsonDecodeFilter']), + new \Twig_SimpleFunction('get_cookie', [$this, 'getCookie']), ]; } @@ -139,7 +140,7 @@ class TwigExtension extends \Twig_Extension */ public function safeEmailFilter($str) { - $email = ''; + $email = ''; $str_len = strlen($str); for ($i = 0; $i < $str_len; $i++) { $email .= "&#" . ord($str[$i]) . ";"; @@ -374,11 +375,11 @@ class TwigExtension extends \Twig_Extension // is it future date or past date if ($now > $unix_date) { $difference = $now - $unix_date; - $tense = $this->grav['language']->translate('NICETIME.AGO', null, true); + $tense = $this->grav['language']->translate('NICETIME.AGO', null, true); } else { $difference = $unix_date - $now; - $tense = $this->grav['language']->translate('NICETIME.FROM_NOW', null, true); + $tense = $this->grav['language']->translate('NICETIME.FROM_NOW', null, true); } for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) { @@ -411,7 +412,7 @@ class TwigExtension extends \Twig_Extension */ public function absoluteUrlFilter($string) { - $url = $this->grav['uri']->base(); + $url = $this->grav['uri']->base(); $string = preg_replace('/((?:href|src) *= *[\'"](?!(http|ftp)))/i', "$1$url", $string); return $string; @@ -425,7 +426,7 @@ class TwigExtension extends \Twig_Extension */ public function markdownFilter($string) { - $page = $this->grav['page']; + $page = $this->grav['page']; $defaults = $this->config->get('system.pages.markdown'); // Initialize the preferred variant of Parsedown @@ -674,16 +675,16 @@ class TwigExtension extends \Twig_Extension * Workaround for twig associative array initialization * Returns a key => val array * - * @param string $key key of item - * @param string $val value of item - * @param string $current_array optional array to add to + * @param string $key key of item + * @param string $val value of item + * @param string $current_array optional array to add to * * @return array */ public function arrayKeyValueFunc($key, $val, $current_array = null) { if (empty($current_array)) { - return array( $key => $val ); + return array($key => $val); } else { $current_array[$key] = $val; return $current_array; @@ -757,14 +758,40 @@ class TwigExtension extends \Twig_Extension return $string; } + /** + * Decodes string from JSON. + * + * @param string $str + * @param bool $assoc + * @param int $depth + * @param int $options + * @return array + */ + public function jsonDecodeFilter($str, $assoc = false, $depth = 512, $options = 0) + { + return json_decode(html_entity_decode($str), $assoc, $depth, $options); + } + + /** + * Used to retrieve a cookie value + * + * @param string $key The cookie name to retrieve + * + * @return mixed + */ + public function getCookie($key) + { + return filter_input(INPUT_COOKIE, $key, FILTER_SANITIZE_STRING); + } + /** * Twig wrapper for PHP's preg_replace method * - * @param mixed $subject the content to perform the replacement on - * @param mixed $pattern the regex pattern to use for matches - * @param mixed $replace the replacement value either as a string or an array of replacements - * @param int $limit the maximum possible replacements for each pattern in each subject - + * @param mixed $subject the content to perform the replacement on + * @param mixed $pattern the regex pattern to use for matches + * @param mixed $replace the replacement value either as a string or an array of replacements + * @param int $limit the maximum possible replacements for each pattern in each subject + * * @return mixed the resulting content */ public function regexReplace($subject, $pattern, $replace, $limit = -1) From 9119ce8679d393bb71a249f94be6cb78540e3ec0 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 10 Mar 2016 10:28:19 -0700 Subject: [PATCH 5/5] Should fix download issues with gzip enabled - #723 --- system/src/Grav/Common/Utils.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 9cd5b9b46..6f69480b6 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -241,6 +241,10 @@ abstract class Utils ignore_user_abort(false); // fix corrupted files + if (Grav::instance()['config']->get('system.cache.gzip')) { + // Flush gzhandler buffer if gzip setting was enabled. + ob_end_clean(); + } ob_clean(); if ($force_download) {