first commit
This commit is contained in:
16
plugins/system/cachecleaner/src/Cache/CDN77.php
Normal file
16
plugins/system/cachecleaner/src/Cache/CDN77.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Cache Cleaner
|
||||
* @version 8.2.2
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link http://regularlabs.com
|
||||
* @copyright Copyright © 2022 Regular Labs All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
|
||||
*/
|
||||
|
||||
namespace RegularLabs\Plugin\System\CacheCleaner\Cache;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// Only used in Pro version
|
||||
270
plugins/system/cachecleaner/src/Cache/Cache.php
Normal file
270
plugins/system/cachecleaner/src/Cache/Cache.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Cache Cleaner
|
||||
* @version 8.2.2
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link http://regularlabs.com
|
||||
* @copyright Copyright © 2022 Regular Labs All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
|
||||
*/
|
||||
|
||||
namespace RegularLabs\Plugin\System\CacheCleaner\Cache;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory as JFactory;
|
||||
use Joomla\CMS\Filesystem\File as JFile;
|
||||
use Joomla\CMS\Filesystem\Folder as JFolder;
|
||||
use Joomla\CMS\Language\Text as JText;
|
||||
use RegularLabs\Library\File as RL_File;
|
||||
use RegularLabs\Plugin\System\CacheCleaner\Cache as CC_Cache;
|
||||
use RegularLabs\Plugin\System\CacheCleaner\Params;
|
||||
|
||||
class Cache
|
||||
{
|
||||
static $ignore_folders = null;
|
||||
static $size = 0;
|
||||
|
||||
public static function addError($error = true)
|
||||
{
|
||||
CC_Cache::addError($error);
|
||||
}
|
||||
|
||||
public static function addMessage($message = '')
|
||||
{
|
||||
CC_Cache::addMessage($message);
|
||||
}
|
||||
|
||||
public static function emptyFolder($path, $min_age_in_minutes = 0)
|
||||
{
|
||||
$params = Params::get();
|
||||
|
||||
if ( ! JFolder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$size = 0;
|
||||
|
||||
if ($params->show_size)
|
||||
{
|
||||
$size = self::getFolderSize($path);
|
||||
}
|
||||
|
||||
// remove folders
|
||||
$folders = JFolder::folders($path, '.', false, false, [], []);
|
||||
|
||||
foreach ($folders as $folder)
|
||||
{
|
||||
$f = $path . '/' . $folder;
|
||||
if (in_array($f, self::getIgnoreFolders()) || ! @opendir($path . '/' . $folder))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (self::isIgnoredParent($f))
|
||||
{
|
||||
self::emptyFolder($f);
|
||||
continue;
|
||||
}
|
||||
|
||||
RL_File::deleteFolder($path . '/' . $folder, false, $min_age_in_minutes);
|
||||
|
||||
// Zoo folder needs to be placed back, otherwise Zoo will break (stupid!)
|
||||
if ($folder == 'com_zoo')
|
||||
{
|
||||
JFolder::create($path . '/' . $folder);
|
||||
}
|
||||
}
|
||||
|
||||
// remove files
|
||||
$files = JFolder::files($path, '.', false, false, [], []);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$file_path = $path . '/' . $file;
|
||||
|
||||
if ( ! is_file($file_path))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
$file == 'index.html'
|
||||
|| in_array($path, self::getIgnoreFolders())
|
||||
|| in_array($file_path, self::getIgnoreFolders())
|
||||
|| $file_path == JPATH_ADMINISTRATOR . '/cache/autoload_psr4.php'
|
||||
)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$deleted = RL_File::delete($file_path, false, $min_age_in_minutes);
|
||||
|
||||
if ( ! $deleted)
|
||||
{
|
||||
self::addError(JText::sprintf('JLIB_FILESYSTEM_DELETE_FAILED', $file_path));
|
||||
}
|
||||
}
|
||||
|
||||
if ($params->show_size)
|
||||
{
|
||||
$size -= self::getFolderSize($path);
|
||||
|
||||
self::$size += $size;
|
||||
}
|
||||
}
|
||||
|
||||
public static function emptyFolderList($folders)
|
||||
{
|
||||
}
|
||||
|
||||
public static function emptyFolders()
|
||||
{
|
||||
$params = Params::get();
|
||||
|
||||
// Empty tmp folder
|
||||
if ($params->clean_tmp)
|
||||
{
|
||||
self::emptyFolder(JPATH_SITE . '/tmp');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function emptyTable($table)
|
||||
{
|
||||
}
|
||||
|
||||
public static function getError()
|
||||
{
|
||||
return CC_Cache::getError();
|
||||
}
|
||||
|
||||
public static function getFolderSize($path)
|
||||
{
|
||||
if (is_file($path))
|
||||
{
|
||||
return @filesize($path);
|
||||
}
|
||||
|
||||
if ( ! JFolder::exists($path) || ! (@opendir($path)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$size = 0;
|
||||
foreach (JFolder::files($path) as $file)
|
||||
{
|
||||
$size += @filesize($path . '/' . $file);
|
||||
}
|
||||
|
||||
foreach (JFolder::folders($path) as $folder)
|
||||
{
|
||||
if ( ! @opendir($path . '/' . $folder))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$size += self::getFolderSize($path . '/' . $folder);
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public static function getIgnoreFolders()
|
||||
{
|
||||
if ( ! is_null(self::$ignore_folders))
|
||||
{
|
||||
return self::$ignore_folders;
|
||||
}
|
||||
|
||||
$params = Params::get();
|
||||
|
||||
if (empty($params->ignore_folders))
|
||||
{
|
||||
self::$ignore_folders = [];
|
||||
|
||||
return self::$ignore_folders;
|
||||
}
|
||||
|
||||
$ignore_folders = explode("\n", str_replace('\n', "\n", $params->ignore_folders));
|
||||
foreach ($ignore_folders as &$folder)
|
||||
{
|
||||
if (trim($folder) == '')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$folder = rtrim(str_replace('\\', '/', trim($folder)), '/');
|
||||
$folder = str_replace('//', '/', JPATH_SITE . '/' . $folder);
|
||||
}
|
||||
|
||||
self::$ignore_folders = $ignore_folders;
|
||||
|
||||
return self::$ignore_folders;
|
||||
}
|
||||
|
||||
public static function getMessage()
|
||||
{
|
||||
return CC_Cache::getMessage();
|
||||
}
|
||||
|
||||
public static function getSize()
|
||||
{
|
||||
if ( ! self::$size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self::$size < 1024)
|
||||
{
|
||||
// Return in Bs
|
||||
return self::$size . ' bytes';
|
||||
}
|
||||
|
||||
if (self::$size < (1024 * 1024))
|
||||
{
|
||||
// Return in KBs
|
||||
return round(self::$size / 1024, 2) . ' KB';
|
||||
}
|
||||
|
||||
// Return in MBs
|
||||
return round(self::$size / (1024 * 1024), 2) . ' MB';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if folder is a parent path of something in the ignore list
|
||||
*/
|
||||
public static function isIgnoredParent($path)
|
||||
{
|
||||
$check = $path . '/';
|
||||
$len = strlen($check);
|
||||
|
||||
foreach (self::getIgnoreFolders() as $ignore_folder)
|
||||
{
|
||||
if (substr($ignore_folder, 0, $len) == $check)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function purgeTables()
|
||||
{
|
||||
}
|
||||
|
||||
public static function setError($error = true)
|
||||
{
|
||||
CC_Cache::setError($error);
|
||||
}
|
||||
|
||||
public static function setMessage($message = '')
|
||||
{
|
||||
CC_Cache::setMessage($message);
|
||||
}
|
||||
|
||||
public static function updateLog()
|
||||
{
|
||||
}
|
||||
}
|
||||
16
plugins/system/cachecleaner/src/Cache/CloudFlare.php
Normal file
16
plugins/system/cachecleaner/src/Cache/CloudFlare.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Cache Cleaner
|
||||
* @version 8.2.2
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link http://regularlabs.com
|
||||
* @copyright Copyright © 2022 Regular Labs All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
|
||||
*/
|
||||
|
||||
namespace RegularLabs\Plugin\System\CacheCleaner\Cache;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// Only used in Pro version
|
||||
35
plugins/system/cachecleaner/src/Cache/Folders.php
Normal file
35
plugins/system/cachecleaner/src/Cache/Folders.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Cache Cleaner
|
||||
* @version 8.2.2
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link http://regularlabs.com
|
||||
* @copyright Copyright © 2022 Regular Labs All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
|
||||
*/
|
||||
|
||||
namespace RegularLabs\Plugin\System\CacheCleaner\Cache;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use RegularLabs\Plugin\System\CacheCleaner\Params;
|
||||
|
||||
class Folders extends Cache
|
||||
{
|
||||
/**
|
||||
* Empty custom folder
|
||||
*/
|
||||
public static function purge_folders()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty tmp folder
|
||||
*/
|
||||
public static function purge_tmp()
|
||||
{
|
||||
$min_age = 0;
|
||||
self::emptyFolder(JPATH_SITE . '/tmp', $min_age);
|
||||
}
|
||||
}
|
||||
235
plugins/system/cachecleaner/src/Cache/Joomla.php
Normal file
235
plugins/system/cachecleaner/src/Cache/Joomla.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Cache Cleaner
|
||||
* @version 8.2.2
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link http://regularlabs.com
|
||||
* @copyright Copyright © 2022 Regular Labs All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
|
||||
*/
|
||||
|
||||
namespace RegularLabs\Plugin\System\CacheCleaner\Cache;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Cache\Cache as JCache;
|
||||
use Joomla\CMS\Cache\CacheController;
|
||||
use Joomla\CMS\Factory as JFactory;
|
||||
use RegularLabs\Library\DB as RL_DB;
|
||||
use RegularLabs\Plugin\System\CacheCleaner\Params;
|
||||
use RuntimeException;
|
||||
|
||||
class Joomla extends Cache
|
||||
{
|
||||
public static function checkIn()
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$tables = $db->getTableList();
|
||||
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
// make sure we get the right tables based on prefix
|
||||
if (strpos($table, $db->getPrefix()) !== 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$columns = RL_DB::getTableColumns($table, false);
|
||||
|
||||
if ( ! (isset($columns['checked_out']) && isset($columns['checked_out_time'])))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$query->clear()->update(RL_DB::quoteName($table));
|
||||
self::checkInAddCheckoutWheres($query, $columns);
|
||||
self::checkInAddCheckoutSets($query, $columns);
|
||||
|
||||
try
|
||||
{
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
JFactory::getApplication()->triggerEvent('onAfterCheckin', [$table]);
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkInAddCheckoutSets(&$query, $fields)
|
||||
{
|
||||
$query->set(RL_DB::quoteName('checked_out') . ' = DEFAULT');
|
||||
|
||||
if (isset($fields['editor']))
|
||||
{
|
||||
$query->set('editor = NULL');
|
||||
}
|
||||
|
||||
if ($fields['checked_out_time']->Null === 'YES')
|
||||
{
|
||||
$query->set(RL_DB::quoteName('checked_out_time') . ' = NULL');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$null_date = RL_DB::getNullDate();
|
||||
$query->set(RL_DB::quoteName('checked_out_time') . ' = :checkouttime')
|
||||
->bind(':checkouttime', $null_date);
|
||||
}
|
||||
|
||||
public static function checkInAddCheckoutWheres(&$query, $fields)
|
||||
{
|
||||
if ($fields['checked_out']->Null === 'YES')
|
||||
{
|
||||
$query->where(RL_DB::quoteName('checked_out') . ' IS NOT NULL');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$query->where(RL_DB::quoteName('checked_out') . ' > 0');
|
||||
}
|
||||
|
||||
public static function purge()
|
||||
{
|
||||
$cache = self::getCache();
|
||||
|
||||
if (isset($cache->options['storage']) && $cache->options['storage'] != 'file')
|
||||
{
|
||||
foreach ($cache->getAll() as $group)
|
||||
{
|
||||
$cache->clean($group->group);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$cache_path = JFactory::getConfig()->get('cache_path', JPATH_SITE . '/cache');
|
||||
|
||||
$min_age = 0;
|
||||
|
||||
self::emptyFolder($cache_path, $min_age);
|
||||
self::emptyFolder(JPATH_ADMINISTRATOR . '/cache', $min_age);
|
||||
|
||||
self::recreateNamespaceMap();
|
||||
}
|
||||
|
||||
public static function purgeDisabledRedirects()
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->delete('#__redirect_links')
|
||||
->where('published = ' . $db->quote(0));
|
||||
|
||||
$min_age_in_days = (int) Params::get()->purge_disabled_redirects_min_age;
|
||||
if ($min_age_in_days)
|
||||
{
|
||||
$to_date = JFactory::getDate()
|
||||
->modify('-' . $min_age_in_days . ' days')
|
||||
->toSql();
|
||||
|
||||
$query->where('modified_date < ' . $db->quote($to_date));
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
}
|
||||
|
||||
public static function purgeExpired()
|
||||
{
|
||||
$min_age = JFactory::getConfig()->get('cachetime');
|
||||
|
||||
if ( ! $min_age)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$cache_path = JFactory::getConfig()->get('cache_path', JPATH_SITE . '/cache');
|
||||
|
||||
self::emptyFolder($cache_path, $min_age);
|
||||
}
|
||||
|
||||
public static function purgeLiteSpeed()
|
||||
{
|
||||
}
|
||||
|
||||
public static function purgeOPcache()
|
||||
{
|
||||
}
|
||||
|
||||
public static function purgeUpdates()
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$db->setQuery('TRUNCATE TABLE #__updates');
|
||||
if ( ! $db->execute())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the last update check timestamp
|
||||
$query = $db->getQuery(true)
|
||||
->update('#__update_sites')
|
||||
->set('last_check_timestamp = ' . $db->quote(0));
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
}
|
||||
|
||||
private static function clearFileInOPCache($file)
|
||||
{
|
||||
$hasOpCache = ini_get('opcache.enable')
|
||||
&& function_exists('opcache_invalidate')
|
||||
&& (
|
||||
! ini_get('opcache.restrict_api')
|
||||
|| stripos(realpath($_SERVER['SCRIPT_FILENAME']), ini_get('opcache.restrict_api')) === 0
|
||||
);
|
||||
|
||||
if ( ! $hasOpCache)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return opcache_invalidate($file, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CacheController
|
||||
*/
|
||||
private static function getCache()
|
||||
{
|
||||
$conf = JFactory::getConfig();
|
||||
|
||||
$options = [
|
||||
'defaultgroup' => '',
|
||||
'storage' => $conf->get('cache_handler', ''),
|
||||
'caching' => true,
|
||||
'cachebase' => $conf->get('cache_path', JPATH_SITE . '/cache'),
|
||||
];
|
||||
|
||||
$cache = JCache::getInstance('callback', $options);
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
private static function recreateNamespaceMap()
|
||||
{
|
||||
// Remove the administrator/cache/autoload_psr4.php file
|
||||
$filename = JPATH_ADMINISTRATOR . '/cache/autoload_psr4.php';
|
||||
|
||||
if (file_exists($filename))
|
||||
{
|
||||
self::clearFileInOPCache($filename);
|
||||
clearstatcache(true, $filename);
|
||||
|
||||
@unlink($filename);
|
||||
}
|
||||
|
||||
JFactory::getApplication()->createExtensionNamespaceMap();
|
||||
}
|
||||
}
|
||||
16
plugins/system/cachecleaner/src/Cache/KeyCDN.php
Normal file
16
plugins/system/cachecleaner/src/Cache/KeyCDN.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Cache Cleaner
|
||||
* @version 8.2.2
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link http://regularlabs.com
|
||||
* @copyright Copyright © 2022 Regular Labs All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
|
||||
*/
|
||||
|
||||
namespace RegularLabs\Plugin\System\CacheCleaner\Cache;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// Only used in Pro version
|
||||
16
plugins/system/cachecleaner/src/Cache/SiteGround.php
Normal file
16
plugins/system/cachecleaner/src/Cache/SiteGround.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Cache Cleaner
|
||||
* @version 8.2.2
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link http://regularlabs.com
|
||||
* @copyright Copyright © 2022 Regular Labs All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
|
||||
*/
|
||||
|
||||
namespace RegularLabs\Plugin\System\CacheCleaner\Cache;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// Only used in Pro version
|
||||
16
plugins/system/cachecleaner/src/Cache/Tables.php
Normal file
16
plugins/system/cachecleaner/src/Cache/Tables.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Cache Cleaner
|
||||
* @version 8.2.2
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link http://regularlabs.com
|
||||
* @copyright Copyright © 2022 Regular Labs All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
|
||||
*/
|
||||
|
||||
namespace RegularLabs\Plugin\System\CacheCleaner\Cache;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// Only used in Pro version
|
||||
Reference in New Issue
Block a user