[BUGFIX] Using ext:sys_action gives a warning about not valid HTML
[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
27 /**
28 * Adds action links to the backend's toolbar
29 *
30 * @author Steffen Kamper <info@sk-typo3.de>
31 */
32 class ActionToolbarMenu implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {
33
34 /**
35 * Reference back to the backend object
36 *
37 * @var \TYPO3\CMS\Backend\Controller\BackendController
38 */
39 protected $backendReference;
40
41 /**
42 * @var string
43 */
44 protected $extensionKey = 'sys_action';
45
46 /**
47 * Constructor
48 */
49 public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
50 $GLOBALS['LANG']->includeLLFile('EXT:sys_action/locallang.xlf');
51 $this->backendReference = $backendReference;
52 }
53
54 /**
55 * Sets the backend reference
56 *
57 * @param \TYPO3\CMS\Backend\Controller\BackendController $backendReference Backend object reference
58 * @return void
59 */
60 public function setBackend(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference) {
61 $this->backendReference = $backendReference;
62 }
63
64 /**
65 * Renders the toolbar menu
66 *
67 * @return string The rendered backend menu
68 * @author Ingo Renner <ingo@typo3.org>
69 */
70 public function render() {
71 $actionMenu = array();
72 $actionEntries = $this->getActionEntries();
73 if ($actionEntries) {
74 $this->addJavascriptToBackend();
75 $this->addCssToBackend();
76 $title = $GLOBALS['LANG']->getLL('action_toolbaritem', TRUE);
77 $actionMenu[] = '<a href="#" class="toolbar-item">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-toolbar-menu-actions', array('title' => $title)) . '</a>';
78 $actionMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
79 foreach ($actionEntries as $linkConf) {
80 $actionMenu[] = '<li><a href="' . htmlspecialchars($linkConf[1]) . '" target="content">' . $linkConf[2] . htmlspecialchars($linkConf[0]) . '</a></li>';
81 }
82 $actionMenu[] = '</ul>';
83 return implode(LF, $actionMenu);
84 } else {
85 return '';
86 }
87 }
88
89 /**
90 * Gets the entries for the action menu
91 *
92 * @return array Array of action menu entries
93 * @author Steffen Kamper <info@sk-typo3.de>
94 * @author Ingo Renner <ingo@typo3.org>
95 */
96 protected function getActionEntries() {
97 $actions = array();
98 if ($GLOBALS['BE_USER']->isAdmin()) {
99 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'pid = 0 AND hidden=0', '', 'sys_action.sorting');
100 } else {
101 $groupList = 0;
102 if ($GLOBALS['BE_USER']->groupList) {
103 $groupList = $GLOBALS['BE_USER']->groupList;
104 }
105 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
106 'sys_action.*',
107 'sys_action',
108 'sys_action_asgr_mm',
109 'be_groups',
110 ' AND be_groups.uid IN (' . $groupList . ') AND sys_action.pid = 0 AND sys_action.hidden = 0',
111 'sys_action.uid',
112 'sys_action.sorting'
113 );
114 }
115
116 if ($queryResource) {
117 while ($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($queryResource)) {
118 $actions[] = array(
119 $actionRow['title'],
120 'mod.php?M=user_task&SET[mode]=tasks&SET[function]=sys_action.TYPO3\\CMS\\SysAction\\ActionTask&show=' . $actionRow['uid'],
121 \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_action', $actionRow)
122 );
123 }
124 $GLOBALS['TYPO3_DB']->sql_free_result($queryResource);
125 }
126 return $actions;
127 }
128
129 /**
130 * Returns additional attributes for the list item in the toolbar
131 *
132 * @return string List item HTML attibutes
133 */
134 public function getAdditionalAttributes() {
135 return 'id="tx-sys-action-menu" ';
136 }
137
138 /**
139 * Adds the neccessary javascript ot the backend
140 *
141 * @return void
142 */
143 protected function addJavascriptToBackend() {
144 $this->backendReference->addJavascriptFile(
145 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->extensionKey) . 'toolbarmenu/tx_sysactions.js'
146 );
147 }
148
149 /**
150 * Adds the neccessary css ot the backend
151 *
152 * @return void
153 */
154 protected function addCssToBackend() {
155 $this->backendReference->addCssFile(
156 'sysaction',
157 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->extensionKey) . 'toolbarmenu/tx_sysactions.css'
158 );
159 }
160
161 /**
162 * Checks if user has access to the sys action menu
163 *
164 * @return boolean TRUE if the user has access, FALSE otherwise
165 */
166 public function checkAccess() {
167 // Taskcenter is enabled for everybody
168 return TRUE;
169 }
170
171 }
172
173 ?>