123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- <?php
- if (!defined('SMF'))
- die('No direct access...');
- function createMenu($menuData, $menuOptions = array())
- {
- global $context, $settings, $txt, $scripturl, $user_info;
-
-
- $context['max_menu_id'] = isset($context['max_menu_id']) ? $context['max_menu_id'] + 1 : 1;
-
- $context['menu_data_' . $context['max_menu_id']] = array();
- $menu_context = &$context['menu_data_' . $context['max_menu_id']];
-
- $menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action'];
-
- if (!empty($menu_context['current_action']))
- call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
-
- if (isset($menuOptions['current_area']) || isset($_GET['area']))
- $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
-
- $menu_context['extra_parameters'] = '';
- if (!empty($menuOptions['extra_url_parameters']))
- foreach ($menuOptions['extra_url_parameters'] as $key => $value)
- $menu_context['extra_parameters'] .= ';' . $key . '=' . $value;
-
- if (empty($menuOptions['disable_url_session_check']))
- $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
- $include_data = array();
-
- foreach ($menuData as $section_id => $section)
- {
-
- if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission'])))
- continue;
-
- foreach ($section['areas'] as $area_id => $area)
- {
-
- if ((!isset($area['enabled']) || $area['enabled'] != false) && (empty($area['permission']) || allowedTo($area['permission'])))
- {
-
- if (isset($area['label']) || (isset($txt[$area_id]) && !isset($area['select'])))
- {
-
- if (!isset($menu_context['current_area']))
- {
- $menu_context['current_area'] = $area_id;
- $include_data = $area;
- }
-
- if (empty($area['hidden']))
- {
-
- if (!isset($menu_context['sections'][$section_id]))
- $menu_context['sections'][$section_id]['title'] = $section['title'];
- $menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]);
-
- $menu_context['sections'][$section_id]['id'] = $section_id;
-
- if (isset($area['custom_url']))
- $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
-
- if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa')
- $menu_context['sections'][$section_id]['areas'][$area_id] = unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9'));
- elseif (isset($area['icon']))
- $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon']) ? '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt=""> ' : '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt=""> ';
- else
- $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '';
-
- if (!empty($menuOptions['do_big_icons']))
- {
- if (isset($area['bigicon']))
- $menu_context['sections'][$section_id]['areas'][$area_id]['bigicon'] = $area['bigicon'];
-
- elseif (isset($area['icon']))
- {
- if (file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon']))
- $menu_context['sections'][$section_id]['areas'][$area_id]['bigicon'] = $settings['images_url'] . '/admin/big/' . $area['icon'];
- elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
- $menu_context['sections'][$section_id]['areas'][$area_id]['bigicon'] = $settings['default_images_url'] . '/admin/big/' . $area['icon'];
- }
-
- if (empty($menu_context['sections'][$section_id]['areas'][$area_id]['bigicon']))
- $menu_context['sections'][$section_id]['areas'][$area_id]['bigicon'] = $settings['default_images_url'] . '/admin/big/default.png';
- }
-
- $menu_context['sections'][$section_id]['areas'][$area_id]['inactive'] = !empty($area['inactive']);
-
- if (!empty($area['subsections']))
- {
- $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'] = array();
- $first_sa = $last_sa = null;
- foreach ($area['subsections'] as $sa => $sub)
- {
- if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled'])))
- {
- if ($first_sa == null)
- $first_sa = $sa;
- $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]);
-
- if (isset($sub['url']))
- $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
-
- if ($menu_context['current_area'] == $area_id)
- {
-
- if (empty($first_sa))
- $first_sa = $sa;
-
- if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa)
- $menu_context['current_subsection'] = $sa;
-
- elseif (!isset($menu_context['current_subsection']) && !empty($sub[2]))
- $menu_context['current_subsection'] = $sa;
- }
-
- $last_sa = $sa;
- }
-
- else
- $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
- }
-
- if (!empty($menu_context['sections'][$section_id]['areas'][$area_id]['subsections']))
- {
- $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true;
- $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true;
- if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection']))
- $menu_context['current_subsection'] = $first_sa;
- }
- }
- }
- }
-
- if ($menu_context['current_area'] == $area_id && empty($found_section))
- {
-
- $found_section = true;
-
- $menu_context['current_section'] = $section_id;
- $menu_context['current_area'] = isset($area['select']) ? $area['select'] : $area_id;
-
- $include_data = $area;
- }
-
- elseif (empty($found_section) && empty($include_data))
- {
- $menu_context['current_section'] = $section_id;
- $backup_area = isset($area['select']) ? $area['select'] : $area_id;
- $include_data = $area;
- }
- }
- }
- }
-
- $menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action'];
-
- if (!empty($menu_context['current_section']))
- {
- $menu_context['sections'][$menu_context['current_section']]['selected'] = true;
- $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true;
- if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]))
- $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
- foreach ($menu_context['sections'] as $section_id => $section)
- foreach ($section['areas'] as $area_id => $area)
- {
- if (!isset($menu_context['sections'][$section_id]['url']))
- {
- $menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id;
- break;
- }
- }
- }
-
- if (isset($backup_area) && empty($found_section))
- $menu_context['current_area'] = $backup_area;
-
- if (empty($menu_context['sections']))
- {
-
- $context['max_menu_id']--;
- if ($context['max_menu_id'] == 0)
- unset($context['max_menu_id']);
- return false;
- }
-
- if (!WIRELESS)
- {
- loadTemplate(isset($menuOptions['template_name']) ? $menuOptions['template_name'] : 'GenericMenu');
- $menu_context['layer_name'] = (isset($menuOptions['layer_name']) ? $menuOptions['layer_name'] : 'generic_menu') . '_dropdown';
- $context['template_layers'][] = $menu_context['layer_name'];
- }
-
- if (empty($include_data))
- return false;
-
- $include_data += array(
- 'current_action' => $menu_context['current_action'],
- 'current_area' => $menu_context['current_area'],
- 'current_section' => $menu_context['current_section'],
- 'current_subsection' => !empty($menu_context['current_subsection']) ? $menu_context['current_subsection'] : '',
- );
- return $include_data;
- }
- function destroyMenu($menu_id = 'last')
- {
- global $context;
- $menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id;
- if (!isset($context[$menu_name]))
- return false;
- $layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']);
- if ($layer_index !== false)
- unset($context['template_layers'][$layer_index]);
- unset($context[$menu_name]);
- }
- ?>
|