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