[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_cache 6 * 7 * @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Cache\Administrator\Controller; 12 13 use Joomla\CMS\HTML\HTMLHelper; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\MVC\Controller\BaseController; 16 use Joomla\CMS\Response\JsonResponse; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('_JEXEC') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Cache Controller 24 * 25 * @since 1.6 26 */ 27 class DisplayController extends BaseController 28 { 29 /** 30 * The default view for the display method. 31 * 32 * @var string 33 * @since 4.0.0 34 */ 35 protected $default_view = 'cache'; 36 37 /** 38 * Method to get The Cache Size 39 * 40 * @since 4.0.0 41 */ 42 public function getQuickiconContent() 43 { 44 $model = $this->getModel('Cache'); 45 46 $data = $model->getData(); 47 48 $size = 0; 49 50 if (!empty($data)) { 51 foreach ($data as $d) { 52 $size += $d->size; 53 } 54 } 55 56 // Number bytes are returned in format xxx.xx MB 57 $bytes = HTMLHelper::_('number.bytes', $size, 'MB', 1); 58 59 if (!empty($bytes)) { 60 $result['amount'] = $bytes; 61 $result['sronly'] = Text::sprintf('COM_CACHE_QUICKICON_SRONLY', $bytes); 62 } else { 63 $result['amount'] = 0; 64 $result['sronly'] = Text::sprintf('COM_CACHE_QUICKICON_SRONLY_NOCACHE'); 65 } 66 67 echo new JsonResponse($result); 68 } 69 70 /** 71 * Method to delete a list of cache groups. 72 * 73 * @return void 74 */ 75 public function delete() 76 { 77 // Check for request forgeries 78 $this->checkToken(); 79 80 $cid = (array) $this->input->post->get('cid', array(), 'string'); 81 82 if (empty($cid)) { 83 $this->app->enqueueMessage(Text::_('JERROR_NO_ITEMS_SELECTED'), 'warning'); 84 } else { 85 $result = $this->getModel('cache')->cleanlist($cid); 86 87 if ($result !== array()) { 88 $this->app->enqueueMessage(Text::sprintf('COM_CACHE_EXPIRED_ITEMS_DELETE_ERROR', implode(', ', $result)), 'error'); 89 } else { 90 $this->app->enqueueMessage(Text::_('COM_CACHE_EXPIRED_ITEMS_HAVE_BEEN_DELETED'), 'message'); 91 } 92 } 93 94 $this->setRedirect('index.php?option=com_cache'); 95 } 96 97 /** 98 * Method to delete all cache groups. 99 * 100 * @return void 101 * 102 * @since 3.6.0 103 */ 104 public function deleteAll() 105 { 106 // Check for request forgeries 107 $this->checkToken(); 108 109 /** @var \Joomla\Component\Cache\Administrator\Model\CacheModel $model */ 110 $model = $this->getModel('cache'); 111 $allCleared = true; 112 113 $mCache = $model->getCache(); 114 115 foreach ($mCache->getAll() as $cache) { 116 if ($mCache->clean($cache->group) === false) { 117 $this->app->enqueueMessage( 118 Text::sprintf( 119 'COM_CACHE_EXPIRED_ITEMS_DELETE_ERROR', 120 Text::_('JADMINISTRATOR') . ' > ' . $cache->group 121 ), 122 'error' 123 ); 124 $allCleared = false; 125 } 126 } 127 128 if ($allCleared) { 129 $this->app->enqueueMessage(Text::_('COM_CACHE_MSG_ALL_CACHE_GROUPS_CLEARED'), 'message'); 130 } else { 131 $this->app->enqueueMessage(Text::_('COM_CACHE_MSG_SOME_CACHE_GROUPS_CLEARED'), 'warning'); 132 } 133 134 $this->app->triggerEvent('onAfterPurge', array()); 135 $this->setRedirect('index.php?option=com_cache&view=cache'); 136 } 137 138 /** 139 * Purge the cache. 140 * 141 * @return void 142 */ 143 public function purge() 144 { 145 // Check for request forgeries 146 $this->checkToken(); 147 148 if (!$this->getModel('cache')->purge()) { 149 $this->app->enqueueMessage(Text::_('COM_CACHE_EXPIRED_ITEMS_PURGING_ERROR'), 'error'); 150 } else { 151 $this->app->enqueueMessage(Text::_('COM_CACHE_EXPIRED_ITEMS_HAVE_BEEN_PURGED'), 'message'); 152 } 153 154 $this->setRedirect('index.php?option=com_cache&view=cache'); 155 } 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |