xmlpage.class.inc.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Class XMLPage
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once(APPROOT."/application/webpage.class.inc.php");
  25. /**
  26. * Simple web page with no includes or fancy formatting, useful to generateXML documents
  27. * The page adds the content-type text/XML and the encoding into the headers
  28. */
  29. class XMLPage extends WebPage
  30. {
  31. /**
  32. * For big XML files, it's better NOT to store everything in memory and output the XML piece by piece
  33. */
  34. var $m_bPassThrough;
  35. var $m_bHeaderSent;
  36. function __construct($s_title, $bPassThrough = false)
  37. {
  38. parent::__construct($s_title);
  39. $this->m_bPassThrough = $bPassThrough;
  40. $this->m_bHeaderSent = false;
  41. $this->add_header("Content-type: text/xml; charset=utf-8");
  42. $this->add_header("Cache-control: no-cache");
  43. $this->add_header("Content-location: export.xml");
  44. }
  45. public function output()
  46. {
  47. if (!$this->m_bPassThrough)
  48. {
  49. $this->add("<?xml version=\"1.0\" encoding=\"UTF-8\"?".">\n");
  50. $this->add_header("Content-Length: ".strlen(trim($this->s_content)));
  51. foreach($this->a_headers as $s_header)
  52. {
  53. header($s_header);
  54. }
  55. echo trim($this->s_content);
  56. }
  57. }
  58. public function add($sText)
  59. {
  60. if (!$this->m_bPassThrough)
  61. {
  62. parent::add($sText);
  63. }
  64. else
  65. {
  66. if ($this->m_bHeaderSent)
  67. {
  68. echo $sText;
  69. }
  70. else
  71. {
  72. $s_captured_output = ob_get_contents();
  73. ob_end_clean();
  74. foreach($this->a_headers as $s_header)
  75. {
  76. header($s_header);
  77. }
  78. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?".">\n";
  79. echo trim($s_captured_output);
  80. echo trim($this->s_content);
  81. echo $sText;
  82. $this->m_bHeaderSent = true;
  83. }
  84. }
  85. }
  86. public function small_p($sText)
  87. {
  88. }
  89. public function table($aConfig, $aData, $aParams = array())
  90. {
  91. }
  92. }
  93. ?>