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