1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368:
<?php
if (!defined('SMF'))
die('No direct access...');
function createMenu($menuData, $menuOptions = array())
{
global $smcFunc, $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();
$menu_context['sections'] = 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'];
if (!empty($section['amt']))
$menu_context['sections'][$section_id]['amt'] = $section['amt'];
$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 (!empty($area['amt']))
$menu_context['sections'][$section_id]['areas'][$area_id]['amt'] = $area['amt'];
if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa')
{
$menu_context['sections'][$section_id]['areas'][$area_id] = $smcFunc['json_decode'](base64_decode('eyJsYWJlbCI6Ik9vbXBhIExvb21wYSIsInVybCI6Imh0dHBzOlwvXC9lbi53aWtpcGVkaWEub3JnXC93aWtpXC9Pb21wYV9Mb29tcGFzPyIsImljb24iOiI8aW1nIHNyYz1cImh0dHBzOlwvXC93d3cuc2ltcGxlbWFjaGluZXMub3JnXC9pbWFnZXNcL29vbXBhLmdpZlwiIGFsdD1cIkknbSBhbiBPb21wYSBMb29tcGFcIiBcLz4ifQ=='), true);
}
elseif (isset($area['icon']))
{
if (file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon']))
{
$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
}
elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
{
$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
}
else
$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="main_icons ' . $area['icon'] . '"></span>';
}
else
$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="main_icons ' . $area_id . '"></span>';
if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon']))
{
$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
}
elseif (isset($area['icon']))
{
if (substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif')
{
if (file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon']))
{
$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
}
elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
{
$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
}
}
$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']);
}
else
$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
$menu_context['sections'][$section_id]['areas'][$area_id]['plain_class'] = !empty($area['icon']) ? $area['icon'] : '';
$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 (!empty($sub['amt']))
$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['amt'] = $sub['amt'];
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;
}
}
}
}
foreach ($menu_context['sections'] as $section_id => $section)
{
if (!empty($section['areas']))
{
foreach ($section['areas'] as $area_id => $area)
{
if (!empty($area['subsections']))
{
foreach ($area['subsections'] as $sa => $sub)
{
if (empty($sub['disabled']))
break;
$menu_context['sections'][$section_id]['areas'][$area_id]['hide_subsections'] = true;
}
}
}
}
}
$menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action'];
if (isset($backup_area) && empty($found_section))
$menu_context['current_area'] = $backup_area;
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 (empty($menu_context['sections']))
{
$context['max_menu_id']--;
if ($context['max_menu_id'] == 0)
unset($context['max_menu_id']);
return false;
}
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]);
}
?>