‪TYPO3CMS  9.5
ImageMenuContentObject.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
30 {
31  public function ‪__construct()
32  {
33  trigger_error('IMGMENU and ImageMenuContentObject will be removed in TYPO3 v10.0, you should build accessible websites with TMENU/Text, and optional images on top, which can be achieved with TypoScript.', E_USER_DEPRECATED);
34  }
35 
42  public function ‪generate()
43  {
44  $NOconf = [];
45  $splitCount = count($this->menuArr);
46  if ($splitCount) {
47  list($NOconf) = $this->‪procesItemStates($splitCount);
48  }
49  if (!empty($this->mconf['debugItemConf'])) {
50  echo '<h3>$NOconf:</h3>';
51  ‪debug($NOconf);
52  }
53  $this->‪makeImageMap($NOconf);
54  }
55 
64  public function ‪makeImageMap(‪$conf)
65  {
66  if (!is_array(‪$conf)) {
67  ‪$conf = [];
68  }
69  if (is_array($this->mconf['main.'])) {
70  $gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
71  $itemsConf = ‪$conf;
72  ‪$conf = $this->mconf['main.'];
73  if (is_array(‪$conf)) {
75  $gifObjCount = (int)end($sKeyArray);
76  // Now we add graphical objects to the gifbuilder-setup
77  $waArr = [];
78  foreach ($itemsConf as $key => $val) {
79  if (is_array($val)) {
80  $gifObjCount++;
81  $waArr[$key]['free'] = $gifObjCount;
83  foreach ($sKeyArray as $theKey) {
84  $theValue = $val[$theKey];
85  if ((int)$theKey && ($theValArr = $val[$theKey . '.'])) {
86  $cObjData = $this->menuArr[$key] ?: [];
87  $gifObjCount++;
88  if ($theValue === 'TEXT') {
89  $waArr[$key]['textNum'] = $gifObjCount;
90  $gifCreator->data = $cObjData;
91  $theValArr = $gifCreator->checkTextObj($theValArr);
92  // if this is not done it seems that imageMaps will be rendered wrong!!
93  unset($theValArr['text.']);
94  // check links
95  $LD = $this->‪menuTypoLink($this->menuArr[$key], $this->mconf['target'], '', '', [], '', $this->mconf['forceTypeValue']);
96  // If access restricted pages should be shown in menus, change the link of such pages to link to a redirection page:
97  $this->‪changeLinksForAccessRestrictedPages($LD, $this->menuArr[$key], $this->mconf['target'], $this->mconf['forceTypeValue']);
98  // Overriding URL / Target if set to do so:
99  if ($this->menuArr[$key]['_OVERRIDE_HREF']) {
100  $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF'];
101  if ($this->menuArr[$key]['_OVERRIDE_TARGET']) {
102  $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET'];
103  }
104  }
105  // Setting target/url for Image Map:
106  if ($theValArr['imgMap.']['url'] === '') {
107  $theValArr['imgMap.']['url'] = $LD['totalURL'];
108  }
109  if ($theValArr['imgMap.']['target'] === '') {
110  $theValArr['imgMap.']['target'] = $LD['target'];
111  }
112  if (is_array($theValArr['imgMap.']['altText.'])) {
113  $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
114  $cObj->start($cObjData, 'pages');
115  if (isset($theValArr['imgMap.']['altText.'])) {
116  $theValArr['imgMap.']['altText'] = $cObj->stdWrap($theValArr['imgMap.']['altText'], $theValArr['imgMap.']['altText.']);
117  }
118  unset($theValArr['imgMap.']['altText.']);
119  }
120  if (is_array($theValArr['imgMap.']['titleText.'])) {
121  $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
122  $cObj->start($cObjData, 'pages');
123  if (isset($theValArr['imgMap.']['titleText.'])) {
124  $theValArr['imgMap.']['titleText'] = $cObj->stdWrap($theValArr['imgMap.']['titleText'], $theValArr['imgMap.']['titleText.']);
125  }
126  unset($theValArr['imgMap.']['titleText.']);
127  }
128  }
129  // 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!!
130  if ($theValue === 'IMAGE') {
131  if ($theValArr['file'] === 'GIFBUILDER') {
132  $temp_sKeyArray = ‪ArrayUtility::filterAndSortByNumericKeys($theValArr['file.']);
133  foreach ($temp_sKeyArray as $temp_theKey) {
134  if ($theValArr['mask.'][$temp_theKey] === 'TEXT') {
135  $gifCreator->data = $this->menuArr[$key] ?: [];
136  $theValArr['mask.'][$temp_theKey . '.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey . '.']);
137  // If this is not done it seems that imageMaps will be rendered wrong!!
138  unset($theValArr['mask.'][$temp_theKey . '.']['text.']);
139  }
140  }
141  }
142  if ($theValArr['mask'] === 'GIFBUILDER') {
143  $temp_sKeyArray = ‪ArrayUtility::filterAndSortByNumericKeys($theValArr['mask.']);
144  foreach ($temp_sKeyArray as $temp_theKey) {
145  if ($theValArr['mask.'][$temp_theKey] === 'TEXT') {
146  $gifCreator->data = $this->menuArr[$key] ?: [];
147  $theValArr['mask.'][$temp_theKey . '.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey . '.']);
148  // if this is not done it seems that imageMaps will be rendered wrong!!
149  unset($theValArr['mask.'][$temp_theKey . '.']['text.']);
150  }
151  }
152  }
153  }
154  // Checks if disabled is set...
155  $setObjFlag = 1;
156  if ($theValArr['if.']) {
158  $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
159  $cObj->start($cObjData, 'pages');
160  if (!empty($theValArr['if.']) && !$cObj->checkIf($theValArr['if.'])) {
161  $setObjFlag = 0;
162  }
163  unset($theValArr['if.']);
164  }
165  // Set the object!
166  if ($setObjFlag) {
167  ‪$conf[$gifObjCount] = $theValue;
168  ‪$conf[$gifObjCount . '.'] = $theValArr;
169  }
170  }
171  }
172  }
173  }
174  $gifCreator->start(‪$conf, $this->‪getTypoScriptFrontendController()->page);
175  // calculations
176  $dConf = [];
177  foreach ($waArr as $key => $val) {
178  if ($dConf[$key] = $itemsConf[$key]['distrib']) {
179  $textBB = $gifCreator->objBB[$val['textNum']];
180  $dConf[$key] = str_replace(
181  ['textX', 'textY'],
182  [$textBB[0], $textBB[1]],
183  $dConf[$key]
184  );
185  $dConf[$key] = GeneralUtility::intExplode(',', $gifCreator->calcOffset($dConf[$key]));
186  }
187  }
188  $workArea = GeneralUtility::intExplode(',', $gifCreator->calcOffset($this->mconf['dWorkArea']));
189  foreach ($waArr as $key => $val) {
190  $index = $val['free'];
191  $gifCreator->setup[$index] = 'WORKAREA';
192  $workArea[2] = $dConf[$key][2] ?: $dConf[$key][0];
193  $workArea[3] = $dConf[$key][3] ?: $dConf[$key][1];
194  $gifCreator->setup[$index . '.']['set'] = implode(',', $workArea);
195  $workArea[0] += $dConf[$key][0];
196  $workArea[1] += $dConf[$key][1];
197  }
198  if ($this->mconf['debugRenumberedObject']) {
199  echo '<h3>Renumbered GIFBUILDER object:</h3>';
200  ‪debug($gifCreator->setup);
201  }
202  GeneralUtility::mkdir_deep(‪Environment::getPublicPath() . '/typo3temp/assets/menu/');
203  $gifFileName = $gifCreator->fileName('assets/menu/');
204  // Gets the ImageMap from the cache...
205  $cache = $this->‪getCache();
206  $imgHash = md5($gifFileName);
207  $imgMap = $cache->get($imgHash);
208  // File exists
209  if ($imgMap && file_exists($gifFileName)) {
210  $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $gifFileName);
211  $w = $imageInfo->getWidth();
212  $h = $imageInfo->getHeight();
213  } else {
214  // file is generated
215  $gifCreator->make();
216  $w = $gifCreator->w;
217  $h = $gifCreator->h;
218  $gifCreator->output($gifFileName);
219  $gifCreator->destroy();
220  $imgMap = $gifCreator->map;
221  $cache->set($imgHash, $imgMap, ['ident_MENUIMAGEMAP'], 0);
222  }
223  $imgMap .= $this->mconf['imgMapExtras'];
224  $this->result = ['output_file' => $gifFileName, 'output_w' => $w, 'output_h' => $h, 'imgMap' => $imgMap];
225  }
226  }
227  }
228 
235  public function ‪writeMenu()
236  {
237  if ($this->result) {
238  $res = ‪$this->result;
239  // shortMD5 260900
240  $menuName = 'menu_' . GeneralUtility::shortMD5($res['imgMap']);
241  ‪$result = '<img src="' . $this->‪getTypoScriptFrontendController()->absRefPrefix . $res['output_file'] . '" width="' . $res['output_w'] . '" height="' . $res['output_h'] . '" usemap="#' . $menuName . '" border="0" ' . $this->mconf['params'];
242  // Adding alt attribute if not set.
243  if (!strstr(‪$result, 'alt="')) {
244  ‪$result .= ' alt="Menu Image Map"';
245  }
246  ‪$result .= ' /><map name="' . $menuName . '" id="' . $menuName . '">' . $res['imgMap'] . '</map>';
247  $this->‪getTypoScriptFrontendController()->imagesOnPage[] = $res['output_file'];
248  return $this->WMcObj->wrap(‪$result, $this->mconf['wrap']);
249  }
250  return '';
251  }
252 }
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\changeLinksForAccessRestrictedPages
‪changeLinksForAccessRestrictedPages(&$LD, $page, $mainTarget, $typeOverride)
Definition: AbstractMenuContentObject.php:1826
‪TYPO3\CMS\Frontend\ContentObject\Menu\ImageMenuContentObject
Definition: ImageMenuContentObject.php:30
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\$conf
‪array $conf
Definition: AbstractMenuContentObject.php:167
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\procesItemStates
‪array procesItemStates($splitCount)
Definition: AbstractMenuContentObject.php:1377
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
Definition: AbstractMenuContentObject.php:45
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\$result
‪array $result
Definition: AbstractMenuContentObject.php:208
‪TYPO3\CMS\Frontend\ContentObject\Menu\ImageMenuContentObject\writeMenu
‪string writeMenu()
Definition: ImageMenuContentObject.php:235
‪TYPO3\CMS\Frontend\ContentObject\Menu\ImageMenuContentObject\makeImageMap
‪makeImageMap($conf)
Definition: ImageMenuContentObject.php:64
‪TYPO3\CMS\Frontend\ContentObject\Menu\ImageMenuContentObject\generate
‪generate()
Definition: ImageMenuContentObject.php:42
‪TYPO3\CMS\Frontend\ContentObject\Menu
Definition: AbstractMenuContentObject.php:2
‪TYPO3\CMS\Frontend\Imaging\GifBuilder
Definition: GifBuilder.php:52
‪TYPO3\CMS\Core\Type\File\ImageInfo
Definition: ImageInfo.php:25
‪debug
‪debug($variable='', $title=null, $group=null)
Definition: GlobalDebugFunctions.php:5
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\getTypoScriptFrontendController
‪TypoScriptFrontendController getTypoScriptFrontendController()
Definition: AbstractMenuContentObject.php:2339
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\menuTypoLink
‪array menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray='', $addParams='', $typeOverride='')
Definition: AbstractMenuContentObject.php:2188
‪TYPO3\CMS\Frontend\ContentObject\Menu\ImageMenuContentObject\__construct
‪__construct()
Definition: ImageMenuContentObject.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\ArrayUtility\filterAndSortByNumericKeys
‪static array filterAndSortByNumericKeys($setupArr, $acceptAnyKeys=false)
Definition: ArrayUtility.php:772
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\getCache
‪TYPO3 CMS Core Cache Frontend FrontendInterface getCache()
Definition: AbstractMenuContentObject.php:2360