Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ------------------------------------------- \\
- // Log Class \\
- // ------------------------------------------- \\
- // Autor: Maciej Czerwiński \\
- // orsonium@gmail.com \\
- // ------------------------------------------- \\
- // Licencja: GNU General Public License v2.0 \\
- // ------------------------------------------- \\
- include_once('libs/xml.php');
- include_once('globals.php');
- class c_Log {
- public $hError;
- public $sFile;
- public $iLine;
- public $sDate;
- public $sReqUri;
- public $sClientIP;
- function __construct($aError){
- $this->hError = $aError['code'];
- $this->sFile = $aError['file'];
- $this->iLine = $aError['line'];
- $this->sDate = time();
- $this->sReqUri = $_SERVER['REQUEST_URI'];
- $this->sClientIP = $_SERVER['REMOTE_ADDR'];
- }
- }
- class c_WriteLog extends c_Log {
- protected $pLogFile;
- protected $hDoc;
- protected function checkFile($aYear, $aMonth, $aDay){
- $sDirectory = "log/$aYear-$aMonth-$aDay.xml";
- if(!is_file($sDirectory)){
- $this->pLogFile = fopen($sDirectory, 'a+');
- if($this->pLogFile){
- fclose($this->pLogFile);
- return $sDirectory;
- }
- else{
- return false;
- }
- }
- else{
- return $sDirectory;
- }
- }
- function addLog(){
- $sDirectory = $this->checkFile(date('Y',$this->sDate),date('m',$this->sDate),date('d',$this->sDate));
- $this->hDoc = new c_XMLDocument($sDirectory);
- $this->hDoc->load($sDirectory);
- $root = $this->hDoc->getElementByTagName('root');
- if(!$root){
- $root = $this->hDoc->createElement('root');
- }
- $item = $root->createElement('item');
- $item->createElement('hError', $this->hError);
- $item->createElement('sFile', $this->sFile);
- $item->createElement('iLine', $this->iLine);
- $item->createElement('sDate', $this->sDate);
- $item->createElement('sReqUri', $this->sReqUri);
- $item->createElement('sClientIP', $this->sClientIP);
- $this->hDoc->save($sDirectory);
- }
- }
- //class c_ReadLog extends c_Log {
- //
- //}
- ?>
- <?php
- // ------------------------------------------- \\
- // XML Renderer Class \\
- // ------------------------------------------- \\
- // Autor: Maciej Czerwiński \\
- // orsonium@gmail.com \\
- // ------------------------------------------- \\
- // Licencja: GNU General Public License v2.0 \\
- // ------------------------------------------- \\
- class c_XMLNode{
- public $hNode;
- public $hDocument;
- public function __construct($node, $hDocument){
- $this->hNode = $node;
- $this->hDocument = $hDocument;
- }
- public function createElement($aTagName, $aTagValue = NULL, $aAttr = NULL){
- $newNode = $this->hDocument->createElement($aTagName, $aTagValue);
- if($aAttr){
- $size = sizeof($aAttr['attrNames']);
- for( $i=0 ; $i < $size ; $i++){
- $newNode->hNode->setAttribute($aAttr['attrNames'][$i],$aAttr['attrValues'][$i]);
- }
- }
- $return = new c_XMLNode($this->hNode->appendChild($newNode->hNode), $this->hDocument);
- return $return;
- }
- public function editText($text){
- $this->hNode->nodeValue = $text;
- }
- public function importXML($aData){
- $content = new DOMDocument;
- $content->loadXML($aData);
- $node = $this->hDocument->hDocument->importNode($content->documentElement, true);
- $return = new c_XMLNode($this->hNode->appendChild($node), $this->hDocument);
- return $return;
- }
- }
- class c_XMLDocument{
- public $hDocument;
- public function __construct(){
- $this->hDocument = new DOMDocument('1.0', 'UTF-8');
- }
- public function load($aScheme){
- if(!$this->hDocument->load($aScheme))
- $error = new c_Error('0x00D0',__FILE__,__LINE__);
- }
- public function createElement($aTagName, $aTagValue = NULL, $aAttr = NULL){
- $newNode = $this->hDocument->createElement($aTagName, $aTagValue);
- if($aAttr){
- $size = sizeof($aAttr['attrNames']);
- for( $i=0 ; $i < $size ; $i++){
- $newNode->setAttribute($aAttr['attrNames'][$i],$aAttr['attrValues'][$i]);
- }
- }
- $return = new c_XMLNode($this->hDocument->appendChild($newNode), $this);
- return $return;
- }
- public function getElement($id){
- $return = new c_XMLNode($this->hDocument->getElementById($id), $this);
- return $return;
- }
- public function getElementByTagName($aTagName){
- $result = $this->hDocument->getElementsByTagName($aTagName);
- if($result->length == 0)
- return false;
- else
- return new c_XMLNode($result->item(0), $this);
- return $return;
- }
- public function save($aDirectory){
- $this->hDocument->save($aDirectory);
- }
- public function printPage(){
- echo $this->hDocument->saveXML();
- }
- public function getPage(){
- return $this->hDocument->saveXML();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement