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