Read Detail

FILTER CLASS

FILTER CLASS dapat dilihat pada file kick/filter/Filter.php. Class ini berfungsi untuk MEMFILTER DATA ATAU VARIABLE. Fungsi FILTER CLASS adalah sebagai berikut :

1. email

public function email($email){
    if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
        return true;
    }else{
        return false;
    }
}

2. url

public function url($url){
    if(filter_var($url, FILTER_VALIDATE_URL)) {
        return true;
    }else{
        return false;
    }
}

3. ipAddress

public function ipAddress($ip){
    if(filter_var($ip, FILTER_VALIDATE_IP)) {
        return true;
    }else{
        return false;
    }
}

4. fileExtension

public function fileExtension($file_name,$format="document") {
    if($format=="document"){
        $ext_array = array(".zip",".rar",".doc",".docx",".xls",".xlsx","ppt", "pptx", ".pdf");   
    }elseif($format=="image"){
        $ext_array = array(".jpg",".gif",".png",".bmp",".jpeg");
    }else{
        $ext_array = array(".zip",".rar",".doc",".docx",".xls",".xlsx","ppt", "pptx", ".pdf",
                            ".jpg",".gif",".png",".bmp",".jpeg");
    }      
    $extension = strtolower(strrchr($file_name,"."));
    $ext_count = count($ext_array);
    if (!$file_name) {
        return false;
    }else{
        if (!$ext_array) {
            return false;
        } else {
            foreach ($ext_array as $value) {
                $first_char = substr($value,0,1);
                    if ($first_char <> ".") {
                        $extensions[] = ".".strtolower($value);
                    } else {
                        $extensions[] = strtolower($value);
                    }
            }               
            foreach ($extensions as $value) {
                if ($value == $extension) {
                    $valid_extension = "TRUE";
                }
            }
            if ($valid_extension) {
                return true;
            } else {
                return false;
            }
        }
    }
}


Cara memanggil pada CONTROLLER.

$email = 'mohonjangandibalas@kickframework.com';
$url = 'http://www.kickframework.com';
$ip = '192.168.1.1';
$file = 'avatar.jpg';

$checkEmail = $this->filter->email($email);
$checkURL = $this->filter->email($url);
$checkIP = $this->filter->ipAddress($ip);
$checkFile = $this->filter->
fileExtension($file, 'image');