Upgrade to 3.8.0

This commit is contained in:
Bastian Allgeier
2022-10-06 10:11:54 +02:00
parent a9ed4e45ca
commit 7d168aae58
332 changed files with 26337 additions and 21977 deletions

View File

@@ -19,9 +19,6 @@ class Txt extends Handler
{
/**
* Converts an array to an encoded Kirby txt string
*
* @param mixed $data
* @return string
*/
public static function encode($data): string
{
@@ -42,11 +39,8 @@ class Txt extends Handler
/**
* Helper for converting the value
*
* @param array|string $value
* @return string
*/
protected static function encodeValue($value): string
protected static function encodeValue(array|string|float $value): string
{
// avoid problems with arrays
if (is_array($value) === true) {
@@ -64,10 +58,6 @@ class Txt extends Handler
/**
* Helper for converting the key and value to the result string
*
* @param string $key
* @param string $value
* @return string
*/
protected static function encodeResult(string $key, string $value): string
{
@@ -88,9 +78,6 @@ class Txt extends Handler
/**
* Parses a Kirby txt string and returns a multi-dimensional array
*
* @param mixed $string
* @return array
*/
public static function decode($string): array
{
@@ -115,18 +102,24 @@ class Txt extends Handler
// loop through all fields and add them to the content
foreach ($fields as $field) {
$pos = strpos($field, ':');
$key = str_replace(['-', ' '], '_', strtolower(trim(substr($field, 0, $pos))));
if ($pos = strpos($field, ':')) {
$key = strtolower(trim(substr($field, 0, $pos)));
$key = str_replace(['-', ' '], '_', $key);
// Don't add fields with empty keys
if (empty($key) === true) {
continue;
// Don't add fields with empty keys
if (empty($key) === true) {
continue;
}
$value = trim(substr($field, $pos + 1));
// unescape escaped dividers within a field
$data[$key] = preg_replace(
'!(?<=\n|^)\\\\----!',
'----',
$value
);
}
$value = trim(substr($field, $pos + 1));
// unescape escaped dividers within a field
$data[$key] = preg_replace('!(?<=\n|^)\\\\----!', '----', $value);
}
return $data;