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