HTMLPurifier_Encoder Klassenreferenz

HTMLPurifier_Encoder Klassenreferenz

Öffentliche, statische Methoden

static muteErrorHandler ()
 
static unsafeIconv ($in, $out, $text)
 
static iconv ($in, $out, $text, $max_chunk_size=8000)
 
static cleanUTF8 ($str, $force_php=false)
 
static unichr ($code)
 
static iconvAvailable ()
 
static convertToUTF8 ($str, $config, $context)
 
static convertFromUTF8 ($str, $config, $context)
 
static convertToASCIIDumbLossless ($str)
 
static testIconvTruncateBug ()
 
static testEncodingSupportsASCII ($encoding, $bypass=false)
 

Datenfelder

const ICONV_OK = 0
 
const ICONV_TRUNCATES = 1
 
const ICONV_UNUSABLE = 2
 

Private Methoden

 __construct ()
 

Ausführliche Beschreibung

A UTF-8 specific character encoder that handles cleaning and transforming.

Zu beachten
All functions in this class should be static.

Definiert in Zeile 7 der Datei Encoder.php.

Beschreibung der Konstruktoren und Destruktoren

__construct ( )
private

Constructor throws fatal error if you attempt to instantiate class

Definiert in Zeile 13 der Datei Encoder.php.

Dokumentation der Elementfunktionen

static cleanUTF8 (   $str,
  $force_php = false 
)
static

Cleans a UTF-8 string for well-formedness and SGML validity

It will parse according to UTF-8 and return a valid UTF8 string, with non-SGML codepoints excluded.

Parameter
string$strThe string to clean
bool$force_php
Rückgabe
string
Zu beachten
Just for reference, the non-SGML code points are 0 to 31 and 127 to 159, inclusive. However, we allow code points 9, 10 and 13, which are the tab, line feed and carriage return respectively. 128 and above the code points map to multibyte UTF-8 representations.
Fallback code adapted from utf8ToUnicode by Henri Sivonen and hsivo.nosp@m.nen@.nosp@m.iki.f.nosp@m.i at http://iki.fi/hsivonen/php-utf8/ under the LGPL license. Notes on what changed are inside, but in general, the original code transformed UTF-8 text into an array of integer Unicode codepoints. Understandably, transforming that back to a string would be somewhat expensive, so the function was modded to directly operate on the string. However, this discourages code reuse, and the logic enumerated here would be useful for any function that needs to be able to understand UTF-8 characters. As of right now, only smart lossless character encoding converters would need that, and I'm probably not going to implement them. Once again, PHP 6 should solve all our problems.

Definiert in Zeile 127 der Datei Encoder.php.

Wird benutzt von HTMLPurifier_Printer\escape(), HTMLPurifier_AttrDef\expandCSSEscape() und HTMLPurifier_Lexer\normalize().

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static convertFromUTF8 (   $str,
  $config,
  $context 
)
static

Converts a string from UTF-8 based on configuration.

Parameter
string$strThe string to convert
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Rückgabe
string
Zu beachten
Currently, this is a lossy conversion, with unexpressable characters being omitted.

Definiert in Zeile 420 der Datei Encoder.php.

Wird benutzt von HTMLPurifier\purify().

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static convertToASCIIDumbLossless (   $str)
static

Lossless (character-wise) conversion of HTML to ASCII

Parameter
string$strUTF-8 string to be converted to ASCII
Rückgabe
string ASCII encoded string with non-ASCII character entity-ized
Warnung
Adapted from MediaWiki, claiming fair use: this is a common algorithm. If you disagree with this license fudgery, implement it yourself.
Zu beachten
Uses decimal numeric entities since they are best supported.
This is a DUMB function: it has no concept of keeping character entities that the projected character encoding can allow. We could possibly implement a smart version but that would require it to also know which Unicode codepoints the charset supported (not an easy task).
Sort of with cleanUTF8() but it assumes that $str is well-formed UTF-8

Definiert in Zeile 474 der Datei Encoder.php.

static convertToUTF8 (   $str,
  $config,
  $context 
)
static

Convert a string to UTF-8 based on configuration.

Parameter
string$strThe string to convert
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Rückgabe
string

Definiert in Zeile 372 der Datei Encoder.php.

Benutzt testIconvTruncateBug().

Wird benutzt von HTMLPurifier\purify().

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static iconv (   $in,
  $out,
  $text,
  $max_chunk_size = 8000 
)
static

iconv wrapper which mutes errors and works around bugs.

Parameter
string$inInput encoding
string$outOutput encoding
string$textThe text to convert
int$max_chunk_size
Rückgabe
string

Definiert in Zeile 48 der Datei Encoder.php.

Wird benutzt von unsafeIconv().

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static iconvAvailable ( )
static
Rückgabe
bool

Definiert in Zeile 356 der Datei Encoder.php.

static muteErrorHandler ( )
static

Error-handler that mutes errors, alternative to shut-up operator.

Definiert in Zeile 21 der Datei Encoder.php.

static testEncodingSupportsASCII (   $encoding,
  $bypass = false 
)
static

This expensive function tests whether or not a given character encoding supports ASCII. 7/8-bit encodings like Shift_JIS will fail this test, and require special processing. Variable width encodings shouldn't ever fail.

Parameter
string$encodingEncoding name to test, as per iconv format
bool$bypassWhether or not to bypass the precompiled arrays.
Rückgabe
Array of UTF-8 characters to their corresponding ASCII, which can be used to "undo" any overzealous iconv action.

Definiert in Zeile 565 der Datei Encoder.php.

static testIconvTruncateBug ( )
static

glibc iconv has a known bug where it doesn't handle the magic //IGNORE stanza correctly. In particular, rather than ignore characters, it will return an EILSEQ after consuming some number of characters, and expect you to restart iconv as if it were an E2BIG. Old versions of PHP did not respect the errno, and returned the fragment, so as a result you would see iconv mysteriously truncating output. We can work around this by manually chopping our input into segments of about 8000 characters, as long as PHP ignores the error code. If PHP starts paying attention to the error code, iconv becomes unusable.

Rückgabe
int Error code indicating severity of bug.

Definiert in Zeile 531 der Datei Encoder.php.

Wird benutzt von convertToUTF8().

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static unichr (   $code)
static

Translates a Unicode codepoint into its corresponding UTF-8 character.

Zu beachten
Based on Feyd's function at http://forums.devnetwork.net/viewtopic.php?p=191404#191404, which is in public domain.
While we're going to do code point parsing anyway, a good optimization would be to refuse to translate code points that are non-SGML characters. However, this could lead to duplication.
This is very similar to the unichr function in maintenance/generate-entity-file.php (although this is superior, due to its sanity checks).

Definiert in Zeile 309 der Datei Encoder.php.

Wird benutzt von HTMLPurifier_AttrDef\expandCSSEscape() und HTMLPurifier_EntityParser\nonSpecialEntityCallback().

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

static unsafeIconv (   $in,
  $out,
  $text 
)
static

iconv wrapper which mutes errors, but doesn't work around bugs.

Parameter
string$inInput encoding
string$outOutput encoding
string$textThe text to convert
Rückgabe
string

Definiert in Zeile 32 der Datei Encoder.php.

Benutzt iconv().

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Dokumentation der Datenelemente

const ICONV_OK = 0

No bugs detected in iconv.

Definiert in Zeile 507 der Datei Encoder.php.

const ICONV_TRUNCATES = 1

Iconv truncates output if converting from UTF-8 to another character set with //IGNORE, and a non-encodable character is found

Definiert in Zeile 511 der Datei Encoder.php.

const ICONV_UNUSABLE = 2

Iconv does not support //IGNORE, making it unusable for transcoding purposes

Definiert in Zeile 515 der Datei Encoder.php.


Die Dokumentation für diese Klasse wurde erzeugt aufgrund der Datei:




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.