d1e64b975f2533a03968c2a8a4fa7d8f0dd84eea
[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 }
98
99 return implode("\n", $actionMenu);
100 }
101
102 /**
103 * gets the entries for the action menu
104 *
105 * @return array array of action menu entries
106 * @author Steffen Kamper <info@sk-typo3.de>
107 * @author Ingo Renner <ingo@typo3.org>
108 */
109 protected function getActionEntries() {
110 $actions = array();
111
112 if ($GLOBALS['BE_USER']->isAdmin()) {
113 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
114 '*',
115 'sys_action',
116 'sys_action.pid = 0',
117 '',
118 'sys_action.sorting'
119 );
120 } else {
121 $groupList = 0;
122 if ($GLOBALS['BE_USER']->groupList) {
123 $groupList = $GLOBALS['BE_USER']->groupList;
124 }
125
126 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
127 'sys_action.*',
128 'sys_action',
129 'sys_action_asgr_mm',
130 'be_groups',
131 ' AND be_groups.uid IN (' . $groupList .
132 ') AND sys_action.pid = 0 AND sys_action.hidden = 0',
133 'sys_action.uid',
134 'sys_action.sorting'
135 );
136 }
137
138 if ($queryResource) {
139 while ($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($queryResource)) {
140 $actions[] = array(
141 $actionRow['title'],
142 'sysext/taskcenter/task/index.php?SET[function]=tx_sysaction&sys_action_uid=' . $actionRow['uid'],
143 t3lib_iconworks::getIconImage(
144 'sys_action',
145 $actionRow,
146 $GLOBALS['BACK_PATH'],
147 'hspace="2" class="absmiddle"'
148 ),
149 );
150 }
151
152 $GLOBALS['TYPO3_DB']->sql_free_result($queryResource);
153 }
154
155 return $actions;
156 }
157
158 /**
159 * returns additional attributes for the list item in the toolbar
160 *
161 * @return string list item HTML attibutes
162 */
163 public function getAdditionalAttributes() {
164 return ' id="tx-sys-action-menu"';
165 }
166
167 /**
168 * adds the neccessary javascript ot the backend
169 *
170 * @return void
171 */
172 protected function addJavascriptToBackend() {
173 $this->backendReference->addJavascriptFile(
174 t3lib_extMgm::extRelPath($this->EXTKEY) . 'toolbarmenu/tx_sysactions.js'
175 );
176 }
177
178 /**
179 * adds the neccessary css ot the backend
180 *
181 * @return void
182 */
183 protected function addCssToBackend() {
184 $this->backendReference->addCssFile(
185 'sysaction',
186 t3lib_extMgm::extRelPath($this->EXTKEY) .
187 'toolbarmenu/tx_sysactions.css'
188 );
189 }
190
191 /**
192 * Checks if user has access to the sys action menu
193 *
194 * @return boolean true if the user has access, false otherwise
195 */
196 public function checkAccess() {
197 // taskcenter is enabled for everybody
198 return true;
199 }
200 }
201
202
203 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php']) {
204 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php']);
205 }
206
207 ?>