Skip to content

Commit

Permalink
Merge pull request #17 from MonkDev/dev
Browse files Browse the repository at this point in the history
Version 0.5
  • Loading branch information
skylerkatz authored Mar 31, 2022
2 parents 5c8a7ed + 7750c06 commit adc0486
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Using [Composer](http://getcomposer.org), add `monkdev/monkcms` to your
```json
{
"require": {
"monkdev/monkcms": "~0.3"
"monkdev/monkcms": "~0.5"
}
}
```
Expand All @@ -39,7 +39,7 @@ $ composer update
Or:

```bash
$ composer require monkdev/monkcms:~0.3
$ composer require monkdev/monkcms:~0.5
```

### Configure
Expand Down
28 changes: 27 additions & 1 deletion lib/Monk/Cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<mcms-interactive-answer>', '{{', $body);
$body = str_replace('</mcms-interactive-answer>', '}}', $body);
$body = str_replace('<mcms-interactive-free-form>', '{##', $body);
$body = str_replace('</mcms-interactive-free-form>', '##}', $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;
}

/**
Expand Down

0 comments on commit adc0486

Please sign in to comment.