mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add global charset for Fenom
This commit is contained in:
parent
c2751e069c
commit
c6dbdfff95
@ -58,6 +58,8 @@ class Fenom
|
|||||||
const ACCESSOR_VAR = 'Fenom\Accessor::parserVar';
|
const ACCESSOR_VAR = 'Fenom\Accessor::parserVar';
|
||||||
const ACCESSOR_CALL = 'Fenom\Accessor::parserCall';
|
const ACCESSOR_CALL = 'Fenom\Accessor::parserCall';
|
||||||
|
|
||||||
|
public static $charset = "UTF-8";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int[] of possible options, as associative array
|
* @var int[] of possible options, as associative array
|
||||||
* @see setOptions
|
* @see setOptions
|
||||||
|
@ -58,13 +58,13 @@ class Modifier
|
|||||||
* @param string $charset
|
* @param string $charset
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function escape($text, $type = 'html', $charset = 'UTF-8')
|
public static function escape($text, $type = 'html', $charset = null)
|
||||||
{
|
{
|
||||||
switch (strtolower($type)) {
|
switch (strtolower($type)) {
|
||||||
case "url":
|
case "url":
|
||||||
return urlencode($text);
|
return urlencode($text);
|
||||||
case "html";
|
case "html";
|
||||||
return htmlspecialchars($text, ENT_COMPAT, $charset);
|
return htmlspecialchars($text, ENT_COMPAT, $charset ? $charset : \Fenom::$charset);
|
||||||
case "js":
|
case "js":
|
||||||
return json_encode($text, 64 | 256); // JSON_UNESCAPED_SLASHES = 64, JSON_UNESCAPED_UNICODE = 256
|
return json_encode($text, 64 | 256); // JSON_UNESCAPED_SLASHES = 64, JSON_UNESCAPED_UNICODE = 256
|
||||||
default:
|
default:
|
||||||
|
@ -490,7 +490,7 @@ class Template extends Render
|
|||||||
$escape = $this->_options & Fenom::AUTO_ESCAPE;
|
$escape = $this->_options & Fenom::AUTO_ESCAPE;
|
||||||
}
|
}
|
||||||
if ($escape) {
|
if ($escape) {
|
||||||
return "echo htmlspecialchars($data, ENT_COMPAT, 'UTF-8');";
|
return "echo htmlspecialchars($data, ENT_COMPAT, ".var_export(Fenom::$charset, true).");";
|
||||||
} else {
|
} else {
|
||||||
return "echo $data;";
|
return "echo $data;";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user