tables
1 year ago
assets.php
1 year ago
baseObject.php
1 year ago
cache.php
1 year ago
controller.php
1 year ago
date.php
1 year ago
db.php
1 year ago
dispatcher.php
1 year ago
errors.php
1 year ago
field.php
1 year ago
fieldAdapter.php
1 year ago
frame.php
1 year ago
helper.php
1 year ago
html.php
1 year ago
installer.php
1 year ago
installerDbUpdater.php
1 year ago
modInstaller.php
1 year ago
model.php
1 year ago
module.php
1 year ago
req.php
1 year ago
response.php
1 year ago
table.php
1 year ago
uri.php
1 year ago
user.php
1 year ago
utils.php
1 year ago
validator.php
1 year ago
view.php
1 year ago
cache.php
57 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | class WaicCache { |
| 6 | private $directories = array(); |
| 7 | |
| 8 | public function init() { |
| 9 | $this->initFilesystem(); |
| 10 | } |
| 11 | public static function getInstance() { |
| 12 | static $instance; |
| 13 | if (!$instance) { |
| 14 | $instance = new WaicCache(); |
| 15 | } |
| 16 | return $instance; |
| 17 | } |
| 18 | public static function _() { |
| 19 | return self::getInstance(); |
| 20 | } |
| 21 | public function getDirectory( $key ) { |
| 22 | return isset($this->directories[$key]) ? $this->directories[$key] : false; |
| 23 | } |
| 24 | protected function initFilesystem() { |
| 25 | $directories = array(); |
| 26 | |
| 27 | foreach ($directories as $key => $dir) { |
| 28 | $fullPath = $this->makeDirectory($dir); |
| 29 | if (false !== $fullPath) { |
| 30 | $this->directories[$key] = $fullPath; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | protected function makeDirectory( $directory ) { |
| 35 | $uploads = wp_upload_dir(); |
| 36 | |
| 37 | $basedir = $uploads['basedir']; |
| 38 | $dir = $basedir . $directory; |
| 39 | if (!is_dir($dir)) { |
| 40 | if (false === @mkdir($dir, 0775, true)) { |
| 41 | return false; |
| 42 | } |
| 43 | } else { |
| 44 | if (!is_writable($dir)) { |
| 45 | return false; |
| 46 | } |
| 47 | } |
| 48 | return $dir; |
| 49 | } |
| 50 | public function cleanCache( $dir, $file ) { |
| 51 | $cachePath = $this->getDirectory($dir) . WAIC_DS . $file; |
| 52 | if (file_exists($cachePath)) { |
| 53 | unlink($cachePath); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 |