mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-02-27 04:39:12 +03:00
65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
|
<?PHP
|
||
|
|
||
|
class SfeedFormat extends FormatAbstract
|
||
|
{
|
||
|
const MIME_TYPE = 'text/plain';
|
||
|
|
||
|
private function escape(string $str)
|
||
|
{
|
||
|
$str = str_replace('\\', '\\\\', $str);
|
||
|
$str = str_replace("\n", "\\n", $str);
|
||
|
return str_replace("\t", "\\t", $str);
|
||
|
}
|
||
|
|
||
|
private function getFirstEnclosure(array $enclosures)
|
||
|
{
|
||
|
if (count($enclosures) >= 1) {
|
||
|
return $enclosures[0];
|
||
|
}
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
private function getCategories(array $cats)
|
||
|
{
|
||
|
$toReturn = '';
|
||
|
$i = 0;
|
||
|
foreach ($cats as $cat) {
|
||
|
$toReturn .= $cat;
|
||
|
if (count($cats) < $i) {
|
||
|
$toReturn .= '|';
|
||
|
}
|
||
|
$i++;
|
||
|
}
|
||
|
return $toReturn;
|
||
|
}
|
||
|
|
||
|
public function stringify()
|
||
|
{
|
||
|
$items = $this->getItems();
|
||
|
|
||
|
$toReturn = '';
|
||
|
foreach ($items as $item) {
|
||
|
$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']),
|
||
|
$item->toArray()['uri'],
|
||
|
$this->escape($item->toArray()['content']),
|
||
|
$item->toArray()['author'],
|
||
|
$this->getFirstEnclosure($item->toArray()['enclosures']),
|
||
|
$this->getCategories($item->toArray()['categories'])
|
||
|
);
|
||
|
}
|
||
|
|
||
|
// Remove invalid non-UTF8 characters
|
||
|
ini_set('mbstring.substitute_character', 'none');
|
||
|
$toReturn = mb_convert_encoding(
|
||
|
$toReturn,
|
||
|
$this->getCharset(),
|
||
|
'UTF-8'
|
||
|
);
|
||
|
return $toReturn;
|
||
|
}
|
||
|
}
|
||
|
// vi: expandtab
|