Location: PHPKode > projects > RAMUI WEBBLOG > fw_blog/include/functions.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.
*/
function fw_strip_slashes($str)
{
        if (get_magic_quotes_gpc()){return stripslashes($str);}
        return $str;
}
function fw_add_slashes($str)
{
        if (!(get_magic_quotes_gpc())){return addslashes($str);}
        return $str;
}
function fw_total_page($c, $p)
{
        if ($c<1){ return 0;}
        $d=$c;
        for ($i=1; $i<=$c; $i++){
            $d=$d-$p;
            if ($d<=0){ return $i;}
        }
}
function fw_preview($s)
{
        $str=str_replace("\n", ' ', $s);
        $str=str_replace("\r", '', $str);
        $str=substr($str, 0, 127).'...';
        return $str;
}
function error($errtype, $errordesc='')
{
        if ($errordesc==''){$errordesc=mysql_error();}
        include "include/error.php";
        exit;
}
function fw_abs_to_url($abs_path)
{
         return 'http://'.str_replace($_SERVER['DOCUMENT_ROOT'], $_SERVER['HTTP_HOST'],$abs_path);
}
function fw_encode_pagename($pagename)
{
         $data=explode('/',$pagename);
         $str='';
         for($c=0; $c<count($data); $c++){
                    $str.='/'.rawurlencode($data[$c]);
         }
         $str=substr($str, 1);
         return $str.'.html';
}
function fw_preview_pagename($name)
{
         $name_array=explode("/",$name);
         $name_array[count($name_array)-1]='preview:'.$name_array[count($name_array)-1];
         return implode("/",$name_array);
}
function fw_find_code(&$content,$page)
{
         $start=strpos($content,'<codx>');
         $end=strpos($content,'</codx>');
         if(($start===false)||($end===false)||($start > $end)){return false;}
         static $n=0;
         $n=$n+1;
         $firstpart=substr($content,0,$start);
         $lastpart=substr($content,$end +7);
         $raw_code=substr($content,$start+6,($end-$start-6));
         $line_count=substr_count($raw_code,"\n");
         $height=20+($line_count-1)*14;
         if($height<40){$height=40;}
         if($height>300){$height=300;}
         $code=htmlspecialchars($raw_code,ENT_NOQUOTES);
         $code=str_replace('%&lt;%','<',str_replace('%&gt;%','>',$code));
         $download_url=fw_abs_to_url(str_replace('include/functions.php','download.php',__FILE__)).'?page='.$page.'&code='.$n;
         $code='<div class="fw_code_heading" id="fw_code'.$n.'">Code'.(($page=='')? ':' : ' | <a class="fw_codedownload" href="'.$download_url.'">Download</a>').'</div><pre class="fw_code" style="padding:5px; overflow:auto; height:'.$height.'px;">'.$code.'</pre>';
         $content=$firstpart.$code.$lastpart;
         return true;
}
function fw_random()
{
         $str='abcdefghijklmnopqrstuvwxyz_0123456789';
         $random='';
         $length=rand(8,16);
         for($i=0; $i<$length; $i++){$random.=$str{rand(0,36)};}
         return $random;
}
function fw_get_docroot()
{
         $docroot=str_replace($_SERVER['DOCUMENT_ROOT'],'',__FILE__);
         return(str_replace('fw_blog/include/functions.php','',$docroot));
}
function fw_uploadpath(&$str)
{
         $path=str_replace('include/functions.php','upload/',__FILE__);
         $url=fw_abs_to_url($path);
         $str=str_ireplace('{UPLOAD_URL}',$url,str_ireplace('{UPLOAD_PATH}',$path,$str));
}
function fw_get_querydata($q,$url='')
{
         if($url==''){$url=$_SERVER['REQUEST_URI'];}
         if(($pos=strrpos($url,'?'.$q.'='))===false){$pos=strrpos($url,'&'.$q.'=');}
         if($pos===false){return false;}
         $x=substr($url,($pos+strlen($q)+2));
         if(($pos=strpos($x,'#'))!==false){$x=substr($x,0,$pos);}
         $query_data=((($y=strpos($x,'&'))===false)? $x : substr($x,0,$y));
         return $query_data;
}
function fw_get_currentpagecontent($str,$page)
{
         $start=0;
         for($i=1;$i<$page;$i++){
                if(($start=strpos($str,'<fw_pagebreak/>',$start))===false){break;}
                $start=$start+15;
         }
         $str=substr($str,$start);
         return ((($pos=strpos($str,'<fw_pagebreak/>'))===false)? $str : substr($str,0,$pos));
}
function fw_validate_pagename($name)
{
         $reference='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/ -_:';
         $length=strlen($name);
         for($i=0; $i<$length; $i++){if(strpos($reference,$name{$i})===false){return false;}}
         if(strpos($reference,substr($name,0,1))>61){return false;}
         if(strpos($reference,substr($name,-1))>61){return false;}
         return true;
}
function fw_validate_user($name,$email)
{
         $reference='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
         $length=strlen($name);
         if(($length>16)||($length<5)){return false;}
         for($i=0; $i<$length; $i++){if(strpos($reference,$name{$i})===false){return false;}}
         $reference.='-_.@';
         $length=strlen($email);
         for($i=0; $i<$length; $i++){if(strpos($reference,$email{$i})===false){return false;}}
         if(strpos($reference,substr($email,0,1))>61){return false;}
         if(strpos($reference,substr($email,-1))>61){return false;}
         return true;
}
function fw_remove_smarttag($s)
{
         $s=str_replace('%u201C','"',str_replace('%u201D','"',$s));
         $s=str_replace("%u2018","'",str_replace("%u2019","'",$s));
         return str_replace("%u2013","-",$s);
}
?>
Return current item: RAMUI WEBBLOG