|
Perforce Chronicle 2012.2/486814
API Documentation
|
Abstract view helper for escaping untrusted data before inserting them in the view. More...
Protected Member Functions | |
| _encode ($value) | |
| Encodes given value. | |
| _encodeChar ($char) | |
| Encode single character into a value that can be safely inserted into the view. | |
| _format ($ordinalValue) | |
| Formats character represented by its ordinal value into a string that can be safely to inserted in the view. | |
| _isAlnum ($ordinalValue) | |
| Help function to detect if given ordinal value represents alphanumeric character. | |
Protected Attributes | |
| $_illegalOrd = array() | |
| $_safeChars = array() | |
Abstract view helper for escaping untrusted data before inserting them in the view.
| P4Cms_View_Helper_EscapeAbstract::_encode | ( | $ | value | ) | [protected] |
Encodes given value.
See _encodeChar() method for details how single characters are encoded.
| string | $value | Value to encode. |
{
$output = '';
$charset = $this->view->getEncoding();
for ($i = 0; $i < iconv_strlen($value, $charset); $i++) {
$char = iconv_substr($value, $i, 1, $charset);
$output .= $this->_encodeChar($char);
}
return $output;
}
| P4Cms_View_Helper_EscapeAbstract::_encodeChar | ( | $ | char | ) | [protected] |
Encode single character into a value that can be safely inserted into the view.
| string | $char | Character to encode. |
{
// if char is safe, return it
if (in_array($char, $this->_safeChars)) {
return $char;
}
// convert char to 4-byte
$char4Byte = iconv($this->view->getEncoding(), "UTF-32LE", $char);
// get the ordinal value of the character
list(, $ordinalValue) = unpack("V", $char4Byte);
// encode char
if ($this->_isAlnum($ordinalValue)) {
return $char;
} else if (in_array($ordinalValue, $this->_illegalOrd)) {
return " ";
} else {
return $this->_format($ordinalValue);
}
}
| P4Cms_View_Helper_EscapeAbstract::_format | ( | $ | ordinalValue | ) | [abstract, protected] |
Formats character represented by its ordinal value into a string that can be safely to inserted in the view.
Implemented by concrete class as it depends on the context (html attrib, js, css etc.).
| int | $ordinalValue | Ordinal value to format. |
Reimplemented in P4Cms_View_Helper_EscapeAttr, and P4Cms_View_Helper_EscapeJs.
| P4Cms_View_Helper_EscapeAbstract::_isAlnum | ( | $ | ordinalValue | ) | [protected] |
Help function to detect if given ordinal value represents alphanumeric character.
| int | $ordinalValue | Ordinal value to check. |
{
return ($ordinalValue >= 48 && $ordinalValue <= 57)
|| ($ordinalValue >= 65 && $ordinalValue <= 90)
|| ($ordinalValue >= 97 && $ordinalValue <= 122);
}
P4Cms_View_Helper_EscapeAbstract::$_illegalOrd = array() [protected] |
P4Cms_View_Helper_EscapeAbstract::$_safeChars = array() [protected] |
Reimplemented in P4Cms_View_Helper_EscapeAttr, and P4Cms_View_Helper_EscapeJs.