[BUGFIX] Usage of undefined variables in ShortcutToolbarItem 41/27641/3
authorTim Lochmueller <tim@fruit-lab.de>
Sun, 16 Feb 2014 12:08:04 +0000 (13:08 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 17 Feb 2014 14:09:24 +0000 (15:09 +0100)
Fix a undefined variable and a wrong variable assignment in the
ShortcurtToolbarItem.

Resolves: #55998
Releases: 6.2, 6.1, 6.0
Change-Id: I0f0ebcc846a9aa56edd05e384d62aad8f0a5b05b
Reviewed-on: https://review.typo3.org/27641
Reviewed-by: Markus Klein
Reviewed-by: Stefano Kowalke
Tested-by: Markus Klein
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/backend/Classes/Toolbar/ClearCacheToolbarItem.php
typo3/sysext/backend/Classes/Toolbar/LiveSearchToolbarItem.php
typo3/sysext/backend/Classes/Toolbar/ShortcutToolbarItem.php

index dd4c336..a38d172 100644 (file)
@@ -51,7 +51,7 @@ class ClearCacheToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHoo
        /**
         * Reference back to the backend object
         *
-        * @var         TYPO3backend
+        * @var \TYPO3\CMS\Backend\Controller\BackendController
         */
        protected $backendReference;
 
index c802d6e..c407da1 100644 (file)
@@ -38,7 +38,7 @@ class LiveSearchToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHoo
        /**
         * Reference back to the backend object
         *
-        * @var         TYPO3backend
+        * @var \TYPO3\CMS\Backend\Controller\BackendController
         */
        protected $backendReference;
 
index 03370b3..7bf1f80 100644 (file)
@@ -39,7 +39,25 @@ use TYPO3\CMS\Core\Utility\MathUtility;
  */
 class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {
 
-       protected $shortcutGroups;
+       const SUPERGLOBAL_GROUP = -100;
+
+       /**
+        * @var string
+        * @todo define visibility
+        */
+       public $perms_clause;
+
+       /**
+        * @var string
+        * @todo define visibility
+        */
+       public $backPath;
+
+       /**
+        * @var array
+        * @todo define visibility
+        */
+       public $fieldArray;
 
        /**
         * All available shortcuts
@@ -49,6 +67,11 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
        protected $shortcuts;
 
        /**
+        * @var array
+        */
+       protected $shortcutGroups;
+
+       /**
         * Labels of all groups.
         * If value is 1, the system will try to find a label in the locallang array.
         *
@@ -59,7 +82,7 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
        /**
         * Reference back to the backend object
         *
-        * @var         TYPO3backend
+        * @var \TYPO3\CMS\Backend\Controller\BackendController
         */
        protected $backendReference;
 
@@ -222,36 +245,43 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
         * @return array Array of shortcuts
         */
        protected function initShortcuts() {
-               $shortcuts = array();
-               $globalGroups = $this->getGlobalShortcutGroups();
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_be_shortcuts', '((userid = ' . $GLOBALS['BE_USER']->user['uid'] . ' AND sc_group>=0) OR sc_group IN (' . implode(',', array_keys($globalGroups)) . '))', '', 'sc_group,sorting');
+               $globalGroupIdList = implode(',', array_keys($this->getGlobalShortcutGroups()));
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                       '*',
+                       'sys_be_shortcuts',
+                       '(userid = ' . (int)$GLOBALS['BE_USER']->user['uid'] . ' AND sc_group>=0) OR sc_group IN (' . $globalGroupIdList . ')',
+                       '',
+                       'sc_group,sorting'
+               );
                // Traverse shortcuts
+               $lastGroup = 0;
+               $shortcuts = array();
                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $shortcut = array('raw' => $row);
-                       $moduleParts = explode('|', $row['module_name']);
-                       $row['module_name'] = $moduleParts[0];
-                       $row['M_module_name'] = $moduleParts[1];
-                       $moduleParts = explode('_', $row['M_module_name'] ?: $row['module_name']);
+
+                       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'])) {
+                       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') {
+                               if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'edit') {
                                        $shortcut['type'] = 'edit';
-                               } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
+                               } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'new') {
                                        $shortcut['type'] = 'new';
                                }
-                               if (substr($shortcut['recordid'], -1) == ',') {
+                               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'];
                        $pageId = $this->getLinkedPageId($row['url']);
                        if (!$GLOBALS['BE_USER']->isAdmin()) {
-                               if (!isset($GLOBALS['LANG']->moduleLabels['tabs_images'][(implode('_', $moduleParts) . '_tab')])) {
+                               if (!isset($GLOBALS['LANG']->moduleLabels['tabs_images'][$moduleName . '_tab'])) {
                                        // Nice hack to check if the user has access to this module
                                        // - otherwise the translation label would not have been loaded :-)
                                        continue;
@@ -268,10 +298,13 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
                                        }
                                }
                        }
-                       $shortcutGroup = $row['sc_group'];
-                       if ($shortcutGroup && (string)$lastGroup !== (string)$shortcutGroup && $shortcutGroup != -100) {
+                       $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 {
@@ -279,9 +312,9 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
                        }
                        $shortcut['group'] = $shortcutGroup;
                        $shortcut['icon'] = $this->getShortcutIcon($row, $shortcut);
-                       $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcutLabel, $row['module_name'], $row['M_module_name']);
-                       $shortcut['action'] = 'jump(unescape(\'' . rawurlencode($row['url']) . '\'),\'' . implode('_', $moduleParts) . '\',\'' . $moduleParts[0] . '\', ' . (int)$pageId . ');';
-                       $lastGroup = $row['sc_group'];
+                       $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcut['label'], $row['module_name'], $row['M_module_name']);
+                       $shortcut['action'] = 'jump(unescape(\'' . rawurlencode($row['url']) . '\'),\'' . $moduleName . '\',\'' . $moduleParts[0] . '\', ' . (int)$pageId . ');';
+
                        $shortcuts[] = $shortcut;
                }
                return $shortcuts;
@@ -321,14 +354,11 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
        }
 
        /**
-        * Gets the available shortcut groups from default gropups, user TSConfig,
-        * and global groups
+        * Gets the available shortcut groups from default groups, user TSConfig, and global groups
         *
-        * @param array $params Array of parameters from the AJAX interface, currently unused
-        * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
         * @return array
         */
-       protected function initShortcutGroups($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
+       protected function initShortcutGroups() {
                // Groups from TSConfig
                $bookmarkGroups = $GLOBALS['BE_USER']->getTSConfigProp('options.bookmarkGroups');
                if (is_array($bookmarkGroups) && count($bookmarkGroups)) {
@@ -348,9 +378,10 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
                        }
                }
                // Group -100 is kind of superglobal and can't be changed.
-               $this->shortcutGroups[-100] = 1;
+               $this->shortcutGroups[self::SUPERGLOBAL_GROUP] = 1;
                // Add labels
                foreach ($this->shortcutGroups as $groupId => $groupLabel) {
+                       $groupId = (int)$groupId;
                        $label = $groupLabel;
                        if ($groupLabel == '1') {
                                $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmark_group_' . abs($groupId), TRUE);
@@ -362,7 +393,7 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
                        if ($groupId < 0) {
                                // Global group
                                $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmark_global', TRUE) . ': ' . (!empty($label) ? $label : abs($groupId));
-                               if ($groupId == -100) {
+                               if ($groupId === self::SUPERGLOBAL_GROUP) {
                                        $label = $GLOBALS['LANG']->getLL('bookmark_global', 1) . ': ' . $GLOBALS['LANG']->getLL('bookmark_all', 1);
                                }
                        }
@@ -523,11 +554,7 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
         * @return string The shortcut group label, can be an empty string if no group was found for the id
         */
        protected function getShortcutGroupLabel($groupId) {
-               $label = '';
-               if ($this->shortcutGroups[$groupId]) {
-                       $label = $this->shortcutGroups[$groupId];
-               }
-               return $label;
+               return isset($this->shortcutGroups[$groupId]) ? $this->shortcutGroups[$groupId] : '';
        }
 
        /**
@@ -570,6 +597,7 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
                        case 'xMOD_alt_doc.php':
                                $table = $shortcut['table'];
                                $recordid = $shortcut['recordid'];
+                               $icon = '';
                                if ($shortcut['type'] == 'edit') {
                                        // Creating the list of fields to include in the SQL query:
                                        $selectFields = $this->fieldArray;
@@ -596,7 +624,7 @@ class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookI
                                        }
                                        // Unique list!
                                        $selectFields = array_unique($selectFields);
-                                       $permissionClause = $table == 'pages' && $this->perms_clause ? ' AND ' . $this->perms_clause : '';
+                                       $permissionClause = $table === 'pages' && $this->perms_clause ? ' AND ' . $this->perms_clause : '';
                                        $sqlQueryParts = array(
                                                'SELECT' => implode(',', $selectFields),
                                                'FROM' => $table,