TYPO3 CMS  TYPO3_7-6
TaskModuleController.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 
29 
34 {
38  protected $pageinfo;
39 
45  protected $moduleTemplate;
46 
52  protected $moduleName = 'user_task';
53 
57  public function __construct()
58  {
59  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
60  $this->moduleTemplate->getPageRenderer()->addCssFile(ExtensionManagementUtility::extRelPath('taskcenter') . 'Resources/Public/Css/styles.css');
61  $this->getLanguageService()->includeLLFile('EXT:taskcenter/Resources/Private/Language/locallang_task.xlf');
62  $this->MCONF = [
63  'name' => $this->moduleName
64  ];
65  parent::init();
66  }
67 
73  public function menuConfig()
74  {
75  $this->MOD_MENU = ['mode' => []];
76  $this->MOD_MENU['mode']['information'] = $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:task_overview');
77  $this->MOD_MENU['mode']['tasks'] = $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:task_tasks');
78  /* Copied from parent::menuConfig, because parent is hardcoded to menu.function,
79  * however menu.function is already used for the individual tasks.
80  * Therefore we use menu.mode here.
81  */
82  // Page/be_user TSconfig settings and blinding of menu-items
83  $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
84  $this->MOD_MENU['mode'] = $this->mergeExternalItems($this->MCONF['name'], 'mode', $this->MOD_MENU['mode']);
85  $this->MOD_MENU['mode'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['mode'], 'menu.mode');
86  parent::menuConfig();
87  }
88 
94  protected function generateMenu()
95  {
96  $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
97  $menu->setIdentifier('WebFuncJumpMenu');
98  foreach ($this->MOD_MENU['mode'] as $controller => $title) {
99  $item = $menu
100  ->makeMenuItem()
101  ->setHref(
102  BackendUtility::getModuleUrl(
103  $this->moduleName,
104  [
105  'id' => $this->id,
106  'SET' => [
107  'mode' => $controller
108  ]
109  ]
110  )
111  )
112  ->setTitle($title);
113  if ($controller === $this->MOD_SETTINGS['mode']) {
114  $item->setActive(true);
115  }
116  $menu->addMenuItem($item);
117  }
118  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
119  }
120 
129  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
130  {
131  $GLOBALS['SOBE'] = $this;
132  $this->main();
133 
134  $this->moduleTemplate->setContent($this->content);
135 
136  $response->getBody()->write($this->moduleTemplate->renderContent());
137  return $response;
138  }
139 
146  public function main()
147  {
148  $this->getButtons();
149  $this->generateMenu();
150  $this->moduleTemplate->addJavaScriptCode(
151  'TaskCenterInlineJavascript',
152  'if (top.fsMod) { top.fsMod.recentIds["web"] = 0; }'
153  );
154 
155  // Render content depending on the mode
156  $mode = (string)$this->MOD_SETTINGS['mode'];
157  if ($mode === 'information') {
158  $this->renderInformationContent();
159  } else {
160  $this->renderModuleContent();
161  }
162  // Renders the module page
163  $this->moduleTemplate->setTitle($this->getLanguageService()->getLL('title'));
164  }
165 
171  public function printContent()
172  {
173  echo $this->content;
174  }
175 
181  protected function renderModuleContent()
182  {
183  $chosenTask = (string)$this->MOD_SETTINGS['function'];
184  // Render the taskcenter task as default
185  if (empty($chosenTask) || $chosenTask == 'index') {
186  $chosenTask = 'taskcenter.tasks';
187  }
188  // Render the task
189  $actionContent = '';
190  $flashMessage = null;
191  list($extKey, $taskClass) = explode('.', $chosenTask, 2);
192  if (class_exists($taskClass)) {
193  $taskInstance = GeneralUtility::makeInstance($taskClass, $this);
194  if ($taskInstance instanceof TaskInterface) {
195  // Check if the task is restricted to admins only
196  if ($this->checkAccess($extKey, $taskClass)) {
197  $actionContent .= $taskInstance->getTask();
198  } else {
199  $flashMessage = GeneralUtility::makeInstance(
200  FlashMessage::class,
201  $this->getLanguageService()->getLL('error-access', true),
202  $this->getLanguageService()->getLL('error_header'),
204  );
205  }
206  } else {
207  // Error if the task is not an instance of \TYPO3\CMS\Taskcenter\TaskInterface
208  $flashMessage = GeneralUtility::makeInstance(
209  FlashMessage::class,
210  sprintf($this->getLanguageService()->getLL('error_no-instance', true), $taskClass, TaskInterface::class),
211  $this->getLanguageService()->getLL('error_header'),
213  );
214  }
215  } else {
216  $flashMessage = GeneralUtility::makeInstance(
217  FlashMessage::class,
218  $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang_mod.xlf:mlang_labels_tabdescr'),
219  $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'),
221  );
222  }
223 
224  if ($flashMessage) {
226  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
228  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
229  $defaultFlashMessageQueue->enqueue($flashMessage);
230  }
231 
232  $content = '<div id="taskcenter-main">
233  <div id="taskcenter-menu">' . $this->indexAction() . '</div>
234  <div id="taskcenter-item" class="' . htmlspecialchars(($extKey . '-' . $taskClass)) . '">' . $actionContent . '
235  </div>
236  </div>';
237  $this->content .= $content;
238  }
239 
245  protected function renderInformationContent()
246  {
247  $content = $this->description($this->getLanguageService()->getLL('mlang_tabs_tab'), $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang_mod.xlf:mlang_labels_tabdescr'));
248  $content .= $this->getLanguageService()->getLL('taskcenter-about');
249  if ($this->getBackendUser()->isAdmin()) {
250  $content .= '<br /><br />' . $this->description($this->getLanguageService()->getLL('taskcenter-adminheader'), $this->getLanguageService()->getLL('taskcenter-admin'));
251  }
252  $this->content .= $content;
253  }
254 
262  public function description($title, $description = '')
263  {
264  $content = '<h1>' . nl2br(htmlspecialchars($title)) . '</h1>';
265  if (!empty($description)) {
266  $content .= '<p class="description">' . nl2br(htmlspecialchars($description)) . '</p>';
267  }
268  return $content;
269  }
270 
286  public function renderListMenu($items, $mainMenu = false)
287  {
288  $content = ($section = '');
289  $count = 0;
290  // Change the sorting of items to the user's one
291  if ($mainMenu) {
292  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Taskcenter/Taskcenter');
293  $userSorting = unserialize($this->getBackendUser()->uc['taskcenter']['sorting']);
294  if (is_array($userSorting)) {
295  $newSorting = [];
296  foreach ($userSorting as $item) {
297  if (isset($items[$item])) {
298  $newSorting[] = $items[$item];
299  unset($items[$item]);
300  }
301  }
302  $items = $newSorting + $items;
303  }
304  }
305  if (is_array($items) && !empty($items)) {
306  foreach ($items as $item) {
307  $title = htmlspecialchars($item['title']);
308  $icon = ($additionalClass = ($collapsedStyle = ''));
309  // Check for custom icon
310  if (!empty($item['icon'])) {
311  if (strpos($item['icon'], '<img ') === false) {
312  $absIconPath = GeneralUtility::getFileAbsFileName($item['icon']);
313  // If the file indeed exists, assemble relative path to it
314  if (file_exists($absIconPath)) {
315  $icon = '../' . str_replace(PATH_site, '', $absIconPath);
316  $icon = '<img src="' . $icon . '" title="' . $title . '" alt="' . $title . '" />';
317  }
318  if (@is_file($icon)) {
319  $icon = '<img src="' . PathUtility::getAbsoluteWebPath($icon) . '" width="16" height="16" title="' . $title . '" alt="' . $title . '" />';
320  }
321  } else {
322  $icon = $item['icon'];
323  }
324  }
325  $description = $item['descriptionHtml'] ?: '<p>' . nl2br(htmlspecialchars($item['description'])) . '</p>';
326  $id = $this->getUniqueKey($item['uid']);
327  // Collapsed & expanded menu items
328  if ($mainMenu && isset($this->getBackendUser()->uc['taskcenter']['states'][$id]) && $this->getBackendUser()->uc['taskcenter']['states'][$id]) {
329  $collapsedStyle = 'style="display:none"';
330  $additionalClass = 'collapsed';
331  } else {
332  $additionalClass = 'expanded';
333  }
334  // First & last menu item
335  if ($count == 0) {
336  $additionalClass .= ' first-item';
337  } elseif ($count + 1 === count($items)) {
338  $additionalClass .= ' last-item';
339  }
340  // Active menu item
341  $active = (string)$this->MOD_SETTINGS['function'] == $item['uid'] ? ' active-task' : '';
342  // Main menu: Render additional syntax to sort tasks
343  if ($mainMenu) {
344  $section = '<div class="down"><i class="fa fa-caret-down fa-fw"></i></div>
345  <div class="drag"><i class="fa fa-arrows"></i></div>';
346  $backgroundClass = 't3-row-header ';
347  } else {
348  $backgroundClass = '';
349  }
350  $content .= '<li class="' . $additionalClass . $active . '" id="el_' . $id . '">
351  ' . $section . '
352  <div class="image">' . $icon . '</div>
353  <div class="' . $backgroundClass . 'link"><a href="' . $item['link'] . '">' . $title . '</a></div>
354  <div class="content " ' . $collapsedStyle . '>' . $description . '</div>
355  </li>';
356  $count++;
357  }
358  $navigationId = $mainMenu ? 'id="task-list"' : '';
359  $content = '<ul ' . $navigationId . ' class="task-list">' . $content . '</ul>';
360  }
361  return $content;
362  }
363 
369  protected function indexAction()
370  {
371  $content = '';
372  $tasks = [];
373  $icon = ExtensionManagementUtility::extRelPath('taskcenter') . 'Resources/Public/Icons/module-taskcenter.svg';
374  // Render the tasks only if there are any available
375  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) && !empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'])) {
376  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'] as $extKey => $extensionReports) {
377  foreach ($extensionReports as $taskClass => $task) {
378  if (!$this->checkAccess($extKey, $taskClass)) {
379  continue;
380  }
381  $link = BackendUtility::getModuleUrl('user_task') . '&SET[function]=' . $extKey . '.' . $taskClass;
382  $taskTitle = $this->getLanguageService()->sL($task['title']);
383  $taskDescriptionHtml = '';
384  // Check for custom icon
385  if (!empty($task['icon'])) {
386  $icon = GeneralUtility::getFileAbsFileName($task['icon']);
387  }
388  if (class_exists($taskClass)) {
389  $taskInstance = GeneralUtility::makeInstance($taskClass, $this);
390  if ($taskInstance instanceof TaskInterface) {
391  $taskDescriptionHtml = $taskInstance->getOverview();
392  }
393  }
394  // Generate an array of all tasks
395  $uniqueKey = $this->getUniqueKey($extKey . '.' . $taskClass);
396  $tasks[$uniqueKey] = [
397  'title' => $taskTitle,
398  'descriptionHtml' => $taskDescriptionHtml,
399  'description' => $this->getLanguageService()->sL($task['description']),
400  'icon' => $icon,
401  'link' => $link,
402  'uid' => $extKey . '.' . $taskClass
403  ];
404  }
405  }
406  $content .= $this->renderListMenu($tasks, true);
407  } else {
408  $flashMessage = GeneralUtility::makeInstance(
409  FlashMessage::class,
410  $this->getLanguageService()->getLL('no-tasks', true),
411  '',
413  );
415  $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
417  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
418  $defaultFlashMessageQueue->enqueue($flashMessage);
419  }
420  return $content;
421  }
422 
429  protected function getButtons()
430  {
431  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
432 
433  // Fullscreen Button
434  $url = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
435  $onClick = 'devlogWin=window.open(' . GeneralUtility::quoteJSvalue($url) . ',\'taskcenter\',\'width=790,status=0,menubar=1,resizable=1,location=0,scrollbars=1,toolbar=0\');return false;';
436  $fullscreenButton = $buttonBar->makeLinkButton()
437  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.openInNewWindow'))
438  ->setOnClick($onClick)
439  ->setHref('#')
440  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-window-open', Icon::SIZE_SMALL))
441  ;
442  $buttonBar->addButton($fullscreenButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
443 
444  // Shortcut
445  $shortcutButton = $buttonBar->makeShortcutButton()
446  ->setModuleName($this->moduleName)
447  ->setSetVariables(['function']);
448  $buttonBar->addButton($shortcutButton);
449  }
450 
461  protected function checkAccess($extKey, $taskClass)
462  {
463  // Check if task is blinded with TsConfig (taskcenter.<extkey>.<taskName>
464  $tsConfig = $this->getBackendUser()->getTSConfig('taskcenter.' . $extKey . '.' . $taskClass);
465  if (isset($tsConfig['value']) && (int)$tsConfig['value'] === 0) {
466  return false;
467  }
468  // Admins are always allowed
469  if ($this->getBackendUser()->isAdmin()) {
470  return true;
471  }
472  // Check if task is restricted to admins
473  if ((int)$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['admin'] === 1) {
474  return false;
475  }
476  return true;
477  }
478 
485  public function urlInIframe($url)
486  {
487  return '<iframe scrolling="auto" width="100%" src="' . $url . '" name="list_frame" id="list_frame" frameborder="no"></iframe>';
488  }
489 
497  protected function getUniqueKey($string)
498  {
499  $search = ['.', '_'];
500  $replace = ['-', ''];
501  return str_replace($search, $replace, $string);
502  }
503 
509  protected function openInNewWindow()
510  {
511  $url = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
512  $onClick = 'devlogWin=window.open(' . GeneralUtility::quoteJSvalue($url) . ',\'taskcenter\',\'width=790,status=0,menubar=1,resizable=1,location=0,scrollbars=1,toolbar=0\');return false;';
513  $content = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.openInNewWindow', true) . '">'
514  . $this->moduleTemplate->getIconFactory()->getIcon('actions-window-open', Icon::SIZE_SMALL)->render()
515  . '</a>';
516  return $content;
517  }
518 
524  protected function getBackendUser()
525  {
526  return $GLOBALS['BE_USER'];
527  }
528 
534  protected function getLanguageService()
535  {
536  return $GLOBALS['LANG'];
537  }
538 
542  public function getModuleTemplate()
543  {
544  return $this->moduleTemplate;
545  }
546 }
static getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:40
mergeExternalItems($modName, $menuKey, $menuArr)
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static unsetMenuItems($modTSconfig, $itemArray, $TSref)
static getFileAbsFileName($filename, $onlyRelative=true, $relToTYPO3_mainDir=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']