Fixed bug #10179: sys_action menu doesn't respect hidden and returns empty ul if...
[Packages/TYPO3.CMS.git] / typo3 / sysext / sys_action / toolbarmenu / class.tx_sysaction_toolbarmenu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 Steffen Kamper <info@sk-typo3.de>
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 // load the language file
29 $GLOBALS['LANG']->includeLLFile('EXT:sys_action/locallang.xml');
30
31 /**
32 * Adds action links to the backend's toolbar
33 *
34 * @author Steffen Kamper <info@sk-typo3.de>
35 * @package TYPO3
36 * @subpackage tx_sysaction
37 */
38 class tx_sysactionToolbarMenu implements backend_toolbarItem {
39
40 /**
41 * reference back to the backend object
42 *
43 * @var TYPO3backend
44 */
45 protected $backendReference;
46 protected $EXTKEY = 'sys_action';
47
48 /**
49 * constructor
50 *
51 * @return void
52 */
53 public function __construct(TYPO3backend &$backendReference = null) {
54 $this->backendReference = $backendReference;
55 }
56
57 /**
58 * sets the backend reference
59 *
60 * @param TYPO3backend backend object reference
61 * @return void
62 */
63 public function setBackend(TYPO3backend &$backendReference) {
64 $this->backendReference = $backendReference;
65 }
66
67 /**
68 * renders the toolbar menu
69 *
70 * @return string the rendered backend menu
71 * @author Ingo Renner <ingo@typo3.org>
72 */
73 public function render() {
74 $actionMenu = array();
75 $actionEntries = $this->getActionEntries();
76
77 if ($actionEntries) {
78 $this->addJavascriptToBackend();
79 $this->addCssToBackend();
80 $title = $GLOBALS['LANG']->getLL('action_toolbaritem', true);
81
82 $actionMenu[] = '<a href="#" class="toolbar-item"><img' .
83 t3lib_iconWorks::skinImg(
84 $this->backPath,
85 t3lib_extMgm::extRelPath($this->EXTKEY) . 'ext_icon.gif',
86 'width="16" height="16"'
87 ) . ' title="' . $title . '" alt="' . $title . '" /></a>';
88
89 $actionMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
90 foreach ($actionEntries as $linkConf) {
91 $actionMenu[] = '<li><a href="' . $linkConf[1] .
92 '" target="content">' . $linkConf[2] .
93 htmlspecialchars($linkConf[0]) . '</a></li>';
94 }
95
96 $actionMenu[] = '</ul>';
97 return implode("\n", $actionMenu);
98 } else {
99 return '';
100 }
101
102
103 }
104
105 /**
106 * gets the entries for the action menu
107 *
108 * @return array array of action menu entries
109 * @author Steffen Kamper <info@sk-typo3.de>
110 * @author Ingo Renner <ingo@typo3.org>
111 */
112 protected function getActionEntries() {
113 $actions = array();
114
115 if ($GLOBALS['BE_USER']->isAdmin()) {
116 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
117 '*',
118 'sys_action',
119 'pid = 0 AND hidden=0',
120 '',
121 'sys_action.sorting'
122 );
123 } else {
124 $groupList = 0;
125 if ($GLOBALS['BE_USER']->groupList) {
126 $groupList = $GLOBALS['BE_USER']->groupList;
127 }
128
129 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
130 'sys_action.*',
131 'sys_action',
132 'sys_action_asgr_mm',
133 'be_groups',
134 ' AND be_groups.uid IN (' . $groupList .
135 ') AND sys_action.pid = 0 AND sys_action.hidden = 0',
136 'sys_action.uid',
137 'sys_action.sorting'
138 );
139 }
140
141 if ($queryResource) {
142 while ($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($queryResource)) {
143 $actions[] = array(
144 $actionRow['title'],
145 'sysext/taskcenter/task/index.php?SET[function]=tx_sysaction&sys_action_uid=' . $actionRow['uid'],
146 t3lib_iconworks::getIconImage(
147 'sys_action',
148 $actionRow,
149 $GLOBALS['BACK_PATH'],
150 'hspace="2" class="absmiddle"'
151 ),
152 );
153 }
154
155 $GLOBALS['TYPO3_DB']->sql_free_result($queryResource);
156 }
157
158 return $actions;
159 }
160
161 /**
162 * returns additional attributes for the list item in the toolbar
163 *
164 * @return string list item HTML attibutes
165 */
166 public function getAdditionalAttributes() {
167 return ' id="tx-sys-action-menu"';
168 }
169
170 /**
171 * adds the neccessary javascript ot the backend
172 *
173 * @return void
174 */
175 protected function addJavascriptToBackend() {
176 $this->backendReference->addJavascriptFile(
177 t3lib_extMgm::extRelPath($this->EXTKEY) . 'toolbarmenu/tx_sysactions.js'
178 );
179 }
180
181 /**
182 * adds the neccessary css ot the backend
183 *
184 * @return void
185 */
186 protected function addCssToBackend() {
187 $this->backendReference->addCssFile(
188 'sysaction',
189 t3lib_extMgm::extRelPath($this->EXTKEY) .
190 'toolbarmenu/tx_sysactions.css'
191 );
192 }
193
194 /**
195 * Checks if user has access to the sys action menu
196 *
197 * @return boolean true if the user has access, false otherwise
198 */
199 public function checkAccess() {
200 // taskcenter is enabled for everybody
201 return true;
202 }
203 }
204
205
206 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php']) {
207 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php']);
208 }
209
210 ?>