diff --git a/e107_admin/cache.php b/e107_admin/cache.php index 3c1648559..dd497543d 100644 --- a/e107_admin/cache.php +++ b/e107_admin/cache.php @@ -12,6 +12,16 @@ * $Id$ * */ + +/** + * Admin page - cache management + * + * @package e107 + * @subpackage admin + * @version $Id$; + * @author e107 Inc + */ + require_once("../class2.php"); if (!getperms("C")) { @@ -24,72 +34,81 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE); $e_sub_cat = 'cache'; require_once("auth.php"); -require_once(e_HANDLER."cache_handler.php"); -require_once(e_HANDLER."form_handler.php"); -require_once(e_HANDLER."message_handler.php"); -$ec = new ecache; -$frm = new e_form(); +$ec = e107::getCache(); +$frm = e107::getForm(); $emessage = eMessage::getInstance(); -if ($pref['cachestatus'] == '2') +if (e107::getPref('cachestatus') == '2') { - $pref['cachestatus'] = '1'; - save_prefs(); + e107::getConfig()->set('cachestatus', 1) + ->save(false); } if(!is_writable(e_CACHE_CONTENT)) { - $ns->tablerender(CACLAN_3, CACLAN_10."
(".$CACHE_DIRECTORY.")"); + e107::getRender()->tablerender(CACLAN_3, CACLAN_10."
(".$CACHE_DIRECTORY.")"); require_once("footer.php"); exit; } if (isset($_POST['submit_cache'])) { - if ($pref['cachestatus'] != $_POST['cachestatus'] || $pref['syscachestatus'] != $_POST['syscachestatus']) + e107::getConfig()->set('cachestatus', intval($_POST['cachestatus'])) + ->set('syscachestatus', intval($_POST['syscachestatus'])) + ->save(false); +} + +if (isset($_POST['trigger_empty_cache'])) +{ + e107::getAdminLog()->logSuccess(CACLAN_6); + switch ($_POST['option_clear_cache']) { - $pref['cachestatus'] = $_POST['cachestatus'] ? '1' : '0'; - $pref['syscachestatus'] = $_POST['syscachestatus'] ? '1' : '0'; + case 'empty_contentcache': + $ec->clear(); + e107::getAdminLog()->flushMessages(CACLAN_5); + break; - save_prefs(); - $admin_log->log_event('CACHE_01', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE,''); + case 'empty_syscache': + $ec->clear_sys(); + e107::getAdminLog()->flushMessages(CACLAN_16); + break; - $ec->clear(); - $ec->clear_sys(); + case 'empty_dbcache': + admin_page_cache_erase(e_CACHE_DB, '*.php'); + e107::getAdminLog()->flushMessages(CACLAN_24); + break; - $emessage->add(CACLAN_4, E_MESSAGE_SUCCESS); - } - else - { - $emessage->add(LAN_NO_CHANGE, E_MESSAGE_INFO); + case 'empty_imgcache': + admin_page_cache_erase(e_CACHE_IMAGE, '*.cache\.bin'); + e107::getAdminLog()->flushMessages(CACLAN_25); + break; + + // all + default: + $ec->clear(); + $ec->clear_sys(); + admin_page_cache_erase(e_CACHE_DB, '*.php'); + admin_page_cache_erase(e_CACHE_IMAGE, '*.cache\.bin'); + e107::getAdminLog()->flushMessages(CACLAN_26); + break; } } -if (isset($_POST['empty_syscache'])) -{ - $ec->clear_sys(); - $admin_log->log_event('CACHE_02', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE, ''); - $emessage->add(CACLAN_15, E_MESSAGE_SUCCESS); -} - -if (isset($_POST['empty_cache'])) -{ - $ec->clear(); - $admin_log->log_event('CACHE_03', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE, ''); - $emessage->add(CACLAN_6, E_MESSAGE_SUCCESS); -} - - - -$syscache_files = glob(e_CACHE_CONTENT."S_*.*"); -$cache_files = glob(e_CACHE_CONTENT."C_*.*"); +$syscache_files = glob(e_CACHE_CONTENT.'S_*.*'); +$cache_files = glob(e_CACHE_CONTENT.'C_*.*'); +$imgcache_files = glob(e_CACHE_IMAGE.'*.cache.bin'); +$dbcache_files = glob(e_CACHE_DB.'*.php'); $syscache_files_num = count($syscache_files); $cache_files_num = count($cache_files); +$imgcache_files_num = count($imgcache_files); +$dbcache_files_num = count($dbcache_files); -$sys_count = CACLAN_17." ".$syscache_files_num." ".($syscache_files_num != 1 ? CACLAN_19 : CACLAN_18); -$nonsys_count = CACLAN_17." ".$cache_files_num." ".($cache_files_num != 1 ? CACLAN_19 : CACLAN_18); +$syscache_label = CACLAN_17.' '.$syscache_files_num.' '.($syscache_files_num != 1 ? CACLAN_19 : CACLAN_18).''; +$contentcache_label = CACLAN_17.' '.$cache_files_num.' '.($cache_files_num != 1 ? CACLAN_19 : CACLAN_18).''; +$imgcache_label = CACLAN_17.' '.$imgcache_files_num.' '.($imgcache_files_num != 1 ? CACLAN_19 : CACLAN_18).''; +$dbcache_label = CACLAN_17.' '.$dbcache_files_num.' '.($dbcache_files_num != 1 ? CACLAN_19 : CACLAN_18).''; $text = "
@@ -109,39 +128,76 @@ $text = " - ".CACLAN_11.": {$nonsys_count} + ".CACLAN_11.": {$contentcache_label}
".CACLAN_13."
- ".$frm->radio('cachestatus', 1, ($pref['cachestatus']))." - ".$frm->label(LAN_ENABLED, 'cachestatus', 1)."   - ".$frm->radio('cachestatus', 0, (!$pref['cachestatus']))." - ".$frm->label(LAN_DISABLED, 'cachestatus', 0)." + ".$frm->radio_switch('cachestatus', e107::getPref('cachestatus'))." - ".CACLAN_12.": {$sys_count} + ".CACLAN_12.": {$syscache_label}
".CACLAN_14."
- ".$frm->radio('syscachestatus', 1, ($pref['syscachestatus']))." - ".$frm->label(LAN_ENABLED, 'syscachestatus', 1)."   - ".$frm->radio('syscachestatus', 0, (!$pref['syscachestatus']))." - ".$frm->label(LAN_DISABLED, 'syscachestatus', 0)." + ".$frm->radio_switch('syscachestatus', e107::getPref('syscachestatus'))." + + + + + ".CACLAN_20.": {$dbcache_label} +
".CACLAN_21."
+ + + ".LAN_ENABLED." + + + + + ".CACLAN_22.": {$imgcache_label} +
".CACLAN_23."
+ + + ".LAN_ENABLED."
".$frm->admin_button('submit_cache', CACLAN_2, 'update f-right')." - ".$frm->admin_button('empty_cache', CACLAN_5, 'delete')." - ".$frm->admin_button('empty_syscache', CACLAN_16, 'delete')." + ".$frm->selectbox('option_clear_cache', array( + 'empty_all' => CACLAN_26, + 'empty_contentcache' => CACLAN_5, + 'empty_syscache' => CACLAN_16, + 'empty_dbcache' => CACLAN_24, + 'empty_imgcache' => CACLAN_25, + ))." + ".$frm->admin_button('trigger_empty_cache', LAN_DELETE, 'delete')."
"; -$ns->tablerender(CACLAN_3, $emessage->render().$text); +e107::getRender()->tablerender(CACLAN_3, $emessage->render().$text); require_once("footer.php"); + +/** + * @param string $path + * @param string $mask + * @return void + */ +function admin_page_cache_erase($path, $mask) +{ + $fl = e107::getFile(false); + $fl->mode = 'fname'; + $files = $fl->get_files($path, $fmask); + if($files) + { + foreach ($files as $file) + { + unlink($path.$file); + } + } +} ?> \ No newline at end of file diff --git a/e107_handlers/cache_handler.php b/e107_handlers/cache_handler.php index a7d36d41b..90eef2110 100644 --- a/e107_handlers/cache_handler.php +++ b/e107_handlers/cache_handler.php @@ -8,10 +8,8 @@ * * Cache handler * - * $Source: /cvs_backup/e107_0.8/e107_handlers/cache_handler.php,v $ - * $Revision$ - * $Date$ - * $Author$ + * $URL$ + * $Id$ */ if (!defined('e107_INIT')) { exit; } @@ -23,9 +21,9 @@ define('CACHE_PREFIX','setDefaults(); } - + /** + * Set default parameters + * @return e_file + */ function setDefaults() { $this->dirFilter = array('/', 'CVS', '.svn'); // Default directory filter (exact matches only) $this->fileFilter = array('^thumbs\.db$','^Thumbs\.db$','.*\._$','^\.htaccess$','^index\.html$','^null\.txt$','\.bak$','^.tmp'); // Default file filter (regex format) + return $this; } + /** + * Set fileinfo mode + * @param string $val + * @return e_file + */ public function setFileInfo($val='default') { $this->finfo = $val; + return $this; } /** @@ -162,7 +188,7 @@ class e_file } if($rejected == FALSE) { - switch($this->mode) + switch($this->mode) { case 'fname': $ret[] = $file; @@ -195,6 +221,12 @@ class e_file return $ret; } + /** + * Collect file information + * @param string $path_to_file + * @param boolean $imgcheck + * @return array + */ function get_file_info($path_to_file, $imgcheck = true) { $finfo = array(); @@ -212,16 +244,21 @@ class e_file $finfo['fsize'] = $tmp['size']; $finfo['modified'] = $tmp['mtime']; } - + // associative array elements: dirname, basename, extension, filename $finfo['pathinfo'] = pathinfo($path_to_file); return $finfo; } - - // Get a list of directories matching $fmask, omitting any in the $omit array - same calling syntax as get_files() - // N.B. - no recursion - just looks in the specified directory. + /** + * Get a list of directories matching $fmask, omitting any in the $omit array - same calling syntax as get_files() + * N.B. - no recursion - just looks in the specified directory. + * @param string $path + * @param strig $fmask + * @param string $omit + * @return array + */ function get_dirs($path, $fmask = '', $omit='standard') { $ret = array(); @@ -256,9 +293,11 @@ class e_file return $ret; } - - - // Delete a complete directory tree + /** + * Delete a complete directory tree + * @param string $dir + * @return boolean success + */ function rmtree($dir) { if (substr($dir, -1) != '/') @@ -298,7 +337,7 @@ class e_file } return false; } - + /** * Parse a file size string (e.g. 16M) and compute the simple numeric value. * diff --git a/e107_languages/English/admin/lan_cache.php b/e107_languages/English/admin/lan_cache.php index 76ffa13f3..c9fb5212c 100644 --- a/e107_languages/English/admin/lan_cache.php +++ b/e107_languages/English/admin/lan_cache.php @@ -8,9 +8,9 @@ */ define("CACLAN_1", "Cache System Status"); define("CACLAN_2", "Set cache status"); -define("CACLAN_3", "Cache System"); +define("CACLAN_3", "Cache Management"); define("CACLAN_4", "Cache status set"); -define("CACLAN_5", "Empty Cache"); +define("CACLAN_5", "Empty Content Cache"); define("CACLAN_6", "Cache Emptied"); define("CACLAN_10", "The cache directory is not writable. Please ensure this directory is set CHMOD 0777"); @@ -25,5 +25,11 @@ define("CACLAN_17", "Currently contains"); define("CACLAN_18", "file"); define("CACLAN_19", "files"); - +define("CACLAN_20", "DB Structure Cache"); +define("CACLAN_21", "Database Structure cache contains system information about database tables structure, needed by various core routines. No actual content will be contained here."); +define("CACLAN_22", "Thumbnail cache"); +define("CACLAN_23", "Thumbnail cache files contains binary image data. They are there to save a lot of server CPU work."); +define("CACLAN_24", "Empty DB Structure Cache"); +define("CACLAN_25", "Empty Thumbnail Cache"); +define("CACLAN_26", "Empty All Cache"); ?> \ No newline at end of file