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