[BUGFIX] Respect options.disableDelete UserTSConfig
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / ClickMenu / ClickMenu.php
1 <?php
2 namespace TYPO3\CMS\Backend\ClickMenu;
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
17 use TYPO3\CMS\Backend\Clipboard\Clipboard;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Imaging\Icon;
21 use TYPO3\CMS\Core\Imaging\IconFactory;
22 use TYPO3\CMS\Core\Resource\Folder;
23 use TYPO3\CMS\Core\Resource\ResourceFactory;
24 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
25 use TYPO3\CMS\Core\Type\Bitmask\Permission;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\CMS\Lang\LanguageService;
29
30 /**
31 * Class for generating the click menu
32 * @internal
33 */
34 class ClickMenu
35 {
36 /**
37 * Defines if the click menu is first level or second.
38 * Second means the click menu is triggered from another menu.
39 *
40 * @var int
41 */
42 public $cmLevel = 0;
43
44 /**
45 * Clipboard array (submitted by eg. pressing the paste button)
46 *
47 * @var bool
48 */
49 public $CB;
50
51 /**
52 * If set, the calling document should be in the listframe of a frameset.
53 *
54 * @var bool
55 */
56 public $listFrame = false;
57
58 /**
59 * If set, the menu is about database records, not files. (set if part 2 [1] of the item-var is NOT blank)
60 *
61 * @var bool
62 */
63 public $isDBmenu = false;
64
65 /**
66 * Stores the parts of the input $item string, splitted by "|":
67 * [0] = table/file, [1] = uid/blank, [2] = flag: If set, listFrame,
68 * If "2" then "content frame" is forced [3] = ("+" prefix = disable
69 * all by default, enable these. Default is to disable) Items key list
70 *
71 * @var array
72 */
73 public $iParts = [];
74
75 /**
76 * Contains list of keywords of items to disable in the menu
77 *
78 * @var array
79 */
80 public $disabledItems = [];
81
82 /**
83 * Array of classes to be used for user processing of the menu content.
84 * This is for the API of adding items to the menu from outside.
85 *
86 * @var array
87 */
88 public $extClassArray = [];
89
90 /**
91 * Set, when edit icon is drawn.
92 *
93 * @var bool
94 */
95 public $editPageIconSet = false;
96
97 /**
98 * Set to TRUE, if editing of the element is OK.
99 *
100 * @var bool
101 */
102 public $editOK = false;
103
104 /**
105 * The current record
106 *
107 * @var array
108 */
109 public $rec = [];
110
111 /**
112 * Clipboard set from the outside
113 * Declared as public for now, should become protected
114 * soon-ish
115 * @var Clipboard;
116 */
117 public $clipObj;
118
119 /**
120 * The current page record
121 * @var array
122 */
123 protected $pageinfo;
124
125 /**
126 * Language Service property. Used to access localized labels
127 *
128 * @var LanguageService
129 */
130 protected $languageService;
131
132 /**
133 * @var BackendUserAuthentication
134 */
135 protected $backendUser;
136
137 /**
138 * @var IconFactory
139 */
140 protected $iconFactory;
141
142 /**
143 * @param LanguageService $languageService Language Service to inject
144 * @param BackendUserAuthentication $backendUser
145 */
146 public function __construct(LanguageService $languageService = null, BackendUserAuthentication $backendUser = null)
147 {
148 $this->languageService = $languageService ?: $GLOBALS['LANG'];
149 $this->backendUser = $backendUser ?: $GLOBALS['BE_USER'];
150 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
151 }
152
153 /**
154 * Initialize click menu
155 *
156 * @return array the array to be returned as JSON including all click menu items
157 */
158 public function init()
159 {
160 $CMcontent = '';
161 // Setting GPvars:
162 $this->cmLevel = (int)GeneralUtility::_GP('cmLevel');
163 $this->CB = GeneralUtility::_GP('CB');
164
165 // Deal with Drag&Drop context menus
166 if ((string)GeneralUtility::_GP('dragDrop') !== '') {
167 return $this->printDragDropClickMenu(GeneralUtility::_GP('dragDrop'), GeneralUtility::_GP('srcId'), GeneralUtility::_GP('dstId'));
168 }
169 // Can be set differently as well
170 $this->iParts[0] = GeneralUtility::_GP('table');
171 $this->iParts[1] = GeneralUtility::_GP('uid');
172 $this->iParts[2] = GeneralUtility::_GP('listFr');
173 $this->iParts[3] = GeneralUtility::_GP('enDisItems');
174 // Setting flags:
175 if ($this->iParts[2]) {
176 $this->listFrame = true;
177 }
178 if (isset($this->iParts[1]) && $this->iParts[1] !== '') {
179 $this->isDBmenu = true;
180 }
181 $TSkey = ($this->isDBmenu ? 'page' : 'folder') . ($this->listFrame ? 'List' : 'Tree');
182 $this->disabledItems = GeneralUtility::trimExplode(',', $this->backendUser->getTSConfigVal('options.contextMenu.' . $TSkey . '.disableItems'), true);
183 // &cmLevel flag detected (2nd level menu)
184 if (!$this->cmLevel) {
185 // Make 1st level clickmenu:
186 if ($this->isDBmenu) {
187 $CMcontent = $this->printDBClickMenu($this->iParts[0], $this->iParts[1]);
188 } else {
189 $CMcontent = $this->printFileClickMenu($this->iParts[0]);
190 }
191 } else {
192 // Make 2nd level clickmenu (only for DBmenus)
193 if ($this->isDBmenu) {
194 $CMcontent = $this->printNewDBLevel($this->iParts[0], $this->iParts[1]);
195 }
196 }
197 // Return clickmenu content:
198 return $CMcontent;
199 }
200
201 /***************************************
202 *
203 * DATABASE
204 *
205 ***************************************/
206 /**
207 * Make 1st level clickmenu:
208 *
209 * @param string $table Table name
210 * @param int $uid UID for the current record.
211 * @return array the array to be returned as JSON
212 */
213 public function printDBClickMenu($table, $uid)
214 {
215 $uid = (int)$uid;
216 // Get record:
217 $this->rec = BackendUtility::getRecordWSOL($table, $uid);
218 $menuItems = [];
219 $root = 0;
220 $DBmount = false;
221 // Rootlevel
222 if ($table === 'pages' && $uid === 0) {
223 $root = 1;
224 }
225 // DB mount
226 if ($table === 'pages' && in_array($uid, $this->backendUser->returnWebmounts())) {
227 $DBmount = true;
228 }
229 // Used to hide cut,copy icons for l10n-records
230 $l10nOverlay = false;
231 // Should only be performed for overlay-records within the same table
232 if (BackendUtility::isTableLocalizable($table) && !isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'])) {
233 $l10nOverlay = (int)$this->rec[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
234 }
235 // If record found (or root), go ahead and fill the $menuItems array which will contain data for the elements to render.
236 if (is_array($this->rec) || $root) {
237 // Get permissions
238 $lCP = $this->backendUser->calcPerms(BackendUtility::getRecord('pages', $table === 'pages' ? (int)$this->rec['uid'] : (int)$this->rec['pid']));
239 // View
240 if (!in_array('view', $this->disabledItems, true)) {
241 if ($table === 'pages') {
242 $menuItems['view'] = $this->DB_view($uid);
243 }
244 if ($table === 'tt_content') {
245 $ws_rec = BackendUtility::getRecordWSOL($table, (int)$this->rec['uid']);
246 $menuItems['view'] = $this->DB_view((int)$ws_rec['pid']);
247 }
248 }
249 // Edit:
250 if (!$root && ($this->backendUser->isPSet($lCP, $table, 'edit') || $this->backendUser->isPSet($lCP, $table, 'editcontent'))) {
251 if (!in_array('edit', $this->disabledItems, true)) {
252 $menuItems['edit'] = $this->DB_edit($table, $uid);
253 }
254 $this->editOK = true;
255 }
256 // New:
257 if (!in_array('new', $this->disabledItems, true) && $this->backendUser->isPSet($lCP, $table, 'new')) {
258 $menuItems['new'] = $this->DB_new($table, $uid);
259 }
260 // Info:
261 if (!in_array('info', $this->disabledItems, true) && !$root) {
262 $menuItems['info'] = $this->DB_info($table, $uid);
263 }
264 $menuItems['spacer1'] = 'spacer';
265 // Copy:
266 if (!in_array('copy', $this->disabledItems, true) && !$root && !$DBmount && !$l10nOverlay) {
267 $menuItems['copy'] = $this->DB_copycut($table, $uid, 'copy');
268 }
269 // Cut:
270 if (!in_array('cut', $this->disabledItems, true) && !$root && !$DBmount && !$l10nOverlay && $this->editOK) {
271 $menuItems['cut'] = $this->DB_copycut($table, $uid, 'cut');
272 }
273 // Paste:
274 $elFromAllTables = count($this->clipObj->elFromTable(''));
275 if (!in_array('paste', $this->disabledItems, true) && $elFromAllTables) {
276 $selItem = $this->clipObj->getSelectedRecord();
277 $elInfo = [
278 GeneralUtility::fixed_lgd_cs($selItem['_RECORD_TITLE'], $this->backendUser->uc['titleLen']),
279 $root ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] : GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $this->rec), $this->backendUser->uc['titleLen']),
280 $this->clipObj->currentMode()
281 ];
282 if ($table === 'pages' && $lCP & Permission::PAGE_NEW) {
283 if ($elFromAllTables) {
284 $menuItems['pasteinto'] = $this->DB_paste('', $uid, 'into', $elInfo);
285 }
286 }
287 $elFromTable = count($this->clipObj->elFromTable($table));
288 if (!$root && !$DBmount && $elFromTable && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
289 $menuItems['pasteafter'] = $this->DB_paste($table, -$uid, 'after', $elInfo);
290 }
291 }
292
293 // Delete:
294 $elInfo = [GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $this->rec), $this->backendUser->uc['titleLen'])];
295 $disableDeleteTS = $this->backendUser->getTSConfig('options.disableDelete');
296 $disableDelete = (bool) trim(isset($disableDeleteTS['properties'][$table]) ? $disableDeleteTS['properties'][$table] : $disableDeleteTS['value']);
297 if (!in_array('delete', $this->disabledItems, true) && !$root && !$DBmount && $this->backendUser->isPSet($lCP, $table, 'delete') && !$disableDelete) {
298 $menuItems['spacer2'] = 'spacer';
299 $menuItems['delete'] = $this->DB_delete($table, $uid, $elInfo);
300 }
301 if (!in_array('history', $this->disabledItems, true)) {
302 $menuItems['history'] = $this->DB_history($table, $uid);
303 }
304
305 $localItems = [];
306 if (!$this->cmLevel && !in_array('moreoptions', $this->disabledItems, true)) {
307 // Creating menu items here:
308 if ($this->editOK) {
309 $localItems['spacer3'] = 'spacer';
310 $localItems['moreoptions'] = $this->linkItem(
311 $this->label('more') . '&nbsp;&nbsp;<span class="fa fa-caret-right"></span>',
312 '<span class="fa fa-fw"></span>',
313 'TYPO3.ClickMenu.fetch(' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript() . '&cmLevel=1&subname=moreoptions') . ');return false;',
314 false,
315 true
316 );
317 $menuItemHideUnhideAllowed = false;
318 $hiddenField = '';
319 // Check if column for disabled is defined
320 if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])) {
321 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
322 if (
323 $hiddenField !== '' && !empty($GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude'])
324 && $this->backendUser->check('non_exclude_fields', $table . ':' . $hiddenField)
325 ) {
326 $menuItemHideUnhideAllowed = true;
327 }
328 }
329 if ($menuItemHideUnhideAllowed && !in_array('hide', $this->disabledItems, true)) {
330 $localItems['hide'] = $this->DB_hideUnhide($table, $this->rec, $hiddenField);
331 }
332 $anyEnableColumnsFieldAllowed = false;
333 // Check if columns are defined
334 if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
335 $columnsToCheck = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
336 if ($table === 'pages' && !empty($columnsToCheck)) {
337 $columnsToCheck[] = 'extendToSubpages';
338 }
339 foreach ($columnsToCheck as $currentColumn) {
340 if (
341 !empty($GLOBALS['TCA'][$table]['columns'][$currentColumn]['exclude'])
342 && $this->backendUser->check('non_exclude_fields', $table . ':' . $currentColumn)
343 ) {
344 $anyEnableColumnsFieldAllowed = true;
345 }
346 }
347 }
348 if ($anyEnableColumnsFieldAllowed && !in_array('edit_access', $this->disabledItems, true)) {
349 $localItems['edit_access'] = $this->DB_editAccess($table, $uid);
350 }
351 }
352 // Find delete element among the input menu items and insert the local items just before that:
353 $c = 0;
354 $deleteFound = false;
355 foreach ($menuItems as $key => $value) {
356 $c++;
357 if ($key === 'delete') {
358 $deleteFound = true;
359 break;
360 }
361 }
362 if ($deleteFound) {
363 // .. subtract two... (delete item + its spacer element...)
364 $c -= 2;
365 // and insert the items just before the delete element.
366 array_splice($menuItems, $c, 0, $localItems);
367 } else {
368 $menuItems = array_merge($menuItems, $localItems);
369 }
370 }
371 }
372 // Adding external elements to the menuItems array
373 $menuItems = $this->processingByExtClassArray($menuItems, $table, $uid);
374 // Processing by external functions?
375 $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
376 if (!is_array($this->rec)) {
377 $this->rec = [];
378 }
379
380 // Return the printed elements:
381 return $this->printItems($menuItems);
382 }
383
384 /**
385 * Make 2nd level clickmenu (only for DBmenus)
386 *
387 * @param string $table Table name
388 * @param int $uid UID for the current record.
389 * @return array the array to be returned as JSON
390 */
391 public function printNewDBLevel($table, $uid)
392 {
393 $localItems = [];
394 $uid = (int)$uid;
395 // Setting internal record to the table/uid :
396 $this->rec = BackendUtility::getRecordWSOL($table, $uid);
397 $menuItems = [];
398 $root = 0;
399 // Rootlevel
400 if ($table === 'pages' && $uid === 0) {
401 $root = 1;
402 }
403 // If record was found, check permissions and get menu items.
404 if (is_array($this->rec) || $root) {
405 $lCP = $this->backendUser->calcPerms(BackendUtility::getRecord('pages', $table === 'pages' ? (int)$this->rec['uid'] : (int)$this->rec['pid']));
406 // Edit:
407 if (!$root && ($this->backendUser->isPSet($lCP, $table, 'edit') || $this->backendUser->isPSet($lCP, $table, 'editcontent'))) {
408 $this->editOK = true;
409 }
410 $menuItems = $this->processingByExtClassArray($menuItems, $table, $uid);
411 }
412
413 $subname = GeneralUtility::_GP('subname');
414 if ($subname === 'moreoptions') {
415 // If the page can be edited, then show this:
416 if ($this->editOK) {
417 if (($table === 'pages' || $table === 'tt_content') && !in_array('move_wizard', $this->disabledItems, true)) {
418 $localItems['move_wizard'] = $this->DB_moveWizard($table, $uid, $this->rec);
419 }
420 if (($table === 'pages' || $table === 'tt_content') && !in_array('new_wizard', $this->disabledItems, true)) {
421 $localItems['new_wizard'] = $this->DB_newWizard($table, $uid, $this->rec);
422 }
423 if ($table === 'pages' && !in_array('perms', $this->disabledItems, true) && $this->backendUser->check('modules', 'system_BeuserTxPermission')) {
424 $localItems['perms'] = $this->DB_perms($table, $uid, $this->rec);
425 }
426 if (!in_array('db_list', $this->disabledItems, true) && $this->backendUser->check('modules', 'web_list')) {
427 $localItems['db_list'] = $this->DB_db_list($table, $uid, $this->rec);
428 }
429 }
430 // Temporary mount point item:
431 if ($table === 'pages') {
432 $localItems['temp_mount_point'] = $this->DB_tempMountPoint($uid);
433 }
434 // Merge the locally created items into the current menu items passed to this function.
435 $menuItems = array_merge($menuItems, $localItems);
436 }
437
438 // Return the printed elements:
439 if (!is_array($menuItems)) {
440 $menuItems = [];
441 }
442 return $this->printItems($menuItems);
443 }
444
445 /**
446 * Processing the $menuItems array (for extension classes) (DATABASE RECORDS)
447 *
448 * @param array $menuItems Array for manipulation.
449 * @return array Processed $menuItems array
450 */
451 public function externalProcessingOfDBMenuItems($menuItems)
452 {
453 return $menuItems;
454 }
455
456 /**
457 * Processing the $menuItems array by external classes (typ. adding items)
458 *
459 * @param array $menuItems Array for manipulation.
460 * @param string $table Table name
461 * @param int $uid UID for the current record.
462 * @return array Processed $menuItems array
463 */
464 public function processingByExtClassArray($menuItems, $table, $uid)
465 {
466 if (is_array($this->extClassArray)) {
467 foreach ($this->extClassArray as $conf) {
468 $obj = GeneralUtility::makeInstance($conf['name']);
469 $menuItems = $obj->main($this, $menuItems, $table, $uid);
470 }
471 }
472 return $menuItems;
473 }
474
475 /**
476 * Returning JavaScript for the onClick event linking to the input URL.
477 *
478 * @param string $url The URL relative to TYPO3_mainDir
479 * @param string $retUrl The return_url-parameter
480 * @param bool $hideCM If set, the "hideCM()" will be called
481 * @param string $overrideLoc If set, gives alternative location to load in (for example top frame or somewhere else)
482 * @return string JavaScript for an onClick event.
483 */
484 public function urlRefForCM($url, $retUrl = '', $hideCM = true, $overrideLoc = '')
485 {
486 $loc = 'top.content.list_frame';
487 return ($overrideLoc ? 'var docRef=' . $overrideLoc : 'var docRef=(top.content.list_frame)?top.content.list_frame:' . $loc)
488 . '; docRef.location.href=' . GeneralUtility::quoteJSvalue($url) . ($retUrl ? '+' . GeneralUtility::quoteJSvalue('&' . $retUrl . '=') . '+top.rawurlencode('
489 . $this->frameLocation('docRef.document') . '.pathname+' . $this->frameLocation('docRef.document') . '.search)' : '')
490 . ';';
491 }
492
493 /**
494 * Adding CM element for Clipboard "copy" and "cut"
495 *
496 * @param string $table Table name
497 * @param int $uid UID for the current record.
498 * @param string $type Type: "copy" or "cut
499 * @return array Item array, element in $menuItems
500 * @internal
501 */
502 public function DB_copycut($table, $uid, $type)
503 {
504 $isSel = '';
505 if ($this->clipObj->current === 'normal') {
506 $isSel = $this->clipObj->isSelected($table, $uid);
507 }
508 $addParam = [];
509 if ($this->listFrame) {
510 $addParam['reloadListFrame'] = 1;
511 }
512 $icon = $this->iconFactory->getIcon('actions-edit-' . $type . ($isSel === $type ? '-release' : ''), Icon::SIZE_SMALL)->render();
513 return $this->linkItem(
514 $this->label($type),
515 $icon,
516 'TYPO3.ClickMenu.fetch(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $uid, ($type === 'copy' ? 1 : 0), ($isSel == $type), $addParam)) . ');return false;'
517 );
518 }
519
520 /**
521 * Adding CM element for Clipboard "paste into"/"paste after"
522 * NOTICE: $table and $uid should follow the special syntax for paste, see clipboard-class :: pasteUrl();
523 *
524 * @param string $table Table name
525 * @param int $uid UID for the current record. NOTICE: Special syntax!
526 * @param string $type Type: "into" or "after
527 * @param array $elInfo Contains instructions about whether to copy or cut an element.
528 * @return array Item array, element in $menuItems
529 * @see \TYPO3\CMS\Backend\Clipboard\Clipboard::pasteUrl()
530 * @internal
531 */
532 public function DB_paste($table, $uid, $type, $elInfo)
533 {
534 $loc = 'top.content.list_frame';
535 $jsCode = $loc . '.location.href='
536 . GeneralUtility::quoteJSvalue($this->clipObj->pasteUrl($table, $uid, 0) . '&redirect=')
537 . ' + top.rawurlencode(' . $this->frameLocation($loc . '.document') . '.pathname+'
538 . $this->frameLocation($loc . '.document') . '.search);';
539
540 if ($this->backendUser->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE)) {
541 $title = $this->languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:clip_paste');
542 $lllKey = ($elInfo[2] === 'copy' ? 'copy' : 'move') . '_' . $type;
543 $confirmMessage = sprintf(
544 $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:mess.' . $lllKey),
545 $elInfo[0],
546 $elInfo[1]
547 );
548 $jsCode = 'top.TYPO3.Modal.confirm(' . GeneralUtility::quoteJSvalue($title) . ', '
549 . GeneralUtility::quoteJSvalue($confirmMessage) . ')'
550 . '.on(\'button.clicked\', function(e) { if (e.target.name === \'ok\') {'
551 . $jsCode
552 . '} top.TYPO3.Modal.dismiss(); });';
553 }
554 $editOnClick = 'if(' . $loc . ') { ' . $jsCode . ' }';
555 return $this->linkItem(
556 $this->label('paste' . $type),
557 $this->iconFactory->getIcon('actions-document-paste-' . $type, Icon::SIZE_SMALL)->render(),
558 $editOnClick . 'return false;'
559 );
560 }
561
562 /**
563 * Adding CM element for Info
564 *
565 * @param string $table Table name
566 * @param int $uid UID for the current record.
567 * @return array Item array, element in $menuItems
568 * @internal
569 */
570 public function DB_info($table, $uid)
571 {
572 return $this->linkItem(
573 $this->label('info'),
574 $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render(),
575 'top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', ' . GeneralUtility::quoteJSvalue($uid) . ');'
576 );
577 }
578
579 /**
580 * Adding CM element for History
581 *
582 * @param string $table Table name
583 * @param int $uid UID for the current record.
584 * @return array Item array, element in $menuItems
585 * @internal
586 */
587 public function DB_history($table, $uid)
588 {
589 $url = BackendUtility::getModuleUrl('record_history', ['element' => $table . ':' . $uid]);
590 return $this->linkItem(
591 htmlspecialchars($this->languageService->getLL('CM_history')),
592 $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render(),
593 $this->urlRefForCM($url, 'returnUrl')
594 );
595 }
596
597 /**
598 * Adding CM element for Permission setting
599 *
600 * @param string $table Table name
601 * @param int $uid UID for the current record.
602 * @param array $rec The "pages" record with "perms_*" fields inside.
603 * @return array Item array, element in $menuItems
604 * @internal
605 */
606 public function DB_perms($table, $uid, $rec)
607 {
608 if (!ExtensionManagementUtility::isLoaded('beuser')) {
609 return '';
610 }
611
612 $parameters = [
613 'id' => $uid,
614 ];
615
616 if ($rec['perms_userid'] == $this->backendUser->user['uid'] || $this->backendUser->isAdmin()) {
617 $parameters['return_id'] = $uid;
618 $parameters['edit'] = '1';
619 }
620
621 $url = BackendUtility::getModuleUrl('system_BeuserTxPermission', $parameters);
622 return $this->linkItem(
623 htmlspecialchars($this->languageService->getLL('CM_perms')),
624 $this->iconFactory->getIcon('status-status-locked', Icon::SIZE_SMALL)->render(),
625 $this->urlRefForCM($url)
626 );
627 }
628
629 /**
630 * Adding CM element for DBlist
631 *
632 * @param string $table Table name
633 * @param int $uid UID for the current record.
634 * @param array $rec Record of the element (needs "pid" field if not pages-record)
635 * @return array Item array, element in $menuItems
636 * @internal
637 */
638 public function DB_db_list($table, $uid, $rec)
639 {
640 $urlParams = [];
641 $urlParams['id'] = $table === 'pages' ? $uid : $rec['pid'];
642 $urlParams['table'] = $table === 'pages' ? '' : $table;
643 $url = BackendUtility::getModuleUrl('web_list', $urlParams, '', true);
644 return $this->linkItem(
645 htmlspecialchars($this->languageService->getLL('CM_db_list')),
646 $this->iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render(),
647 'top.nextLoadModuleUrl=' . GeneralUtility::quoteJSvalue($url) . ';top.goToModule(\'web_list\', 1);'
648 );
649 }
650
651 /**
652 * Adding CM element for Moving wizard
653 *
654 * @param string $table Table name
655 * @param int $uid UID for the current record.
656 * @param array $rec Record. Needed for tt-content elements which will have the sys_language_uid sent
657 * @return array Item array, element in $menuItems
658 * @internal
659 */
660 public function DB_moveWizard($table, $uid, $rec)
661 {
662 // Hardcoded field for tt_content elements.
663 $url = BackendUtility::getModuleUrl('move_element') . '&table=' . $table . '&uid=' . $uid;
664 $url .= ($table === 'tt_content' ? '&sys_language_uid=' . (int)$rec['sys_language_uid'] : '');
665 return $this->linkItem(
666 htmlspecialchars($this->languageService->getLL('CM_moveWizard' . ($table === 'pages' ? '_page' : ''))),
667 $this->iconFactory->getIcon('actions-' . ($table === 'pages' ? 'page' : 'document') . '-move', Icon::SIZE_SMALL)->render(),
668 $this->urlRefForCM($url, 'returnUrl')
669 );
670 }
671
672 /**
673 * Adding CM element for Create new wizard (either BackendUtility::getModuleUrl('db_new') or BackendUtility::getModuleUrl('new_content_element') or custom wizard)
674 *
675 * @param string $table Table name
676 * @param int $uid UID for the current record.
677 * @param array $rec Record.
678 * @return array Item array, element in $menuItems
679 * @internal
680 */
681 public function DB_newWizard($table, $uid, $rec)
682 {
683 if ($table === 'pages') {
684 $url = BackendUtility::getModuleUrl('db_new', ['id' => $uid, 'pagesOnly' => 1]);
685 } else {
686 // If mod.newContentElementWizard.override is set, use a custom module instead
687 $tsConfig = BackendUtility::getModTSconfig((int)$this->pageinfo['uid'], 'mod');
688 $newContentWizardModuleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
689 ? $tsConfig['properties']['newContentElementWizard.']['override']
690 : 'new_content_element';
691 $url = BackendUtility::getModuleUrl($newContentWizardModuleName, ['id' => $rec['pid'], 'sys_language_uid' => (int)$rec['sys_language_uid']]);
692 }
693 return $this->linkItem(
694 htmlspecialchars($this->languageService->getLL('CM_newWizard')),
695 $this->iconFactory->getIcon(($table === 'pages' ? 'actions-page-new' : 'actions-document-new'), Icon::SIZE_SMALL)->render(),
696 $this->urlRefForCM($url, 'returnUrl')
697 );
698 }
699
700 /**
701 * Adding CM element for Editing of the access related fields of a table (disable, starttime, endtime, fe_groups)
702 *
703 * @param string $table Table name
704 * @param int $uid UID for the current record.
705 * @return array Item array, element in $menuItems
706 * @internal
707 */
708 public function DB_editAccess($table, $uid)
709 {
710 $url = BackendUtility::getModuleUrl('record_edit', [
711 'columnsOnly' => (implode(',', $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']) . ($table === 'pages' ? ',extendToSubpages' : '')),
712 'edit[' . $table . '][' . $uid . ']' => 'edit'
713 ]);
714 return $this->linkItem(
715 htmlspecialchars($this->languageService->getLL('CM_editAccess')),
716 $this->iconFactory->getIcon('actions-document-edit-access', Icon::SIZE_SMALL)->render(),
717 $this->urlRefForCM($url, 'returnUrl'),
718 1
719 );
720 }
721
722 /**
723 * Adding CM element for edit page properties
724 *
725 * @param int $uid page uid to edit (PID)
726 * @return array Item array, element in $menuItems
727 * @internal
728 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
729 */
730 public function DB_editPageProperties($uid)
731 {
732 GeneralUtility::logDeprecatedFunction();
733 $url = BackendUtility::getModuleUrl('record_edit', [
734 'edit[pages][' . $uid . ']' => 'edit'
735 ]);
736 return $this->linkItem(
737 htmlspecialchars($this->languageService->getLL('CM_editPageProperties')),
738 $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render(),
739 $this->urlRefForCM($url, 'returnUrl'),
740 1
741 );
742 }
743
744 /**
745 * Adding CM element for regular editing of the element!
746 *
747 * @param string $table Table name
748 * @param int $uid UID for the current record.
749 * @return array Item array, element in $menuItems
750 * @internal
751 */
752 public function DB_edit($table, $uid)
753 {
754 // If another module was specified, replace the default Page module with the new one
755 $newPageModule = trim($this->backendUser->getTSConfigVal('options.overridePageModule'));
756 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
757 $loc = 'top.content.list_frame';
758 $theIcon = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render();
759
760 $link = BackendUtility::getModuleUrl('record_edit', [
761 'edit[' . $table . '][' . $uid . ']' => 'edit'
762 ]);
763
764 if ($this->iParts[0] === 'pages' && $this->iParts[1] && $this->backendUser->check('modules', $pageModule)) {
765 $this->editPageIconSet = true;
766 }
767 $editOnClick = 'if(' . $loc . '){' . $loc . '.location.href=' . GeneralUtility::quoteJSvalue($link . '&returnUrl=') . '+top.rawurlencode(' . $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search);}';
768 return $this->linkItem($this->label('edit'), $theIcon, $editOnClick . ';');
769 }
770
771 /**
772 * Adding CM element for regular Create new element
773 *
774 * @param string $table Table name
775 * @param int $uid UID for the current record.
776 * @return array Item array, element in $menuItems
777 * @internal
778 */
779 public function DB_new($table, $uid)
780 {
781 $frame = 'top.content.list_frame';
782 $location = $this->frameLocation($frame . '.document');
783 $module = $this->listFrame
784 ? GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('record_edit', ['edit[' . $table . '][-' . $uid . ']' => 'new']) . '&returnUrl=') . '+top.rawurlencode(' . $location . '.pathname+' . $location . '.search)'
785 : GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', ['id' => (int)$uid]));
786 $editOnClick = 'if(' . $frame . '){' . $frame . '.location.href=' . $module . ';}';
787 $icon = $this->iconFactory->getIcon('actions-' . ($table === 'pages' ? 'page' : 'document') . '-new', Icon::SIZE_SMALL)->render();
788 return $this->linkItem($this->label('new'), $icon, $editOnClick);
789 }
790
791 /**
792 * Adding CM element for Delete
793 *
794 * @param string $table Table name
795 * @param int $uid UID for the current record.
796 * @param array $elInfo Label for including in the confirmation message, EXT:lang/locallang_core.xlf:mess.delete
797 * @return array Item array, element in $menuItems
798 * @internal
799 */
800 public function DB_delete($table, $uid, $elInfo)
801 {
802 $loc = 'top.content.list_frame';
803 $jsCode = $loc . '.location.href='
804 . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&redirect=')
805 . '+top.rawurlencode(' . $this->frameLocation($loc . '.document') . '.pathname+'
806 . $this->frameLocation($loc . '.document') . '.search)+'
807 . GeneralUtility::quoteJSvalue(
808 '&cmd[' . $table . '][' . $uid . '][delete]=1&prErr=1&vC=' . $this->backendUser->veriCode()
809 );
810
811 if ($table === 'pages') {
812 $jsCode .= 'top.nav.refresh.defer(500, top.nav);';
813 }
814
815 if ($this->backendUser->jsConfirmation(JsConfirmation::DELETE)) {
816 $title = $this->languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:delete');
817 $confirmMessage = sprintf(
818 $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'),
819 $elInfo[0]
820 );
821 $confirmMessage .= BackendUtility::referenceCount(
822 $table,
823 $uid,
824 ' ' . $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToRecord')
825 );
826 $confirmMessage .= BackendUtility::translationCount(
827 $table,
828 $uid,
829 ' ' . $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')
830 );
831 $jsCode = 'top.TYPO3.Modal.confirm(' . GeneralUtility::quoteJSvalue($title) . ', '
832 . GeneralUtility::quoteJSvalue($confirmMessage) . ')'
833 . '.on(\'button.clicked\', function(e) { if (e.target.name === \'ok\') {'
834 . $jsCode
835 . '} top.TYPO3.Modal.dismiss(); });';
836 }
837 $editOnClick = 'if(' . $loc . ') { ' . $jsCode . ' }';
838 return $this->linkItem(
839 $this->label('delete'),
840 $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(),
841 $editOnClick . 'return false;'
842 );
843 }
844
845 /**
846 * Adding CM element for View Page
847 *
848 * @param int $id Page uid (PID)
849 * @param string $anchor Anchor, if any
850 * @return array Item array, element in $menuItems
851 * @internal
852 */
853 public function DB_view($id, $anchor = '')
854 {
855 $icon = $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render();
856 return $this->linkItem($this->label('view'), $icon, BackendUtility::viewOnClick($id, '', null, $anchor) . ';');
857 }
858
859 /**
860 * Adding element for setting temporary mount point.
861 *
862 * @param int $page_id Page uid (PID)
863 * @return array Item array, element in $menuItems
864 * @internal
865 */
866 public function DB_tempMountPoint($page_id)
867 {
868 return $this->linkItem(
869 $this->label('tempMountPoint'),
870 $this->iconFactory->getIcon('actions-pagetree-mountroot', Icon::SIZE_SMALL)->render(),
871 'if (top.content.nav_frame) {
872 var node = top.TYPO3.Backend.NavigationContainer.PageTree.getSelected();
873 if (node === null) {
874 return false;
875 }
876
877 var useNode = {
878 attributes: {
879 nodeData: {
880 id: ' . (int)$page_id . '
881 }
882 }
883 };
884
885 node.ownerTree.commandProvider.mountAsTreeRoot(useNode, node.ownerTree);
886 }
887 ');
888 }
889
890 /**
891 * Adding CM element for hide/unhide of the input record
892 *
893 * @param string $table Table name
894 * @param array $rec Record array
895 * @param string $hideField Name of the hide field
896 * @return array Item array, element in $menuItems
897 * @internal
898 */
899 public function DB_hideUnhide($table, $rec, $hideField)
900 {
901 return $this->DB_changeFlag($table, $rec, $hideField, $this->label(($rec[$hideField] ? 'un' : '') . 'hide'));
902 }
903
904 /**
905 * Adding CM element for a flag field of the input record
906 *
907 * @param string $table Table name
908 * @param array $rec Record array
909 * @param string $flagField Name of the flag field
910 * @param string $title Menu item Title
911 * @return array Item array, element in $menuItems
912 */
913 public function DB_changeFlag($table, $rec, $flagField, $title)
914 {
915 $uid = $rec['_ORIG_uid'] ?: $rec['uid'];
916 $loc = 'top.content.list_frame';
917 $editOnClick = 'if(' . $loc . '){' . $loc . '.location.href=' .
918 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&redirect=') . '+top.rawurlencode(' .
919 $this->frameLocation($loc . '.document') . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
920 GeneralUtility::quoteJSvalue(
921 '&data[' . $table . '][' . $uid . '][' . $flagField . ']=' . ($rec[$flagField] ? 0 : 1) . '&prErr=1&vC=' . $this->backendUser->veriCode()
922 ) . ';};';
923 if ($table === 'pages') {
924 $editOnClick .= 'top.nav.refresh.defer(500, top.nav);';
925 }
926 return $this->linkItem(
927 $title,
928 $this->iconFactory->getIcon('actions-edit-' . ($rec[$flagField] ? 'un' : '') . 'hide', Icon::SIZE_SMALL)->render(),
929 $editOnClick . 'return false;',
930 1
931 );
932 }
933
934 /***************************************
935 *
936 * FILE
937 *
938 ***************************************/
939 /**
940 * Make 1st level clickmenu:
941 *
942 * @param string $combinedIdentifier The combined identifier
943 * @return string HTML content
944 * @see \TYPO3\CMS\Core\Resource\ResourceFactory::retrieveFileOrFolderObject()
945 */
946 public function printFileClickMenu($combinedIdentifier)
947 {
948 $identifier = '';
949 $menuItems = [];
950 $combinedIdentifier = rawurldecode($combinedIdentifier);
951 $fileObject = ResourceFactory::getInstance()
952 ->retrieveFileOrFolderObject($combinedIdentifier);
953 if ($fileObject) {
954 $folder = false;
955 $isStorageRoot = false;
956 $isOnline = true;
957 $userMayViewStorage = false;
958 $userMayEditStorage = false;
959 $identifier = $fileObject->getCombinedIdentifier();
960 if ($fileObject instanceof Folder) {
961 $folder = true;
962 if ($fileObject->getIdentifier() === $fileObject->getStorage()->getRootLevelFolder()->getIdentifier()) {
963 $isStorageRoot = true;
964 if ($this->backendUser->check('tables_select', 'sys_file_storage')) {
965 $userMayViewStorage = true;
966 }
967 if ($this->backendUser->check('tables_modify', 'sys_file_storage')) {
968 $userMayEditStorage = true;
969 }
970 }
971 if (!$fileObject->getStorage()->isOnline()) {
972 $isOnline = false;
973 }
974 }
975 // Hide
976 if (!in_array('hide', $this->disabledItems, true) && $isStorageRoot && $userMayEditStorage) {
977 $record = BackendUtility::getRecord('sys_file_storage', $fileObject->getStorage()->getUid());
978 $menuItems['hide'] = $this->DB_changeFlag(
979 'sys_file_storage',
980 $record,
981 'is_online',
982 $this->label($record['is_online'] ? 'offline' : 'online')
983 );
984 }
985 // Edit
986 if (!in_array('edit', $this->disabledItems, true) && $fileObject->checkActionPermission('write')) {
987 if (!$folder && !$isStorageRoot && $fileObject->isIndexed() && $this->backendUser->check('tables_modify', 'sys_file_metadata')) {
988 $metaData = $fileObject->_getMetaData();
989 $menuItems['edit2'] = $this->DB_edit('sys_file_metadata', $metaData['uid']);
990 }
991 if (!$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileObject->getExtension()) && $fileObject->checkActionPermission('write')) {
992 $menuItems['edit'] = $this->FILE_launch($identifier, 'file_edit', 'editcontent', 'actions-page-open');
993 } elseif ($isStorageRoot && $userMayEditStorage) {
994 $menuItems['edit'] = $this->DB_edit('sys_file_storage', $fileObject->getStorage()->getUid());
995 }
996 }
997 // Rename
998 if (!in_array('rename', $this->disabledItems, true) && !$isStorageRoot && $fileObject->checkActionPermission('rename')) {
999 $menuItems['rename'] = $this->FILE_launch($identifier, 'file_rename', 'rename', 'actions-edit-rename');
1000 }
1001 // Upload
1002 if (!in_array('upload', $this->disabledItems, true) && $folder && $isOnline && $fileObject->checkActionPermission('write')) {
1003 $menuItems['upload'] = $this->FILE_launch($identifier, 'file_upload', 'upload', 'actions-edit-upload');
1004 }
1005 // New
1006 if (!in_array('new', $this->disabledItems, true) && $folder && $isOnline && $fileObject->checkActionPermission('write')) {
1007 $menuItems['new'] = $this->FILE_launch($identifier, 'file_newfolder', 'new', 'actions-document-new');
1008 }
1009 // Info
1010 if (!in_array('info', $this->disabledItems, true) && $fileObject->checkActionPermission('read')) {
1011 if ($isStorageRoot && $userMayViewStorage) {
1012 $menuItems['info'] = $this->DB_info('sys_file_storage', $fileObject->getStorage()->getUid());
1013 } elseif (!$folder) {
1014 $menuItems['info'] = $this->fileInfo($identifier);
1015 }
1016 }
1017 $menuItems[] = 'spacer';
1018 // Copy:
1019 if (!in_array('copy', $this->disabledItems, true) && !$isStorageRoot && $fileObject->checkActionPermission('read')) {
1020 $menuItems['copy'] = $this->FILE_copycut($identifier, 'copy');
1021 }
1022 // Cut:
1023 if (!in_array('cut', $this->disabledItems, true) && !$isStorageRoot && $fileObject->checkActionPermission('move')) {
1024 $menuItems['cut'] = $this->FILE_copycut($identifier, 'cut');
1025 }
1026 // Paste:
1027 $elFromAllTables = count($this->clipObj->elFromTable('_FILE'));
1028 if (!in_array('paste', $this->disabledItems, true) && $elFromAllTables && $folder && $fileObject->checkActionPermission('write')) {
1029 $elArr = $this->clipObj->elFromTable('_FILE');
1030 $selItem = reset($elArr);
1031 $clickedFileOrFolder = ResourceFactory::getInstance()->retrieveFileOrFolderObject($combinedIdentifier);
1032 $fileOrFolderInClipBoard = ResourceFactory::getInstance()->retrieveFileOrFolderObject($selItem);
1033 $elInfo = [
1034 $fileOrFolderInClipBoard->getName(),
1035 $clickedFileOrFolder->getName(),
1036 $this->clipObj->currentMode()
1037 ];
1038 if (!$fileOrFolderInClipBoard instanceof Folder || !$fileOrFolderInClipBoard->getStorage()->isWithinFolder($fileOrFolderInClipBoard, $clickedFileOrFolder)) {
1039 $menuItems['pasteinto'] = $this->FILE_paste($identifier, $selItem, $elInfo);
1040 }
1041 }
1042 $menuItems[] = 'spacer';
1043 // Delete:
1044 if (!in_array('delete', $this->disabledItems, true) && $fileObject->checkActionPermission('delete')) {
1045 if ($isStorageRoot && $userMayEditStorage) {
1046 $elInfo = [GeneralUtility::fixed_lgd_cs($fileObject->getStorage()->getName(), $this->backendUser->uc['titleLen'])];
1047 $menuItems['delete'] = $this->DB_delete('sys_file_storage', $fileObject->getStorage()->getUid(), $elInfo);
1048 } elseif (!$isStorageRoot) {
1049 $menuItems['delete'] = $this->FILE_delete($identifier);
1050 }
1051 }
1052 }
1053 // Adding external elements to the menuItems array
1054 $menuItems = $this->processingByExtClassArray($menuItems, $identifier, 0);
1055 // Processing by external functions?
1056 $menuItems = $this->externalProcessingOfFileMenuItems($menuItems);
1057 // Return the printed elements:
1058 return $this->printItems($menuItems);
1059 }
1060
1061 /**
1062 * Processing the $menuItems array (for extension classes) (FILES)
1063 *
1064 * @param array $menuItems Array for manipulation.
1065 * @return array Processed $menuItems array
1066 */
1067 public function externalProcessingOfFileMenuItems($menuItems)
1068 {
1069 return $menuItems;
1070 }
1071
1072 /**
1073 * Multi-function for adding an entry to the $menuItems array
1074 *
1075 * @param string $path Path to the file/directory (target)
1076 * @param string $moduleName Script (deprecated) or module name (e.g. file_edit) to pass &target= to
1077 * @param string $type "type" is the code which fetches the correct label for the element from "cm.
1078 * @param string $iconName
1079 * @param bool $noReturnUrl If set, the return URL parameter will not be set in the link
1080 * @return array Item array, element in $menuItems
1081 * @internal
1082 */
1083 public function FILE_launch($path, $moduleName, $type, $iconName, $noReturnUrl = false)
1084 {
1085 $loc = 'top.content.list_frame';
1086 $scriptUrl = BackendUtility::getModuleUrl($moduleName);
1087
1088 $editOnClick = 'if(' . $loc . '){' . $loc . '.location.href=' . GeneralUtility::quoteJSvalue($scriptUrl . '&target=' . rawurlencode($path)) . ($noReturnUrl ? '' : '+\'&returnUrl=\'+top.rawurlencode(' . $this->frameLocation($loc . '.document') . '.pathname+' . $this->frameLocation($loc . '.document') . '.search)') . ';}';
1089 return $this->linkItem(
1090 $this->label($type),
1091 $this->iconFactory->getIcon($iconName, Icon::SIZE_SMALL)->render(),
1092 $editOnClick . 'top.nav.refresh();'
1093 );
1094 }
1095
1096 /**
1097 * Returns element for copy or cut of files.
1098 *
1099 * @param string $path Path to the file/directory (target)
1100 * @param string $type Type: "copy" or "cut
1101 * @return array Item array, element in $menuItems
1102 * @internal
1103 */
1104 public function FILE_copycut($path, $type)
1105 {
1106 $isSel = '';
1107 // Pseudo table name for use in the clipboard.
1108 $table = '_FILE';
1109 $uid = GeneralUtility::shortMD5($path);
1110 if ($this->clipObj->current === 'normal') {
1111 $isSel = $this->clipObj->isSelected($table, $uid);
1112 }
1113 $addParam = [];
1114 if ($this->listFrame) {
1115 $addParam['reloadListFrame'] = 1;
1116 }
1117 return $this->linkItem(
1118 $this->label($type),
1119 $this->iconFactory->getIcon('actions-edit-' . $type . ($isSel === $type ? '-release' : ''), Icon::SIZE_SMALL)->render(),
1120 'TYPO3.ClickMenu.fetch(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlFile($path, ($type === 'copy' ? 1 : 0), ($isSel == $type), $addParam)) . ');return false;'
1121 );
1122 }
1123
1124 /**
1125 * Creates element for deleting of target
1126 *
1127 * @param string $path Path to the file/directory (target)
1128 * @return array Item array, element in $menuItems
1129 * @internal
1130 */
1131 public function FILE_delete($path)
1132 {
1133 $loc = 'top.content.list_frame';
1134 $jsCode = $loc . '.location.href='
1135 . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&redirect=')
1136 . '+top.rawurlencode(' . $this->frameLocation(($loc . '.document'))
1137 . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1138 GeneralUtility::quoteJSvalue(
1139 '&file[delete][0][data]=' . rawurlencode($path) . '&vC=' . $this->backendUser->veriCode()
1140 );
1141 if ($this->backendUser->jsConfirmation(JsConfirmation::DELETE)) {
1142 $fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($path);
1143 $title = $this->languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:delete');
1144 $confirmMessage = sprintf(
1145 $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'),
1146 $fileOrFolderObject->getName()
1147 );
1148 if ($fileOrFolderObject instanceof Folder) {
1149 $confirmMessage .= BackendUtility::referenceCount('_FILE', $fileOrFolderObject->getIdentifier(), ' ' . $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToFolder'));
1150 } else {
1151 $confirmMessage .= BackendUtility::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' ' . $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToFile'));
1152 }
1153 $jsCode = 'top.TYPO3.Modal.confirm(' . GeneralUtility::quoteJSvalue($title) . ', '
1154 . GeneralUtility::quoteJSvalue($confirmMessage) . ')'
1155 . '.on(\'button.clicked\', function(e) { if (e.target.name === \'ok\') {'
1156 . $jsCode
1157 . '} top.TYPO3.Modal.dismiss(); });';
1158 }
1159 $editOnClick = 'if(' . $loc . ') { ' . $jsCode . ' }';
1160 return $this->linkItem(
1161 $this->label('delete'),
1162 $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(),
1163 $editOnClick . 'return false;'
1164 );
1165 }
1166
1167 /**
1168 * Creates element for pasting files.
1169 *
1170 * @param string $path Path to the file/directory (target)
1171 * @param string $target target - NOT USED.
1172 * @param array $elInfo Various values for the labels.
1173 * @return array Item array, element in $menuItems
1174 * @internal
1175 */
1176 public function FILE_paste($path, $target, $elInfo)
1177 {
1178 $loc = 'top.content.list_frame';
1179
1180 $jsCode = $loc . '.location.href='
1181 . GeneralUtility::quoteJSvalue($this->clipObj->pasteUrl('_FILE', $path, 0) . '&redirect=')
1182 . '+top.rawurlencode(' . $this->frameLocation($loc . '.document')
1183 . '.pathname+' . $this->frameLocation($loc . '.document') . '.search); top.nav.refresh();';
1184
1185 if ($this->backendUser->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE)) {
1186 $title = $this->languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:clip_paste');
1187
1188 $confirmMessage = sprintf(
1189 $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:mess.'
1190 . ($elInfo[2] === 'copy' ? 'copy' : 'move') . '_into'),
1191 $elInfo[0],
1192 $elInfo[1]
1193 );
1194
1195 $jsCode = 'top.TYPO3.Modal.confirm(' . GeneralUtility::quoteJSvalue($title) . ', '
1196 . GeneralUtility::quoteJSvalue($confirmMessage) . ')'
1197 . '.on(\'button.clicked\', function(e) { if (e.target.name === \'ok\') {'
1198 . $jsCode
1199 . '} top.TYPO3.Modal.dismiss(); });';
1200 }
1201 $editOnClick = 'if(' . $loc . ') { ' . $jsCode . ' }';
1202 return $this->linkItem(
1203 $this->label('pasteinto'),
1204 $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render(),
1205 $editOnClick . 'return false;'
1206 );
1207 }
1208
1209 /**
1210 * Adding ClickMenu element for file info
1211 *
1212 * @param string $identifier The combined identifier of the file.
1213 * @return array Item array, element in $menuItems
1214 */
1215 protected function fileInfo($identifier)
1216 {
1217 return $this->DB_info('_FILE', $identifier);
1218 }
1219
1220 /***************************************
1221 *
1222 * DRAG AND DROP
1223 *
1224 ***************************************/
1225 /**
1226 * Make 1st level clickmenu:
1227 *
1228 * @param string $table The absolute path
1229 * @param int $srcId UID for the current record.
1230 * @param int $dstId Destination ID
1231 * @return array the array to be returned as JSON
1232 */
1233 public function printDragDropClickMenu($table, $srcId, $dstId)
1234 {
1235 $menuItems = [];
1236 // If the drag and drop menu should apply to PAGES use this set of menu items
1237 if ($table === 'pages') {
1238 // Move Into:
1239 $menuItems['movePage_into'] = $this->dragDrop_copymovepage($srcId, $dstId, 'move', 'into');
1240 // Move After:
1241 $menuItems['movePage_after'] = $this->dragDrop_copymovepage($srcId, $dstId, 'move', 'after');
1242 // Copy Into:
1243 $menuItems['copyPage_into'] = $this->dragDrop_copymovepage($srcId, $dstId, 'copy', 'into');
1244 // Copy After:
1245 $menuItems['copyPage_after'] = $this->dragDrop_copymovepage($srcId, $dstId, 'copy', 'after');
1246 }
1247 // If the drag and drop menu should apply to FOLDERS use this set of menu items
1248 if ($table === 'folders') {
1249 // Move Into:
1250 $menuItems['moveFolder_into'] = $this->dragDrop_copymovefolder($srcId, $dstId, 'move');
1251 // Copy Into:
1252 $menuItems['copyFolder_into'] = $this->dragDrop_copymovefolder($srcId, $dstId, 'copy');
1253 }
1254 // Adding external elements to the menuItems array
1255 $menuItems = $this->processingByExtClassArray($menuItems, 'dragDrop_' . $table, $srcId);
1256 // to extend this, you need to apply a Context Menu to a "virtual" table called "dragDrop_pages" or similar
1257 // Processing by external functions?
1258 $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
1259 // Return the printed elements:
1260 return $this->printItems($menuItems);
1261 }
1262
1263 /**
1264 * Processing the $menuItems array (for extension classes) (DRAG'N DROP)
1265 *
1266 * @param array $menuItems Array for manipulation.
1267 * @return array Processed $menuItems array
1268 */
1269 public function externalProcessingOfDragDropMenuItems($menuItems)
1270 {
1271 return $menuItems;
1272 }
1273
1274 /**
1275 * Adding CM element for Copying/Moving a Page Into/After from a drag & drop action
1276 *
1277 * @param int $srcUid source UID code for the record to modify
1278 * @param int $dstUid destination UID code for the record to modify
1279 * @param string $action Action code: either "move" or "copy
1280 * @param string $into Parameter code: either "into" or "after
1281 * @return array Item array, element in $menuItems
1282 * @internal
1283 */
1284 public function dragDrop_copymovepage($srcUid, $dstUid, $action, $into)
1285 {
1286 $negativeSign = $into === 'into' ? '' : '-';
1287 $loc = 'top.content.list_frame';
1288 $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=' .
1289 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&redirect=') . '+top.rawurlencode(' .
1290 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1291 GeneralUtility::quoteJSvalue(
1292 '&cmd[pages][' . $srcUid . '][' . $action . ']=' . $negativeSign . $dstUid . '&prErr=1&vC=' .
1293 $this->backendUser->veriCode()
1294 ) . ';};top.nav.refresh();';
1295 return $this->linkItem(
1296 $this->label($action . 'Page_' . $into),
1297 $this->iconFactory->getIcon('actions-document-paste-' . $into, Icon::SIZE_SMALL)->render(),
1298 $editOnClick . 'return false;'
1299 );
1300 }
1301
1302 /**
1303 * Adding CM element for Copying/Moving a Folder Into from a drag & drop action
1304 *
1305 * @param string $srcPath source path for the record to modify
1306 * @param string $dstPath destination path for the records to modify
1307 * @param string $action Action code: either "move" or "copy
1308 * @return array Item array, element in $menuItems
1309 * @internal
1310 */
1311 public function dragDrop_copymovefolder($srcPath, $dstPath, $action)
1312 {
1313 $loc = 'top.content.list_frame';
1314 $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=' .
1315 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&redirect=') . '+top.rawurlencode(' .
1316 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1317 GeneralUtility::quoteJSvalue(
1318 '&file[' . $action . '][0][data]=' . $srcPath . '&file[' . $action . '][0][target]=' . $dstPath . '&prErr=1&vC=' .
1319 $this->backendUser->veriCode()
1320 ) . ';};top.nav.refresh();';
1321 return $this->linkItem(
1322 $this->label($action . 'Folder_into'),
1323 $this->iconFactory->getIcon('apps-pagetree-drag-move-into', Icon::SIZE_SMALL)->render(),
1324 $editOnClick . 'return false;'
1325 );
1326 }
1327
1328 /***************************************
1329 *
1330 * COMMON
1331 *
1332 **************************************/
1333 /**
1334 * Prints the items from input $menuItems array - as JS section for writing to the div-layers.
1335 *
1336 * @param array $menuItems Array
1337 * @return array the array to be returned via JSON
1338 */
1339 public function printItems($menuItems)
1340 {
1341 // Enable/Disable items
1342 $menuItems = $this->enableDisableItems($menuItems);
1343 // Clean up spacers
1344 $menuItems = $this->cleanUpSpacers($menuItems);
1345 // Adding JS part and return the content
1346 return $this->printLayerJScode($menuItems);
1347 }
1348
1349 /**
1350 * Create the JavaScript section
1351 *
1352 * @param array $menuItems The $menuItems array to print
1353 * @return array|null the items to print, and The JavaScript section which will print the content of the CM to the div-layer in the target frame.
1354 */
1355 public function printLayerJScode($menuItems)
1356 {
1357 // Clipboard must not be submitted - then it's probably a copy/cut situation.
1358 if ($this->isCMlayers()) {
1359 // Create the table displayed in the clickmenu layer:
1360 // Wrap the inner table in another table to create outer border:
1361 return [
1362 'items' => $this->menuItemsForClickMenu($menuItems),
1363 'level' => $this->cmLevel
1364 ];
1365 }
1366 }
1367
1368 /**
1369 * Traverses the menuItems and generates an output array for implosion in the CM div-layers table.
1370 *
1371 * @param array $menuItems Array
1372 * @return array array for implosion in the CM div-layers table.
1373 */
1374 public function menuItemsForClickMenu($menuItems)
1375 {
1376 $out = [];
1377 foreach ($menuItems as $cc => $i) {
1378 // MAKE horizontal spacer
1379 if (is_string($i) && $i === 'spacer') {
1380 $out[] = '<span class="list-group-item list-group-item-divider"></span>';
1381 } else {
1382 // Just make normal element:
1383 $onClick = $i[3];
1384 $onClick = preg_replace('/return[[:space:]]+hideCM\\(\\)[[:space:]]*;/i', '', $onClick);
1385 $onClick = preg_replace('/return[[:space:]]+false[[:space:]]*;/i', '', $onClick);
1386 $onClick = preg_replace('/hideCM\\(\\);/i', '', $onClick);
1387 if (!$i[5]) {
1388 $onClick .= 'TYPO3.ClickMenu.hideAll();';
1389 }
1390 $out[] = '
1391 <a href="javascript:;" class="list-group-item" onclick="' . htmlspecialchars($onClick) . '">
1392 <span class="list-group-item-icon">' . $i[2] . '</span> ' . $i[1] . '
1393 </a>';
1394 }
1395 }
1396 return $out;
1397 }
1398
1399 /**
1400 * Adds or inserts a menu item
1401 * Can be used to set the position of new menu entries within the list of existing menu entries. Has this syntax: [cmd]:[menu entry key],[cmd].... cmd can be "after", "before" or "top" (or blank/"bottom" which is default). If "after"/"before" then menu items will be inserted after/before the existing entry with [menu entry key] if found. "after-spacer" and "before-spacer" do the same, but inserts before or after an item and a spacer. If not found, the bottom of list. If "top" the items are inserted in the top of the list.
1402 *
1403 * @param array $menuItems Menu items array
1404 * @param array $newMenuItems Menu items array to insert
1405 * @param string $position Position command string. Has this syntax: [cmd]:[menu entry key],[cmd].... cmd can be "after", "before" or "top" (or blank/"bottom" which is default). If "after"/"before" then menu items will be inserted after/before the existing entry with [menu entry key] if found. "after-spacer" and "before-spacer" do the same, but inserts before or after an item and a spacer. If not found, the bottom of list. If "top" the items are inserted in the top of the list.
1406 * @return array Menu items array, processed.
1407 */
1408 public function addMenuItems($menuItems, $newMenuItems, $position = '')
1409 {
1410 if (is_array($newMenuItems)) {
1411 $pointer = 0;
1412 if ($position) {
1413 $posArr = GeneralUtility::trimExplode(',', $position, true);
1414 foreach ($posArr as $pos) {
1415 list($place, $menuEntry) = GeneralUtility::trimExplode(':', $pos, true);
1416 list($place, $placeExtra) = GeneralUtility::trimExplode('-', $place, true);
1417 // Bottom
1418 $pointer = count($menuItems);
1419 $found = false;
1420 if ($place) {
1421 switch (strtolower($place)) {
1422 case 'after':
1423 case 'before':
1424 if ($menuEntry) {
1425 $p = 1;
1426 reset($menuItems);
1427 while (true) {
1428 if ((string)key($menuItems) === $menuEntry) {
1429 $pointer = $p;
1430 $found = true;
1431 break;
1432 }
1433 if (!next($menuItems)) {
1434 break;
1435 }
1436 $p++;
1437 }
1438 if (!$found) {
1439 break;
1440 }
1441 if ($place === 'before') {
1442 $pointer--;
1443 if ($placeExtra === 'spacer' and prev($menuItems) === 'spacer') {
1444 $pointer--;
1445 }
1446 } elseif ($place === 'after') {
1447 if ($placeExtra === 'spacer' and next($menuItems) === 'spacer') {
1448 $pointer++;
1449 }
1450 }
1451 }
1452 break;
1453 default:
1454 if (strtolower($place) === 'top') {
1455 $pointer = 0;
1456 } else {
1457 $pointer = count($menuItems);
1458 }
1459 $found = true;
1460 }
1461 }
1462 if ($found) {
1463 break;
1464 }
1465 }
1466 }
1467 $pointer = max(0, $pointer);
1468 $menuItemsBefore = array_slice($menuItems, 0, $pointer ?: 0);
1469 $menuItemsAfter = array_slice($menuItems, $pointer);
1470 $menuItems = $menuItemsBefore + $newMenuItems + $menuItemsAfter;
1471 }
1472 return $menuItems;
1473 }
1474
1475 /**
1476 * Creating an array with various elements for the clickmenu entry
1477 *
1478 * @param string $str The label, htmlspecialchar'ed already
1479 * @param string $icon <img>-tag for the icon
1480 * @param string $onClick JavaScript onclick event for label/icon
1481 * @param int $onlyCM ==1 and the element will NOT appear in clickmenus in the topframe (unless clickmenu is totally unavailable)! ==2 and the item will NEVER appear in top frame. (This is mostly for "less important" options since the top frame is not capable of holding so many elements horizontally)
1482 * @param int $dontHide If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear...
1483 * @return array $menuItem entry with 6 numerical entries: [0] is the HTML for display of the element with link and icon an mouseover etc., [1]-[5] is simply the input params passed through!
1484 */
1485 public function linkItem($str, $icon, $onClick, $onlyCM = 0, $dontHide = 0)
1486 {
1487 return [
1488 '<a href="javascript:;" onclick="' . htmlspecialchars($onClick) . '">' . $str . $icon . '</a>',
1489 $str,
1490 $icon,
1491 $onClick,
1492 $onlyCM,
1493 $dontHide
1494 ];
1495 }
1496
1497 /**
1498 * Enabling / Disabling items based on list provided from GET var ($this->iParts[3])
1499 *
1500 * @param array $menuItems Menu items array
1501 * @return array Menu items array, processed.
1502 */
1503 public function enableDisableItems($menuItems)
1504 {
1505 if ($this->iParts[3]) {
1506 // Detect "only" mode: (only showing listed items)
1507 if ($this->iParts[3][0] === '+') {
1508 $this->iParts[3] = substr($this->iParts[3], 1);
1509 $only = true;
1510 } else {
1511 $only = false;
1512 }
1513 // Do filtering:
1514 // Transfer ONLY elements which are mentioned (or are spacers)
1515 if ($only) {
1516 $newMenuArray = [];
1517 foreach ($menuItems as $key => $value) {
1518 if (GeneralUtility::inList($this->iParts[3], $key) || is_string($value) && $value === 'spacer') {
1519 $newMenuArray[$key] = $value;
1520 }
1521 }
1522 $menuItems = $newMenuArray;
1523 } else {
1524 // Traverse all elements except those listed (just unsetting them):
1525 $elements = GeneralUtility::trimExplode(',', $this->iParts[3], true);
1526 foreach ($elements as $value) {
1527 unset($menuItems[$value]);
1528 }
1529 }
1530 }
1531 // Return processed menu items:
1532 return $menuItems;
1533 }
1534
1535 /**
1536 * Clean up spacers; Will remove any spacers in the start/end of menu items array plus any duplicates.
1537 *
1538 * @param array $menuItems Menu items array
1539 * @return array Menu items array, processed.
1540 */
1541 public function cleanUpSpacers($menuItems)
1542 {
1543 // Remove doubles:
1544 $prevItemWasSpacer = false;
1545 foreach ($menuItems as $key => $value) {
1546 if (is_string($value) && $value === 'spacer') {
1547 if ($prevItemWasSpacer) {
1548 unset($menuItems[$key]);
1549 }
1550 $prevItemWasSpacer = true;
1551 } else {
1552 $prevItemWasSpacer = false;
1553 }
1554 }
1555 // Remove first:
1556 reset($menuItems);
1557 $key = key($menuItems);
1558 $value = current($menuItems);
1559 if (is_string($value) && $value === 'spacer') {
1560 unset($menuItems[$key]);
1561 }
1562 // Remove last:
1563 end($menuItems);
1564 $key = key($menuItems);
1565 $value = current($menuItems);
1566 if (is_string($value) && $value === 'spacer') {
1567 unset($menuItems[$key]);
1568 }
1569 // Return processed menu items:
1570 return $menuItems;
1571 }
1572
1573 /**
1574 * Get label from locallang_core.xlf:cm.*
1575 *
1576 * @param string $label The "cm."-suffix to get.
1577 * @return string
1578 */
1579 public function label($label)
1580 {
1581 return htmlspecialchars($this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.' . $label));
1582 }
1583
1584 /**
1585 * Returns TRUE if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers)
1586 *
1587 * @return bool
1588 */
1589 public function isCMlayers()
1590 {
1591 return !$this->CB;
1592 }
1593
1594 /**
1595 * Appends ".location" to input string
1596 *
1597 * @param string $str Input string, probably a JavaScript document reference
1598 * @return string
1599 */
1600 public function frameLocation($str)
1601 {
1602 return $str . '.location';
1603 }
1604 }