/** * 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; } }
/** * Build a MenuBar from a XML file * @param $xml_file path for the file */ public static function newFromXML($xml_file) { 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; if (in_array(ini_get('php-gtk.codepage'), array('ISO8859-1', 'ISO-8859-1'))) { $label = utf8_decode($label); } $menuItem = new TMenuItem($label, $action, $icon); $menubar->append($menuItem, $xmlElement->menu->menuitem); } return $menubar; } }