1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace TYPO3\CMS\Adminpanel\Service; |
5
|
|
|
|
6
|
|
|
/* |
7
|
|
|
* This file is part of the TYPO3 CMS project. |
8
|
|
|
* |
9
|
|
|
* It is free software; you can redistribute it and/or modify it under |
10
|
|
|
* the terms of the GNU General Public License, either version 2 |
11
|
|
|
* of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* For the full copyright and license information, please read the |
14
|
|
|
* LICENSE.txt file that was distributed with this source code. |
15
|
|
|
* |
16
|
|
|
* The TYPO3 project - inspiring people to share! |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication; |
20
|
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder; |
21
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
22
|
|
|
use TYPO3\CMS\Core\Context\Context; |
23
|
|
|
use TYPO3\CMS\Core\Context\LanguageAspect; |
24
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
25
|
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer; |
26
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
27
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
28
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
29
|
|
|
use TYPO3\CMS\Core\Type\Bitmask\Permission; |
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
31
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class for the Edit Toolbar |
35
|
|
|
* |
36
|
|
|
* @internal |
37
|
|
|
*/ |
38
|
|
|
class EditToolbarService |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Creates the tool bar links for the "edit" section of the Admin Panel. |
43
|
|
|
* |
44
|
|
|
* @return string A string containing images wrapped in <a>-tags linking them to proper functions. |
45
|
|
|
*/ |
46
|
|
|
public function createToolbar(): string |
47
|
|
|
{ |
48
|
|
|
/** @var LanguageAspect $languageAspect */ |
49
|
|
|
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language'); |
50
|
|
|
$iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
51
|
|
|
$tsfe = $this->getTypoScriptFrontendController(); |
52
|
|
|
// If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead: |
53
|
|
|
$moduleName = BackendUtility::getPagesTSconfig($tsfe->page['uid'])['mod.']['newContentElementWizard.']['override'] ?? 'new_content_element'; |
54
|
|
|
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
55
|
|
|
$perms = $this->getBackendUser()->calcPerms($tsfe->page); |
56
|
|
|
$langAllowed = $this->getBackendUser()->checkLanguageAccess($languageAspect->getId()); |
57
|
|
|
$id = $tsfe->id; |
58
|
|
|
$returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI'); |
59
|
|
|
$classes = 'typo3-adminPanel-btn typo3-adminPanel-btn-default'; |
60
|
|
|
$output = []; |
61
|
|
|
$output[] = '<div class="typo3-adminPanel-form-group">'; |
62
|
|
|
$output[] = ' <div class="typo3-adminPanel-btn-group" role="group">'; |
63
|
|
|
|
64
|
|
|
// History |
65
|
|
|
$link = (string)$uriBuilder->buildUriFromRoute( |
66
|
|
|
'record_history', |
67
|
|
|
[ |
68
|
|
|
'element' => 'pages:' . $id, |
69
|
|
|
'returnUrl' => $returnUrl, |
70
|
|
|
] |
71
|
|
|
); |
72
|
|
|
$title = $this->getLabel('edit_recordHistory'); |
73
|
|
|
$output[] = '<a class="' . |
74
|
|
|
$classes . |
75
|
|
|
'" href="' . |
76
|
|
|
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
77
|
|
|
'#latest" title="' . |
78
|
|
|
$title . |
79
|
|
|
'">'; |
80
|
|
|
$output[] = ' ' . $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render(); |
81
|
|
|
$output[] = '</a>'; |
82
|
|
|
|
83
|
|
|
// New Content |
84
|
|
|
if ($perms & Permission::CONTENT_EDIT && $langAllowed) { |
85
|
|
|
$linkParameters = [ |
86
|
|
|
'id' => $id, |
87
|
|
|
'returnUrl' => $returnUrl, |
88
|
|
|
]; |
89
|
|
|
if (!empty($languageAspect->getId())) { |
90
|
|
|
$linkParameters['sys_language_uid'] = $languageAspect->getId(); |
91
|
|
|
} |
92
|
|
|
$link = (string)$uriBuilder->buildUriFromRoute($moduleName, $linkParameters); |
93
|
|
|
$icon = $iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render(); |
94
|
|
|
$title = $this->getLabel('edit_newContentElement'); |
95
|
|
|
$output[] = '<a class="' . |
96
|
|
|
$classes . |
97
|
|
|
'" href="' . |
98
|
|
|
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
99
|
|
|
'" title="' . |
100
|
|
|
$title . |
101
|
|
|
'">'; |
102
|
|
|
$output[] = ' ' . $icon; |
103
|
|
|
$output[] = '</a>'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// Move Page |
107
|
|
|
if ($perms & Permission::PAGE_EDIT) { |
108
|
|
|
$link = (string)$uriBuilder->buildUriFromRoute( |
109
|
|
|
'move_element', |
110
|
|
|
[ |
111
|
|
|
'table' => 'pages', |
112
|
|
|
'uid' => $id, |
113
|
|
|
'returnUrl' => $returnUrl, |
114
|
|
|
] |
115
|
|
|
); |
116
|
|
|
$icon = $iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL)->render(); |
117
|
|
|
$title = $this->getLabel('edit_move_page'); |
118
|
|
|
$output[] = '<a class="' . |
119
|
|
|
$classes . |
120
|
|
|
'" href="' . |
121
|
|
|
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
122
|
|
|
'" title="' . |
123
|
|
|
$title . |
124
|
|
|
'">'; |
125
|
|
|
$output[] = ' ' . $icon; |
126
|
|
|
$output[] = '</a>'; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// New Page |
130
|
|
|
if ($perms & Permission::PAGE_NEW) { |
131
|
|
|
$link = (string)$uriBuilder->buildUriFromRoute( |
132
|
|
|
'db_new', |
133
|
|
|
[ |
134
|
|
|
'id' => $id, |
135
|
|
|
'pagesOnly' => 1, |
136
|
|
|
'returnUrl' => $returnUrl, |
137
|
|
|
] |
138
|
|
|
); |
139
|
|
|
$icon = $iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render(); |
140
|
|
|
$title = $this->getLabel('edit_newPage'); |
141
|
|
|
$output[] = '<a class="' . |
142
|
|
|
$classes . |
143
|
|
|
'" href="' . |
144
|
|
|
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
145
|
|
|
'" title="' . |
146
|
|
|
$title . |
147
|
|
|
'">'; |
148
|
|
|
$output[] = ' ' . $icon; |
149
|
|
|
$output[] = '</a>'; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
// Edit Page |
153
|
|
|
if ($perms & Permission::PAGE_EDIT) { |
154
|
|
|
$link = (string)$uriBuilder->buildUriFromRoute( |
155
|
|
|
'record_edit', |
156
|
|
|
[ |
157
|
|
|
'edit[pages][' . $id . ']' => 'edit', |
158
|
|
|
'noView' => 1, |
159
|
|
|
'returnUrl' => $returnUrl, |
160
|
|
|
] |
161
|
|
|
); |
162
|
|
|
$icon = $iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render(); |
163
|
|
|
$title = $this->getLabel('edit_editPageProperties'); |
164
|
|
|
$output[] = '<a class="' . |
165
|
|
|
$classes . |
166
|
|
|
'" href="' . |
167
|
|
|
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
168
|
|
|
'" title="' . |
169
|
|
|
$title . |
170
|
|
|
'">'; |
171
|
|
|
$output[] = ' ' . $icon; |
172
|
|
|
$output[] = '</a>'; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
// Edit Page Overlay |
176
|
|
|
if ($perms & Permission::PAGE_EDIT && $languageAspect->getId() > 0 && $langAllowed) { |
177
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
178
|
|
|
->getQueryBuilderForTable('pages'); |
179
|
|
|
$queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class)); |
180
|
|
|
$row = $queryBuilder |
181
|
|
|
->select('uid', 'pid', 't3ver_state') |
182
|
|
|
->from('pages') |
183
|
|
|
->where( |
184
|
|
|
$queryBuilder->expr()->eq( |
185
|
|
|
$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'], |
186
|
|
|
$queryBuilder->createNamedParameter($id, \PDO::PARAM_INT) |
187
|
|
|
), |
188
|
|
|
$queryBuilder->expr()->eq( |
189
|
|
|
$GLOBALS['TCA']['pages']['ctrl']['languageField'], |
190
|
|
|
$queryBuilder->createNamedParameter($languageAspect->getId(), \PDO::PARAM_INT) |
191
|
|
|
) |
192
|
|
|
) |
193
|
|
|
->setMaxResults(1) |
194
|
|
|
->execute() |
195
|
|
|
->fetch(); |
196
|
|
|
$tsfe->sys_page->versionOL('pages', $row); |
197
|
|
|
if (is_array($row)) { |
198
|
|
|
$link = (string)$uriBuilder->buildUriFromRoute( |
199
|
|
|
'record_edit', |
200
|
|
|
[ |
201
|
|
|
'edit[pages][' . $row['uid'] . ']' => 'edit', |
202
|
|
|
'noView' => 1, |
203
|
|
|
'returnUrl' => $returnUrl, |
204
|
|
|
] |
205
|
|
|
); |
206
|
|
|
$icon = $iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL) |
207
|
|
|
->render(); |
208
|
|
|
$title = $this->getLabel('edit_editPageOverlay'); |
209
|
|
|
$output[] = '<a class="' . |
210
|
|
|
$classes . |
211
|
|
|
'" href="' . |
212
|
|
|
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
213
|
|
|
'" title="' . |
214
|
|
|
$title . |
215
|
|
|
'">'; |
216
|
|
|
$output[] = ' ' . $icon; |
217
|
|
|
$output[] = '</a>'; |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
// Open list view |
222
|
|
|
if ($this->getBackendUser()->check('modules', 'web_list')) { |
223
|
|
|
$link = (string)$uriBuilder->buildUriFromRoute( |
224
|
|
|
'web_list', |
225
|
|
|
[ |
226
|
|
|
'id' => $id, |
227
|
|
|
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'), |
228
|
|
|
] |
229
|
|
|
); |
230
|
|
|
$icon = $iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render(); |
231
|
|
|
$title = $this->getLabel('edit_db_list'); |
232
|
|
|
$output[] = '<a class="' . |
233
|
|
|
$classes . |
234
|
|
|
'" href="' . |
235
|
|
|
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) . |
236
|
|
|
'" title="' . |
237
|
|
|
$title . |
238
|
|
|
'">'; |
239
|
|
|
$output[] = ' ' . $icon; |
240
|
|
|
$output[] = '</a>'; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
$output[] = ' </div>'; |
244
|
|
|
$output[] = '</div>'; |
245
|
|
|
return implode('', $output); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Translate given key |
250
|
|
|
* |
251
|
|
|
* @param string $key Key for a label in the $LOCAL_LANG array of "sysext/core/Resources/Private/Language/locallang_tsfe.xlf |
252
|
|
|
* @return string The value for the $key |
253
|
|
|
*/ |
254
|
|
|
protected function getLabel($key): ?string |
255
|
|
|
{ |
256
|
|
|
return htmlspecialchars($this->getLanguageService()->getLL($key), ENT_QUOTES | ENT_HTML5); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @return FrontendBackendUserAuthentication |
261
|
|
|
*/ |
262
|
|
|
protected function getBackendUser(): FrontendBackendUserAuthentication |
263
|
|
|
{ |
264
|
|
|
return $GLOBALS['BE_USER']; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @return LanguageService |
269
|
|
|
*/ |
270
|
|
|
protected function getLanguageService(): LanguageService |
271
|
|
|
{ |
272
|
|
|
return $GLOBALS['LANG']; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @return TypoScriptFrontendController |
277
|
|
|
*/ |
278
|
|
|
protected function getTypoScriptFrontendController(): TypoScriptFrontendController |
279
|
|
|
{ |
280
|
|
|
return $GLOBALS['TSFE']; |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|