2 require_once('common/include/Error.class');
5 class HTMLSupport extends Error {
7 var $allowed_html_tags = array();
9 // must be called after HTML was initialized
10 function HTMLSupport(){
14 /* Replace allowed tags back to original
17 function replaceallowed($text) {
18 $allowed = array ("<b>" => "<b>","</b>" => "</b>","<i>" => "<i>","</i>" => "</i>","<u>" => "<u>","</u>" => "</u>",
19 "<ul>" => "<ul>","</ul>" => "</ul>","<li>" => "<li>","</li>" => "</li>",
20 "<ol>" => "<ol>","</ol>" => "</ol>");
21 //for img tag it isn´t as simple as a conversion table
22 preg_match_all('/<img src=.*>/', $text, $matches);
23 foreach ($matches[0] as $one) {
24 $one = html_entity_decode($one,ENT_QUOTES);
25 $one = stripslashes($one);
26 $text = preg_replace('/(<img src=)(.*)(>)/',$one,$text,1);
31 return (strtr($text,$allowed));
34 function prepareText($text, $strip_html) {
36 $trans_tbl = get_html_translation_table (HTML_ENTITIES,ENT_QUOTES); // more restrictive
38 $trans_tbl = get_html_translation_table (HTML_SPECIALCHARS); // translate all
41 // MS Word strangeness..
42 // smart single/ double quotes:
43 $trans_tbl[chr(145)] = '\'';
44 $trans_tbl[chr(146)] = '\'';
45 $trans_tbl[chr(147)] = '&';
46 $trans_tbl[chr(148)] = '&';
48 $trans_tbl[chr(142)] = 'è';
50 $text = strtr ($text, $trans_tbl);
51 //re-replace the allowed tags
53 $text = $this->replaceallowed($text);