TYPO3 CMS  TYPO3_6-2
ImageMenuContentObject.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
34  public function generate() {
35  $splitCount = count($this->menuArr);
36  if ($splitCount) {
37  list($NOconf) = $this->procesItemStates($splitCount);
38  } else {
39  $NOconf = array();
40  }
41  if ($this->mconf['debugItemConf']) {
42  echo '<h3>$NOconf:</h3>';
43  debug($NOconf);
44  }
45  $this->makeImageMap($NOconf);
46  }
47 
58  public function makeImageMap($conf) {
59  if (!is_array($conf)) {
60  $conf = array();
61  }
62  if (is_array($this->mconf['main.'])) {
63  $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
64  $gifCreator->init();
65  $itemsConf = $conf;
66  $conf = $this->mconf['main.'];
67  if (is_array($conf)) {
69  $gifObjCount = (int)end($sKeyArray);
70  // Now we add graphical objects to the gifbuilder-setup
71  $waArr = array();
72  foreach ($itemsConf as $key => $val) {
73  if (is_array($val)) {
74  $gifObjCount++;
75  $waArr[$key]['free'] = $gifObjCount;
76  $sKeyArray = TemplateService::sortedKeyList($val);
77  foreach ($sKeyArray as $theKey) {
78  $theValue = $val[$theKey];
79  if ((int)$theKey && ($theValArr = $val[$theKey . '.'])) {
80  $cObjData = $this->menuArr[$key] ?: array();
81  $gifObjCount++;
82  if ($theValue == 'TEXT') {
83  $waArr[$key]['textNum'] = $gifObjCount;
84  $gifCreator->data = $cObjData;
85  $theValArr = $gifCreator->checkTextObj($theValArr);
86  // if this is not done it seems that imageMaps will be rendered wrong!!
87  unset($theValArr['text.']);
88  // check links
89  $LD = $this->menuTypoLink($this->menuArr[$key], $this->mconf['target'], '', '', array(), '', $this->mconf['forceTypeValue']);
90  // If access restricted pages should be shown in menus, change the link of such pages to link to a redirection page:
91  $this->changeLinksForAccessRestrictedPages($LD, $this->menuArr[$key], $this->mconf['target'], $this->mconf['forceTypeValue']);
92  // Overriding URL / Target if set to do so:
93  if ($this->menuArr[$key]['_OVERRIDE_HREF']) {
94  $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF'];
95  if ($this->menuArr[$key]['_OVERRIDE_TARGET']) {
96  $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET'];
97  }
98  }
99  // Setting target/url for Image Map:
100  if ($theValArr['imgMap.']['url'] == '') {
101  $theValArr['imgMap.']['url'] = $LD['totalURL'];
102  }
103  if ($theValArr['imgMap.']['target'] == '') {
104  $theValArr['imgMap.']['target'] = $LD['target'];
105  }
106  if (is_array($theValArr['imgMap.']['altText.'])) {
107  $cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
108  $cObj->start($cObjData, 'pages');
109  if (isset($theValArr['imgMap.']['altText.'])) {
110  $theValArr['imgMap.']['altText'] = $cObj->stdWrap($theValArr['imgMap.']['altText'], $theValArr['imgMap.']['altText.']);
111  }
112  unset($theValArr['imgMap.']['altText.']);
113  }
114  if (is_array($theValArr['imgMap.']['titleText.'])) {
115  $cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
116  $cObj->start($cObjData, 'pages');
117  if (isset($theValArr['imgMap.']['titleText.'])) {
118  $theValArr['imgMap.']['titleText'] = $cObj->stdWrap($theValArr['imgMap.']['titleText'], $theValArr['imgMap.']['titleText.']);
119  }
120  unset($theValArr['imgMap.']['titleText.']);
121  }
122  }
123  // 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!!
124  if ($theValue == 'IMAGE') {
125  if ($theValArr['file'] == 'GIFBUILDER') {
126  $temp_sKeyArray = TemplateService::sortedKeyList($theValArr['file.']);
127  foreach ($temp_sKeyArray as $temp_theKey) {
128  if ($theValArr['mask.'][$temp_theKey] == 'TEXT') {
129  $gifCreator->data = $this->menuArr[$key] ?: array();
130  $theValArr['mask.'][$temp_theKey . '.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey . '.']);
131  // If this is not done it seems that imageMaps will be rendered wrong!!
132  unset($theValArr['mask.'][$temp_theKey . '.']['text.']);
133  }
134  }
135  }
136  if ($theValArr['mask'] == 'GIFBUILDER') {
137  $temp_sKeyArray = TemplateService::sortedKeyList($theValArr['mask.']);
138  foreach ($temp_sKeyArray as $temp_theKey) {
139  if ($theValArr['mask.'][$temp_theKey] == 'TEXT') {
140  $gifCreator->data = $this->menuArr[$key] ?: array();
141  $theValArr['mask.'][$temp_theKey . '.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey . '.']);
142  // if this is not done it seems that imageMaps will be rendered wrong!!
143  unset($theValArr['mask.'][$temp_theKey . '.']['text.']);
144  }
145  }
146  }
147  }
148  // Checks if disabled is set...
149  $setObjFlag = 1;
150  if ($theValArr['if.']) {
152  $cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
153  $cObj->start($cObjData, 'pages');
154  if (!empty($theValArr['if.']) && !$cObj->checkIf($theValArr['if.'])) {
155  $setObjFlag = 0;
156  }
157  unset($theValArr['if.']);
158  }
159  // Set the object!
160  if ($setObjFlag) {
161  $conf[$gifObjCount] = $theValue;
162  $conf[$gifObjCount . '.'] = $theValArr;
163  }
164  }
165  }
166  }
167  }
168  $gifCreator->start($conf, $GLOBALS['TSFE']->page);
169  // calculations
170  $dConf = array();
171  foreach ($waArr as $key => $val) {
172  if ($dConf[$key] = $itemsConf[$key]['distrib']) {
173  $textBB = $gifCreator->objBB[$val['textNum']];
174  $dConf[$key] = str_replace(
175  array('textX', 'textY'),
176  array($textBB[0], $textBB[1]),
177  $dConf[$key]
178  );
179  $dConf[$key] = GeneralUtility::intExplode(',', $gifCreator->calcOffset($dConf[$key]));
180  }
181  }
182  $workArea = GeneralUtility::intExplode(',', $gifCreator->calcOffset($this->mconf['dWorkArea']));
183  foreach ($waArr as $key => $val) {
184  $index = $val['free'];
185  $gifCreator->setup[$index] = 'WORKAREA';
186  $workArea[2] = $dConf[$key][2] ?: $dConf[$key][0];
187  $workArea[3] = $dConf[$key][3] ?: $dConf[$key][1];
188  $gifCreator->setup[$index . '.']['set'] = implode(',', $workArea);
189  $workArea[0] += $dConf[$key][0];
190  $workArea[1] += $dConf[$key][1];
191  }
192  if ($this->mconf['debugRenumberedObject']) {
193  echo '<h3>Renumbered GIFBUILDER object:</h3>';
194  debug($gifCreator->setup);
195  }
196  $gifCreator->createTempSubDir('menu/');
197  $gifFileName = $gifCreator->fileName('menu/');
198  // Gets the ImageMap from the cache...
199  $cache = $this->getCache();
200  $imgHash = md5($gifFileName);
201  $imgMap = $cache->get($imgHash);
202  // File exists
203  if ($imgMap && file_exists($gifFileName)) {
204  $info = @getimagesize($gifFileName);
205  $w = $info[0];
206  $h = $info[1];
207  } else {
208  // file is generated
209  $gifCreator->make();
210  $w = $gifCreator->w;
211  $h = $gifCreator->h;
212  $gifCreator->output($gifFileName);
213  $gifCreator->destroy();
214  $imgMap = $gifCreator->map;
215  $cache->set($imgHash, $imgMap, array('ident_MENUIMAGEMAP'), 0);
216  }
217  $imgMap .= $this->mconf['imgMapExtras'];
218  $gifFileName = GeneralUtility::png_to_gif_by_imagemagick($gifFileName);
219  $this->result = array('output_file' => $gifFileName, 'output_w' => $w, 'output_h' => $h, 'imgMap' => $imgMap);
220  }
221  }
222  }
223 
231  public function writeMenu() {
232  if ($this->result) {
233  $res = &$this->result;
234  // shortMD5 260900
235  $menuName = 'menu_' . GeneralUtility::shortMD5($res['imgMap']);
236  $result = '<img src="' . $GLOBALS['TSFE']->absRefPrefix . $res['output_file'] . '" width="' . $res['output_w'] . '" height="' . $res['output_h'] . '" usemap="#' . $menuName . '" border="0" ' . $this->mconf['params'];
237  // Adding alt attribute if not set.
238  if (!strstr($result, 'alt="')) {
239  $result .= ' alt="Menu Image Map"';
240  }
241  $result .= ' /><map name="' . $menuName . '" id="' . $menuName . '">' . $res['imgMap'] . '</map>';
242  $GLOBALS['TSFE']->imagesOnPage[] = $res['output_file'];
243  return $this->tmpl->wrap($result, $this->mconf['wrap']);
244  }
245  return '';
246  }
247 
248 }
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray='', $addParams='', $typeOverride='')
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static sortedKeyList($setupArr, $acceptOnlyProperties=FALSE)