[ Index ]
 

Code source de Claroline 188

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/claroline/inc/lib/cas/ -> domxml-php4-php5.php (source)

   1  <?php // $Id: domxml-php4-php5.php,v 1.5 2006/10/16 07:55:02 moosh Exp $
   2  if ( count( get_included_files() ) == 1 ) die( '---' );
   3  
   4  /**
   5   * @file domxml-php4-php5.php
   6   * Require PHP5, uses built-in DOM extension.
   7   * To be used in PHP4 scripts using DOMXML extension.
   8   * Allows PHP4/DOMXML scripts to run on PHP5/DOM.
   9   * (Requires PHP5/XSL extension for domxml_xslt functions)
  10   *
  11   * Typical use:
  12   * <pre>
  13   * {
  14   *  if (version_compare(PHP_VERSION,'5','>='))
  15   *   require_once('domxml-php4-to-php5.php');
  16   * }
  17   * </pre>
  18   *
  19   * Version 1.5.5, 2005-01-18, http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/
  20   *
  21   * ------------------------------------------------------------------<br>
  22   * Written by Alexandre Alapetite, http://alexandre.alapetite.net/cv/
  23   *
  24   * Copyright 2004, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR),
  25   * http://creativecommons.org/licenses/by-sa/2.0/fr/
  26   * http://alexandre.alapetite.net/divers/apropos/#by-sa
  27   * - Attribution. You must give the original author credit
  28   * - Share Alike. If you alter, transform, or build upon this work,
  29   *   you may distribute the resulting work only under a license identical to this one
  30   * - The French law is authoritative
  31   * - Any of these conditions can be waived if you get permission from Alexandre Alapetite
  32   * - Please send to Alexandre Alapetite the modifications you make,
  33   *   in order to improve this file for the benefit of everybody
  34   *
  35   * If you want to distribute this code, please do it as a link to:
  36   * http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/
  37   */
  38  
  39  function domxml_new_doc($version) {return new php4DOMDocument('');}
  40  function domxml_open_file($filename) {return new php4DOMDocument($filename);}
  41  function domxml_open_mem($str)
  42  {
  43   $dom=new php4DOMDocument('');
  44   $dom->myDOMNode->loadXML($str);
  45   return $dom;
  46  }
  47  function xpath_eval($xpath_context,$eval_str,$contextnode=null) {return $xpath_context->query($eval_str,$contextnode);}
  48  function xpath_new_context($dom_document) {return new php4DOMXPath($dom_document);}
  49  
  50  class php4DOMAttr extends php4DOMNode
  51  {
  52   function php4DOMAttr($aDOMAttr) {$this->myDOMNode=$aDOMAttr;}
  53   function Name() {return $this->myDOMNode->name;}
  54   function Specified() {return $this->myDOMNode->specified;}
  55   function Value() {return $this->myDOMNode->value;}
  56  }
  57  
  58  class php4DOMDocument extends php4DOMNode
  59  {
  60   function php4DOMDocument($filename='')
  61   {
  62    $this->myDOMNode=new DOMDocument();
  63    if ($filename!='') $this->myDOMNode->load($filename);
  64   }
  65   function create_attribute($name,$value)
  66   {
  67    $myAttr=$this->myDOMNode->createAttribute($name);
  68    $myAttr->value=$value;
  69    return new php4DOMAttr($myAttr,$this);
  70   }
  71   function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);}
  72   function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);}
  73   function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);}
  74   function create_text_node($content) {return new php4DOMNode($this->myDOMNode->createTextNode($content),$this);}
  75   function document_element() {return new php4DOMElement($this->myDOMNode->documentElement,$this);}
  76   function dump_file($filename,$compressionmode=false,$format=false) {return $this->myDOMNode->save($filename);}
  77   function dump_mem($format=false,$encoding=false) {return $this->myDOMNode->saveXML();}
  78   function get_element_by_id($id) {return new php4DOMElement($this->myDOMNode->getElementById($id),$this);}
  79   function get_elements_by_tagname($name)
  80   {
  81    $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
  82    $nodeSet=array();
  83    $i=0;
  84    if (isset($myDOMNodeList))
  85     while ($node=$myDOMNodeList->item($i))
  86     {
  87      $nodeSet[]=new php4DOMElement($node,$this);
  88      $i++;
  89     }
  90    return $nodeSet;
  91   }
  92   function html_dump_mem() {return $this->myDOMNode->saveHTML();}
  93   function root() {return new php4DOMElement($this->myDOMNode->documentElement,$this);}
  94  }
  95  
  96  class php4DOMElement extends php4DOMNode
  97  {
  98   function get_attribute($name) {return $this->myDOMNode->getAttribute($name);}
  99   function get_elements_by_tagname($name)
 100   {
 101    $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
 102    $nodeSet=array();
 103    $i=0;
 104    if (isset($myDOMNodeList))
 105     while ($node=$myDOMNodeList->item($i))
 106     {
 107      $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
 108      $i++;
 109     }
 110    return $nodeSet;
 111   }
 112   function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);}
 113   function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);}
 114   function set_attribute($name,$value) {return $this->myDOMNode->setAttribute($name,$value);}
 115   function tagname() {return $this->myDOMNode->tagName;}
 116  }
 117  
 118  class php4DOMNode
 119  {
 120   var $myDOMNode;
 121   var $myOwnerDocument;
 122   function php4DOMNode($aDomNode,$aOwnerDocument)
 123   {
 124    $this->myDOMNode=$aDomNode;
 125    $this->myOwnerDocument=$aOwnerDocument;
 126   }
 127   function __get($name)
 128   {
 129    if ($name=='type') return $this->myDOMNode->nodeType;
 130    elseif ($name=='tagname') return $this->myDOMNode->tagName;
 131    elseif ($name=='content') return $this->myDOMNode->textContent;
 132    else
 133    {
 134     $myErrors=debug_backtrace();
 135     trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE);
 136     return false;
 137    }
 138   }
 139   function append_child($newnode) {return new php4DOMElement($this->myDOMNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);}
 140   function append_sibling($newnode) {return new php4DOMElement($this->myDOMNode->parentNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);}
 141   function attributes()
 142   {
 143    $myDOMNodeList=$this->myDOMNode->attributes;
 144    $nodeSet=array();
 145    $i=0;
 146    if (isset($myDOMNodeList))
 147     while ($node=$myDOMNodeList->item($i))
 148     {
 149      $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument);
 150      $i++;
 151     }
 152    return $nodeSet;
 153   }
 154   function child_nodes()
 155   {
 156    $myDOMNodeList=$this->myDOMNode->childNodes;
 157    $nodeSet=array();
 158    $i=0;
 159    if (isset($myDOMNodeList))
 160     while ($node=$myDOMNodeList->item($i))
 161     {
 162      $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
 163      $i++;
 164     }
 165    return $nodeSet;
 166   }
 167   function children() {return $this->child_nodes();}
 168   function clone_node($deep=false) {return new php4DOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);}
 169   function first_child() {return new php4DOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);}
 170   function get_content() {return $this->myDOMNode->textContent;}
 171   function has_attributes() {return $this->myDOMNode->hasAttributes();}
 172   function has_child_nodes() {return $this->myDOMNode->hasChildNodes();}
 173   function insert_before($newnode,$refnode) {return new php4DOMElement($this->myDOMNode->insertBefore($newnode->myDOMNode,$refnode->myDOMNode),$this->myOwnerDocument);}
 174   function is_blank_node()
 175   {
 176    $myDOMNodeList=$this->myDOMNode->childNodes;
 177    $i=0;
 178    if (isset($myDOMNodeList))
 179     while ($node=$myDOMNodeList->item($i))
 180     {
 181      if (($node->nodeType==XML_ELEMENT_NODE)||
 182          (($node->nodeType==XML_TEXT_NODE)&&!ereg('^([[:cntrl:]]|[[:space:]])*$',$node->nodeValue)))
 183       return false;
 184      $i++;
 185     }
 186    return true;
 187   }
 188   function last_child() {return new php4DOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);}
 189   function new_child($name,$content)
 190   {
 191    $mySubNode=$this->myDOMNode->ownerDocument->createElement($name);
 192    $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($content));
 193    $this->myDOMNode->appendChild($mySubNode);
 194    return new php4DOMElement($mySubNode,$this->myOwnerDocument);
 195   }
 196   function next_sibling() {return new php4DOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);}
 197   function node_name() {return $this->myDOMNode->localName;}
 198   function node_type() {return $this->myDOMNode->nodeType;}
 199   function node_value() {return $this->myDOMNode->nodeValue;}
 200   function owner_document() {return $this->myOwnerDocument;}
 201   function parent_node() {return new php4DOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);}
 202   function prefix() {return $this->myDOMNode->prefix;}
 203   function previous_sibling() {return new php4DOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);}
 204   function remove_child($oldchild) {return new php4DOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);}
 205   function replace_child($oldnode,$newnode) {return new php4DOMElement($this->myDOMNode->replaceChild($oldnode->myDOMNode,$newnode->myDOMNode),$this->myOwnerDocument);}
 206   function set_content($text)
 207   {
 208    if (($this->myDOMNode->hasChildNodes())&&($this->myDOMNode->firstChild->nodeType==XML_TEXT_NODE))
 209     $this->myDOMNode->removeChild($this->myDOMNode->firstChild);
 210    return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($text));
 211   }
 212  }
 213  
 214  class php4DOMNodelist
 215  {
 216   var $myDOMNodelist;
 217   var $nodeset;
 218   function php4DOMNodelist($aDOMNodelist,$aOwnerDocument)
 219   {
 220    $this->myDOMNodelist=$aDOMNodelist;
 221    $this->nodeset=array();
 222    $i=0;
 223    if (isset($this->myDOMNodelist))
 224     while ($node=$this->myDOMNodelist->item($i))
 225     {
 226      $this->nodeset[]=new php4DOMElement($node,$aOwnerDocument);
 227      $i++;
 228     }
 229   }
 230  }
 231  
 232  class php4DOMXPath
 233  {
 234   var $myDOMXPath;
 235   var $myOwnerDocument;
 236   function php4DOMXPath($dom_document)
 237   {
 238    $this->myOwnerDocument=$dom_document;
 239    $this->myDOMXPath=new DOMXPath($dom_document->myDOMNode);
 240   }
 241   function query($eval_str,$contextnode)
 242   {
 243    if (isset($contextnode)) return new php4DOMNodelist($this->myDOMXPath->query($eval_str,$contextnode->myDOMNode),$this->myOwnerDocument);
 244    else return new php4DOMNodelist($this->myDOMXPath->query($eval_str),$this->myOwnerDocument);
 245   }
 246   function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);}
 247  }
 248  
 249  if (extension_loaded('xsl'))
 250  {//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/
 251   function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));}
 252   function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);}
 253   function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));}
 254   class php4DomXsltStylesheet
 255   {
 256    var $myxsltProcessor;
 257    function php4DomXsltStylesheet($dom_document)
 258    {
 259     $this->myxsltProcessor=new xsltProcessor();
 260     $this->myxsltProcessor->importStyleSheet($dom_document);
 261    }
 262    function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false)
 263    {
 264     foreach ($xslt_parameters as $param=>$value)
 265      $this->myxsltProcessor->setParameter('',$param,$value);
 266     $myphp4DOMDocument=new php4DOMDocument();
 267     $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode);
 268     return $myphp4DOMDocument;
 269    }
 270    function result_dump_file($dom_document,$filename)
 271    {
 272     $html=$dom_document->myDOMNode->saveHTML();
 273     file_put_contents($filename,$html);
 274     return $html;
 275    }
 276    function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();}
 277   }
 278  }
 279  ?>


Généré le : Thu Nov 29 14:38:42 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics