Chris@76: 'int', 'id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'), Chris@76: array( Chris@76: array( Chris@76: $user_info['id'], Chris@76: $settings['theme_id'], Chris@76: 'use_sidebar_menu', Chris@76: empty($options['use_sidebar_menu']) ? '1' : '0', Chris@76: ), Chris@76: ), Chris@76: array('id_member', 'id_theme', 'variable') Chris@76: ); Chris@76: Chris@76: // Clear the theme settings cache for this user. Chris@76: $themes = explode(',', $modSettings['knownThemes']); Chris@76: foreach ($themes as $theme) Chris@76: cache_put_data('theme_settings-' . $theme . ':' . $user_info['id'], null, 60); Chris@76: Chris@76: // Redirect as this seems to work best. Chris@76: $redirect_url = isset($menuOptions['toggle_redirect_url']) ? $menuOptions['toggle_redirect_url'] : 'action=' . (isset($_GET['action']) ? $_GET['action'] : 'admin') . ';area=' . (isset($_GET['area']) ? $_GET['area'] : 'index') . ';sa=' . (isset($_GET['sa']) ? $_GET['sa'] : 'settings') . (isset($_GET['u']) ? ';u=' . $_GET['u'] : '') . ';' . $context['session_var'] . '=' . $context['session_id']; Chris@76: redirectexit($redirect_url); Chris@76: } Chris@76: Chris@76: // Work out where we should get our images from. Chris@76: $context['menu_image_path'] = file_exists($settings['theme_dir'] . '/images/admin/change_menu.png') ? $settings['images_url'] . '/admin' : $settings['default_images_url'] . '/admin'; Chris@76: Chris@76: /* Note menuData is array of form: Chris@76: Chris@76: Possible fields: Chris@76: For Section: Chris@76: string $title: Section title. Chris@76: bool $enabled: Should section be shown? Chris@76: array $areas: Array of areas within this section. Chris@76: array $permission: Permission required to access the whole section. Chris@76: Chris@76: For Areas: Chris@76: array $permission: Array of permissions to determine who can access this area. Chris@76: string $label: Optional text string for link (Otherwise $txt[$index] will be used) Chris@76: string $file: Name of source file required for this area. Chris@76: string $function: Function to call when area is selected. Chris@76: string $custom_url: URL to use for this menu item. Chris@76: bool $enabled: Should this area even be accessible? Chris@76: bool $hidden: Should this area be visible? Chris@76: string $select: If set this item will not be displayed - instead the item indexed here shall be. Chris@76: array $subsections: Array of subsections from this area. Chris@76: Chris@76: For Subsections: Chris@76: string 0: Text label for this subsection. Chris@76: array 1: Array of permissions to check for this subsection. Chris@76: bool 2: Is this the default subaction - if not set for any will default to first... Chris@76: bool enabled: Bool to say whether this should be enabled or not. Chris@76: */ Chris@76: Chris@76: // Every menu gets a unique ID, these are shown in first in, first out order. Chris@76: $context['max_menu_id'] = isset($context['max_menu_id']) ? $context['max_menu_id'] + 1 : 1; Chris@76: Chris@76: // This will be all the data for this menu - and we'll make a shortcut to it to aid readability here. Chris@76: $context['menu_data_' . $context['max_menu_id']] = array(); Chris@76: $menu_context = &$context['menu_data_' . $context['max_menu_id']]; Chris@76: Chris@76: // What is the general action of this menu (i.e. $scripturl?action=XXXX. Chris@76: $menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action']; Chris@76: Chris@76: // What is the current area selected? Chris@76: if (isset($menuOptions['current_area']) || isset($_GET['area'])) Chris@76: $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; Chris@76: Chris@76: // Build a list of additional parameters that should go in the URL. Chris@76: $menu_context['extra_parameters'] = ''; Chris@76: if (!empty($menuOptions['extra_url_parameters'])) Chris@76: foreach ($menuOptions['extra_url_parameters'] as $key => $value) Chris@76: $menu_context['extra_parameters'] .= ';' . $key . '=' . $value; Chris@76: Chris@76: // Only include the session ID in the URL if it's strictly necessary. Chris@76: if (empty($menuOptions['disable_url_session_check'])) Chris@76: $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; Chris@76: Chris@76: $include_data = array(); Chris@76: Chris@76: // Now setup the context correctly. Chris@76: foreach ($menuData as $section_id => $section) Chris@76: { Chris@76: // Is this enabled - or has as permission check - which fails? Chris@76: if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) Chris@76: continue; Chris@76: Chris@76: // Now we cycle through the sections to pick the right area. Chris@76: foreach ($section['areas'] as $area_id => $area) Chris@76: { Chris@76: // Can we do this? Chris@76: if ((!isset($area['enabled']) || $area['enabled'] != false) && (empty($area['permission']) || allowedTo($area['permission']))) Chris@76: { Chris@76: // Add it to the context... if it has some form of name! Chris@76: if (isset($area['label']) || (isset($txt[$area_id]) && !isset($area['select']))) Chris@76: { Chris@76: // If we haven't got an area then the first valid one is our choice. Chris@76: if (!isset($menu_context['current_area'])) Chris@76: { Chris@76: $menu_context['current_area'] = $area_id; Chris@76: $include_data = $area; Chris@76: } Chris@76: Chris@76: // If this is hidden from view don't do the rest. Chris@76: if (empty($area['hidden'])) Chris@76: { Chris@76: // First time this section? Chris@76: if (!isset($menu_context['sections'][$section_id])) Chris@76: $menu_context['sections'][$section_id]['title'] = $section['title']; Chris@76: Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]); Chris@76: // We'll need the ID as well... Chris@76: $menu_context['sections'][$section_id]['id'] = $section_id; Chris@76: // Does it have a custom URL? Chris@76: if (isset($area['custom_url'])) Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; Chris@76: Chris@76: // Does this area have its own icon? Chris@76: if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id] = unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9')); Chris@76: elseif (isset($area['icon'])) Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '  '; Chris@76: else Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = ''; Chris@76: Chris@76: // Did it have subsections? Chris@76: if (!empty($area['subsections'])) Chris@76: { Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'] = array(); Chris@76: $first_sa = $last_sa = null; Chris@76: foreach ($area['subsections'] as $sa => $sub) Chris@76: { Chris@76: if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled']))) Chris@76: { Chris@76: if ($first_sa == null) Chris@76: $first_sa = $sa; Chris@76: Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]); Chris@76: // Custom URL? Chris@76: if (isset($sub['url'])) Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; Chris@76: Chris@76: // A bit complicated - but is this set? Chris@76: if ($menu_context['current_area'] == $area_id) Chris@76: { Chris@76: // Save which is the first... Chris@76: if (empty($first_sa)) Chris@76: $first_sa = $sa; Chris@76: Chris@76: // Is this the current subsection? Chris@76: if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) Chris@76: $menu_context['current_subsection'] = $sa; Chris@76: // Otherwise is it the default? Chris@76: elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) Chris@76: $menu_context['current_subsection'] = $sa; Chris@76: } Chris@76: Chris@76: // Let's assume this is the last, for now. Chris@76: $last_sa = $sa; Chris@76: } Chris@76: // Mark it as disabled... Chris@76: else Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; Chris@76: } Chris@76: Chris@76: // Set which one is first, last and selected in the group. Chris@76: if (!empty($menu_context['sections'][$section_id]['areas'][$area_id]['subsections'])) Chris@76: { Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true; Chris@76: $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true; Chris@76: Chris@76: if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) Chris@76: $menu_context['current_subsection'] = $first_sa; Chris@76: } Chris@76: } Chris@76: } Chris@76: } Chris@76: Chris@76: // Is this the current section? Chris@76: if ($menu_context['current_area'] == $area_id && empty($found_section)) Chris@76: { Chris@76: // Only do this once? Chris@76: $found_section = true; Chris@76: Chris@76: // Update the context if required - as we can have areas pretending to be others. ;) Chris@76: $menu_context['current_section'] = $section_id; Chris@76: $menu_context['current_area'] = isset($area['select']) ? $area['select'] : $area_id; Chris@76: Chris@76: // This will be the data we return. Chris@76: $include_data = $area; Chris@76: } Chris@76: // Make sure we have something in case it's an invalid area. Chris@76: elseif (empty($found_section) && empty($include_data)) Chris@76: { Chris@76: $menu_context['current_section'] = $section_id; Chris@76: $backup_area = isset($area['select']) ? $area['select'] : $area_id; Chris@76: $include_data = $area; Chris@76: } Chris@76: } Chris@76: } Chris@76: } Chris@76: Chris@76: // Should we use a custom base url, or use the default? Chris@76: $menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action']; Chris@76: Chris@76: // What about the toggle url? Chris@76: $menu_context['toggle_url'] = isset($menuOptions['toggle_url']) ? $menuOptions['toggle_url'] : $menu_context['base_url'] . (!empty($menu_context['current_area']) ? ';area=' . $menu_context['current_area'] : '') . (!empty($menu_context['current_subsection']) ? ';sa=' . $menu_context['current_subsection'] : '') . $menu_context['extra_parameters'] . ';togglebar'; Chris@76: Chris@76: // If we didn't find the area we were looking for go to a default one. Chris@76: if (isset($backup_area) && empty($found_section)) Chris@76: $menu_context['current_area'] = $backup_area; Chris@76: Chris@76: // If still no data then return - nothing to show! Chris@76: if (empty($menu_context['sections'])) Chris@76: { Chris@76: // Never happened! Chris@76: $context['max_menu_id']--; Chris@76: if ($context['max_menu_id'] == 0) Chris@76: unset($context['max_menu_id']); Chris@76: Chris@76: return false; Chris@76: } Chris@76: Chris@76: // What type of menu is this? Chris@76: if (empty($menuOptions['menu_type'])) Chris@76: { Chris@76: $menuOptions['menu_type'] = '_' . (empty($options['use_sidebar_menu']) ? 'dropdown' : 'sidebar'); Chris@76: $menu_context['can_toggle_drop_down'] = !$user_info['is_guest'] && isset($settings['theme_version']) && $settings['theme_version'] >= 2.0; Chris@76: } Chris@76: else Chris@76: $menu_context['can_toggle_drop_down'] = !empty($menuOptions['can_toggle_drop_down']); Chris@76: Chris@76: // Almost there - load the template and add to the template layers. Chris@76: if (!WIRELESS) Chris@76: { Chris@76: loadTemplate(isset($menuOptions['template_name']) ? $menuOptions['template_name'] : 'GenericMenu'); Chris@76: $menu_context['layer_name'] = (isset($menuOptions['layer_name']) ? $menuOptions['layer_name'] : 'generic_menu') . $menuOptions['menu_type']; Chris@76: $context['template_layers'][] = $menu_context['layer_name']; Chris@76: } Chris@76: Chris@76: // Check we had something - for sanity sake. Chris@76: if (empty($include_data)) Chris@76: return false; Chris@76: Chris@76: // Finally - return information on the selected item. Chris@76: $include_data += array( Chris@76: 'current_action' => $menu_context['current_action'], Chris@76: 'current_area' => $menu_context['current_area'], Chris@76: 'current_section' => $menu_context['current_section'], Chris@76: 'current_subsection' => !empty($menu_context['current_subsection']) ? $menu_context['current_subsection'] : '', Chris@76: ); Chris@76: Chris@76: return $include_data; Chris@76: } Chris@76: Chris@76: // Delete a menu. Chris@76: function destroyMenu($menu_id = 'last') Chris@76: { Chris@76: global $context; Chris@76: Chris@76: $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; Chris@76: if (!isset($context[$menu_name])) Chris@76: return false; Chris@76: Chris@76: $layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']); Chris@76: if ($layer_index !== false) Chris@76: unset($context['template_layers'][$layer_index]); Chris@76: Chris@76: unset($context[$menu_name]); Chris@76: } Chris@76: Chris@76: ?>