diff -r de56132c008d -r bdac73ed481e plugins/admin/CacheManager.php --- a/plugins/admin/CacheManager.php Sun Mar 28 21:49:26 2010 -0400 +++ b/plugins/admin/CacheManager.php Sun Mar 28 23:10:46 2010 -0400 @@ -15,306 +15,306 @@ function page_Admin_CacheManager() { - global $db, $session, $paths, $template, $plugins; // Common objects - global $lang; - global $cache; - if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) - { - $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); - echo '

' . $lang->get('adm_err_not_auth_title') . '

'; - echo '

' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '

'; - return; - } - - // validation/actions - if ( isset($_POST['refresh']) || isset($_POST['clear']) ) - { - $success = false; - - $target = ( isset($_POST['refresh']) ) ? $_POST['refresh'] : $_POST['clear']; - $do_refresh = isset($_POST['refresh']); - switch ( $target ) - { - case 'page': - $success = $cache->purge('page_meta'); - if ( $do_refresh && $success ) - $success = $paths->update_metadata_cache(); - break; - case 'ranks': - $success = $cache->purge('ranks'); - if ( $do_refresh && $success ) - $success = generate_cache_userranks(); - break; - case 'sidebar': - $success = $cache->purge('anon_sidebar'); - break; - case 'plugins': - $success = $cache->purge('plugins'); - if ( $do_refresh && $success ) - $success = $plugins->generate_plugins_cache(); - break; - case 'template': - if ( $dh = opendir(ENANO_ROOT . '/cache') ) - { - while ( $file = @readdir($dh) ) - { - $fullpath = ENANO_ROOT . "/cache/$file"; - // we don't want to mess with directories - if ( !is_file($fullpath) ) - continue; - - if ( preg_match('/\.(?:tpl|css)\.php$/', $file) ) - { - unlink($fullpath); - } - } - $success = true; - } - break; - case 'aes': - $success = @unlink(ENANO_ROOT . '/cache/aes_decrypt.php'); - break; - case 'lang': - if ( $dh = opendir(ENANO_ROOT . '/cache') ) - { - while ( $file = @readdir($dh) ) - { - $fullpath = ENANO_ROOT . "/cache/$file"; - // we don't want to mess with directories - if ( !is_file($fullpath) ) - continue; - - if ( preg_match('/^lang_json_(?:[a-f0-9]+?)\.php$/', $file) || preg_match('/^(?:cache_)?lang_(?:[0-9]+?)\.php$/', $file) ) - unlink($fullpath); - } - $success = true; - } - if ( $do_refresh && $success ) - { - // for each language in the database, call regen_caches() - $q = $db->sql_query('SELECT lang_id FROM ' . table_prefix . 'language;'); - if ( !$q ) - $db->_die(); - while ( $row = $db->fetchrow($q) ) - { - $lang_local = ( $row['lang_id'] == $lang->lang_id ) ? $lang : new Language($row['lang_id']); - $success = $lang_local->regen_caches(); - if ( !$success ) - break 2; - } - } - break; - case 'js': - if ( $dh = opendir(ENANO_ROOT . '/cache') ) - { - while ( $file = @readdir($dh) ) - { - $fullpath = ENANO_ROOT . "/cache/$file"; - // we don't want to mess with directories - if ( !is_file($fullpath) ) - continue; - - // compressed javascript - if ( preg_match('/^jsres_(?:[A-z0-9_-]+)\.js\.json$/', $file) ) - unlink($fullpath); - // tinymce stuff - else if ( preg_match('/^tiny_mce_(?:[a-f0-9]+)\.gz$/', $file) ) - unlink($fullpath); - } - $success = true; - } - break; - case 'thumbs': - if ( $dh = opendir(ENANO_ROOT . '/cache') ) - { - while ( $file = @readdir($dh) ) - { - $fullpath = ENANO_ROOT . "/cache/$file"; - // we don't want to mess with directories - if ( !is_file($fullpath) ) - continue; - - if ( preg_match('/^(?:[a-z0-9\._,-]+)-(?:[0-9]{10})-[0-9]+x[0-9]+\.([a-z0-9_-]+)$/i', $file) ) - unlink($fullpath); - } - $success = true; - } - break; - case 'wikieditnotice': - $cache->purge('wiki_edit_notice'); - if ( $do_refresh ) - $template->get_wiki_edit_notice(); - - $success = true; - break; - case 'all': - $success = purge_all_caches(); - if ( $do_refresh ) - { - // - // refresh all static (non-incremental) caches - // - - // pages - $success = $paths->update_metadata_cache(); - if ( !$success ) - break; - - // user ranks - $success = generate_cache_userranks(); - if ( !$success ) - break; - - // plugins - $success = $plugins->generate_plugins_cache(); - if ( !$success ) - break; - - // wiki edit notice - $template->get_wiki_edit_notice(); - - // languages - $q = $db->sql_query('SELECT lang_id FROM ' . table_prefix . 'language;'); - if ( !$q ) - $db->_die(); - while ( $row = $db->fetchrow($q) ) - { - $lang_local = ( $row['lang_id'] == $lang->lang_id ) ? $lang : new Language($row['lang_id']); - $success = $lang_local->regen_caches(); - if ( !$success ) - break 2; - } - } - break; - default: - $code = $plugins->setHook('acp_cache_manager_action'); - foreach ( $code as $cmd ) - { - eval($cmd); - } - break; - } - if ( $success ) - { - echo '
' . $lang->get('acpcm_msg_action_success') . '
'; - } - else - { - echo '
' . $lang->get('acpcm_err_action_failed') . '
'; - } - } - else if ( isset($_POST['save']) ) - { - $config_value = ( isset($_POST['cache_thumbs']) ) ? '1' : '0'; - setConfig('cache_thumbs', $config_value); - echo '
' . $lang->get('acpcm_msg_action_success') . '
'; - } - - echo '

    ' . $lang->get('acpcm_heading_main') . '

'; - echo '

' . $lang->get('acpcm_intro') . '

'; - - echo '
' . $lang->get('acpcm_msg_refresh_warning') . '
'; - - acp_start_form(); - ?> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setHook('acp_cache_manager_list_caches'); - foreach ( $code as $cmd ) - { - eval($cmd); - } - foreach ( $cache_list as $target ) - { - $class = ( $class == 'row1' ) ? 'row2' : 'row1'; - ?> - - - - - - - - - -
- get('acpcm_table_header'); ?> -
- -
- - get('acpcm_hint_enable_cache'); ?> - -
- - - get('acpcm_hint_clear_all'); ?> -
- - - get('acpcm_hint_refresh_all'); ?> -
- get('acpcm_th_individual_caches'); ?> -
- - - - get("acpcm_cache_{$target}_desc_title"); ?> – - get("acpcm_cache_{$target}_desc_body"); ?> -
- - -
-
- '; + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + global $cache; + if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) + { + $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); + echo '

' . $lang->get('adm_err_not_auth_title') . '

'; + echo '

' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '

'; + return; + } + + // validation/actions + if ( isset($_POST['refresh']) || isset($_POST['clear']) ) + { + $success = false; + + $target = ( isset($_POST['refresh']) ) ? $_POST['refresh'] : $_POST['clear']; + $do_refresh = isset($_POST['refresh']); + switch ( $target ) + { + case 'page': + $success = $cache->purge('page_meta'); + if ( $do_refresh && $success ) + $success = $paths->update_metadata_cache(); + break; + case 'ranks': + $success = $cache->purge('ranks'); + if ( $do_refresh && $success ) + $success = generate_cache_userranks(); + break; + case 'sidebar': + $success = $cache->purge('anon_sidebar'); + break; + case 'plugins': + $success = $cache->purge('plugins'); + if ( $do_refresh && $success ) + $success = $plugins->generate_plugins_cache(); + break; + case 'template': + if ( $dh = opendir(ENANO_ROOT . '/cache') ) + { + while ( $file = @readdir($dh) ) + { + $fullpath = ENANO_ROOT . "/cache/$file"; + // we don't want to mess with directories + if ( !is_file($fullpath) ) + continue; + + if ( preg_match('/\.(?:tpl|css)\.php$/', $file) ) + { + unlink($fullpath); + } + } + $success = true; + } + break; + case 'aes': + $success = @unlink(ENANO_ROOT . '/cache/aes_decrypt.php'); + break; + case 'lang': + if ( $dh = opendir(ENANO_ROOT . '/cache') ) + { + while ( $file = @readdir($dh) ) + { + $fullpath = ENANO_ROOT . "/cache/$file"; + // we don't want to mess with directories + if ( !is_file($fullpath) ) + continue; + + if ( preg_match('/^lang_json_(?:[a-f0-9]+?)\.php$/', $file) || preg_match('/^(?:cache_)?lang_(?:[0-9]+?)\.php$/', $file) ) + unlink($fullpath); + } + $success = true; + } + if ( $do_refresh && $success ) + { + // for each language in the database, call regen_caches() + $q = $db->sql_query('SELECT lang_id FROM ' . table_prefix . 'language;'); + if ( !$q ) + $db->_die(); + while ( $row = $db->fetchrow($q) ) + { + $lang_local = ( $row['lang_id'] == $lang->lang_id ) ? $lang : new Language($row['lang_id']); + $success = $lang_local->regen_caches(); + if ( !$success ) + break 2; + } + } + break; + case 'js': + if ( $dh = opendir(ENANO_ROOT . '/cache') ) + { + while ( $file = @readdir($dh) ) + { + $fullpath = ENANO_ROOT . "/cache/$file"; + // we don't want to mess with directories + if ( !is_file($fullpath) ) + continue; + + // compressed javascript + if ( preg_match('/^jsres_(?:[A-z0-9_-]+)\.js\.json$/', $file) ) + unlink($fullpath); + // tinymce stuff + else if ( preg_match('/^tiny_mce_(?:[a-f0-9]+)\.gz$/', $file) ) + unlink($fullpath); + } + $success = true; + } + break; + case 'thumbs': + if ( $dh = opendir(ENANO_ROOT . '/cache') ) + { + while ( $file = @readdir($dh) ) + { + $fullpath = ENANO_ROOT . "/cache/$file"; + // we don't want to mess with directories + if ( !is_file($fullpath) ) + continue; + + if ( preg_match('/^(?:[a-z0-9\._,-]+)-(?:[0-9]{10})-[0-9]+x[0-9]+\.([a-z0-9_-]+)$/i', $file) ) + unlink($fullpath); + } + $success = true; + } + break; + case 'wikieditnotice': + $cache->purge('wiki_edit_notice'); + if ( $do_refresh ) + $template->get_wiki_edit_notice(); + + $success = true; + break; + case 'all': + $success = purge_all_caches(); + if ( $do_refresh ) + { + // + // refresh all static (non-incremental) caches + // + + // pages + $success = $paths->update_metadata_cache(); + if ( !$success ) + break; + + // user ranks + $success = generate_cache_userranks(); + if ( !$success ) + break; + + // plugins + $success = $plugins->generate_plugins_cache(); + if ( !$success ) + break; + + // wiki edit notice + $template->get_wiki_edit_notice(); + + // languages + $q = $db->sql_query('SELECT lang_id FROM ' . table_prefix . 'language;'); + if ( !$q ) + $db->_die(); + while ( $row = $db->fetchrow($q) ) + { + $lang_local = ( $row['lang_id'] == $lang->lang_id ) ? $lang : new Language($row['lang_id']); + $success = $lang_local->regen_caches(); + if ( !$success ) + break 2; + } + } + break; + default: + $code = $plugins->setHook('acp_cache_manager_action'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + break; + } + if ( $success ) + { + echo '
' . $lang->get('acpcm_msg_action_success') . '
'; + } + else + { + echo '
' . $lang->get('acpcm_err_action_failed') . '
'; + } + } + else if ( isset($_POST['save']) ) + { + $config_value = ( isset($_POST['cache_thumbs']) ) ? '1' : '0'; + setConfig('cache_thumbs', $config_value); + echo '
' . $lang->get('acpcm_msg_action_success') . '
'; + } + + echo '

    ' . $lang->get('acpcm_heading_main') . '

'; + echo '

' . $lang->get('acpcm_intro') . '

'; + + echo '
' . $lang->get('acpcm_msg_refresh_warning') . '
'; + + acp_start_form(); + ?> +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + setHook('acp_cache_manager_list_caches'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + foreach ( $cache_list as $target ) + { + $class = ( $class == 'row1' ) ? 'row2' : 'row1'; + ?> + + + + + + + + + +
+ get('acpcm_table_header'); ?> +
+ +
+ + get('acpcm_hint_enable_cache'); ?> + +
+ + + get('acpcm_hint_clear_all'); ?> +
+ + + get('acpcm_hint_refresh_all'); ?> +
+ get('acpcm_th_individual_caches'); ?> +
+ + + + get("acpcm_cache_{$target}_desc_title"); ?> – + get("acpcm_cache_{$target}_desc_body"); ?> +
+ + +
+
+ '; } ?>