788ad3246a0579896d2f18a6c3b7420605c16d73
[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 $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 ($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 $this->languageService->makeEntities($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 $this->languageService->makeEntities($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 $this->languageService->makeEntities($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
1067 if (strpos($moduleName, '.php') !== false) {
1068 GeneralUtility::deprecationLog(
1069 'Using a php file directly in ClickMenu is deprecated since TYPO3 CMS 7, and will be removed in CMS 8.'
1070 . ' Register the class as module and use BackendUtility::getModuleUrl() to get the right link.'
1071 . ' For examples how to do this see ext_tables.php of EXT:backend.'
1072 );
1073 $scriptUrl = $moduleName;
1074 } else {
1075 $scriptUrl = BackendUtility::getModuleUrl($moduleName);
1076 }
1077
1078 $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)') . ';}';
1079 return $this->linkItem(
1080 $this->label($type),
1081 $this->iconFactory->getIcon($iconName, Icon::SIZE_SMALL)->render(),
1082 $editOnClick . 'top.nav.refresh();'
1083 );
1084 }
1085
1086 /**
1087 * Returns element for copy or cut of files.
1088 *
1089 * @param string $path Path to the file/directory (target)
1090 * @param string $type Type: "copy" or "cut
1091 * @return array Item array, element in $menuItems
1092 * @internal
1093 */
1094 public function FILE_copycut($path, $type)
1095 {
1096 $isSel = '';
1097 // Pseudo table name for use in the clipboard.
1098 $table = '_FILE';
1099 $uid = GeneralUtility::shortmd5($path);
1100 if ($this->clipObj->current === 'normal') {
1101 $isSel = $this->clipObj->isSelected($table, $uid);
1102 }
1103 $addParam = array();
1104 if ($this->listFrame) {
1105 $addParam['reloadListFrame'] = $this->alwaysContentFrame ? 2 : 1;
1106 }
1107 return $this->linkItem(
1108 $this->label($type),
1109 $this->iconFactory->getIcon('actions-edit-' . $type . ($isSel === $type ? '-release' : ''), Icon::SIZE_SMALL)->render(),
1110 'TYPO3.ClickMenu.fetch(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlFile($path, ($type === 'copy' ? 1 : 0), ($isSel == $type), $addParam)) . ');return false;'
1111 );
1112 }
1113
1114 /**
1115 * Creates element for deleting of target
1116 *
1117 * @param string $path Path to the file/directory (target)
1118 * @return array Item array, element in $menuItems
1119 * @internal
1120 */
1121 public function FILE_delete($path)
1122 {
1123 $loc = 'top.content.list_frame';
1124 if ($this->backendUser->jsConfirmation(JsConfirmation::DELETE)) {
1125 $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')))) . ')';
1126 } else {
1127 $conf = '1==1';
1128 }
1129 $editOnClick = 'if(' . $loc . ' && ' . $conf . ' ){' . $loc . '.location.href=' .
1130 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&redirect=') . '+top.rawurlencode(' .
1131 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1132 GeneralUtility::quoteJSvalue(
1133 '&file[delete][0][data]=' . rawurlencode($path) . '&vC=' . $this->backendUser->veriCode()
1134 ) . ';};';
1135 return $this->linkItem(
1136 $this->label('delete'),
1137 $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(),
1138 $editOnClick . 'return false;'
1139 );
1140 }
1141
1142 /**
1143 * Creates element for pasting files.
1144 *
1145 * @param string $path Path to the file/directory (target)
1146 * @param string $target target - NOT USED.
1147 * @param array $elInfo Various values for the labels.
1148 * @return array Item array, element in $menuItems
1149 * @internal
1150 */
1151 public function FILE_paste($path, $target, $elInfo)
1152 {
1153 $loc = 'top.content.list_frame';
1154 if ($this->backendUser->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE)) {
1155 $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])) . ')';
1156 } else {
1157 $conf = $loc;
1158 }
1159 $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();';
1160 return $this->linkItem(
1161 $this->label('pasteinto'),
1162 $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render(),
1163 $editOnClick . 'return false;'
1164 );
1165 }
1166
1167 /**
1168 * Adding ClickMenu element for file info
1169 *
1170 * @param string $identifier The combined identifier of the file.
1171 * @return array Item array, element in $menuItems
1172 */
1173 protected function fileInfo($identifier)
1174 {
1175 return $this->DB_info('_FILE', $identifier);
1176 }
1177
1178 /***************************************
1179 *
1180 * DRAG AND DROP
1181 *
1182 ***************************************/
1183 /**
1184 * Make 1st level clickmenu:
1185 *
1186 * @param string $table The absolute path
1187 * @param int $srcId UID for the current record.
1188 * @param int $dstId Destination ID
1189 * @return string HTML content
1190 */
1191 public function printDragDropClickMenu($table, $srcId, $dstId)
1192 {
1193 $menuItems = array();
1194 // If the drag and drop menu should apply to PAGES use this set of menu items
1195 if ($table === 'pages') {
1196 // Move Into:
1197 $menuItems['movePage_into'] = $this->dragDrop_copymovepage($srcId, $dstId, 'move', 'into');
1198 // Move After:
1199 $menuItems['movePage_after'] = $this->dragDrop_copymovepage($srcId, $dstId, 'move', 'after');
1200 // Copy Into:
1201 $menuItems['copyPage_into'] = $this->dragDrop_copymovepage($srcId, $dstId, 'copy', 'into');
1202 // Copy After:
1203 $menuItems['copyPage_after'] = $this->dragDrop_copymovepage($srcId, $dstId, 'copy', 'after');
1204 }
1205 // If the drag and drop menu should apply to FOLDERS use this set of menu items
1206 if ($table === 'folders') {
1207 // Move Into:
1208 $menuItems['moveFolder_into'] = $this->dragDrop_copymovefolder($srcId, $dstId, 'move');
1209 // Copy Into:
1210 $menuItems['copyFolder_into'] = $this->dragDrop_copymovefolder($srcId, $dstId, 'copy');
1211 }
1212 // Adding external elements to the menuItems array
1213 $menuItems = $this->processingByExtClassArray($menuItems, 'dragDrop_' . $table, $srcId);
1214 // to extend this, you need to apply a Context Menu to a "virtual" table called "dragDrop_pages" or similar
1215 // Processing by external functions?
1216 $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
1217 // Return the printed elements:
1218 return $this->printItems($menuItems);
1219 }
1220
1221 /**
1222 * Processing the $menuItems array (for extension classes) (DRAG'N DROP)
1223 *
1224 * @param array $menuItems Array for manipulation.
1225 * @return array Processed $menuItems array
1226 */
1227 public function externalProcessingOfDragDropMenuItems($menuItems)
1228 {
1229 return $menuItems;
1230 }
1231
1232 /**
1233 * Adding CM element for Copying/Moving a Page Into/After from a drag & drop action
1234 *
1235 * @param int $srcUid source UID code for the record to modify
1236 * @param int $dstUid destination UID code for the record to modify
1237 * @param string $action Action code: either "move" or "copy
1238 * @param string $into Parameter code: either "into" or "after
1239 * @return array Item array, element in $menuItems
1240 * @internal
1241 */
1242 public function dragDrop_copymovepage($srcUid, $dstUid, $action, $into)
1243 {
1244 $negativeSign = $into === 'into' ? '' : '-';
1245 $loc = 'top.content.list_frame';
1246 $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=' .
1247 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&redirect=') . '+top.rawurlencode(' .
1248 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1249 GeneralUtility::quoteJSvalue(
1250 '&cmd[pages][' . $srcUid . '][' . $action . ']=' . $negativeSign . $dstUid . '&prErr=1&vC=' .
1251 $this->backendUser->veriCode()
1252 ) . ';};top.nav.refresh();';
1253 return $this->linkItem(
1254 $this->label($action . 'Page_' . $into),
1255 $this->iconFactory->getIcon('actions-document-paste-' . $into, Icon::SIZE_SMALL)->render(),
1256 $editOnClick . 'return false;'
1257 );
1258 }
1259
1260 /**
1261 * Adding CM element for Copying/Moving a Folder Into from a drag & drop action
1262 *
1263 * @param string $srcPath source path for the record to modify
1264 * @param string $dstPath destination path for the records to modify
1265 * @param string $action Action code: either "move" or "copy
1266 * @return array Item array, element in $menuItems
1267 * @internal
1268 */
1269 public function dragDrop_copymovefolder($srcPath, $dstPath, $action)
1270 {
1271 $loc = 'top.content.list_frame';
1272 $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=' .
1273 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&redirect=') . '+top.rawurlencode(' .
1274 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1275 GeneralUtility::quoteJSvalue(
1276 '&file[' . $action . '][0][data]=' . $srcPath . '&file[' . $action . '][0][target]=' . $dstPath . '&prErr=1&vC=' .
1277 $this->backendUser->veriCode()
1278 ) . ';};top.nav.refresh();';
1279 return $this->linkItem(
1280 $this->label($action . 'Folder_into'),
1281 $this->iconFactory->getIcon('apps-pagetree-drag-move-into', Icon::SIZE_SMALL)->render(),
1282 $editOnClick . 'return false;'
1283 );
1284 }
1285
1286 /***************************************
1287 *
1288 * COMMON
1289 *
1290 **************************************/
1291 /**
1292 * Prints the items from input $menuItems array - as JS section for writing to the div-layers.
1293 *
1294 * @param array $menuItems Array
1295 * @return string HTML code
1296 */
1297 public function printItems($menuItems)
1298 {
1299 // Enable/Disable items
1300 $menuItems = $this->enableDisableItems($menuItems);
1301 // Clean up spacers
1302 $menuItems = $this->cleanUpSpacers($menuItems);
1303 // Adding JS part and return the content
1304 return $this->printLayerJScode($menuItems);
1305 }
1306
1307 /**
1308 * Create the JavaScript section
1309 *
1310 * @param array $menuItems The $menuItems array to print
1311 * @return string The JavaScript section which will print the content of the CM to the div-layer in the target frame.
1312 */
1313 public function printLayerJScode($menuItems)
1314 {
1315 // Clipboard must not be submitted - then it's probably a copy/cut situation.
1316 if ($this->isCMlayers()) {
1317 // Create the table displayed in the clickmenu layer:
1318 // Wrap the inner table in another table to create outer border:
1319 $CMtable = '
1320 <div class="typo3-CSM-wrapperCM">
1321 <table border="0" cellpadding="0" cellspacing="0" class="typo3-CSM">
1322 ' . implode('', $this->menuItemsForClickMenu($menuItems)) . '
1323 </table></div>';
1324 return '<data><clickmenu><htmltable><![CDATA[' . $CMtable . ']]></htmltable><cmlevel>' . $this->cmLevel . '</cmlevel></clickmenu></data>';
1325 }
1326 }
1327
1328 /**
1329 * Wrapping the input string in a table with background color 4 and a black border style.
1330 * For the pop-up menu
1331 *
1332 * @param string $str HTML content to wrap in table.
1333 * @return string
1334 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1335 */
1336 public function wrapColorTableCM($str)
1337 {
1338 GeneralUtility::logDeprecatedFunction();
1339 return '<div class="typo3-CSM-wrapperCM">
1340 ' . $str . '
1341 </div>';
1342 }
1343
1344 /**
1345 * Traverses the menuItems and generates an output array for implosion in the CM div-layers table.
1346 *
1347 * @param array $menuItems Array
1348 * @return array array for implosion in the CM div-layers table.
1349 */
1350 public function menuItemsForClickMenu($menuItems)
1351 {
1352 $out = array();
1353 foreach ($menuItems as $cc => $i) {
1354 // MAKE horizontal spacer
1355 if (is_string($i) && $i === 'spacer') {
1356 $out[] = '
1357 <tr style="height: 1px;" class="bgColor2">
1358 <td colspan="2"></td>
1359 </tr>';
1360 } else {
1361 // Just make normal element:
1362 $onClick = $i[3];
1363 $onClick = preg_replace('/return[[:space:]]+hideCM\\(\\)[[:space:]]*;/i', '', $onClick);
1364 $onClick = preg_replace('/return[[:space:]]+false[[:space:]]*;/i', '', $onClick);
1365 $onClick = preg_replace('/hideCM\\(\\);/i', '', $onClick);
1366 if (!$i[5]) {
1367 $onClick .= 'TYPO3.ClickMenu.hideAll();';
1368 }
1369 $CSM = ' oncontextmenu="this.click();return false;"';
1370 $out[] = '
1371 <tr class="typo3-CSM-itemRow" onclick="' . htmlspecialchars($onClick) . '"' . $CSM . '>
1372 ' . (!$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>') . '
1373 </tr>';
1374 }
1375 }
1376 return $out;
1377 }
1378
1379 /**
1380 * Adds or inserts a menu item
1381 * 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.
1382 *
1383 * @param array $menuItems Menu items array
1384 * @param array $newMenuItems Menu items array to insert
1385 * @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.
1386 * @return array Menu items array, processed.
1387 */
1388 public function addMenuItems($menuItems, $newMenuItems, $position = '')
1389 {
1390 if (is_array($newMenuItems)) {
1391 $pointer = 0;
1392 if ($position) {
1393 $posArr = GeneralUtility::trimExplode(',', $position, true);
1394 foreach ($posArr as $pos) {
1395 list($place, $menuEntry) = GeneralUtility::trimExplode(':', $pos, true);
1396 list($place, $placeExtra) = GeneralUtility::trimExplode('-', $place, true);
1397 // Bottom
1398 $pointer = count($menuItems);
1399 $found = false;
1400 if ($place) {
1401 switch (strtolower($place)) {
1402 case 'after':
1403 case 'before':
1404 if ($menuEntry) {
1405 $p = 1;
1406 reset($menuItems);
1407 while (true) {
1408 if ((string)key($menuItems) === $menuEntry) {
1409 $pointer = $p;
1410 $found = true;
1411 break;
1412 }
1413 if (!next($menuItems)) {
1414 break;
1415 }
1416 $p++;
1417 }
1418 if (!$found) {
1419 break;
1420 }
1421 if ($place === 'before') {
1422 $pointer--;
1423 if ($placeExtra === 'spacer' and prev($menuItems) === 'spacer') {
1424 $pointer--;
1425 }
1426 } elseif ($place === 'after') {
1427 if ($placeExtra === 'spacer' and next($menuItems) === 'spacer') {
1428 $pointer++;
1429 }
1430 }
1431 }
1432 break;
1433 default:
1434 if (strtolower($place) === 'top') {
1435 $pointer = 0;
1436 } else {
1437 $pointer = count($menuItems);
1438 }
1439 $found = true;
1440 }
1441 }
1442 if ($found) {
1443 break;
1444 }
1445 }
1446 }
1447 $pointer = max(0, $pointer);
1448 $menuItemsBefore = array_slice($menuItems, 0, $pointer ?: 0);
1449 $menuItemsAfter = array_slice($menuItems, $pointer);
1450 $menuItems = $menuItemsBefore + $newMenuItems + $menuItemsAfter;
1451 }
1452 return $menuItems;
1453 }
1454
1455 /**
1456 * Creating an array with various elements for the clickmenu entry
1457 *
1458 * @param string $str The label, htmlspecialchar'ed already
1459 * @param string $icon <img>-tag for the icon
1460 * @param string $onClick JavaScript onclick event for label/icon
1461 * @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)
1462 * @param int $dontHide If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear...
1463 * @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!
1464 */
1465 public function linkItem($str, $icon, $onClick, $onlyCM = 0, $dontHide = 0)
1466 {
1467 $onClick = str_replace('top.loadTopMenu', 'showClickmenu_raw', $onClick);
1468 return array(
1469 '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $str . $icon . '</a>',
1470 $str,
1471 $icon,
1472 $onClick,
1473 $onlyCM,
1474 $dontHide
1475 );
1476 }
1477
1478 /**
1479 * Returns the input string IF not a user setting has disabled display of icons.
1480 *
1481 * @param string $iconCode The icon-image tag
1482 * @return string The icon-image tag prefixed with space char IF the icon should be printed at all due to user settings
1483 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1484 */
1485 public function excludeIcon($iconCode)
1486 {
1487 GeneralUtility::logDeprecatedFunction();
1488 return $this->backendUser->uc['noMenuMode'] && $this->backendUser->uc['noMenuMode'] !== 'icons' ? '' : ' ' . $iconCode;
1489 }
1490
1491 /**
1492 * Enabling / Disabling items based on list provided from GET var ($this->iParts[3])
1493 *
1494 * @param array $menuItems Menu items array
1495 * @return array Menu items array, processed.
1496 */
1497 public function enableDisableItems($menuItems)
1498 {
1499 if ($this->iParts[3]) {
1500 // Detect "only" mode: (only showing listed items)
1501 if ($this->iParts[3][0] === '+') {
1502 $this->iParts[3] = substr($this->iParts[3], 1);
1503 $only = true;
1504 } else {
1505 $only = false;
1506 }
1507 // Do filtering:
1508 // Transfer ONLY elements which are mentioned (or are spacers)
1509 if ($only) {
1510 $newMenuArray = array();
1511 foreach ($menuItems as $key => $value) {
1512 if (GeneralUtility::inList($this->iParts[3], $key) || is_string($value) && $value === 'spacer') {
1513 $newMenuArray[$key] = $value;
1514 }
1515 }
1516 $menuItems = $newMenuArray;
1517 } else {
1518 // Traverse all elements except those listed (just unsetting them):
1519 $elements = GeneralUtility::trimExplode(',', $this->iParts[3], true);
1520 foreach ($elements as $value) {
1521 unset($menuItems[$value]);
1522 }
1523 }
1524 }
1525 // Return processed menu items:
1526 return $menuItems;
1527 }
1528
1529 /**
1530 * Clean up spacers; Will remove any spacers in the start/end of menu items array plus any duplicates.
1531 *
1532 * @param array $menuItems Menu items array
1533 * @return array Menu items array, processed.
1534 */
1535 public function cleanUpSpacers($menuItems)
1536 {
1537 // Remove doubles:
1538 $prevItemWasSpacer = false;
1539 foreach ($menuItems as $key => $value) {
1540 if (is_string($value) && $value === 'spacer') {
1541 if ($prevItemWasSpacer) {
1542 unset($menuItems[$key]);
1543 }
1544 $prevItemWasSpacer = true;
1545 } else {
1546 $prevItemWasSpacer = false;
1547 }
1548 }
1549 // Remove first:
1550 reset($menuItems);
1551 $key = key($menuItems);
1552 $value = current($menuItems);
1553 if (is_string($value) && $value === 'spacer') {
1554 unset($menuItems[$key]);
1555 }
1556 // Remove last:
1557 end($menuItems);
1558 $key = key($menuItems);
1559 $value = current($menuItems);
1560 if (is_string($value) && $value === 'spacer') {
1561 unset($menuItems[$key]);
1562 }
1563 // Return processed menu items:
1564 return $menuItems;
1565 }
1566
1567 /**
1568 * Get label from locallang_core.xlf:cm.*
1569 *
1570 * @param string $label The "cm."-suffix to get.
1571 * @return string
1572 */
1573 public function label($label)
1574 {
1575 return $this->languageService->makeEntities($this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.' . $label, true));
1576 }
1577
1578 /**
1579 * Returns TRUE if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers)
1580 *
1581 * @return bool
1582 */
1583 public function isCMlayers()
1584 {
1585 return !$this->CB;
1586 }
1587
1588 /**
1589 * Appends ".location" to input string
1590 *
1591 * @param string $str Input string, probably a JavaScript document reference
1592 * @return string
1593 */
1594 public function frameLocation($str)
1595 {
1596 return $str . '.location';
1597 }
1598 }