TYPO3 CMS  TYPO3_8-7
TextMenuContentObject.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  */
18 
23 {
30  public function generate()
31  {
32  $NOconf = [];
33  $splitCount = count($this->menuArr);
34  if ($splitCount) {
35  list($NOconf) = $this->procesItemStates($splitCount);
36  }
37  if (!empty($this->mconf['debugItemConf'])) {
38  echo '<h3>$NOconf:</h3>';
39  debug($NOconf);
40  }
41  $this->result = $NOconf;
42  }
43 
53  public function writeMenu()
54  {
55  if (empty($this->result)) {
56  return '';
57  }
58 
59  $this->WMresult = '';
60  $this->INPfixMD5 = substr(md5(microtime() . 'tmenu'), 0, 4);
61  $this->WMmenuItems = count($this->result);
62  $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
63  $this->WMsubmenuObjSuffixes = $typoScriptService->explodeConfigurationForOptionSplit(['sOSuffix' => $this->mconf['submenuObjSuffixes']], $this->WMmenuItems);
64  $this->extProc_init();
65  foreach ($this->result as $key => $val) {
66  $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ']++;
67  $GLOBALS['TSFE']->register['count_MENUOBJ']++;
68  // Initialize the cObj with the page record of the menu item
69  $this->WMcObj->start($this->menuArr[$key], 'pages');
70  $this->I = [];
71  $this->I['key'] = $key;
72  $this->I['INPfix'] = ($this->imgNameNotRandom ? '' : '_' . $this->INPfixMD5) . '_' . $key;
73  $this->I['val'] = $val;
74  $this->I['title'] = isset($this->I['val']['stdWrap.']) ? $this->WMcObj->stdWrap($this->getPageTitle($this->menuArr[$key]['title'], $this->menuArr[$key]['nav_title']), $this->I['val']['stdWrap.']) : $this->getPageTitle($this->menuArr[$key]['title'], $this->menuArr[$key]['nav_title']);
75  $this->I['uid'] = $this->menuArr[$key]['uid'];
76  $this->I['mount_pid'] = $this->menuArr[$key]['mount_pid'];
77  $this->I['pid'] = $this->menuArr[$key]['pid'];
78  $this->I['spacer'] = $this->menuArr[$key]['isSpacer'];
79  // Set access key
80  if ($this->mconf['accessKey']) {
81  $this->I['accessKey'] = $this->accessKey($this->I['title']);
82  } else {
83  $this->I['accessKey'] = [];
84  }
85  // Make link tag
86  $this->I['val']['ATagParams'] = $this->WMcObj->getATagParams($this->I['val']);
87  if (isset($this->I['val']['additionalParams.'])) {
88  $this->I['val']['additionalParams'] = $this->WMcObj->stdWrap($this->I['val']['additionalParams'], $this->I['val']['additionalParams.']);
89  }
90  $this->I['linkHREF'] = $this->link($key, $this->I['val']['altTarget'], $this->mconf['forceTypeValue']);
91  if (empty($this->I['linkHREF'])) {
92  $this->I['val']['doNotLinkIt'] = 1;
93  }
94  // Title attribute of links:
95  $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'];
96  if ($titleAttrValue !== '') {
97  $this->I['linkHREF']['title'] = $titleAttrValue;
98  }
99 
100  // Calling extra processing function
101  $this->extProc_beforeLinking($key);
102  // stdWrap for doNotLinkIt
103  if (isset($this->I['val']['doNotLinkIt.'])) {
104  $this->I['val']['doNotLinkIt'] = $this->WMcObj->stdWrap($this->I['val']['doNotLinkIt'], $this->I['val']['doNotLinkIt.']);
105  }
106  // Compile link tag
107  if (!$this->I['val']['doNotLinkIt']) {
108  $this->I['val']['doNotLinkIt'] = 0;
109  }
110  if (!$this->I['spacer'] && $this->I['val']['doNotLinkIt'] != 1) {
111  $this->setATagParts();
112  } else {
113  $this->I['A1'] = '';
114  $this->I['A2'] = '';
115  }
116  // ATagBeforeWrap processing:
117  if ($this->I['val']['ATagBeforeWrap']) {
118  $wrapPartsBefore = explode('|', $this->I['val']['linkWrap']);
119  $wrapPartsAfter = ['', ''];
120  } else {
121  $wrapPartsBefore = ['', ''];
122  $wrapPartsAfter = explode('|', $this->I['val']['linkWrap']);
123  }
124  if ($this->I['val']['stdWrap2'] || isset($this->I['val']['stdWrap2.'])) {
125  $stdWrap2 = isset($this->I['val']['stdWrap2.']) ? $this->WMcObj->stdWrap('|', $this->I['val']['stdWrap2.']) : '|';
126  $wrapPartsStdWrap = explode($this->I['val']['stdWrap2'] ? $this->I['val']['stdWrap2'] : '|', $stdWrap2);
127  } else {
128  $wrapPartsStdWrap = ['', ''];
129  }
130  // Make before, middle and after parts
131  $this->I['parts'] = [];
132  $this->I['parts']['before'] = $this->getBeforeAfter('before');
133  $this->I['parts']['stdWrap2_begin'] = $wrapPartsStdWrap[0];
134  // stdWrap for doNotShowLink
135  if (isset($this->I['val']['doNotShowLink.'])) {
136  $this->I['val']['doNotShowLink'] = $this->WMcObj->stdWrap($this->I['val']['doNotShowLink'], $this->I['val']['doNotShowLink.']);
137  }
138  if (!$this->I['val']['doNotShowLink']) {
139  $this->I['parts']['notATagBeforeWrap_begin'] = $wrapPartsAfter[0];
140  $this->I['parts']['ATag_begin'] = $this->I['A1'];
141  $this->I['parts']['ATagBeforeWrap_begin'] = $wrapPartsBefore[0];
142  $this->I['parts']['title'] = $this->I['title'];
143  $this->I['parts']['ATagBeforeWrap_end'] = $wrapPartsBefore[1];
144  $this->I['parts']['ATag_end'] = $this->I['A2'];
145  $this->I['parts']['notATagBeforeWrap_end'] = $wrapPartsAfter[1];
146  }
147  $this->I['parts']['stdWrap2_end'] = $wrapPartsStdWrap[1];
148  $this->I['parts']['after'] = $this->getBeforeAfter('after');
149  // Passing I to a user function
150  if ($this->mconf['IProcFunc']) {
151  $this->I = $this->userProcess('IProcFunc', $this->I);
152  }
153  // Merge parts + beforeAllWrap
154  $this->I['theItem'] = implode('', $this->I['parts']);
155  $this->I['theItem'] = $this->extProc_beforeAllWrap($this->I['theItem'], $key);
156  // allWrap:
157  $allWrap = isset($this->I['val']['allWrap.']) ? $this->WMcObj->stdWrap($this->I['val']['allWrap'], $this->I['val']['allWrap.']) : $this->I['val']['allWrap'];
158  $this->I['theItem'] = $this->WMcObj->wrap($this->I['theItem'], $allWrap);
159  if ($this->I['val']['subst_elementUid']) {
160  $this->I['theItem'] = str_replace('{elementUid}', $this->I['uid'], $this->I['theItem']);
161  }
162  // allStdWrap:
163  if (is_array($this->I['val']['allStdWrap.'])) {
164  $this->I['theItem'] = $this->WMcObj->stdWrap($this->I['theItem'], $this->I['val']['allStdWrap.']);
165  }
166  // Calling extra processing function
167  $this->extProc_afterLinking($key);
168  }
169  return $this->extProc_finish();
170  }
171 
178  public function getBeforeAfter($pref)
179  {
180  $res = '';
181  if ($imgInfo = $this->WMcObj->getImgResource($this->I['val'][$pref . 'Img'], $this->I['val'][$pref . 'Img.'])) {
182  $theName = $this->imgNamePrefix . $this->I['uid'] . $this->I['INPfix'] . $pref;
183  $name = ' ' . $this->nameAttribute . '="' . $theName . '"';
184  $GLOBALS['TSFE']->imagesOnPage[] = $imgInfo[3];
185  $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'] : '') . $this->parent_cObj->getBorderAttr(' border="0"');
186  if (!strstr($res, 'alt="')) {
187  // Adding alt attribute if not set.
188  $res .= ' alt=""';
189  }
190  $res .= ' />';
191  if ($this->I['val'][$pref . 'ImgLink']) {
192  $res = $this->I['A1'] . $res . $this->I['A2'];
193  }
194  }
195  $processedPref = isset($this->I['val'][$pref . '.']) ? $this->WMcObj->stdWrap($this->I['val'][$pref], $this->I['val'][$pref . '.']) : $this->I['val'][$pref];
196  if (isset($this->I['val'][$pref . 'Wrap'])) {
197  return $this->WMcObj->wrap($res . $processedPref, $this->I['val'][$pref . 'Wrap']);
198  }
199  return $res . $processedPref;
200  }
201 
209  public function extProc_init()
210  {
211  }
212 
220  public function extProc_beforeLinking($key)
221  {
222  }
223 
232  public function extProc_afterLinking($key)
233  {
234  // Add part to the accumulated result + fetch submenus
235  if (!$this->I['spacer']) {
236  $this->I['theItem'] .= $this->subMenu($this->I['uid'], $this->WMsubmenuObjSuffixes[$key]['sOSuffix']);
237  }
238  $part = isset($this->I['val']['wrapItemAndSub.']) ? $this->WMcObj->stdWrap($this->I['val']['wrapItemAndSub'], $this->I['val']['wrapItemAndSub.']) : $this->I['val']['wrapItemAndSub'];
239  $this->WMresult .= $part ? $this->WMcObj->wrap($this->I['theItem'], $part) : $this->I['theItem'];
240  }
241 
251  public function extProc_beforeAllWrap($item, $key)
252  {
253  return $item;
254  }
255 
263  public function extProc_finish()
264  {
265  // stdWrap:
266  if (is_array($this->mconf['stdWrap.'])) {
267  $this->WMresult = $this->WMcObj->stdWrap($this->WMresult, $this->mconf['stdWrap.']);
268  }
269  return $this->WMcObj->wrap($this->WMresult, $this->mconf['wrap']) . $this->WMextraScript;
270  }
271 }
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel='E_DEBUG')
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']