Advertisement
fruffl

Untitled

Nov 5th, 2011
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.64 KB | None | 0 0
  1.         private function get_XML()
  2.         {
  3.             if($this->xml instanceOf DOMDocument)
  4.                 return $this->xml;
  5.            
  6.            
  7.             $this->xml = new DOMDocument;
  8.             $this->xml->formatOutput = true;
  9.             $this->xml->preserveWhiteSpace = true;
  10.             $this->xml->validateOnParse = true;
  11.            
  12.             return $this->xml;
  13.         }
  14.        
  15.         private function get_XMLConfig()
  16.         {
  17.             if(NULL === $this->xml_config)
  18.                 $this->xml_config = $this->get_XML()->createElement("config:group");
  19.            
  20.             return $this->xml_config;
  21.         }
  22.        
  23.         private function get_XMLPage()
  24.         {
  25.             if(NULL === $this->xml_page)
  26.                 $this->xml_page = $this->get_XML()->createElement("section:group");
  27.            
  28.             return $this->xml_page;
  29.         }
  30.  
  31.  
  32.  
  33.         private function load_XMLConfig(broadcast $loadstuff, type $type)
  34.         {
  35.             if(empty($loadstuff))
  36.                 $configurl = self::$data_config_file;
  37.             else
  38.                 $configurl = $loadstuff.DIRECTORY_SEPARATOR.self::$data_config_file;
  39.            
  40.            
  41.             if(FALSE !== ($r = $this->findConfig($configurl)))
  42.                 return $r;
  43.            
  44.            
  45.             $configdoc = NULL;
  46.            
  47.             $ispage = is_file(self::$broadcaster.$loadstuff.DIRECTORY_SEPARATOR.self::$data_page_file);
  48.            
  49.            
  50.             if(is_file($_pl = self::$broadcaster.$configurl))
  51.             {
  52.                 $configdoc = new DOMDocument;
  53.                 $configdoc->formatOutput = true;
  54.                 $configdoc->preserveWhiteSpace = true;
  55.                
  56.                 if($type == 'root' || TRUE === $ispage)
  57.                 {
  58.                     $configdoc->load($_pl);
  59.                     if(($re = $configdoc->documentElement->nodeName) != 'config')
  60.                         throw New ILLI_Exception('Unknown root-element "'.$re.' in config-file "'.$configurl.'"');
  61.                     $configdoc = $configdoc->documentElement;
  62.                 }
  63.                 else    $configdoc = NULL;
  64.             }
  65.            
  66.             if($type == 'root' && NULL === $configdoc)
  67.                 throw new ILLI_Exception('Missing root-config '.self::$broadcaster.$configurl);
  68.            
  69.             if(NULL === $configdoc)
  70.             {
  71.                 $configdoc = new DOMDocument;
  72.                 $configdoc->formatOutput = true;
  73.                 $configdoc->preserveWhiteSpace = true;
  74.                 $configdoc = $configdoc->createElement('config');
  75.             }
  76.            
  77.             $configdoc = $this->get_XML()->importNode($configdoc, true);
  78.            
  79.            
  80.             $pin = array();
  81.             foreach(explode(DIRECTORY_SEPARATOR, $configurl) as $p)
  82.                 if(($p = preg_replace('#[^0-9]#', NULL, $p)) != '')
  83.                     $pin[] = $p;
  84.                    
  85.             $configdoc->setAttribute('pin', ((($pin = implode('_', $pin)) == '') ? 0 : $pin));
  86.             $configdoc->setAttribute('config', $this->saveChar($configurl));
  87.             $configdoc->setAttribute("type", $type);
  88.            
  89.             $configdoc->setAttribute("ispage", ((TRUE === $ispage) ? "true" : "false"));
  90.            
  91.             if($type == 'section')
  92.                 $configdoc->setAttribute("chapters", 0);
  93.            
  94.            
  95.             $this->get_XMLConfig()->appendChild($configdoc);
  96.             if($type == 'root')
  97.             {
  98.                 $this->parse_XMLConfigRoot();
  99.             }
  100.             else
  101.             {
  102.                 $this->parse_XMLConfigSub($pin);
  103.             }
  104.            
  105.             $this->parse_XMLConfig($configurl);
  106.            
  107.             return $configdoc;
  108.         }
  109.  
  110.  
  111.        
  112.         private function isTextNode(DOMNode $c)
  113.         {
  114.             return ($c->nodeName == '#text');
  115.         }
  116.        
  117.         private function saveChar(string $s)
  118.         {
  119.             return utf8_encode($s);
  120.         }
  121.        
  122.         private function unsaveChar(string $s)
  123.         {
  124.             return utf8_decode($s);
  125.         }
  126.        
  127.         public static function is_Type($type)
  128.         {
  129.             switch($type):
  130.                 case 'root':
  131.                 case 'section':
  132.                 case 'chapter':
  133.                     return true;
  134.             endswitch;
  135.            
  136.             return false;
  137.         }
  138.  
  139.         public static function is_broadcast($loadstuff)
  140.         {
  141.             if(!is_string($loadstuff))
  142.                 return FALSE;
  143.                
  144.             return (bool) is_dir(self::$broadcaster.$loadstuff);
  145.         }
  146.        
  147.         public static function is_broadcastConfigFile($config_xml)
  148.         {
  149.             if(!is_string($config_xml))
  150.                 return FALSE;
  151.                
  152.             return (bool) preg_match('#'.self::$data_config_file.'#i', $config_xml);
  153.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement