/**
  * Traverses the ->result['NO'] array of menu items configuration (made by ->generate()) and renders the HTML of each item (the images themselves was made with makeGifs() before this. See ->generate())
  * During the execution of this function many internal methods prefixed "extProc_" from this class is called and many of these are for now dummy functions. But they can be used for processing as they are used by the GMENU_LAYERS
  *
  * @return string The HTML for the menu (returns result through $this->extProc_finish(); )
  * @todo Define visibility
  */
 public function writeMenu()
 {
     if (is_array($this->menuArr) && is_array($this->result) && count($this->result) && is_array($this->result['NO'])) {
         // Create new tslib_cObj for our use
         $this->WMcObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
         $this->WMresult = '';
         $this->INPfixMD5 = substr(md5(microtime() . $this->GMENU_fixKey), 0, 4);
         $this->WMmenuItems = count($this->result['NO']);
         $this->WMsubmenuObjSuffixes = $this->tmpl->splitConfArray(array('sOSuffix' => $this->mconf['submenuObjSuffixes']), $this->WMmenuItems);
         $this->extProc_init();
         for ($key = 0; $key < $this->WMmenuItems; $key++) {
             if ($this->result['NO'][$key]['output_file']) {
                 // Initialize the cObj with the page record of the menu item
                 $this->WMcObj->start($this->menuArr[$key], 'pages');
                 $this->I = array();
                 $this->I['key'] = $key;
                 $this->I['INPfix'] = ($this->imgNameNotRandom ? '' : '_' . $this->INPfixMD5) . '_' . $key;
                 $this->I['val'] = $this->result['NO'][$key];
                 $this->I['title'] = $this->getPageTitle($this->menuArr[$key]['title'], $this->menuArr[$key]['nav_title']);
                 $this->I['uid'] = $this->menuArr[$key]['uid'];
                 $this->I['mount_pid'] = $this->menuArr[$key]['mount_pid'];
                 $this->I['pid'] = $this->menuArr[$key]['pid'];
                 $this->I['spacer'] = $this->menuArr[$key]['isSpacer'];
                 if (!$this->I['uid'] && !$this->menuArr[$key]['_OVERRIDE_HREF']) {
                     $this->I['spacer'] = 1;
                 }
                 $this->I['noLink'] = $this->I['spacer'] || $this->I['val']['noLink'] || !count($this->menuArr[$key]);
                 // !count($this->menuArr[$key]) means that this item is a dummyItem
                 $this->I['name'] = '';
                 // Set access key
                 if ($this->mconf['accessKey']) {
                     $this->I['accessKey'] = $this->accessKey($this->I['title']);
                 } else {
                     $this->I['accessKey'] = array();
                 }
                 // Make link tag
                 $this->I['val']['ATagParams'] = $this->WMcObj->getATagParams($this->I['val']);
                 if (isset($this->I['val']['additionalParams.'])) {
                     $this->I['val']['additionalParams'] = $this->WMcObj->stdWrap($this->I['val']['additionalParams'], $this->I['val']['additionalParams.']);
                 }
                 $this->I['linkHREF'] = $this->link($key, $this->I['val']['altTarget'], $this->mconf['forceTypeValue']);
                 // Title attribute of links:
                 $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'];
                 if (strlen($titleAttrValue)) {
                     $this->I['linkHREF']['title'] = $titleAttrValue;
                 }
                 // Set rollover
                 if ($this->result['RO'][$key] && !$this->I['noLink']) {
                     $this->I['theName'] = $this->imgNamePrefix . $this->I['uid'] . $this->I['INPfix'];
                     $this->I['name'] = ' ' . $this->nameAttribute . '="' . $this->I['theName'] . '"';
                     $this->I['linkHREF']['onMouseover'] = $this->WMfreezePrefix . 'over(\'' . $this->I['theName'] . '\');';
                     $this->I['linkHREF']['onMouseout'] = $this->WMfreezePrefix . 'out(\'' . $this->I['theName'] . '\');';
                     $GLOBALS['TSFE']->JSImgCode .= LF . $this->I['theName'] . '_n=new Image(); ' . $this->I['theName'] . '_n.src = "' . $GLOBALS['TSFE']->absRefPrefix . $this->I['val']['output_file'] . '"; ';
                     $GLOBALS['TSFE']->JSImgCode .= LF . $this->I['theName'] . '_h=new Image(); ' . $this->I['theName'] . '_h.src = "' . $GLOBALS['TSFE']->absRefPrefix . $this->result['RO'][$key]['output_file'] . '"; ';
                     $GLOBALS['TSFE']->imagesOnPage[] = $this->result['RO'][$key]['output_file'];
                     $GLOBALS['TSFE']->setJS('mouseOver');
                     $this->extProc_RO($key);
                 }
                 // Set altText
                 $this->I['altText'] = $this->I['title'] . $this->I['accessKey']['alt'];
                 // Calling extra processing function
                 $this->extProc_beforeLinking($key);
                 // Set linking
                 if (!$this->I['noLink']) {
                     $this->setATagParts();
                 } else {
                     $this->I['A1'] = '';
                     $this->I['A2'] = '';
                 }
                 $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'] . '" ' . \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::getBorderAttr('border="0"') . ($this->mconf['disableAltText'] ? '' : ' alt="' . htmlspecialchars($this->I['altText']) . '"') . $this->I['name'] . ($this->I['val']['imgParams'] ? ' ' . $this->I['val']['imgParams'] : '') . ' />';
                 // Make before, middle and after parts
                 $this->I['parts'] = array();
                 $this->I['parts']['ATag_begin'] = $this->I['A1'];
                 $this->I['parts']['image'] = $this->I['IMG'];
                 $this->I['parts']['ATag_end'] = $this->I['A2'];
                 // Passing I to a user function
                 if ($this->mconf['IProcFunc']) {
                     $this->I = $this->userProcess('IProcFunc', $this->I);
                 }
                 // Putting the item together.
                 // Merge parts + beforeAllWrap
                 $this->I['theItem'] = implode('', $this->I['parts']);
                 $this->I['theItem'] = $this->extProc_beforeAllWrap($this->I['theItem'], $key);
                 // wrap:
                 $this->I['theItem'] = $this->tmpl->wrap($this->I['theItem'], $this->I['val']['wrap']);
                 // allWrap:
                 $allWrap = isset($this->I['val']['allWrap.']) ? $this->WMcObj->stdWrap($this->I['val']['allWrap'], $this->I['val']['allWrap.']) : $this->I['val']['allWrap'];
                 $this->I['theItem'] = $this->tmpl->wrap($this->I['theItem'], $allWrap);
                 if ($this->I['val']['subst_elementUid']) {
                     $this->I['theItem'] = str_replace('{elementUid}', $this->I['uid'], $this->I['theItem']);
                 }
                 // allStdWrap:
                 if (is_array($this->I['val']['allStdWrap.'])) {
                     $this->I['theItem'] = $this->WMcObj->stdWrap($this->I['theItem'], $this->I['val']['allStdWrap.']);
                 }
                 $GLOBALS['TSFE']->imagesOnPage[] = $this->I['val']['output_file'];
                 $this->extProc_afterLinking($key);
             }
         }
         return $this->extProc_finish();
     }
 }
 /**
  * Generates the before* and after* images for TMENUs
  *
  * @param string $pref Can be "before" or "after" and determines which kind of image to create (basically this is the prefix of the TypoScript properties that are read from the ->I['val'] array
  * @return string The resulting HTML of the image, if any.
  * @todo Define visibility
  */
 public function getBeforeAfter($pref)
 {
     $res = '';
     if ($imgInfo = $this->WMcObj->getImgResource($this->I['val'][$pref . 'Img'], $this->I['val'][$pref . 'Img.'])) {
         $imgInfo[3] = \TYPO3\CMS\Core\Utility\GeneralUtility::png_to_gif_by_imagemagick($imgInfo[3]);
         if ($this->I['val']['RO'] && $this->I['val'][$pref . 'ROImg'] && !$this->I['spacer']) {
             $imgROInfo = $this->WMcObj->getImgResource($this->I['val'][$pref . 'ROImg'], $this->I['val'][$pref . 'ROImg.']);
             $imgROInfo[3] = \TYPO3\CMS\Core\Utility\GeneralUtility::png_to_gif_by_imagemagick($imgROInfo[3]);
             if ($imgROInfo) {
                 $theName = $this->imgNamePrefix . $this->I['uid'] . $this->I['INPfix'] . $pref;
                 $name = ' ' . $this->nameAttribute . '="' . $theName . '"';
                 $GLOBALS['TSFE']->JSImgCode .= LF . $theName . '_n=new Image(); ' . $theName . '_n.src = "' . $GLOBALS['TSFE']->absRefPrefix . $imgInfo[3] . '"; ';
                 $GLOBALS['TSFE']->JSImgCode .= LF . $theName . '_h=new Image(); ' . $theName . '_h.src = "' . $GLOBALS['TSFE']->absRefPrefix . $imgROInfo[3] . '"; ';
             }
         }
         $GLOBALS['TSFE']->imagesOnPage[] = $imgInfo[3];
         $res = '<img' . ' src="' . $GLOBALS['TSFE']->absRefPrefix . $imgInfo[3] . '"' . ' width="' . $imgInfo[0] . '"' . ' height="' . $imgInfo[1] . '"' . $name . ($this->I['val'][$pref . 'ImgTagParams'] ? ' ' . $this->I['val'][$pref . 'ImgTagParams'] : '') . \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::getBorderAttr(' border="0"');
         if (!strstr($res, 'alt="')) {
             // Adding alt attribute if not set.
             $res .= ' alt=""';
         }
         $res .= ' />';
         if ($this->I['val'][$pref . 'ImgLink']) {
             $res = $this->I['A1'] . $res . $this->I['A2'];
         }
     }
     $processedPref = isset($this->I['val'][$pref . '.']) ? $this->WMcObj->stdWrap($this->I['val'][$pref], $this->I['val'][$pref . '.']) : $this->I['val'][$pref];
     if (isset($this->I['val'][$pref . 'Wrap'])) {
         return $this->tmpl->wrap($res . $processedPref, $this->I['val'][$pref . 'Wrap']);
     } else {
         return $res . $processedPref;
     }
 }