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