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