TYPO3  7.6
TextMenuContentObject.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject\Menu;
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 
17 
22 {
30  public function generate()
31  {
32  $NOconf = array();
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  $this->WMsubmenuObjSuffixes = $this->tmpl->splitConfArray(array('sOSuffix' => $this->mconf['submenuObjSuffixes']), $this->WMmenuItems);
63  $this->extProc_init();
64  foreach ($this->result as $key => $val) {
65  $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ']++;
66  $GLOBALS['TSFE']->register['count_MENUOBJ']++;
67  // Initialize the cObj with the page record of the menu item
68  $this->WMcObj->start($this->menuArr[$key], 'pages');
69  $this->I = array();
70  $this->I['key'] = $key;
71  $this->I['INPfix'] = ($this->imgNameNotRandom ? '' : '_' . $this->INPfixMD5) . '_' . $key;
72  $this->I['val'] = $val;
73  $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']);
74  $this->I['uid'] = $this->menuArr[$key]['uid'];
75  $this->I['mount_pid'] = $this->menuArr[$key]['mount_pid'];
76  $this->I['pid'] = $this->menuArr[$key]['pid'];
77  $this->I['spacer'] = $this->menuArr[$key]['isSpacer'];
78  // Set access key
79  if ($this->mconf['accessKey']) {
80  $this->I['accessKey'] = $this->accessKey($this->I['title']);
81  } else {
82  $this->I['accessKey'] = array();
83  }
84  // Make link tag
85  $this->I['val']['ATagParams'] = $this->WMcObj->getATagParams($this->I['val']);
86  if (isset($this->I['val']['additionalParams.'])) {
87  $this->I['val']['additionalParams'] = $this->WMcObj->stdWrap($this->I['val']['additionalParams'], $this->I['val']['additionalParams.']);
88  }
89  $this->I['linkHREF'] = $this->link($key, $this->I['val']['altTarget'], $this->mconf['forceTypeValue']);
90  if (empty($this->I['linkHREF'])) {
91  $this->I['val']['doNotLinkIt'] = 1;
92  }
93  // Title attribute of links:
94  $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'];
95  if ($titleAttrValue !== '') {
96  $this->I['linkHREF']['title'] = $titleAttrValue;
97  }
98 
99  // Calling extra processing function
100  $this->extProc_beforeLinking($key);
101  // stdWrap for doNotLinkIt
102  if (isset($this->I['val']['doNotLinkIt.'])) {
103  $this->I['val']['doNotLinkIt'] = $this->WMcObj->stdWrap($this->I['val']['doNotLinkIt'], $this->I['val']['doNotLinkIt.']);
104  }
105  // Compile link tag
106  if (!$this->I['val']['doNotLinkIt']) {
107  $this->I['val']['doNotLinkIt'] = 0;
108  }
109  if (!$this->I['spacer'] && $this->I['val']['doNotLinkIt'] != 1) {
110  $this->setATagParts();
111  } else {
112  $this->I['A1'] = '';
113  $this->I['A2'] = '';
114  }
115  // ATagBeforeWrap processing:
116  if ($this->I['val']['ATagBeforeWrap']) {
117  $wrapPartsBefore = explode('|', $this->I['val']['linkWrap']);
118  $wrapPartsAfter = array('', '');
119  } else {
120  $wrapPartsBefore = array('', '');
121  $wrapPartsAfter = explode('|', $this->I['val']['linkWrap']);
122  }
123  if ($this->I['val']['stdWrap2'] || isset($this->I['val']['stdWrap2.'])) {
124  $stdWrap2 = isset($this->I['val']['stdWrap2.']) ? $this->WMcObj->stdWrap('|', $this->I['val']['stdWrap2.']) : '|';
125  $wrapPartsStdWrap = explode($this->I['val']['stdWrap2'] ? $this->I['val']['stdWrap2'] : '|', $stdWrap2);
126  } else {
127  $wrapPartsStdWrap = array('', '');
128  }
129  // Make before, middle and after parts
130  $this->I['parts'] = array();
131  $this->I['parts']['before'] = $this->getBeforeAfter('before');
132  $this->I['parts']['stdWrap2_begin'] = $wrapPartsStdWrap[0];
133  // stdWrap for doNotShowLink
134  if (isset($this->I['val']['doNotShowLink.'])) {
135  $this->I['val']['doNotShowLink'] = $this->WMcObj->stdWrap($this->I['val']['doNotShowLink'], $this->I['val']['doNotShowLink.']);
136  }
137  if (!$this->I['val']['doNotShowLink']) {
138  $this->I['parts']['notATagBeforeWrap_begin'] = $wrapPartsAfter[0];
139  $this->I['parts']['ATag_begin'] = $this->I['A1'];
140  $this->I['parts']['ATagBeforeWrap_begin'] = $wrapPartsBefore[0];
141  $this->I['parts']['title'] = $this->I['title'];
142  $this->I['parts']['ATagBeforeWrap_end'] = $wrapPartsBefore[1];
143  $this->I['parts']['ATag_end'] = $this->I['A2'];
144  $this->I['parts']['notATagBeforeWrap_end'] = $wrapPartsAfter[1];
145  }
146  $this->I['parts']['stdWrap2_end'] = $wrapPartsStdWrap[1];
147  $this->I['parts']['after'] = $this->getBeforeAfter('after');
148  // Passing I to a user function
149  if ($this->mconf['IProcFunc']) {
150  $this->I = $this->userProcess('IProcFunc', $this->I);
151  }
152  // Merge parts + beforeAllWrap
153  $this->I['theItem'] = implode('', $this->I['parts']);
154  $this->I['theItem'] = $this->extProc_beforeAllWrap($this->I['theItem'], $key);
155  // allWrap:
156  $allWrap = isset($this->I['val']['allWrap.']) ? $this->WMcObj->stdWrap($this->I['val']['allWrap'], $this->I['val']['allWrap.']) : $this->I['val']['allWrap'];
157  $this->I['theItem'] = $this->WMcObj->wrap($this->I['theItem'], $allWrap);
158  if ($this->I['val']['subst_elementUid']) {
159  $this->I['theItem'] = str_replace('{elementUid}', $this->I['uid'], $this->I['theItem']);
160  }
161  // allStdWrap:
162  if (is_array($this->I['val']['allStdWrap.'])) {
163  $this->I['theItem'] = $this->WMcObj->stdWrap($this->I['theItem'], $this->I['val']['allStdWrap.']);
164  }
165  // Calling extra processing function
166  $this->extProc_afterLinking($key);
167  }
168  return $this->extProc_finish();
169  }
170 
177  public function getBeforeAfter($pref)
178  {
179  $res = '';
180  if ($imgInfo = $this->WMcObj->getImgResource($this->I['val'][$pref . 'Img'], $this->I['val'][$pref . 'Img.'])) {
181  $theName = $this->imgNamePrefix . $this->I['uid'] . $this->I['INPfix'] . $pref;
182  $name = ' ' . $this->nameAttribute . '="' . $theName . '"';
183  $GLOBALS['TSFE']->imagesOnPage[] = $imgInfo[3];
184  $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"');
185  if (!strstr($res, 'alt="')) {
186  // Adding alt attribute if not set.
187  $res .= ' alt=""';
188  }
189  $res .= ' />';
190  if ($this->I['val'][$pref . 'ImgLink']) {
191  $res = $this->I['A1'] . $res . $this->I['A2'];
192  }
193  }
194  $processedPref = isset($this->I['val'][$pref . '.']) ? $this->WMcObj->stdWrap($this->I['val'][$pref], $this->I['val'][$pref . '.']) : $this->I['val'][$pref];
195  if (isset($this->I['val'][$pref . 'Wrap'])) {
196  return $this->WMcObj->wrap($res . $processedPref, $this->I['val'][$pref . 'Wrap']);
197  } else {
198  return $res . $processedPref;
199  }
200  }
201 
210  public function extProc_init()
211  {
212  }
213 
222  public function extProc_beforeLinking($key)
223  {
224  }
225 
235  public function extProc_afterLinking($key)
236  {
237  // Add part to the accumulated result + fetch submenus
238  if (!$this->I['spacer']) {
239  $this->I['theItem'] .= $this->subMenu($this->I['uid'], $this->WMsubmenuObjSuffixes[$key]['sOSuffix']);
240  }
241  $part = isset($this->I['val']['wrapItemAndSub.']) ? $this->WMcObj->stdWrap($this->I['val']['wrapItemAndSub'], $this->I['val']['wrapItemAndSub.']) : $this->I['val']['wrapItemAndSub'];
242  $this->WMresult .= $part ? $this->WMcObj->wrap($this->I['theItem'], $part) : $this->I['theItem'];
243  }
244 
254  public function extProc_beforeAllWrap($item, $key)
255  {
256  return $item;
257  }
258 
266  public function extProc_finish()
267  {
268  // stdWrap:
269  if (is_array($this->mconf['stdWrap.'])) {
270  $this->WMresult = $this->WMcObj->stdWrap($this->WMresult, $this->mconf['stdWrap.']);
271  }
272  return $this->WMcObj->wrap($this->WMresult, $this->mconf['wrap']) . $this->WMextraScript;
273  }
274 }