| Conditions | 40 |
| Paths | > 20000 |
| Total Lines | 162 |
| Code Lines | 114 |
| Lines | 53 |
| Ratio | 32.72 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 55 | public function makeImageMap($conf) |
||
| 56 | { |
||
| 57 | if (!is_array($conf)) { |
||
| 58 | $conf = []; |
||
| 59 | } |
||
| 60 | if (is_array($this->mconf['main.'])) { |
||
| 61 | $gifCreator = GeneralUtility::makeInstance(GifBuilder::class); |
||
| 62 | $gifCreator->init(); |
||
| 63 | $itemsConf = $conf; |
||
| 64 | $conf = $this->mconf['main.']; |
||
| 65 | if (is_array($conf)) { |
||
| 66 | $sKeyArray = ArrayUtility::filterAndSortByNumericKeys($conf); |
||
| 67 | $gifObjCount = (int)end($sKeyArray); |
||
| 68 | // Now we add graphical objects to the gifbuilder-setup |
||
| 69 | $waArr = []; |
||
| 70 | foreach ($itemsConf as $key => $val) { |
||
| 71 | if (is_array($val)) { |
||
| 72 | $gifObjCount++; |
||
| 73 | $waArr[$key]['free'] = $gifObjCount; |
||
| 74 | $sKeyArray = ArrayUtility::filterAndSortByNumericKeys($val); |
||
| 75 | foreach ($sKeyArray as $theKey) { |
||
| 76 | $theValue = $val[$theKey]; |
||
| 77 | if ((int)$theKey && ($theValArr = $val[$theKey . '.'])) { |
||
| 78 | $cObjData = $this->menuArr[$key] ?: []; |
||
| 79 | $gifObjCount++; |
||
| 80 | if ($theValue === 'TEXT') { |
||
| 81 | $waArr[$key]['textNum'] = $gifObjCount; |
||
| 82 | $gifCreator->data = $cObjData; |
||
| 83 | $theValArr = $gifCreator->checkTextObj($theValArr); |
||
| 84 | // if this is not done it seems that imageMaps will be rendered wrong!! |
||
| 85 | unset($theValArr['text.']); |
||
| 86 | // check links |
||
| 87 | $LD = $this->menuTypoLink($this->menuArr[$key], $this->mconf['target'], '', '', [], '', $this->mconf['forceTypeValue']); |
||
| 88 | // If access restricted pages should be shown in menus, change the link of such pages to link to a redirection page: |
||
| 89 | $this->changeLinksForAccessRestrictedPages($LD, $this->menuArr[$key], $this->mconf['target'], $this->mconf['forceTypeValue']); |
||
| 90 | // Overriding URL / Target if set to do so: |
||
| 91 | View Code Duplication | if ($this->menuArr[$key]['_OVERRIDE_HREF']) { |
|
| 92 | $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF']; |
||
| 93 | if ($this->menuArr[$key]['_OVERRIDE_TARGET']) { |
||
| 94 | $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET']; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | // Setting target/url for Image Map: |
||
| 98 | if ($theValArr['imgMap.']['url'] === '') { |
||
| 99 | $theValArr['imgMap.']['url'] = $LD['totalURL']; |
||
| 100 | } |
||
| 101 | if ($theValArr['imgMap.']['target'] === '') { |
||
| 102 | $theValArr['imgMap.']['target'] = $LD['target']; |
||
| 103 | } |
||
| 104 | View Code Duplication | if (is_array($theValArr['imgMap.']['altText.'])) { |
|
| 105 | $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); |
||
| 106 | $cObj->start($cObjData, 'pages'); |
||
| 107 | if (isset($theValArr['imgMap.']['altText.'])) { |
||
| 108 | $theValArr['imgMap.']['altText'] = $cObj->stdWrap($theValArr['imgMap.']['altText'], $theValArr['imgMap.']['altText.']); |
||
| 109 | } |
||
| 110 | unset($theValArr['imgMap.']['altText.']); |
||
| 111 | } |
||
| 112 | View Code Duplication | if (is_array($theValArr['imgMap.']['titleText.'])) { |
|
| 113 | $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); |
||
| 114 | $cObj->start($cObjData, 'pages'); |
||
| 115 | if (isset($theValArr['imgMap.']['titleText.'])) { |
||
| 116 | $theValArr['imgMap.']['titleText'] = $cObj->stdWrap($theValArr['imgMap.']['titleText'], $theValArr['imgMap.']['titleText.']); |
||
| 117 | } |
||
| 118 | unset($theValArr['imgMap.']['titleText.']); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | // 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!! |
||
| 122 | if ($theValue === 'IMAGE') { |
||
| 123 | View Code Duplication | if ($theValArr['file'] === 'GIFBUILDER') { |
|
| 124 | $temp_sKeyArray = ArrayUtility::filterAndSortByNumericKeys($theValArr['file.']); |
||
| 125 | foreach ($temp_sKeyArray as $temp_theKey) { |
||
| 126 | if ($theValArr['mask.'][$temp_theKey] === 'TEXT') { |
||
| 127 | $gifCreator->data = $this->menuArr[$key] ?: []; |
||
| 128 | $theValArr['mask.'][$temp_theKey . '.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey . '.']); |
||
| 129 | // If this is not done it seems that imageMaps will be rendered wrong!! |
||
| 130 | unset($theValArr['mask.'][$temp_theKey . '.']['text.']); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } |
||
| 134 | View Code Duplication | if ($theValArr['mask'] === 'GIFBUILDER') { |
|
| 135 | $temp_sKeyArray = ArrayUtility::filterAndSortByNumericKeys($theValArr['mask.']); |
||
| 136 | foreach ($temp_sKeyArray as $temp_theKey) { |
||
| 137 | if ($theValArr['mask.'][$temp_theKey] === 'TEXT') { |
||
| 138 | $gifCreator->data = $this->menuArr[$key] ?: []; |
||
| 139 | $theValArr['mask.'][$temp_theKey . '.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey . '.']); |
||
| 140 | // if this is not done it seems that imageMaps will be rendered wrong!! |
||
| 141 | unset($theValArr['mask.'][$temp_theKey . '.']['text.']); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | // Checks if disabled is set... |
||
| 147 | $setObjFlag = 1; |
||
| 148 | View Code Duplication | if ($theValArr['if.']) { |
|
| 149 | /** @var ContentObjectRenderer $cObj */ |
||
| 150 | $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); |
||
| 151 | $cObj->start($cObjData, 'pages'); |
||
| 152 | if (!empty($theValArr['if.']) && !$cObj->checkIf($theValArr['if.'])) { |
||
| 153 | $setObjFlag = 0; |
||
| 154 | } |
||
| 155 | unset($theValArr['if.']); |
||
| 156 | } |
||
| 157 | // Set the object! |
||
| 158 | if ($setObjFlag) { |
||
| 159 | $conf[$gifObjCount] = $theValue; |
||
| 160 | $conf[$gifObjCount . '.'] = $theValArr; |
||
| 161 | } |
||
| 162 | } |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | $gifCreator->start($conf, $this->getTypoScriptFrontendController()->page); |
||
| 167 | // calculations |
||
| 168 | $dConf = []; |
||
| 169 | foreach ($waArr as $key => $val) { |
||
| 170 | if ($dConf[$key] = $itemsConf[$key]['distrib']) { |
||
| 171 | $textBB = $gifCreator->objBB[$val['textNum']]; |
||
| 172 | $dConf[$key] = str_replace( |
||
| 173 | ['textX', 'textY'], |
||
| 174 | [$textBB[0], $textBB[1]], |
||
| 175 | $dConf[$key] |
||
| 176 | ); |
||
| 177 | $dConf[$key] = GeneralUtility::intExplode(',', $gifCreator->calcOffset($dConf[$key])); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | $workArea = GeneralUtility::intExplode(',', $gifCreator->calcOffset($this->mconf['dWorkArea'])); |
||
| 181 | foreach ($waArr as $key => $val) { |
||
| 182 | $index = $val['free']; |
||
| 183 | $gifCreator->setup[$index] = 'WORKAREA'; |
||
| 184 | $workArea[2] = $dConf[$key][2] ?: $dConf[$key][0]; |
||
| 185 | $workArea[3] = $dConf[$key][3] ?: $dConf[$key][1]; |
||
| 186 | $gifCreator->setup[$index . '.']['set'] = implode(',', $workArea); |
||
| 187 | $workArea[0] += $dConf[$key][0]; |
||
| 188 | $workArea[1] += $dConf[$key][1]; |
||
| 189 | } |
||
| 190 | if ($this->mconf['debugRenumberedObject']) { |
||
| 191 | echo '<h3>Renumbered GIFBUILDER object:</h3>'; |
||
| 192 | debug($gifCreator->setup); |
||
| 193 | } |
||
| 194 | GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/menu/'); |
||
| 195 | $gifFileName = $gifCreator->fileName('assets/menu/'); |
||
| 196 | // Gets the ImageMap from the cache... |
||
| 197 | $cache = $this->getCache(); |
||
| 198 | $imgHash = md5($gifFileName); |
||
| 199 | $imgMap = $cache->get($imgHash); |
||
| 200 | // File exists |
||
| 201 | if ($imgMap && file_exists($gifFileName)) { |
||
| 202 | $info = @getimagesize($gifFileName); |
||
| 203 | $w = $info[0]; |
||
| 204 | $h = $info[1]; |
||
| 205 | } else { |
||
| 206 | // file is generated |
||
| 207 | $gifCreator->make(); |
||
| 208 | $w = $gifCreator->w; |
||
| 209 | $h = $gifCreator->h; |
||
| 210 | $gifCreator->output($gifFileName); |
||
| 211 | $gifCreator->destroy(); |
||
| 212 | $imgMap = $gifCreator->map; |
||
| 213 | $cache->set($imgHash, $imgMap, ['ident_MENUIMAGEMAP'], 0); |
||
| 214 | } |
||
| 215 | $imgMap .= $this->mconf['imgMapExtras']; |
||
| 216 | $this->result = ['output_file' => $gifFileName, 'output_w' => $w, 'output_h' => $h, 'imgMap' => $imgMap]; |
||
| 217 | } |
||
| 245 |