[Sfeed] Fixed category separator and random white spaces (#3308)

This commit is contained in:
mad-reyk 2023-03-12 14:21:21 +00:00 committed by GitHub
parent c1f446fd19
commit 224cce08a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 9 deletions

View File

@ -7,8 +7,8 @@ class SfeedFormat extends FormatAbstract
private function escape(string $str) private function escape(string $str)
{ {
$str = str_replace('\\', '\\\\', $str); $str = str_replace('\\', '\\\\', $str);
$str = str_replace("\n", "\\n", $str); $str = str_replace("\n", '\\n', $str);
return str_replace("\t", "\\t", $str); return str_replace("\t", '\\t', $str);
} }
private function getFirstEnclosure(array $enclosures) private function getFirstEnclosure(array $enclosures)
@ -22,13 +22,12 @@ class SfeedFormat extends FormatAbstract
private function getCategories(array $cats) private function getCategories(array $cats)
{ {
$toReturn = ''; $toReturn = '';
$i = 0; $i = 1;
foreach ($cats as $cat) { foreach ($cats as $cat) {
$toReturn .= $cat; $toReturn .= trim($cat);
if (count($cats) < $i) { if (count($cats) > $i++) {
$toReturn .= '|'; $toReturn .= '|';
} }
$i++;
} }
return $toReturn; return $toReturn;
} }
@ -42,12 +41,18 @@ class SfeedFormat extends FormatAbstract
$toReturn .= sprintf( $toReturn .= sprintf(
"%s\t%s\t%s\t%s\thtml\t\t%s\t%s\t%s\n", "%s\t%s\t%s\t%s\thtml\t\t%s\t%s\t%s\n",
$item->toArray()['timestamp'], $item->toArray()['timestamp'],
$this->escape($item->toArray()['title']), preg_replace('/\s/', ' ', $item->toArray()['title']),
$item->toArray()['uri'], $item->toArray()['uri'],
$this->escape($item->toArray()['content']), $this->escape($item->toArray()['content']),
$item->toArray()['author'], $item->toArray()['author'],
$this->getFirstEnclosure($item->toArray()['enclosures']), $this->getFirstEnclosure(
$this->getCategories($item->toArray()['categories']) $item->toArray()['enclosures']
),
$this->escape(
$this->getCategories(
$item->toArray()['categories']
)
)
); );
} }