Skip to content

Commit 224cce0

Browse files
authored
[Sfeed] Fixed category separator and random white spaces (RSS-Bridge#3308)
1 parent c1f446f commit 224cce0

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

formats/SfeedFormat.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class SfeedFormat extends FormatAbstract
77
private function escape(string $str)
88
{
99
$str = str_replace('\\', '\\\\', $str);
10-
$str = str_replace("\n", "\\n", $str);
11-
return str_replace("\t", "\\t", $str);
10+
$str = str_replace("\n", '\\n', $str);
11+
return str_replace("\t", '\\t', $str);
1212
}
1313

1414
private function getFirstEnclosure(array $enclosures)
@@ -22,13 +22,12 @@ private function getFirstEnclosure(array $enclosures)
2222
private function getCategories(array $cats)
2323
{
2424
$toReturn = '';
25-
$i = 0;
25+
$i = 1;
2626
foreach ($cats as $cat) {
27-
$toReturn .= $cat;
28-
if (count($cats) < $i) {
27+
$toReturn .= trim($cat);
28+
if (count($cats) > $i++) {
2929
$toReturn .= '|';
3030
}
31-
$i++;
3231
}
3332
return $toReturn;
3433
}
@@ -42,12 +41,18 @@ public function stringify()
4241
$toReturn .= sprintf(
4342
"%s\t%s\t%s\t%s\thtml\t\t%s\t%s\t%s\n",
4443
$item->toArray()['timestamp'],
45-
$this->escape($item->toArray()['title']),
44+
preg_replace('/\s/', ' ', $item->toArray()['title']),
4645
$item->toArray()['uri'],
4746
$this->escape($item->toArray()['content']),
4847
$item->toArray()['author'],
49-
$this->getFirstEnclosure($item->toArray()['enclosures']),
50-
$this->getCategories($item->toArray()['categories'])
48+
$this->getFirstEnclosure(
49+
$item->toArray()['enclosures']
50+
),
51+
$this->escape(
52+
$this->getCategories(
53+
$item->toArray()['categories']
54+
)
55+
)
5156
);
5257
}
5358

0 commit comments

Comments
 (0)