| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup DolphinCore Dolphin Core
- * @{
- */
- // TODO: check if it is used or maybe usefull for future use, also it needs some refactoring
- class BxDolCacheUtilities extends BxDol
- {
- protected $oMemberMenu;
- protected $oCacheMemberMenu;
- protected $oCachePb;
- protected $oCacheDb;
- protected $oCacheTemplates;
- function __construct ()
- {
- parent::__construct();
- // member menu
- bx_import('BxDolMemberMenu');
- $this->oMemberMenu = new BxDolMemberMenu();
- $this->oCacheMemberMenu = $this->oMemberMenu->getCacheObject();
- // page blocks
- bx_import('BxDolPageViewAdmin');
- $oPageViewCacher = new BxDolPageViewCacher ('', '');
- $this->oCachePb = $oPageViewCacher->getBlocksCacheObject ();
- // DB
- $this->oCacheDb = $GLOBALS['MySQL']->getDbCacheObject();
- // templates
- $this->oCacheTemplates = $GLOBALS['oSysTemplate']->getTemplatesCacheObject();
- }
- function clear($sCache)
- {
- return $this->_action($sCache, 'clear');
- }
- function size($sCache, $isFormatted = false)
- {
- $iSize = $this->_action($sCache, 'size');
- return $isFormatted ? sprintf("%.2f", $iSize / 1024 / 1024) : $iSize;
- }
- function _action($sCache, $sMode = 'clear')
- {
- $sFuncCacheObject = ('clear' == $sMode ? '_clearCacheObject' : '_getSizeCacheObject');
- $sFuncCacheFile = ('clear' == $sMode ? '_clearCache' : '_getSizeCache');
- switch ($sCache) {
- case 'member_menu':
- $mixedResult = $this->$sFuncCacheObject ($this->oCacheMemberMenu, $this->oMemberMenu->sMenuMemberKeysCache);
- break;
- case 'pb':
- $mixedResult = $this->$sFuncCacheObject ($this->oCacheDb, 'pb_');
- break;
- case 'users':
- $mixedResult = $this->$sFuncCacheFile('user', BX_DIRECTORY_PATH_CACHE);
- break;
- case 'db':
- $mixedResult = $this->$sFuncCacheObject ($this->oCacheDb, 'db_');
- break;
- case 'template':
- $mixedResult = $this->$sFuncCacheObject ($this->oCacheTemplates, $GLOBALS['oSysTemplate']->_sCacheFilePrefix);
- break;
- case 'css':
- $mixedResult = $this->$sFuncCacheFile($GLOBALS['oSysTemplate']->_sCssCachePrefix, BX_DIRECTORY_PATH_CACHE_PUBLIC);
- break;
- case 'js':
- $mixedResult = $this->$sFuncCacheFile($GLOBALS['oSysTemplate']->_sJsCachePrefix, BX_DIRECTORY_PATH_CACHE_PUBLIC);
- break;
- }
- return $mixedResult;
- }
- function _clearCacheObject($oCache, $sPrefix)
- {
- if (!$oCache->removeAllByPrefix ($sPrefix))
- return array('code' => 1, 'message' => _t('_adm_txt_dashboard_cache_clean_failed'));
- else
- return array('code' => 0, 'message' => _t('_adm_txt_dashboard_cache_clean_success'));
- }
- function _getSizeCacheObject($oCache, $sPrefix)
- {
- return $oCache->getSizeByPrefix ($sPrefix);
- }
- function _clearCache($sPrefix, $sPath)
- {
- if (!($rHandler = opendir($sPath)))
- return array('code' => 1, 'message' => _t('_adm_txt_dashboard_cache_clean_failed'));
- $l = strlen($sPrefix);
- while (($sFile = readdir($rHandler)) !== false)
- if (0 == strncmp($sFile, $sPrefix, $l))
- @unlink($sPath . $sFile);
- closedir($rHandler);
- return array('code' => 0, 'message' => _t('_adm_txt_dashboard_cache_clean_success'));
- }
- function _getSizeCache($sPrefix, $sPath)
- {
- if (!($rHandler = opendir($sPath)))
- return 0;
- $iSize = 0;
- $l = strlen($sPrefix);
- while (($sFile = readdir($rHandler)) !== false)
- if (0 == strncmp($sFile, $sPrefix, $l))
- $iSize += filesize($sPath . $sFile);
- closedir($rHandler);
- return $iSize;
- }
- }
- /** @} */
|