class Html { /* * Permet de générer facilement de l'HTML * * @auteur PifyZ * @version 1.0 20/02/2012 */ private $html = ''; private $inline = array('br', 'hr', 'img', 'input'); private $balisesOuverte = array(); public function __construct() { /* Vide */ } public function __call($balise, $attributs) { $attributs = implode('|', $attributs); $attributs = explode('|', $attributs); $return = '<' . $balise; foreach ($attributs AS $attribut) : $pregMatch1 = '#(.[^:]+):(.+)#'; $pregReplace1 = ' $1="$2"'; $pregMatch2 = '#texte:(.+)#'; $pregReplace2 = '$1'; if (preg_match($pregMatch1, $attribut) AND !preg_match($pregMatch2, $attribut)) : $return .= preg_replace($pregMatch1, $pregReplace1, $attribut); endif; $texte = (preg_match($pregMatch2, $attribut)) ? preg_replace($pregMatch2, $pregReplace2, $attribut) : ''; endforeach; if (in_array($balise, $this->inline)) : $return .= ' />'; else : $this->balisesOuverte[] = $balise; $return .= '>' . $texte; endif; $this->html .= $return; return $this; } public function texte($texte) { $this->html .= $texte; return $this; } public function BBCode($texte) { $return = $texte; $return = preg_replace_callback('#\[\[\=\=(.+)\=\=\]\]#isU', array($this, 'protection'), $return); $return = preg_replace('#\[lien=(http://(.+))\|(.+)\]#isU', '$3', $return); $return = preg_replace('#\[lien=(http://(.+))\\]#isU', '$1', $return); $return = preg_replace('#\[p=(center|left|right|justify)\](.+)\[/p\]#isU', '
$2
', $return); $return = preg_replace('#\*\*(.+)\*\*#isU', '$1', $return); $return = preg_replace('#\-\-(.+)\-\-#isU', '$1', $return); $return = preg_replace('#\_\_(.+)\_\_#isU', '$1', $return); $return = preg_replace('#\`\`(.+)\`\`#isU', '$1', $return); $return = preg_replace('#\,\,(.+)\,\,#isU', '$1', $return); // $return = preg_replace('#\/\/(.+)\/\/#isU', '$1', $return); $this->html .= $return; return $this; } private function protection($captures) { $return = nl2br(htmlentities($captures[1])); return $return; } public function fin() { $this->html .= '' . array_pop($this->balisesOuverte) . '>'; return $this; } public function debug() { var_dump($this->html); var_dump($this->balisesOuverte); } public function __toString() { return $this->html; } }