From 8b14192a7bf474a1c5591d2619a22f15f095bf0a Mon Sep 17 00:00:00 2001 From: Skyler Katz Date: Thu, 31 Mar 2022 06:58:32 -0700 Subject: [PATCH 1/2] Support replacing placeholder values --- lib/Monk/Cms.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/Monk/Cms.php b/lib/Monk/Cms.php index adf3293..9c55d7c 100644 --- a/lib/Monk/Cms.php +++ b/lib/Monk/Cms.php @@ -239,7 +239,33 @@ private function request(array $queryParams) $responseBody = substr($response->body, 10); - return json_decode($responseBody, true); + return json_decode($this->replacePlaceholderValues($responseBody), true); + } + + /** + * Replace placeholder values with the expected values + * + * @param string $body + * @return string + */ + private function replacePlaceholderValues($body) + { + $body = str_replace('', '{{', $body); + $body = str_replace('', '}}', $body); + $body = str_replace('', '{##', $body); + $body = str_replace('', '##}', $body); + // if requesting json the tag may be escaped + $body = str_replace('<\/mcms-interactive-answer>', '}}', $body); + $body = str_replace('<\/mcms-interactive-free-form>', '##}', $body); + + if (array_key_exists('HTTP_ACCEPT', $_SERVER) && in_array('image/webp', explode(',', $_SERVER['HTTP_ACCEPT']))) { + $body = str_replace('MONK_IMAGE_FORMAT_REPLACE_ME', 'webp', $body); + } else { + // If the browser does not support webp, remove the format line altogether + $body = str_replace('?fm=MONK_IMAGE_FORMAT_REPLACE_ME', '', $body); + } + + return $body; } /** From a77db64ab0438964949369f005721a3f1b486d65 Mon Sep 17 00:00:00 2001 From: Skyler Katz Date: Thu, 31 Mar 2022 07:00:08 -0700 Subject: [PATCH 2/2] update readme instructions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a4b17b..eb76b0e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Using [Composer](http://getcomposer.org), add `monkdev/monkcms` to your ```json { "require": { - "monkdev/monkcms": "~0.3" + "monkdev/monkcms": "~0.5" } } ``` @@ -39,7 +39,7 @@ $ composer update Or: ```bash -$ composer require monkdev/monkcms:~0.3 +$ composer require monkdev/monkcms:~0.5 ``` ### Configure