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