9da47a2fa19aab92562908708ccd599808ae495b
[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 ? $this->iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL) . 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 ? $this->iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL) . 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 $this->iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL), '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')), $this->iconFactory->getIcon(($table === 'pages' ? 'actions-page-new' : 'actions-document-new'), Icon::SIZE_SMALL), $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')), $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL), $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 = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL);
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'), $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()
752 ) . ';};';
753 if ($table === 'pages') {
754 $editOnClick .= 'top.nav.refresh.defer(500, top.nav);';
755 }
756 return $this->linkItem($this->label('delete'), $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL), $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()
829 ) . ';};';
830 if ($table === 'pages') {
831 $editOnClick .= 'top.nav.refresh.defer(500, top.nav);';
832 }
833 return $this->linkItem($title, $this->iconFactory->getIcon('actions-edit-' . ($rec[$flagField] ? 'un' : '') . 'hide', Icon::SIZE_SMALL), $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 $elInfo = array(
946 $fileOrFolderInClipBoard->getName(),
947 $clickedFileOrFolder->getName(),
948 $this->clipObj->currentMode()
949 );
950 if (!$fileOrFolderInClipBoard instanceof Folder || !$fileOrFolderInClipBoard->getStorage()->isWithinFolder($fileOrFolderInClipBoard, $clickedFileOrFolder)) {
951 $menuItems['pasteinto'] = $this->FILE_paste($identifier, $selItem, $elInfo);
952 }
953 }
954 $menuItems[] = 'spacer';
955 // Delete:
956 if (!in_array('delete', $this->disabledItems) && $fileObject->checkActionPermission('delete')) {
957 if ($isStorageRoot && $userMayEditStorage) {
958 $elInfo = array(GeneralUtility::fixed_lgd_cs($fileObject->getStorage()->getName(), $this->backendUser->uc['titleLen']));
959 $menuItems['delete'] = $this->DB_delete('sys_file_storage', $fileObject->getStorage()->getUid(), $elInfo);
960 } elseif (!$isStorageRoot) {
961 $menuItems['delete'] = $this->FILE_delete($identifier);
962 }
963 }
964 }
965 // Adding external elements to the menuItems array
966 $menuItems = $this->processingByExtClassArray($menuItems, $identifier, 0);
967 // Processing by external functions?
968 $menuItems = $this->externalProcessingOfFileMenuItems($menuItems);
969 // Return the printed elements:
970 return $this->printItems($menuItems, $icon . $fileObject->getName());
971 }
972
973 /**
974 * Processing the $menuItems array (for extension classes) (FILES)
975 *
976 * @param array $menuItems Array for manipulation.
977 * @return array Processed $menuItems array
978 */
979 public function externalProcessingOfFileMenuItems($menuItems) {
980 return $menuItems;
981 }
982
983 /**
984 * Multi-function for adding an entry to the $menuItems array
985 *
986 * @param string $path Path to the file/directory (target)
987 * @param string $moduleName Script (deprecated) or module name (e.g. file_edit) to pass &target= to
988 * @param string $type "type" is the code which fetches the correct label for the element from "cm.
989 * @param string $iconName
990 * @param bool $noReturnUrl If set, the return URL parameter will not be set in the link
991 * @return array Item array, element in $menuItems
992 * @internal
993 */
994 public function FILE_launch($path, $moduleName, $type, $iconName, $noReturnUrl = FALSE) {
995 $loc = 'top.content.list_frame';
996
997 if (strpos($moduleName, '.php') !== FALSE) {
998 GeneralUtility::deprecationLog(
999 'Using a php file directly in ClickMenu is deprecated since TYPO3 CMS 7, and will be removed in CMS 8.'
1000 . ' Register the class as module and use BackendUtility::getModuleUrl() to get the right link.'
1001 . ' For examples how to do this see ext_tables.php of EXT:backend.'
1002 );
1003 $scriptUrl = $moduleName;
1004 } else {
1005 $scriptUrl = BackendUtility::getModuleUrl($moduleName);
1006 }
1007
1008 $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)') . ';}';
1009 return $this->linkItem($this->label($type), $this->iconFactory->getIcon($iconName, Icon::SIZE_SMALL), $editOnClick . 'top.nav.refresh();');
1010 }
1011
1012 /**
1013 * Returns element for copy or cut of files.
1014 *
1015 * @param string $path Path to the file/directory (target)
1016 * @param string $type Type: "copy" or "cut
1017 * @return array Item array, element in $menuItems
1018 * @internal
1019 */
1020 public function FILE_copycut($path, $type) {
1021 $isSel = '';
1022 // Pseudo table name for use in the clipboard.
1023 $table = '_FILE';
1024 $uid = GeneralUtility::shortmd5($path);
1025 if ($this->clipObj->current === 'normal') {
1026 $isSel = $this->clipObj->isSelected($table, $uid);
1027 }
1028 $addParam = array();
1029 if ($this->listFrame) {
1030 $addParam['reloadListFrame'] = $this->alwaysContentFrame ? 2 : 1;
1031 }
1032 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;');
1033 }
1034
1035 /**
1036 * Creates element for deleting of target
1037 *
1038 * @param string $path Path to the file/directory (target)
1039 * @return array Item array, element in $menuItems
1040 * @internal
1041 */
1042 public function FILE_delete($path) {
1043 $loc = 'top.content.list_frame';
1044 if ($this->backendUser->jsConfirmation(4)) {
1045 $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!)'))) . ')';
1046 } else {
1047 $conf = '1==1';
1048 }
1049 $editOnClick = 'if(' . $loc . ' && ' . $conf . ' ){' . $loc . '.location.href=' .
1050 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&redirect=') . '+top.rawurlencode(' .
1051 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1052 GeneralUtility::quoteJSvalue(
1053 '&file[delete][0][data]=' . rawurlencode($path) . '&vC=' . $this->backendUser->veriCode()
1054 ) . ';};';
1055 return $this->linkItem($this->label('delete'), $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL), $editOnClick . 'return false;');
1056 }
1057
1058 /**
1059 * Creates element for pasting files.
1060 *
1061 * @param string $path Path to the file/directory (target)
1062 * @param string $target target - NOT USED.
1063 * @param array $elInfo Various values for the labels.
1064 * @return array Item array, element in $menuItems
1065 * @internal
1066 */
1067 public function FILE_paste($path, $target, $elInfo) {
1068 $loc = 'top.content.list_frame';
1069 if ($this->backendUser->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE)) {
1070 $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])) . ')';
1071 } else {
1072 $conf = $loc;
1073 }
1074 $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();';
1075 return $this->linkItem($this->label('pasteinto'), $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL), $editOnClick . 'return false;');
1076 }
1077
1078 /**
1079 * Adding ClickMenu element for file info
1080 *
1081 * @param string $identifier The combined identifier of the file.
1082 * @return array Item array, element in $menuItems
1083 */
1084 protected function fileInfo($identifier) {
1085 return $this->DB_info('_FILE', $identifier);
1086 }
1087
1088 /***************************************
1089 *
1090 * DRAG AND DROP
1091 *
1092 ***************************************/
1093 /**
1094 * Make 1st level clickmenu:
1095 *
1096 * @param string $table The absolute path
1097 * @param int $srcId UID for the current record.
1098 * @param int $dstId Destination ID
1099 * @return string HTML content
1100 */
1101 public function printDragDropClickMenu($table, $srcId, $dstId) {
1102 $menuItems = array();
1103 // If the drag and drop menu should apply to PAGES use this set of menu items
1104 if ($table === 'pages') {
1105 // Move Into:
1106 $menuItems['movePage_into'] = $this->dragDrop_copymovepage($srcId, $dstId, 'move', 'into');
1107 // Move After:
1108 $menuItems['movePage_after'] = $this->dragDrop_copymovepage($srcId, $dstId, 'move', 'after');
1109 // Copy Into:
1110 $menuItems['copyPage_into'] = $this->dragDrop_copymovepage($srcId, $dstId, 'copy', 'into');
1111 // Copy After:
1112 $menuItems['copyPage_after'] = $this->dragDrop_copymovepage($srcId, $dstId, 'copy', 'after');
1113 }
1114 // If the drag and drop menu should apply to FOLDERS use this set of menu items
1115 if ($table === 'folders') {
1116 // Move Into:
1117 $menuItems['moveFolder_into'] = $this->dragDrop_copymovefolder($srcId, $dstId, 'move');
1118 // Copy Into:
1119 $menuItems['copyFolder_into'] = $this->dragDrop_copymovefolder($srcId, $dstId, 'copy');
1120 }
1121 // Adding external elements to the menuItems array
1122 $menuItems = $this->processingByExtClassArray($menuItems, 'dragDrop_' . $table, $srcId);
1123 // to extend this, you need to apply a Context Menu to a "virtual" table called "dragDrop_pages" or similar
1124 // Processing by external functions?
1125 $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
1126 // Return the printed elements:
1127 return $this->printItems($menuItems, IconUtility::getSpriteIconForRecord($table, $this->rec, array('title' => BackendUtility::getRecordTitle($table, $this->rec, TRUE))));
1128 }
1129
1130 /**
1131 * Processing the $menuItems array (for extension classes) (DRAG'N DROP)
1132 *
1133 * @param array $menuItems Array for manipulation.
1134 * @return array Processed $menuItems array
1135 */
1136 public function externalProcessingOfDragDropMenuItems($menuItems) {
1137 return $menuItems;
1138 }
1139
1140 /**
1141 * Adding CM element for Copying/Moving a Page Into/After from a drag & drop action
1142 *
1143 * @param int $srcUid source UID code for the record to modify
1144 * @param int $dstUid destination UID code for the record to modify
1145 * @param string $action Action code: either "move" or "copy
1146 * @param string $into Parameter code: either "into" or "after
1147 * @return array Item array, element in $menuItems
1148 * @internal
1149 */
1150 public function dragDrop_copymovepage($srcUid, $dstUid, $action, $into) {
1151 $negativeSign = $into === 'into' ? '' : '-';
1152 $loc = 'top.content.list_frame';
1153 $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=' .
1154 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&redirect=') . '+top.rawurlencode(' .
1155 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1156 GeneralUtility::quoteJSvalue(
1157 '&cmd[pages][' . $srcUid . '][' . $action . ']=' . $negativeSign . $dstUid . '&prErr=1&vC=' .
1158 $this->backendUser->veriCode()
1159 ) . ';};top.nav.refresh();';
1160 return $this->linkItem($this->label($action . 'Page_' . $into), IconUtility::getSpriteIcon('actions-document-paste-' . $into), $editOnClick . 'return false;', 0);
1161 }
1162
1163 /**
1164 * Adding CM element for Copying/Moving a Folder Into from a drag & drop action
1165 *
1166 * @param string $srcPath source path for the record to modify
1167 * @param string $dstPath destination path for the records to modify
1168 * @param string $action Action code: either "move" or "copy
1169 * @return array Item array, element in $menuItems
1170 * @internal
1171 */
1172 public function dragDrop_copymovefolder($srcPath, $dstPath, $action) {
1173 $loc = 'top.content.list_frame';
1174 $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=' .
1175 GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&redirect=') . '+top.rawurlencode(' .
1176 $this->frameLocation(($loc . '.document')) . '.pathname+' . $this->frameLocation(($loc . '.document')) . '.search)+' .
1177 GeneralUtility::quoteJSvalue(
1178 '&file[' . $action . '][0][data]=' . $srcPath . '&file[' . $action . '][0][target]=' . $dstPath . '&prErr=1&vC=' .
1179 $this->backendUser->veriCode()
1180 ) . ';};top.nav.refresh();';
1181 return $this->linkItem($this->label($action . 'Folder_into'), IconUtility::getSpriteIcon('apps-pagetree-drag-move-into'), $editOnClick . 'return false;', 0);
1182 }
1183
1184 /***************************************
1185 *
1186 * COMMON
1187 *
1188 **************************************/
1189 /**
1190 * Prints the items from input $menuItems array - as JS section for writing to the div-layers.
1191 *
1192 * @param array $menuItems Array
1193 * @return string HTML code
1194 */
1195 public function printItems($menuItems) {
1196 // Enable/Disable items
1197 $menuItems = $this->enableDisableItems($menuItems);
1198 // Clean up spacers
1199 $menuItems = $this->cleanUpSpacers($menuItems);
1200 // Adding JS part and return the content
1201 return $this->printLayerJScode($menuItems);
1202 }
1203
1204 /**
1205 * Create the JavaScript section
1206 *
1207 * @param array $menuItems The $menuItems array to print
1208 * @return string The JavaScript section which will print the content of the CM to the div-layer in the target frame.
1209 */
1210 public function printLayerJScode($menuItems) {
1211 // Clipboard must not be submitted - then it's probably a copy/cut situation.
1212 if ($this->isCMlayers()) {
1213 // Create the table displayed in the clickmenu layer:
1214 // Wrap the inner table in another table to create outer border:
1215 $CMtable = '
1216 <div class="typo3-CSM-wrapperCM">
1217 <table border="0" cellpadding="0" cellspacing="0" class="typo3-CSM">
1218 ' . implode('', $this->menuItemsForClickMenu($menuItems)) . '
1219 </table></div>';
1220 return '<data><clickmenu><htmltable><![CDATA[' . $CMtable . ']]></htmltable><cmlevel>' . $this->cmLevel . '</cmlevel></clickmenu></data>';
1221 }
1222 }
1223
1224 /**
1225 * Wrapping the input string in a table with background color 4 and a black border style.
1226 * For the pop-up menu
1227 *
1228 * @param string $str HTML content to wrap in table.
1229 * @return string
1230 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1231 */
1232 public function wrapColorTableCM($str) {
1233 GeneralUtility::logDeprecatedFunction();
1234 return '<div class="typo3-CSM-wrapperCM">
1235 ' . $str . '
1236 </div>';
1237 }
1238
1239 /**
1240 * Traverses the menuItems and generates an output array for implosion in the CM div-layers table.
1241 *
1242 * @param array $menuItems Array
1243 * @return array array for implosion in the CM div-layers table.
1244 */
1245 public function menuItemsForClickMenu($menuItems) {
1246 $out = array();
1247 foreach ($menuItems as $cc => $i) {
1248 // MAKE horizontal spacer
1249 if (is_string($i) && $i === 'spacer') {
1250 $out[] = '
1251 <tr style="height: 1px;" class="bgColor2">
1252 <td colspan="2"></td>
1253 </tr>';
1254 } else {
1255 // Just make normal element:
1256 $onClick = $i[3];
1257 $onClick = preg_replace('/return[[:space:]]+hideCM\\(\\)[[:space:]]*;/i', '', $onClick);
1258 $onClick = preg_replace('/return[[:space:]]+false[[:space:]]*;/i', '', $onClick);
1259 $onClick = preg_replace('/hideCM\\(\\);/i', '', $onClick);
1260 if (!$i[5]) {
1261 $onClick .= 'TYPO3.ClickMenu.hideAll();';
1262 }
1263 $CSM = ' oncontextmenu="this.click();return false;"';
1264 $out[] = '
1265 <tr class="typo3-CSM-itemRow" onclick="' . htmlspecialchars($onClick) . '"' . $CSM . '>
1266 ' . (!$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>') . '
1267 </tr>';
1268 }
1269 }
1270 return $out;
1271 }
1272
1273 /**
1274 * Adds or inserts a menu item
1275 * 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.
1276 *
1277 * @param array $menuItems Menu items array
1278 * @param array $newMenuItems Menu items array to insert
1279 * @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.
1280 * @return array Menu items array, processed.
1281 */
1282 public function addMenuItems($menuItems, $newMenuItems, $position = '') {
1283 if (is_array($newMenuItems)) {
1284 if ($position) {
1285 $posArr = GeneralUtility::trimExplode(',', $position, TRUE);
1286 foreach ($posArr as $pos) {
1287 list($place, $menuEntry) = GeneralUtility::trimExplode(':', $pos, TRUE);
1288 list($place, $placeExtra) = GeneralUtility::trimExplode('-', $place, TRUE);
1289 // Bottom
1290 $pointer = count($menuItems);
1291 $found = FALSE;
1292 if ($place) {
1293 switch (strtolower($place)) {
1294 case 'after':
1295 case 'before':
1296 if ($menuEntry) {
1297 $p = 1;
1298 reset($menuItems);
1299 while (TRUE) {
1300 if ((string)key($menuItems) === $menuEntry) {
1301 $pointer = $p;
1302 $found = TRUE;
1303 break;
1304 }
1305 if (!next($menuItems)) {
1306 break;
1307 }
1308 $p++;
1309 }
1310 if (!$found) {
1311 break;
1312 }
1313 if ($place === 'before') {
1314 $pointer--;
1315 if ($placeExtra === 'spacer' and prev($menuItems) === 'spacer') {
1316 $pointer--;
1317 }
1318 } elseif ($place === 'after') {
1319 if ($placeExtra === 'spacer' and next($menuItems) === 'spacer') {
1320 $pointer++;
1321 }
1322 }
1323 }
1324 break;
1325 default:
1326 if (strtolower($place) === 'top') {
1327 $pointer = 0;
1328 } else {
1329 $pointer = count($menuItems);
1330 }
1331 $found = TRUE;
1332 }
1333 }
1334 if ($found) {
1335 break;
1336 }
1337 }
1338 }
1339 $pointer = max(0, $pointer);
1340 $menuItemsBefore = array_slice($menuItems, 0, $pointer ?: 0);
1341 $menuItemsAfter = array_slice($menuItems, $pointer);
1342 $menuItems = $menuItemsBefore + $newMenuItems + $menuItemsAfter;
1343 }
1344 return $menuItems;
1345 }
1346
1347 /**
1348 * Creating an array with various elements for the clickmenu entry
1349 *
1350 * @param string $str The label, htmlspecialchar'ed already
1351 * @param string $icon <img>-tag for the icon
1352 * @param string $onClick JavaScript onclick event for label/icon
1353 * @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)
1354 * @param bool $dontHide If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear...
1355 * @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!
1356 */
1357 public function linkItem($str, $icon, $onClick, $onlyCM = 0, $dontHide = 0) {
1358 $onClick = str_replace('top.loadTopMenu', 'showClickmenu_raw', $onClick);
1359 return array(
1360 '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $str . $icon . '</a>',
1361 $str,
1362 $icon,
1363 $onClick,
1364 $onlyCM,
1365 $dontHide
1366 );
1367 }
1368
1369 /**
1370 * Returns the input string IF not a user setting has disabled display of icons.
1371 *
1372 * @param string $iconCode The icon-image tag
1373 * @return string The icon-image tag prefixed with space char IF the icon should be printed at all due to user settings
1374 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1375 */
1376 public function excludeIcon($iconCode) {
1377 GeneralUtility::logDeprecatedFunction();
1378 return $this->backendUser->uc['noMenuMode'] && $this->backendUser->uc['noMenuMode'] !== 'icons' ? '' : ' ' . $iconCode;
1379 }
1380
1381 /**
1382 * Enabling / Disabling items based on list provided from GET var ($this->iParts[3])
1383 *
1384 * @param array $menuItems Menu items array
1385 * @return array Menu items array, processed.
1386 */
1387 public function enableDisableItems($menuItems) {
1388 if ($this->iParts[3]) {
1389 // Detect "only" mode: (only showing listed items)
1390 if ($this->iParts[3][0] === '+') {
1391 $this->iParts[3] = substr($this->iParts[3], 1);
1392 $only = TRUE;
1393 } else {
1394 $only = FALSE;
1395 }
1396 // Do filtering:
1397 // Transfer ONLY elements which are mentioned (or are spacers)
1398 if ($only) {
1399 $newMenuArray = array();
1400 foreach ($menuItems as $key => $value) {
1401 if (GeneralUtility::inList($this->iParts[3], $key) || is_string($value) && $value === 'spacer') {
1402 $newMenuArray[$key] = $value;
1403 }
1404 }
1405 $menuItems = $newMenuArray;
1406 } else {
1407 // Traverse all elements except those listed (just unsetting them):
1408 $elements = GeneralUtility::trimExplode(',', $this->iParts[3], TRUE);
1409 foreach ($elements as $value) {
1410 unset($menuItems[$value]);
1411 }
1412 }
1413 }
1414 // Return processed menu items:
1415 return $menuItems;
1416 }
1417
1418 /**
1419 * Clean up spacers; Will remove any spacers in the start/end of menu items array plus any duplicates.
1420 *
1421 * @param array $menuItems Menu items array
1422 * @return array Menu items array, processed.
1423 */
1424 public function cleanUpSpacers($menuItems) {
1425 // Remove doubles:
1426 $prevItemWasSpacer = FALSE;
1427 foreach ($menuItems as $key => $value) {
1428 if (is_string($value) && $value === 'spacer') {
1429 if ($prevItemWasSpacer) {
1430 unset($menuItems[$key]);
1431 }
1432 $prevItemWasSpacer = TRUE;
1433 } else {
1434 $prevItemWasSpacer = FALSE;
1435 }
1436 }
1437 // Remove first:
1438 reset($menuItems);
1439 $key = key($menuItems);
1440 $value = current($menuItems);
1441 if (is_string($value) && $value === 'spacer') {
1442 unset($menuItems[$key]);
1443 }
1444 // Remove last:
1445 end($menuItems);
1446 $key = key($menuItems);
1447 $value = current($menuItems);
1448 if (is_string($value) && $value === 'spacer') {
1449 unset($menuItems[$key]);
1450 }
1451 // Return processed menu items:
1452 return $menuItems;
1453 }
1454
1455 /**
1456 * Get label from locallang_core.xlf:cm.*
1457 *
1458 * @param string $label The "cm."-suffix to get.
1459 * @return string
1460 */
1461 public function label($label) {
1462 return $this->languageService->makeEntities($this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.' . $label, TRUE));
1463 }
1464
1465 /**
1466 * Returns TRUE if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers)
1467 *
1468 * @return bool
1469 */
1470 public function isCMlayers() {
1471 return !$this->CB;
1472 }
1473
1474 /**
1475 * Appends ".location" to input string
1476 *
1477 * @param string $str Input string, probably a JavaScript document reference
1478 * @return string
1479 */
1480 public function frameLocation($str) {
1481 return $str . '.location';
1482 }
1483
1484 }