Skip to content

Instantly share code, notes, and snippets.

@slawkens
Last active December 20, 2024 19:18
Show Gist options
  • Save slawkens/c65bb5b25a94780894de9fcbfe035d4f to your computer and use it in GitHub Desktop.
Save slawkens/c65bb5b25a94780894de9fcbfe035d4f to your computer and use it in GitHub Desktop.
Import odin menus to MyAAC
<?php
/**
* Paste this into system/pages/import_menus.php
*
* Then visit http://localhost/?import_menus
* The menus will be created.
**/
$menus = [
MENU_CATEGORY_NEWS => [
'Latest News' => 'news',
'News Archive' => 'news/archive',
'Changelog' => 'changelog',
],
MENU_CATEGORY_ACCOUNT => [
'Account Management' => 'account/manage',
'Create Account' => 'account/create',
'Lost Account?' => 'account/lost',
'Server Rules' => 'rules',
'Downloads' => 'downloads',
],
MENU_CATEGORY_COMMUNITY => [
'Characters' => 'characters',
'Who is Online?' => 'online',
'Highscores' => 'highscores',
'Last Kills' => 'last-kills',
'Houses' => 'houses',
'Guilds' => 'guilds',
'Polls' => 'polls',
'Bans' => 'bans',
'Support List' => 'team',
],
MENU_CATEGORY_FORUM => [
'Forum' => 'forum',
],
MENU_CATEGORY_LIBRARY => [
'Monsters' => 'creatures',
'Spells' => 'spells',
'Commands' => 'commands',
'Exp Stages' => 'exp-stages',
'Gallery' => 'gallery',
'Server Info' => 'server-info',
'Exp Table' => 'exp-table',
'FAQ' => 'faq',
],
MENU_CATEGORY_SHOP => [
'Buy Points' => 'points',
'Shop Offer' => 'gifts',
'Shop History' => 'gifts/history',
],
];
installMenus('odin', $menus);
success('Menus for Odin imported.');
function installMenus($templateName, $menus, $clearOld = false)
{
global $db;
if ($clearOld) {
$db->query('DELETE FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($templateName));
}
// check if menus already exist
$query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($templateName) . ' LIMIT 1;');
if ($query->rowCount() > 0) {
return;
}
foreach ($menus as $category => $_menus) {
$i = 0;
foreach ($_menus as $name => $link) {
$color = '';
$blank = 0;
if (is_array($link)) {
if (isset($link['name'])) {
$name = $link['name'];
}
if (isset($link['color'])) {
$color = $link['color'];
}
if (isset($link['blank'])) {
$blank = $link['blank'] ? 1 : 0;
}
$link = $link['link'];
}
$insert_array = [
'template' => $templateName,
'name' => $name,
'link' => $link,
'category' => $category,
'ordering' => $i++,
'blank' => $blank,
'color' => $color,
];
$db->insert(TABLE_PREFIX . 'menu', $insert_array);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment