ea7cf0cc950a38caab76274a7d569ffc19b1fb6c
[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' ? $this->rec['uid'] : $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, $this->rec['uid']);
264 $menuItems['view'] = $this->DB_view($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, $elInfo);
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' ? $this->rec['uid'] : $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 $this->languageService->makeEntities($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 $this->languageService->makeEntities($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 $this->languageService->makeEntities($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 $this->languageService->makeEntities($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 mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
689 $tmpTSc = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod.web_list');
690 $tmpTSc = $tmpTSc['properties']['newContentWiz.']['overrideWithExtension'];
691
692 $newContentWizScriptPath = ExtensionManagementUtility::isLoaded($tmpTSc) ? ExtensionManagementUtility::extRelPath($tmpTSc) . 'mod1/db_new_content_el.php?' : BackendUtility::getModuleUrl('new_content_element') . '&';
693 $url = $table === 'pages' ? BackendUtility::getModuleUrl('db_new', ['id' => $uid, 'pagesOnly' => 1]) : $newContentWizScriptPath . 'id=' . $rec['pid'] . '&sys_language_uid=' . (int)$rec['sys_language_uid'];
694 return $this->linkItem(
695 $this->languageService->makeEntities($this->languageService->getLL('CM_newWizard')),
696 $this->iconFactory->getIcon(($table === 'pages' ? 'actions-page-new' : 'actions-document-new'), Icon::SIZE_SMALL)->render(),
697 $this->urlRefForCM($url, 'returnUrl')
698 );
699 }
700
701 /**
702 * Adding CM element for Editing of the access related fields of a table (disable, starttime, endtime, fe_groups)
703 *
704 * @param string $table Table name
705 * @param int $uid UID for the current record.
706 * @return array Item array, element in $menuItems
707 * @internal
708 */
709 public function DB_editAccess($table, $uid)
710 {
711 $url = BackendUtility::getModuleUrl('record_edit', array(
712 'columnsOnly' => rawurlencode((implode(',', $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']) . ($table === 'pages' ? ',extendToSubpages' : ''))),
713 'edit[' . $table . '][' . $uid . ']' => 'edit'
714 ));
715 return $this->linkItem(
716 $this->languageService->makeEntities($this->languageService->getLL('CM_editAccess')),
717 $this->iconFactory->getIcon('actions-document-edit-access', Icon::SIZE_SMALL)->render(),
718 $this->urlRefForCM($url, 'returnUrl'),
719 1
720 );
721 }
722
723 /**
724 * Adding CM element for edit page properties
725 *
726 * @param int $uid page uid to edit (PID)
727 * @return array Item array, element in $menuItems
728 * @internal
729 */
730 public function DB_editPageProperties($uid)
731 {
732 $url = BackendUtility::getModuleUrl('record_edit', array(
733 'edit[pages][' . $uid . ']' => 'edit'
734 ));
735 return $this->linkItem(
736 $this->languageService->makeEntities($this->languageService->getLL('CM_editPageProperties')),
737 $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render(),
738 $this->urlRefForCM($url, 'returnUrl'),
739 1
740 );
741 }
742
743 /**
744 * Adding CM element for regular editing of the element!
745 *
746 * @param string $table Table name
747 * @param int $uid UID for the current record.
748 * @return array Item array, element in $menuItems
749 * @internal
750 */
751 public function DB_edit($table, $uid)
752 {
753 // If another module was specified, replace the default Page module with the new one
754 $newPageModule = trim($this->backendUser->getTSConfigVal('options.overridePageModule'));
755 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
756 $loc = 'top.content.list_frame';
757 $theIcon = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render();
758
759 $link = BackendUtility::getModuleUrl('record_edit', array(
760 'edit[' . $table . '][' . $uid . ']' => 'edit'
761 ));
762
763 if ($this->iParts[0] === 'pages' && $this->iParts[1] && $this->backendUser->check('modules', $pageModule)) {
764 $this->editPageIconSet = true;
765 }
766 $editOnClick = 'if(' . $loc . '){' . $loc . '.location.href=' . GeneralUtility::quoteJSvalue($link . '&returnUrl=') . '+top.rawurlencode(' . $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search);}';
767 return $this->linkItem($this->label('edit'), $theIcon, $editOnClick . ';');
768 }
769
770 /**
771 * Adding CM element for regular Create new element
772 *
773 * @param string $table Table name
774 * @param int $uid UID for the current record.
775 * @return array Item array, element in $menuItems
776 * @internal
777 */
778 public function DB_new($table, $uid)
779 {
780 $frame = 'top.content.list_frame';
781 $location = $this->frameLocation($frame . '.document');
782 $module = $this->listFrame
783 ? GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('record_edit', array('edit[' . $table . '][-' . $uid . ']' => 'new')) . '&returnUrl=') . '+top.rawurlencode(' . $location . '.pathname+' . $location . '.search)'
784 : GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', array('id' => (int)$uid)));
785 $editOnClick = 'if(' . $frame . '){' . $frame . '.location.href=' . $module . ';}';
786 $icon = $this->iconFactory->getIcon('actions-' . ($table === 'pages' ? 'page' : 'document') . '-new', Icon::SIZE_SMALL)->render();
787 return $this->linkItem($this->label('new'), $icon, $editOnClick);
788 }
789
790 /**
791 * Adding CM element for Delete
792 *
793 * @param string $table Table name
794 * @param int $uid UID for the current record.
795 * @param array $elInfo Label for including in the confirmation message, EXT:lang/locallang_core.xlf:mess.delete
796 * @return array Item array, element in $menuItems
797 * @internal
798 */
799 public function DB_delete($table, $uid, $elInfo)
800 {
801 $loc = 'top.content.list_frame';
802 if ($this->backendUser->jsConfirmation(JsConfirmation::DELETE)) {
803 $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')))) . ')';
804 } else {
805 $conf = '1==1';
806 }
807 $editOnClick = 'if(' . $loc . ' && ' . $conf . ' ){' . $loc . '.location.href=' .
808 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&redirect=') . '+top.rawurlencode(' .
809 $this->frameLocation($loc . '.document') . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
810 GeneralUtility::quoteJSvalue(
811 '&cmd[' . $table . '][' . $uid . '][delete]=1&prErr=1&vC=' . $this->backendUser->veriCode()
812 ) . ';};';
813 if ($table === 'pages') {
814 $editOnClick .= 'top.nav.refresh.defer(500, top.nav);';
815 }
816 return $this->linkItem(
817 $this->label('delete'),
818 $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(),
819 $editOnClick . 'return false;'
820 );
821 }
822
823 /**
824 * Adding CM element for View Page
825 *
826 * @param int $id Page uid (PID)
827 * @param string $anchor Anchor, if any
828 * @return array Item array, element in $menuItems
829 * @internal
830 */
831 public function DB_view($id, $anchor = '')
832 {
833 $icon = $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render();
834 return $this->linkItem($this->label('view'), $icon, BackendUtility::viewOnClick($id, '', null, $anchor) . ';');
835 }
836
837 /**
838 * Adding element for setting temporary mount point.
839 *
840 * @param int $page_id Page uid (PID)
841 * @return array Item array, element in $menuItems
842 * @internal
843 */
844 public function DB_tempMountPoint($page_id)
845 {
846 return $this->linkItem(
847 $this->label('tempMountPoint'),
848 $this->iconFactory->getIcon('apps-pagetree-page-mountpoint', Icon::SIZE_SMALL)->render(),
849 'if (top.content.nav_frame) {
850 var node = top.TYPO3.Backend.NavigationContainer.PageTree.getSelected();
851 if (node === null) {
852 return false;
853 }
854
855 var useNode = {
856 attributes: {
857 nodeData: {
858 id: ' . (int)$page_id . '
859 }
860 }
861 };
862
863 node.ownerTree.commandProvider.mountAsTreeRoot(useNode, node.ownerTree);
864 }
865 ');
866 }
867
868 /**
869 * Adding CM element for hide/unhide of the input record
870 *
871 * @param string $table Table name
872 * @param array $rec Record array
873 * @param string $hideField Name of the hide field
874 * @return array Item array, element in $menuItems
875 * @internal
876 */
877 public function DB_hideUnhide($table, $rec, $hideField)
878 {
879 return $this->DB_changeFlag($table, $rec, $hideField, $this->label(($rec[$hideField] ? 'un' : '') . 'hide'), 'hide');
880 }
881
882 /**
883 * Adding CM element for a flag field of the input record
884 *
885 * @param string $table Table name
886 * @param array $rec Record array
887 * @param string $flagField Name of the flag field
888 * @param string $title Menu item Title
889 * @return array Item array, element in $menuItems
890 */
891 public function DB_changeFlag($table, $rec, $flagField, $title)
892 {
893 $uid = $rec['_ORIG_uid'] ?: $rec['uid'];
894 $loc = 'top.content.list_frame';
895 $editOnClick = 'if(' . $loc . '){' . $loc . '.location.href=' .
896 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&redirect=') . '+top.rawurlencode(' .
897 $this->frameLocation($loc . '.document') . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
898 GeneralUtility::quoteJSvalue(
899 '&data[' . $table . '][' . $uid . '][' . $flagField . ']=' . ($rec[$flagField] ? 0 : 1) . '&prErr=1&vC=' . $this->backendUser->veriCode()
900 ) . ';};';
901 if ($table === 'pages') {
902 $editOnClick .= 'top.nav.refresh.defer(500, top.nav);';
903 }
904 return $this->linkItem(
905 $title,
906 $this->iconFactory->getIcon('actions-edit-' . ($rec[$flagField] ? 'un' : '') . 'hide', Icon::SIZE_SMALL)->render(),
907 $editOnClick . 'return false;',
908 1
909 );
910 }
911
912 /***************************************
913 *
914 * FILE
915 *
916 ***************************************/
917 /**
918 * Make 1st level clickmenu:
919 *
920 * @param string $combinedIdentifier The combined identifier
921 * @return string HTML content
922 * @see \TYPO3\CMS\Core\Resource\ResourceFactory::retrieveFileOrFolderObject()
923 */
924 public function printFileClickMenu($combinedIdentifier)
925 {
926 $icon = '';
927 $identifier = '';
928 $menuItems = array();
929 $combinedIdentifier = rawurldecode($combinedIdentifier);
930 $fileObject = ResourceFactory::getInstance()
931 ->retrieveFileOrFolderObject($combinedIdentifier);
932 if ($fileObject) {
933 $folder = false;
934 $isStorageRoot = false;
935 $isOnline = true;
936 $userMayViewStorage = false;
937 $userMayEditStorage = false;
938 $identifier = $fileObject->getCombinedIdentifier();
939 if ($fileObject instanceof Folder) {
940 $icon = '<span title="' . htmlspecialchars($fileObject->getName()) . '" class="absmiddle">'
941 . $this->iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render()
942 . '</span>';
943 $folder = true;
944 if ($fileObject->getIdentifier() === $fileObject->getStorage()->getRootLevelFolder()->getIdentifier()) {
945 $isStorageRoot = true;
946 if ($this->backendUser->check('tables_select', 'sys_file_storage')) {
947 $userMayViewStorage = true;
948 }
949 if ($this->backendUser->check('tables_modify', 'sys_file_storage')) {
950 $userMayEditStorage = true;
951 }
952 }
953 if (!$fileObject->getStorage()->isOnline()) {
954 $isOnline = false;
955 }
956 } else {
957 $title = $fileObject->getName() . ' (' . GeneralUtility::formatSize($fileObject->getSize()) . ')';
958 $icon = '<span class="absmiddle" title="' . htmlspecialchars($title) . '">'
959 . $this->iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render()
960 . '</span>';
961 }
962 // Hide
963 if (!in_array('hide', $this->disabledItems, true) && $isStorageRoot && $userMayEditStorage) {
964 $record = BackendUtility::getRecord('sys_file_storage', $fileObject->getStorage()->getUid());
965 $menuItems['hide'] = $this->DB_changeFlag(
966 'sys_file_storage',
967 $record,
968 'is_online',
969 $this->label($record['is_online'] ? 'offline' : 'online'),
970 'hide'
971 );
972 }
973 // Edit
974 if (!in_array('edit', $this->disabledItems, true) && $fileObject->checkActionPermission('write')) {
975 if (!$folder && !$isStorageRoot && $fileObject->isIndexed() && $this->backendUser->check('tables_modify', 'sys_file_metadata')) {
976 $metaData = $fileObject->_getMetaData();
977 $menuItems['edit2'] = $this->DB_edit('sys_file_metadata', $metaData['uid']);
978 }
979 if (!$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileObject->getExtension()) && $fileObject->checkActionPermission('write')) {
980 $menuItems['edit'] = $this->FILE_launch($identifier, 'file_edit', 'editcontent', 'actions-page-open');
981 } elseif ($isStorageRoot && $userMayEditStorage) {
982 $menuItems['edit'] = $this->DB_edit('sys_file_storage', $fileObject->getStorage()->getUid());
983 }
984 }
985 // Rename
986 if (!in_array('rename', $this->disabledItems, true) && !$isStorageRoot && $fileObject->checkActionPermission('rename')) {
987 $menuItems['rename'] = $this->FILE_launch($identifier, 'file_rename', 'rename', 'actions-edit-rename');
988 }
989 // Upload
990 if (!in_array('upload', $this->disabledItems, true) && $folder && $isOnline && $fileObject->checkActionPermission('write')) {
991 $menuItems['upload'] = $this->FILE_launch($identifier, 'file_upload', 'upload', 'actions-edit-upload');
992 }
993 // New
994 if (!in_array('new', $this->disabledItems, true) && $folder && $isOnline && $fileObject->checkActionPermission('write')) {
995 $menuItems['new'] = $this->FILE_launch($identifier, 'file_newfolder', 'new', 'actions-document-new');
996 }
997 // Info
998 if (!in_array('info', $this->disabledItems, true) && $fileObject->checkActionPermission('read')) {
999 if ($isStorageRoot && $userMayViewStorage) {
1000 $menuItems['info'] = $this->DB_info('sys_file_storage', $fileObject->getStorage()->getUid());
1001 } elseif (!$folder) {
1002 $menuItems['info'] = $this->fileInfo($identifier);
1003 }
1004 }
1005 $menuItems[] = 'spacer';
1006 // Copy:
1007 if (!in_array('copy', $this->disabledItems, true) && !$isStorageRoot && $fileObject->checkActionPermission('read')) {
1008 $menuItems['copy'] = $this->FILE_copycut($identifier, 'copy');
1009 }
1010 // Cut:
1011 if (!in_array('cut', $this->disabledItems, true) && !$isStorageRoot && $fileObject->checkActionPermission('move')) {
1012 $menuItems['cut'] = $this->FILE_copycut($identifier, 'cut');
1013 }
1014 // Paste:
1015 $elFromAllTables = count($this->clipObj->elFromTable('_FILE'));
1016 if (!in_array('paste', $this->disabledItems, true) && $elFromAllTables && $folder && $fileObject->checkActionPermission('write')) {
1017 $elArr = $this->clipObj->elFromTable('_FILE');
1018 $selItem = reset($elArr);
1019 $clickedFileOrFolder = ResourceFactory::getInstance()->retrieveFileOrFolderObject($combinedIdentifier);
1020 $fileOrFolderInClipBoard = ResourceFactory::getInstance()->retrieveFileOrFolderObject($selItem);
1021 $elInfo = array(
1022 $fileOrFolderInClipBoard->getName(),
1023 $clickedFileOrFolder->getName(),
1024 $this->clipObj->currentMode()
1025 );
1026 if (!$fileOrFolderInClipBoard instanceof Folder || !$fileOrFolderInClipBoard->getStorage()->isWithinFolder($fileOrFolderInClipBoard, $clickedFileOrFolder)) {
1027 $menuItems['pasteinto'] = $this->FILE_paste($identifier, $selItem, $elInfo);
1028 }
1029 }
1030 $menuItems[] = 'spacer';
1031 // Delete:
1032 if (!in_array('delete', $this->disabledItems, true) && $fileObject->checkActionPermission('delete')) {
1033 if ($isStorageRoot && $userMayEditStorage) {
1034 $elInfo = array(GeneralUtility::fixed_lgd_cs($fileObject->getStorage()->getName(), $this->backendUser->uc['titleLen']));
1035 $menuItems['delete'] = $this->DB_delete('sys_file_storage', $fileObject->getStorage()->getUid(), $elInfo);
1036 } elseif (!$isStorageRoot) {
1037 $menuItems['delete'] = $this->FILE_delete($identifier);
1038 }
1039 }
1040 }
1041 // Adding external elements to the menuItems array
1042 $menuItems = $this->processingByExtClassArray($menuItems, $identifier, 0);
1043 // Processing by external functions?
1044 $menuItems = $this->externalProcessingOfFileMenuItems($menuItems);
1045 // Return the printed elements:
1046 return $this->printItems($menuItems);
1047 }
1048
1049 /**
1050 * Processing the $menuItems array (for extension classes) (FILES)
1051 *
1052 * @param array $menuItems Array for manipulation.
1053 * @return array Processed $menuItems array
1054 */
1055 public function externalProcessingOfFileMenuItems($menuItems)
1056 {
1057 return $menuItems;
1058 }
1059
1060 /**
1061 * Multi-function for adding an entry to the $menuItems array
1062 *
1063 * @param string $path Path to the file/directory (target)
1064 * @param string $moduleName Script (deprecated) or module name (e.g. file_edit) to pass &target= to
1065 * @param string $type "type" is the code which fetches the correct label for the element from "cm.
1066 * @param string $iconName
1067 * @param bool $noReturnUrl If set, the return URL parameter will not be set in the link
1068 * @return array Item array, element in $menuItems
1069 * @internal
1070 */
1071 public function FILE_launch($path, $moduleName, $type, $iconName, $noReturnUrl = false)
1072 {
1073 $loc = 'top.content.list_frame';
1074
1075 if (strpos($moduleName, '.php') !== false) {
1076 GeneralUtility::deprecationLog(
1077 'Using a php file directly in ClickMenu is deprecated since TYPO3 CMS 7, and will be removed in CMS 8.'
1078 . ' Register the class as module and use BackendUtility::getModuleUrl() to get the right link.'
1079 . ' For examples how to do this see ext_tables.php of EXT:backend.'
1080 );
1081 $scriptUrl = $moduleName;
1082 } else {
1083 $scriptUrl = BackendUtility::getModuleUrl($moduleName);
1084 }
1085
1086 $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)') . ';}';
1087 return $this->linkItem(
1088 $this->label($type),
1089 $this->iconFactory->getIcon($iconName, Icon::SIZE_SMALL)->render(),
1090 $editOnClick . 'top.nav.refresh();'
1091 );
1092 }
1093
1094 /**
1095 * Returns element for copy or cut of files.
1096 *
1097 * @param string $path Path to the file/directory (target)
1098 * @param string $type Type: "copy" or "cut
1099 * @return array Item array, element in $menuItems
1100 * @internal
1101 */
1102 public function FILE_copycut($path, $type)
1103 {
1104 $isSel = '';
1105 // Pseudo table name for use in the clipboard.
1106 $table = '_FILE';
1107 $uid = GeneralUtility::shortmd5($path);
1108 if ($this->clipObj->current === 'normal') {
1109 $isSel = $this->clipObj->isSelected($table, $uid);
1110 }
1111 $addParam = array();
1112 if ($this->listFrame) {
1113 $addParam['reloadListFrame'] = $this->alwaysContentFrame ? 2 : 1;
1114 }
1115 return $this->linkItem(
1116 $this->label($type),
1117 $this->iconFactory->getIcon('actions-edit-' . $type . ($isSel === $type ? '-release' : ''), Icon::SIZE_SMALL)->render(),
1118 'TYPO3.ClickMenu.fetch(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlFile($path, ($type === 'copy' ? 1 : 0), ($isSel == $type), $addParam)) . ');return false;'
1119 );
1120 }
1121
1122 /**
1123 * Creates element for deleting of target
1124 *
1125 * @param string $path Path to the file/directory (target)
1126 * @return array Item array, element in $menuItems
1127 * @internal
1128 */
1129 public function FILE_delete($path)
1130 {
1131 $loc = 'top.content.list_frame';
1132 if ($this->backendUser->jsConfirmation(JsConfirmation::DELETE)) {
1133 $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')))) . ')';
1134 } else {
1135 $conf = '1==1';
1136 }
1137 $editOnClick = 'if(' . $loc . ' && ' . $conf . ' ){' . $loc . '.location.href=' .
1138 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&redirect=') . '+top.rawurlencode(' .
1139 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1140 GeneralUtility::quoteJSvalue(
1141 '&file[delete][0][data]=' . rawurlencode($path) . '&vC=' . $this->backendUser->veriCode()
1142 ) . ';};';
1143 return $this->linkItem(
1144 $this->label('delete'),
1145 $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(),
1146 $editOnClick . 'return false;'
1147 );
1148 }
1149
1150 /**
1151 * Creates element for pasting files.
1152 *
1153 * @param string $path Path to the file/directory (target)
1154 * @param string $target target - NOT USED.
1155 * @param array $elInfo Various values for the labels.
1156 * @return array Item array, element in $menuItems
1157 * @internal
1158 */
1159 public function FILE_paste($path, $target, $elInfo)
1160 {
1161 $loc = 'top.content.list_frame';
1162 if ($this->backendUser->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE)) {
1163 $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])) . ')';
1164 } else {
1165 $conf = $loc;
1166 }
1167 $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();';
1168 return $this->linkItem(
1169 $this->label('pasteinto'),
1170 $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render(),
1171 $editOnClick . 'return false;'
1172 );
1173 }
1174
1175 /**
1176 * Adding ClickMenu element for file info
1177 *
1178 * @param string $identifier The combined identifier of the file.
1179 * @return array Item array, element in $menuItems
1180 */
1181 protected function fileInfo($identifier)
1182 {
1183 return $this->DB_info('_FILE', $identifier);
1184 }
1185
1186 /***************************************
1187 *
1188 * DRAG AND DROP
1189 *
1190 ***************************************/
1191 /**
1192 * Make 1st level clickmenu:
1193 *
1194 * @param string $table The absolute path
1195 * @param int $srcId UID for the current record.
1196 * @param int $dstId Destination ID
1197 * @return string HTML content
1198 */
1199 public function printDragDropClickMenu($table, $srcId, $dstId)
1200 {
1201 $menuItems = array();
1202 // If the drag and drop menu should apply to PAGES use this set of menu items
1203 if ($table === 'pages') {
1204 // Move Into:
1205 $menuItems['movePage_into'] = $this->dragDrop_copymovepage($srcId, $dstId, 'move', 'into');
1206 // Move After:
1207 $menuItems['movePage_after'] = $this->dragDrop_copymovepage($srcId, $dstId, 'move', 'after');
1208 // Copy Into:
1209 $menuItems['copyPage_into'] = $this->dragDrop_copymovepage($srcId, $dstId, 'copy', 'into');
1210 // Copy After:
1211 $menuItems['copyPage_after'] = $this->dragDrop_copymovepage($srcId, $dstId, 'copy', 'after');
1212 }
1213 // If the drag and drop menu should apply to FOLDERS use this set of menu items
1214 if ($table === 'folders') {
1215 // Move Into:
1216 $menuItems['moveFolder_into'] = $this->dragDrop_copymovefolder($srcId, $dstId, 'move');
1217 // Copy Into:
1218 $menuItems['copyFolder_into'] = $this->dragDrop_copymovefolder($srcId, $dstId, 'copy');
1219 }
1220 // Adding external elements to the menuItems array
1221 $menuItems = $this->processingByExtClassArray($menuItems, 'dragDrop_' . $table, $srcId);
1222 // to extend this, you need to apply a Context Menu to a "virtual" table called "dragDrop_pages" or similar
1223 // Processing by external functions?
1224 $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
1225 // Return the printed elements:
1226 return $this->printItems($menuItems);
1227 }
1228
1229 /**
1230 * Processing the $menuItems array (for extension classes) (DRAG'N DROP)
1231 *
1232 * @param array $menuItems Array for manipulation.
1233 * @return array Processed $menuItems array
1234 */
1235 public function externalProcessingOfDragDropMenuItems($menuItems)
1236 {
1237 return $menuItems;
1238 }
1239
1240 /**
1241 * Adding CM element for Copying/Moving a Page Into/After from a drag & drop action
1242 *
1243 * @param int $srcUid source UID code for the record to modify
1244 * @param int $dstUid destination UID code for the record to modify
1245 * @param string $action Action code: either "move" or "copy
1246 * @param string $into Parameter code: either "into" or "after
1247 * @return array Item array, element in $menuItems
1248 * @internal
1249 */
1250 public function dragDrop_copymovepage($srcUid, $dstUid, $action, $into)
1251 {
1252 $negativeSign = $into === 'into' ? '' : '-';
1253 $loc = 'top.content.list_frame';
1254 $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=' .
1255 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&redirect=') . '+top.rawurlencode(' .
1256 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1257 GeneralUtility::quoteJSvalue(
1258 '&cmd[pages][' . $srcUid . '][' . $action . ']=' . $negativeSign . $dstUid . '&prErr=1&vC=' .
1259 $this->backendUser->veriCode()
1260 ) . ';};top.nav.refresh();';
1261 return $this->linkItem(
1262 $this->label($action . 'Page_' . $into),
1263 $this->iconFactory->getIcon('actions-document-paste-' . $into, Icon::SIZE_SMALL)->render(),
1264 $editOnClick . 'return false;'
1265 );
1266 }
1267
1268 /**
1269 * Adding CM element for Copying/Moving a Folder Into from a drag & drop action
1270 *
1271 * @param string $srcPath source path for the record to modify
1272 * @param string $dstPath destination path for the records to modify
1273 * @param string $action Action code: either "move" or "copy
1274 * @return array Item array, element in $menuItems
1275 * @internal
1276 */
1277 public function dragDrop_copymovefolder($srcPath, $dstPath, $action)
1278 {
1279 $loc = 'top.content.list_frame';
1280 $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=' .
1281 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&redirect=') . '+top.rawurlencode(' .
1282 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1283 GeneralUtility::quoteJSvalue(
1284 '&file[' . $action . '][0][data]=' . $srcPath . '&file[' . $action . '][0][target]=' . $dstPath . '&prErr=1&vC=' .
1285 $this->backendUser->veriCode()
1286 ) . ';};top.nav.refresh();';
1287 return $this->linkItem(
1288 $this->label($action . 'Folder_into'),
1289 $this->iconFactory->getIcon('apps-pagetree-drag-move-into', Icon::SIZE_SMALL)->render(),
1290 $editOnClick . 'return false;'
1291 );
1292 }
1293
1294 /***************************************
1295 *
1296 * COMMON
1297 *
1298 **************************************/
1299 /**
1300 * Prints the items from input $menuItems array - as JS section for writing to the div-layers.
1301 *
1302 * @param array $menuItems Array
1303 * @return string HTML code
1304 */
1305 public function printItems($menuItems)
1306 {
1307 // Enable/Disable items
1308 $menuItems = $this->enableDisableItems($menuItems);
1309 // Clean up spacers
1310 $menuItems = $this->cleanUpSpacers($menuItems);
1311 // Adding JS part and return the content
1312 return $this->printLayerJScode($menuItems);
1313 }
1314
1315 /**
1316 * Create the JavaScript section
1317 *
1318 * @param array $menuItems The $menuItems array to print
1319 * @return string The JavaScript section which will print the content of the CM to the div-layer in the target frame.
1320 */
1321 public function printLayerJScode($menuItems)
1322 {
1323 // Clipboard must not be submitted - then it's probably a copy/cut situation.
1324 if ($this->isCMlayers()) {
1325 // Create the table displayed in the clickmenu layer:
1326 // Wrap the inner table in another table to create outer border:
1327 $CMtable = '
1328 <div class="typo3-CSM-wrapperCM">
1329 <table border="0" cellpadding="0" cellspacing="0" class="typo3-CSM">
1330 ' . implode('', $this->menuItemsForClickMenu($menuItems)) . '
1331 </table></div>';
1332 return '<data><clickmenu><htmltable><![CDATA[' . $CMtable . ']]></htmltable><cmlevel>' . $this->cmLevel . '</cmlevel></clickmenu></data>';
1333 }
1334 }
1335
1336 /**
1337 * Wrapping the input string in a table with background color 4 and a black border style.
1338 * For the pop-up menu
1339 *
1340 * @param string $str HTML content to wrap in table.
1341 * @return string
1342 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1343 */
1344 public function wrapColorTableCM($str)
1345 {
1346 GeneralUtility::logDeprecatedFunction();
1347 return '<div class="typo3-CSM-wrapperCM">
1348 ' . $str . '
1349 </div>';
1350 }
1351
1352 /**
1353 * Traverses the menuItems and generates an output array for implosion in the CM div-layers table.
1354 *
1355 * @param array $menuItems Array
1356 * @return array array for implosion in the CM div-layers table.
1357 */
1358 public function menuItemsForClickMenu($menuItems)
1359 {
1360 $out = array();
1361 foreach ($menuItems as $cc => $i) {
1362 // MAKE horizontal spacer
1363 if (is_string($i) && $i === 'spacer') {
1364 $out[] = '
1365 <tr style="height: 1px;" class="bgColor2">
1366 <td colspan="2"></td>
1367 </tr>';
1368 } else {
1369 // Just make normal element:
1370 $onClick = $i[3];
1371 $onClick = preg_replace('/return[[:space:]]+hideCM\\(\\)[[:space:]]*;/i', '', $onClick);
1372 $onClick = preg_replace('/return[[:space:]]+false[[:space:]]*;/i', '', $onClick);
1373 $onClick = preg_replace('/hideCM\\(\\);/i', '', $onClick);
1374 if (!$i[5]) {
1375 $onClick .= 'TYPO3.ClickMenu.hideAll();';
1376 }
1377 $CSM = ' oncontextmenu="this.click();return false;"';
1378 $out[] = '
1379 <tr class="typo3-CSM-itemRow" onclick="' . htmlspecialchars($onClick) . '"' . $CSM . '>
1380 ' . (!$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>') . '
1381 </tr>';
1382 }
1383 }
1384 return $out;
1385 }
1386
1387 /**
1388 * Adds or inserts a menu item
1389 * 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.
1390 *
1391 * @param array $menuItems Menu items array
1392 * @param array $newMenuItems Menu items array to insert
1393 * @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.
1394 * @return array Menu items array, processed.
1395 */
1396 public function addMenuItems($menuItems, $newMenuItems, $position = '')
1397 {
1398 if (is_array($newMenuItems)) {
1399 if ($position) {
1400 $posArr = GeneralUtility::trimExplode(',', $position, true);
1401 foreach ($posArr as $pos) {
1402 list($place, $menuEntry) = GeneralUtility::trimExplode(':', $pos, true);
1403 list($place, $placeExtra) = GeneralUtility::trimExplode('-', $place, true);
1404 // Bottom
1405 $pointer = count($menuItems);
1406 $found = false;
1407 if ($place) {
1408 switch (strtolower($place)) {
1409 case 'after':
1410 case 'before':
1411 if ($menuEntry) {
1412 $p = 1;
1413 reset($menuItems);
1414 while (true) {
1415 if ((string)key($menuItems) === $menuEntry) {
1416 $pointer = $p;
1417 $found = true;
1418 break;
1419 }
1420 if (!next($menuItems)) {
1421 break;
1422 }
1423 $p++;
1424 }
1425 if (!$found) {
1426 break;
1427 }
1428 if ($place === 'before') {
1429 $pointer--;
1430 if ($placeExtra === 'spacer' and prev($menuItems) === 'spacer') {
1431 $pointer--;
1432 }
1433 } elseif ($place === 'after') {
1434 if ($placeExtra === 'spacer' and next($menuItems) === 'spacer') {
1435 $pointer++;
1436 }
1437 }
1438 }
1439 break;
1440 default:
1441 if (strtolower($place) === 'top') {
1442 $pointer = 0;
1443 } else {
1444 $pointer = count($menuItems);
1445 }
1446 $found = true;
1447 }
1448 }
1449 if ($found) {
1450 break;
1451 }
1452 }
1453 }
1454 $pointer = max(0, $pointer);
1455 $menuItemsBefore = array_slice($menuItems, 0, $pointer ?: 0);
1456 $menuItemsAfter = array_slice($menuItems, $pointer);
1457 $menuItems = $menuItemsBefore + $newMenuItems + $menuItemsAfter;
1458 }
1459 return $menuItems;
1460 }
1461
1462 /**
1463 * Creating an array with various elements for the clickmenu entry
1464 *
1465 * @param string $str The label, htmlspecialchar'ed already
1466 * @param string $icon <img>-tag for the icon
1467 * @param string $onClick JavaScript onclick event for label/icon
1468 * @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)
1469 * @param bool $dontHide If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear...
1470 * @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!
1471 */
1472 public function linkItem($str, $icon, $onClick, $onlyCM = 0, $dontHide = 0)
1473 {
1474 $onClick = str_replace('top.loadTopMenu', 'showClickmenu_raw', $onClick);
1475 return array(
1476 '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $str . $icon . '</a>',
1477 $str,
1478 $icon,
1479 $onClick,
1480 $onlyCM,
1481 $dontHide
1482 );
1483 }
1484
1485 /**
1486 * Returns the input string IF not a user setting has disabled display of icons.
1487 *
1488 * @param string $iconCode The icon-image tag
1489 * @return string The icon-image tag prefixed with space char IF the icon should be printed at all due to user settings
1490 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1491 */
1492 public function excludeIcon($iconCode)
1493 {
1494 GeneralUtility::logDeprecatedFunction();
1495 return $this->backendUser->uc['noMenuMode'] && $this->backendUser->uc['noMenuMode'] !== 'icons' ? '' : ' ' . $iconCode;
1496 }
1497
1498 /**
1499 * Enabling / Disabling items based on list provided from GET var ($this->iParts[3])
1500 *
1501 * @param array $menuItems Menu items array
1502 * @return array Menu items array, processed.
1503 */
1504 public function enableDisableItems($menuItems)
1505 {
1506 if ($this->iParts[3]) {
1507 // Detect "only" mode: (only showing listed items)
1508 if ($this->iParts[3][0] === '+') {
1509 $this->iParts[3] = substr($this->iParts[3], 1);
1510 $only = true;
1511 } else {
1512 $only = false;
1513 }
1514 // Do filtering:
1515 // Transfer ONLY elements which are mentioned (or are spacers)
1516 if ($only) {
1517 $newMenuArray = array();
1518 foreach ($menuItems as $key => $value) {
1519 if (GeneralUtility::inList($this->iParts[3], $key) || is_string($value) && $value === 'spacer') {
1520 $newMenuArray[$key] = $value;
1521 }
1522 }
1523 $menuItems = $newMenuArray;
1524 } else {
1525 // Traverse all elements except those listed (just unsetting them):
1526 $elements = GeneralUtility::trimExplode(',', $this->iParts[3], true);
1527 foreach ($elements as $value) {
1528 unset($menuItems[$value]);
1529 }
1530 }
1531 }
1532 // Return processed menu items:
1533 return $menuItems;
1534 }
1535
1536 /**
1537 * Clean up spacers; Will remove any spacers in the start/end of menu items array plus any duplicates.
1538 *
1539 * @param array $menuItems Menu items array
1540 * @return array Menu items array, processed.
1541 */
1542 public function cleanUpSpacers($menuItems)
1543 {
1544 // Remove doubles:
1545 $prevItemWasSpacer = false;
1546 foreach ($menuItems as $key => $value) {
1547 if (is_string($value) && $value === 'spacer') {
1548 if ($prevItemWasSpacer) {
1549 unset($menuItems[$key]);
1550 }
1551 $prevItemWasSpacer = true;
1552 } else {
1553 $prevItemWasSpacer = false;
1554 }
1555 }
1556 // Remove first:
1557 reset($menuItems);
1558 $key = key($menuItems);
1559 $value = current($menuItems);
1560 if (is_string($value) && $value === 'spacer') {
1561 unset($menuItems[$key]);
1562 }
1563 // Remove last:
1564 end($menuItems);
1565 $key = key($menuItems);
1566 $value = current($menuItems);
1567 if (is_string($value) && $value === 'spacer') {
1568 unset($menuItems[$key]);
1569 }
1570 // Return processed menu items:
1571 return $menuItems;
1572 }
1573
1574 /**
1575 * Get label from locallang_core.xlf:cm.*
1576 *
1577 * @param string $label The "cm."-suffix to get.
1578 * @return string
1579 */
1580 public function label($label)
1581 {
1582 return $this->languageService->makeEntities($this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.' . $label, true));
1583 }
1584
1585 /**
1586 * Returns TRUE if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers)
1587 *
1588 * @return bool
1589 */
1590 public function isCMlayers()
1591 {
1592 return !$this->CB;
1593 }
1594
1595 /**
1596 * Appends ".location" to input string
1597 *
1598 * @param string $str Input string, probably a JavaScript document reference
1599 * @return string
1600 */
1601 public function frameLocation($str)
1602 {
1603 return $str . '.location';
1604 }
1605 }