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