/** * Build a MenuBar from a XML file * @param $xml_file path for the file * @param $permission_callback check permission callback */ public static function newFromXML($xml_file, $permission_callback = NULL, $bar_class = 'nav navbar-nav', $menu_class = 'dropdown-menu', $item_class = '') { if (file_exists($xml_file)) { $menu_string = file_get_contents($xml_file); if (utf8_encode(utf8_decode($menu_string)) == $menu_string) { $xml = new SimpleXMLElement($menu_string); } else { $xml = new SimpleXMLElement(utf8_encode($menu_string)); } $menubar = new TMenuBar(); $ul = new TElement('ul'); $ul->{'class'} = $bar_class; $menubar->add($ul); foreach ($xml as $xmlElement) { $atts = $xmlElement->attributes(); $label = (string) $atts['label']; $action = (string) $xmlElement->action; $icon = (string) $xmlElement->icon; $item = new TMenuItem($label, $action, $icon); $menu = new TMenu($xmlElement->menu->menuitem, $permission_callback, 1, $menu_class, $item_class); // check children count (permissions) if (count($menu->getMenuItems()) > 0) { $item->setMenu($menu); $item->{'class'} = 'active'; $ul->add($item); } else { if ($action) { $ul->add($item); } } } return $menubar; } }
/** * Build a MenuBar from a XML file * @param $xml_file path for the file * @param $permission_callback check permission callback */ public static function newFromXML($xml_file, $permission_callback = NULL, $bar_class = 'nav navbar-nav', $menu_class = 'dropdown-menu', $item_class = '') { if (file_exists($xml_file)) { $menu_string = file_get_contents($xml_file); if (utf8_encode(utf8_decode($menu_string)) == $menu_string) { $xml = new SimpleXMLElement($menu_string); } else { $xml = new SimpleXMLElement(utf8_encode($menu_string)); } $menubar = new TMenuBar(); $menubar->{'class'} = $bar_class; foreach ($xml as $xmlElement) { $atts = $xmlElement->attributes(); $label = (string) $atts['label']; $action = (string) $xmlElement->action; $icon = (string) $xmlElement->icon; $button_div = new TElement('div'); $button_div->{'class'} = 'btn-group'; $button = new TElement('button'); $button->{'data-toggle'} = 'dropdown'; $button->{'class'} = 'btn btn-default dropdown-toggle'; $button->add($label); $span = new TElement('span'); $span->{'class'} = 'caret'; $span->add(''); $button->add($span); $menu = new TMenu($xmlElement->menu->menuitem, $permission_callback, 1, $menu_class, $item_class); // check children count (permissions) if (count($menu->getMenuItems()) > 0) { $button_div->add($button); $button_div->add($menu); $menubar->add($button_div); } } return $menubar; } }
<?php use Adianti\Control\TPage; use Adianti\Registry\TSession; use Adianti\Widget\Menu\TMenu; require_once 'init.php'; $uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $template = 'theme1'; new TSession(); $menu_string = ''; if (TSession::getValue('logged')) { $content = file_get_contents("app/templates/{$template}/layout.html"); ob_start(); $callback = array('PermissaoSistema', 'checkPermission'); $xml = new SimpleXMLElement(file_get_contents('menu.xml')); $menu = new TMenu($xml, $callback, 0, 'nav collapse', ''); $menu->class = 'nav'; $menu->id = 'side-menu'; $menu->show(); $menu_string = ob_get_clean(); } else { $content = file_get_contents("app/templates/{$template}/login.html"); } $content = TApplicationTranslator::translateTemplate($content); $content = str_replace('{LIBRARIES}', file_get_contents("app/templates/{$template}/libraries.html"), $content); $content = str_replace('{URI}', $uri, $content); $content = str_replace('{class}', isset($_REQUEST['class']) ? $_REQUEST['class'] : '', $content); $content = str_replace('{template}', $template, $content); $content = str_replace('{MENU}', $menu_string, $content); $content = str_replace('{username}', TSession::getValue('nome'), $content); $css = TPage::getLoadedCSS();