Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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', '<a href="$1">$3</a>', $return);
- $return = preg_replace('#\[lien=(http://(.+))\\]#isU', '<a href="$1">$1</a>', $return);
- $return = preg_replace('#\[p=(center|left|right|justify)\](.+)\[/p\]#isU', '<p class="$1">$2</p>', $return);
- $return = preg_replace('#\*\*(.+)\*\*#isU', '<span class="gras">$1</span>', $return);
- $return = preg_replace('#\-\-(.+)\-\-#isU', '<span class="surligne">$1</span>', $return);
- $return = preg_replace('#\_\_(.+)\_\_#isU', '<span class="souligneDessous">$1</span>', $return);
- $return = preg_replace('#\`\`(.+)\`\`#isU', '<span class="souligneDessus">$1</span>', $return);
- $return = preg_replace('#\,\,(.+)\,\,#isU', '<span class="petitesMajuscules">$1</span>', $return);
- // $return = preg_replace('#\/\/(.+)\/\/#isU', '<span class="italique">$1</span>', $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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement