[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/auth/cas/CAS/ -> domxml-php4-php5.php (source)

   1  <?php
   2  
   3  
   4  /**
   5  
   6  
   7   * @file domxml-php4-php5.php
   8  
   9  
  10   * Require PHP5, uses built-in DOM extension.
  11  
  12  
  13   * To be used in PHP4 scripts using DOMXML extension.
  14  
  15  
  16   * Allows PHP4/DOMXML scripts to run on PHP5/DOM.
  17  
  18  
  19   * (Requires PHP5/XSL extension for domxml_xslt functions)
  20  
  21  
  22   *
  23  
  24  
  25   * Typical use:
  26  
  27  
  28   * <pre>
  29  
  30  
  31   * {
  32  
  33  
  34   *  if (version_compare(PHP_VERSION,'5','>='))
  35  
  36  
  37   *   require_once('domxml-php4-to-php5.php');
  38  
  39  
  40   * }
  41  
  42  
  43   * </pre>
  44  
  45  
  46   *
  47  
  48  
  49   * Version 1.5.5, 2005-01-18, http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/
  50  
  51  
  52   *
  53  
  54  
  55   * ------------------------------------------------------------------<br>
  56  
  57  
  58   * Written by Alexandre Alapetite, http://alexandre.alapetite.net/cv/
  59  
  60  
  61   *
  62  
  63  
  64   * Copyright 2004, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR),
  65  
  66  
  67   * http://creativecommons.org/licenses/by-sa/2.0/fr/
  68  
  69  
  70   * http://alexandre.alapetite.net/divers/apropos/#by-sa
  71  
  72  
  73   * - Attribution. You must give the original author credit
  74  
  75  
  76   * - Share Alike. If you alter, transform, or build upon this work,
  77  
  78  
  79   *   you may distribute the resulting work only under a license identical to this one
  80  
  81  
  82   * - The French law is authoritative
  83  
  84  
  85   * - Any of these conditions can be waived if you get permission from Alexandre Alapetite
  86  
  87  
  88   * - Please send to Alexandre Alapetite the modifications you make,
  89  
  90  
  91   *   in order to improve this file for the benefit of everybody
  92  
  93  
  94   *
  95  
  96  
  97   * If you want to distribute this code, please do it as a link to:
  98  
  99  
 100   * http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/
 101  
 102  
 103   */
 104  
 105  
 106  
 107  
 108  
 109  function domxml_new_doc($version) {return new php4DOMDocument('');}
 110  
 111  
 112  function domxml_open_file($filename) {return new php4DOMDocument($filename);}
 113  
 114  
 115  function domxml_open_mem($str)
 116  
 117  
 118  {
 119  
 120  
 121   $dom=new php4DOMDocument('');
 122  
 123  
 124   $dom->myDOMNode->loadXML($str);
 125  
 126  
 127   return $dom;
 128  
 129  
 130  }
 131  
 132  
 133  function xpath_eval($xpath_context,$eval_str,$contextnode=null) {return $xpath_context->query($eval_str,$contextnode);}
 134  
 135  
 136  function xpath_new_context($dom_document) {return new php4DOMXPath($dom_document);}
 137  
 138  
 139  
 140  
 141  
 142  class php4DOMAttr extends php4DOMNode
 143  
 144  
 145  {
 146  
 147  
 148   function php4DOMAttr($aDOMAttr) {$this->myDOMNode=$aDOMAttr;}
 149  
 150  
 151   function Name() {return $this->myDOMNode->name;}
 152  
 153  
 154   function Specified() {return $this->myDOMNode->specified;}
 155  
 156  
 157   function Value() {return $this->myDOMNode->value;}
 158  
 159  
 160  }
 161  
 162  
 163  
 164  
 165  
 166  class php4DOMDocument extends php4DOMNode
 167  
 168  
 169  {
 170  
 171  
 172   function php4DOMDocument($filename='')
 173  
 174  
 175   {
 176  
 177  
 178    $this->myDOMNode=new DOMDocument();
 179  
 180  
 181    if ($filename!='') $this->myDOMNode->load($filename);
 182  
 183  
 184   }
 185  
 186  
 187   function create_attribute($name,$value)
 188  
 189  
 190   {
 191  
 192  
 193    $myAttr=$this->myDOMNode->createAttribute($name);
 194  
 195  
 196    $myAttr->value=$value;
 197  
 198  
 199    return new php4DOMAttr($myAttr,$this);
 200  
 201  
 202   }
 203  
 204  
 205   function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);}
 206  
 207  
 208   function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);}
 209  
 210  
 211   function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);}
 212  
 213  
 214   function create_text_node($content) {return new php4DOMNode($this->myDOMNode->createTextNode($content),$this);}
 215  
 216  
 217   function document_element() {return new php4DOMElement($this->myDOMNode->documentElement,$this);}
 218  
 219  
 220   function dump_file($filename,$compressionmode=false,$format=false) {return $this->myDOMNode->save($filename);}
 221  
 222  
 223   function dump_mem($format=false,$encoding=false) {return $this->myDOMNode->saveXML();}
 224  
 225  
 226   function get_element_by_id($id) {return new php4DOMElement($this->myDOMNode->getElementById($id),$this);}
 227  
 228  
 229   function get_elements_by_tagname($name)
 230  
 231  
 232   {
 233  
 234  
 235    $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
 236  
 237  
 238    $nodeSet=array();
 239  
 240  
 241    $i=0;
 242  
 243  
 244    if (isset($myDOMNodeList))
 245  
 246  
 247     while ($node=$myDOMNodeList->item($i))
 248  
 249  
 250     {
 251  
 252  
 253      $nodeSet[]=new php4DOMElement($node,$this);
 254  
 255  
 256      $i++;
 257  
 258  
 259     }
 260  
 261  
 262    return $nodeSet;
 263  
 264  
 265   }
 266  
 267  
 268   function html_dump_mem() {return $this->myDOMNode->saveHTML();}
 269  
 270  
 271   function root() {return new php4DOMElement($this->myDOMNode->documentElement,$this);}
 272  
 273  
 274  }
 275  
 276  
 277  
 278  
 279  
 280  class php4DOMElement extends php4DOMNode
 281  
 282  
 283  {
 284  
 285  
 286   function get_attribute($name) {return $this->myDOMNode->getAttribute($name);}
 287  
 288  
 289   function get_elements_by_tagname($name)
 290  
 291  
 292   {
 293  
 294  
 295    $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
 296  
 297  
 298    $nodeSet=array();
 299  
 300  
 301    $i=0;
 302  
 303  
 304    if (isset($myDOMNodeList))
 305  
 306  
 307     while ($node=$myDOMNodeList->item($i))
 308  
 309  
 310     {
 311  
 312  
 313      $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
 314  
 315  
 316      $i++;
 317  
 318  
 319     }
 320  
 321  
 322    return $nodeSet;
 323  
 324  
 325   }
 326  
 327  
 328   function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);}
 329  
 330  
 331   function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);}
 332  
 333  
 334   function set_attribute($name,$value) {return $this->myDOMNode->setAttribute($name,$value);}
 335  
 336  
 337   function tagname() {return $this->myDOMNode->tagName;}
 338  
 339  
 340  }
 341  
 342  
 343  
 344  
 345  
 346  class php4DOMNode
 347  
 348  
 349  {
 350  
 351  
 352   var $myDOMNode;
 353  
 354  
 355   var $myOwnerDocument;
 356  
 357  
 358   function php4DOMNode($aDomNode,$aOwnerDocument)
 359  
 360  
 361   {
 362  
 363  
 364    $this->myDOMNode=$aDomNode;
 365  
 366  
 367    $this->myOwnerDocument=$aOwnerDocument;
 368  
 369  
 370   }
 371  
 372  
 373   function __get($name)
 374  
 375  
 376   {
 377  
 378  
 379    if ($name=='type') return $this->myDOMNode->nodeType;
 380  
 381  
 382    elseif ($name=='tagname') return $this->myDOMNode->tagName;
 383  
 384  
 385    elseif ($name=='content') return $this->myDOMNode->textContent;
 386  
 387  
 388    else
 389  
 390  
 391    {
 392  
 393  
 394     $myErrors=debug_backtrace();
 395  
 396  
 397     trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE);
 398  
 399  
 400     return false;
 401  
 402  
 403    }
 404  
 405  
 406   }
 407  
 408  
 409   function append_child($newnode) {return new php4DOMElement($this->myDOMNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);}
 410  
 411  
 412   function append_sibling($newnode) {return new php4DOMElement($this->myDOMNode->parentNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);}
 413  
 414  
 415   function attributes()
 416  
 417  
 418   {
 419  
 420  
 421    $myDOMNodeList=$this->myDOMNode->attributes;
 422  
 423  
 424    $nodeSet=array();
 425  
 426  
 427    $i=0;
 428  
 429  
 430    if (isset($myDOMNodeList))
 431  
 432  
 433     while ($node=$myDOMNodeList->item($i))
 434  
 435  
 436     {
 437  
 438  
 439      $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument);
 440  
 441  
 442      $i++;
 443  
 444  
 445     }
 446  
 447  
 448    return $nodeSet;
 449  
 450  
 451   }
 452  
 453  
 454   function child_nodes()
 455  
 456  
 457   {
 458  
 459  
 460    $myDOMNodeList=$this->myDOMNode->childNodes;
 461  
 462  
 463    $nodeSet=array();
 464  
 465  
 466    $i=0;
 467  
 468  
 469    if (isset($myDOMNodeList))
 470  
 471  
 472     while ($node=$myDOMNodeList->item($i))
 473  
 474  
 475     {
 476  
 477  
 478      $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
 479  
 480  
 481      $i++;
 482  
 483  
 484     }
 485  
 486  
 487    return $nodeSet;
 488  
 489  
 490   }
 491  
 492  
 493   function children() {return $this->child_nodes();}
 494  
 495  
 496   function clone_node($deep=false) {return new php4DOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);}
 497  
 498  
 499   function first_child() {return new php4DOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);}
 500  
 501  
 502   function get_content() {return $this->myDOMNode->textContent;}
 503  
 504  
 505   function has_attributes() {return $this->myDOMNode->hasAttributes();}
 506  
 507  
 508   function has_child_nodes() {return $this->myDOMNode->hasChildNodes();}
 509  
 510  
 511   function insert_before($newnode,$refnode) {return new php4DOMElement($this->myDOMNode->insertBefore($newnode->myDOMNode,$refnode->myDOMNode),$this->myOwnerDocument);}
 512  
 513  
 514   function is_blank_node()
 515  
 516  
 517   {
 518  
 519  
 520    $myDOMNodeList=$this->myDOMNode->childNodes;
 521  
 522  
 523    $i=0;
 524  
 525  
 526    if (isset($myDOMNodeList))
 527  
 528  
 529     while ($node=$myDOMNodeList->item($i))
 530  
 531  
 532     {
 533  
 534  
 535      if (($node->nodeType==XML_ELEMENT_NODE)||
 536  
 537  
 538          (($node->nodeType==XML_TEXT_NODE)&&!ereg('^([[:cntrl:]]|[[:space:]])*$',$node->nodeValue)))
 539  
 540  
 541       return false;
 542  
 543  
 544      $i++;
 545  
 546  
 547     }
 548  
 549  
 550    return true;
 551  
 552  
 553   }
 554  
 555  
 556   function last_child() {return new php4DOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);}
 557  
 558  
 559   function new_child($name,$content)
 560  
 561  
 562   {
 563  
 564  
 565    $mySubNode=$this->myDOMNode->ownerDocument->createElement($name);
 566  
 567  
 568    $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($content));
 569  
 570  
 571    $this->myDOMNode->appendChild($mySubNode);
 572  
 573  
 574    return new php4DOMElement($mySubNode,$this->myOwnerDocument);
 575  
 576  
 577   }
 578  
 579  
 580   function next_sibling() {return new php4DOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);}
 581  
 582  
 583   function node_name() {return $this->myDOMNode->localName;}
 584  
 585  
 586   function node_type() {return $this->myDOMNode->nodeType;}
 587  
 588  
 589   function node_value() {return $this->myDOMNode->nodeValue;}
 590  
 591  
 592   function owner_document() {return $this->myOwnerDocument;}
 593  
 594  
 595   function parent_node() {return new php4DOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);}
 596  
 597  
 598   function prefix() {return $this->myDOMNode->prefix;}
 599  
 600  
 601   function previous_sibling() {return new php4DOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);}
 602  
 603  
 604   function remove_child($oldchild) {return new php4DOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);}
 605  
 606  
 607   function replace_child($oldnode,$newnode) {return new php4DOMElement($this->myDOMNode->replaceChild($oldnode->myDOMNode,$newnode->myDOMNode),$this->myOwnerDocument);}
 608  
 609  
 610   function set_content($text)
 611  
 612  
 613   {
 614  
 615  
 616    if (($this->myDOMNode->hasChildNodes())&&($this->myDOMNode->firstChild->nodeType==XML_TEXT_NODE))
 617  
 618  
 619     $this->myDOMNode->removeChild($this->myDOMNode->firstChild);
 620  
 621  
 622    return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($text));
 623  
 624  
 625   }
 626  
 627  
 628  }
 629  
 630  
 631  
 632  
 633  
 634  class php4DOMNodelist
 635  
 636  
 637  {
 638  
 639  
 640   var $myDOMNodelist;
 641  
 642  
 643   var $nodeset;
 644  
 645  
 646   function php4DOMNodelist($aDOMNodelist,$aOwnerDocument)
 647  
 648  
 649   {
 650  
 651  
 652    $this->myDOMNodelist=$aDOMNodelist;
 653  
 654  
 655    $this->nodeset=array();
 656  
 657  
 658    $i=0;
 659  
 660  
 661    if (isset($this->myDOMNodelist))
 662  
 663  
 664     while ($node=$this->myDOMNodelist->item($i))
 665  
 666  
 667     {
 668  
 669  
 670      $this->nodeset[]=new php4DOMElement($node,$aOwnerDocument);
 671  
 672  
 673      $i++;
 674  
 675  
 676     }
 677  
 678  
 679   }
 680  
 681  
 682  }
 683  
 684  
 685  
 686  
 687  
 688  class php4DOMXPath
 689  
 690  
 691  {
 692  
 693  
 694   var $myDOMXPath;
 695  
 696  
 697   var $myOwnerDocument;
 698  
 699  
 700   function php4DOMXPath($dom_document)
 701  
 702  
 703   {
 704  
 705  
 706    $this->myOwnerDocument=$dom_document;
 707  
 708  
 709    $this->myDOMXPath=new DOMXPath($dom_document->myDOMNode);
 710  
 711  
 712   }
 713  
 714  
 715   function query($eval_str,$contextnode)
 716  
 717  
 718   {
 719  
 720  
 721    if (isset($contextnode)) return new php4DOMNodelist($this->myDOMXPath->query($eval_str,$contextnode->myDOMNode),$this->myOwnerDocument);
 722  
 723  
 724    else return new php4DOMNodelist($this->myDOMXPath->query($eval_str),$this->myOwnerDocument);
 725  
 726  
 727   }
 728  
 729  
 730   function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);}
 731  
 732  
 733  }
 734  
 735  
 736  
 737  
 738  
 739  if (extension_loaded('xsl'))
 740  
 741  
 742  {//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/
 743  
 744  
 745   function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));}
 746  
 747  
 748   function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);}
 749  
 750  
 751   function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));}
 752  
 753  
 754   class php4DomXsltStylesheet
 755  
 756  
 757   {
 758  
 759  
 760    var $myxsltProcessor;
 761  
 762  
 763    function php4DomXsltStylesheet($dom_document)
 764  
 765  
 766    {
 767  
 768  
 769     $this->myxsltProcessor=new xsltProcessor();
 770  
 771  
 772     $this->myxsltProcessor->importStyleSheet($dom_document);
 773  
 774  
 775    }
 776  
 777  
 778    function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false)
 779  
 780  
 781    {
 782  
 783  
 784     foreach ($xslt_parameters as $param=>$value)
 785  
 786  
 787      $this->myxsltProcessor->setParameter('',$param,$value);
 788  
 789  
 790     $myphp4DOMDocument=new php4DOMDocument();
 791  
 792  
 793     $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode);
 794  
 795  
 796     return $myphp4DOMDocument;
 797  
 798  
 799    }
 800  
 801  
 802    function result_dump_file($dom_document,$filename)
 803  
 804  
 805    {
 806  
 807  
 808     $html=$dom_document->myDOMNode->saveHTML();
 809  
 810  
 811     file_put_contents($filename,$html);
 812  
 813  
 814     return $html;
 815  
 816  
 817    }
 818  
 819  
 820    function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();}
 821  
 822  
 823   }
 824  
 825  
 826  }
 827  
 828  
 829  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7