[BUGFIX] ClickMenu: Visibility-options only if fields allowed
[Packages/TYPO3.CMS.git] / typo3 / sysext / extra_page_cm_options / Classes / ExtraPageContextMenuOptions.php
1 <?php
2 namespace TYPO3\CMS\ExtraPageCmOptions;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Class to add extra context menu options
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class ExtraPageContextMenuOptions {
36
37 /**
38 * Adding various standard options to the context menu.
39 * This includes both first and second level.
40 *
41 * @param object $backRef The calling object. Value by reference.
42 * @param array $menuItems Array with the currently collected menu items to show.
43 * @param string $table Table name of clicked item.
44 * @param integer $uid UID of clicked item.
45 * @return array Modified $menuItems array
46 */
47 public function main(&$backRef, $menuItems, $table, $uid) {
48 // Accumulation of local items.
49 $localItems = array();
50 $subname = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('subname');
51 // Detecting menu level
52 // LEVEL: Primary menu.
53 if (!in_array('moreoptions', $backRef->disabledItems) && !$backRef->cmLevel) {
54 // Creating menu items here:
55 if ($backRef->editOK) {
56 $localLanguage = $GLOBALS['LANG']->includeLLFile('EXT:extra_page_cm_options/locallang.xlf', FALSE);
57 $localItems[] = 'spacer';
58 $localItems['moreoptions'] = $backRef->linkItem(
59 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLLL('label', $localLanguage)),
60 $backRef->excludeIcon(''),
61 'top.loadTopMenu(\'' . \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript() . '&cmLevel=1&subname=moreoptions\');return false;',
62 0,
63 1
64 );
65 $menuItemHideUnhideAllowed = FALSE;
66 $hiddenField = '';
67 // Check if column for disabled is defined
68 if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']) && isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])) {
69 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
70 if (
71 $hiddenField !== '' && !empty($GLOBALS['TCA'][$table]['columns'][$hiddenField])
72 && (!empty($GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude'])
73 && $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $hiddenField))
74 ) {
75 $menuItemHideUnhideAllowed = TRUE;
76 }
77 }
78 if ($menuItemHideUnhideAllowed && !in_array('hide', $backRef->disabledItems)) {
79 $localItems['hide'] = $backRef->DB_hideUnhide($table, $backRef->rec, $hiddenField);
80 }
81 $anyEnableColumnsFieldAllowed = FALSE;
82 // Check if columns are defined
83 if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
84 $columnsToCheck = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
85 if ($table === 'pages' && !empty($columnsToCheck)) {
86 $columnsToCheck[] = 'extendToSubpages';
87 }
88 foreach ($columnsToCheck as $currentColumn) {
89 if (
90 isset($GLOBALS['TCA'][$table]['columns'][$currentColumn])
91 && (!empty($GLOBALS['TCA'][$table]['columns'][$currentColumn]['exclude'])
92 && $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $currentColumn))
93 ) {
94 $anyEnableColumnsFieldAllowed = TRUE;
95 }
96 }
97 }
98 if ($anyEnableColumnsFieldAllowed && !in_array('edit_access', $backRef->disabledItems)) {
99 $localItems['edit_access'] = $backRef->DB_editAccess($table, $uid);
100 }
101 if ($table === 'pages' && $backRef->editPageIconSet && !in_array('edit_pageproperties', $backRef->disabledItems)) {
102 $localItems['edit_pageproperties'] = $backRef->DB_editPageProperties($uid);
103 }
104 }
105 // Find delete element among the input menu items and insert the local items just before that:
106 $c = 0;
107 $deleteFound = FALSE;
108 foreach ($menuItems as $key => $value) {
109 $c++;
110 if ($key === 'delete') {
111 $deleteFound = TRUE;
112 break;
113 }
114 }
115 if ($deleteFound) {
116 // .. subtract two... (delete item + its spacer element...)
117 $c -= 2;
118 // and insert the items just before the delete element.
119 array_splice($menuItems, $c, 0, $localItems);
120 } else {
121 $menuItems = array_merge($menuItems, $localItems);
122 }
123 } elseif ($subname === 'moreoptions') {
124 // If the page can be edited, then show this:
125 if ($backRef->editOK) {
126 if (($table === 'pages' || $table === 'tt_content') && !in_array('move_wizard', $backRef->disabledItems)) {
127 $localItems['move_wizard'] = $backRef->DB_moveWizard($table, $uid, $backRef->rec);
128 }
129 if (($table === 'pages' || $table === 'tt_content') && !in_array('new_wizard', $backRef->disabledItems)) {
130 $localItems['new_wizard'] = $backRef->DB_newWizard($table, $uid, $backRef->rec);
131 }
132 if ($table === 'pages' && !in_array('perms', $backRef->disabledItems) && $GLOBALS['BE_USER']->check('modules', 'web_perm')) {
133 $localItems['perms'] = $backRef->DB_perms($table, $uid, $backRef->rec);
134 }
135 if (!in_array('db_list', $backRef->disabledItems) && $GLOBALS['BE_USER']->check('modules', 'web_list')) {
136 $localItems['db_list'] = $backRef->DB_db_list($table, $uid, $backRef->rec);
137 }
138 }
139 // Temporary mount point item:
140 if ($table === 'pages') {
141 $localItems['temp_mount_point'] = $backRef->DB_tempMountPoint($uid);
142 }
143 // Merge the locally made items into the current menu items passed to this function.
144 $menuItems = array_merge($menuItems, $localItems);
145 }
146 return $menuItems;
147 }
148
149 }