[TASK] Speed up menu objects 27/38127/3
authorWouter Wolters <typo3@wouterwolters.nl>
Tue, 24 Mar 2015 17:57:37 +0000 (18:57 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Wed, 25 Mar 2015 02:13:23 +0000 (03:13 +0100)
* use strict checks
* remove count() were possible

Resolves: #65984
Releases: master
Change-Id: I3434a201d5db3c725c7923b658f27cc413335288
Reviewed-on: http://review.typo3.org/38127
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
typo3/sysext/frontend/Classes/ContentObject/Menu/CategoryMenuUtility.php
typo3/sysext/frontend/Classes/ContentObject/Menu/GraphicalMenuContentObject.php
typo3/sysext/frontend/Classes/ContentObject/Menu/ImageMenuContentObject.php
typo3/sysext/frontend/Classes/ContentObject/Menu/JavaScriptMenuContentObject.php

index 0943c87..b1c94f8 100644 (file)
@@ -337,7 +337,7 @@ abstract class AbstractMenuContentObject {
                                        }
                                        // Add to register:
                                        $this->rL_uidRegister[] = 'ITEM:' . $v_rl['uid'] .
-                                               (count($rl_MParray)
+                                               (!empty($rl_MParray)
                                                        ? ':' . implode(',', $rl_MParray)
                                                        : ''
                                                );
@@ -350,12 +350,12 @@ abstract class AbstractMenuContentObject {
                        // Set $directoryLevel so the following evalution of the nextActive will not return
                        // an invalid value if .special=directory was set
                        $directoryLevel = 0;
-                       if ($this->conf['special'] == 'directory') {
+                       if ($this->conf['special'] === 'directory') {
                                $value = isset($this->conf['special.']['value.']) ? $this->parent_cObj->stdWrap(
                                        $this->conf['special.']['value'],
                                        $this->conf['special.']['value.']
                                ) : $this->conf['special.']['value'];
-                               if ($value == '') {
+                               if ($value === '') {
                                        $value = $tsfe->page['uid'];
                                }
                                $directoryLevel = (int)$tsfe->tmpl->getRootlineLevel($value);
@@ -366,7 +366,7 @@ abstract class AbstractMenuContentObject {
                        $currentLevel = $startLevel + $this->menuNumber;
                        if (is_array($this->tmpl->rootLine[$currentLevel])) {
                                $nextMParray = $this->MP_array;
-                               if (!count($nextMParray) && !$this->tmpl->rootLine[$currentLevel]['_MOUNT_OL'] && $currentLevel > 0) {
+                               if (empty($nextMParray) && !$this->tmpl->rootLine[$currentLevel]['_MOUNT_OL'] && $currentLevel > 0) {
                                        // Make sure to slide-down any mount point information (_MP_PARAM) to children records in the rootline
                                        // otherwise automatic expansion will not work
                                        $parentRecord = $this->tmpl->rootLine[$currentLevel - 1];
@@ -379,7 +379,7 @@ abstract class AbstractMenuContentObject {
                                        $nextMParray[] = $this->tmpl->rootLine[$currentLevel]['_MP_PARAM'];
                                }
                                $this->nextActive = $this->tmpl->rootLine[$currentLevel]['uid'] .
-                                       (count($nextMParray)
+                                       (!empty($nextMParray)
                                                ? ':' . implode(',', $nextMParray)
                                                : ''
                                        );
@@ -650,9 +650,9 @@ abstract class AbstractMenuContentObject {
                        }
                        // Checking if the "disabled" state should be set.
                        if (GeneralUtility::hideIfNotTranslated($tsfe->page['l18n_cfg']) && $sUid &&
-                               !count($lRecs) || $tsfe->page['l18n_cfg'] & 1 &&
-                               (!$sUid || !count($lRecs)) ||
-                               !$this->conf['special.']['normalWhenNoLanguage'] && $sUid && !count($lRecs)
+                               empty($lRecs) || $tsfe->page['l18n_cfg'] & 1 &&
+                               (!$sUid || empty($lRecs)) ||
+                               !$this->conf['special.']['normalWhenNoLanguage'] && $sUid && empty($lRecs)
                        ) {
                                $iState = $tsfe->sys_language_uid == $sUid ? 'USERDEF2' : 'USERDEF1';
                        } else {
@@ -721,7 +721,7 @@ abstract class AbstractMenuContentObject {
                                                // Using "getPage" is OK since we need the check for enableFields
                                                // AND for type 2 of mount pids we DO require a doktype < 200!
                                                $mp_row = $this->sys_page->getPage($mount_info['mount_pid']);
-                                               if (count($mp_row)) {
+                                               if (!empty($mp_row)) {
                                                        $row = $mp_row;
                                                        $row['_MP_PARAM'] = $mount_info['MPvar'];
                                                } else {
@@ -769,7 +769,7 @@ abstract class AbstractMenuContentObject {
                                // Using "getPage" is OK since we need the check for enableFields
                                // AND for type 2 of mount pids we DO require a doktype < 200!
                                $mp_row = $this->sys_page->getPage($mount_info['mount_pid']);
-                               if (count($mp_row)) {
+                               if (!empty($mp_row)) {
                                        $row = $mp_row;
                                        $row['_MP_PARAM'] = $mount_info['MPvar'];
                                        // Overlays should already have their full MPvars calculated
@@ -842,7 +842,6 @@ abstract class AbstractMenuContentObject {
                                $sortField = 'starttime';
                                break;
                        case 'lastUpdated':
-
                        case 'manual':
                                $sortField = 'lastUpdated';
                                break;
@@ -875,6 +874,7 @@ abstract class AbstractMenuContentObject {
                                $menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
                        }
                }
+               $this->getDatabaseConnection()->sql_free_result($res);
                return $menuItems;
        }
 
@@ -908,7 +908,6 @@ abstract class AbstractMenuContentObject {
                                $sortField = 'starttime';
                                break;
                        case 'lastUpdated':
-
                        case 'manual':
                                $sortField = 'lastUpdated';
                                break;
@@ -970,6 +969,7 @@ abstract class AbstractMenuContentObject {
                                        $menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
                                }
                        }
+                       $this->getDatabaseConnection()->sql_free_result($res);
                }
                return $menuItems;
        }
@@ -1004,7 +1004,7 @@ abstract class AbstractMenuContentObject {
                        if ($k_rl >= $beginKey && $k_rl <= $endKey) {
                                $temp_key = $k_rl;
                                $menuItems[$temp_key] = $this->sys_page->getPage($v_rl['uid']);
-                               if (count($menuItems[$temp_key])) {
+                               if (!empty($menuItems[$temp_key])) {
                                        // If there are no specific target for the page, put the level specific target on.
                                        if (!$menuItems[$temp_key]['target']) {
                                                $menuItems[$temp_key]['target'] = $this->conf['special.']['targets.'][$k_rl];
@@ -1089,7 +1089,7 @@ abstract class AbstractMenuContentObject {
                                foreach ($prevnextsection_menu as $k_b => $v_b) {
                                        if ($nextActive) {
                                                $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($v_b['uid'], '*', $sortingField, $additionalWhere));
-                                               if (count($sectionRec_temp)) {
+                                               if (!empty($sectionRec_temp)) {
                                                        $recArr['nextsection'] = reset($sectionRec_temp);
                                                        $recArr['nextsection_last'] = end($sectionRec_temp);
                                                        $nextActive = 0;
@@ -1149,7 +1149,7 @@ abstract class AbstractMenuContentObject {
         */
        protected function analyzeCacheHashRequirements($queryString) {
                $parameters = GeneralUtility::explodeUrl2Array($queryString);
-               if (count($parameters) > 0) {
+               if (!empty($parameters)) {
                        /** @var CacheHashCalculator $cacheHashCalculator */
                        $cacheHashCalculator = GeneralUtility::makeInstance(CacheHashCalculator::class);
                        $cHashParameters = $cacheHashCalculator->getRelevantParameters($queryString);
@@ -1218,7 +1218,7 @@ abstract class AbstractMenuContentObject {
                                                $languageUid = (int)$tsfe->config['config']['sys_language_uid'];
                                                if ($languageUid && ($this->conf['protectLvar'] == 'all' || GeneralUtility::hideIfNotTranslated($data['l18n_cfg']))) {
                                                        $olRec = $tsfe->sys_page->getPageOverlay($data['uid'], $languageUid);
-                                                       if (!count($olRec)) {
+                                                       if (empty($olRec)) {
                                                                // If no pages_language_overlay record then page can NOT be accessed in
                                                                // the language pointed to by "&L" and therefore we protect the link by setting "&L=0"
                                                                $data['_ADD_GETVARS'] .= '&L=0';
@@ -1756,7 +1756,7 @@ abstract class AbstractMenuContentObject {
         */
        public function isNext($uid, $MPvar = '') {
                // Check for always active PIDs:
-               if (count($this->alwaysActivePIDlist) && in_array($uid, $this->alwaysActivePIDlist)) {
+               if (!empty($this->alwaysActivePIDlist) && in_array((int)$uid, $this->alwaysActivePIDlist, TRUE)) {
                        return TRUE;
                }
                $testUid = $uid . ($MPvar ? ':' . $MPvar : '');
@@ -1776,11 +1776,11 @@ abstract class AbstractMenuContentObject {
         */
        public function isActive($uid, $MPvar = '') {
                // Check for always active PIDs:
-               if (count($this->alwaysActivePIDlist) && in_array($uid, $this->alwaysActivePIDlist)) {
+               if (!empty($this->alwaysActivePIDlist) && in_array((int)$uid, $this->alwaysActivePIDlist, TRUE)) {
                        return TRUE;
                }
                $testUid = $uid . ($MPvar ? ':' . $MPvar : '');
-               if ($uid && in_array('ITEM:' . $testUid, $this->rL_uidRegister)) {
+               if ($uid && in_array('ITEM:' . $testUid, $this->rL_uidRegister, TRUE)) {
                        return TRUE;
                }
                return FALSE;
index 7ebd244..f553d91 100644 (file)
@@ -112,7 +112,7 @@ class CategoryMenuUtility {
                                // Make sure the order property is either "asc" or "desc" (default is "asc")
                                if (!empty($order)) {
                                        $order = strtolower($order);
-                                       if ($order != 'desc') {
+                                       if ($order !== 'desc') {
                                                $order = 'asc';
                                        }
                                }
@@ -124,7 +124,7 @@ class CategoryMenuUtility {
                                        )
                                );
                                // If the sort order is descending, reverse the sorted array
-                               if ($order == 'desc') {
+                               if ($order === 'desc') {
                                        $pages = array_reverse($pages, TRUE);
                                }
                        }
index de5c09c..330ec2e 100644 (file)
@@ -124,7 +124,7 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject {
                foreach ($conf as $key => $val) {
                        $this->getTypoScriptFrontendController()->register['count_HMENU_MENUOBJ']++;
                        $this->getTypoScriptFrontendController()->register['count_MENUOBJ']++;
-                       if ($items == $c + 1 && $minDim) {
+                       if ($items === $c + 1 && $minDim) {
                                $Lobjs = $this->mconf['removeObjectsOfDummy'];
                                if ($Lobjs) {
                                        $Lobjs = GeneralUtility::intExplode(',', $Lobjs);
@@ -156,7 +156,7 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject {
                                $gifCreator->init();
                                $gifCreator->start($val, $this->menuArr[$key]);
                                // If useLargestItemH/W is specified
-                               if (count($totalWH) && ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'])) {
+                               if (!empty($totalWH) && ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'])) {
                                        $tempXY = explode(',', $gifCreator->setup['XY']);
                                        if ($this->mconf['useLargestItemX']) {
                                                $tempXY[0] = max($totalWH['W']);
@@ -171,7 +171,7 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject {
                                        $gifCreator->start($val, $this->menuArr[$key]);
                                }
                                // If distributeH/W is specified
-                               if (count($totalWH) && ($this->mconf['distributeX'] || $this->mconf['distributeY'])) {
+                               if (!empty($totalWH) && ($this->mconf['distributeX'] || $this->mconf['distributeY'])) {
                                        $tempXY = explode(',', $gifCreator->setup['XY']);
                                        if ($this->mconf['distributeX']) {
                                                $diff = $this->mconf['distributeX'] - $totalWH['W_total'] - $distributeAccu['W'];
@@ -284,6 +284,7 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject {
         * @see makeGifs()
         */
        public function findLargestDims($conf, $items, $Hobjs, $Wobjs, $minDim, $maxDim) {
+               $items = (int)$items;
                $totalWH = array(
                        'W' => array(),
                        'H' => array(),
@@ -296,7 +297,7 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject {
                $maxFlag = 0;
                foreach ($conf as $key => $val) {
                        // SAME CODE AS makeGifs()! BEGIN
-                       if ($items == $c + 1 && $minDim) {
+                       if ($items === $c + 1 && $minDim) {
                                $Lobjs = $this->mconf['removeObjectsOfDummy'];
                                if ($Lobjs) {
                                        $Lobjs = GeneralUtility::intExplode(',', $Lobjs);
index 6a25c7a..6f44386 100644 (file)
@@ -80,7 +80,7 @@ class ImageMenuContentObject extends AbstractMenuContentObject {
                                                        if ((int)$theKey && ($theValArr = $val[$theKey . '.'])) {
                                                                $cObjData = $this->menuArr[$key] ?: array();
                                                                $gifObjCount++;
-                                                               if ($theValue == 'TEXT') {
+                                                               if ($theValue === 'TEXT') {
                                                                        $waArr[$key]['textNum'] = $gifObjCount;
                                                                        $gifCreator->data = $cObjData;
                                                                        $theValArr = $gifCreator->checkTextObj($theValArr);
@@ -98,10 +98,10 @@ class ImageMenuContentObject extends AbstractMenuContentObject {
                                                                                }
                                                                        }
                                                                        // Setting target/url for Image Map:
-                                                                       if ($theValArr['imgMap.']['url'] == '') {
+                                                                       if ($theValArr['imgMap.']['url'] === '') {
                                                                                $theValArr['imgMap.']['url'] = $LD['totalURL'];
                                                                        }
-                                                                       if ($theValArr['imgMap.']['target'] == '') {
+                                                                       if ($theValArr['imgMap.']['target'] === '') {
                                                                                $theValArr['imgMap.']['target'] = $LD['target'];
                                                                        }
                                                                        if (is_array($theValArr['imgMap.']['altText.'])) {
@@ -122,11 +122,11 @@ class ImageMenuContentObject extends AbstractMenuContentObject {
                                                                        }
                                                                }
                                                                // This code goes one level in if the object is an image. If 'file' and/or 'mask' appears to be GIFBUILDER-objects, they are both searched for TEXT objects, and if a textobj is found, it's checked with the currently loaded record!!
-                                                               if ($theValue == 'IMAGE') {
-                                                                       if ($theValArr['file'] == 'GIFBUILDER') {
+                                                               if ($theValue === 'IMAGE') {
+                                                                       if ($theValArr['file'] === 'GIFBUILDER') {
                                                                                $temp_sKeyArray = TemplateService::sortedKeyList($theValArr['file.']);
                                                                                foreach ($temp_sKeyArray as $temp_theKey) {
-                                                                                       if ($theValArr['mask.'][$temp_theKey] == 'TEXT') {
+                                                                                       if ($theValArr['mask.'][$temp_theKey] === 'TEXT') {
                                                                                                $gifCreator->data = $this->menuArr[$key] ?: array();
                                                                                                $theValArr['mask.'][$temp_theKey . '.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey . '.']);
                                                                                                // If this is not done it seems that imageMaps will be rendered wrong!!
@@ -134,10 +134,10 @@ class ImageMenuContentObject extends AbstractMenuContentObject {
                                                                                        }
                                                                                }
                                                                        }
-                                                                       if ($theValArr['mask'] == 'GIFBUILDER') {
+                                                                       if ($theValArr['mask'] === 'GIFBUILDER') {
                                                                                $temp_sKeyArray = TemplateService::sortedKeyList($theValArr['mask.']);
                                                                                foreach ($temp_sKeyArray as $temp_theKey) {
-                                                                                       if ($theValArr['mask.'][$temp_theKey] == 'TEXT') {
+                                                                                       if ($theValArr['mask.'][$temp_theKey] === 'TEXT') {
                                                                                                $gifCreator->data = $this->menuArr[$key] ?: array();
                                                                                                $theValArr['mask.'][$temp_theKey . '.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey . '.']);
                                                                                                // if this is not done it seems that imageMaps will be rendered wrong!!
index f85816b..206100b 100644 (file)
@@ -78,7 +78,7 @@ var ' . $this->JSVarName . $a . '=0;';
                        $formCode .= '<select name="selector' . $a . '" onchange="' . $this->JSMenuName . '.act(' . $a . ');"' . ($levelConf['additionalParams'] ? ' ' . $levelConf['additionalParams'] : '') . '>';
                        for ($b = 0; $b < $height; $b++) {
                                $formCode .= '<option value="0">';
-                               if ($b == 0) {
+                               if ($b === 0) {
                                        $formCode .= $lengthStr;
                                }
                                $formCode .= '</option>';
@@ -105,6 +105,7 @@ var ' . $this->JSVarName . $a . '=0;';
         * @access private
         */
        public function generate_level($levels, $count, $pid, $menuItemArray = '', $MP_array = array()) {
+               $count = (int)$count;
                $levelConf = $this->mconf[$count . '.'];
                // Translate PID to a mount page, if any:
                $mount_info = $this->sys_page->getMountPointInfo($pid);
@@ -117,7 +118,7 @@ var ' . $this->JSVarName . $a . '=0;';
                // Initializing variables:
                $var = $this->JSVarName;
                $menuName = $this->JSMenuName;
-               $parent = $count == 1 ? 0 : $var . ($count - 1);
+               $parent = $count === 1 ? 0 : $var . ($count - 1);
                $prev = 0;
                $c = 0;
                $codeLines = '';
@@ -160,7 +161,7 @@ var ' . $this->JSVarName . $a . '=0;';
                                        $first = !$c && $levelConf['showFirst'];
                                        // do it...
                                        if ($active || $first) {
-                                               if ($count == 1) {
+                                               if ($count === 1) {
                                                        $codeLines .= LF . $menuName . '.openID = ' . $var . $count . ';';
                                                } else {
                                                        $codeLines .= LF . $menuName . '.entry[' . $parent . '].openID = ' . $var . $count . ';';