<?php
/*
Copyright (C) 2008 by oscim   Project lossim  [ 15.09.2009, 09:17:59] @oscim
// kate: replace-trailing-space-save true; space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; word-wrap-marker-color #41C2A4
ENCODE UTF-8
*/
/**
  @package lossim <web http://www.lossim.org>
  @author oscim <mail dom@oscim.fr > <web http://www.oscim.fr>
  @class xml_parser

*/
class xml_parser  extends cstr{
  var $analyseur;
  var $fichierXml;
  var $balisesOuvrantes;
  var $balisesFermantes;
  var $recup_bf;

  function xml_parser ($fichier,$b_more=true) {
    $this->fichierXml = $fichier;
    /* Si more actif , block sortie */
    $this->balise_more = ($b_more==true) ? true : false ;
    $this->more=false;
    include("type_parser/balises.inc");
    $this->balisesOuvrantes =$Ouvrantes;
    $this->balisesFermantes =$Fermantes;
    $this->recup_bf=$this->recup_bf_cpt=array();
  }


  /**
    function de recuperation des balise manquante pour eviter casser html
  */
  function recup_balisef($op,$nom=''){
    $this->recup_bf_cpt[]=$nom;
    $this->recup_bf[$nom] = (isset($this->recup_bf[$nom])) ? $this->recup_bf[$nom] : 0 ;

    if ($op=='ouvre') $this->recup_bf[$nom]= ($this->recup_bf[$nom] + 1)  ;
    elseif ($op=='ferme') $this->recup_bf[$nom]=  ($this->recup_bf[$nom] - 1) ;

    if ($op=='recup')  return krsort($this->recup_bf_cpt);
    return $this->recup_bf;
  }


  /**
   balise standard
  */
  function deb_bali($parser,$nom,$attributs){
    $bal=strtolower($nom);
    $html = (!empty($this->align))? " align=\"".$this->align."\"" : '' ;
    $html .= (isset($this->onmouseover)&&!empty($this->onmouseover))? " onmouseover=\"".$this->onmouseover."\"" : '' ;
    $html .= (!empty($this->onmouseout))? " onmouseout=\"".$this->onmouseout."\"" : '' ;
    $html .= (!empty($this->onclick))? " onclick=\"".$this->onclick."\"" : '' ;
    $html .= (!empty($this->onmouseup))? " onmouseup=\"".$this->onmouseup."\"" : '' ;
    $html .= (!empty($this->onmousedown))? " onmousedown=\"".$this->onmousedown."\"" : '' ;
    $html .= (!empty($this->onblur))? " onblur=\"".$this->onblur."\"" : '' ;
    $s= '<'.$bal.'';
    $s .=($this->id !='')? ' id="'.$this->id.'"':'';
    $s .=($this->style !='')? ' style="'.$this->style.'"':'';
    $s .=($this->classe !='')? ' class="'.$this->classe.'"':'';
    $s .=$html. ">";
    /* Block si parser */
    if (!isset($CSS_AFTER_BODY)) print $s;
  }


  //Methodes
  function debutBalise($parser, $nom, $attributs) {
    ## parametre generaux
    $this->id = (!empty($attributs["ID"])) ? $attributs["ID"] : '' ;
    $this->classe = (!empty($attributs["CLASS"])) ? $attributs["CLASS"] : '' ;
    $this->style = (!empty($attributs["STYLE"])) ? $attributs["STYLE"] : '' ;
            $this->style .= (!empty($attributs["SIZE"])) ? ' font-size:'.($attributs["SIZE"]*20 +100).'%; ' : '' ;
            $this->style .= (!empty($attributs["COLOR"])) ? ' color:'.$attributs["COLOR"].'; ' : '' ;
    $this->align = (!empty($attributs["ALIGN"])) ? $attributs["ALIGN"] : '' ;
    $this->onmouseover = (!empty($attributs["ONMOUSEOVER"])) ? $attributs["ONMOUSEOVER"] : '' ;
    $this->onmouseout = (!empty($attributs["ONMOUSEOUT"])) ? $attributs["ONMOUSEOUT"] : '' ;
    $this->onclick = (!empty($attributs["ONCLICK"])) ? $attributs["ONCLICK"] : '' ;
    $this->onmouseup = (!empty($attributs["ONMOUSEUP"])) ? $attributs["ONMOUSEUP"] : '' ;
    $this->onmousedown = (!empty($attributs["ONMOUSEDOWN"])) ? $attributs["ONMOUSEDOWN"] : '' ;
    $this->onblur = (!empty($attributs["ONBLUR"])) ? $attributs["ONBLUR"] : '' ;

    if($nom == "FONT"  ) $nom = "SPAN";
    if ($this->more !=true ){
      /* passage name */
      $this->recup_balisef('ouvre',$nom);
      if (isset($this->balisesOuvrantes[$nom])){
        if($nom == "MORE") return $this->more = ($this->balise_more ==true)? true : false;
        if($nom == "NEWS") {
                $this->date=$attributs["DATE"];
                $this->user_post=$attributs["AUTEUR"];
        }
        /* traitement base */
        if ($this->balisesOuvrantes[$nom]!='auto' && $this->balisesOuvrantes[$nom]!='') print($this->balisesOuvrantes[$nom]);
        /* traitement standard auto */
        elseif ($this->balisesOuvrantes[$nom]=='auto') $this->deb_bali($parser,$nom,$attributs);
        /* traitement complexe  */
        else {
          if( $nom == "IMG" ) include("type_parser/img.inc");
          elseif( in_array($nom ,array("TABLE", "TR", "TD", "TH")))  include("type_parser/table.inc");
          elseif( $nom == "SWF" || $nom == "YOUTUBE" || $nom == "OBJECT" ) include("type_parser/flash.inc");
          elseif( $nom == "A" ) include("type_parser/liens.inc");
          elseif( in_array($nom ,array("INPUT", "FORM", "LABEL")) ) include("type_parser/input.inc");

          include(TBL_PARSER_BALISE);

          if (isset($_Parser_balise)&&is_array($_Parser_balise)){
          reset($_Parser_balise);
          while ($r=each($_Parser_balise))
                  if( $nom == strtoupper($r['key'])) include("type_parser/".strtolower($r['value']['complexe']).".inc");
          }
        }
      }
    }
  }

  function finBalise($parser, $nom) {
    /* Si more actif , block sortie */
    if ($this->more !=true) {
      /* passage name */
      $this->recup_balisef('ferme',$nom);
      if($nom == "MORE"  ) return;
      if (isset($this->balisesFermantes[$nom])&& $this->balisesFermantes[$nom] !='') print($this->balisesFermantes[$nom]);
      else{
        if($nom=="AUTEUR")include("type_parser/auteur_f.inc");
        elseif($nom == "A" )include("type_parser/liens_f.inc");
        elseif( $nom == "IMG" )include("type_parser/img_f.inc");
        elseif( in_array($nom ,array("INPUT")) ) include("type_parser/input_f.inc");

         include(TBL_PARSER_BALISE);

         if (isset($_Parser_balise)&&is_array($_Parser_balise)){
         reset($_Parser_balise);
         while ($r=each($_Parser_balise)){
                if( $nom == strtoupper($r['key'])) require("type_parser/".strtolower($r['value']['complexe'])."_f.inc");
        }
        }
      }
    }
  }

  function texte($parser, $data) {
    if ($this->more !=true) print nett_acen("$data");
  }

  function gestionnaireDePI($parser, $cible, $data) {
    require("lib_parser/gestionnaireDePI.inc");
  }

  function gestionnaireDeRefExterne($parser, $openEntityNames, $base, $systemId, $publicId) {
    if(test_const('REF_EXT_FOR_PARSE_XML')) require("lib_parser/gestionnaireDeRefExterne.inc");
  }

  function analyser() {
     require("lib_parser/analyser.inc");
  }
}
/*
require_once("class.xml_parser_complement.php");*/

?>