|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Common; |
|
14
|
|
|
|
|
15
|
|
|
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; |
|
16
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
17
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
|
|
|
|
|
18
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Abstract module class for the 'dlf' extension |
|
22
|
|
|
* |
|
23
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
24
|
|
|
* @package TYPO3 |
|
25
|
|
|
* @subpackage dlf |
|
26
|
|
|
* @access public |
|
27
|
|
|
* @abstract |
|
28
|
|
|
*/ |
|
29
|
|
|
abstract class AbstractModule |
|
30
|
|
|
{ |
|
31
|
|
|
public $extKey = 'dlf'; |
|
32
|
|
|
public $prefixId = 'tx_dlf'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Holds the page record if access granted or false if access denied |
|
36
|
|
|
* |
|
37
|
|
|
* @var mixed |
|
38
|
|
|
* @access protected |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $pageInfo; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Holds the module's marker array |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
* @access protected |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $markerArray = []; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Holds the PSR-7 response object |
|
52
|
|
|
* |
|
53
|
|
|
* @var \Psr\Http\Message\ResponseInterface |
|
54
|
|
|
* @access protected |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $response; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Holds the module's subpart array |
|
60
|
|
|
* |
|
61
|
|
|
* @var array |
|
62
|
|
|
* @access protected |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $subpartArray = []; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Holds the TYPO3_CONF_VARS array of this extension |
|
68
|
|
|
* |
|
69
|
|
|
* @var array |
|
70
|
|
|
* @access protected |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $conf = []; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Holds the submitted form's data |
|
76
|
|
|
* |
|
77
|
|
|
* @var array |
|
78
|
|
|
* @access protected |
|
79
|
|
|
*/ |
|
80
|
|
|
protected $data; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var \TYPO3\CMS\Backend\Template\DocumentTemplate |
|
|
|
|
|
|
84
|
|
|
*/ |
|
85
|
|
|
public $doc; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Main function of the module. |
|
89
|
|
|
* |
|
90
|
|
|
* @access public |
|
91
|
|
|
* |
|
92
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request: The request object |
|
93
|
|
|
* |
|
94
|
|
|
* @abstract |
|
95
|
|
|
* |
|
96
|
|
|
* @return \Psr\Http\Message\ResponseInterface The response object |
|
97
|
|
|
*/ |
|
98
|
|
|
abstract public function main(\Psr\Http\Message\ServerRequestInterface $request); |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Fills the response object with the module's output. |
|
102
|
|
|
* |
|
103
|
|
|
* @access protected |
|
104
|
|
|
* |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function printContent() |
|
108
|
|
|
{ |
|
109
|
|
|
$languageService = GeneralUtility::makeInstance(LanguageService::class); |
|
110
|
|
|
$this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class); |
|
111
|
|
|
$this->doc->setModuleTemplate('EXT:' . $this->extKey . '/Resources/Private/Templates/' . Helper::getUnqualifiedClassName(get_class($this)) . '.tmpl'); |
|
112
|
|
|
$this->doc->backPath = $GLOBALS['BACK_PATH']; |
|
113
|
|
|
$this->doc->bodyTagAdditions = 'class="ext-' . $this->extKey . '-modules"'; |
|
114
|
|
|
$this->doc->form = '<form action="" method="post" enctype="multipart/form-data">'; |
|
115
|
|
|
// Add Javascript for function menu. |
|
116
|
|
|
$this->doc->JScode .= '<script type="text/javascript">script_ended = 0;function jumpToUrl(URL) { document.location = URL; }</script>'; |
|
117
|
|
|
// Add Javascript for convenient module switch. |
|
118
|
|
|
$this->doc->postCode .= '<script type="text/javascript">script_ended = 1;</script>'; |
|
119
|
|
|
// Render output. |
|
120
|
|
|
$this->content .= $this->doc->startPage($languageService->sL('title')); |
|
|
|
|
|
|
121
|
|
|
// Set defaults for menu. |
|
122
|
|
|
if (empty($this->markerArray['CSH'])) { |
|
123
|
|
|
$this->markerArray['CSH'] = \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('_MOD_' . $GLOBALS['MCONF']['name'], 'csh'); |
|
124
|
|
|
} |
|
125
|
|
|
if (empty($this->markerArray['MOD_MENU'])) { |
|
126
|
|
|
$this->markerArray['MOD_MENU'] = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']); |
|
127
|
|
|
} |
|
128
|
|
|
$this->content .= $this->doc->moduleBody($this->pageInfo, [], $this->markerArray, $this->subpartArray); |
|
129
|
|
|
$this->content .= $this->doc->endPage(); |
|
130
|
|
|
return $this->content; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Initializes the backend module. |
|
135
|
|
|
* |
|
136
|
|
|
* @access public |
|
137
|
|
|
* |
|
138
|
|
|
* @return void |
|
139
|
|
|
*/ |
|
140
|
|
|
public function __construct() |
|
141
|
|
|
{ |
|
142
|
|
|
$languageService = GeneralUtility::makeInstance(LanguageService::class); |
|
143
|
|
|
$languageService->includeLLFile('EXT:' . $this->extKey . '/Resources/Private/Language/' . Helper::getUnqualifiedClassName(get_class($this)) . '.xml'); |
|
144
|
|
|
// Read extension configuration. |
|
145
|
|
|
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$this->extKey]) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$this->extKey])) { |
|
146
|
|
|
$this->conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get($this->extKey); |
|
147
|
|
|
} |
|
148
|
|
|
$this->data = GeneralUtility::_GPmerged($this->prefixId); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Initializes the backend module by setting internal variables, initializing the menu. |
|
153
|
|
|
* |
|
154
|
|
|
* @see menuConfig() |
|
155
|
|
|
*/ |
|
156
|
|
|
public function init() |
|
157
|
|
|
{ |
|
158
|
|
|
// Name might be set from outside |
|
159
|
|
|
if (!$this->MCONF['name']) { |
|
160
|
|
|
$this->MCONF = $GLOBALS['MCONF']; |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
$this->id = (int)GeneralUtility::_GP('id'); |
|
|
|
|
|
|
163
|
|
|
$this->CMD = GeneralUtility::_GP('CMD'); |
|
|
|
|
|
|
164
|
|
|
$this->perms_clause = $this->getBackendUser()->getPagePermsClause(1); |
|
|
|
|
|
|
165
|
|
|
$this->menuConfig(); |
|
166
|
|
|
$this->handleExternalFunctionValue(); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Returns the Backend User |
|
171
|
|
|
* @return BackendUserAuthentication |
|
|
|
|
|
|
172
|
|
|
*/ |
|
173
|
|
|
protected function getBackendUser() |
|
174
|
|
|
{ |
|
175
|
|
|
return $GLOBALS['BE_USER']; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Initializes the internal MOD_MENU array setting and unsetting items based on various conditions. It also merges in external menu items from the global array TBE_MODULES_EXT (see mergeExternalItems()) |
|
180
|
|
|
* Then MOD_SETTINGS array is cleaned up (see \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData()) so it contains only valid values. It's also updated with any SET[] values submitted. |
|
181
|
|
|
* Also loads the modTSconfig internal variable. |
|
182
|
|
|
* |
|
183
|
|
|
* @see init(), $MOD_MENU, $MOD_SETTINGS, \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData(), mergeExternalItems() |
|
184
|
|
|
*/ |
|
185
|
|
|
public function menuConfig() |
|
186
|
|
|
{ |
|
187
|
|
|
// Page/be_user TSconfig settings and blinding of menu-items |
|
188
|
|
|
$userTsConfig = $this->getBackendUser()->getTSConfig(); |
|
189
|
|
|
$this->modTSconfig = $userTsConfig['mod.'][$this->MCONF['name']]; |
|
|
|
|
|
|
190
|
|
|
$this->MOD_MENU['function'] = $this->mergeExternalItems($this->MCONF['name'], 'function', $this->MOD_MENU['function']); |
|
|
|
|
|
|
191
|
|
|
$this->MOD_MENU['function'] = $this->unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function'); |
|
192
|
|
|
$this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList); |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Removes menu items from $itemArray if they are configured to be removed by TSconfig for the module ($modTSconfig) |
|
197
|
|
|
* See Inside TYPO3 about how to program modules and use this API. |
|
198
|
|
|
* |
|
199
|
|
|
* @param array $modTSconfig Module TS config array |
|
200
|
|
|
* @param array $itemArray Array of items from which to remove items. |
|
201
|
|
|
* @param string $TSref $TSref points to the "object string" in $modTSconfig |
|
202
|
|
|
* @return array The modified $itemArray is returned. |
|
203
|
|
|
*/ |
|
204
|
|
|
public function unsetMenuItems($modTSconfig, $itemArray, $TSref) |
|
|
|
|
|
|
205
|
|
|
{ |
|
206
|
|
|
// Getting TS-config options for this module for the Backend User: |
|
207
|
|
|
if (is_array($modTSconfig)) { |
|
|
|
|
|
|
208
|
|
|
foreach ($modTSconfig as $key => $val) { |
|
209
|
|
|
if (!$val) { |
|
210
|
|
|
unset($itemArray[$key]); |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
return $itemArray; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Merges menu items from global array $TBE_MODULES_EXT |
|
219
|
|
|
* |
|
220
|
|
|
* @param string $modName Module name for which to find value |
|
221
|
|
|
* @param string $menuKey Menu key, eg. 'function' for the function menu. |
|
222
|
|
|
* @param array $menuArr The part of a MOD_MENU array to work on. |
|
223
|
|
|
* @return array Modified array part. |
|
224
|
|
|
* @access private |
|
225
|
|
|
* @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::insertModuleFunction(), menuConfig() |
|
226
|
|
|
*/ |
|
227
|
|
|
public function mergeExternalItems($modName, $menuKey, $menuArr) |
|
228
|
|
|
{ |
|
229
|
|
|
$mergeArray = $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey]; |
|
230
|
|
|
if (is_array($mergeArray)) { |
|
231
|
|
|
foreach ($mergeArray as $k => $v) { |
|
232
|
|
|
if (((string)$v['ws'] === '' || $this->getBackendUser()->workspace === 0 && GeneralUtility::inList($v['ws'], 'online')) || $this->getBackendUser()->workspace === -1 && GeneralUtility::inList($v['ws'], 'offline') || $this->getBackendUser()->workspace > 0 && GeneralUtility::inList($v['ws'], 'custom')) { |
|
233
|
|
|
$menuArr[$k] = $this->getLanguageService()->sL($v['title']); |
|
|
|
|
|
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
return $menuArr; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Loads $this->extClassConf with the configuration for the CURRENT function of the menu. |
|
242
|
|
|
* |
|
243
|
|
|
* @param string $MM_key The key to MOD_MENU for which to fetch configuration. 'function' is default since it is first and foremost used to get information per "extension object" (I think that is what its called) |
|
244
|
|
|
* @param string $MS_value The value-key to fetch from the config array. If NULL (default) MOD_SETTINGS[$MM_key] will be used. This is useful if you want to force another function than the one defined in MOD_SETTINGS[function]. Call this in init() function of your Script Class: handleExternalFunctionValue('function', $forcedSubModKey) |
|
245
|
|
|
* @see getExternalItemConfig(), init() |
|
246
|
|
|
*/ |
|
247
|
|
|
public function handleExternalFunctionValue($MM_key = 'function', $MS_value = null) |
|
248
|
|
|
{ |
|
249
|
|
|
if ($MS_value === null) { |
|
250
|
|
|
$MS_value = $this->MOD_SETTINGS[$MM_key]; |
|
251
|
|
|
} |
|
252
|
|
|
$this->extClassConf = $this->getExternalItemConfig($this->MCONF['name'], $MM_key, $MS_value); |
|
|
|
|
|
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Returns configuration values from the global variable $TBE_MODULES_EXT for the module given. |
|
257
|
|
|
* For example if the module is named "web_info" and the "function" key ($menuKey) of MOD_SETTINGS is "stat" ($value) then you will have the values of $TBE_MODULES_EXT['webinfo']['MOD_MENU']['function']['stat'] returned. |
|
258
|
|
|
* |
|
259
|
|
|
* @param string $modName Module name |
|
260
|
|
|
* @param string $menuKey Menu key, eg. "function" for the function menu. See $this->MOD_MENU |
|
261
|
|
|
* @param string $value Optionally the value-key to fetch from the array that would otherwise have been returned if this value was not set. Look source... |
|
262
|
|
|
* @return mixed The value from the TBE_MODULES_EXT array. |
|
263
|
|
|
* @see handleExternalFunctionValue() |
|
264
|
|
|
*/ |
|
265
|
|
|
public function getExternalItemConfig($modName, $menuKey, $value = '') |
|
266
|
|
|
{ |
|
267
|
|
|
if (isset($GLOBALS['TBE_MODULES_EXT'][$modName])) { |
|
268
|
|
|
return (string)$value !== '' ? $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value] : $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey]; |
|
269
|
|
|
} |
|
270
|
|
|
return null; |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths