refine purify definition to allow for anchor tags

This commit is contained in:
Klaus Leithoff 2009-11-24 08:21:03 +00:00
parent 37c3e480b4
commit 00dc88fbf6

View File

@ -1267,9 +1267,36 @@ class html
{ {
$config = HTMLPurifier_Config::createDefault(); $config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', self::$charset); $config->set('Core', 'Encoding', self::$charset);
// maybe the two following lines are useful for caching???
$config->set('HTML','DefinitionID', 'egroupware');
$config->set('HTML','DefinitionRev', 1);
// doctype and tidylevel
$config->set('HTML','Doctype', 'XHTML 1.0 Transitional');
$config->set('HTML','TidyLevel', 'light');
// EnableID is needed for anchor tags
$config->set('Attr','EnableID',true);
// actual allowed tags and attributes
$config->set('HTML', 'Allowed', 'br,p[align],b,i,u,s,em,pre,tt,strong,strike,center,div[align],hr[class|style],'.
'ul[type],ol[type|start],li,'.
'h1,h2,h3,'.
'span[class|style],'.
'table[class|border|cellpadding|cellspacing|width|style|align|bgcolor|align],'.
'tbody,thead,tfoot,colgroup,'.
'col[width|span],'.
'blockquote[class|cite|dir],'.
'tr[class|style|align|bgcolor|align|valign],'.
'td[class|colspan|rowspan|width|style|align|bgcolor|align|valign|nowrap],'.
'th[class|colspan|rowspan|width|style|align|bgcolor|align|valign|nowrap],'.
'a[href|target|name|title],img[src|alt|title]');
$config->set('Cache', 'SerializerPath', $GLOBALS['egw_info']['server']['temp_dir']); $config->set('Cache', 'SerializerPath', $GLOBALS['egw_info']['server']['temp_dir']);
} }
$purifier = new HTMLPurifier($config); $purifier = new HTMLPurifier($config);
// the latter may enable you to modify the config later on, but by now
// the effort for e.g. enabling anchor tags is already included above
//$def =& $purifier->config->getHTMLDefinition(true);
//$def->addAttribute('a', 'name', 'Text');
} }
return $purifier->purify( $html ); return $purifier->purify( $html );
} }