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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| class Bbcode {
var $urls = array(
'url' => '/(http:\/\/)?(www.)?((([a-zA-Z0-9-]){2,}\.){1,4}([a-zA-Z]){2,6}(\/([a-zA-Z-_\/\.0-9#:?=&;,]*)?)?)/',
'urls' => '/(https:\/\/)(\[ZzZ\])((([a-zA-Z0-9-]){2,}\.){1,4}([a-zA-Z]){2,6}(\/([a-zA-Z-_\/\.0-9#:?=&;,]*)?)?)/'
);
var $bburls = array(
'url' => '[ZzZ]\\2\\3[/ZzZ]',
'urls' => '[ZzZs]\\3'
);
var $bbcodes = array(
'b' => '/(\[[Bb]\])(.+?)(\[\/[Bb]\])/',
'i' => '/(\[[Ii]\])(.+?)(\[\/[Ii]\])/',
'u' => '/(\[[Uu]\])(.+?)(\[\/[Uu]\])/',
's' => '/(\[[Ss]\])(.+?)(\[\/[Ss]\])/',
'size' => '/(\[size=)(.+?)(\])(.+?)(\[\/size\])/',
'color' => '/(\[color=)(.+?)(\])(.+?)(\[\/color\])/',
'link' => '/(\[ZzZ\])(.+?)(\[\/ZzZ\])/',
'links' => '/(\[ZzZs\])(.+?)(\[\/ZzZ\])/',
'url' => '/(\[url\])(.+?)(\[\/url\])/',
'url2' => '/(\[url=)(<a href=")(.+?)(" target="_blank">)(.+?)(<\/a>)(\])(.+?)(\[\/url\])/',
'wink' => '/(;\))/',
'cry' => '/(:\'\()/',
'happy' => '/(:\))/',
'sad' => '/(:\()/',
'tong' => '/(:p)/',
'lol' => '/(:lol:)/',
'grin' => '/(:D)/',
'toto' => '/(t|T)(oto|OTO)/'
);
var $htmlcodes = array(
'b' => '<b>\\2</b>',
'i' => '<i>\\2</i>',
'u' => '<u>\\2</u>',
's' => '<strike>\\2</strike>',
'size' => '<font size="\\2">\\4</font>',
'color' => '<font color="\\2">\\4</font>',
'link' => '<a href="http://\\2" target="_blank">\\2</a>',
'links' => '<a href="https://\\2" target="_blank">\\2</a>',
'url' => '\\2',
'url2' => '<a href="\\3" target="_blank">\\8</a>',
'wink' => '<img src="/img/emoticons/wink.gif" title="wink">',
'cry' => '<img src="/img/emoticons/cry.png" title="cry">',
'happy' => '<img src="/img/emoticons/happy.gif" title="happy">',
'sad' => '<img src="/img/emoticons/sad.png" title="sad">',
'tongue' => '<img src="/img/emoticons/tongue.gif" title="tongue">',
'lol' => '<img src="/img/emoticons/giggle.gif" title="giggle">',
'grin' => '<img src="/img/emoticons/grin.gif" title="grin">',
'toto' => '<a href="https://www.toto.fr/voir-toto" target="_blank">Toto</a>'
);
function parse($text) {
// j'isole les urls en leur donnant un bbcode temporaire du type [ZzZ][/ZzZ]
$text = preg_replace($this->urls, $this->bburls, $text);
$pattern = '/(\[ZzZ)(.+?)(\[\/ZzZ\])/';
preg_match_all($pattern, $text, $hyperlink);
$pattern ='toto';
if ($hyperlink[0]) {
$new_url = $hyperlink[1][0].preg_replace($pattern, '[tata]', $hyperlink[2][0]).$hyperlink[3][0];
$text = str_replace($hyperlink[0][0], $new_url, $text);
}
// bbcodes conversion
$text = preg_replace($this->bbcodes, $this->htmlcodes, $text);
// on remet toto à la place de [tata]
$pattern = '/(\[tata\])/';
$text = preg_replace($pattern, $sponsor, $text);
return $this->output($text);
}
} |
Partager