[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)
{
$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']
)
)
);
}