Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TMenuParser.php

Documentation is available at TMenuParser.php

  1. <?php
  2. namespace Adianti\Widget\Menu;
  3.  
  4. use Adianti\Core\AdiantiCoreTranslator;
  5. use Adianti\Util\AdiantiStringConversion;
  6. use SimpleXMLElement;
  7. use Exception;
  8. use DomDocument;
  9. use DomElement;
  10.  
  11. /**
  12.  * Menu Parser
  13.  *
  14.  * @version    7.4
  15.  * @package    widget
  16.  * @subpackage menu
  17.  * @author     Pablo Dall'Oglio
  18.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  19.  * @license    http://www.adianti.com.br/framework-license
  20.  */
  21. {
  22.     private $paths;
  23.     private $path;
  24.     
  25.     /**
  26.      * Parse a menu XML file
  27.      * @param $xml_file file path
  28.      */
  29.     public function __construct($xml_file)
  30.     {
  31.         $this->path  $xml_file;
  32.         $this->paths [];
  33.         
  34.         if (file_exists($xml_file))
  35.         {
  36.             $menu_string AdiantiStringConversion::assureUnicode(file_get_contents($xml_file));
  37.             $xml new SimpleXMLElement($menu_string);
  38.             
  39.             foreach ($xml as $xmlElement)
  40.             {
  41.                 $atts   $xmlElement->attributes();
  42.                 $label  = (string) $atts['label'];
  43.                 $action = (string) $xmlElement-> action;
  44.                 $icon   = (string) $xmlElement-> icon;
  45.                 
  46.                 if ($action)
  47.                 {
  48.                     $this->paths[$action[$label];
  49.                 }
  50.                 
  51.                 if (substr($label03== '_t{')
  52.                 {
  53.                     $label _t(substr($label,3,-1)3-1);
  54.                 }
  55.                 
  56.                 $this->parse($xmlElement-> menu-> menuitemarray($label));
  57.             }
  58.         }
  59.         else
  60.         {
  61.             throw new Exception(AdiantiCoreTranslator::translate('File not found'': ' $xml_file);
  62.         }
  63.     }
  64.     
  65.     /**
  66.      * Parse a XMLElement reading menu entries
  67.      * @param $xml A SimpleXMLElement Object
  68.      */
  69.     private function parse($xml$path)
  70.     {
  71.         $i 0;
  72.         if ($xml)
  73.         {
  74.             foreach ($xml as $xmlElement)
  75.             {
  76.                 $atts   $xmlElement->attributes();
  77.                 $label  = (string) $atts['label'];
  78.                 $action = (string) $xmlElement-> action;
  79.                 
  80.                 if (substr($label03== '_t{')
  81.                 {
  82.                     $label _t(substr($label,3,-1)3-1);
  83.                 }
  84.                 
  85.                 if (strpos($action'#'!== FALSE)
  86.                 {
  87.                     list($action$methodexplode('#'$action);
  88.                 }
  89.                 $icon   = (string) $xmlElement-> icon;
  90.                 
  91.                 if ($xmlElement->menu)
  92.                 {
  93.                     $this->parse($xmlElement-> menu-> menuitemarray_merge($patharray($label)));
  94.                 }
  95.                 
  96.                 // just child nodes have actions
  97.                 if ($action)
  98.                 {
  99.                     $this->paths[$actionarray_merge($patharray($label));
  100.                 }
  101.             }
  102.         }
  103.     }
  104.     
  105.     /**
  106.      * Return an indexed array of programs
  107.      */
  108.     public function getIndexedPrograms()
  109.     {
  110.         $programs [];
  111.         foreach ($this->paths as $action => $path)
  112.         {
  113.             $programs[$actionarray_pop($path);
  114.         }
  115.         return $programs;
  116.     }
  117.     
  118.     /**
  119.      * Return the controller path
  120.      */
  121.     public function getPath($controller)
  122.     {
  123.         return isset($this->paths[$controller]$this->paths[$controllernull;
  124.     }
  125.     
  126.     /**
  127.      * Check if a module exists
  128.      */
  129.     public function moduleExists($module)
  130.     {
  131.         $xml_doc new DomDocument;
  132.         $xml_doc->load($this->path);
  133.         $xml_doc->encoding 'utf-8';
  134.         
  135.         foreach ($xml_doc->getElementsByTagName('menuitem'as $node)
  136.         {
  137.             $node_label $node->getAttribute('label');
  138.             foreach ($node->childNodes as $subnode)
  139.             {
  140.                 if ($subnode instanceof DOMElement)
  141.                 {
  142.                     if ($subnode->tagName == 'menu' and $node_label == $module)
  143.                     {
  144.                         return true;
  145.                     }
  146.                 }
  147.             }
  148.         }
  149.         
  150.         return false;
  151.     }
  152.     
  153.     /**
  154.      * Get Modules
  155.      */
  156.     public function getModules()
  157.     {
  158.         $xml_doc new DomDocument;
  159.         $xml_doc->preserveWhiteSpace false;
  160.         $xml_doc->formatOutput true;
  161.         $xml_doc->load($this->path);
  162.         $xml_doc->encoding 'utf-8';
  163.         
  164.         $modules [];
  165.         
  166.         foreach ($xml_doc->getElementsByTagName('menuitem'as $node)
  167.         {
  168.             $node_label $node->getAttribute('label');
  169.             foreach ($node->childNodes as $subnode)
  170.             {
  171.                 if ($subnode instanceof DOMElement)
  172.                 {
  173.                     if ($subnode->tagName == 'menu')
  174.                     {
  175.                         $modules$node_label $node_label;
  176.                     }
  177.                 }
  178.             }
  179.         }
  180.         
  181.         return $modules;
  182.     }
  183. }