Public paste
What;s wrong??
By: Xmoo | Date: May 7 2009 10:49 | Format: PHP | Expires: never | Size: 7.63 KB | Hits: 1402

  1. <?php
  2. function noXSS ($input) {
  3.     # add slashes if PHP didn't do it.
  4.    if(!get_magic_quotes_gpc($input))
  5.         $input = addslashes($input);
  6.    
  7.     #replace: javascript,'
  8.    $input = str_replace(array(
  9.             'javascript',
  10.             '"'
  11.     ),array(
  12.             'java script',
  13.             '&#39;'
  14.     ),$input);
  15.    
  16.     #replace: ", <, >,&
  17.    return $input;
  18. }
  19.  
  20. //bb_codes
  21. function ubb_code($string) {
  22.  $string = noXSS($string);
  23.  $string = htmlspecialchars($string);
  24.  $string = htmlentities($string);
  25.  $string = nl2br($string);
  26.        
  27.         //smileys
  28.         $string = str_replace(":D","<img src='images/smileys/laugh.gif'>","$string");
  29.         $string = str_replace(":d","<img src='images/smileys/laugh.gif'>","$string");
  30.         $string = str_replace(":p","<img src='images/smileys/tongue.gif'>","$string");
  31.         $string = str_replace(":P","<img src='images/smileys/tongue.gif'>","$string");
  32.         $string = str_replace(";)","<img src='images/smileys/wink.gif'>","$string");
  33.         $string = str_replace(":(","<img src='images/smileys/sad.gif'>","$string");
  34.         $string = str_replace(":)","<img src='images/smileys/smile.gif'>","$string");
  35.         $string = str_replace(":@","<img src='images/smileys/angry.gif'>","$string");
  36.         $string = str_replace(":O","<img src='images/smileys/ohhh.gif'>","$string");
  37.         $string = str_replace("(h)","<img src='images/smileys/cool.gif'>","$string");
  38.         $string = str_replace("(H)","<img src='images/smileys/cool.gif'>","$string");  
  39.         $string = str_replace("(a)","<img src='images/smileys/innocent.gif'>","$string");
  40.         $string = str_replace("(A)","<img src='images/smileys/innocent.gif'>","$string");
  41.         $string = str_replace(":'(","<img src='images/smileys/crying.gif'>","$string");
  42.         $string = str_replace("(><)","<img src='images/smileys/pinch.gif'>","$string");
  43.         $string = str_replace("o0","<img src='images/smileys/blink.gif'>","$string");
  44.         $string = str_replace("0o","<img src='images/smileys/blink.gif'>","$string");
  45.        
  46.         //bb_flags
  47.         $string = str_replace("[nl]","<img src='images/flags/nl.gif'>","$string");
  48.         $string = str_replace("[de]","<img src='images/flags/de.gif'>","$string");
  49.         $string = str_replace("[es]","<img src='images/flags/es.gif'>","$string");
  50.         $string = str_replace("[fr]","<img src='images/flags/fr.gif'>","$string");
  51.         $string = str_replace("[eu]","<img src='images/flags/eu.gif'>","$string");
  52.         $string = str_replace("[-]","<img src='images/flags/-.gif'>","$string");
  53.         $string = str_replace("[uk]","<img src='images/flags/uk.gif'>","$string");
  54.        
  55.         $string = str_replace("[NL]","<img src='images/flags/nl.gif'>","$string");
  56.         $string = str_replace("[DE]","<img src='images/flags/de.gif'>","$string");
  57.         $string = str_replace("[ES]","<img src='images/flags/es.gif'>","$string");
  58.         $string = str_replace("[FR]","<img src='images/flags/fr.gif'>","$string");
  59.         $string = str_replace("[EU]","<img src='images/flags/eu.gif'>","$string");
  60.         $string = str_replace("[-]","<img src='images/flags/-.gif'>","$string");
  61.         $string = str_replace("[UK]","<img src='images/flags/uk.gif'>","$string");
  62.        
  63.         //bb_news
  64.         $string = str_replace("[EU]","<img src='images/newsicons/eu.gif'>","$string");
  65.         $string = str_replace("[world]","<img src='images/newsicons/world.gif'>","$string");
  66.         $string = str_replace("[-]","<img src='images/newsicons/none.gif'>","$string");
  67.         $string = str_replace("[review]","<img src='images/newsicons/review.gif'>","$string");
  68.         $string = str_replace("[interview]","<img src='images/newsicons/interview.gif'>","$string");
  69.        
  70.         //bb_codes
  71.         $string = preg_replace("#[url](http|ftp)(.+?)[/url]#is","<a href="\1\2" target="_blank">\1\2</a>",$string);
  72.         $string = preg_replace("#[url](mailto:)(.+?)[/url]#is","<a href="\1\2" target="_blank">\2</a>",$string);
  73.         $string = preg_replace("#[mail](.+?)[/mail]#is","\1",$string);
  74.         $string = preg_replace("#[url](.+?)[/url]#is","<a href="http://\1" target="_blank">\1</a>",$string);
  75.         $string = preg_replace("#[url=(http|ftp|mailto)(.+?)](.+?)[/url]#is","<a href="\1\2" target="_blank">\3</a>",$string);
  76.         $string = preg_replace("#[url=(.+?)](.+?)[/url]#is","<a href="http://\1" target="_blank">\2</a>",$string);
  77.         $string = eregi_replace("(^|[ nrt])((http(s?)://)(www.)?([a-z0-9_-]+(.[a-z0-9_-]+)+)(/[^/ nr]*)*)","\1<a href="\2" target="_blank">\2</a>", $string);
  78.         $string = eregi_replace("(^|[ nrt])((ftp://)(www.)?([a-z0-9_-]+(.[a-z0-9_-]+)+)(/[^/ nr]*)*)","\1<a href="\2" target="_blank">\2</a>", $string);
  79.         $string = eregi_replace("([a-z_-][a-z0-9._-]*@[a-z0-9_-]+(.[a-z0-9_-]+)+)","<a href="mailto:\1">\1</a>", $string);
  80.         $string = eregi_replace("(^|[ nrt])(www.([a-z0-9_-]+(.[a-z0-9_-]+)+)(/[^/ nr]*)*)","\1<a href="http://\2" target="_blank">\2</a>", $string);
  81.         $string = eregi_replace("(^|[ nrt])(ftp.([a-z0-9_-]+(.[a-z0-9_-]+)+)(/[^/ nr]*)*)","\1<a href="ftp://\2" target="_blank">\2</a>", $string);
  82.         $string = preg_replace("#[i](.+?)[/i]#is","<i>\1</i>",$string);
  83.         $string = preg_replace("#[u](.+?)[/u]#is","<u>\1</u>",$string);
  84.         $string = preg_replace("#[b](.+?)[/b]#is","<b>\1</b>",$string);
  85.         $string = preg_replace("#[s](.+?)[/s]#is","<s>\1</s>",$string);
  86.         $string = preg_replace("#[quote](.+?)[/quote]#is","<table width="100%" cellspacing="0" cellpadding="0"><tr><td width="3%">&nbsp;</td><td><small>Quote</small></td></tr><tr><td width="3%">&nbsp;</td><td style="border: 1px solid #232850;"><table><tr><td>\1</td></tr></table></td></tr></table>",$string);
  87.         $string = preg_replace("#[quote=(.+?)](.+?)[/quote]#is","<table width="100%" cellspacing="0" cellpadding="0"><tr><td width="3%">&nbsp;</td><td><small>Quote: <b>\1</b></small></td></tr><tr><td width="3%">&nbsp;</td><td style="border: 1px solid #232850;"><table><tr><td>\2</td></tr></table></td></tr></table>",$string);
  88.         $string = preg_replace("#[img](http)(.+?)[/img]#is","<img src="\1\2" alt="Plaatje" />",$string);
  89.         $string = preg_replace("#[img](.+?)[/img]#is","<img src="http://\1" alt="Plaatje" />",$string);
  90.         $string = preg_replace("#[color=(.+?)](.+?)[/color]#is","<font color="\1">\2</font>",$string);
  91.         $string = preg_replace("#[size=(.+?)](.+?)[/size]#is","<font size="\1">\2</font>",$string);
  92.         $string = str_replace ("[left]", "<div align='left>'", $string);
  93.         $string = str_replace ("[/left]", "</div>", $string);
  94.         $string = str_replace ("[center]", "<div align='center'>", $string);
  95.         $string = str_replace ("[/center]", "</div>", $bericht);
  96.         $string = str_replace ("[right]", "<div align='right'>", $string);
  97.         $string = str_replace ("[/right]", "</div>", $string);
  98.         $string = str_replace ("[hr]","<hr color='#000000' noshade />",$string);
  99.         $string = str_replace ("[list]","<ul>",$string);
  100.         $string = str_replace ("[*]","<li>",$string);
  101.         $string = str_replace ("[/list]","</li></ul>",$string);
  102.         $string = str_replace ("[table]","<table class='main'>",$string);
  103.         $string = str_replace ("[/table]","</table>",$string);
  104.         $string = str_replace ("[tr]","<tr>",$string);
  105.         $string = str_replace ("[/tr]","</tr>",$string);
  106.         $string = str_replace ("[td]","<td>",$string);
  107.         $string = str_replace ("[/td]","</td>",$string);
  108.        
  109.         $string = str_replace(chr(128), "&euro;", $string);
  110.     $string = str_replace(chr(137), "&permil;", $string);
  111.     $string = str_replace(chr(153), "&trade;", $string);
  112.  
  113.     for($i = 128; $i < 160; $i++) // for($i = 128; $i < 256; $i++)
  114.         {
  115.     $string = str_replace(chr($i), "&#" . $i . ";", $string);
  116.         }
  117.  
  118.     $string = str_replace("&", "&amp;", $string);
  119.     $string = str_replace("<", "&lt;", $string);
  120.     $string = str_replace(">", "&gt;", $string);
  121.     $string = str_replace(""", "&quot;", $string);
  122.  
  123.                 return $string;
  124. }
  125. ?>