TYPO3 CMS  TYPO3_6-2
TaskModuleController.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
27  protected $pageinfo;
28 
34  public function __construct() {
35  $GLOBALS['LANG']->includeLLFile('EXT:taskcenter/task/locallang.xlf');
36  $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
37  parent::init();
38  // Initialize document
39  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
40  $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('taskcenter') . 'res/mod_template.html');
41  $this->doc->backPath = $GLOBALS['BACK_PATH'];
42  $this->doc->getPageRenderer()->loadScriptaculous('effects,dragdrop');
43  $this->doc->addStyleSheet('tx_taskcenter', '../' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('taskcenter') . 'res/mod_styles.css');
44  }
45 
51  public function menuConfig() {
52  $this->MOD_MENU = array('mode' => array());
53  $this->MOD_MENU['mode']['information'] = $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/locallang.xlf:task_overview');
54  $this->MOD_MENU['mode']['tasks'] = 'Tasks';
55  parent::menuConfig();
56  }
57 
64  public function main() {
65  $docHeaderButtons = $this->getButtons();
66  $markers = array();
67  $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) { top.fsMod.recentIds["web"] = 0; }');
68 
69  // Render content depending on the mode
70  $mode = (string) $this->MOD_SETTINGS['mode'];
71  if ($mode == 'information') {
72  $this->renderInformationContent();
73  } else {
74  $this->renderModuleContent();
75  }
76  // Compile document
77  $markers['FUNC_MENU'] = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[mode]', $this->MOD_SETTINGS['mode'], $this->MOD_MENU['mode']);
78  $markers['CONTENT'] = $this->content;
79  // Build the <body> for the module
80  $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
81  // Renders the module page
82  $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
83  }
84 
90  public function printContent() {
91  echo $this->content;
92  }
93 
99  protected function renderModuleContent() {
100  $title = ($content = ($actionContent = ''));
101  $chosenTask = (string) $this->MOD_SETTINGS['function'];
102  // Render the taskcenter task as default
103  if (empty($chosenTask) || $chosenTask == 'index') {
104  $chosenTask = 'taskcenter.tasks';
105  }
106  // Render the task
107  list($extKey, $taskClass) = explode('.', $chosenTask, 2);
108  $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['title']);
109  if (class_exists($taskClass)) {
110  $taskInstance = GeneralUtility::makeInstance($taskClass, $this);
111  if ($taskInstance instanceof \TYPO3\CMS\Taskcenter\TaskInterface) {
112  // Check if the task is restricted to admins only
113  if ($this->checkAccess($extKey, $taskClass)) {
114  $actionContent .= $taskInstance->getTask();
115  } else {
116  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('error-access', TRUE), $GLOBALS['LANG']->getLL('error_header'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
117  $actionContent .= $flashMessage->render();
118  }
119  } else {
120  // Error if the task is not an instance of \TYPO3\CMS\Taskcenter\TaskInterface
121  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('error_no-instance', TRUE), $taskClass, 'TYPO3\\CMS\\Taskcenter\\TaskInterface'), $GLOBALS['LANG']->getLL('error_header'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
122  $actionContent .= $flashMessage->render();
123  }
124  } else {
125  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xlf:mlang_labels_tabdescr'), $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xlf:mlang_tabs_tab'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
126  $actionContent .= $flashMessage->render();
127  }
128  $content = '<div id="taskcenter-main">
129  <div id="taskcenter-menu">' . $this->indexAction() . '</div>
130  <div id="taskcenter-item" class="' . htmlspecialchars(($extKey . '-' . $taskClass)) . '">' . $actionContent . '
131  </div>
132  </div>';
133  $this->content .= $content;
134  }
135 
141  protected function renderInformationContent() {
142  $content = $this->description($GLOBALS['LANG']->getLL('mlang_tabs_tab'), $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xlf:mlang_labels_tabdescr'));
143  $content .= $GLOBALS['LANG']->getLL('taskcenter-about');
144  if ($GLOBALS['BE_USER']->isAdmin()) {
145  $content .= '<br /><br />' . $this->description($GLOBALS['LANG']->getLL('taskcenter-adminheader'), $GLOBALS['LANG']->getLL('taskcenter-admin'));
146  }
147  $this->content .= $content;
148  }
149 
157  public function description($title, $description = '') {
158  if (!empty($description)) {
159  $description = '<p class="description">' . nl2br(htmlspecialchars($description)) . '</p><br />';
160  }
161  $content = $this->doc->section($title, $description, FALSE, TRUE);
162  return $content;
163  }
164 
180  public function renderListMenu($items, $mainMenu = FALSE) {
181  $content = ($section = '');
182  $count = 0;
183  // Change the sorting of items to the user's one
184  if ($mainMenu) {
185  $this->doc->getPageRenderer()->addJsFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('taskcenter') . 'res/tasklist.js');
186  $userSorting = unserialize($GLOBALS['BE_USER']->uc['taskcenter']['sorting']);
187  if (is_array($userSorting)) {
188  $newSorting = array();
189  foreach ($userSorting as $item) {
190  if (isset($items[$item])) {
191  $newSorting[] = $items[$item];
192  unset($items[$item]);
193  }
194  }
195  $items = $newSorting + $items;
196  }
197  }
198  if (is_array($items) && count($items) > 0) {
199  foreach ($items as $item) {
200  $title = htmlspecialchars($item['title']);
201  $icon = ($additionalClass = ($collapsedStyle = ''));
202  // Check for custom icon
203  if (!empty($item['icon'])) {
204  if (strpos($item['icon'], '<img ') === FALSE) {
205  $absIconPath = GeneralUtility::getFileAbsFilename($item['icon']);
206  // If the file indeed exists, assemble relative path to it
207  if (file_exists($absIconPath)) {
208  $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
209  $icon = '<img src="' . $icon . '" title="' . $title . '" alt="' . $title . '" />';
210  }
211  if (@is_file($icon)) {
212  $icon = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $title . '" alt="' . $title . '" />';
213  }
214  } else {
215  $icon = $item['icon'];
216  }
217  }
218  $description = $item['descriptionHtml'] ?: '<p>' . nl2br(htmlspecialchars($item['description'])) . '</p>';
219  $id = $this->getUniqueKey($item['uid']);
220  // Collapsed & expanded menu items
221  if ($mainMenu && isset($GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) && $GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) {
222  $collapsedStyle = 'style="display:none"';
223  $additionalClass = 'collapsed';
224  } else {
225  $additionalClass = 'expanded';
226  }
227  // First & last menu item
228  if ($count == 0) {
229  $additionalClass .= ' first-item';
230  } elseif ($count + 1 === count($items)) {
231  $additionalClass .= ' last-item';
232  }
233  // Active menu item
234  $active = (string) $this->MOD_SETTINGS['function'] == $item['uid'] ? ' active-task' : '';
235  // Main menu: Render additional syntax to sort tasks
236  if ($mainMenu) {
237  $dragIcon = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/move.gif', 'width="16" height="16" hspace="2"') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.move', TRUE) . '" alt="" />';
238  $section = '<div class="down">&nbsp;</div>
239  <div class="drag">' . $dragIcon . '</div>';
240  $backgroundClass = 't3-row-header ';
241  }
242  $content .= '<li class="' . $additionalClass . $active . '" id="el_' . $id . '">
243  ' . $section . '
244  <div class="image">' . $icon . '</div>
245  <div class="' . $backgroundClass . 'link"><a href="' . $item['link'] . '">' . $title . '</a></div>
246  <div class="content " ' . $collapsedStyle . '>' . $description . '</div>
247  </li>';
248  $count++;
249  }
250  $navigationId = $mainMenu ? 'id="task-list"' : '';
251  $content = '<ul ' . $navigationId . ' class="task-list">' . $content . '</ul>';
252  }
253  return $content;
254  }
255 
261  protected function indexAction() {
262  $content = '';
263  $tasks = array();
264  $icon = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('taskcenter') . 'task/task.gif';
265  // Render the tasks only if there are any available
266  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) && count($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) > 0) {
267  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'] as $extKey => $extensionReports) {
268  foreach ($extensionReports as $taskClass => $task) {
269  if (!$this->checkAccess($extKey, $taskClass)) {
270  continue;
271  }
272  $link = BackendUtility::getModuleUrl('user_task') . '&SET[function]=' . $extKey . '.' . $taskClass;
273  $taskTitle = $GLOBALS['LANG']->sL($task['title']);
274  $taskDescriptionHtml = '';
275  // Check for custom icon
276  if (!empty($task['icon'])) {
277  $icon = GeneralUtility::getFileAbsFilename($task['icon']);
278  }
279  if (class_exists($taskClass)) {
280  $taskInstance = GeneralUtility::makeInstance($taskClass, $this);
281  if ($taskInstance instanceof \TYPO3\CMS\Taskcenter\TaskInterface) {
282  $taskDescriptionHtml = $taskInstance->getOverview();
283  }
284  }
285  // Generate an array of all tasks
286  $uniqueKey = $this->getUniqueKey($extKey . '.' . $taskClass);
287  $tasks[$uniqueKey] = array(
288  'title' => $taskTitle,
289  'descriptionHtml' => $taskDescriptionHtml,
290  'description' => $GLOBALS['LANG']->sL($task['description']),
291  'icon' => $icon,
292  'link' => $link,
293  'uid' => $extKey . '.' . $taskClass
294  );
295  }
296  }
297  $content .= $this->renderListMenu($tasks, TRUE);
298  } else {
299  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('no-tasks', TRUE), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
300  $this->content .= $flashMessage->render();
301  }
302  return $content;
303  }
304 
311  protected function getButtons() {
312  $buttons = array(
313  'csh' => \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
314  'shortcut' => '',
315  'open_new_window' => $this->openInNewWindow()
316  );
317  // Shortcut
318  if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
319  $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
320  }
321  return $buttons;
322  }
323 
334  protected function checkAccess($extKey, $taskClass) {
335  // Check if task is blinded with TsConfig (taskcenter.<extkey>.<taskName>
336  $tsConfig = $GLOBALS['BE_USER']->getTSConfig('taskcenter.' . $extKey . '.' . $taskClass);
337  if (isset($tsConfig['value']) && (int)$tsConfig['value'] === 0) {
338  return FALSE;
339  }
340  // Admins are always allowed
341  if ($GLOBALS['BE_USER']->isAdmin()) {
342  return TRUE;
343  }
344  // Check if task is restricted to admins
345  if ((int)$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['admin'] === 1) {
346  return FALSE;
347  }
348  return TRUE;
349  }
350 
358  public function urlInIframe($url, $max = 0) {
359  $this->doc->JScodeArray[] = 'function resizeIframe(frame,max) {
360  var parent = $("typo3-docbody");
361  var parentHeight = $(parent).getHeight() - 0;
362  var parentWidth = $(parent).getWidth() - $("taskcenter-menu").getWidth() - 50;
363  $("list_frame").setStyle({height: parentHeight+"px", width: parentWidth+"px"});
364 
365  }
366  Event.observe(window, "resize", resizeIframe, false);';
367  return '<iframe onload="resizeIframe(this,' . $max . ');" scrolling="auto" width="100%" src="' . $url . '" name="list_frame" id="list_frame" frameborder="no" style="margin-top:-51px;border: none;"></iframe>';
368  }
369 
377  protected function getUniqueKey($string) {
378  $search = array('.', '_');
379  $replace = array('-', '');
380  return str_replace($search, $replace, $string);
381  }
382 
388  protected function openInNewWindow() {
389  $url = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
390  $onClick = 'devlogWin=window.open(\'' . $url . '\',\'taskcenter\',\'width=790,status=0,menubar=1,resizable=1,location=0,scrollbars=1,toolbar=0\');return false;';
391  $content = '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/open_in_new_window.gif', 'width="19" height="14"') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.openInNewWindow', TRUE) . '" class="absmiddle" alt="" />' . '</a>';
392  return $content;
393  }
394 
395 }
static skinImg($backPath, $src, $wHattribs='', $outputMode=0)
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
static getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addparams='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]