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