[formats] Use custom characterset in all formats
The specified characterset will now apply to all formats thus allowing other charactersets than 'UTF-8'
This commit is contained in:
parent
4f4fb11789
commit
3a2cb9ea1e
5 changed files with 35 additions and 17 deletions
|
@ -47,10 +47,11 @@ 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 +65,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();
|
||||
|
|
|
@ -42,12 +42,14 @@ class HtmlFormat extends FormatAbstract {
|
|||
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 +66,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();
|
||||
|
|
|
@ -48,12 +48,14 @@ class MrssFormat extends FormatAbstract {
|
|||
EOD;
|
||||
}
|
||||
|
||||
$charset = $this->getCharset();
|
||||
|
||||
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
||||
$toReturn = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$toReturn .= <<<EOD
|
||||
<rss version="2.0"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:media="http://search.yahoo.com/mrss/"
|
||||
$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/"
|
||||
xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>{$title}</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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue