assign('\[b\](.*)\[/b\]', '$1');
$this->assign('\[i\](.*)\[/i\]', '$1');
$this->assign('\[u\](.*)\[/u\]', '$1');
$this->assign('\[quote\](?s)(.*)\[/quote\]', '$1');
$this->assign('\[img\](.*)\[/img\]', '"
"', true);
$this->assign('\[youtube\](.*)\[/youtube\]', '$this->handleYoutubeBBcode(\'\\1\')', true);
$this->assign('\[xxx\](.*)\[/xxx\]', '$this->handlePornBBcode(\'\\1\')', true);
$this->assign('\[link\](.*)\[/link\]', '$this->handleLinkBBcode(\'\\1\')', true);
$this->assign('\[spoiler\](?s)(.*)\[/spoiler\]', '$1');
}
public function parse($content) {
if(!count($this->bbcodes)) return $content;
foreach($this->bbcodes as $bbcode) {
while(preg_match('~' . $bbcode['find'] . '~U', $content)) {
if(isset($bbcode['eval']))
$content = preg_replace('~' . $bbcode['find'] . '~Ue', $bbcode['eval'], $content);
else $content = preg_replace('~' . $bbcode['find'] . '~U', $bbcode['replace'], $content);
}
}
return $content;
}
public function assign($find, $replace, $eval = false) {
$pattern = array('find' => $find);
$pattern[(($eval === true) ? 'eval' : 'replace')] = $replace;
$this->bbcodes[] = $pattern;
}
protected function handleYoutubeBBcode($url) {
if(preg_match("/youtube/i",$url)) {
$stack = array();
preg_match('/v=([A-z0-9=\-]+?)(&.*)?$/i', $url, $stack);
if(empty($stack[1])) return '';
$watch = $stack[1]; //\w kann nur a-zA-Z0-9_. sein, kein risiko
} else {
$watch = preg_replace('~\W+~', '', $url);
if(empty($watch)) return '';
}
return "[youtube]";
}
protected function handlePornBBcode($url) {
if(preg_match("/xvideo/i",$url)) {
$source = "http://flashservice.xvideos.com/embedframe/";
preg_match_all("/.*?(\d+)/is", $url, $matches);
$watch=$matches[1][0];
}
/*else if(preg_match("/pornhub/i",$url)){
$source = "http://www.pornhub.com/embed/";
preg_match_all("/.*?(\d+)/is", $url, $matches);
$watch=$matches[1][0];
}*/
else{
if(empty($watch)) return '';
}
return "[xxx]";
}
protected function handleLinkBBcode($text) {
if (!empty($text)){
if (preg_match("/is.gd/i", $text)) {
$text = preg_replace('#(?]+)#i', "$text",$text);
return($text);
}
else {
$link = $text;
$text = preg_replace('#(?]+)#i', "$link",$text);
return($text);
}
}
else{
return("Link-Fail");
}
}
}
/*
function short($url){
$res = "";
$handle = @fopen("http://is.gd/api.php?longurl=".urlencode($url), "rb");
if($handle){
while (!feof($handle)) {
$res .= fgets($handle,2000);
}
fclose($handle);
}
else{
throw new Exception("Link kann nicht gekürzt werden!");
}
return $res;
}*/
?>