833ab6f1f76c016a04fd52d3736e92394c7bac66
[Packages/TYPO3.CMS.git] / typo3 / sysext / sys_action / Classes / ActionToolbarMenu.php
1 <?php
2 namespace TYPO3\CMS\SysAction;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Steffen Kamper <info@sk-typo3.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 use TYPO3\CMS\Backend\Utility\BackendUtility;
27
28 /**
29 * Adds action links to the backend's toolbar
30 *
31 * @author Steffen Kamper <info@sk-typo3.de>
32 */
33 class ActionToolbarMenu implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {
34
35 /**
36 * Reference back to the backend object
37 *
38 * @var \TYPO3\CMS\Backend\Controller\BackendController
39 */
40 protected $backendReference;
41
42 /**
43 * @var string
44 */
45 protected $extensionKey = 'sys_action';
46
47 /**
48 * Constructor
49 */
50 public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
51 $GLOBALS['LANG']->includeLLFile('EXT:sys_action/locallang.xlf');
52 $this->backendReference = $backendReference;
53 }
54
55 /**
56 * Sets the backend reference
57 *
58 * @param \TYPO3\CMS\Backend\Controller\BackendController $backendReference Backend object reference
59 * @return void
60 */
61 public function setBackend(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference) {
62 $this->backendReference = $backendReference;
63 }
64
65 /**
66 * Renders the toolbar menu
67 *
68 * @return string The rendered backend menu
69 * @author Ingo Renner <ingo@typo3.org>
70 */
71 public function render() {
72 $actionMenu = array();
73 $actionEntries = $this->getActionEntries();
74 if ($actionEntries) {
75 $this->addJavascriptToBackend();
76 $this->addCssToBackend();
77 $title = $GLOBALS['LANG']->getLL('action_toolbaritem', TRUE);
78 $actionMenu[] = '<a href="#" class="toolbar-item">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-toolbar-menu-actions', array('title' => $title)) . '</a>';
79 $actionMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
80 foreach ($actionEntries as $linkConf) {
81 $actionMenu[] = '<li><a href="' . htmlspecialchars($linkConf[1]) . '" target="content">' . $linkConf[2] . htmlspecialchars($linkConf[0]) . '</a></li>';
82 }
83 $actionMenu[] = '</ul>';
84 return implode(LF, $actionMenu);
85 } else {
86 return '';
87 }
88 }
89
90 /**
91 * Gets the entries for the action menu
92 *
93 * @return array Array of action menu entries
94 * @author Steffen Kamper <info@sk-typo3.de>
95 * @author Ingo Renner <ingo@typo3.org>
96 */
97 protected function getActionEntries() {
98 $actions = array();
99 if ($GLOBALS['BE_USER']->isAdmin()) {
100 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'pid = 0 AND hidden=0', '', 'sys_action.sorting');
101 } else {
102 $groupList = 0;
103 if ($GLOBALS['BE_USER']->groupList) {
104 $groupList = $GLOBALS['BE_USER']->groupList;
105 }
106 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
107 'sys_action.*',
108 'sys_action',
109 'sys_action_asgr_mm',
110 'be_groups',
111 ' AND be_groups.uid IN (' . $groupList . ') AND sys_action.pid = 0 AND sys_action.hidden = 0',
112 'sys_action.uid',
113 'sys_action.sorting'
114 );
115 }
116
117 if ($queryResource) {
118 while ($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($queryResource)) {
119 $actions[] = array(
120 $actionRow['title'],
121 BackendUtility::getModuleUrl('user_task') . '&SET[mode]=tasks&SET[function]=sys_action.TYPO3\\CMS\\SysAction\\ActionTask&show=' . $actionRow['uid'],
122 \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_action', $actionRow)
123 );
124 }
125 $GLOBALS['TYPO3_DB']->sql_free_result($queryResource);
126 }
127 return $actions;
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="tx-sys-action-menu" ';
137 }
138
139 /**
140 * Adds the necessary javascript ot the backend
141 *
142 * @return void
143 */
144 protected function addJavascriptToBackend() {
145 $this->backendReference->addJavascriptFile(
146 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->extensionKey) . 'toolbarmenu/tx_sysactions.js'
147 );
148 }
149
150 /**
151 * Adds the necessary css ot the backend
152 *
153 * @return void
154 */
155 protected function addCssToBackend() {
156 $this->backendReference->addCssFile(
157 'sysaction',
158 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->extensionKey) . 'toolbarmenu/tx_sysactions.css'
159 );
160 }
161
162 /**
163 * Checks if user has access to the sys action menu
164 *
165 * @return boolean TRUE if the user has access, FALSE otherwise
166 */
167 public function checkAccess() {
168 // Taskcenter is enabled for everybody
169 return TRUE;
170 }
171
172 }