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