forked from blallo/rss-bridge
Merge branch 'ImproveFormat' of https://github.com/logmanoriginal/rss-bridge
This commit is contained in:
commit
84bc9d2da6
7 changed files with 64 additions and 27 deletions
|
@ -26,9 +26,12 @@ class AtomFormat extends FormatAbstract{
|
|||
$entryUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : '';
|
||||
$entryTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_ATOM, $item['timestamp'])) : '';
|
||||
$entryContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : '';
|
||||
$entryEnclosures = "";
|
||||
foreach($item['enclosures'] as $enclosure)
|
||||
$entryEnclosures .= "<link rel=\"enclosure\" href=\"".$this->xml_encode($enclosure)."\"/>";
|
||||
|
||||
$entryEnclosure = '';
|
||||
if(isset($item['enclosure'])){
|
||||
$entryEnclosure = '<link rel="enclosure" href="' . $this->xml_encode($item['enclosure']) . '"/>';
|
||||
}
|
||||
|
||||
$entries .= <<<EOD
|
||||
|
||||
<entry>
|
||||
|
@ -40,17 +43,18 @@ class AtomFormat extends FormatAbstract{
|
|||
<id>{$entryUri}</id>
|
||||
<updated>{$entryTimestamp}</updated>
|
||||
<content type="html">{$entryContent}</content>
|
||||
{$entryEnclosures}
|
||||
{$entryEnclosure}
|
||||
</entry>
|
||||
|
||||
EOD;
|
||||
}
|
||||
|
||||
$feedTimestamp = date(DATE_ATOM, time());
|
||||
$charset = $this->getCharset();
|
||||
|
||||
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
||||
$toReturn = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$toReturn .= <<<EOD
|
||||
$toReturn = <<<EOD
|
||||
<?xml version="1.0" encoding="{$charset}"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">
|
||||
|
||||
<title type="text">{$title}</title>
|
||||
|
@ -64,15 +68,15 @@ EOD;
|
|||
</feed>
|
||||
EOD;
|
||||
|
||||
// Remove invalid non-UTF8 characters
|
||||
// Remove invalid characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$toReturn = mb_convert_encoding($toReturn, 'UTF-8', 'UTF-8');
|
||||
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
||||
return $toReturn;
|
||||
}
|
||||
|
||||
public function display(){
|
||||
$this
|
||||
->setContentType('application/atom+xml; charset=UTF-8')
|
||||
->setContentType('application/atom+xml; charset=' . $this->getCharset())
|
||||
->callContentType();
|
||||
|
||||
return parent::display();
|
||||
|
|
|
@ -30,6 +30,13 @@ class HtmlFormat extends FormatAbstract {
|
|||
. '</div>';
|
||||
}
|
||||
|
||||
$entryEnclosure = '';
|
||||
if(isset($item['enclosure'])){
|
||||
$entryEnclosure = '<div class="enclosure"><a href="'
|
||||
. $this->sanitizeHtml($item['enclosure'])
|
||||
. '">enclosure</a><div>';
|
||||
}
|
||||
|
||||
$entries .= <<<EOD
|
||||
|
||||
<section class="feeditem">
|
||||
|
@ -37,17 +44,20 @@ class HtmlFormat extends FormatAbstract {
|
|||
{$entryTimestamp}
|
||||
{$entryAuthor}
|
||||
{$entryContent}
|
||||
{$entryEnclosure}
|
||||
</section>
|
||||
|
||||
EOD;
|
||||
}
|
||||
|
||||
$charset = $this->getCharset();
|
||||
|
||||
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
||||
$toReturn = <<<EOD
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta charset="{$charset}">
|
||||
<title>{$title}</title>
|
||||
<link href="css/HtmlFormat.css" rel="stylesheet">
|
||||
<meta name="robots" content="noindex, follow">
|
||||
|
@ -64,6 +74,9 @@ EOD;
|
|||
</html>
|
||||
EOD;
|
||||
|
||||
// Remove invalid characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
||||
return $toReturn;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,17 @@ class JsonFormat extends FormatAbstract {
|
|||
|
||||
public function stringify(){
|
||||
$items = $this->getItems();
|
||||
return json_encode($items, JSON_PRETTY_PRINT);
|
||||
$toReturn = json_encode($items, JSON_PRETTY_PRINT);
|
||||
|
||||
// Remove invalid non-UTF8 characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
||||
return $toReturn;
|
||||
}
|
||||
|
||||
public function display(){
|
||||
$this
|
||||
->setContentType('application/json')
|
||||
->setContentType('application/json; charset=' . $this->getCharset())
|
||||
->callContentType();
|
||||
|
||||
return parent::display();
|
||||
|
|
|
@ -30,9 +30,12 @@ class MrssFormat extends FormatAbstract {
|
|||
$itemUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : '';
|
||||
$itemTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $item['timestamp'])) : '';
|
||||
$itemContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : '';
|
||||
$entryEnclosures = "";
|
||||
foreach($item['enclosures'] as $enclosure)
|
||||
$entryEnclosures .= "<enclosure url=\"".$this->xml_encode($enclosure)."\"/>";
|
||||
|
||||
$entryEnclosure = '';
|
||||
if(isset($item['enclosure'])){
|
||||
$entryEnclosure = '<enclosure url="' . $this->xml_encode($item['enclosure']) . '"/>';
|
||||
}
|
||||
|
||||
$items .= <<<EOD
|
||||
|
||||
<item>
|
||||
|
@ -42,15 +45,17 @@ class MrssFormat extends FormatAbstract {
|
|||
<pubDate>{$itemTimestamp}</pubDate>
|
||||
<description>{$itemContent}</description>
|
||||
<author>{$itemAuthor}</author>
|
||||
{$entryEnclosures}
|
||||
{$entryEnclosure}
|
||||
</item>
|
||||
|
||||
EOD;
|
||||
}
|
||||
|
||||
$charset = $this->getCharset();
|
||||
|
||||
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
||||
$toReturn = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$toReturn .= <<<EOD
|
||||
$toReturn = <<<EOD
|
||||
<?xml version="1.0" encoding="{$charset}"?>
|
||||
<rss version="2.0"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:media="http://search.yahoo.com/mrss/"
|
||||
|
@ -69,13 +74,13 @@ EOD;
|
|||
|
||||
// Remove invalid non-UTF8 characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$toReturn = mb_convert_encoding($toReturn, 'UTF-8', 'UTF-8');
|
||||
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
||||
return $toReturn;
|
||||
}
|
||||
|
||||
public function display(){
|
||||
$this
|
||||
->setContentType('application/rss+xml; charset=UTF-8')
|
||||
->setContentType('application/rss+xml; charset=' . $this->getCharset())
|
||||
->callContentType();
|
||||
|
||||
return parent::display();
|
||||
|
|
|
@ -7,12 +7,17 @@ class PlaintextFormat extends FormatAbstract {
|
|||
|
||||
public function stringify(){
|
||||
$items = $this->getItems();
|
||||
return print_r($items, true);
|
||||
$toReturn = print_r($items, true);
|
||||
|
||||
// Remove invalid non-UTF8 characters
|
||||
ini_set('mbstring.substitute_character', 'none');
|
||||
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
||||
return $toReturn;
|
||||
}
|
||||
|
||||
public function display(){
|
||||
$this
|
||||
->setContentType('text/plain;charset=' . $this->getCharset())
|
||||
->setContentType('text/plain; charset=' . $this->getCharset())
|
||||
->callContentType();
|
||||
|
||||
return parent::display();
|
||||
|
|
|
@ -18,7 +18,7 @@ abstract class FormatAbstract implements FormatInterface {
|
|||
public function getCharset(){
|
||||
$charset = $this->charset;
|
||||
|
||||
return is_null($charset) ? self::DEFAULT_CHARSET : $charset;
|
||||
return is_null($charset) ? static::DEFAULT_CHARSET : $charset;
|
||||
}
|
||||
|
||||
protected function setContentType($contentType){
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
<?php
|
||||
interface FormatInterface{
|
||||
interface FormatInterface {
|
||||
public function stringify();
|
||||
public function display();
|
||||
public function setItems(array $bridges);
|
||||
public function getItems();
|
||||
public function setExtraInfos(array $infos);
|
||||
public function getExtraInfos();
|
||||
public function setCharset($charset);
|
||||
public function getCharset();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue