diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index eca9f83f..4168ff98 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -47,10 +47,11 @@ EOD; } $feedTimestamp = date(DATE_ATOM, time()); + $charset = $this->getCharset(); /* Data are prepared, now let's begin the "MAGIE !!!" */ - $toReturn = ''; - $toReturn .= << {$title} @@ -64,15 +65,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 c32c3a1c..b928d139 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -42,12 +42,14 @@ class HtmlFormat extends FormatAbstract { EOD; } + $charset = $this->getCharset(); + /* Data are prepared, now let's begin the "MAGIE !!!" */ $toReturn = << - + {$title} @@ -64,6 +66,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 ac6e450a..a60601a0 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 52ee86fb..da75b77f 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -48,12 +48,14 @@ class MrssFormat extends FormatAbstract { EOD; } + $charset = $this->getCharset(); + /* Data are prepared, now let's begin the "MAGIE !!!" */ - $toReturn = ''; - $toReturn .= << + {$title} @@ -69,13 +71,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 593e938d..c9691d0f 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();