TYPO3 CMS  TYPO3_8-7
BaseScriptClass.php
Go to the documentation of this file.
1 <?php
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 
25 
70 {
77  public $MCONF = [];
78 
85  public $id;
86 
93  public $CMD;
94 
102 
109  public $MOD_MENU = [
110  'function' => []
111  ];
112 
119  public $MOD_SETTINGS = [];
120 
127  public $modTSconfig;
128 
136  public $modMenu_type = '';
137 
146 
155 
163 
169  public $content = '';
170 
174  public $doc;
175 
182  public $extObj;
183 
187  protected $pageRenderer = null;
188 
194  public function init()
195  {
196  // Name might be set from outside
197  if (!$this->MCONF['name']) {
198  $this->MCONF = $GLOBALS['MCONF'];
199  }
200  $this->id = (int)GeneralUtility::_GP('id');
201  $this->CMD = GeneralUtility::_GP('CMD');
202  $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
203  $this->menuConfig();
205  }
206 
214  public function menuConfig()
215  {
216  // Page/be_user TSconfig settings and blinding of menu-items
217  $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
218  $this->MOD_MENU['function'] = $this->mergeExternalItems($this->MCONF['name'], 'function', $this->MOD_MENU['function']);
219  $this->MOD_MENU['function'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function');
220  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
221  }
222 
233  public function mergeExternalItems($modName, $menuKey, $menuArr)
234  {
235  $mergeArray = $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
236  if (is_array($mergeArray)) {
237  foreach ($mergeArray as $k => $v) {
238  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')) {
239  $menuArr[$k] = $this->getLanguageService()->sL($v['title']);
240  }
241  }
242  }
243  return $menuArr;
244  }
245 
253  public function handleExternalFunctionValue($MM_key = 'function', $MS_value = null)
254  {
255  if ($MS_value === null) {
256  $MS_value = $this->MOD_SETTINGS[$MM_key];
257  }
258  $this->extClassConf = $this->getExternalItemConfig($this->MCONF['name'], $MM_key, $MS_value);
259  }
260 
271  public function getExternalItemConfig($modName, $menuKey, $value = '')
272  {
273  if (isset($GLOBALS['TBE_MODULES_EXT'][$modName])) {
274  return (string)$value !== '' ? $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value] : $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
275  }
276  return null;
277  }
278 
287  public function checkExtObj()
288  {
289  if (is_array($this->extClassConf) && $this->extClassConf['name']) {
290  $this->extObj = GeneralUtility::makeInstance($this->extClassConf['name']);
291  $this->extObj->init($this, $this->extClassConf);
292  // Re-write:
293  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
294  }
295  }
296 
300  public function checkSubExtObj()
301  {
302  if (is_object($this->extObj)) {
303  $this->extObj->checkExtObj();
304  }
305  }
306 
311  public function extObjHeader()
312  {
313  if (is_callable([$this->extObj, 'head'])) {
314  $this->extObj->head();
315  }
316  }
317 
321  public function extObjContent()
322  {
323  if ($this->extObj === null) {
324  $flashMessage = GeneralUtility::makeInstance(
325  FlashMessage::class,
326  $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:no_modules_registered'),
327  $this->getLanguageService()->getLL('title'),
329  );
331  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
333  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
334  $defaultFlashMessageQueue->enqueue($flashMessage);
335  } else {
336  $this->extObj->pObj = $this;
337  if (is_callable([$this->extObj, 'main'])) {
338  $this->content .= $this->extObj->main();
339  }
340  }
341  }
342 
348  public function getExtObjContent()
349  {
350  $savedContent = $this->content;
351  $this->content = '';
352  $this->extObjContent();
353  $newContent = $this->content;
354  $this->content = $savedContent;
355  return $newContent;
356  }
357 
362  protected function getLanguageService()
363  {
364  return $GLOBALS['LANG'];
365  }
366 
371  protected function getBackendUser()
372  {
373  return $GLOBALS['BE_USER'];
374  }
375 
380  protected function getDatabaseConnection()
381  {
383  return $GLOBALS['TYPO3_DB'];
384  }
385 
389  protected function getPageRenderer()
390  {
391  if ($this->pageRenderer === null) {
392  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
393  }
394 
395  return $this->pageRenderer;
396  }
397 }
getExternalItemConfig($modName, $menuKey, $value='')
static getModuleData( $MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
mergeExternalItems($modName, $menuKey, $menuArr)
static makeInstance($className,... $constructorArguments)
static unsetMenuItems($modTSconfig, $itemArray, $TSref)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
handleExternalFunctionValue($MM_key='function', $MS_value=null)