2023-03-12 02:13:27 +03:00
|
|
|
<?PHP
|
|
|
|
|
|
|
|
class SfeedFormat extends FormatAbstract
|
|
|
|
{
|
|
|
|
const MIME_TYPE = 'text/plain';
|
|
|
|
|
2024-08-23 18:34:06 +03:00
|
|
|
public function render(): string
|
2023-09-25 23:32:15 +03:00
|
|
|
{
|
|
|
|
$text = '';
|
|
|
|
foreach ($this->getItems() as $item) {
|
|
|
|
$text .= sprintf(
|
|
|
|
"%s\t%s\t%s\t%s\thtml\t\t%s\t%s\t%s\n",
|
|
|
|
$item->toArray()['timestamp'],
|
|
|
|
preg_replace('/\s/', ' ', $item->toArray()['title']),
|
|
|
|
$item->toArray()['uri'],
|
|
|
|
$this->escape($item->toArray()['content']),
|
|
|
|
$item->toArray()['author'],
|
|
|
|
$this->getFirstEnclosure(
|
|
|
|
$item->toArray()['enclosures']
|
|
|
|
),
|
|
|
|
$this->escape(
|
|
|
|
$this->getCategories(
|
|
|
|
$item->toArray()['categories']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2023-03-12 02:13:27 +03:00
|
|
|
private function escape(string $str)
|
|
|
|
{
|
|
|
|
$str = str_replace('\\', '\\\\', $str);
|
2023-03-12 17:21:21 +03:00
|
|
|
$str = str_replace("\n", '\\n', $str);
|
|
|
|
return str_replace("\t", '\\t', $str);
|
2023-03-12 02:13:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getFirstEnclosure(array $enclosures)
|
|
|
|
{
|
|
|
|
if (count($enclosures) >= 1) {
|
|
|
|
return $enclosures[0];
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getCategories(array $cats)
|
|
|
|
{
|
|
|
|
$toReturn = '';
|
2023-03-12 17:21:21 +03:00
|
|
|
$i = 1;
|
2023-03-12 02:13:27 +03:00
|
|
|
foreach ($cats as $cat) {
|
2023-03-12 17:21:21 +03:00
|
|
|
$toReturn .= trim($cat);
|
|
|
|
if (count($cats) > $i++) {
|
2023-03-12 02:13:27 +03:00
|
|
|
$toReturn .= '|';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $toReturn;
|
|
|
|
}
|
|
|
|
}
|