function fn_magiczoom_getCacheInfo($path, $usedSubCache = null) { $totalSize = 0; $totalCount = 0; $usedSize = 0; $usedCount = 0; if (is_dir($path)) { if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { $next = $path . MT_DS . $file; if ($file != '.' && $file != '..' && !is_link($next)) { if (is_dir($next)) { $result = fn_magiczoom_getCacheInfo($next); if ($file == $usedSubCache) { $usedSize += $result['totalSize']; $usedCount += $result['totalCount']; } $totalSize += $result['totalSize']; $totalCount += $result['totalCount']; } elseif (is_file($next)) { $totalSize += filesize($next); $totalCount++; } } } closedir($handle); } } return array('totalSize' => $totalSize, 'totalCount' => $totalCount, 'unusedSize' => $totalSize - $usedSize, 'unusedCount' => $totalCount - $usedCount); }
$section = Settings::instance()->getSectionByName('magiczoom', Settings::ADDON_SECTION); $addon_options = db_get_hash_single_array('SELECT name, value FROM ?:settings_objects WHERE section_id = \'?p\' AND type != \'H\'', array('name', 'value'), $section['section_id']); if (isset($addon_options['cache-path-to-cache'])) { $pathToCache = $addon_options['cache-path-to-cache']; } else { $pathToCache = '/images/magictoolbox_cache'; } $tool = fn_magiczoom_load(); require_once dirname(__FILE__) . '/../../classes/magictoolbox.imagehelper.class.php'; $imagehelper = new MagicToolboxImageHelperClass(Registry::get('config.dir.root'), $pathToCache, $tool->params); $usedSubCache = $imagehelper->getOptionsHash(); if (is_dir(Registry::get('config.dir.root') . $pathToCache)) { fn_magiczoom_clearCache(Registry::get('config.dir.root') . $pathToCache, $mode == 'clear_all_items' ? null : $usedSubCache); } fn_set_notification('N', __('notice'), "Image cache was cleared."); $cacheInfo = fn_magiczoom_getCacheInfo(Registry::get('config.dir.root') . $pathToCache, $usedSubCache); echo $cacheInfo['totalCount'] . ' (' . fn_magiczoom_format_size($cacheInfo['totalSize']) . ')'; exit; } return array(CONTROLLER_STATUS_OK); function fn_magiczoom_clearCache($path, $usedSubCache = null) { $files = glob($path . DIRECTORY_SEPARATOR . '*'); if ($files !== FALSE && !empty($files)) { foreach ($files as $file) { if (is_dir($file)) { if (!$usedSubCache || $usedSubCache != substr($file, strrpos($file, DIRECTORY_SEPARATOR) + 1)) { fn_magiczoom_clearCache($file); @rmdir($file); } } else {