require_once PATH_TO_ROOT . '/admin/admin_header.php'; $id = retrieve(REQUEST, 'id', 0); $id_post = retrieve(POST, 'id', 0); $action = retrieve(REQUEST, 'action', ''); $action_post = retrieve(POST, 'action', ''); if ($action_post == 'save') { // Save a Menu (New / Edit) $menu = null; $menu_name = retrieve(POST, 'name', '', TSTRING_UNCHANGE); if (!empty($id_post)) { // Edit the Menu $menu = MenuService::load($id_post); $menu->set_title($menu_name); } else { // Add the new Menu $menu = new ContentMenu($menu_name); } if (!$menu instanceof ContentMenu) { AppContext::get_response()->redirect('menus.php'); } $menu->enabled(retrieve(POST, 'activ', Menu::MENU_NOT_ENABLED)); if ($menu->is_enabled()) { $menu->set_block(retrieve(POST, 'location', Menu::BLOCK_POSITION__NOT_ENABLED)); } $menu->set_hidden_with_small_screens((bool) retrieve(POST, 'hidden_with_small_screens', false)); $menu->set_auth(Authorizations::build_auth_array_from_form(Menu::MENU_AUTH_BIT)); $menu->set_display_title(retrieve(POST, 'display_title', false)); $menu->set_content(retrieve(POST, 'contents', '', TSTRING_UNCHANGE)); //Filters MenuAdminService::set_retrieved_filters($menu); MenuService::move($menu, $menu->get_block());
/** * @access private * @desc Build a Menu object from a database result * @param string[key] $db_result the map from the database with the Menu id and serialized object * @return Menu the menu object from the serialized one */ private static function initialize($db_result) { if (!class_exists($db_result['class'])) { $menu = new ContentMenu('Unable to load the menu'); $menu->set_content('Unable to load the menu with the following class : ' . $db_result['class']); } else { $menu = unserialize($db_result['object']); } // Synchronize the object and the database $menu->id($db_result['id']); $menu->enabled($db_result['enabled']); $menu->set_block($db_result['block']); $menu->set_block_position($db_result['position']); if ($menu instanceof LinksMenu || $menu instanceof LinksMenuLink) { $menu->update_uid(); } return $menu; }