Advertisement
Guest User

functions.php

a guest
Nov 9th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.13 KB | None | 0 0
  1. <?php
  2. function fw_strip_slashes($str)
  3. {
  4.         if (get_magic_quotes_gpc()){return stripslashes($str);}
  5.         return $str;
  6. }
  7. function fw_format_text($text,$autolink)
  8. {
  9.         $text=htmlspecialchars($text,ENT_NOQUOTES);
  10.         $text=str_replace("\r","",$text);
  11.         $text=str_replace("\n[code]","[code]",str_replace("[/code]\n","[/code]",$text));
  12.         $text=str_replace("\n[quote]","[quote]",str_replace("[/quote]\n","[/quote]",$text));
  13.         $text=str_replace("\n[ul]","[ul]",str_replace("[/ul]\n","[/ul]",$text));
  14.         $text=str_replace("\n[ol]","[ol]",str_replace("[/ol]\n","[/ol]",$text));
  15.         $text=str_replace("\n[li]","[li]",str_replace("[/li]\n","[/li]",$text));
  16.         while(strpos($text,"[noparse][url]\n")!==false){$text=str_replace("[url]\n","\n[url]",$text);}
  17.         while(strpos($text,"\n[/url][/noparse]")!==false){$text=str_replace("\n[/url]","[/url]\n",$text);}
  18.         while(strpos($text,"[img]\n")!==false){$text=str_replace("[img]\n","\n[img]",$text);}
  19.         while(strpos($text,"\n[/img]")!==false){$text=str_replace("\n[/img]","[/img]\n",$text);}
  20.         fw_escape_code($text,$autolink);
  21.         return $text;
  22. }
  23. function fw_escape_code(&$content,$autolink)
  24. {
  25.         if(empty($content)){return;}
  26.         $start=strpos($content,'[code]');
  27.         $end=strpos($content,'[/code]');
  28.         if(($start===false)||($end===false)||($start > $end)){
  29.             fw_url($content,$autolink);
  30.             return;}
  31.         $firstpart=substr($content,0,$start);
  32.         fw_url($firstpart,$autolink);
  33.         $code=substr($content,$start+6,($end-$start-6));
  34.         $code=fw_formatcode($code);
  35.         $lastpart=substr($content,$end +7);
  36.         fw_escape_code($lastpart);
  37.         $content=$firstpart.$code.$lastpart;
  38. }
  39. function fw_formatcode($code)
  40. {
  41.         if(empty($code)){return;}
  42.         static $n=0;
  43.         $n=$n+1;
  44.         $line_count=substr_count($code,"\n");
  45.         $height=20+($line_count-1)*14;
  46.         if($height<40){$height=40;}
  47.         if($height>300){$height=300;}
  48.         $code='<div class="fw_code_heading">Code'.$n.':</div><pre class="fw_code" style="padding:5px; overflow:auto; height:'.$height.'px;">'.$code.'</pre>';
  49.         return $code;
  50. }
  51.  
  52. function fw_url(&$content,$autolink)
  53. {
  54.         if($autolink){$content=fw_convert2_link($content);}
  55.         $content=preg_replace("/\[noparse][url\](.+)\[\/url\]/eiUs", "fw_geturl('\\1')", $content);
  56.         $content=preg_replace('/\[url\=(.+)\](.+)\[\/url\]/eiUs', "fw_imglink('\\2','\\1')", $content);
  57.         $content=preg_replace('/\[color\=(.+)\](.+)\[\/color\]/iUs', '<span style="color:$1">$2</span>', $content);
  58.         $content=preg_replace("/\[img\](.+)\[\/img\]/eiUs", "fw_imglink('\\1');", $content);
  59.         $content=nl2br($content);
  60.         $content=fw_convert2_html($content);
  61. }
  62. function fw_geturl($link)
  63. {
  64.         if(strpos($link,']')!==false){
  65.             $x=str_replace('[','<',str_replace(']','>',$link));
  66.             $x=strip_tags($x);
  67.             return '<a target="_blank" href="'.$x.'">'.$link.'</a>';
  68.         }
  69.         else{return '<a target="_blank" href="'.$link.'">'.$link.'</a>';}
  70. }
  71. function fw_imglink($img,$url='')
  72. {
  73.         if(!empty($url)){
  74.             if(strpos($img,'[img]')===false){return '<a target="_blank" href="'.$url.'">'.$img.'</a>';}
  75.             $img=substr($img,5,-6);}
  76.         if(!(@getimagesize($img))){return;}
  77.         if(empty($url)){return '<div class="fw_image"><img src="'.$img.'" /></div>';}
  78.         else{return '<div class="fw_image"><a target="_blank" href="'.$url.'"><img src="'.$img.'" /></a></div>';}
  79. }
  80. function fw_convert2_link($x)
  81. {
  82.         $x=str_replace('[url]http','[url]xttp',str_replace('[url=http','[url=xttp',$x));
  83.         $exp='/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}+([^\[\ \n\r\t]*)/i';
  84.         $x=preg_replace($exp, ' [url]${0}[/url][/noparse]', $x);
  85.         $x=str_replace('[url]xttp','[url]http',str_replace('[url=xttp','[url=http',$x));
  86.         return $x;
  87. }
  88.  
  89. function fw_convert2_html($text)
  90. {
  91.         $search=array('[b]','[/b]','[u]','[/u]','[i]','[/i]','[s]','[/s]','[sup]','[/sup]','[sub]','[/sub]','[quote]','[/quote]','[ul]','[/ul]','[ol]','[/ol]','[li]','[/li]');
  92.         $replace=array('<b>','</b>','<u>','</u>','<i>','</i>','<s>','</s>','<sup>','</sup>','<sub>','</sub>','<blockquote><p>','</p></blockquote>','<ul>','</ul>','<ol>','</ol>','<li>','</li>');
  93.         return str_replace($search,$replace,$text);
  94.         return $text;
  95. }
  96. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement