Added feature #14247: Add a concatenator for CSS and JS (thanks to Steffen Gebert)
[Packages/TYPO3.CMS.git] / typo3 / classes / class.clearcachemenu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2009 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 * $Id$
33 *
34 * @author Ingo Renner <ingo@typo3.org>
35 * @package TYPO3
36 * @subpackage core
37 */
38 class ClearCacheMenu implements backend_toolbarItem {
39
40 protected $cacheActions;
41 protected $optionValues;
42
43 /**
44 * reference back to the backend object
45 *
46 * @var TYPO3backend
47 */
48 protected $backendReference;
49
50 /**
51 * constructor
52 *
53 * @param TYPO3backend TYPO3 backend object reference
54 */
55 public function __construct(TYPO3backend &$backendReference = null) {
56 $this->backendReference = $backendReference;
57 $this->cacheActions = array();
58 $this->optionValues = array('all', 'pages');
59
60 // Clear cache for ALL tables!
61 if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) {
62 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_all', true);
63 $this->cacheActions[] = array(
64 'id' => 'all',
65 'title' => $title,
66 'href' => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=all',
67 'icon' => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning_red.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
68 );
69 }
70
71 // Clear cache for either ALL pages
72 if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
73 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_pages', true);
74 $this->cacheActions[] = array(
75 'id' => 'pages',
76 'title' => $title,
77 'href' => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=pages',
78 'icon' => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
79 );
80 }
81
82 // Clearing of cache-files in typo3conf/ + menu
83 if($GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) {
84 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_allTypo3Conf', true);
85 $this->cacheActions[] = array(
86 'id' => 'temp_CACHED',
87 'title' => $title,
88 'href' => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=temp_CACHED',
89 'icon' => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning_green.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
90 );
91 }
92
93 // hook for manipulate cacheActions
94 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) {
95 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] as $cacheAction) {
96 $hookObject = t3lib_div::getUserObj($cacheAction);
97
98 if(!($hookObject instanceof backend_cacheActionsHook)) {
99 throw new UnexpectedValueException('$hookObject must implement interface backend_cacheActionsHook', 1228262000);
100 }
101
102 $hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues);
103 }
104 }
105
106 }
107
108 /**
109 * checks whether the user has access to this toolbar item
110 *
111 * @return boolean true if user has access, false if not
112 */
113 public function checkAccess() {
114
115 if ($GLOBALS['BE_USER']->isAdmin()) {
116 return true;
117 }
118
119 if (is_array($this->optionValues)) {
120 foreach($this->optionValues as $value) {
121 if ($GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.' . $value)) {
122 return true;
123 }
124 }
125 }
126 return false;
127
128 }
129
130 /**
131 * Creates the selector for workspaces
132 *
133 * @return string workspace selector as HTML select
134 */
135 public function render() {
136 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_clearCache', true);
137 $this->addJavascriptToBackend();
138 $cacheMenu = array();
139
140 $cacheMenu[] = '<a href="#" class="toolbar-item"><img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" /></a>';
141
142 $cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
143
144 foreach($this->cacheActions as $actionKey => $cacheAction) {
145 $cacheMenu[] = '<li><a href="'.htmlspecialchars($cacheAction['href']).'">'.$cacheAction['icon'].' '.$cacheAction['title'].'</a></li>';
146 }
147
148 $cacheMenu[] = '</ul>';
149
150 return implode(LF, $cacheMenu);
151 }
152
153 /**
154 * adds the necessary JavaScript to the backend
155 *
156 * @return void
157 */
158 protected function addJavascriptToBackend() {
159 $this->backendReference->addJavascriptFile('js/clearcachemenu.js');
160 }
161
162 /**
163 * returns additional attributes for the list item in the toolbar
164 *
165 * @return string list item HTML attibutes
166 */
167 public function getAdditionalAttributes() {
168 return ' id="clear-cache-actions-menu"';
169 }
170
171 }
172
173 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']) {
174 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']);
175 }
176
177 ?>