Follow Up for #8270: fixed some naming and CGL issues
[Packages/TYPO3.CMS.git] / typo3 / classes / class.clearcachemenu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2008 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
42 /**
43 * reference back to the backend object
44 *
45 * @var TYPO3backend
46 */
47 protected $backendReference;
48
49 /**
50 * constructor
51 *
52 * @param TYPO3backend TYPO3 backend object reference
53 */
54 public function __construct(TYPO3backend &$backendReference = null) {
55 $this->backendReference = $backendReference;
56 $this->cacheActions = array();
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.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=all',
65 'icon' => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning_red.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
66 );
67 }
68
69 // Clear cache for either ALL pages
70 if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
71 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_pages', true);
72 $this->cacheActions[] = array(
73 'id' => 'pages',
74 'title' => $title,
75 'href' => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=pages',
76 'icon' => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
77 );
78 }
79
80 // Clearing of cache-files in typo3conf/ + menu
81 if($GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) {
82 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_allTypo3Conf', true);
83 $this->cacheActions[] = array(
84 'id' => 'temp_CACHED',
85 'title' => $title,
86 'href' => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=temp_CACHED',
87 'icon' => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning_green.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
88 );
89 }
90
91 }
92
93 /**
94 * checks whether the user has access to this toolbar item
95 *
96 * @return boolean true if user has access, false if not
97 */
98 public function checkAccess() {
99 return (
100 $GLOBALS['BE_USER']->isAdmin()
101 || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')
102 || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')
103 );
104 }
105
106 /**
107 * Creates the selector for workspaces
108 *
109 * @return string workspace selector as HTML select
110 */
111 public function render() {
112 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_clearCache', true);
113 $this->addJavascriptToBackend();
114 $cacheMenu = array();
115
116 $cacheMenu[] = '<a href="#" class="toolbar-item"><img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" /></a>';
117
118 $cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
119
120 foreach($this->cacheActions as $actionKey => $cacheAction) {
121 $cacheMenu[] = '<li><a href="'.htmlspecialchars($cacheAction['href']).'">'.$cacheAction['icon'].' '.$cacheAction['title'].'</a></li>';
122 }
123
124 $cacheMenu[] = '</ul>';
125
126 return implode("\n", $cacheMenu);
127 }
128
129 /**
130 * adds the necessary JavaScript to the backend
131 *
132 * @return void
133 */
134 protected function addJavascriptToBackend() {
135 $this->backendReference->addJavascriptFile('js/clearcachemenu.js');
136 }
137
138 /**
139 * returns additional attributes for the list item in the toolbar
140 *
141 * @return string list item HTML attibutes
142 */
143 public function getAdditionalAttributes() {
144 return ' id="clear-cache-actions-menu"';
145 }
146
147 }
148
149 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']) {
150 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']);
151 }
152
153 ?>