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