TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
BaseScriptClass.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Module;
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 
76 {
83  public $MCONF = [];
84 
91  public $id;
92 
99  public $CMD;
100 
108 
115  public $MOD_MENU = [
116  'function' => []
117  ];
118 
125  public $MOD_SETTINGS = [];
126 
133  public $modTSconfig;
134 
142  public $modMenu_type = '';
143 
152 
161 
169 
175  public $content = '';
176 
180  public $doc;
181 
188  public $extObj;
189 
193  protected $pageRenderer = null;
194 
201  public function init()
202  {
203  // Name might be set from outside
204  if (!$this->MCONF['name']) {
205  $this->MCONF = $GLOBALS['MCONF'];
206  }
207  $this->id = (int)GeneralUtility::_GP('id');
208  $this->CMD = GeneralUtility::_GP('CMD');
209  $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
210  $this->menuConfig();
212  }
213 
222  public function menuConfig()
223  {
224  // Page/be_user TSconfig settings and blinding of menu-items
225  $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
226  $this->MOD_MENU['function'] = $this->mergeExternalItems($this->MCONF['name'], 'function', $this->MOD_MENU['function']);
227  $this->MOD_MENU['function'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function');
228  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
229  }
230 
241  public function mergeExternalItems($modName, $menuKey, $menuArr)
242  {
243  $mergeArray = $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
244  if (is_array($mergeArray)) {
245  foreach ($mergeArray as $k => $v) {
246  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')) {
247  $menuArr[$k] = $this->getLanguageService()->sL($v['title']);
248  }
249  }
250  }
251  return $menuArr;
252  }
253 
262  public function handleExternalFunctionValue($MM_key = 'function', $MS_value = null)
263  {
264  if ($MS_value === null) {
265  $MS_value = $this->MOD_SETTINGS[$MM_key];
266  }
267  $this->extClassConf = $this->getExternalItemConfig($this->MCONF['name'], $MM_key, $MS_value);
268  }
269 
280  public function getExternalItemConfig($modName, $menuKey, $value = '')
281  {
282  if (isset($GLOBALS['TBE_MODULES_EXT'][$modName])) {
283  return (string)$value !== '' ? $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value] : $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
284  }
285  return null;
286  }
287 
297  public function checkExtObj()
298  {
299  if (is_array($this->extClassConf) && $this->extClassConf['name']) {
300  $this->extObj = GeneralUtility::makeInstance($this->extClassConf['name']);
301  $this->extObj->init($this, $this->extClassConf);
302  // Re-write:
303  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
304  }
305  }
306 
312  public function checkSubExtObj()
313  {
314  if (is_object($this->extObj)) {
315  $this->extObj->checkExtObj();
316  }
317  }
318 
325  public function extObjHeader()
326  {
327  if (is_callable([$this->extObj, 'head'])) {
328  $this->extObj->head();
329  }
330  }
331 
337  public function extObjContent()
338  {
339  if ($this->extObj === null) {
340  $flashMessage = GeneralUtility::makeInstance(
341  FlashMessage::class,
342  $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:no_modules_registered'),
343  $this->getLanguageService()->getLL('title'),
345  );
347  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
349  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
350  $defaultFlashMessageQueue->enqueue($flashMessage);
351  } else {
352  $this->extObj->pObj = $this;
353  if (is_callable([$this->extObj, 'main'])) {
354  $this->content .= $this->extObj->main();
355  }
356  }
357  }
358 
364  public function getExtObjContent()
365  {
366  $savedContent = $this->content;
367  $this->content = '';
368  $this->extObjContent();
369  $newContent = $this->content;
370  $this->content = $savedContent;
371  return $newContent;
372  }
373 
378  protected function getLanguageService()
379  {
380  return $GLOBALS['LANG'];
381  }
382 
387  protected function getBackendUser()
388  {
389  return $GLOBALS['BE_USER'];
390  }
391 
396  protected function getDatabaseConnection()
397  {
399  return $GLOBALS['TYPO3_DB'];
400  }
401 
405  protected function getPageRenderer()
406  {
407  if ($this->pageRenderer === null) {
408  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
409  }
410 
411  return $this->pageRenderer;
412  }
413 }
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type= '', $dontValidateList= '', $setDefaultList= '')
mergeExternalItems($modName, $menuKey, $menuArr)
handleExternalFunctionValue($MM_key= 'function', $MS_value=null)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
getExternalItemConfig($modName, $menuKey, $value= '')