diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php
index eca9f83..1944905 100644
--- a/formats/AtomFormat.php
+++ b/formats/AtomFormat.php
@@ -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 .= "xml_encode($enclosure)."\"/>";
+
+ $entryEnclosure = '';
+ if(isset($item['enclosure'])){
+ $entryEnclosure = '';
+ }
+
$entries .= <<
@@ -40,17 +43,18 @@ class AtomFormat extends FormatAbstract{
{$entryUri}
{$entryTimestamp}
{$entryContent}
- {$entryEnclosures}
+ {$entryEnclosure}
EOD;
}
$feedTimestamp = date(DATE_ATOM, time());
+ $charset = $this->getCharset();
/* Data are prepared, now let's begin the "MAGIE !!!" */
- $toReturn = '';
- $toReturn .= <<
{$title}
@@ -64,15 +68,15 @@ EOD;
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();
diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php
index c32c3a1..8f96466 100644
--- a/formats/HtmlFormat.php
+++ b/formats/HtmlFormat.php
@@ -30,6 +30,13 @@ class HtmlFormat extends FormatAbstract {
. '';
}
+ $entryEnclosure = '';
+ if(isset($item['enclosure'])){
+ $entryEnclosure = 'enclosure';
+ }
+
$entries .= <<
@@ -37,17 +44,20 @@ class HtmlFormat extends FormatAbstract {
{$entryTimestamp}
{$entryAuthor}
{$entryContent}
+ {$entryEnclosure}
EOD;
}
+ $charset = $this->getCharset();
+
/* Data are prepared, now let's begin the "MAGIE !!!" */
$toReturn = <<
-
+
{$title}
@@ -64,6 +74,9 @@ EOD;
EOD;
+ // Remove invalid characters
+ ini_set('mbstring.substitute_character', 'none');
+ $toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
return $toReturn;
}
diff --git a/formats/JsonFormat.php b/formats/JsonFormat.php
index ac6e450..a60601a 100644
--- a/formats/JsonFormat.php
+++ b/formats/JsonFormat.php
@@ -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();
diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php
index 52ee86f..19c703e 100644
--- a/formats/MrssFormat.php
+++ b/formats/MrssFormat.php
@@ -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 .= "xml_encode($enclosure)."\"/>";
+
+ $entryEnclosure = '';
+ if(isset($item['enclosure'])){
+ $entryEnclosure = '';
+ }
+
$items .= <<
@@ -42,18 +45,20 @@ class MrssFormat extends FormatAbstract {
{$itemTimestamp}
{$itemContent}
{$itemAuthor}
- {$entryEnclosures}
+ {$entryEnclosure}
EOD;
}
+ $charset = $this->getCharset();
+
/* Data are prepared, now let's begin the "MAGIE !!!" */
- $toReturn = '';
- $toReturn .= <<
+
{$title}
@@ -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();
diff --git a/formats/PlaintextFormat.php b/formats/PlaintextFormat.php
index 593e938..c9691d0 100644
--- a/formats/PlaintextFormat.php
+++ b/formats/PlaintextFormat.php
@@ -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();
diff --git a/lib/FormatAbstract.php b/lib/FormatAbstract.php
index 6bcc2f9..c359026 100644
--- a/lib/FormatAbstract.php
+++ b/lib/FormatAbstract.php
@@ -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){
diff --git a/lib/FormatInterface.php b/lib/FormatInterface.php
index 2fac3fc..f99d214 100644
--- a/lib/FormatInterface.php
+++ b/lib/FormatInterface.php
@@ -1,6 +1,11 @@