Skip to content

Commit

Permalink
Clear Cache now also clears the Data folder, File Manager and any Plu…
Browse files Browse the repository at this point in the history
…gin Cache files

For feature #820. Also added PLG_clearCache function so plugins can clear any of their own caches.
  • Loading branch information
eSilverStrike committed Dec 1, 2017
1 parent 8918d4b commit 15bf8c1
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
2 changes: 1 addition & 1 deletion language/english.php
Expand Up @@ -1554,7 +1554,7 @@
153 => 'You last emailed an article %1$d seconds ago. This site requires at least %2$d seconds between emailing articles.',
400 => 'Not all required fields have been passed validation', // Error codes in the 400 range reserved for CUSTOM membership
401 => 'Please enter Fullname',
500 => 'The Template Cache has been successfully cleared.'
500 => 'The Data, Template, Resource, and File Manager Cache has been successfully cleared.'
);

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion language/english_utf-8.php
Expand Up @@ -1555,7 +1555,7 @@
153 => 'You last emailed an article %1$d seconds ago. This site requires at least %2$d seconds between emailing articles.',
400 => 'Not all required fields have been passed validation', // Error codes in the 400 range reserved for CUSTOM membership
401 => 'Please enter Fullname',
500 => 'The Template Cache has been successfully cleared.'
500 => 'The Data, Template, Resource, and File Manager Cache has been successfully cleared.'
);

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion language/japanese_utf-8.php
Expand Up @@ -1556,7 +1556,7 @@
153 => 'あなたは %1$d 秒前に友だちに記事を送信しています。次に送信する前に %2$d 秒以上あけてください。',
400 => '検証に通っていない必須のフィールドがあります。',
401 => '氏名を入力してください。',
500 => 'テンプレートのキャッシュを削除しました。'
500 => 'The Data, Template, Resource, and File Manager Cache has been successfully cleared.'
);

###############################################################################
Expand Down
64 changes: 62 additions & 2 deletions public_html/admin/clearctl.php
Expand Up @@ -40,12 +40,72 @@
exit;
}

// Clean directory
function clean_directory($dir, $leave_dirs = array(), $leave_files = array()) {

foreach( glob("$dir/*") as $file ) {
if (is_dir($file)) {
if (!in_array(basename($file), $leave_dirs)) {
delete_files($file); // delete all sub directories and files in those directories
}
} elseif( !in_array(basename($file), $leave_files) ) {
unlink($file);
}
}
}

// Delete all files in a directory and any sub directory
function delete_files($dir) {

foreach(glob($dir . '/*') as $file) {
if (is_dir($file)) {
delete_files($file);
} else {
unlink($file);
}
}
rmdir($dir);
}

/*
* Main processing
*/
CTL_clearCache(); // Clearing Template Cache

// Clearing Theme Template Cache
CTL_clearCache();

// Clearing Resource Cache (CSS, and Javascript concatenated and minified files)
Geeklog\Cache::clear();

// Clean out Data directory (includes things like temp uploaded plugin files, user batch files, etc...)
$leave_dirs = array('cache', 'layout_cache', 'layout_css');
$leave_files = array('cacert.pem', 'README');
clean_directory($_CONF['path_data'], $leave_dirs, $leave_files);

// File Manager Thumbnail Files

$leave_dirs = array();
$leave_files = array('index.html');
clean_directory($_CONF['path_images'] . '_thumbs/articles/', $leave_dirs, $leave_files);

$leave_dirs = array();
$leave_files = array('index.html');
clean_directory($_CONF['path_images'] . '_thumbs/userphotos/', $leave_dirs, $leave_files);

$leave_dirs = array();
$leave_files = array('index.html');
clean_directory($_CONF['path_images'] . '_thumbs/library/image/', $leave_dirs, $leave_files);

$leave_dirs = array('Image');
$leave_files = array();
clean_directory($_CONF['path_images'] . '_thumbs/library/', $leave_dirs, $leave_files);

$leave_dirs = array('articles', 'library', 'userphotos');
$leave_files = array();
clean_directory($_CONF['path_images'] . '_thumbs/', $leave_dirs, $leave_files);

Geeklog\Cache::clear(); // Clearing Resource Cache (CSS, and Javascript concatenated and minified files)
// Allow Plugins to clear any cached items
PLG_clearCache();

COM_redirect($_CONF['site_admin_url'] . '/index.php?msg=500');

21 changes: 21 additions & 0 deletions system/lib-plugins.php
Expand Up @@ -2315,6 +2315,27 @@ function PLG_getItemInfo($type, $id, $what, $uid = 0, $options = array())
return PLG_callFunctionForOnePlugin($function, $args);
}

/**
* Asks each plugin tif they want to clear any cache of files they control
* Used by clear cache in Geeklog Administration
*
* @return array Plugins that cleared their cache files and if they where successful or not
*/
function PLG_clearCache()
{
global $_PLUGINS;

$plugin_cache_name = array();
foreach ($_PLUGINS as $pi_name) {
$function = 'plugin_clearcache_' . $pi_name;
if (function_exists($function)) {
$plugin_cache_name[$pi_name] = $function(); // Should return true if success
}
}

return $plugin_cache_name;
}

/**
* Geeklog is about to perform an operation on a trackback or pingback comment
* to one of the items under the plugin's control and asks for the plugin's
Expand Down

0 comments on commit 15bf8c1

Please sign in to comment.