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