1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <?php
// --------------------------------------------------------------
// FONCTION : PROTECTION contre les failles XSS dans le html des TEXTAREA (EDITEUR WYSIWYG)
// --------------------------------------------------------------
function formatage_from_textarea( $chaine )
{
// -----------------
// remplacement : -> espaces / passages à la ligne (CKeditor)
$chaine = str_replace(array(' ', '\r\n ', '\r\n ', '\r\n'), array(' ', '', '', ''), $chaine);
// remplacement : CHEMIN RELATIF -> CHEMIN ABSOLU
$chaine = str_replace('="/', '="'.SITE_URL_HTTP, $chaine);
// -----------------
$chaine = html_entity_decode($chaine, ENT_QUOTES, 'UTF-8'); // Convertit les entités HTML spéciales en caractères
// -----------------
// balises qui seront conservees
// (ajoutez ou supprimez des balises a votre convenance)
$allowable_tags = '<abbr><acronym><a><b><br><blockquote><cite><code><dl><dt><dd>';
$allowable_tags .= '<em><i><b><strong><small><pre><u><ul><ol><li><s><sup><sub><ins>';
$allowable_tags .= '<div><img><h1><h2><h3><h4><h5><h6><hr><p><span>'; // titres
$allowable_tags .= '<table><caption><legend><thead><tfoot><tbody><tr><th><td><colgroup><col>'; // tableau
$allowable_tags .= '<audio><video><object><param><embed>'; // audio/video
$allowable_tags .= '<form><fieldset><input><select><label><button>'; // formulaire
// -----------------
// SPECIAL ADMIN : on autorise les iframe,...
if ( strpos(' '.$_SERVER['REQUEST_URI'],'/'.REP_ADMIN) ) // ADMIN UNIQUEMENT
{
$allowable_tags .= '<iframe>'; // iframe
}
// -----------------
$chaine = strip_tags($chaine, $allowable_tags);
// -----------------
return $chaine;
}; |
Partager