Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function fw_strip_slashes($str)
- {
- if (get_magic_quotes_gpc()){return stripslashes($str);}
- return $str;
- }
- function fw_format_text($text,$autolink)
- {
- $text=htmlspecialchars($text,ENT_NOQUOTES);
- $text=str_replace("\r","",$text);
- $text=str_replace("\n[code]","[code]",str_replace("[/code]\n","[/code]",$text));
- $text=str_replace("\n[quote]","[quote]",str_replace("[/quote]\n","[/quote]",$text));
- $text=str_replace("\n[ul]","[ul]",str_replace("[/ul]\n","[/ul]",$text));
- $text=str_replace("\n[ol]","[ol]",str_replace("[/ol]\n","[/ol]",$text));
- $text=str_replace("\n[li]","[li]",str_replace("[/li]\n","[/li]",$text));
- while(strpos($text,"[noparse][url]\n")!==false){$text=str_replace("[url]\n","\n[url]",$text);}
- while(strpos($text,"\n[/url][/noparse]")!==false){$text=str_replace("\n[/url]","[/url]\n",$text);}
- while(strpos($text,"[img]\n")!==false){$text=str_replace("[img]\n","\n[img]",$text);}
- while(strpos($text,"\n[/img]")!==false){$text=str_replace("\n[/img]","[/img]\n",$text);}
- fw_escape_code($text,$autolink);
- return $text;
- }
- function fw_escape_code(&$content,$autolink)
- {
- if(empty($content)){return;}
- $start=strpos($content,'[code]');
- $end=strpos($content,'[/code]');
- if(($start===false)||($end===false)||($start > $end)){
- fw_url($content,$autolink);
- return;}
- $firstpart=substr($content,0,$start);
- fw_url($firstpart,$autolink);
- $code=substr($content,$start+6,($end-$start-6));
- $code=fw_formatcode($code);
- $lastpart=substr($content,$end +7);
- fw_escape_code($lastpart);
- $content=$firstpart.$code.$lastpart;
- }
- function fw_formatcode($code)
- {
- if(empty($code)){return;}
- static $n=0;
- $n=$n+1;
- $line_count=substr_count($code,"\n");
- $height=20+($line_count-1)*14;
- if($height<40){$height=40;}
- if($height>300){$height=300;}
- $code='<div class="fw_code_heading">Code'.$n.':</div><pre class="fw_code" style="padding:5px; overflow:auto; height:'.$height.'px;">'.$code.'</pre>';
- return $code;
- }
- function fw_url(&$content,$autolink)
- {
- if($autolink){$content=fw_convert2_link($content);}
- $content=preg_replace("/\[noparse][url\](.+)\[\/url\]/eiUs", "fw_geturl('\\1')", $content);
- $content=preg_replace('/\[url\=(.+)\](.+)\[\/url\]/eiUs', "fw_imglink('\\2','\\1')", $content);
- $content=preg_replace('/\[color\=(.+)\](.+)\[\/color\]/iUs', '<span style="color:$1">$2</span>', $content);
- $content=preg_replace("/\[img\](.+)\[\/img\]/eiUs", "fw_imglink('\\1');", $content);
- $content=nl2br($content);
- $content=fw_convert2_html($content);
- }
- function fw_geturl($link)
- {
- if(strpos($link,']')!==false){
- $x=str_replace('[','<',str_replace(']','>',$link));
- $x=strip_tags($x);
- return '<a target="_blank" href="'.$x.'">'.$link.'</a>';
- }
- else{return '<a target="_blank" href="'.$link.'">'.$link.'</a>';}
- }
- function fw_imglink($img,$url='')
- {
- if(!empty($url)){
- if(strpos($img,'[img]')===false){return '<a target="_blank" href="'.$url.'">'.$img.'</a>';}
- $img=substr($img,5,-6);}
- if(!(@getimagesize($img))){return;}
- if(empty($url)){return '<div class="fw_image"><img src="'.$img.'" /></div>';}
- else{return '<div class="fw_image"><a target="_blank" href="'.$url.'"><img src="'.$img.'" /></a></div>';}
- }
- function fw_convert2_link($x)
- {
- $x=str_replace('[url]http','[url]xttp',str_replace('[url=http','[url=xttp',$x));
- $exp='/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}+([^\[\ \n\r\t]*)/i';
- $x=preg_replace($exp, ' [url]${0}[/url][/noparse]', $x);
- $x=str_replace('[url]xttp','[url]http',str_replace('[url=xttp','[url=http',$x));
- return $x;
- }
- function fw_convert2_html($text)
- {
- $search=array('[b]','[/b]','[u]','[/u]','[i]','[/i]','[s]','[/s]','[sup]','[/sup]','[sub]','[/sub]','[quote]','[/quote]','[ul]','[/ul]','[ol]','[/ol]','[li]','[/li]');
- $replace=array('<b>','</b>','<u>','</u>','<i>','</i>','<s>','</s>','<sup>','</sup>','<sub>','</sub>','<blockquote><p>','</p></blockquote>','<ul>','</ul>','<ol>','</ol>','<li>','</li>');
- return str_replace($search,$replace,$text);
- return $text;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement