thoigian = 3600; //thoi gian luu bo dem, mac dinh 3600 = 1 gio public static $chinhsua_qua_url = false; //cho phap cap nhat, xoa tat ca cac bo dem thong qua url public static $chuoi_phanbiet = "&goloi_dem="; //chuoi duoc su dung khi den cac url rieng biet $_GET['goloi_dem']) public static $morong = "hqv"; //mo rong cua tap tin luu tru /* khoi tao lop */ function __construct($tenmien,$thoigian) { $this->thumuc_luu_dem = 'thuvien/'.$tenmien.'/_bodem/'; $this->trang_hientai = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $this->md5_pg = md5($this->trang_hientai).".".self::$morong; $this->luutru = self::$this->thumuc_luu_dem.$this->md5_pg; $this->tuychon = "binhthuong"; $this->hanhdong = false; $this->trolai = true; $this->thoigian = $thoigian; //mag xu de go loi $this->mang_goloi = array("capnhat","lamsach","xoa"); //cap quyen cho cac thu muc dem @mkdir(self::$this->thumuc_luu_dem,0777,true); @chmod(self::$this->thumuc_luu_dem,0777); //cac thong so go loi qua url if(self::$chinhsua_qua_url != false && self::$chuoi_phanbiet != false) { //chia tach thanh phan $mang_url = explode(self::$chuoi_phanbiet,$this->trang_hientai); //hanh dong thuc thi $this->hanhdong = $mang_url[count($mang_url)-1]; }elseif(self::$chinhsua_qua_url != false && isset($_GET['goloi_dem'])){ $this->hanhdong = $_GET['goloi_dem']; } } /* doc va hien thi noi dung dem neu no ton tai */ public function docDem() { //xac nhan phuong phap du lieu if($_SERVER['REQUEST_METHOD'] != "POST"||$this->url_seo('rss')!='rss'||$this->url_seo('xml')!='xml') { //neu co hanh dong go loi if($this->hanhdong != false && in_array($this->hanhdong,$this->mang_goloi)) { switch($this->hanhdong) { case "capnhat": default: $this->trolai = false; break; //xoa tap tin hien tai case "lamsach": @unlink($this->luutru); break; //xoa tat ca cac tap tin dem case "xoa": if($thumuc = opendir(self::$this->thumuc_luu_dem)) { while(false !== ($taptin = readdir($thumuc))) { if($taptin != "." and $taptin != "..") { @unlink(self::$this->thumuc_luu_dem.$taptin); } } closedir($thumuc); } } } elseif(file_exists($this->luutru) && (time() - self::$this->thoigian < filemtime($this->luutru))) { return file_get_contents($this->luutru); exit; } if($this->trolai != false) { ob_start("ob_gzhandler"); } } } /* tao bo dem voi tap tin */ public function taoDem($tuychon="") { //kiem tra cac phuong phap nhan du lieu if($_SERVER['REQUEST_METHOD'] != "POST" || $this->trolai != false) { $fp = @fopen($this->luutru,"w"); if($tuychon == "") { $tuychon = $this->tuychon; } switch($tuychon) { case "coban": default: $dem = ob_get_contents(); break; case "binhthuong": $dem = str_replace(array("\r\n", "\r", "\n", "\t"), '', ob_get_contents()); break; case "cao": $dem = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', ob_get_contents()); break; } $dem = utf8_encode($dem); $dem="\xEF\xBB\xBF".$dem; /* luu tap tin */ @fwrite($fp,$dem); /* dong tap tin va hien thi noi dung cho trinh duyet */ @fclose($fp); ob_end_flush(); } } function url_seo($u=''){ $taptin = $_GET['hqv']; $morong = substr(strrchr($taptin,'.'),1); $url = str_replace($morong,'',@$_GET['hqv']); $url = explode('/', $url); for($i=0; $i < (count($url)); $i++) { if($u == $url[$i]){ return $url[$i]; } } return $url; } }