[TASK] Remove superfluous parenthesis in sysext frontend
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / Menu / JavaScriptMenuContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject\Menu;
3
4 /**
5 * JavaScript/Selectorbox based menus
6 *
7 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
8 * @package TYPO3
9 * @subpackage tslib
10 */
11 class JavaScriptMenuContentObject extends \TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject {
12
13 /**
14 * Dummy. Should do nothing, because we don't use the result-array here!
15 *
16 * @return void
17 * @todo Define visibility
18 */
19 public function generate() {
20
21 }
22
23 /**
24 * Creates the HTML (mixture of a <form> and a JavaScript section) for the JavaScript menu (basically an array of selector boxes with onchange handlers)
25 *
26 * @return string The HTML code for the menu
27 * @todo Define visibility
28 */
29 public function writeMenu() {
30 if ($this->id) {
31 // Making levels:
32 $levels = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->mconf['levels'], 1, 5);
33 $this->levels = $levels;
34 $uniqueParam = \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5(microtime(), 5);
35 $this->JSVarName = 'eid' . $uniqueParam;
36 $this->JSMenuName = $this->mconf['menuName'] ? $this->mconf['menuName'] : 'JSmenu' . $uniqueParam;
37 $JScode = '
38 var ' . $this->JSMenuName . ' = new JSmenu(' . $levels . ', \'' . $this->JSMenuName . 'Form\');';
39 for ($a = 1; $a <= $levels; $a++) {
40 $JScode .= '
41 var ' . $this->JSVarName . $a . '=0;';
42 }
43 $JScode .= $this->generate_level($levels, 1, $this->id, $this->menuArr, $this->MP_array) . LF;
44 $GLOBALS['TSFE']->additionalHeaderData['JSMenuCode'] = '<script type="text/javascript" src="' . $GLOBALS['TSFE']->absRefPrefix . 't3lib/jsfunc.menu.js"></script>';
45 $GLOBALS['TSFE']->JSCode .= $JScode;
46 // Printing:
47 $allFormCode = '';
48 for ($a = 1; $a <= $this->levels; $a++) {
49 $formCode = '';
50 $levelConf = $this->mconf[$a . '.'];
51 $length = $levelConf['width'] ? $levelConf['width'] : 14;
52 $lenghtStr = '';
53 for ($b = 0; $b < $length; $b++) {
54 $lenghtStr .= '_';
55 }
56 $height = $levelConf['elements'] ? $levelConf['elements'] : 5;
57 $formCode .= '<select name="selector' . $a . '" onchange="' . $this->JSMenuName . '.act(' . $a . ');"' . ($levelConf['additionalParams'] ? ' ' . $levelConf['additionalParams'] : '') . '>';
58 for ($b = 0; $b < $height; $b++) {
59 $formCode .= '<option value="0">';
60 if ($b == 0) {
61 $formCode .= $lenghtStr;
62 }
63 $formCode .= '</option>';
64 }
65 $formCode .= '</select>';
66 $allFormCode .= $this->tmpl->wrap($formCode, $levelConf['wrap']);
67 }
68 $formCode = $this->tmpl->wrap($allFormCode, $this->mconf['wrap']);
69 $formCode = '<form action="" method="post" style="margin: 0 0 0 0;" name="' . $this->JSMenuName . 'Form">' . $formCode . '</form>';
70 $formCode .= '<script type="text/javascript"> /*<![CDATA[*/ ' . $this->JSMenuName . '.writeOut(1,' . $this->JSMenuName . '.openID,1); /*]]>*/ </script>';
71 return $this->tmpl->wrap($formCode, $this->mconf['wrapAfterTags']);
72 }
73 }
74
75 /**
76 * Generates a number of lines of JavaScript code for a menu level.
77 * Calls itself recursively for additional levels.
78 *
79 * @param integer $levels Number of levels to generate
80 * @param integer $count Current level being generated - and if this number is less than $levels it will call itself recursively with $count incremented
81 * @param integer $pid Page id of the starting point.
82 * @param array $menuItemArray $this->menuArr passed along
83 * @param array $MP_array Previous MP vars
84 * @return string JavaScript code lines.
85 * @access private
86 * @todo Define visibility
87 */
88 public function generate_level($levels, $count, $pid, $menuItemArray = '', $MP_array = array()) {
89 $levelConf = $this->mconf[$count . '.'];
90 // Translate PID to a mount page, if any:
91 $mount_info = $this->sys_page->getMountPointInfo($pid);
92 if (is_array($mount_info)) {
93 $MP_array[] = $mount_info['MPvar'];
94 $pid = $mount_info['mount_pid'];
95 }
96 // UIDs to ban:
97 $banUidArray = $this->getBannedUids();
98 // Initializing variables:
99 $var = $this->JSVarName;
100 $menuName = $this->JSMenuName;
101 $parent = $count == 1 ? 0 : $var . ($count - 1);
102 $prev = 0;
103 $c = 0;
104 $codeLines = '';
105 $menuItems = is_array($menuItemArray) ? $menuItemArray : $this->sys_page->getMenu($pid);
106 foreach ($menuItems as $uid => $data) {
107 // $data['_MP_PARAM'] contains MP param for overlay mount points (MPs with "substitute this page" set)
108 // if present: add param to copy of MP array (copy used for that submenu branch only)
109 $MP_array_sub = $MP_array;
110 if (array_key_exists('_MP_PARAM', $data) && $data['_MP_PARAM']) {
111 $MP_array_sub[] = $data['_MP_PARAM'];
112 }
113 // Set "&MP=" var:
114 $MP_var = implode(',', $MP_array_sub);
115 $MP_params = $MP_var ? '&MP=' . rawurlencode($MP_var) : '';
116 // If item is a spacer, $spacer is set
117 $spacer = \TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->spacerIDList, $data['doktype']) ? 1 : 0;
118 // If the spacer-function is not enabled, spacers will not enter the $menuArr
119 if ($this->mconf['SPC'] || !$spacer) {
120 // Page may not be 'not_in_menu' or 'Backend User Section' + not in banned uid's
121 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->doktypeExcludeList, $data['doktype']) && (!$data['nav_hide'] || $this->conf['includeNotInMenu']) && !\TYPO3\CMS\Core\Utility\GeneralUtility::inArray($banUidArray, $uid)) {
122 if ($count < $levels) {
123 $addLines = $this->generate_level($levels, $count + 1, $data['uid'], '', $MP_array_sub);
124 } else {
125 $addLines = '';
126 }
127 $title = $data['title'];
128 $url = '';
129 $target = '';
130 if (!$addLines && !$levelConf['noLink'] || $levelConf['alwaysLink']) {
131 $LD = $this->menuTypoLink($data, $this->mconf['target'], '', '', array(), $MP_params, $this->mconf['forceTypeValue']);
132 // If access restricted pages should be shown in menus, change the link of such pages to link to a redirection page:
133 $this->changeLinksForAccessRestrictedPages($LD, $data, $this->mconf['target'], $this->mconf['forceTypeValue']);
134 $url = $GLOBALS['TSFE']->baseUrlWrap($LD['totalURL']);
135 $target = $LD['target'];
136 }
137 $codeLines .= LF . $var . $count . '=' . $menuName . '.add(' . $parent . ',' . $prev . ',0,' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($title, TRUE) . ',' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($url, TRUE) . ',' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($target, TRUE) . ');';
138 // If the active one should be chosen...
139 $active = $levelConf['showActive'] && $this->isActive($data['uid'], $MP_var);
140 // If the first item should be shown
141 $first = !$c && $levelConf['showFirst'];
142 // do it...
143 if ($active || $first) {
144 if ($count == 1) {
145 $codeLines .= LF . $menuName . '.openID = ' . $var . $count . ';';
146 } else {
147 $codeLines .= LF . $menuName . '.entry[' . $parent . '].openID = ' . $var . $count . ';';
148 }
149 }
150 // Add submenu...
151 $codeLines .= $addLines;
152 $prev = $var . $count;
153 $c++;
154 }
155 }
156 }
157 if ($this->mconf['firstLabelGeneral'] && !$levelConf['firstLabel']) {
158 $levelConf['firstLabel'] = $this->mconf['firstLabelGeneral'];
159 }
160 if ($levelConf['firstLabel'] && $codeLines) {
161 $codeLines .= LF . $menuName . '.defTopTitle[' . $count . '] = ' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($levelConf['firstLabel'], TRUE) . ';';
162 }
163 return $codeLines;
164 }
165
166 }
167
168
169 ?>