[TASK] Remove unneeded parenthesis on array-access
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / Menu / TextMenuContentObject.php
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
18 /**
19 * Extension class creating text based menus
20 */
21 class TextMenuContentObject extends AbstractMenuContentObject
22 {
23 /**
24 * Calls procesItemStates() so that the common configuration for the menu items are resolved into individual configuration per item.
25 * Sets the result for the new "normal state" in $this->result
26 *
27 * @return void
28 * @see AbstractMenuContentObject::procesItemStates()
29 */
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
44 /**
45 * Traverses the ->result array of menu items configuration (made by ->generate()) and renders each item.
46 * During the execution of this function many internal methods prefixed "extProc_" from this class is called and
47 * many of these are for now dummy functions. But they can be used for processing as they are used by the TMENU_LAYERS
48 * An instance of ContentObjectRenderer is also made and for each menu item rendered it is loaded with
49 * the record for that page so that any stdWrap properties that applies will have the current menu items record available.
50 *
51 * @return string The HTML for the menu (returns result through $this->extProc_finish(); )
52 */
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
171 /**
172 * Generates the before* and after* images for TMENUs
173 *
174 * @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
175 * @return string The resulting HTML of the image, if any.
176 */
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
202 /**
203 * Called right before the traversing of $this->result begins.
204 * Can be used for various initialization
205 *
206 * @return void
207 * @access private
208 * @see writeMenu()
209 */
210 public function extProc_init()
211 {
212 }
213
214 /**
215 * Called right before the creation of the link for the menu item
216 *
217 * @param int $key Pointer to $this->menuArr[$key] where the current menu element record is found
218 * @return void
219 * @access private
220 * @see writeMenu()
221 */
222 public function extProc_beforeLinking($key)
223 {
224 }
225
226 /**
227 * Called right after the creation of links for the menu item. This is also the last function call before the while-loop traversing menu items goes to the next item.
228 * This function MUST set $this->WMresult.=[HTML for menu item] to add the generated menu item to the internal accumulation of items.
229 *
230 * @param int $key Pointer to $this->menuArr[$key] where the current menu element record is found
231 * @return void
232 * @access private
233 * @see writeMenu()
234 */
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
245 /**
246 * Called before the "allWrap" happens on the menu item.
247 *
248 * @param string $item The current content of the menu item, $this->I['theItem'], passed along.
249 * @param int $key Pointer to $this->menuArr[$key] where the current menu element record is found
250 * @return string The modified version of $item, going back into $this->I['theItem']
251 * @access private
252 * @see writeMenu()
253 */
254 public function extProc_beforeAllWrap($item, $key)
255 {
256 return $item;
257 }
258
259 /**
260 * Called before the writeMenu() function returns (only if a menu was generated)
261 *
262 * @return string The total menu content should be returned by this function
263 * @access private
264 * @see writeMenu()
265 */
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 }