From 36e1180bbce42161a729bc68df0bd38f3f447b40 Mon Sep 17 00:00:00 2001 From: tokul Date: Sun, 25 Apr 2004 10:04:57 +0000 Subject: [PATCH 1/1] adding sq_htmlentities function git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7233 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/htmlentities/index.php | 13 ++ functions/htmlentities/iso-8859-1.php | 109 +++++++++ functions/htmlentities/readme.php | 317 ++++++++++++++++++++++++++ functions/htmlentities/utf-8.php | 275 ++++++++++++++++++++++ functions/strings.php | 80 +++++++ 5 files changed, 794 insertions(+) create mode 100644 functions/htmlentities/index.php create mode 100644 functions/htmlentities/iso-8859-1.php create mode 100644 functions/htmlentities/readme.php create mode 100644 functions/htmlentities/utf-8.php diff --git a/functions/htmlentities/index.php b/functions/htmlentities/index.php new file mode 100644 index 00000000..5963dfd6 --- /dev/null +++ b/functions/htmlentities/index.php @@ -0,0 +1,13 @@ + diff --git a/functions/htmlentities/iso-8859-1.php b/functions/htmlentities/iso-8859-1.php new file mode 100644 index 00000000..981eccb7 --- /dev/null +++ b/functions/htmlentities/iso-8859-1.php @@ -0,0 +1,109 @@ + ' ', + "\xA1" => '¡', + "\xA2" => '¢', + "\xA3" => '£', + "\xA4" => '¤', + "\xA5" => '¥', + "\xA6" => '¦', + "\xA7" => '§', + "\xA8" => '¨', + "\xA9" => '©', + "\xAA" => 'ª', + "\xAB" => '«', + "\xAC" => '¬', + "\xAD" => '­', + "\xAE" => '®', + "\xAF" => '¯', + "\xB0" => '°', + "\xB1" => '±', + "\xB2" => '²', + "\xB3" => '³', + "\xB4" => '´', + "\xB5" => 'µ', + "\xB6" => '¶', + "\xB7" => '·', + "\xB8" => '¸', + "\xB9" => '¹', + "\xBA" => 'º', + "\xBB" => '»', + "\xBC" => '¼', + "\xBD" => '½', + "\xBE" => '¾', + "\xBF" => '¿', + "\xC0" => 'À', + "\xC1" => 'Á', + "\xC2" => 'Â', + "\xC3" => 'Ã', + "\xC4" => 'Ä', + "\xC5" => 'Å', + "\xC6" => 'Æ', + "\xC7" => 'Ç', + "\xC8" => 'È', + "\xC9" => 'É', + "\xCA" => 'Ê', + "\xCB" => 'Ë', + "\xCC" => 'Ì', + "\xCD" => 'Í', + "\xCE" => 'Î', + "\xCF" => 'Ï', + "\xD0" => 'Ð', + "\xD1" => 'Ñ', + "\xD2" => 'Ò', + "\xD3" => 'Ó', + "\xD4" => 'Ô', + "\xD5" => 'Õ', + "\xD6" => 'Ö', + "\xD7" => '×', + "\xD8" => 'Ø', + "\xD9" => 'Ù', + "\xDA" => 'Ú', + "\xDB" => 'Û', + "\xDC" => 'Ü', + "\xDD" => 'Ý', + "\xDE" => 'Þ', + "\xDF" => 'ß', + "\xE0" => 'à', + "\xE1" => 'á', + "\xE2" => 'â', + "\xE3" => 'ã', + "\xE4" => 'ä', + "\xE5" => 'å', + "\xE6" => 'æ', + "\xE7" => 'ç', + "\xE8" => 'è', + "\xE9" => 'é', + "\xEA" => 'ê', + "\xEB" => 'ë', + "\xEC" => 'ì', + "\xED" => 'í', + "\xEE" => 'î', + "\xEF" => 'ï', + "\xF0" => 'ð', + "\xF1" => 'ñ', + "\xF2" => 'ò', + "\xF3" => 'ó', + "\xF4" => 'ô', + "\xF5" => 'õ', + "\xF6" => 'ö', + "\xF7" => '÷', + "\xF8" => 'ø', + "\xF9" => 'ù', + "\xFA" => 'ú', + "\xFB" => 'û', + "\xFC" => 'ü', + "\xFD" => 'ý', + "\xFE" => 'þ', + "\xFF" => 'ÿ') + ); +?> \ No newline at end of file diff --git a/functions/htmlentities/readme.php b/functions/htmlentities/readme.php new file mode 100644 index 00000000..a7abba84 --- /dev/null +++ b/functions/htmlentities/readme.php @@ -0,0 +1,317 @@ + \ No newline at end of file diff --git a/functions/htmlentities/utf-8.php b/functions/htmlentities/utf-8.php new file mode 100644 index 00000000..5d806f06 --- /dev/null +++ b/functions/htmlentities/utf-8.php @@ -0,0 +1,275 @@ + ' ', + "\xC2\xA1" => '¡', + "\xC2\xA2" => '¢', + "\xC2\xA3" => '£', + "\xC2\xA4" => '¤', + "\xC2\xA5" => '¥', + "\xC2\xA6" => '¦', + "\xC2\xA7" => '§', + "\xC2\xA8" => '¨', + "\xC2\xA9" => '©', + "\xC2\xAA" => 'ª', + "\xC2\xAB" => '«', + "\xC2\xAC" => '¬', + "\xC2\xAD" => '­', + "\xC2\xAE" => '®', + "\xC2\xAF" => '¯', + "\xC2\xB0" => '°', + "\xC2\xB1" => '±', + "\xC2\xB2" => '²', + "\xC2\xB3" => '³', + "\xC2\xB4" => '´', + "\xC2\xB5" => 'µ', + "\xC2\xB6" => '¶', + "\xC2\xB7" => '·', + "\xC2\xB8" => '¸', + "\xC2\xB9" => '¹', + "\xC2\xBA" => 'º', + "\xC2\xBB" => '»', + "\xC2\xBC" => '¼', + "\xC2\xBD" => '½', + "\xC2\xBE" => '¾', + "\xC2\xBF" => '¿', + "\xC3\x80" => 'À', + "\xC3\x81" => 'Á', + "\xC3\x82" => 'Â', + "\xC3\x83" => 'Ã', + "\xC3\x84" => 'Ä', + "\xC3\x85" => 'Å', + "\xC3\x86" => 'Æ', + "\xC3\x87" => 'Ç', + "\xC3\x88" => 'È', + "\xC3\x89" => 'É', + "\xC3\x8A" => 'Ê', + "\xC3\x8B" => 'Ë', + "\xC3\x8C" => 'Ì', + "\xC3\x8D" => 'Í', + "\xC3\x8E" => 'Î', + "\xC3\x8F" => 'Ï', + "\xC3\x90" => 'Ð', + "\xC3\x91" => 'Ñ', + "\xC3\x92" => 'Ò', + "\xC3\x93" => 'Ó', + "\xC3\x94" => 'Ô', + "\xC3\x95" => 'Õ', + "\xC3\x96" => 'Ö', + "\xC3\x97" => '×', + "\xC3\x98" => 'Ø', + "\xC3\x99" => 'Ù', + "\xC3\x9A" => 'Ú', + "\xC3\x9B" => 'Û', + "\xC3\x9C" => 'Ü', + "\xC3\x9D" => 'Ý', + "\xC3\x9E" => 'Þ', + "\xC3\x9F" => 'ß', + "\xC3\xA0" => 'à', + "\xC3\xA1" => 'á', + "\xC3\xA2" => 'â', + "\xC3\xA3" => 'ã', + "\xC3\xA4" => 'ä', + "\xC3\xA5" => 'å', + "\xC3\xA6" => 'æ', + "\xC3\xA7" => 'ç', + "\xC3\xA8" => 'è', + "\xC3\xA9" => 'é', + "\xC3\xAA" => 'ê', + "\xC3\xAB" => 'ë', + "\xC3\xAC" => 'ì', + "\xC3\xAD" => 'í', + "\xC3\xAE" => 'î', + "\xC3\xAF" => 'ï', + "\xC3\xB0" => 'ð', + "\xC3\xB1" => 'ñ', + "\xC3\xB2" => 'ò', + "\xC3\xB3" => 'ó', + "\xC3\xB4" => 'ô', + "\xC3\xB5" => 'õ', + "\xC3\xB6" => 'ö', + "\xC3\xB7" => '÷', + "\xC3\xB8" => 'ø', + "\xC3\xB9" => 'ù', + "\xC3\xBA" => 'ú', + "\xC3\xBB" => 'û', + "\xC3\xBC" => 'ü', + "\xC3\xBD" => 'ý', + "\xC3\xBE" => 'þ', + "\xC3\xBF" => 'ÿ', + // Latin Extended-A + "\xC5\x92" => 'Œ', + "\xC5\x93" => 'œ', + "\xC5\xA0" => 'Š', + "\xC5\xA1" => 'š', + "\xC5\xB8" => 'Ÿ', + // Spacing Modifier Letters + "\xCB\x86" => 'ˆ', + "\xCB\x9C" => '˜', + // General Punctuation + "\xE2\x80\x82" => ' ', + "\xE2\x80\x83" => ' ', + "\xE2\x80\x89" => ' ', + "\xE2\x80\x8C" => '‌', + "\xE2\x80\x8D" => '‍', + "\xE2\x80\x8E" => '‎', + "\xE2\x80\x8F" => '‏', + "\xE2\x80\x93" => '–', + "\xE2\x80\x94" => '—', + "\xE2\x80\x98" => '‘', + "\xE2\x80\x99" => '’', + "\xE2\x80\x9A" => '‚', + "\xE2\x80\x9C" => '“', + "\xE2\x80\x9D" => '”', + "\xE2\x80\x9E" => '„', + "\xE2\x80\xA0" => '†', + "\xE2\x80\xA1" => '‡', + "\xE2\x80\xB0" => '‰', + "\xE2\x80\xB9" => '‹', + "\xE2\x80\xBA" => '›', + "\xE2\x82\xAC" => '€', + // Latin Extended-B + "\xC6\x92" => 'ƒ', + // Greek + "\xCE\x91" => 'Α', + "\xCE\x92" => 'Β', + "\xCE\x93" => 'Γ', + "\xCE\x94" => 'Δ', + "\xCE\x95" => 'Ε', + "\xCE\x96" => 'Ζ', + "\xCE\x97" => 'Η', + "\xCE\x98" => 'Θ', + "\xCE\x99" => 'Ι', + "\xCE\x9A" => 'Κ', + "\xCE\x9B" => 'Λ', + "\xCE\x9C" => 'Μ', + "\xCE\x9D" => 'Ν', + "\xCE\x9E" => 'Ξ', + "\xCE\x9F" => 'Ο', + "\xCE\xA0" => 'Π', + "\xCE\xA1" => 'Ρ', + "\xCE\xA3" => 'Σ', + "\xCE\xA4" => 'Τ', + "\xCE\xA5" => 'Υ', + "\xCE\xA6" => 'Φ', + "\xCE\xA7" => 'Χ', + "\xCE\xA8" => 'Ψ', + "\xCE\xA9" => 'Ω', + "\xCE\xB1" => 'α', + "\xCE\xB2" => 'β', + "\xCE\xB3" => 'γ', + "\xCE\xB4" => 'δ', + "\xCE\xB5" => 'ε', + "\xCE\xB6" => 'ζ', + "\xCE\xB7" => 'η', + "\xCE\xB8" => 'θ', + "\xCE\xB9" => 'ι', + "\xCE\xBA" => 'κ', + "\xCE\xBB" => 'λ', + "\xCE\xBC" => 'μ', + "\xCE\xBD" => 'ν', + "\xCE\xBE" => 'ξ', + "\xCE\xBF" => 'ο', + "\xCF\x80" => 'π', + "\xCF\x81" => 'ρ', + "\xCF\x82" => 'ς', + "\xCF\x83" => 'σ', + "\xCF\x84" => 'τ', + "\xCF\x85" => 'υ', + "\xCF\x86" => 'φ', + "\xCF\x87" => 'χ', + "\xCF\x88" => 'ψ', + "\xCF\x89" => 'ω', + "\xCF\x91" => 'ϑ', + "\xCF\x92" => 'ϒ', + "\xCF\x96" => 'ϖ', + // General Punctuation + "\xE2\x80\xA2" => '•', + "\xE2\x80\xA6" => '…', + "\xE2\x80\xB2" => '′', + "\xE2\x80\xB3" => '″', + "\xE2\x80\xBE" => '‾', + "\xE2\x81\x84" => '⁄', + // Letterlike Symbols + "\xE2\x84\x98" => '℘', + "\xE2\x84\x91" => 'ℑ', + "\xE2\x84\x9C" => 'ℜ', + "\xE2\x84\xA2" => '™', + "\xE2\x84\xB5" => 'ℵ', + // Arrows + "\xE2\x86\x90" => '←', + "\xE2\x86\x91" => '↑', + "\xE2\x86\x92" => '→', + "\xE2\x86\x93" => '↓', + "\xE2\x86\x94" => '↔', + "\xE2\x86\xB5" => '↵', + "\xE2\x87\x90" => '⇐', + "\xE2\x87\x91" => '⇑', + "\xE2\x87\x92" => '⇒', + "\xE2\x87\x93" => '⇓', + "\xE2\x87\x94" => '⇔', + // Mathematical Operators + "\xE2\x88\x80" => '∀', + "\xE2\x88\x82" => '∂', + "\xE2\x88\x83" => '∃', + "\xE2\x88\x85" => '∅', + "\xE2\x88\x87" => '∇', + "\xE2\x88\x88" => '∈', + "\xE2\x88\x89" => '∉', + "\xE2\x88\x8B" => '∋', + "\xE2\x88\x8F" => '∏', + "\xE2\x88\x91" => '∑', + "\xE2\x88\x92" => '−', + "\xE2\x88\x97" => '∗', + "\xE2\x88\x9A" => '√', + "\xE2\x88\x9D" => '∝', + "\xE2\x88\x9E" => '∞', + "\xE2\x88\xA0" => '∠', + "\xE2\x88\xA7" => '∧', + "\xE2\x88\xA8" => '∨', + "\xE2\x88\xA9" => '∩', + "\xE2\x88\xAA" => '∪', + "\xE2\x88\xAB" => '∫', + "\xE2\x88\xB4" => '∴', + "\xE2\x88\xBC" => '∼', + "\xE2\x89\x85" => '≅', + "\xE2\x89\x88" => '≈', + "\xE2\x89\xA0" => '≠', + "\xE2\x89\xA1" => '≡', + "\xE2\x89\xA4" => '≤', + "\xE2\x89\xA5" => '≥', + "\xE2\x8A\x82" => '⊂', + "\xE2\x8A\x83" => '⊃', + "\xE2\x8A\x84" => '⊄', + "\xE2\x8A\x86" => '⊆', + "\xE2\x8A\x87" => '⊇', + "\xE2\x8A\x95" => '⊕', + "\xE2\x8A\x97" => '⊗', + "\xE2\x8A\xA5" => '⊥', + "\xE2\x8B\x85" => '⋅', + // Miscellaneous Technical + "\xE2\x8C\x88" => '⌈', + "\xE2\x8C\x89" => '⌉', + "\xE2\x8C\x8A" => '⌊', + "\xE2\x8C\x8B" => '⌋', + "\xE2\x8C\xA9" => '⟨', + "\xE2\x8C\xAA" => '⟩', + // Geometric Shapes + "\xE2\x97\x8A" => '◊', + // Miscellaneous Symbols + "\xE2\x99\xA0" => '♠', + "\xE2\x99\xA3" => '♣', + "\xE2\x99\xA5" => '♥', + "\xE2\x99\xA6" => '♦' + ) + ); +?> \ No newline at end of file diff --git a/functions/strings.php b/functions/strings.php index 157656a4..b2758608 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -576,5 +576,85 @@ function sq_fwrite($fp, $string) { return $count; } +/** + * sq_get_html_translation_table + * + * Returns the translation table used by sq_htmlentities() + * + * @param integer $table html translation table. Possible values (without quotes): + * HTML_ENTITIES - full html entities table defined by charset + * HTML_SPECIALCHARS - html special characters table + * @param integer $quote_style quote encoding style. Possible values (without quotes): + * ENT_COMPAT - (default) encode double quotes + * ENT_NOQUOTES - don't encode double or single quotes + * ENT_QUOTES - encode double and single quotes + * @param string $charset charset used for encoding. default to us-ascii, 'auto' uses $default_charset global value. + * @return array html translation array + */ +function sq_get_html_translation_table($table,$quote_style=ENT_COMPAT,$charset='us-ascii') { + global $default_charset; + + if ($table == HTML_SPECIALCHARS) $charset='us-ascii'; + + // Start array with ampersand + $sq_html_ent_table = array( "&" => '&' ); + + // < and > + $sq_html_ent_table = array_merge($sq_html_ent_table, + array("<" => '<', + ">" => '>') + ); + // double quotes + if ($quote_style == ENT_COMPAT) + $sq_html_ent_table = array_merge($sq_html_ent_table, + array("\"" => '"') + ); + + // double and single quotes + if ($quote_style == ENT_QUOTES) + $sq_html_ent_table = array_merge($sq_html_ent_table, + array("\"" => '"', + "'" => ''') + ); + + if ($charset=='auto') $charset=$default_charset; + + // add entities that depend on charset + switch($charset){ + case 'iso-8859-1': + include_once(SM_PATH . 'functions/htmlentities/iso-8859-1.php'); + break; + case 'utf-8': + include_once(SM_PATH . 'functions/htmlentities/utf-8.php'); + break; + case 'us-ascii': + default: + break; + } + // return table + return $sq_html_ent_table; +} + +/** + * sq_htmlentities + * + * Convert all applicable characters to HTML entities. + * Minimal php requirement - v.4.0.5 + * + * @param string $string string that has to be sanitized + * @param integer $quote_style quote encoding style. Possible values (without quotes): + * ENT_COMPAT - (default) encode double quotes + * ENT_NOQUOTES - don't encode double or single quotes + * ENT_QUOTES - encode double and single quotes + * @param string $charset charset used for encoding. defaults to 'us-ascii', 'auto' uses $default_charset global value. + * @return string sanitized string + */ +function sq_htmlentities($string,$quote_style=ENT_COMPAT,$charset='us-ascii') { + // get translation table + $sq_html_ent_table=sq_get_html_translation_table(HTML_ENTITIES,$quote_style,$charset); + // convert characters + return str_replace(array_keys($sq_html_ent_table),array_values($sq_html_ent_table),$string); +} + $PHP_SELF = php_self(); ?> \ No newline at end of file -- 2.25.1