Advertisement
Guest User

Balmung

a guest
Oct 12th, 2008
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.69 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function htmlentitiesutf8($str){
  5.     return htmlentities($str, ENT_QUOTES, 'UTF-8'); // 'UTF-8' einfach in 'ISO-8859-1' ändern, wenn du kein UTF-8 nutzt
  6. }
  7.  
  8. function bbcode_img($action, $attributes, $content, $params, &$node_object){
  9.     if($action == 'validate'){
  10.         if(preg_match('@^https?://.+(jpg|jpeg|png|gif)$@i', $content)){
  11.             return true;
  12.         }
  13.         return false;
  14.     }elseif($action == 'output'){
  15.         return '<img src="'.htmlentitiesutf8($content).'" alt="Bild" />';
  16.     }
  17. }
  18.  
  19. function bbcode_code($action, $attributes, $content, $params, &$node_object){
  20.     if($action == 'validate'){
  21.         return true;
  22.     }elseif($action == 'output'){
  23.         $lang = "";
  24.         if(isset($attributes['default'])){
  25.             $lang = strtolower($attributes['default']);
  26.            
  27.             //überprüfen ob syntaxhiglight für die sprache existiert
  28.             //hier erlaube ich nur php, sollte ausgebaut werden, wenn nötig
  29.             if($lang != "php"){
  30.                 $lang = "";
  31.             }
  32.         }
  33.         $content = trim($content, "\r\n");
  34.         if($lang == ""){
  35.             $codetype = 'Code';
  36.             $content = htmlentitiesutf8($content);
  37.         }elseif($lang == 'php'){
  38.             $codetype = 'PHP-Code';
  39.             $content = highlight_string($content, true);
  40.         }
  41.         return '<div style="width:400px; padding:5px; border:1px solid #AAAAAA; white-space:pre; font-family:monospace;">'
  42.             .'<div style="font-weight:bold; font-family:sans-serif; font-size:12px;">'.$codetype.'</div>'
  43.             .$content.'</div>';
  44.     }
  45. }
  46.  
  47.  
  48. function bbcode_url($action, $attributes, $content, $params, &$node_object){
  49.     if($action == 'validate'){
  50.         if(isset($attributes['default'])){
  51.             $url = $attributes['default'];
  52.         }else{
  53.             $url = $content;
  54.         }
  55.         if(preg_match('@^(https?|ftp|irc|blubb)://[a-z0-9_\-\.]+(/.*)?$@i', $url)){
  56.             return true;
  57.         }
  58.         return false;
  59.     }elseif($action == 'output'){
  60.         if(isset($attributes['default'])){
  61.             $url = $attributes['default'];
  62.             return '<a href="'.htmlentitiesutf8($url).'">'.$content.'</a>';
  63.         }else{
  64.             return '<a href="'.$content.'">'.$content.'</a>';
  65.         }
  66.        
  67.     }
  68. }
  69.  
  70.  
  71. function bbcode_color($action, $attributes, $content, $params, &$node_object){
  72.     global $color_names;
  73.     if($action == 'validate'){
  74.         return true;
  75.     }elseif($action == 'output'){
  76.         $textcol = "";
  77.         $bgcol = "";
  78.         if(isset($attributes['default'])){
  79.             $textcol = $attributes['default'];
  80.         }else{
  81.             if(isset($attributes['text'])){
  82.                 $textcol = $attributes['text'];
  83.             }
  84.             if(isset($attributes['bg'])){
  85.                 $bgcol = $attributes['bg'];
  86.             }
  87.         }
  88.         if($textcol != ""){
  89.             if(preg_match('/^#[a-fA-F0-9]{6}$/', $textcol)){
  90.                 $textcol = strtoupper($textcol);
  91.             }elseif(preg_match('/^#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/', $textcol, $ret)){
  92.                 $textcol = strtoupper('#'.$ret[1].$ret[1].$ret[2].$ret[2].$ret[3].$ret[3]);
  93.             }elseif(isset($color_names[strtolower($textcol)])){
  94.                 $textcol = $color_names[$textcol];
  95.             }else{
  96.                 $textcol = "";
  97.             }
  98.         }
  99.         if($bgcol != ""){
  100.             if(preg_match('/^#[a-fA-F0-9]{6}$/', $bgcol)){
  101.                 $bgcol = strtoupper($bgcol);
  102.             }elseif(preg_match('/^#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/', $bgcol, $ret)){
  103.                 $bgcol = strtoupper('#'.$ret[1].$ret[1].$ret[2].$ret[2].$ret[3].$ret[3]);
  104.             }elseif(isset($color_names[strtolower($bgcol)])){
  105.                 $bgcol = $color_names[$bgcol];
  106.             }else{
  107.                 $bgcol = "";
  108.             }
  109.         }
  110.         if($textcol != "" && $bgcol != ""){
  111.             return '<span style="color:'.$textcol.'; background-color:'.$bgcol.';">'.$content.'</span>';
  112.         }elseif($textcol != ""){
  113.             return '<span style="color:'.$textcol.'; background-color:none;">'.$content.'</span>';
  114.         }elseif($bgcol != ""){
  115.             return '<span style="color:none; background-color:'.$bgcol.';">'.$content.'</span>';
  116.         }else{
  117.             return '<span style="color:none; background-color:none;">'.$content.'</span>';
  118.         }
  119.        
  120.     }
  121. }
  122.  
  123. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement