PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/gulliver/thirdparty/html2ps_pdf/treebuilder.class.php

https://bitbucket.org/ferOnti/processmaker
PHP | 48 lines | 36 code | 4 blank | 8 comment | 6 complexity | b74da689d014077ebc7d05546a4695a1 MD5 | raw file
  1. <?php
  2. // $Header: /cvsroot/html2ps/treebuilder.class.php,v 1.16 2006/11/11 13:43:53 Konstantin Exp $
  3. require_once(HTML2PS_DIR.'dom.activelink.inc.php');
  4. require_once(HTML2PS_DIR.'dom.php5.inc.php');
  5. if (!defined('XML_ELEMENT_NODE')) { define('XML_ELEMENT_NODE',1); };
  6. if (!defined('XML_TEXT_NODE')) { define('XML_TEXT_NODE',2); };
  7. if (!defined('XML_DOCUMENT_NODE')) { define('XML_DOCUMENT_NODE',3); };
  8. class TreeBuilder {
  9. function build($xmlstring) {
  10. // Detect if we're using PHP 4 (DOM XML extension)
  11. // or PHP 5 (DOM extension)
  12. // First uses a set of domxml_* functions,
  13. // Second - object-oriented interface
  14. // Third - pure PHP XML parser
  15. if (function_exists('domxml_open_mem')) { return domxml_open_mem($xmlstring); };
  16. if (class_exists('DOMDocument')) { return DOMTree::from_DOMDocument(DOMDocument::loadXML($xmlstring)); };
  17. if (file_exists(HTML2PS_DIR.'/classes/include.php')) {
  18. require_once(HTML2PS_DIR.'classes/include.php');
  19. import('org.active-link.xml.XML');
  20. import('org.active-link.xml.XMLDocument');
  21. // preprocess character references
  22. // literal references (actually, parser SHOULD do it itself; nevertheless, Activelink just ignores these entities)
  23. $xmlstring = preg_replace("/&amp;/","&",$xmlstring);
  24. $xmlstring = preg_replace("/&quot;/","\"",$xmlstring);
  25. $xmlstring = preg_replace("/&lt;/","<",$xmlstring);
  26. $xmlstring = preg_replace("/&gt;/",">",$xmlstring);
  27. // in decimal form
  28. while (preg_match("@&#(\d+);@",$xmlstring, $matches)) {
  29. $xmlstring = preg_replace("@&#".$matches[1].";@",code_to_utf8($matches[1]),$xmlstring);
  30. };
  31. // in hexadecimal form
  32. while (preg_match("@&#x(\d+);@i",$xmlstring, $matches)) {
  33. $xmlstring = preg_replace("@&#x".$matches[1].";@i",code_to_utf8(hexdec($matches[1])),$xmlstring);
  34. };
  35. $tree = ActiveLinkDOMTree::from_XML(new XML_($xmlstring));
  36. return $tree;
  37. }
  38. die("None of DOM/XML, DOM or ActiveLink DOM extension found. Check your PHP configuration.");
  39. }
  40. };
  41. ?>