Upgrade to 3.8.0
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user