Example #1
0
 /**
  * Retrieves the shortcuts for the current user
  *
  * @return array Array of shortcuts
  */
 protected function initShortcuts()
 {
     $backendUser = $this->getBackendUser();
     // Traverse shortcuts
     $lastGroup = 0;
     $shortcuts = [];
     $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_be_shortcuts');
     $result = $queryBuilder->select('*')->from('sys_be_shortcuts')->where($queryBuilder->expr()->andX($queryBuilder->expr()->eq('userid', $queryBuilder->createNamedParameter($backendUser->user['uid'], \PDO::PARAM_INT)), $queryBuilder->expr()->gte('sc_group', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))))->orWhere($queryBuilder->expr()->in('sc_group', $queryBuilder->createNamedParameter(array_keys($this->getGlobalShortcutGroups()), Connection::PARAM_INT_ARRAY)))->orderBy('sc_group')->addOrderBy('sorting')->execute();
     while ($row = $result->fetch()) {
         $shortcut = ['raw' => $row];
         list($row['module_name'], $row['M_module_name']) = explode('|', $row['module_name']);
         $queryParts = parse_url($row['url']);
         $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], 1);
         if ($row['module_name'] === 'xMOD_alt_doc.php' && is_array($queryParameters['edit'])) {
             $shortcut['table'] = key($queryParameters['edit']);
             $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
             if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'edit') {
                 $shortcut['type'] = 'edit';
             } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'new') {
                 $shortcut['type'] = 'new';
             }
             if (substr($shortcut['recordid'], -1) === ',') {
                 $shortcut['recordid'] = substr($shortcut['recordid'], 0, -1);
             }
         } else {
             $shortcut['type'] = 'other';
         }
         // Check for module access
         $moduleName = $row['M_module_name'] ?: $row['module_name'];
         // Check if the user has access to this module
         if (!is_array($this->moduleLoader->checkMod($moduleName))) {
             continue;
         }
         $pageId = $this->getLinkedPageId($row['url']);
         if (!$backendUser->isAdmin()) {
             if (MathUtility::canBeInterpretedAsInteger($pageId)) {
                 // Check for webmount access
                 if ($backendUser->isInWebMount($pageId) === null) {
                     continue;
                 }
                 // Check for record access
                 $pageRow = BackendUtility::getRecord('pages', $pageId);
                 if ($pageRow === null) {
                     continue;
                 }
                 if (!$backendUser->doesUserHaveAccess($pageRow, $perms = 1)) {
                     continue;
                 }
             }
         }
         $moduleParts = explode('_', $moduleName);
         $shortcutGroup = (int) $row['sc_group'];
         if ($shortcutGroup && $lastGroup !== $shortcutGroup && $shortcutGroup !== self::SUPERGLOBAL_GROUP) {
             $shortcut['groupLabel'] = $this->getShortcutGroupLabel($shortcutGroup);
         }
         $lastGroup = $shortcutGroup;
         if ($row['description']) {
             $shortcut['label'] = $row['description'];
         } else {
             $shortcut['label'] = GeneralUtility::fixed_lgd_cs(rawurldecode($queryParts['query']), 150);
         }
         $shortcut['group'] = $shortcutGroup;
         $shortcut['icon'] = $this->getShortcutIcon($row, $shortcut);
         $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcut['label'], $row['module_name'], $row['M_module_name']);
         $shortcut['action'] = 'jump(' . GeneralUtility::quoteJSvalue($this->getTokenUrl($row['url'])) . ',' . GeneralUtility::quoteJSvalue($moduleName) . ',' . GeneralUtility::quoteJSvalue($moduleParts[0]) . ', ' . (int) $pageId . ');';
         $shortcuts[] = $shortcut;
     }
     return $shortcuts;
 }
 /**
  * Retrieves the shortcuts for the current user
  *
  * @return array Array of shortcuts
  */
 protected function initShortcuts()
 {
     $databaseConnection = $this->getDatabaseConnection();
     $globalGroupIdList = implode(',', array_keys($this->getGlobalShortcutGroups()));
     $backendUser = $this->getBackendUser();
     $res = $databaseConnection->exec_SELECTquery('*', 'sys_be_shortcuts', '(userid = ' . (int) $backendUser->user['uid'] . ' AND sc_group>=0) OR sc_group IN (' . $globalGroupIdList . ')', '', 'sc_group,sorting');
     // Traverse shortcuts
     $lastGroup = 0;
     $shortcuts = array();
     while ($row = $databaseConnection->sql_fetch_assoc($res)) {
         $shortcut = array('raw' => $row);
         list($row['module_name'], $row['M_module_name']) = explode('|', $row['module_name']);
         $queryParts = parse_url($row['url']);
         $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], 1);
         if ($row['module_name'] === 'xMOD_alt_doc.php' && is_array($queryParameters['edit'])) {
             $shortcut['table'] = key($queryParameters['edit']);
             $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
             if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'edit') {
                 $shortcut['type'] = 'edit';
             } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'new') {
                 $shortcut['type'] = 'new';
             }
             if (substr($shortcut['recordid'], -1) === ',') {
                 $shortcut['recordid'] = substr($shortcut['recordid'], 0, -1);
             }
         } else {
             $shortcut['type'] = 'other';
         }
         // Check for module access
         $moduleName = $row['M_module_name'] ?: $row['module_name'];
         // Check if the user has access to this module
         if (!is_array($this->moduleLoader->checkMod($moduleName))) {
             continue;
         }
         if (!$backendUser->isAdmin()) {
             $pageId = $this->getLinkedPageId($row['url']);
             if (MathUtility::canBeInterpretedAsInteger($pageId)) {
                 // Check for webmount access
                 if (!$backendUser->isInWebMount($pageId)) {
                     continue;
                 }
                 // Check for record access
                 $pageRow = BackendUtility::getRecord('pages', $pageId);
                 if (!$backendUser->doesUserHaveAccess($pageRow, $perms = 1)) {
                     continue;
                 }
             }
         }
         $moduleParts = explode('_', $moduleName);
         $shortcutGroup = (int) $row['sc_group'];
         if ($shortcutGroup && $lastGroup !== $shortcutGroup && $shortcutGroup !== self::SUPERGLOBAL_GROUP) {
             $shortcut['groupLabel'] = $this->getShortcutGroupLabel($shortcutGroup);
         }
         $lastGroup = $shortcutGroup;
         if ($row['description']) {
             $shortcut['label'] = $row['description'];
         } else {
             $shortcut['label'] = GeneralUtility::fixed_lgd_cs(rawurldecode($queryParts['query']), 150);
         }
         $shortcut['group'] = $shortcutGroup;
         $shortcut['icon'] = $this->getShortcutIcon($row, $shortcut);
         $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcut['label'], $row['module_name'], $row['M_module_name']);
         $shortcut['action'] = 'jump(' . GeneralUtility::quoteJSvalue($this->getTokenUrl($row['url'])) . ',' . GeneralUtility::quoteJSvalue($moduleName) . ',' . GeneralUtility::quoteJSvalue($moduleParts[0]) . ', ' . (int) $pageId . ');';
         $shortcuts[] = $shortcut;
     }
     return $shortcuts;
 }