TYPO3 CMS  TYPO3_6-2
GraphicalMenuContentObject.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, $ROconf) = $this->procesItemStates($splitCount);
38  //store initial count value
39  $temp_HMENU_MENUOBJ = $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ'];
40  $temp_MENUOBJ = $GLOBALS['TSFE']->register['count_MENUOBJ'];
41  // Now we generate the giffiles:
42  $this->makeGifs($NOconf, 'NO');
43  // store count from NO obj
44  $tempcnt_HMENU_MENUOBJ = $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ'];
45  $tempcnt_MENUOBJ = $GLOBALS['TSFE']->register['count_MENUOBJ'];
46  if ($this->mconf['debugItemConf']) {
47  echo '<h3>$NOconf:</h3>';
48  debug($NOconf);
49  }
50  // RollOver
51  if ($ROconf) {
52  // Start recount for rollover with initial values
53  $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ'] = $temp_HMENU_MENUOBJ;
54  $GLOBALS['TSFE']->register['count_MENUOBJ'] = $temp_MENUOBJ;
55  $this->makeGifs($ROconf, 'RO');
56  if ($this->mconf['debugItemConf']) {
57  echo '<h3>$ROconf:</h3>';
58  debug($ROconf);
59  }
60  }
61  // Use count from NO obj
62  $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ'] = $tempcnt_HMENU_MENUOBJ;
63  $GLOBALS['TSFE']->register['count_MENUOBJ'] = $tempcnt_MENUOBJ;
64  }
65  }
66 
78  public function makeGifs($conf, $resKey) {
79  $isGD = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'];
80  if (!is_array($conf)) {
81  $conf = array();
82  }
83  $totalWH = array();
84  $items = count($conf);
85  if ($isGD) {
86  // Generate the gif-files. the $menuArr is filled with some values like output_w, output_h, output_file
87  $Hcounter = 0;
88  $Wcounter = 0;
89  $Hobjs = $this->mconf['applyTotalH'];
90  if ($Hobjs) {
91  $Hobjs = GeneralUtility::intExplode(',', $Hobjs);
92  }
93  $Wobjs = $this->mconf['applyTotalW'];
94  if ($Wobjs) {
95  $Wobjs = GeneralUtility::intExplode(',', $Wobjs);
96  }
97  $minDim = $this->mconf['min'];
98  if ($minDim) {
99  $minDim = $this->parent_cObj->calcIntExplode(',', $minDim . ',');
100  }
101  $maxDim = $this->mconf['max'];
102  if ($maxDim) {
103  $maxDim = $this->parent_cObj->calcIntExplode(',', $maxDim . ',');
104  }
105  if ($minDim) {
106  $conf[$items] = $conf[$items - 1];
107  $this->menuArr[$items] = array();
108  $items = count($conf);
109  }
110  // TOTAL width
111  if ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'] || $this->mconf['distributeX'] || $this->mconf['distributeY']) {
112  $totalWH = $this->findLargestDims($conf, $items, $Hobjs, $Wobjs, $minDim, $maxDim);
113  }
114  }
115  $c = 0;
116  $maxFlag = 0;
117  $distributeAccu = array('H' => 0, 'W' => 0);
118  foreach ($conf as $key => $val) {
119  $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ']++;
120  $GLOBALS['TSFE']->register['count_MENUOBJ']++;
121  if ($items == $c + 1 && $minDim) {
122  $Lobjs = $this->mconf['removeObjectsOfDummy'];
123  if ($Lobjs) {
124  $Lobjs = GeneralUtility::intExplode(',', $Lobjs);
125  foreach ($Lobjs as $remItem) {
126  unset($val[$remItem]);
127  unset($val[$remItem . '.']);
128  }
129  }
130  $flag = 0;
131  $tempXY = explode(',', $val['XY']);
132  if ($Wcounter < $minDim[0]) {
133  $tempXY[0] = $minDim[0] - $Wcounter;
134  $flag = 1;
135  }
136  if ($Hcounter < $minDim[1]) {
137  $tempXY[1] = $minDim[1] - $Hcounter;
138  $flag = 1;
139  }
140  $val['XY'] = implode(',', $tempXY);
141  if (!$flag) {
142  break;
143  }
144  }
145  $c++;
146  if ($isGD) {
147  // Pre-working the item
148  $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
149  $gifCreator->init();
150  $gifCreator->start($val, $this->menuArr[$key]);
151  // If useLargestItemH/W is specified
152  if (count($totalWH) && ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'])) {
153  $tempXY = explode(',', $gifCreator->setup['XY']);
154  if ($this->mconf['useLargestItemX']) {
155  $tempXY[0] = max($totalWH['W']);
156  }
157  if ($this->mconf['useLargestItemY']) {
158  $tempXY[1] = max($totalWH['H']);
159  }
160  // Regenerate the new values...
161  $val['XY'] = implode(',', $tempXY);
162  $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
163  $gifCreator->init();
164  $gifCreator->start($val, $this->menuArr[$key]);
165  }
166  // If distributeH/W is specified
167  if (count($totalWH) && ($this->mconf['distributeX'] || $this->mconf['distributeY'])) {
168  $tempXY = explode(',', $gifCreator->setup['XY']);
169  if ($this->mconf['distributeX']) {
170  $diff = $this->mconf['distributeX'] - $totalWH['W_total'] - $distributeAccu['W'];
171  $compensate = round($diff / ($items - $c + 1));
172  $distributeAccu['W'] += $compensate;
173  $tempXY[0] = $totalWH['W'][$key] + $compensate;
174  }
175  if ($this->mconf['distributeY']) {
176  $diff = $this->mconf['distributeY'] - $totalWH['H_total'] - $distributeAccu['H'];
177  $compensate = round($diff / ($items - $c + 1));
178  $distributeAccu['H'] += $compensate;
179  $tempXY[1] = $totalWH['H'][$key] + $compensate;
180  }
181  // Regenerate the new values...
182  $val['XY'] = implode(',', $tempXY);
183  $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
184  $gifCreator->init();
185  $gifCreator->start($val, $this->menuArr[$key]);
186  }
187  // If max dimensions are specified
188  if ($maxDim) {
189  $tempXY = explode(',', $val['XY']);
190  if ($maxDim[0] && $Wcounter + $gifCreator->XY[0] >= $maxDim[0]) {
191  $tempXY[0] == $maxDim[0] - $Wcounter;
192  $maxFlag = 1;
193  }
194  if ($maxDim[1] && $Hcounter + $gifCreator->XY[1] >= $maxDim[1]) {
195  $tempXY[1] = $maxDim[1] - $Hcounter;
196  $maxFlag = 1;
197  }
198  if ($maxFlag) {
199  $val['XY'] = implode(',', $tempXY);
200  $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
201  $gifCreator->init();
202  $gifCreator->start($val, $this->menuArr[$key]);
203  }
204  }
205  // displace
206  if ($Hobjs) {
207  foreach ($Hobjs as $index) {
208  if ($gifCreator->setup[$index] && $gifCreator->setup[$index . '.']) {
209  $oldOffset = explode(',', $gifCreator->setup[$index . '.']['offset']);
210  $gifCreator->setup[$index . '.']['offset'] = implode(',', $gifCreator->applyOffset($oldOffset, array(0, -$Hcounter)));
211  }
212  }
213  }
214  if ($Wobjs) {
215  foreach ($Wobjs as $index) {
216  if ($gifCreator->setup[$index] && $gifCreator->setup[$index . '.']) {
217  $oldOffset = explode(',', $gifCreator->setup[$index . '.']['offset']);
218  $gifCreator->setup[$index . '.']['offset'] = implode(',', $gifCreator->applyOffset($oldOffset, array(-$Wcounter, 0)));
219  }
220  }
221  }
222  }
223  // Finding alternative GIF names if any (by altImgResource)
224  $gifFileName = '';
225  if ($conf[$key]['altImgResource'] || is_array($conf[$key]['altImgResource.'])) {
226  if (!is_object($cObj)) {
227  $cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
228  }
229  $cObj->start($this->menuArr[$key], 'pages');
230  $altImgInfo = $cObj->getImgResource($conf[$key]['altImgResource'], $conf[$key]['altImgResource.']);
231  $gifFileName = $altImgInfo[3];
232  }
233  // If an alternative name was NOT given, find the GIFBUILDER name.
234  if (!$gifFileName && $isGD) {
235  $gifCreator->createTempSubDir('menu/');
236  $gifFileName = $gifCreator->fileName('menu/');
237  }
238  $this->result[$resKey][$key] = $conf[$key];
239  // Generation of image file:
240  // File exists
241  if (file_exists($gifFileName)) {
242  $info = @getimagesize($gifFileName);
243  $this->result[$resKey][$key]['output_w'] = (int)$info[0];
244  $this->result[$resKey][$key]['output_h'] = (int)$info[1];
245  $this->result[$resKey][$key]['output_file'] = $gifFileName;
246  } elseif ($isGD) {
247  // file is generated
248  $gifCreator->make();
249  $this->result[$resKey][$key]['output_w'] = $gifCreator->w;
250  $this->result[$resKey][$key]['output_h'] = $gifCreator->h;
251  $this->result[$resKey][$key]['output_file'] = $gifFileName;
252  $gifCreator->output($this->result[$resKey][$key]['output_file']);
253  $gifCreator->destroy();
254  }
255  $this->result[$resKey][$key]['output_file'] = GeneralUtility::png_to_gif_by_imagemagick($this->result[$resKey][$key]['output_file']);
256  // counter is increased
257  $Hcounter += $this->result[$resKey][$key]['output_h'];
258  // counter is increased
259  $Wcounter += $this->result[$resKey][$key]['output_w'];
260  if ($maxFlag) {
261  break;
262  }
263  }
264  }
265 
282  public function findLargestDims($conf, $items, $Hobjs, $Wobjs, $minDim, $maxDim) {
283  $totalWH = array(
284  'W' => array(),
285  'H' => array(),
286  'W_total' => 0,
287  'H_total' => 0
288  );
289  $Hcounter = 0;
290  $Wcounter = 0;
291  $c = 0;
292  $maxFlag = 0;
293  foreach ($conf as $key => $val) {
294  // SAME CODE AS makeGifs()! BEGIN
295  if ($items == $c + 1 && $minDim) {
296  $Lobjs = $this->mconf['removeObjectsOfDummy'];
297  if ($Lobjs) {
298  $Lobjs = GeneralUtility::intExplode(',', $Lobjs);
299  foreach ($Lobjs as $remItem) {
300  unset($val[$remItem]);
301  unset($val[$remItem . '.']);
302  }
303  }
304  $flag = 0;
305  $tempXY = explode(',', $val['XY']);
306  if ($Wcounter < $minDim[0]) {
307  $tempXY[0] = $minDim[0] - $Wcounter;
308  $flag = 1;
309  }
310  if ($Hcounter < $minDim[1]) {
311  $tempXY[1] = $minDim[1] - $Hcounter;
312  $flag = 1;
313  }
314  $val['XY'] = implode(',', $tempXY);
315  if (!$flag) {
316  break;
317  }
318  }
319  $c++;
320  $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
321  $gifCreator->init();
322  $gifCreator->start($val, $this->menuArr[$key]);
323  if ($maxDim) {
324  $tempXY = explode(',', $val['XY']);
325  if ($maxDim[0] && $Wcounter + $gifCreator->XY[0] >= $maxDim[0]) {
326  $tempXY[0] == $maxDim[0] - $Wcounter;
327  $maxFlag = 1;
328  }
329  if ($maxDim[1] && $Hcounter + $gifCreator->XY[1] >= $maxDim[1]) {
330  $tempXY[1] = $maxDim[1] - $Hcounter;
331  $maxFlag = 1;
332  }
333  if ($maxFlag) {
334  $val['XY'] = implode(',', $tempXY);
335  $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
336  $gifCreator->init();
337  $gifCreator->start($val, $this->menuArr[$key]);
338  }
339  }
340  // SAME CODE AS makeGifs()! END
341  // Setting the width/height
342  $totalWH['W'][$key] = $gifCreator->XY[0];
343  $totalWH['H'][$key] = $gifCreator->XY[1];
344  $totalWH['W_total'] += $gifCreator->XY[0];
345  $totalWH['H_total'] += $gifCreator->XY[1];
346  // counter is increased
347  $Hcounter += $gifCreator->XY[1];
348  // counter is increased
349  $Wcounter += $gifCreator->XY[0];
350  if ($maxFlag) {
351  break;
352  }
353  }
354  return $totalWH;
355  }
356 
364  public function writeMenu() {
365  if (!is_array($this->menuArr) || empty($this->result) || !is_array($this->result['NO'])) {
366  return '';
367  }
368  // Create new \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer for our use
369  $this->WMcObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
370  $this->WMresult = '';
371  $this->INPfixMD5 = substr(md5(microtime() . $this->GMENU_fixKey), 0, 4);
372  $this->WMmenuItems = count($this->result['NO']);
373  $this->WMsubmenuObjSuffixes = $this->tmpl->splitConfArray(array('sOSuffix' => $this->mconf['submenuObjSuffixes']), $this->WMmenuItems);
374  $this->extProc_init();
375  for ($key = 0; $key < $this->WMmenuItems; $key++) {
376  if ($this->result['NO'][$key]['output_file']) {
377  // Initialize the cObj with the page record of the menu item
378  $this->WMcObj->start($this->menuArr[$key], 'pages');
379  $this->I = array();
380  $this->I['key'] = $key;
381  $this->I['INPfix'] = ($this->imgNameNotRandom ? '' : '_' . $this->INPfixMD5) . '_' . $key;
382  $this->I['val'] = $this->result['NO'][$key];
383  $this->I['title'] = $this->getPageTitle($this->menuArr[$key]['title'], $this->menuArr[$key]['nav_title']);
384  $this->I['uid'] = $this->menuArr[$key]['uid'];
385  $this->I['mount_pid'] = $this->menuArr[$key]['mount_pid'];
386  $this->I['pid'] = $this->menuArr[$key]['pid'];
387  $this->I['spacer'] = $this->menuArr[$key]['isSpacer'];
388  if (!$this->I['uid'] && !$this->menuArr[$key]['_OVERRIDE_HREF']) {
389  $this->I['spacer'] = 1;
390  }
391  $this->I['noLink'] = $this->I['spacer'] || $this->I['val']['noLink'] || !count($this->menuArr[$key]);
392  // !count($this->menuArr[$key]) means that this item is a dummyItem
393  $this->I['name'] = '';
394  // Set access key
395  if ($this->mconf['accessKey']) {
396  $this->I['accessKey'] = $this->accessKey($this->I['title']);
397  } else {
398  $this->I['accessKey'] = array();
399  }
400  // Make link tag
401  $this->I['val']['ATagParams'] = $this->WMcObj->getATagParams($this->I['val']);
402  if (isset($this->I['val']['additionalParams.'])) {
403  $this->I['val']['additionalParams'] = $this->WMcObj->stdWrap($this->I['val']['additionalParams'], $this->I['val']['additionalParams.']);
404  }
405  $this->I['linkHREF'] = $this->link($key, $this->I['val']['altTarget'], $this->mconf['forceTypeValue']);
406  // Title attribute of links:
407  $titleAttrValue = isset($this->I['val']['ATagTitle.']) ? $this->WMcObj->stdWrap($this->I['val']['ATagTitle'], $this->I['val']['ATagTitle.']) . $this->I['accessKey']['alt'] : $this->I['val']['ATagTitle'] . $this->I['accessKey']['alt'];
408  if (strlen($titleAttrValue)) {
409  $this->I['linkHREF']['title'] = $titleAttrValue;
410  }
411  // Set rollover
412  if ($this->result['RO'][$key] && !$this->I['noLink']) {
413  $this->I['theName'] = $this->imgNamePrefix . $this->I['uid'] . $this->I['INPfix'];
414  $this->I['name'] = ' ' . $this->nameAttribute . '="' . $this->I['theName'] . '"';
415  $this->I['linkHREF']['onMouseover'] = $this->WMfreezePrefix . 'over(\'' . $this->I['theName'] . '\');';
416  $this->I['linkHREF']['onMouseout'] = $this->WMfreezePrefix . 'out(\'' . $this->I['theName'] . '\');';
417  $GLOBALS['TSFE']->JSImgCode .= LF . $this->I['theName'] . '_n=new Image(); ' . $this->I['theName'] . '_n.src = "' . $GLOBALS['TSFE']->absRefPrefix . $this->I['val']['output_file'] . '"; ';
418  $GLOBALS['TSFE']->JSImgCode .= LF . $this->I['theName'] . '_h=new Image(); ' . $this->I['theName'] . '_h.src = "' . $GLOBALS['TSFE']->absRefPrefix . $this->result['RO'][$key]['output_file'] . '"; ';
419  $GLOBALS['TSFE']->imagesOnPage[] = $this->result['RO'][$key]['output_file'];
420  $GLOBALS['TSFE']->setJS('mouseOver');
421  $this->extProc_RO($key);
422  }
423  // Set altText
424  $this->I['altText'] = $this->I['title'] . $this->I['accessKey']['alt'];
425  // Calling extra processing function
426  $this->extProc_beforeLinking($key);
427  // Set linking
428  if (!$this->I['noLink']) {
429  $this->setATagParts();
430  } else {
431  $this->I['A1'] = '';
432  $this->I['A2'] = '';
433  }
434  $this->I['IMG'] = '<img src="' . $GLOBALS['TSFE']->absRefPrefix . $this->I['val']['output_file'] . '" width="' . $this->I['val']['output_w'] . '" height="' . $this->I['val']['output_h'] . '" ' . $this->parent_cObj->getBorderAttr('border="0"') . ($this->mconf['disableAltText'] ? '' : ' alt="' . htmlspecialchars($this->I['altText']) . '"') . $this->I['name'] . ($this->I['val']['imgParams'] ? ' ' . $this->I['val']['imgParams'] : '') . ' />';
435  // Make before, middle and after parts
436  $this->I['parts'] = array();
437  $this->I['parts']['ATag_begin'] = $this->I['A1'];
438  $this->I['parts']['image'] = $this->I['IMG'];
439  $this->I['parts']['ATag_end'] = $this->I['A2'];
440  // Passing I to a user function
441  if ($this->mconf['IProcFunc']) {
442  $this->I = $this->userProcess('IProcFunc', $this->I);
443  }
444  // Putting the item together.
445  // Merge parts + beforeAllWrap
446  $this->I['theItem'] = implode('', $this->I['parts']);
447  $this->I['theItem'] = $this->extProc_beforeAllWrap($this->I['theItem'], $key);
448  // wrap:
449  $this->I['theItem'] = $this->tmpl->wrap($this->I['theItem'], $this->I['val']['wrap']);
450  // allWrap:
451  $allWrap = isset($this->I['val']['allWrap.']) ? $this->WMcObj->stdWrap($this->I['val']['allWrap'], $this->I['val']['allWrap.']) : $this->I['val']['allWrap'];
452  $this->I['theItem'] = $this->tmpl->wrap($this->I['theItem'], $allWrap);
453  if ($this->I['val']['subst_elementUid']) {
454  $this->I['theItem'] = str_replace('{elementUid}', $this->I['uid'], $this->I['theItem']);
455  }
456  // allStdWrap:
457  if (is_array($this->I['val']['allStdWrap.'])) {
458  $this->I['theItem'] = $this->WMcObj->stdWrap($this->I['theItem'], $this->I['val']['allStdWrap.']);
459  }
460  $GLOBALS['TSFE']->imagesOnPage[] = $this->I['val']['output_file'];
461  $this->extProc_afterLinking($key);
462  }
463  }
464  return $this->extProc_finish();
465  }
466 
476  public function extProc_init() {
477 
478  }
479 
489  public function extProc_RO($key) {
490 
491  }
492 
502  public function extProc_beforeLinking($key) {
503 
504  }
505 
517  public function extProc_afterLinking($key) {
518  // Add part to the accumulated result + fetch submenus
519  if (!$this->I['spacer']) {
520  $this->I['theItem'] .= $this->subMenu($this->I['uid'], $this->WMsubmenuObjSuffixes[$key]['sOSuffix']);
521  }
522  $part = isset($this->I['val']['wrapItemAndSub.']) ? $this->WMcObj->stdWrap($this->I['val']['wrapItemAndSub'], $this->I['val']['wrapItemAndSub.']) : $this->I['val']['wrapItemAndSub'];
523  $this->WMresult .= $part ? $this->tmpl->wrap($this->I['theItem'], $part) : $this->I['theItem'];
524  }
525 
536  public function extProc_beforeAllWrap($item, $key) {
537  return $item;
538  }
539 
548  public function extProc_finish() {
549  // stdWrap:
550  if (is_array($this->mconf['stdWrap.'])) {
551  $this->WMresult = $this->WMcObj->stdWrap($this->WMresult, $this->mconf['stdWrap.']);
552  }
553  return $this->tmpl->wrap($this->WMresult, $this->mconf['wrap']) . $this->WMextraScript;
554  }
555 
556 }
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)
findLargestDims($conf, $items, $Hobjs, $Wobjs, $minDim, $maxDim)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]