Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.90 KB | None | 0 0
  1. <?php
  2. // ------------------------------------------- \\
  3. //  Log Class                                  \\
  4. // ------------------------------------------- \\
  5. //  Autor: Maciej Czerwiński                   \\
  6. //         orsonium@gmail.com                  \\
  7. // ------------------------------------------- \\
  8. //  Licencja: GNU General Public License v2.0  \\
  9. // ------------------------------------------- \\
  10. include_once('libs/xml.php');
  11. include_once('globals.php');
  12.  
  13. class c_Log {
  14.  
  15.      public $hError;
  16.      public $sFile;
  17.      public $iLine;
  18.      public $sDate;
  19.      public $sReqUri;
  20.      public $sClientIP;
  21.      
  22.      function __construct($aError){
  23.           $this->hError = $aError['code'];
  24.           $this->sFile = $aError['file'];
  25.           $this->iLine = $aError['line'];
  26.           $this->sDate = time();
  27.           $this->sReqUri = $_SERVER['REQUEST_URI'];
  28.           $this->sClientIP = $_SERVER['REMOTE_ADDR'];
  29.      }
  30. }
  31.  
  32. class c_WriteLog extends c_Log {
  33.      
  34.      protected $pLogFile;
  35.      protected $hDoc;
  36.      
  37.      protected function checkFile($aYear, $aMonth, $aDay){
  38.           $sDirectory = "log/$aYear-$aMonth-$aDay.xml";
  39.           if(!is_file($sDirectory)){
  40.                $this->pLogFile = fopen($sDirectory, 'a+');
  41.                if($this->pLogFile){
  42.                    
  43.                     fclose($this->pLogFile);
  44.                     return $sDirectory;
  45.                }
  46.                else{
  47.                     return false;
  48.                }
  49.           }
  50.           else{
  51.                return $sDirectory;
  52.           }
  53.          
  54.      }
  55.      
  56.      function addLog(){                                            
  57.                $sDirectory = $this->checkFile(date('Y',$this->sDate),date('m',$this->sDate),date('d',$this->sDate));
  58.                $this->hDoc = new c_XMLDocument($sDirectory);
  59.                $this->hDoc->load($sDirectory);
  60.                
  61.                $root = $this->hDoc->getElementByTagName('root');
  62.                
  63.                if(!$root){
  64.                     $root = $this->hDoc->createElement('root');
  65.                }
  66.                $item = $root->createElement('item');
  67.                $item->createElement('hError', $this->hError);
  68.                $item->createElement('sFile', $this->sFile);
  69.                $item->createElement('iLine', $this->iLine);
  70.                $item->createElement('sDate', $this->sDate);
  71.                $item->createElement('sReqUri', $this->sReqUri);
  72.                $item->createElement('sClientIP', $this->sClientIP);
  73.                              
  74.                $this->hDoc->save($sDirectory);              
  75.      }
  76.              
  77. }
  78.  
  79. //class c_ReadLog extends c_Log {
  80. //
  81. //}
  82. ?>
  83.  
  84. <?php
  85. // ------------------------------------------- \\
  86. //  XML Renderer Class                         \\
  87. // ------------------------------------------- \\
  88. //  Autor: Maciej Czerwiński                   \\
  89. //         orsonium@gmail.com                  \\
  90. // ------------------------------------------- \\
  91. //  Licencja: GNU General Public License v2.0  \\
  92. // ------------------------------------------- \\
  93.  
  94. class c_XMLNode{
  95.  
  96.      public $hNode;
  97.      public $hDocument;
  98.      
  99.      public function __construct($node, $hDocument){
  100.           $this->hNode = $node;
  101.           $this->hDocument = $hDocument;
  102.      }
  103.      
  104.      public function createElement($aTagName, $aTagValue = NULL, $aAttr = NULL){
  105.           $newNode = $this->hDocument->createElement($aTagName, $aTagValue);
  106.           if($aAttr){
  107.                $size = sizeof($aAttr['attrNames']);
  108.                for( $i=0 ; $i < $size ; $i++){
  109.                     $newNode->hNode->setAttribute($aAttr['attrNames'][$i],$aAttr['attrValues'][$i]);
  110.                }
  111.           }
  112.           $return = new c_XMLNode($this->hNode->appendChild($newNode->hNode), $this->hDocument);
  113.           return $return;
  114.      }
  115.      
  116.      public function editText($text){
  117.           $this->hNode->nodeValue = $text;
  118.      }
  119.      
  120.      public function importXML($aData){
  121.           $content = new DOMDocument;
  122.           $content->loadXML($aData);
  123.           $node = $this->hDocument->hDocument->importNode($content->documentElement, true);
  124.           $return = new c_XMLNode($this->hNode->appendChild($node), $this->hDocument);
  125.           return $return;
  126.      }
  127.      
  128. }
  129.  
  130. class c_XMLDocument{
  131.  
  132.      public $hDocument;
  133.      
  134.      public function __construct(){
  135.           $this->hDocument = new DOMDocument('1.0', 'UTF-8');        
  136.      }
  137.      
  138.      public function load($aScheme){
  139.           if(!$this->hDocument->load($aScheme))
  140.                $error = new c_Error('0x00D0',__FILE__,__LINE__);
  141.      }
  142.      
  143.      public function createElement($aTagName, $aTagValue = NULL, $aAttr = NULL){
  144.           $newNode = $this->hDocument->createElement($aTagName, $aTagValue);
  145.           if($aAttr){
  146.                $size = sizeof($aAttr['attrNames']);
  147.                for( $i=0 ; $i < $size ; $i++){
  148.                     $newNode->setAttribute($aAttr['attrNames'][$i],$aAttr['attrValues'][$i]);
  149.                }
  150.           }
  151.           $return = new c_XMLNode($this->hDocument->appendChild($newNode), $this);
  152.           return $return;
  153.      }
  154.      
  155.      public function getElement($id){
  156.           $return = new c_XMLNode($this->hDocument->getElementById($id), $this);
  157.           return $return;    
  158.      }
  159.      
  160.      public function getElementByTagName($aTagName){
  161.           $result = $this->hDocument->getElementsByTagName($aTagName);
  162.           if($result->length == 0)
  163.             return false;
  164.           else
  165.             return new c_XMLNode($result->item(0), $this);
  166.           return $return;    
  167.      }
  168.      
  169.      
  170.      public function save($aDirectory){
  171.           $this->hDocument->save($aDirectory);
  172.      }
  173.      
  174.      public function printPage(){
  175.           echo $this->hDocument->saveXML();
  176.      }
  177.      
  178.      public function getPage(){
  179.           return $this->hDocument->saveXML();
  180.      }
  181.      
  182. }
  183. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement