From c45652de81f77256c30642afe9c9971ee8b09f09 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 14 Dec 2015 14:21:39 +0100 Subject: [PATCH 01/33] Make sure Grav can work with the 2.0.0-alpha1 Whoops update, and with the current 1.1 too --- system/src/Grav/Common/Errors/Errors.php | 76 ++++++++++--------- .../Common/Service/ErrorServiceProvider.php | 26 ------- 2 files changed, 40 insertions(+), 62 deletions(-) diff --git a/system/src/Grav/Common/Errors/Errors.php b/system/src/Grav/Common/Errors/Errors.php index 61e62625c..b201bfb94 100644 --- a/system/src/Grav/Common/Errors/Errors.php +++ b/system/src/Grav/Common/Errors/Errors.php @@ -2,51 +2,55 @@ namespace Grav\Common\Errors; use Grav\Common\Grav; -use Whoops\Handler\CallbackHandler; -use Whoops\Handler\HandlerInterface; -use Whoops\Run; +use Whoops; /** * Class Debugger * @package Grav\Common */ -class Errors extends Run +class Errors { - - public function pushHandler($handler, $key = null) - { - if (is_callable($handler)) { - $handler = new CallbackHandler($handler); - } - - if (!$handler instanceof HandlerInterface) { - throw new \InvalidArgumentException( - "Argument to " . __METHOD__ . " must be a callable, or instance of" - . "Whoops\\Handler\\HandlerInterface" - ); - } - - // Store with key if provided - if ($key) { - $this->handlerStack[$key] = $handler; - } else { - $this->handlerStack[] = $handler; - } - - return $this; - } - public function resetHandlers() { $grav = Grav::instance(); $config = $grav['config']->get('system.errors'); - if (isset($config['display']) && !$config['display']) { - unset($this->handlerStack['pretty']); - $this->handlerStack = array('simple' => new SimplePageHandler()) + $this->handlerStack; - } - if (isset($config['log']) && !$config['log']) { - unset($this->handlerStack['log']); - } - } + // Setup Whoops-based error handler + $whoops = new \Whoops\Run; + + if (isset($config['display'])) { + if ($config['display']) { + $error_page = new Whoops\Handler\PrettyPageHandler; + $error_page->setPageTitle('Crikey! There was an error...'); + $error_page->setEditor('sublime'); + $error_page->addResourcePath(GRAV_ROOT . '/system/assets'); + $error_page->addCustomCss('whoops.css'); + $whoops->pushHandler($error_page); + } else { + $whoops->pushHandler(new SimplePageHandler); + } + } + + if (function_exists('Whoops\isAjaxRequest')) { //Whoops 2 + if (Whoops\isAjaxRequest()) { + $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler); + } + } else { //Whoops 1 + $json_page = new Whoops\Handler\JsonResponseHandler; + $json_page->onlyForAjaxRequests(true); + } + + if (isset($config['log']) && $config['log']) { + $logger = $grav['log']; + $whoops->pushHandler(function($exception, $inspector, $run) use ($logger) { + try { + $logger->addCritical($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString()); + } catch (\Exception $e) { + echo $e; + } + }, 'log'); + } + + $whoops->register(); + } } diff --git a/system/src/Grav/Common/Service/ErrorServiceProvider.php b/system/src/Grav/Common/Service/ErrorServiceProvider.php index ac676ad98..3417354e4 100644 --- a/system/src/Grav/Common/Service/ErrorServiceProvider.php +++ b/system/src/Grav/Common/Service/ErrorServiceProvider.php @@ -12,33 +12,7 @@ class ErrorServiceProvider implements ServiceProviderInterface { public function register(Container $container) { - // Setup Whoops-based error handler $errors = new Errors; - - $error_page = new PrettyPageHandler; - $error_page->setPageTitle('Crikey! There was an error...'); - $error_page->setEditor('sublime'); - $error_page->addResourcePath(GRAV_ROOT . '/system/assets'); - $error_page->addCustomCss('whoops.css'); - - $json_page = new JsonResponseHandler; - $json_page->onlyForAjaxRequests(true); - - $errors->pushHandler($error_page, 'pretty'); - $errors->pushHandler(new PlainTextHandler, 'text'); - $errors->pushHandler($json_page, 'json'); - - $logger = $container['log']; - $errors->pushHandler(function (\Exception $exception, $inspector, $run) use ($logger) { - try { - $logger->addCritical($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString()); - } catch (\Exception $e) { - echo $e; - } - }, 'log'); - - $errors->register(); - $container['errors'] = $errors; } } From 78accfe98b7c31af821c83c63aa10784f4ecd5b9 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Tue, 15 Dec 2015 22:58:31 +0100 Subject: [PATCH 02/33] Bump whoops version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 302cabfdc..5fff88f73 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "symfony/var-dumper": "~2.8", "symfony/polyfill-iconv": "~1.0", "doctrine/cache": "~1.5", - "filp/whoops": "1.1.10", + "filp/whoops": "2.0.0-alpha2", "monolog/monolog": "~1.0", "gregwar/image": "~2.0", "ircmaxell/password-compat": "1.0.*", From 215b2cdfa840e5cd6870a207c9141ccd7212c751 Mon Sep 17 00:00:00 2001 From: Mike Wink Date: Sat, 19 Dec 2015 00:12:01 +0100 Subject: [PATCH 03/33] Fixed hardcoded string "Security" Added the PLUGIN_ADMIN.SECURITY constant instead. Will add this to the admin language files too. --- system/blueprints/user/account.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/blueprints/user/account.yaml b/system/blueprints/user/account.yaml index 81a659d0c..f9adc56be 100644 --- a/system/blueprints/user/account.yaml +++ b/system/blueprints/user/account.yaml @@ -55,7 +55,7 @@ form: help: PLUGIN_ADMIN.LANGUAGE_HELP security: - title: Security + title: PLUGIN_ADMIN.SECURITY type: section security: admin.super @@ -82,4 +82,4 @@ form: label: PLUGIN_ADMIN.SITE_ACCESS multiple: false validate: - type: array \ No newline at end of file + type: array From d2ed424a7c7a08f56f6035a32406886bba1a5744 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Fri, 18 Dec 2015 16:05:35 -0800 Subject: [PATCH 04/33] Fixed Travis parsing error [ci skip] --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c458c24ef..680635957 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ before_install: - export TZ=Pacific/Honolulu - composer self-update - go get github.com/aktau/github-release - - echo "Travis Date: `date`" + - echo "Travis Date - `date`" - git clone --quiet --depth=50 --branch=master https://${BB_TOKEN}bitbucket.org/rockettheme/grav-devtools.git $RT_DEVTOOLS &>/dev/null; - if [ ! -z "$TRAVIS_TAG" ]; then cd "${RT_DEVTOOLS}"; From 8f9cdad916eb0251f1d11efa21bfffb9c7425f43 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 18 Dec 2015 20:50:07 -0700 Subject: [PATCH 05/33] Updated spelling in Parsedown to match imminent update --- .../Common/Markdown/ParsedownGravTrait.php | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index a735a2ca9..460cf7490 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -18,8 +18,8 @@ trait ParsedownGravTrait protected $special_chars; protected $twig_link_regex = '/\!*\[(?:.*)\]\((\{([\{%#])\s*(.*?)\s*(?:\2|\})\})\)/'; - public $completeable_blocks = []; - public $continueable_blocks = []; + public $completable_blocks = []; + public $continuable_blocks = []; /** * Initialization function to setup key variables needed by the MarkdownGravLinkTrait @@ -57,16 +57,16 @@ trait ParsedownGravTrait * @param $type * @param $tag */ - public function addBlockType($type, $tag, $continueable = false, $completeable = false) + public function addBlockType($type, $tag, $continuable = false, $completable = false) { $this->BlockTypes[$type] []= $tag; - if ($continueable) { - $this->continueable_blocks[] = $tag; + if ($continuable) { + $this->continuable_blocks[] = $tag; } - if ($completeable) { - $this->completeable_blocks[] = $tag; + if ($completable) { + $this->completable_blocks[] = $tag; } } @@ -83,27 +83,27 @@ trait ParsedownGravTrait } /** - * Overrides the default behavior to allow for plugin-provided blocks to be continueable + * Overrides the default behavior to allow for plugin-provided blocks to be continuable * * @param $Type * @return bool */ - protected function isBlockContinueable($Type) + protected function isBlockContinuable($Type) { - $continueable = in_array($Type, $this->continueable_blocks) || method_exists($this, 'block'.$Type.'Continue'); - return $continueable; + $continuable = in_array($Type, $this->continuable_blocks) || method_exists($this, 'block'.$Type.'Continue'); + return $continuable; } /** - * Overrides the default behavior to allow for plugin-provided blocks to be completeable + * Overrides the default behavior to allow for plugin-provided blocks to be completable * * @param $Type * @return bool */ - protected function isBlockCompleteable($Type) + protected function isBlockCompletable($Type) { - $completeable = in_array($Type, $this->completeable_blocks) || method_exists($this, 'block'.$Type.'Complete'); - return $completeable; + $completable = in_array($Type, $this->completable_blocks) || method_exists($this, 'block'.$Type.'Complete'); + return $completable; } From bf05a36dfe84204129b887466b162331de09220d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 18 Dec 2015 23:08:14 -0700 Subject: [PATCH 06/33] Updated some libs --- composer.json | 4 +-- composer.lock | 57 +++++++++++++++++--------------- system/src/Grav/Common/Cache.php | 8 ++++- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index ba3c6e317..979a20506 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "http://getgrav.org", "license": "MIT", "require": { - "php": ">=5.4.0", + "php": ">=5.5.9", "twig/twig": "~1.23", "erusev/parsedown": "dev-master as 1.6.0", "erusev/parsedown-extra": "~0.7", @@ -16,7 +16,7 @@ "symfony/var-dumper": "~2.8", "symfony/polyfill-iconv": "~1.0", "doctrine/cache": "~1.5", - "filp/whoops": "1.1.10", + "filp/whoops": "2.0.0-alpha2", "monolog/monolog": "~1.0", "gregwar/image": "~2.0", "ircmaxell/password-compat": "1.0.*", diff --git a/composer.lock b/composer.lock index d0dca3cdd..0db4f5797 100644 --- a/composer.lock +++ b/composer.lock @@ -4,21 +4,21 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "82d333365d7424d73da22f99a2daa42c", - "content-hash": "6d876da7dbe11934a98374e67d15550c", + "hash": "94131c9b1e1bafa572e1022ca6093544", + "content-hash": "fd3f9839960586cb8d7c841eb3a51610", "packages": [ { "name": "doctrine/cache", - "version": "v1.5.2", + "version": "v1.5.4", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "47c7128262da274f590ae6f86eb137a7a64e82af" + "reference": "47cdc76ceb95cc591d9c79a36dc3794975b5d136" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/47c7128262da274f590ae6f86eb137a7a64e82af", - "reference": "47c7128262da274f590ae6f86eb137a7a64e82af", + "url": "https://api.github.com/repos/doctrine/cache/zipball/47cdc76ceb95cc591d9c79a36dc3794975b5d136", + "reference": "47cdc76ceb95cc591d9c79a36dc3794975b5d136", "shasum": "" }, "require": { @@ -75,7 +75,7 @@ "cache", "caching" ], - "time": "2015-12-03 10:50:37" + "time": "2015-12-19 05:03:47" }, { "name": "donatj/phpuseragentparser", @@ -134,12 +134,12 @@ "source": { "type": "git", "url": "https://github.com/getgrav/parsedown.git", - "reference": "10a7ff776c3f16b1b3aa41c176c48150fc091065" + "reference": "e7443a2bd868e78946ae6a01a1b07d477ce6f4cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getgrav/parsedown/zipball/10a7ff776c3f16b1b3aa41c176c48150fc091065", - "reference": "10a7ff776c3f16b1b3aa41c176c48150fc091065", + "url": "https://api.github.com/repos/getgrav/parsedown/zipball/e7443a2bd868e78946ae6a01a1b07d477ce6f4cc", + "reference": "e7443a2bd868e78946ae6a01a1b07d477ce6f4cc", "shasum": "" }, "type": "library", @@ -167,7 +167,7 @@ "support": { "source": "https://github.com/getgrav/parsedown/tree/master" }, - "time": "2015-12-17 17:48:21" + "time": "2015-12-19 03:45:14" }, { "name": "erusev/parsedown-extra", @@ -215,36 +215,41 @@ }, { "name": "filp/whoops", - "version": "1.1.10", + "version": "2.0.0-alpha2", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "72538eeb70bbfb11964412a3d098d109efd012f7" + "reference": "eb1ce6439db161a9f00cd57f33a9cfa1355229ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/72538eeb70bbfb11964412a3d098d109efd012f7", - "reference": "72538eeb70bbfb11964412a3d098d109efd012f7", + "url": "https://api.github.com/repos/filp/whoops/zipball/eb1ce6439db161a9f00cd57f33a9cfa1355229ec", + "reference": "eb1ce6439db161a9f00cd57f33a9cfa1355229ec", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=5.5.9" }, "require-dev": { - "mockery/mockery": "0.9.*" + "mockery/mockery": "0.9.*", + "phpunit/phpunit": "^4.8 || ^5.0" + }, + "suggest": { + "symfony/var-dumper": "Pretty print complex values better with var-dumper available", + "whoops/soap": "Formats errors as SOAP responses" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "2.0-dev" } }, "autoload": { - "psr-0": { - "Whoops": "src/" + "psr-4": { + "Whoops\\": "src/Whoops/" }, - "classmap": [ - "src/deprecated" + "files": [ + "src/Whoops/functions.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -265,11 +270,10 @@ "exception", "handling", "library", - "silex-provider", "whoops", "zf2" ], - "time": "2015-06-29 05:42:04" + "time": "2015-12-15 12:27:17" }, { "name": "gregwar/cache", @@ -1137,12 +1141,13 @@ ], "minimum-stability": "stable", "stability-flags": { - "erusev/parsedown": 20 + "erusev/parsedown": 20, + "filp/whoops": 15 }, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.4.0" + "php": ">=5.5.9" }, "platform-dev": [] } diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index da0825ed9..c8c186548 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -131,7 +131,9 @@ class Cache extends Getters $driver_name = 'file'; if (!$setting || $setting == 'auto') { - if (extension_loaded('apc')) { + if (extension_loaded('apcu')) { + $driver_name = 'apcu'; + } elseif (extension_loaded('apc')) { $driver_name = 'apc'; } elseif (extension_loaded('wincache')) { $driver_name = 'wincache'; @@ -145,6 +147,10 @@ class Cache extends Getters $this->driver_name = $driver_name; switch ($driver_name) { + case 'apcu': + $driver = new \Doctrine\Common\Cache\ApcuCache(); + break; + case 'apc': $driver = new \Doctrine\Common\Cache\ApcCache(); break; From c5d3098b25cdc91cc59aee47626905a2be6adaa4 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sat, 19 Dec 2015 10:28:06 +0100 Subject: [PATCH 07/33] Only call extra method on blueprints if blueprints exist Reverts partial change made in https://github.com/getgrav/grav/commit/ac3396e6c46f9bcd8d5cbb45370b5daad c84aadc --- system/src/Grav/Common/Data/Data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Data/Data.php b/system/src/Grav/Common/Data/Data.php index fe70efb1b..0a0850765 100644 --- a/system/src/Grav/Common/Data/Data.php +++ b/system/src/Grav/Common/Data/Data.php @@ -211,7 +211,7 @@ class Data implements DataInterface, \ArrayAccess, \Countable, ExportInterface */ public function extra() { - return $this->blueprints()->extra($this->items); + return $this->blueprints ? $this->blueprints->extra($this->items) : array(); } /** From 05c2b989293d309c37f074fc24294d6c57ddf653 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sat, 19 Dec 2015 10:48:52 +0100 Subject: [PATCH 08/33] Fix #523 locale in url with base_url_* variables, even if include_default_lang is set to false --- system/src/Grav/Common/Twig/Twig.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Twig/Twig.php b/system/src/Grav/Common/Twig/Twig.php index 0f5f4b97d..0b3be023c 100644 --- a/system/src/Grav/Common/Twig/Twig.php +++ b/system/src/Grav/Common/Twig/Twig.php @@ -80,7 +80,10 @@ class Twig $active_language = $language->getActive(); - $language_append = $active_language ? '/'.$active_language : ''; + $language_append = ''; + if ($language->getDefault() != $active_language || $config->get('system.languages.include_default_lang') === true) { + $language_append = $active_language ? '/' . $active_language : ''; + } // handle language templates if available if ($language->enabled()) { From 55bc84c11858998734d78356a00d0312863de24f Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sat, 19 Dec 2015 14:20:45 +0100 Subject: [PATCH 09/33] Fix #535 case insensitive https check --- system/src/Grav/Common/Uri.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 87ee096ab..efe9d1efc 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -46,7 +46,7 @@ class Uri // set the base if (isset($_SERVER['HTTPS'])) { - $base = (@$_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://'; + $base = (strtolower(@$_SERVER['HTTPS']) == 'on') ? 'https://' : 'http://'; } else { $base = 'http://'; } From 2f2adaaee8c3678a321960bb1190441ca7f3c846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 19 Dec 2015 18:17:07 +0100 Subject: [PATCH 10/33] Update fr.yaml --- system/languages/fr.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/languages/fr.yaml b/system/languages/fr.yaml index 4dcafc8a8..c84cd19d1 100644 --- a/system/languages/fr.yaml +++ b/system/languages/fr.yaml @@ -43,13 +43,13 @@ INFLECTOR_SINGULAR: '/([ti])a$/i': '\1um' '/(n)ews$/i': '\1ews' '/s$/i': '' -INFLECTOR_UNCOUNTABLE: ['équipment', 'information', 'riz', 'argent', 'espèces', 'séries', 'poisson', 'mouton'] +INFLECTOR_UNCOUNTABLE: ['équipement', 'information', 'riz', 'argent', 'espèces', 'séries', 'poisson', 'mouton'] INFLECTOR_IRREGULAR: 'person': 'personnes' - 'man': 'Hommes' + 'man': 'hommes' 'child': 'enfants' 'sex': 'sexes' - 'move': 'déplacemements' + 'move': 'déplacements' INFLECTOR_ORDINALS: 'default': 'ème' 'first': 'er' From b89044a709c543e3f762750a0e215f7cff1141d8 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 20 Dec 2015 11:51:48 +0100 Subject: [PATCH 11/33] Fix language string --- system/blueprints/user/account.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/blueprints/user/account.yaml b/system/blueprints/user/account.yaml index f9adc56be..669f5c7bb 100644 --- a/system/blueprints/user/account.yaml +++ b/system/blueprints/user/account.yaml @@ -55,7 +55,7 @@ form: help: PLUGIN_ADMIN.LANGUAGE_HELP security: - title: PLUGIN_ADMIN.SECURITY + title: PLUGIN_ADMIN.ACCESS_LEVELS type: section security: admin.super From 6c6871f607eee72614ec2bf1524011374989dbe7 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 20 Dec 2015 14:18:56 +0100 Subject: [PATCH 12/33] Proposed fix for #541 After reading http://stackoverflow.com/a/6998242 rawurldecode (and rawurlencode) is better over urldecode/urlencode: "rawurlencode is the way to go most of the time. It deals with the modern scheme for URI components, where as urlencode does things the old school way, where + meant "space." --- system/src/Grav/Common/Grav.php | 2 +- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 6 +++--- system/src/Grav/Common/Page/Medium/Medium.php | 2 +- system/src/Grav/Common/Uri.php | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index bb987f751..33b46acef 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -484,7 +484,7 @@ class Grav extends Container if ($page) { $media = $page->media()->all(); - $parsed_url = parse_url(urldecode($uri->basename())); + $parsed_url = parse_url(rawurldecode($uri->basename())); $media_file = $parsed_url['path']; diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 460cf7490..d24635322 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -194,7 +194,7 @@ trait ParsedownGravTrait // get the local path to page media if possible if ($path_parts['dirname'] == $this->page->url(false, false, false)) { - $url['path'] = urldecode($path_parts['basename']); + $url['path'] = rawurldecode($path_parts['basename']); // get the media objects for this page $media = $this->page->media(); } else { @@ -204,7 +204,7 @@ trait ParsedownGravTrait $ext_page = $this->pages->dispatch($page_route, true); if ($ext_page) { $media = $ext_page->media(); - $url['path'] = urldecode($path_parts['basename']); + $url['path'] = rawurldecode($path_parts['basename']); } } @@ -226,7 +226,7 @@ trait ParsedownGravTrait // loop through actions for the image and call them foreach ($actions as $action) { - $medium = call_user_func_array(array($medium, $action['method']), explode(',', urldecode($action['params']))); + $medium = call_user_func_array(array($medium, $action['method']), explode(',', rawurldecode($action['params']))); } if (isset($url['fragment'])) { diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index 714eeb5e8..b1ba569a2 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -449,7 +449,7 @@ class Medium extends Data implements RenderableInterface { $qs = $method; if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) { - $qs .= '=' . implode(',', array_map(function ($a) { return urlencode($a); }, $args)); + $qs .= '=' . implode(',', array_map(function ($a) { return rawurlencode($a); }, $args)); } if (!empty($qs)) { diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index efe9d1efc..bde30115a 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -170,7 +170,7 @@ class Uri if (strpos($bit, $delimiter) !== false) { $param = explode($delimiter, $bit); if (count($param) == 2) { - $plain_var = filter_var(urldecode($param[1]), FILTER_SANITIZE_STRING); + $plain_var = filter_var(rawurldecode($param[1]), FILTER_SANITIZE_STRING); $this->params[$param[0]] = $plain_var; } } else { @@ -206,7 +206,7 @@ class Uri */ public function route($absolute = false, $domain = false) { - return urldecode(($absolute ? $this->rootUrl($domain) : '') . '/' . implode('/', $this->paths)); + return rawurldecode(($absolute ? $this->rootUrl($domain) : '') . '/' . implode('/', $this->paths)); } /** @@ -268,7 +268,7 @@ class Uri public function param($id) { if (isset($this->params[$id])) { - return urldecode($this->params[$id]); + return rawurldecode($this->params[$id]); } else { return false; } @@ -545,8 +545,8 @@ class Uri if (file_exists($full_path)) { // do nothing - } elseif (file_exists(urldecode($full_path))) { - $full_path = urldecode($full_path); + } elseif (file_exists(rawurldecode($full_path))) { + $full_path = rawurldecode($full_path); } else { return $normalized_url; } From a8ad14222d1887f0e348e6b4bb8fd0ca2a7477ad Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 20 Dec 2015 11:50:45 -0700 Subject: [PATCH 13/33] moved sample web server configs into a dedicated directory --- .htaccess | 4 ++-- webserver-configs/Caddyfile | 12 ++++++++++++ htaccess.txt => webserver-configs/htaccess.txt | 4 ++-- lighttpd.conf => webserver-configs/lighttpd.conf | 0 nginx.conf => webserver-configs/nginx.conf | 0 web.config => webserver-configs/web.config | 0 6 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 webserver-configs/Caddyfile rename htaccess.txt => webserver-configs/htaccess.txt (93%) rename lighttpd.conf => webserver-configs/lighttpd.conf (100%) rename nginx.conf => webserver-configs/nginx.conf (100%) rename web.config => webserver-configs/web.config (100%) diff --git a/.htaccess b/.htaccess index 4017987a9..a5f6b9c96 100644 --- a/.htaccess +++ b/.htaccess @@ -44,7 +44,7 @@ RewriteRule .* index.php [L] ## Begin - Security # Block all direct access for these folders -RewriteRule ^(.git|cache|bin|logs|backup)/(.*) error [F] +RewriteRule ^(.git|cache|bin|logs|backup|webserver-configs)/(.*) error [F] # Block access to specific file types for these system folders RewriteRule ^(system|vendor)/(.*)\.(txt|xml|md|html|yaml|php|pl|py|cgi|twig|sh|bat)$ error [F] # Block access to specific file types for these user folders @@ -54,7 +54,7 @@ RewriteRule \.md$ error [F] # Block all direct access to files and folders beginning with a dot RewriteRule (^\.|/\.) - [F] # Block access to specific files in the root folder -RewriteRule ^(LICENSE.txt|composer.lock|composer.json|nginx.conf|web.config|htaccess.txt|\.htaccess)$ error [F] +RewriteRule ^(LICENSE.txt|composer.lock|composer.json|\.htaccess)$ error [F] ## End - Security diff --git a/webserver-configs/Caddyfile b/webserver-configs/Caddyfile new file mode 100644 index 000000000..3b11a6203 --- /dev/null +++ b/webserver-configs/Caddyfile @@ -0,0 +1,12 @@ +:8080 +gzip +fastcgi / 127.0.0.1:9000 { + ext .php + split .php + index index.php +} +rewrite { + regexp .* + ext / + to /index.php?_url={uri} +} diff --git a/htaccess.txt b/webserver-configs/htaccess.txt similarity index 93% rename from htaccess.txt rename to webserver-configs/htaccess.txt index 4017987a9..a5f6b9c96 100644 --- a/htaccess.txt +++ b/webserver-configs/htaccess.txt @@ -44,7 +44,7 @@ RewriteRule .* index.php [L] ## Begin - Security # Block all direct access for these folders -RewriteRule ^(.git|cache|bin|logs|backup)/(.*) error [F] +RewriteRule ^(.git|cache|bin|logs|backup|webserver-configs)/(.*) error [F] # Block access to specific file types for these system folders RewriteRule ^(system|vendor)/(.*)\.(txt|xml|md|html|yaml|php|pl|py|cgi|twig|sh|bat)$ error [F] # Block access to specific file types for these user folders @@ -54,7 +54,7 @@ RewriteRule \.md$ error [F] # Block all direct access to files and folders beginning with a dot RewriteRule (^\.|/\.) - [F] # Block access to specific files in the root folder -RewriteRule ^(LICENSE.txt|composer.lock|composer.json|nginx.conf|web.config|htaccess.txt|\.htaccess)$ error [F] +RewriteRule ^(LICENSE.txt|composer.lock|composer.json|\.htaccess)$ error [F] ## End - Security diff --git a/lighttpd.conf b/webserver-configs/lighttpd.conf similarity index 100% rename from lighttpd.conf rename to webserver-configs/lighttpd.conf diff --git a/nginx.conf b/webserver-configs/nginx.conf similarity index 100% rename from nginx.conf rename to webserver-configs/nginx.conf diff --git a/web.config b/webserver-configs/web.config similarity index 100% rename from web.config rename to webserver-configs/web.config From 06a5aa6d01fd282997bc73865c3d3edc1778674e Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 20 Dec 2015 11:58:53 -0700 Subject: [PATCH 14/33] Manually rolled back APCu support for PHP7 until it is available in the released version of Doctrine (currently only in master branch) --- system/src/Grav/Common/Cache.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index c8c186548..da0825ed9 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -131,9 +131,7 @@ class Cache extends Getters $driver_name = 'file'; if (!$setting || $setting == 'auto') { - if (extension_loaded('apcu')) { - $driver_name = 'apcu'; - } elseif (extension_loaded('apc')) { + if (extension_loaded('apc')) { $driver_name = 'apc'; } elseif (extension_loaded('wincache')) { $driver_name = 'wincache'; @@ -147,10 +145,6 @@ class Cache extends Getters $this->driver_name = $driver_name; switch ($driver_name) { - case 'apcu': - $driver = new \Doctrine\Common\Cache\ApcuCache(); - break; - case 'apc': $driver = new \Doctrine\Common\Cache\ApcCache(); break; From f0974e0d24ca7f7642e673a8e273ab1819654c14 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 20 Dec 2015 12:30:15 -0700 Subject: [PATCH 15/33] minor whoops styling --- system/assets/whoops.css | 103 +---------------------- system/src/Grav/Common/Errors/Errors.php | 1 - 2 files changed, 4 insertions(+), 100 deletions(-) diff --git a/system/assets/whoops.css b/system/assets/whoops.css index 6362d527c..8b325df04 100644 --- a/system/assets/whoops.css +++ b/system/assets/whoops.css @@ -1,110 +1,15 @@ -body { - background-color: #eee; -} - body header { - background: #349886; - border-left: 8px solid #29796B; -} - -body .clipboard { - width: 28px; - height: 28px; - background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcAQMAAABIw03XAAAAA3NCSVQICAjb4U/gAAAABlBMVEX///////9VfPVsAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAcdEVYdFNvZnR3YXJlAEFkb2JlIEZpcmV3b3JrcyBDUzbovLKMAAAAFnRFWHRDcmVhdGlvbiBUaW1lADEwLzE1LzE0xr/LJAAAADhJREFUCJlj+P///wcGBPGDQR5E8OMi2IEEczOIaAQRHSCioQBGHAAR/7AT/z+DiA8MMALVXhABAJf9Sr5aY+UFAAAAAElFTkSuQmCC); + background: #8552A2; } body .exc-title-primary { - color: #1C3631; - text-shadow: none; + color: #fff; } body .exc-title { - color: #2F5B52; - text-shadow: none; -} - -body .data-table-container label { - color: #0082BA; -} - -body .frame { - border: 0; -} - -body .frames-container { - overflow-y: auto; - overflow-x: hidden; -} - -body .active .frame-class { - color: #E3D8E9; -} - -body .frame-class { - color: #9055AF; -} - -body .frame.active { - border: 0; - box-shadow: none; - background-color: #9055AF; + color: #ddd; } body .frame:not(.active):hover { - background: #e9e9e9; -} - -body .frame-file, body .data-table tbody { - font-family: "DejaVu Sans Mono", Menlo, Monaco, Consolas, Courier, monospace; - font-size: 13px; -} - -body .frame-code { - background: #305669; - border-left: 8px solid #253A47; - padding: 1rem; -} - -body .frame-code .frame-file { - background: #253A47; - color: #eee; - text-shadow: none; - box-shadow: none; - font-family: inherit; -} - -body .frame-code .frame-file strong { - color: #fff; - font-weight: normal; -} - -body .frame-comments { - background: #283E4D; - - box-shadow: none; -} - -body .frame-comments.empty:before { - color: #789AAB; -} - -body .details-container { - border: 0; -} - -body .details { - background-color: #eee; - border-left: 8px solid #ddd; - padding: 1rem; -} - -body .code-block { - background: #2C4454; - box-shadow: none; - font-family: "DejaVu Sans Mono", Menlo, Monaco, Consolas, Courier, monospace; - font-size: 13px; -} - -body .handler.active { - background: #666; + background: #e6e6e6; } diff --git a/system/src/Grav/Common/Errors/Errors.php b/system/src/Grav/Common/Errors/Errors.php index b201bfb94..b8575fb06 100644 --- a/system/src/Grav/Common/Errors/Errors.php +++ b/system/src/Grav/Common/Errors/Errors.php @@ -22,7 +22,6 @@ class Errors if ($config['display']) { $error_page = new Whoops\Handler\PrettyPageHandler; $error_page->setPageTitle('Crikey! There was an error...'); - $error_page->setEditor('sublime'); $error_page->addResourcePath(GRAV_ROOT . '/system/assets'); $error_page->addCustomCss('whoops.css'); $whoops->pushHandler($error_page); From 5ab4d916b09c3fc0b2c51247fc6257ce1c1cbbb3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 20 Dec 2015 12:32:23 -0700 Subject: [PATCH 16/33] tweaked whoops sidebar --- system/assets/whoops.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/assets/whoops.css b/system/assets/whoops.css index 8b325df04..c50aae385 100644 --- a/system/assets/whoops.css +++ b/system/assets/whoops.css @@ -2,6 +2,10 @@ body header { background: #8552A2; } +body .left-panel { + background: inherit; +} + body .exc-title-primary { color: #fff; } From 484a34cd92e2cbfb0122b9ed15227aaf14eaf7b0 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 13:55:29 +0100 Subject: [PATCH 17/33] Fix orientation for images added via twig --- system/src/Grav/Common/Page/Medium/ImageMedium.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 3db039643..6da85af45 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -41,7 +41,8 @@ class ImageMedium extends Medium public static $magic_actions = [ 'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop', 'negate', 'brightness', 'contrast', 'grayscale', 'emboss', - 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive' + 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', + 'fixOrientation' ]; /** @@ -260,6 +261,7 @@ class ImageMedium extends Medium if ($this->image) { $this->image(); $this->image->clearOperations(); // Clear previously applied operations + $this->fixOrientation(); $this->filter(); } @@ -469,6 +471,7 @@ class ImageMedium extends Medium ->setPrettyName(basename($this->get('basename'))); $this->filter(); + $this->fixOrientation(); return $this; } From 328e9b20de37fbd4c61a0593653b436156445681 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 16:16:26 +0100 Subject: [PATCH 18/33] Also add config save to themes --- system/src/Grav/Common/Theme.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/system/src/Grav/Common/Theme.php b/system/src/Grav/Common/Theme.php index 12195127e..2f4ed468c 100644 --- a/system/src/Grav/Common/Theme.php +++ b/system/src/Grav/Common/Theme.php @@ -20,4 +20,26 @@ class Theme extends Plugin parent::__construct($name, $grav, $config); } + + /** + * Persists to disk the theme parameters currently stored in the Grav Config object + * + * @param string $theme_name The name of the theme whose config it should store. + * + * @return true + */ + public static function saveConfig($theme_name) { + if (!$theme_name) { + return false; + } + + $locator = Grav::instance()['locator']; + $filename = 'config://themes/' . $theme_name . '.yaml'; + $file = YamlFile::instance($locator->findResource($filename, true, true)); + $content = Grav::instance()['config']->get('themes.' . $theme_name); + $file->save($content); + $file->free(); + + return true; + } } From bf361db5fca1671a0bf694bab106c0867e8e49cc Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 16:26:05 +0100 Subject: [PATCH 19/33] File field validation, handle case multiple not specified --- system/src/Grav/Common/Data/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index 9f0266bd4..9387effba 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -283,7 +283,7 @@ class Validation protected static function filterFile($value, array $params, array $field) { - if ($field['multiple'] == true) { + if (isset($field['multiple']) && $field['multiple'] == true) { return (array) $value; } From 729f83b3d409c703b1c28efabfc3927be3878de8 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 18:02:25 +0100 Subject: [PATCH 20/33] Fix regression in image parameters handling introduced in https://github.com/getgrav/grav/commit/23a9a736002cdcac08f22810f2e74ce2a9772a4d Parameters without a value (e.g. `sepia`, `grayscale`, `emboss` and others) were not applied any more) --- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 460cf7490..bca1a4e34 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -272,7 +272,7 @@ trait ParsedownGravTrait if (isset($url['query'])) { $actions = array_reduce(explode('&', $url['query']), function ($carry, $item) { $parts = explode('=', $item, 2); - $value = isset($parts[1]) ? $parts[1] : null; + $value = isset($parts[1]) ? $parts[1] : true; $carry[$parts[0]] = $value; return $carry; From 4581077dcd08b613476b58f13316de8d7c54d555 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 19:10:19 +0100 Subject: [PATCH 21/33] Fix for images orientation in page content --- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 5 +++++ system/src/Grav/Common/Page/Medium/ImageMedium.php | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 460cf7490..21143636a 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -278,6 +278,8 @@ trait ParsedownGravTrait return $carry; }, []); + $actions['fixOrientation'] = true; + // valid attributes supported $valid_attributes = ['rel', 'target', 'id', 'class', 'classes']; @@ -301,6 +303,9 @@ trait ParsedownGravTrait } + $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); + } else { + $actions['fixOrientation'] = true; $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); } diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 6da85af45..cc9e77717 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -41,8 +41,7 @@ class ImageMedium extends Medium public static $magic_actions = [ 'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop', 'negate', 'brightness', 'contrast', 'grayscale', 'emboss', - 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', - 'fixOrientation' + 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', 'fixOrientation' ]; /** @@ -261,7 +260,6 @@ class ImageMedium extends Medium if ($this->image) { $this->image(); $this->image->clearOperations(); // Clear previously applied operations - $this->fixOrientation(); $this->filter(); } @@ -471,7 +469,6 @@ class ImageMedium extends Medium ->setPrettyName(basename($this->get('basename'))); $this->filter(); - $this->fixOrientation(); return $this; } From b2c7e22634fcff63bbd9e2225b19de20d73ed01a Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 19:18:51 +0100 Subject: [PATCH 22/33] Cleanup --- .../Grav/Common/Markdown/ParsedownGravTrait.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 21143636a..a51f20b52 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -267,7 +267,8 @@ trait ParsedownGravTrait // if this is a link if (isset($excerpt['element']['attributes']['href'])) { $url = parse_url(htmlspecialchars_decode($excerpt['element']['attributes']['href'])); - + $actions = []; + // if there is a query, then parse it and build action calls if (isset($url['query'])) { $actions = array_reduce(explode('&', $url['query']), function ($carry, $item) { @@ -278,8 +279,6 @@ trait ParsedownGravTrait return $carry; }, []); - $actions['fixOrientation'] = true; - // valid attributes supported $valid_attributes = ['rel', 'target', 'id', 'class', 'classes']; @@ -301,14 +300,11 @@ trait ParsedownGravTrait } } } - - - $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); - } else { - $actions['fixOrientation'] = true; - $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); } + $actions['fixOrientation'] = true; + $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); + // if no query elements left, unset query if (empty($url['query'])) { unset ($url['query']); From 7440074491250215284122185ab617b9826e8389 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 21 Dec 2015 21:46:36 -0700 Subject: [PATCH 23/33] Revert "Proposed fix for #541" This reverts commit 6c6871f607eee72614ec2bf1524011374989dbe7. --- system/src/Grav/Common/Grav.php | 2 +- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 6 +++--- system/src/Grav/Common/Page/Medium/Medium.php | 2 +- system/src/Grav/Common/Uri.php | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 33b46acef..bb987f751 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -484,7 +484,7 @@ class Grav extends Container if ($page) { $media = $page->media()->all(); - $parsed_url = parse_url(rawurldecode($uri->basename())); + $parsed_url = parse_url(urldecode($uri->basename())); $media_file = $parsed_url['path']; diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index cb6194034..9b13c955c 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -194,7 +194,7 @@ trait ParsedownGravTrait // get the local path to page media if possible if ($path_parts['dirname'] == $this->page->url(false, false, false)) { - $url['path'] = rawurldecode($path_parts['basename']); + $url['path'] = urldecode($path_parts['basename']); // get the media objects for this page $media = $this->page->media(); } else { @@ -204,7 +204,7 @@ trait ParsedownGravTrait $ext_page = $this->pages->dispatch($page_route, true); if ($ext_page) { $media = $ext_page->media(); - $url['path'] = rawurldecode($path_parts['basename']); + $url['path'] = urldecode($path_parts['basename']); } } @@ -226,7 +226,7 @@ trait ParsedownGravTrait // loop through actions for the image and call them foreach ($actions as $action) { - $medium = call_user_func_array(array($medium, $action['method']), explode(',', rawurldecode($action['params']))); + $medium = call_user_func_array(array($medium, $action['method']), explode(',', urldecode($action['params']))); } if (isset($url['fragment'])) { diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index b1ba569a2..714eeb5e8 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -449,7 +449,7 @@ class Medium extends Data implements RenderableInterface { $qs = $method; if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) { - $qs .= '=' . implode(',', array_map(function ($a) { return rawurlencode($a); }, $args)); + $qs .= '=' . implode(',', array_map(function ($a) { return urlencode($a); }, $args)); } if (!empty($qs)) { diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index bde30115a..efe9d1efc 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -170,7 +170,7 @@ class Uri if (strpos($bit, $delimiter) !== false) { $param = explode($delimiter, $bit); if (count($param) == 2) { - $plain_var = filter_var(rawurldecode($param[1]), FILTER_SANITIZE_STRING); + $plain_var = filter_var(urldecode($param[1]), FILTER_SANITIZE_STRING); $this->params[$param[0]] = $plain_var; } } else { @@ -206,7 +206,7 @@ class Uri */ public function route($absolute = false, $domain = false) { - return rawurldecode(($absolute ? $this->rootUrl($domain) : '') . '/' . implode('/', $this->paths)); + return urldecode(($absolute ? $this->rootUrl($domain) : '') . '/' . implode('/', $this->paths)); } /** @@ -268,7 +268,7 @@ class Uri public function param($id) { if (isset($this->params[$id])) { - return rawurldecode($this->params[$id]); + return urldecode($this->params[$id]); } else { return false; } @@ -545,8 +545,8 @@ class Uri if (file_exists($full_path)) { // do nothing - } elseif (file_exists(rawurldecode($full_path))) { - $full_path = rawurldecode($full_path); + } elseif (file_exists(urldecode($full_path))) { + $full_path = urldecode($full_path); } else { return $normalized_url; } From ef75582e20808faf0271f1b3b6f45cb2ca8c17b4 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 20 Dec 2015 14:18:56 +0100 Subject: [PATCH 24/33] Proposed fix for #541 After reading http://stackoverflow.com/a/6998242 rawurldecode (and rawurlencode) is better over urldecode/urlencode: "rawurlencode is the way to go most of the time. It deals with the modern scheme for URI components, where as urlencode does things the old school way, where + meant "space." --- system/src/Grav/Common/Grav.php | 2 +- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 6 +++--- system/src/Grav/Common/Page/Medium/Medium.php | 2 +- system/src/Grav/Common/Uri.php | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index bb987f751..33b46acef 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -484,7 +484,7 @@ class Grav extends Container if ($page) { $media = $page->media()->all(); - $parsed_url = parse_url(urldecode($uri->basename())); + $parsed_url = parse_url(rawurldecode($uri->basename())); $media_file = $parsed_url['path']; diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index bca1a4e34..5ae25165a 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -194,7 +194,7 @@ trait ParsedownGravTrait // get the local path to page media if possible if ($path_parts['dirname'] == $this->page->url(false, false, false)) { - $url['path'] = urldecode($path_parts['basename']); + $url['path'] = rawurldecode($path_parts['basename']); // get the media objects for this page $media = $this->page->media(); } else { @@ -204,7 +204,7 @@ trait ParsedownGravTrait $ext_page = $this->pages->dispatch($page_route, true); if ($ext_page) { $media = $ext_page->media(); - $url['path'] = urldecode($path_parts['basename']); + $url['path'] = rawurldecode($path_parts['basename']); } } @@ -226,7 +226,7 @@ trait ParsedownGravTrait // loop through actions for the image and call them foreach ($actions as $action) { - $medium = call_user_func_array(array($medium, $action['method']), explode(',', urldecode($action['params']))); + $medium = call_user_func_array(array($medium, $action['method']), explode(',', rawurldecode($action['params']))); } if (isset($url['fragment'])) { diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index 714eeb5e8..b1ba569a2 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -449,7 +449,7 @@ class Medium extends Data implements RenderableInterface { $qs = $method; if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) { - $qs .= '=' . implode(',', array_map(function ($a) { return urlencode($a); }, $args)); + $qs .= '=' . implode(',', array_map(function ($a) { return rawurlencode($a); }, $args)); } if (!empty($qs)) { diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index efe9d1efc..bde30115a 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -170,7 +170,7 @@ class Uri if (strpos($bit, $delimiter) !== false) { $param = explode($delimiter, $bit); if (count($param) == 2) { - $plain_var = filter_var(urldecode($param[1]), FILTER_SANITIZE_STRING); + $plain_var = filter_var(rawurldecode($param[1]), FILTER_SANITIZE_STRING); $this->params[$param[0]] = $plain_var; } } else { @@ -206,7 +206,7 @@ class Uri */ public function route($absolute = false, $domain = false) { - return urldecode(($absolute ? $this->rootUrl($domain) : '') . '/' . implode('/', $this->paths)); + return rawurldecode(($absolute ? $this->rootUrl($domain) : '') . '/' . implode('/', $this->paths)); } /** @@ -268,7 +268,7 @@ class Uri public function param($id) { if (isset($this->params[$id])) { - return urldecode($this->params[$id]); + return rawurldecode($this->params[$id]); } else { return false; } @@ -545,8 +545,8 @@ class Uri if (file_exists($full_path)) { // do nothing - } elseif (file_exists(urldecode($full_path))) { - $full_path = urldecode($full_path); + } elseif (file_exists(rawurldecode($full_path))) { + $full_path = rawurldecode($full_path); } else { return $normalized_url; } From 593fd20a15332b86af13a0d740813b7324b896e9 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 13:55:29 +0100 Subject: [PATCH 25/33] Fix orientation for images added via twig --- system/src/Grav/Common/Page/Medium/ImageMedium.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 3db039643..6da85af45 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -41,7 +41,8 @@ class ImageMedium extends Medium public static $magic_actions = [ 'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop', 'negate', 'brightness', 'contrast', 'grayscale', 'emboss', - 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive' + 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', + 'fixOrientation' ]; /** @@ -260,6 +261,7 @@ class ImageMedium extends Medium if ($this->image) { $this->image(); $this->image->clearOperations(); // Clear previously applied operations + $this->fixOrientation(); $this->filter(); } @@ -469,6 +471,7 @@ class ImageMedium extends Medium ->setPrettyName(basename($this->get('basename'))); $this->filter(); + $this->fixOrientation(); return $this; } From 9a8efdf9cdd9b6493a0904bfbf11c8f587ee8294 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 19:10:19 +0100 Subject: [PATCH 26/33] Fix for images orientation in page content --- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 5 +++++ system/src/Grav/Common/Page/Medium/ImageMedium.php | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 5ae25165a..3614f770c 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -278,6 +278,8 @@ trait ParsedownGravTrait return $carry; }, []); + $actions['fixOrientation'] = true; + // valid attributes supported $valid_attributes = ['rel', 'target', 'id', 'class', 'classes']; @@ -301,6 +303,9 @@ trait ParsedownGravTrait } + $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); + } else { + $actions['fixOrientation'] = true; $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); } diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 6da85af45..cc9e77717 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -41,8 +41,7 @@ class ImageMedium extends Medium public static $magic_actions = [ 'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop', 'negate', 'brightness', 'contrast', 'grayscale', 'emboss', - 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', - 'fixOrientation' + 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', 'fixOrientation' ]; /** @@ -261,7 +260,6 @@ class ImageMedium extends Medium if ($this->image) { $this->image(); $this->image->clearOperations(); // Clear previously applied operations - $this->fixOrientation(); $this->filter(); } @@ -471,7 +469,6 @@ class ImageMedium extends Medium ->setPrettyName(basename($this->get('basename'))); $this->filter(); - $this->fixOrientation(); return $this; } From d47faed8702d2045f93d850e640e342291f8e441 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Dec 2015 19:18:51 +0100 Subject: [PATCH 27/33] Cleanup --- .../Grav/Common/Markdown/ParsedownGravTrait.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 3614f770c..cb6194034 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -267,7 +267,8 @@ trait ParsedownGravTrait // if this is a link if (isset($excerpt['element']['attributes']['href'])) { $url = parse_url(htmlspecialchars_decode($excerpt['element']['attributes']['href'])); - + $actions = []; + // if there is a query, then parse it and build action calls if (isset($url['query'])) { $actions = array_reduce(explode('&', $url['query']), function ($carry, $item) { @@ -278,8 +279,6 @@ trait ParsedownGravTrait return $carry; }, []); - $actions['fixOrientation'] = true; - // valid attributes supported $valid_attributes = ['rel', 'target', 'id', 'class', 'classes']; @@ -301,14 +300,11 @@ trait ParsedownGravTrait } } } - - - $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); - } else { - $actions['fixOrientation'] = true; - $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); } + $actions['fixOrientation'] = true; + $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); + // if no query elements left, unset query if (empty($url['query'])) { unset ($url['query']); From 25b33d020489d7ef48fbb117fe2da66b1887d48d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 21 Dec 2015 21:46:36 -0700 Subject: [PATCH 28/33] Revert "Proposed fix for #541" This reverts commit 6c6871f607eee72614ec2bf1524011374989dbe7. --- system/src/Grav/Common/Grav.php | 2 +- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 6 +++--- system/src/Grav/Common/Page/Medium/Medium.php | 2 +- system/src/Grav/Common/Uri.php | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 33b46acef..bb987f751 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -484,7 +484,7 @@ class Grav extends Container if ($page) { $media = $page->media()->all(); - $parsed_url = parse_url(rawurldecode($uri->basename())); + $parsed_url = parse_url(urldecode($uri->basename())); $media_file = $parsed_url['path']; diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index cb6194034..9b13c955c 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -194,7 +194,7 @@ trait ParsedownGravTrait // get the local path to page media if possible if ($path_parts['dirname'] == $this->page->url(false, false, false)) { - $url['path'] = rawurldecode($path_parts['basename']); + $url['path'] = urldecode($path_parts['basename']); // get the media objects for this page $media = $this->page->media(); } else { @@ -204,7 +204,7 @@ trait ParsedownGravTrait $ext_page = $this->pages->dispatch($page_route, true); if ($ext_page) { $media = $ext_page->media(); - $url['path'] = rawurldecode($path_parts['basename']); + $url['path'] = urldecode($path_parts['basename']); } } @@ -226,7 +226,7 @@ trait ParsedownGravTrait // loop through actions for the image and call them foreach ($actions as $action) { - $medium = call_user_func_array(array($medium, $action['method']), explode(',', rawurldecode($action['params']))); + $medium = call_user_func_array(array($medium, $action['method']), explode(',', urldecode($action['params']))); } if (isset($url['fragment'])) { diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index b1ba569a2..714eeb5e8 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -449,7 +449,7 @@ class Medium extends Data implements RenderableInterface { $qs = $method; if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) { - $qs .= '=' . implode(',', array_map(function ($a) { return rawurlencode($a); }, $args)); + $qs .= '=' . implode(',', array_map(function ($a) { return urlencode($a); }, $args)); } if (!empty($qs)) { diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index bde30115a..efe9d1efc 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -170,7 +170,7 @@ class Uri if (strpos($bit, $delimiter) !== false) { $param = explode($delimiter, $bit); if (count($param) == 2) { - $plain_var = filter_var(rawurldecode($param[1]), FILTER_SANITIZE_STRING); + $plain_var = filter_var(urldecode($param[1]), FILTER_SANITIZE_STRING); $this->params[$param[0]] = $plain_var; } } else { @@ -206,7 +206,7 @@ class Uri */ public function route($absolute = false, $domain = false) { - return rawurldecode(($absolute ? $this->rootUrl($domain) : '') . '/' . implode('/', $this->paths)); + return urldecode(($absolute ? $this->rootUrl($domain) : '') . '/' . implode('/', $this->paths)); } /** @@ -268,7 +268,7 @@ class Uri public function param($id) { if (isset($this->params[$id])) { - return rawurldecode($this->params[$id]); + return urldecode($this->params[$id]); } else { return false; } @@ -545,8 +545,8 @@ class Uri if (file_exists($full_path)) { // do nothing - } elseif (file_exists(rawurldecode($full_path))) { - $full_path = rawurldecode($full_path); + } elseif (file_exists(urldecode($full_path))) { + $full_path = urldecode($full_path); } else { return $normalized_url; } From c9b8fc0e1bfc4edf3b9c2e9b4bf57dac8573d842 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 21 Dec 2015 22:01:18 -0700 Subject: [PATCH 29/33] Revert "Cleanup" This reverts commit b2c7e22634fcff63bbd9e2225b19de20d73ed01a. --- .../Grav/Common/Markdown/ParsedownGravTrait.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 9b13c955c..22d1eb67c 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -267,8 +267,7 @@ trait ParsedownGravTrait // if this is a link if (isset($excerpt['element']['attributes']['href'])) { $url = parse_url(htmlspecialchars_decode($excerpt['element']['attributes']['href'])); - $actions = []; - + // if there is a query, then parse it and build action calls if (isset($url['query'])) { $actions = array_reduce(explode('&', $url['query']), function ($carry, $item) { @@ -279,6 +278,8 @@ trait ParsedownGravTrait return $carry; }, []); + $actions['fixOrientation'] = true; + // valid attributes supported $valid_attributes = ['rel', 'target', 'id', 'class', 'classes']; @@ -300,10 +301,13 @@ trait ParsedownGravTrait } } } - } - $actions['fixOrientation'] = true; - $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); + + $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); + } else { + $actions['fixOrientation'] = true; + $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); + } // if no query elements left, unset query if (empty($url['query'])) { From 2d3b41c62decd7a8447b8c3bb007c0a963566942 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 21 Dec 2015 22:01:32 -0700 Subject: [PATCH 30/33] Revert "Fix for images orientation in page content" This reverts commit 4581077dcd08b613476b58f13316de8d7c54d555. --- system/src/Grav/Common/Markdown/ParsedownGravTrait.php | 5 ----- system/src/Grav/Common/Page/Medium/ImageMedium.php | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 22d1eb67c..bca1a4e34 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -278,8 +278,6 @@ trait ParsedownGravTrait return $carry; }, []); - $actions['fixOrientation'] = true; - // valid attributes supported $valid_attributes = ['rel', 'target', 'id', 'class', 'classes']; @@ -303,9 +301,6 @@ trait ParsedownGravTrait } - $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); - } else { - $actions['fixOrientation'] = true; $url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986); } diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index cc9e77717..6da85af45 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -41,7 +41,8 @@ class ImageMedium extends Medium public static $magic_actions = [ 'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop', 'negate', 'brightness', 'contrast', 'grayscale', 'emboss', - 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', 'fixOrientation' + 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', + 'fixOrientation' ]; /** @@ -260,6 +261,7 @@ class ImageMedium extends Medium if ($this->image) { $this->image(); $this->image->clearOperations(); // Clear previously applied operations + $this->fixOrientation(); $this->filter(); } @@ -469,6 +471,7 @@ class ImageMedium extends Medium ->setPrettyName(basename($this->get('basename'))); $this->filter(); + $this->fixOrientation(); return $this; } From 37dd107281ae447c451b28fa303a4a32566ae8d4 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 21 Dec 2015 22:01:38 -0700 Subject: [PATCH 31/33] Revert "Fix orientation for images added via twig" This reverts commit 484a34cd92e2cbfb0122b9ed15227aaf14eaf7b0. --- system/src/Grav/Common/Page/Medium/ImageMedium.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 6da85af45..3db039643 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -41,8 +41,7 @@ class ImageMedium extends Medium public static $magic_actions = [ 'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop', 'negate', 'brightness', 'contrast', 'grayscale', 'emboss', - 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive', - 'fixOrientation' + 'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive' ]; /** @@ -261,7 +260,6 @@ class ImageMedium extends Medium if ($this->image) { $this->image(); $this->image->clearOperations(); // Clear previously applied operations - $this->fixOrientation(); $this->filter(); } @@ -471,7 +469,6 @@ class ImageMedium extends Medium ->setPrettyName(basename($this->get('basename'))); $this->filter(); - $this->fixOrientation(); return $this; } From 8e1b2bc6e47bf7c845fb3dc59b9661f318b30ae3 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 22 Dec 2015 11:54:20 +0200 Subject: [PATCH 32/33] FastCGI: Use Apache's mod_deflate if Grav's builtin gzip compression was turned off (#548) --- system/src/Grav/Common/Grav.php | 74 ++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index bb987f751..74e973f1d 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -417,41 +417,49 @@ class Grav extends Container */ public function shutdown() { - if ($this['config']->get('system.debugger.shutdown.close_connection')) { - // Prevent user abort. - if (function_exists('ignore_user_abort')) { - @ignore_user_abort(true); - } - - // Close the session. - if (isset($this['session'])) { - $this['session']->close(); - } - - if ($this['config']->get('system.cache.gzip')) { - // Flush gzhandler buffer if gzip was enabled. - ob_end_flush(); - } else { - // Otherwise prevent server from compressing the output. - header('Content-Encoding: none'); - } - - // Get length and close the connection. - header('Content-Length: ' . ob_get_length()); - header("Connection: close"); - - // flush the regular buffer - ob_end_flush(); - @ob_flush(); - flush(); - - // Fix for fastcgi close connection issue. - if (function_exists('fastcgi_finish_request')) { - @fastcgi_finish_request(); - } - + // Prevent user abort allowing onShutdown event to run without interruptions. + if (function_exists('ignore_user_abort')) { + @ignore_user_abort(true); } + // Close the session allowing new requests to be handled. + if (isset($this['session'])) { + $this['session']->close(); + } + + if ($this['config']->get('system.debugger.shutdown.close_connection', true)) { + // Flush the response and close the connection to allow time consuming tasks to be performed without leaving + // the connection to the client open. This will make page loads to feel much faster. + + // FastCGI allows us to flush all response data to the client and finish the request. + $success = function_exists('fastcgi_finish_request') ? @fastcgi_finish_request() : false; + + if (!$success) { + // Unfortunately without FastCGI there is no way to close the connection. We need to ask browser to + // close the connection for us. + + if ($this['config']->get('system.cache.gzip')) { + // Flush gzhandler buffer if gzip setting was enabled. + ob_end_flush(); + + } else { + // Without gzip we have no other choice than to prevent server from compressing the output. + // This action turns off mod_deflate which would prevent us from closing the connection. + header('Content-Encoding: none'); + } + + // Get length and close the connection. + header('Content-Length: ' . ob_get_length()); + header("Connection: close"); + + // Finally flush the regular buffer. + ob_end_flush(); + @ob_flush(); + flush(); + } + } + + // Run any time consuming tasks. $this->fireEvent('onShutdown'); } From 879b5ef272ace6e16fc88c3f3efca24a2ca026c8 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 22 Dec 2015 17:15:34 -0700 Subject: [PATCH 33/33] version update --- CHANGELOG.md | 17 +++++++++++++++++ system/defines.php | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a45de808d..56d165cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +# v1.0.6 +## 12/22/2015 + +1. [](#new) + * Set minimum requirements to [PHP 5.5.9](http://bit.ly/1Jt9OXO) + * Added `saveConfig` to Themes +1. [](#improved) + * Updated Whoops to new 2.0 version (PHP 7.0 compatbile) + * Moved sample web server configs into dedicated directory + * FastCGI will use Apache's `mod_deflate` if gzip turned off +1. [](#bugfix) + * Fix broken media image operators + * Only call extra method of blueprints if blueprints exist + * Fix lang prefix in url twig variables #523 + * Fix case insensitive HTTPS check #535 + * Field field validation handles case `multiple` missing + # v1.0.5 ## 12/18/2015 diff --git a/system/defines.php b/system/defines.php index 1153fcbe5..929d5d2e4 100644 --- a/system/defines.php +++ b/system/defines.php @@ -2,7 +2,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '1.0.5'); +define('GRAV_VERSION', '1.0.6'); define('DS', '/'); define('GRAV_PHP_MIN', '5.5.9');