[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extra_page_cm_options / Classes / ExtraPageContextMenuOptions.php
1 <?php
2 namespace TYPO3\CMS\ExtraPageCmOptions;
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 /**
18 * Class to add extra context menu options
19 *
20 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
21 */
22 class ExtraPageContextMenuOptions {
23
24 /**
25 * Adding various standard options to the context menu.
26 * This includes both first and second level.
27 *
28 * @param object $backRef The calling object. Value by reference.
29 * @param array $menuItems Array with the currently collected menu items to show.
30 * @param string $table Table name of clicked item.
31 * @param integer $uid UID of clicked item.
32 * @return array Modified $menuItems array
33 */
34 public function main(&$backRef, $menuItems, $table, $uid) {
35 // Accumulation of local items.
36 $localItems = array();
37 $subname = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('subname');
38 // Detecting menu level
39 // LEVEL: Primary menu.
40 if (!in_array('moreoptions', $backRef->disabledItems) && !$backRef->cmLevel) {
41 // Creating menu items here:
42 if ($backRef->editOK) {
43 $localLanguage = $GLOBALS['LANG']->includeLLFile('EXT:extra_page_cm_options/locallang.xlf', FALSE);
44 $localItems[] = 'spacer';
45 $localItems['moreoptions'] = $backRef->linkItem(
46 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLLL('label', $localLanguage)),
47 $backRef->excludeIcon(''),
48 'top.loadTopMenu(\'' . \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript() . '&cmLevel=1&subname=moreoptions\');return false;',
49 0,
50 1
51 );
52 $menuItemHideUnhideAllowed = FALSE;
53 $hiddenField = '';
54 // Check if column for disabled is defined
55 if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']) && isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])) {
56 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
57 if (
58 $hiddenField !== '' && !empty($GLOBALS['TCA'][$table]['columns'][$hiddenField])
59 && (!empty($GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude'])
60 && $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $hiddenField))
61 ) {
62 $menuItemHideUnhideAllowed = TRUE;
63 }
64 }
65 if ($menuItemHideUnhideAllowed && !in_array('hide', $backRef->disabledItems)) {
66 $localItems['hide'] = $backRef->DB_hideUnhide($table, $backRef->rec, $hiddenField);
67 }
68 $anyEnableColumnsFieldAllowed = FALSE;
69 // Check if columns are defined
70 if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
71 $columnsToCheck = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
72 if ($table === 'pages' && !empty($columnsToCheck)) {
73 $columnsToCheck[] = 'extendToSubpages';
74 }
75 foreach ($columnsToCheck as $currentColumn) {
76 if (
77 isset($GLOBALS['TCA'][$table]['columns'][$currentColumn])
78 && (!empty($GLOBALS['TCA'][$table]['columns'][$currentColumn]['exclude'])
79 && $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $currentColumn))
80 ) {
81 $anyEnableColumnsFieldAllowed = TRUE;
82 }
83 }
84 }
85 if ($anyEnableColumnsFieldAllowed && !in_array('edit_access', $backRef->disabledItems)) {
86 $localItems['edit_access'] = $backRef->DB_editAccess($table, $uid);
87 }
88 if ($table === 'pages' && $backRef->editPageIconSet && !in_array('edit_pageproperties', $backRef->disabledItems)) {
89 $localItems['edit_pageproperties'] = $backRef->DB_editPageProperties($uid);
90 }
91 }
92 // Find delete element among the input menu items and insert the local items just before that:
93 $c = 0;
94 $deleteFound = FALSE;
95 foreach ($menuItems as $key => $value) {
96 $c++;
97 if ($key === 'delete') {
98 $deleteFound = TRUE;
99 break;
100 }
101 }
102 if ($deleteFound) {
103 // .. subtract two... (delete item + its spacer element...)
104 $c -= 2;
105 // and insert the items just before the delete element.
106 array_splice($menuItems, $c, 0, $localItems);
107 } else {
108 $menuItems = array_merge($menuItems, $localItems);
109 }
110 } elseif ($subname === 'moreoptions') {
111 // If the page can be edited, then show this:
112 if ($backRef->editOK) {
113 if (($table === 'pages' || $table === 'tt_content') && !in_array('move_wizard', $backRef->disabledItems)) {
114 $localItems['move_wizard'] = $backRef->DB_moveWizard($table, $uid, $backRef->rec);
115 }
116 if (($table === 'pages' || $table === 'tt_content') && !in_array('new_wizard', $backRef->disabledItems)) {
117 $localItems['new_wizard'] = $backRef->DB_newWizard($table, $uid, $backRef->rec);
118 }
119 if ($table === 'pages' && !in_array('perms', $backRef->disabledItems) && $GLOBALS['BE_USER']->check('modules', 'web_perm')) {
120 $localItems['perms'] = $backRef->DB_perms($table, $uid, $backRef->rec);
121 }
122 if (!in_array('db_list', $backRef->disabledItems) && $GLOBALS['BE_USER']->check('modules', 'web_list')) {
123 $localItems['db_list'] = $backRef->DB_db_list($table, $uid, $backRef->rec);
124 }
125 }
126 // Temporary mount point item:
127 if ($table === 'pages') {
128 $localItems['temp_mount_point'] = $backRef->DB_tempMountPoint($uid);
129 }
130 // Merge the locally made items into the current menu items passed to this function.
131 $menuItems = array_merge($menuItems, $localItems);
132 }
133 return $menuItems;
134 }
135
136 }