Source for file TMenuParser.php
Documentation is available at TMenuParser.php
namespace
Adianti \
Widget \
Menu ;
* @author Pablo Dall'Oglio
* @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
* @license http://www.adianti.com.br/framework-license
* @param $xml_file file path
$xml =
new SimpleXMLElement ( $menu_string ) ;
foreach ( $xml as $xmlElement )
$atts =
$xmlElement -> attributes ( ) ;
$label = (string)
$atts [ 'label' ] ;
$action = (string)
$xmlElement -> action ;
$icon = (string)
$xmlElement -> icon ;
$this -> paths [ $action ] =
[ $label ] ;
if ( substr ( $label , 0 , 3 ) ==
'_t{' )
$label =
_t ( substr ( $label , 3 , -
1 ) , 3 , -
1 ) ;
$this -> parse ( $xmlElement -> menu -> menuitem , array ( $label )) ;
* Parse a XMLElement reading menu entries
* @param $xml A SimpleXMLElement Object
private function parse ( $xml , $path )
foreach ( $xml as $xmlElement )
$atts =
$xmlElement -> attributes ( ) ;
$label = (string)
$atts [ 'label' ] ;
$action = (string)
$xmlElement -> action ;
if ( substr ( $label , 0 , 3 ) ==
'_t{' )
$label =
_t ( substr ( $label , 3 , -
1 ) , 3 , -
1 ) ;
if ( strpos ( $action , '#' ) !==
FALSE )
list
( $action , $method ) =
explode ( '#' , $action ) ;
$icon = (string)
$xmlElement -> icon ;
$this -> parse ( $xmlElement -> menu -> menuitem , array_merge ( $path , array ( $label ))) ;
// just child nodes have actions
$this -> paths [ $action ] =
array_merge ( $path , array ( $label )) ;
* Return an indexed array of programs
foreach ( $this -> paths as $action =>
$path )
* Return the controller path
public function getPath ( $controller )
return isset
( $this -> paths [ $controller ] ) ?
$this -> paths [ $controller ] :
null ;
* Check if a module exists
$xml_doc =
new DomDocument ;
$xml_doc -> load ( $this -> path ) ;
$xml_doc -> encoding =
'utf-8' ;
foreach ( $xml_doc -> getElementsByTagName ( 'menuitem' ) as $node )
$node_label =
$node -> getAttribute ( 'label' ) ;
foreach ( $node -> childNodes as $subnode )
if ( $subnode instanceof
DOMElement )
if ( $subnode -> tagName ==
'menu' and $node_label ==
$module )
$xml_doc =
new DomDocument ;
$xml_doc -> preserveWhiteSpace =
false ;
$xml_doc -> formatOutput =
true ;
$xml_doc -> load ( $this -> path ) ;
$xml_doc -> encoding =
'utf-8' ;
foreach ( $xml_doc -> getElementsByTagName ( 'menuitem' ) as $node )
$node_label =
$node -> getAttribute ( 'label' ) ;
foreach ( $node -> childNodes as $subnode )
if ( $subnode instanceof
DOMElement )
if ( $subnode -> tagName ==
'menu' )
$modules [ $node_label ] =
$node_label ;