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