| 1 |
<?php |
| 2 |
|
| 3 |
class autopimizeCache |
| 4 |
{ |
| 5 |
private $filename; |
| 6 |
private $mime; |
| 7 |
private $cachedir; |
| 8 |
|
| 9 |
public function __construct($cachedir,$md5) |
| 10 |
{ |
| 11 |
$this->cachedir = $cachedir; |
| 12 |
$this->filename = 'autoptimize_'.$md5.'.php'; |
| 13 |
} |
| 14 |
|
| 15 |
public function check() |
| 16 |
{ |
| 17 |
if(!file_exists($this->cachedir.$this->filename)) |
| 18 |
{ |
| 19 |
//No cached file, sorry |
| 20 |
return false; |
| 21 |
} |
| 22 |
//Cache exists! |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
public function cache($code,$mime) |
| 27 |
{ |
| 28 |
$phpcode = file_get_contents(WP_PLUGIN_DIR.'/autoptimize/config/default.php'); |
| 29 |
$phpcode = str_replace(array('%%CONTENT%%','exit;'),array($mime,''),$phpcode); |
| 30 |
file_put_contents($this->cachedir.$this->filename,$phpcode); |
| 31 |
file_put_contents($this->cachedir.$this->filename.'.deflate',gzencode($code,9,FORCE_DEFLATE)); |
| 32 |
file_put_contents($this->cachedir.$this->filename.'.gzip',gzencode($code,9,FORCE_GZIP)); |
| 33 |
file_put_contents($this->cachedir.$this->filename.'.none',$code); |
| 34 |
} |
| 35 |
|
| 36 |
public function getname() |
| 37 |
{ |
| 38 |
return $this->filename; |
| 39 |
} |
| 40 |
} |
| 41 |
|