CoreFiles by mySites.guru
DisplayController.php170 lines, 3,586 bytes, from Joomla_4.1.1-Stable-Full_Package.zip
Raw History Compare with 4.1.0
md5
c9bda646e9293e76d28f351a5f47637e
sha1
b0f4327c4856c885f20ccdac50d8adb608d0252c
sha256
662f3ac2575c7a6aef4bd6da1e3d1bda1353291b6c9bd4f4fe18f864eb23e866
<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_cache
 *
 * @copyright   (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Cache\Administrator\Controller;

\defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Response\JsonResponse;

/**
 * Cache Controller
 *
 * @since  1.6
 */
class DisplayController extends BaseController
{
	/**
	 * The default view for the display method.
	 *
	 * @var    string
	 * @since  4.0.0
	 */
	protected $default_view = 'cache';

	/**
	 * Method to get The Cache Size
	 *
	 * @since   4.0.0
	 */
	public function getQuickiconContent()
	{
		$model = $this->getModel('Cache');

		$data = $model->getData();

		$size = 0;

		if (!empty($data))
		{
			foreach ($data as $d)
			{
				$size += $d->size;
			}
		}

		// Number bytes are returned in format xxx.xx MB
		$bytes = HTMLHelper::_('number.bytes', $size, 'MB', 1);

		if (!empty($bytes))
		{
			$result['amount'] = $bytes;
			$result['sronly'] = Text::sprintf('COM_CACHE_QUICKICON_SRONLY', $bytes);
		}
		else
		{
			$result['amount'] = 0;
			$result['sronly'] = Text::sprintf('COM_CACHE_QUICKICON_SRONLY_NOCACHE');
		}

		echo new JsonResponse($result);
	}

	/**
	 * Method to delete a list of cache groups.
	 *
	 * @return  void
	 */
	public function delete()
	{
		// Check for request forgeries
		$this->checkToken();

		$cid = (array) $this->input->post->get('cid', array(), 'string');

		if (empty($cid))
		{
			$this->app->enqueueMessage(Text::_('JERROR_NO_ITEMS_SELECTED'), 'warning');
		}
		else
		{
			$result = $this->getModel('cache')->cleanlist($cid);

			if ($result !== array())
			{
				$this->app->enqueueMessage(Text::sprintf('COM_CACHE_EXPIRED_ITEMS_DELETE_ERROR', implode(', ', $result)), 'error');
			}
			else
			{
				$this->app->enqueueMessage(Text::_('COM_CACHE_EXPIRED_ITEMS_HAVE_BEEN_DELETED'), 'message');
			}
		}

		$this->setRedirect('index.php?option=com_cache');
	}

	/**
	 * Method to delete all cache groups.
	 *
	 * @return  void
	 *
	 * @since  3.6.0
	 */
	public function deleteAll()
	{
		// Check for request forgeries
		$this->checkToken();

		/** @var \Joomla\Component\Cache\Administrator\Model\CacheModel $model */
		$model      = $this->getModel('cache');
		$allCleared = true;

		$mCache = $model->getCache();

		foreach ($mCache->getAll() as $cache)
		{
			if ($mCache->clean($cache->group) === false)
			{
				$this->app->enqueueMessage(
					Text::sprintf(
						'COM_CACHE_EXPIRED_ITEMS_DELETE_ERROR', Text::_('JADMINISTRATOR') . ' > ' . $cache->group
					), 'error'
				);
				$allCleared = false;
			}
		}

		if ($allCleared)
		{
			$this->app->enqueueMessage(Text::_('COM_CACHE_MSG_ALL_CACHE_GROUPS_CLEARED'), 'message');
		}
		else
		{
			$this->app->enqueueMessage(Text::_('COM_CACHE_MSG_SOME_CACHE_GROUPS_CLEARED'), 'warning');
		}

		$this->app->triggerEvent('onAfterPurge', array());
		$this->setRedirect('index.php?option=com_cache&view=cache');
	}

	/**
	 * Purge the cache.
	 *
	 * @return  void
	 */
	public function purge()
	{
		// Check for request forgeries
		$this->checkToken();

		if (!$this->getModel('cache')->purge())
		{
			$this->app->enqueueMessage(Text::_('COM_CACHE_EXPIRED_ITEMS_PURGING_ERROR'), 'error');
		}
		else
		{
			$this->app->enqueueMessage(Text::_('COM_CACHE_EXPIRED_ITEMS_HAVE_BEEN_PURGED'), 'message');
		}

		$this->setRedirect('index.php?option=com_cache&view=cache');
	}
}

The same content is in 14 releases, Joomla 4.1.1 to 4.2.0-beta2. See them all, or every version of this file.