From 21bef62b82f63b71cd2c14a8b19704c631870f77 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 30 Nov 2017 18:28:25 -0700 Subject: [PATCH 1/3] Added get and set FlashCookieObject() methods --- CHANGELOG.md | 1 + system/src/Grav/Common/Session.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6b8f2fe4e..78f1197833 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Added `Medium::copy()` method to create a copy of a medium object * Added new `force_lowercase_urls` functionality on routes and slugs * Added new `item-list` filter type to remove empty items + * Added new `setFlashCookieObject()` and `getFlashCookieObject()` methods to `Session` object 1. [](#bugfix) * Fixed issue with multibyte Markdown link URLs [#1749](https://github.com/getgrav/grav/issues/1749) * Fixed issue with multibyte folder names [#1751](https://github.com/getgrav/grav/issues/1751) diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php index 7186768436..cbf2477b7d 100644 --- a/system/src/Grav/Common/Session.php +++ b/system/src/Grav/Common/Session.php @@ -105,4 +105,20 @@ public function getFlashObject($name) return $object; } + + // Store something in cookie temporarily + public function setFlashCookieObject($name, $object, $time = 60) + { + setcookie($name, json_encode($object), time() + $time, '/'); + } + + // Return object and remove it from the cookie + public function getFlashCookieObject($name) + { + if (isset($_COOKIE[$name])) { + $object = json_decode($_COOKIE[$name]); + setcookie($name, '', time() - 3600, '/'); + return $object; + } + } } From eac16911d0dea621d0080d9855a247bb8bf91699 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 30 Nov 2017 18:31:13 -0700 Subject: [PATCH 2/3] Added new core twig templates --- CHANGELOG.md | 1 + system/src/Grav/Common/Twig/Twig.php | 3 +++ system/templates/partials/messages.html.twig | 14 ++++++++++++++ system/templates/partials/metadata.html.twig | 3 +++ 4 files changed, 21 insertions(+) create mode 100644 system/templates/partials/messages.html.twig create mode 100644 system/templates/partials/metadata.html.twig diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f1197833..271ae1356a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## xx/xx/2017 1. [](#new) + * Added new core Twig templates for `partials/metadata.html.twig` and `partials/messages.html.twig` * Added ability to work with GPM locally [#1742](https://github.com/getgrav/grav/issues/1742) * Added new HTML5 audio controls [#1756](https://github.com/getgrav/grav/issues/1756) * Added `Medium::copy()` method to create a copy of a medium object diff --git a/system/src/Grav/Common/Twig/Twig.php b/system/src/Grav/Common/Twig/Twig.php index 7f2ec0990f..74d3e0a8e5 100644 --- a/system/src/Grav/Common/Twig/Twig.php +++ b/system/src/Grav/Common/Twig/Twig.php @@ -85,6 +85,9 @@ public function init() $active_language = $language->getActive(); + // Add Grav core templates location + $this->twig_paths[] = $locator->findResource('system://templates'); + // handle language templates if available if ($language->enabled()) { $lang_templates = $locator->findResource('theme://templates/' . ($active_language ? $active_language : $language->getDefault())); diff --git a/system/templates/partials/messages.html.twig b/system/templates/partials/messages.html.twig new file mode 100644 index 0000000000..2b80b1feef --- /dev/null +++ b/system/templates/partials/messages.html.twig @@ -0,0 +1,14 @@ +{% set type_mapping = {'info':'green', 'error': 'red', 'warning': 'yellow'} %} + +{% if grav.messages.all %} +
+ {% for message in grav.messages.fetch %} + + {% set scope = message.scope|e %} + {% set type = type_mapping[scope] %} + +

{{ message.message|raw }}

+ + {% endfor %} +
+{% endif %} diff --git a/system/templates/partials/metadata.html.twig b/system/templates/partials/metadata.html.twig new file mode 100644 index 0000000000..bf323e7ab2 --- /dev/null +++ b/system/templates/partials/metadata.html.twig @@ -0,0 +1,3 @@ +{% for meta in page.metadata %} + +{% endfor %} \ No newline at end of file From b4cf7899bb51de69b96a7f8f96be99336acf43fd Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 1 Dec 2017 00:01:23 -0700 Subject: [PATCH 3/3] cleanup --- system/templates/partials/messages.html.twig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/templates/partials/messages.html.twig b/system/templates/partials/messages.html.twig index 2b80b1feef..261b3fc8fb 100644 --- a/system/templates/partials/messages.html.twig +++ b/system/templates/partials/messages.html.twig @@ -1,13 +1,13 @@ -{% set type_mapping = {'info':'green', 'error': 'red', 'warning': 'yellow'} %} +{% set status_mapping = {'info':'green', 'error': 'red', 'warning': 'yellow'} %} {% if grav.messages.all %}
{% for message in grav.messages.fetch %} {% set scope = message.scope|e %} - {% set type = type_mapping[scope] %} + {% set color = status_mapping[scope] %} -

{{ message.message|raw }}

+

{{ message.message|raw }}

{% endfor %}