/** * Build a MenuBar from a XML file * @param $xml_file path for the file */ public static function newFromXML($xml_file) { //TPage::include_js('lib/bootstrap/js/bootstrap-dropdown.js'); 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(); 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 dropdown-toggle'; $button->add($label); $span = new TElement('span'); $span->{'class'} = 'caret'; $span->add(''); $button->add($span); $menu = new TMenu($xmlElement->menu->menuitem); $button_div->add($button); $button_div->add($menu); $menubar->add($button_div); } 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) { 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(); 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 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); // check children count (permissions) if (count($menu->getMenuItems()) > 0) { $button_div->add($button); $button_div->add($menu); $menubar->add($button_div); } } return $menubar; } }