Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function htmlentitiesutf8($str){
- return htmlentities($str, ENT_QUOTES, 'UTF-8'); // 'UTF-8' einfach in 'ISO-8859-1' ändern, wenn du kein UTF-8 nutzt
- }
- function bbcode_img($action, $attributes, $content, $params, &$node_object){
- if($action == 'validate'){
- if(preg_match('@^https?://.+(jpg|jpeg|png|gif)$@i', $content)){
- return true;
- }
- return false;
- }elseif($action == 'output'){
- return '<img src="'.htmlentitiesutf8($content).'" alt="Bild" />';
- }
- }
- function bbcode_code($action, $attributes, $content, $params, &$node_object){
- if($action == 'validate'){
- return true;
- }elseif($action == 'output'){
- $lang = "";
- if(isset($attributes['default'])){
- $lang = strtolower($attributes['default']);
- //überprüfen ob syntaxhiglight für die sprache existiert
- //hier erlaube ich nur php, sollte ausgebaut werden, wenn nötig
- if($lang != "php"){
- $lang = "";
- }
- }
- $content = trim($content, "\r\n");
- if($lang == ""){
- $codetype = 'Code';
- $content = htmlentitiesutf8($content);
- }elseif($lang == 'php'){
- $codetype = 'PHP-Code';
- $content = highlight_string($content, true);
- }
- return '<div style="width:400px; padding:5px; border:1px solid #AAAAAA; white-space:pre; font-family:monospace;">'
- .'<div style="font-weight:bold; font-family:sans-serif; font-size:12px;">'.$codetype.'</div>'
- .$content.'</div>';
- }
- }
- function bbcode_url($action, $attributes, $content, $params, &$node_object){
- if($action == 'validate'){
- if(isset($attributes['default'])){
- $url = $attributes['default'];
- }else{
- $url = $content;
- }
- if(preg_match('@^(https?|ftp|irc|blubb)://[a-z0-9_\-\.]+(/.*)?$@i', $url)){
- return true;
- }
- return false;
- }elseif($action == 'output'){
- if(isset($attributes['default'])){
- $url = $attributes['default'];
- return '<a href="'.htmlentitiesutf8($url).'">'.$content.'</a>';
- }else{
- return '<a href="'.$content.'">'.$content.'</a>';
- }
- }
- }
- function bbcode_color($action, $attributes, $content, $params, &$node_object){
- global $color_names;
- if($action == 'validate'){
- return true;
- }elseif($action == 'output'){
- $textcol = "";
- $bgcol = "";
- if(isset($attributes['default'])){
- $textcol = $attributes['default'];
- }else{
- if(isset($attributes['text'])){
- $textcol = $attributes['text'];
- }
- if(isset($attributes['bg'])){
- $bgcol = $attributes['bg'];
- }
- }
- if($textcol != ""){
- if(preg_match('/^#[a-fA-F0-9]{6}$/', $textcol)){
- $textcol = strtoupper($textcol);
- }elseif(preg_match('/^#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/', $textcol, $ret)){
- $textcol = strtoupper('#'.$ret[1].$ret[1].$ret[2].$ret[2].$ret[3].$ret[3]);
- }elseif(isset($color_names[strtolower($textcol)])){
- $textcol = $color_names[$textcol];
- }else{
- $textcol = "";
- }
- }
- if($bgcol != ""){
- if(preg_match('/^#[a-fA-F0-9]{6}$/', $bgcol)){
- $bgcol = strtoupper($bgcol);
- }elseif(preg_match('/^#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/', $bgcol, $ret)){
- $bgcol = strtoupper('#'.$ret[1].$ret[1].$ret[2].$ret[2].$ret[3].$ret[3]);
- }elseif(isset($color_names[strtolower($bgcol)])){
- $bgcol = $color_names[$bgcol];
- }else{
- $bgcol = "";
- }
- }
- if($textcol != "" && $bgcol != ""){
- return '<span style="color:'.$textcol.'; background-color:'.$bgcol.';">'.$content.'</span>';
- }elseif($textcol != ""){
- return '<span style="color:'.$textcol.'; background-color:none;">'.$content.'</span>';
- }elseif($bgcol != ""){
- return '<span style="color:none; background-color:'.$bgcol.';">'.$content.'</span>';
- }else{
- return '<span style="color:none; background-color:none;">'.$content.'</span>';
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement