Location: PHPKode > projects > RAMUI WEBBLOG > fw_blog/admin/include/clsformat.php
<?php
/*
Copyright (c) 2008 http://ramui.com. All right reserved.
This product is protected by copyright and distributed under licenses restricting copying, distribution. Permission is granted to the public to download and use this script provided that this Notice and any statement of authorship are reproduced in every page on all copies of the script.
*/
class clsformat extends clsmain
{

private function escape_code($content)
{
         if(empty($content)){return false;}
         $start=strpos($content,'<codx>');
         $end=strpos($content,'</codx>');
         if(($start===false)||($end===false)){return $this->convert2_html($content);}
         if($start > $end){return false;}
         $firstpart=substr($content,0,$start);
         $firstpart=$this->convert2_html($firstpart);
         $code=substr($content,$start,($end-$start+7));
         $lastpart=substr($content,$end +7);
         $lastpart=$this->escape_code($lastpart);
         if($lastpart!==false){return($firstpart.$code.$lastpart);}
         else{return($firstpart.$code);}
}
private function escape_link($content)
{
         if(empty($content)){return false;}
         $start=strpos($content,'<a ');
         $end=strpos($content,'</a>');
         if(($start===false)||($end===false)){return $this->convert2_link($content);}
         if($start > $end){return false;}
         $firstpart=substr($content,0,$start);
         $firstpart=$this->convert2_link($firstpart);
         $link=substr($content,$start,($end-$start+4));
         $lastpart=substr($content,$end +4);
         $lastpart=$this->escape_link($lastpart);
         if($lastpart!==false){return($firstpart.$link.$lastpart);}
         else{return($firstpart.$link);}
}
private function convert2_html($s)
{
         $s=str_replace("\r","",$s);
         if(strpos($s,"\n")===0){$s='|^%~^|'.substr($s,1);}
         $s=str_replace("<br>\n","<br />",str_replace("<br />\n","<br />",$s));
         $s=str_replace(">\n",">|^%~^|",$s);
         $s=nl2br($s);
         return $this->escape_link($s);
}

private function convert2_link($s) {
         $s = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a href="\\1" target="_blank">\\1</a>', $s);
         $s = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a href="\\1" target="_blank">\\1</a>', $s);
         $s = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1<a href="http://\\2" target="_blank">\\2</a>', $s);
         $s = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href="mailto:\\1" target="_blank">\\1</a>', $s);
         return $s;
}

private function format_text()
{
        $text=fw_strip_slashes(rawurldecode(trim($_POST['text'])));
        $text=fw_remove_smarttag($text);
        $text=str_replace('< ','<',str_replace(' >','>',$text));
        $text=$this->escape_code($text);
        $text=str_replace("\n","\r\n",str_replace("|^%~^|","\n",$text));
        echo(empty($text)? 'error' : $text);
        exit;
}

public function get_query($query)
{
       if ($this->validate_user()){$this->format_text();}
}
}
?>
Return current item: RAMUI WEBBLOG