[BUGFIX] Missing XCLASS statement for class LiveSearch
[Packages/TYPO3.CMS.git] / typo3 / classes / class.clearcachemenu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2011 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28
29 /**
30 * class to render the menu for the cache clearing actions
31 *
32 * @author Ingo Renner <ingo@typo3.org>
33 * @package TYPO3
34 * @subpackage core
35 */
36 class ClearCacheMenu implements backend_toolbarItem {
37
38 protected $cacheActions;
39 protected $optionValues;
40
41 /**
42 * reference back to the backend object
43 *
44 * @var TYPO3backend
45 */
46 protected $backendReference;
47
48 /**
49 * constructor
50 *
51 * @param TYPO3backend TYPO3 backend object reference
52 */
53 public function __construct(TYPO3backend &$backendReference = NULL) {
54 $this->backendReference = $backendReference;
55 $this->cacheActions = array();
56 $this->optionValues = array('all', 'pages');
57
58 // Clear cache for ALL tables!
59 if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) {
60 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_all', TRUE);
61 $this->cacheActions[] = array(
62 'id' => 'all',
63 'title' => $title,
64 'href' => $this->backPath .
65 'tce_db.php?vC=' .
66 $GLOBALS['BE_USER']->veriCode() .
67 '&cacheCmd=all&ajaxCall=1' .
68 t3lib_BEfunc::getUrlToken('tceAction'),
69 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-high')
70 );
71 }
72
73 // Clear cache for either ALL pages
74 if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
75 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_pages', TRUE);
76 $this->cacheActions[] = array(
77 'id' => 'pages',
78 'title' => $title,
79 'href' => $this->backPath .
80 'tce_db.php?vC=' .
81 $GLOBALS['BE_USER']->veriCode() .
82 '&cacheCmd=pages&ajaxCall=1' .
83 t3lib_BEfunc::getUrlToken('tceAction'),
84 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-medium')
85 );
86 }
87
88 // Clearing of cache-files in typo3conf/ + menu
89 if($GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) {
90 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_allTypo3Conf', TRUE);
91 $this->cacheActions[] = array(
92 'id' => 'temp_CACHED',
93 'title' => $title,
94 'href' => $this->backPath .
95 'tce_db.php?vC=' .
96 $GLOBALS['BE_USER']->veriCode() .
97 '&cacheCmd=temp_CACHED&ajaxCall=1' .
98 t3lib_BEfunc::getUrlToken('tceAction'),
99 'icon' => t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear-impact-low')
100 );
101 }
102
103 // hook for manipulate cacheActions
104 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) {
105 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] as $cacheAction) {
106 $hookObject = t3lib_div::getUserObj($cacheAction);
107
108 if(!($hookObject instanceof backend_cacheActionsHook)) {
109 throw new UnexpectedValueException('$hookObject must implement interface backend_cacheActionsHook', 1228262000);
110 }
111
112 $hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues);
113 }
114 }
115 }
116
117 /**
118 * checks whether the user has access to this toolbar item
119 *
120 * @return boolean TRUE if user has access, FALSE if not
121 */
122 public function checkAccess() {
123
124 if ($GLOBALS['BE_USER']->isAdmin()) {
125 return TRUE;
126 }
127
128 if (is_array($this->optionValues)) {
129 foreach($this->optionValues as $value) {
130 if ($GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.' . $value)) {
131 return TRUE;
132 }
133 }
134 }
135 return FALSE;
136
137 }
138
139 /**
140 * Creates the selector for workspaces
141 *
142 * @return string workspace selector as HTML select
143 */
144 public function render() {
145 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_clearCache', TRUE);
146 $this->addJavascriptToBackend();
147 $cacheMenu = array();
148
149 $cacheMenu[] = '<a href="#" class="toolbar-item">' .
150 t3lib_iconWorks::getSpriteIcon('apps-toolbar-menu-cache', array('title' => $title)) .
151 '</a>';
152
153 $cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
154
155 foreach($this->cacheActions as $actionKey => $cacheAction) {
156 $cacheMenu[] = '<li><a href="'.htmlspecialchars($cacheAction['href']).'">'.$cacheAction['icon'].' '.$cacheAction['title'].'</a></li>';
157 }
158
159 $cacheMenu[] = '</ul>';
160
161 return implode(LF, $cacheMenu);
162 }
163
164 /**
165 * adds the necessary JavaScript to the backend
166 *
167 * @return void
168 */
169 protected function addJavascriptToBackend() {
170 $this->backendReference->addJavascriptFile('js/clearcachemenu.js');
171 }
172
173 /**
174 * returns additional attributes for the list item in the toolbar
175 *
176 * @return string list item HTML attibutes
177 */
178 public function getAdditionalAttributes() {
179 return ' id="clear-cache-actions-menu"';
180 }
181
182 }
183
184 if(defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']) {
185 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']);
186 }
187
188 ?>