[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / sys_action / Classes / ActionToolbarMenu.php
1 <?php
2 namespace TYPO3\CMS\SysAction;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Backend\Utility\BackendUtility;
17
18 /**
19 * Adds action links to the backend's toolbar
20 *
21 * @author Steffen Kamper <info@sk-typo3.de>
22 */
23 class ActionToolbarMenu implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {
24
25 /**
26 * Reference back to the backend object
27 *
28 * @var \TYPO3\CMS\Backend\Controller\BackendController
29 */
30 protected $backendReference;
31
32 /**
33 * @var string
34 */
35 protected $extensionKey = 'sys_action';
36
37 /**
38 * Constructor
39 */
40 public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
41 $GLOBALS['LANG']->includeLLFile('EXT:sys_action/locallang.xlf');
42 $this->backendReference = $backendReference;
43 }
44
45 /**
46 * Sets the backend reference
47 *
48 * @param \TYPO3\CMS\Backend\Controller\BackendController $backendReference Backend object reference
49 * @return void
50 */
51 public function setBackend(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference) {
52 $this->backendReference = $backendReference;
53 }
54
55 /**
56 * Renders the toolbar menu
57 *
58 * @return string The rendered backend menu
59 * @author Ingo Renner <ingo@typo3.org>
60 */
61 public function render() {
62 $actionMenu = array();
63 $actionEntries = $this->getActionEntries();
64 if ($actionEntries) {
65 $this->addJavascriptToBackend();
66 $this->addCssToBackend();
67 $title = $GLOBALS['LANG']->getLL('action_toolbaritem', TRUE);
68 $actionMenu[] = '<a href="#" class="toolbar-item">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-toolbar-menu-actions', array('title' => $title)) . '</a>';
69 $actionMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
70 foreach ($actionEntries as $linkConf) {
71 $actionMenu[] = '<li><a href="' . htmlspecialchars($linkConf[1]) . '" target="content">' . $linkConf[2] . htmlspecialchars($linkConf[0]) . '</a></li>';
72 }
73 $actionMenu[] = '</ul>';
74 return implode(LF, $actionMenu);
75 } else {
76 return '';
77 }
78 }
79
80 /**
81 * Gets the entries for the action menu
82 *
83 * @return array Array of action menu entries
84 * @author Steffen Kamper <info@sk-typo3.de>
85 * @author Ingo Renner <ingo@typo3.org>
86 */
87 protected function getActionEntries() {
88 $actions = array();
89 if ($GLOBALS['BE_USER']->isAdmin()) {
90 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'pid = 0 AND hidden=0', '', 'sys_action.sorting');
91 } else {
92 $groupList = 0;
93 if ($GLOBALS['BE_USER']->groupList) {
94 $groupList = $GLOBALS['BE_USER']->groupList;
95 }
96 $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
97 'sys_action.*',
98 'sys_action',
99 'sys_action_asgr_mm',
100 'be_groups',
101 ' AND be_groups.uid IN (' . $groupList . ') AND sys_action.pid = 0 AND sys_action.hidden = 0',
102 'sys_action.uid',
103 'sys_action.sorting'
104 );
105 }
106
107 if ($queryResource) {
108 while ($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($queryResource)) {
109 $actions[] = array(
110 $actionRow['title'],
111 BackendUtility::getModuleUrl('user_task') . '&SET[mode]=tasks&SET[function]=sys_action.TYPO3\\CMS\\SysAction\\ActionTask&show=' . $actionRow['uid'],
112 \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_action', $actionRow)
113 );
114 }
115 $GLOBALS['TYPO3_DB']->sql_free_result($queryResource);
116 }
117 return $actions;
118 }
119
120 /**
121 * Returns additional attributes for the list item in the toolbar
122 *
123 * @return string List item HTML attibutes
124 */
125 public function getAdditionalAttributes() {
126 return 'id="tx-sys-action-menu"';
127 }
128
129 /**
130 * Adds the necessary javascript ot the backend
131 *
132 * @return void
133 */
134 protected function addJavascriptToBackend() {
135 $this->backendReference->addJavascriptFile(
136 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->extensionKey) . 'toolbarmenu/tx_sysactions.js'
137 );
138 }
139
140 /**
141 * Adds the necessary css ot the backend
142 *
143 * @return void
144 */
145 protected function addCssToBackend() {
146 $this->backendReference->addCssFile(
147 'sysaction',
148 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->extensionKey) . 'toolbarmenu/tx_sysactions.css'
149 );
150 }
151
152 /**
153 * Checks if user has access to the sys action menu
154 *
155 * @return boolean TRUE if the user has access, FALSE otherwise
156 */
157 public function checkAccess() {
158 // Taskcenter is enabled for everybody
159 return TRUE;
160 }
161
162 }