TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
JavaScriptMenuContentObject.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 
21 
26 {
30  public $levels = 0;
31 
35  public $JSVarName = '';
36 
40  public $JSMenuName = '';
41 
47  public function writeMenu()
48  {
49  if (!$this->id) {
50  return '';
51  }
52 
53  $levels = MathUtility::forceIntegerInRange($this->mconf['levels'], 1, 5);
54  $this->levels = $levels;
55  $uniqueParam = GeneralUtility::shortMD5(microtime(), 5);
56  $this->JSVarName = 'eid' . $uniqueParam;
57  $this->JSMenuName = $this->mconf['menuName'] ?: 'JSmenu' . $uniqueParam;
58  $JScode = '
59 var ' . $this->JSMenuName . ' = new JSmenu(' . $levels . ', ' . GeneralUtility::quoteJSvalue($this->JSMenuName . 'Form') . ');';
60  for ($a = 1; $a <= $levels; $a++) {
61  $JScode .= '
62 var ' . $this->JSVarName . $a . '=0;';
63  }
64  $JScode .= $this->generate_level($levels, 1, $this->id, $this->menuArr, $this->MP_array) . LF;
65  $GLOBALS['TSFE']->additionalHeaderData['JSMenuCode'] = '<script type="text/javascript" src="' . $GLOBALS['TSFE']->absRefPrefix . ExtensionManagementUtility::siteRelPath('frontend') . 'Resources/Public/JavaScript/jsfunc.menu.js"></script>';
66  $GLOBALS['TSFE']->additionalJavaScript['JSCode'] .= $JScode;
67  // Printing:
68  $allFormCode = '';
69  for ($a = 1; $a <= $this->levels; $a++) {
70  $formCode = '';
71  $levelConf = $this->mconf[$a . '.'];
72  $length = $levelConf['width'] ?: 14;
73  $lengthStr = '';
74  for ($b = 0; $b < $length; $b++) {
75  $lengthStr .= '_';
76  }
77  $height = $levelConf['elements'] ?: 5;
78  $formCode .= '<select name="selector' . $a . '" onchange="' . $this->JSMenuName . '.act(' . $a . ');"' . ($levelConf['additionalParams'] ? ' ' . $levelConf['additionalParams'] : '') . '>';
79  for ($b = 0; $b < $height; $b++) {
80  $formCode .= '<option value="0">';
81  if ($b === 0) {
82  $formCode .= $lengthStr;
83  }
84  $formCode .= '</option>';
85  }
86  $formCode .= '</select>';
87  $allFormCode .= $this->WMcObj->wrap($formCode, $levelConf['wrap']);
88  }
89  $formContent = $this->WMcObj->wrap($allFormCode, $this->mconf['wrap']);
90  $formCode = '<form action="" method="post" style="margin: 0 0 0 0;" name="' . $this->JSMenuName . 'Form">' . $formContent . '</form>';
91  $formCode .= '<script type="text/javascript"> /*<![CDATA[*/ ' . $this->JSMenuName . '.writeOut(1,' . $this->JSMenuName . '.openID,1); /*]]>*/ </script>';
92  return $this->WMcObj->wrap($formCode, $this->mconf['wrapAfterTags']);
93  }
94 
107  public function generate_level($levels, $count, $pid, $menuItemArray = '', $MP_array = [])
108  {
109  $count = (int)$count;
110  $levelConf = $this->mconf[$count . '.'];
111  // Translate PID to a mount page, if any:
112  $mount_info = $this->sys_page->getMountPointInfo($pid);
113  if (is_array($mount_info)) {
114  $MP_array[] = $mount_info['MPvar'];
115  $pid = $mount_info['mount_pid'];
116  }
117  // UIDs to ban:
118  $banUidArray = $this->getBannedUids();
119  // Initializing variables:
120  $var = $this->JSVarName;
121  $menuName = $this->JSMenuName;
122  $parent = $count === 1 ? 0 : $var . ($count - 1);
123  $prev = 0;
124  $c = 0;
125  $codeLines = '';
126  $menuItems = is_array($menuItemArray) ? $menuItemArray : $this->sys_page->getMenu($pid);
127  foreach ($menuItems as $uid => $data) {
128  // $data['_MP_PARAM'] contains MP param for overlay mount points (MPs with "substitute this page" set)
129  // if present: add param to copy of MP array (copy used for that submenu branch only)
130  $MP_array_sub = $MP_array;
131  if (array_key_exists('_MP_PARAM', $data) && $data['_MP_PARAM']) {
132  $MP_array_sub[] = $data['_MP_PARAM'];
133  }
134  // Set "&MP=" var:
135  $MP_var = implode(',', $MP_array_sub);
136  $MP_params = $MP_var ? '&MP=' . rawurlencode($MP_var) : '';
137  // If item is a spacer, $spacer is set
138  $spacer = GeneralUtility::inList($this->spacerIDList, $data['doktype']);
139  // If the spacer-function is not enabled, spacers will not enter the $menuArr
140  if ($this->mconf['SPC'] || !$spacer) {
141  // Page may not be 'not_in_menu' or 'Backend User Section' + not in banned uid's
142  if (!GeneralUtility::inList($this->doktypeExcludeList, $data['doktype']) && (!$data['nav_hide'] || $this->conf['includeNotInMenu']) && !ArrayUtility::inArray($banUidArray, $uid)) {
143  if ($count < $levels) {
144  $addLines = $this->generate_level($levels, $count + 1, $data['uid'], '', $MP_array_sub);
145  } else {
146  $addLines = '';
147  }
148  $title = $data['title'];
149  $url = '';
150  $target = '';
151  if (!$addLines && !$levelConf['noLink'] || $levelConf['alwaysLink']) {
152  $LD = $this->menuTypoLink($data, $this->mconf['target'], '', '', [], $MP_params, $this->mconf['forceTypeValue']);
153  // If access restricted pages should be shown in menus, change the link of such pages to link to a redirection page:
154  $this->changeLinksForAccessRestrictedPages($LD, $data, $this->mconf['target'], $this->mconf['forceTypeValue']);
155  $url = $this->getTypoScriptFrontendController()->baseUrlWrap($LD['totalURL']);
156  $target = $LD['target'];
157  }
158  $codeLines .= LF . $var . $count . '=' . $menuName . '.add(' . $parent . ',' . $prev . ',0,' . GeneralUtility::quoteJSvalue($title, true) . ',' . GeneralUtility::quoteJSvalue($url, true) . ',' . GeneralUtility::quoteJSvalue($target, true) . ');';
159  // If the active one should be chosen...
160  $active = $levelConf['showActive'] && $this->isActive($data['uid'], $MP_var);
161  // If the first item should be shown
162  $first = !$c && $levelConf['showFirst'];
163  // do it...
164  if ($active || $first) {
165  if ($count === 1) {
166  $codeLines .= LF . $menuName . '.openID = ' . $var . $count . ';';
167  } else {
168  $codeLines .= LF . $menuName . '.entry[' . $parent . '].openID = ' . $var . $count . ';';
169  }
170  }
171  // Add submenu...
172  $codeLines .= $addLines;
173  $prev = $var . $count;
174  $c++;
175  }
176  }
177  }
178  if ($this->mconf['firstLabelGeneral'] && !$levelConf['firstLabel']) {
179  $levelConf['firstLabel'] = $this->mconf['firstLabelGeneral'];
180  }
181  if ($levelConf['firstLabel'] && $codeLines) {
182  $codeLines .= LF . $menuName . '.defTopTitle[' . $count . '] = ' . GeneralUtility::quoteJSvalue($levelConf['firstLabel'], true) . ';';
183  }
184  return $codeLines;
185  }
186 }
generate_level($levels, $count, $pid, $menuItemArray= '', $MP_array=[])
menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray= '', $addParams= '', $typeOverride= '')
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31