Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / sys_action / toolbarmenu / class.tx_sysaction_toolbarmenu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2011 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">'.
83 t3lib_iconWorks::getSpriteIcon('apps-toolbar-menu-actions', array('title' => $title)) .
84 '</a>';
85
86 $actionMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
87 foreach ($actionEntries as $linkConf) {
88 $actionMenu[] = '<li><a href="' . htmlspecialchars($linkConf[1]) .
89 '" target="content">' . $linkConf[2] .
90 htmlspecialchars($linkConf[0]) . '</a></li>';
91 }
92
93 $actionMenu[] = '</ul>';
94 return implode("\n", $actionMenu);
95 } else {
96 return '';
97 }
98
99
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 'pid = 0 AND hidden=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 'mod.php?M=user_task&SET[function]==sys_action.tx_sysaction_task&show=' . $actionRow['uid'],
143 t3lib_iconworks::getSpriteIconForRecord(
144 'sys_action',
145 $actionRow
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') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php'])) {
202 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php']);
203 }
204
205 ?>