forked from 4ducky/4ducky
mirror
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
class SimpleBBCode {
|
||||
|
||||
protected $bbcodes = array();
|
||||
|
||||
public function __construct() {
|
||||
|
||||
//standard bbcodes hinzufügen
|
||||
$this->assign('\[b\](.*)\[/b\]', '<strong>$1</strong>');
|
||||
$this->assign('\[i\](.*)\[/i\]', '<em>$1</em>');
|
||||
$this->assign('\[u\](.*)\[/u\]', '<u>$1</u>');
|
||||
$this->assign('\[quote\](?s)(.*)\[/quote\]', '<span class="quote">$1</span>');
|
||||
$this->assign('\[img\](.*)\[/img\]', '"<a href=\"" . htmlentities(\'\\1\', ENT_COMPAT) . "\" rel=\"lightbox[more]\" target=\"_blank\"><img onError=\"this.src=\'/media/dolan404.jpg\';\" src=\"" . htmlentities(\'\\1\', ENT_COMPAT) . "\" border=\"0\" class=\"imgbbcode\"></a>"', 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\]', '<span class="Spoiler">$1</span>');
|
||||
}
|
||||
|
||||
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 "<a href=\"javascript:;\" id=\"YTbutton\" onclick=\"toggle('YT" . $watch . "')\">[youtube]</a><iframe id=\"YT" . $watch . "\" width=\"425\" style=\"display:none;\" height=\"344\" src=\"http://www.youtube.com/embed/".$watch."\" frameborder=\"0\" allowfullscreen></iframe>";
|
||||
}
|
||||
|
||||
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 "<a href=\"javascript:;\" id=\"Pornbutton\" onclick=\"toggle('Porn" . $watch . "')\">[xxx]</a><iframe id=\"Porn" .$watch. "\" width=\"425\" height=\"344\" style=\"display:none;\" src=\"".$source.$watch."\" frameborder=\"0\"></iframe>";
|
||||
}
|
||||
|
||||
protected function handleLinkBBcode($text) {
|
||||
if (!empty($text)){
|
||||
if (preg_match("/is.gd/i", $text)) {
|
||||
$text = preg_replace('#(?<!\w)((http://)|(www\.))([^\s<>]+)#i', "<a target=\"_blank\" href=\"http://$3$4\">$text</a>",$text);
|
||||
return($text);
|
||||
}
|
||||
else {
|
||||
$link = $text;
|
||||
$text = preg_replace('#(?<!\w)((http://)|(www\.))([^\s<>]+)#i', "<a target=\"_blank\" href=\"http://$3$4\">$link</a>",$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;
|
||||
}*/
|
||||
?>
|
||||
Reference in New Issue
Block a user