From 224cce08a851a496686a723a35e5ac7524c2ff54 Mon Sep 17 00:00:00 2001 From: mad-reyk Date: Sun, 12 Mar 2023 14:21:21 +0000 Subject: [PATCH] [Sfeed] Fixed category separator and random white spaces (#3308) --- formats/SfeedFormat.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/formats/SfeedFormat.php b/formats/SfeedFormat.php index 66dddfee..85d5f608 100644 --- a/formats/SfeedFormat.php +++ b/formats/SfeedFormat.php @@ -7,8 +7,8 @@ class SfeedFormat extends FormatAbstract private function escape(string $str) { $str = str_replace('\\', '\\\\', $str); - $str = str_replace("\n", "\\n", $str); - return str_replace("\t", "\\t", $str); + $str = str_replace("\n", '\\n', $str); + return str_replace("\t", '\\t', $str); } private function getFirstEnclosure(array $enclosures) @@ -22,13 +22,12 @@ class SfeedFormat extends FormatAbstract private function getCategories(array $cats) { $toReturn = ''; - $i = 0; + $i = 1; foreach ($cats as $cat) { - $toReturn .= $cat; - if (count($cats) < $i) { + $toReturn .= trim($cat); + if (count($cats) > $i++) { $toReturn .= '|'; } - $i++; } return $toReturn; } @@ -42,12 +41,18 @@ class SfeedFormat extends FormatAbstract $toReturn .= sprintf( "%s\t%s\t%s\t%s\thtml\t\t%s\t%s\t%s\n", $item->toArray()['timestamp'], - $this->escape($item->toArray()['title']), + preg_replace('/\s/', ' ', $item->toArray()['title']), $item->toArray()['uri'], $this->escape($item->toArray()['content']), $item->toArray()['author'], - $this->getFirstEnclosure($item->toArray()['enclosures']), - $this->getCategories($item->toArray()['categories']) + $this->getFirstEnclosure( + $item->toArray()['enclosures'] + ), + $this->escape( + $this->getCategories( + $item->toArray()['categories'] + ) + ) ); }