static function cleanPostForTextArea($value) { if (is_array($value)) { return array_map(array(__CLASS__, __METHOD__), $value); } $order = array('\\r\\n', '\\n', "\\'", '\\"', '\\\\'); $replace = array("\n", "\n", "'", '"', "\\"); return str_replace($order, $replace, $value); }
/** * Construit le code HTML pour un champ de saisie texte libre en textarea * * @param integer/string $id * id de la règle dont fait partie le champ (integer ou tag de nouvel id) * @param string $param * nom du paramètre à afficher (champ name du select) * @param array $desc * description du paramètre à afficher * @param string $values * valeur à utiliser pour préremplir le champ (doit être html-échappée) * @param boolean $can_write * vrai ssi on doit afficher un menu sélectionnable, sinon on affiche juste le texte. * @return string code html à afficher */ private static final function makeTextArea($id, $param, $desc, $value, $can_write) { $result = ''; $rows = isset($desc['rows']) ? $desc['rows'] : 5; $cols = isset($desc['cols']) ? $desc['cols'] : 50; $resize = isset($desc['resize']) ? $desc['resize'] : 'both'; $maxlength = $desc['maxlength']; if ($can_write) { $result .= '<textarea name="rules[' . $id . '][' . $param . ']" rows="' . $rows . '" cols="' . $cols . '" style="resize:' . $resize . '" maxlength="' . $maxlength . '">' . Html::cleanPostForTextArea($value) . '</textarea>'; } else { $result .= nl2br($value); } return $result; }