xmlpage.class.inc.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // Copyright (C) 2010-2014 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Class XMLPage
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  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. // Get the unexpected output but do nothing with it
  50. $sTrash = $this->ob_get_clean_safe();
  51. $this->s_content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?".">\n".trim($this->s_content);
  52. $this->add_header("Content-Length: ".strlen($this->s_content));
  53. foreach($this->a_headers as $s_header)
  54. {
  55. header($s_header);
  56. }
  57. echo $this->s_content;
  58. }
  59. if (class_exists('MetaModel'))
  60. {
  61. MetaModel::RecordQueryTrace();
  62. }
  63. }
  64. public function add($sText)
  65. {
  66. if (!$this->m_bPassThrough)
  67. {
  68. parent::add($sText);
  69. }
  70. else
  71. {
  72. if ($this->m_bHeaderSent)
  73. {
  74. echo $sText;
  75. }
  76. else
  77. {
  78. $s_captured_output = $this->ob_get_clean_safe();
  79. foreach($this->a_headers as $s_header)
  80. {
  81. header($s_header);
  82. }
  83. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?".">\n";
  84. echo trim($s_captured_output);
  85. echo trim($this->s_content);
  86. echo $sText;
  87. $this->m_bHeaderSent = true;
  88. }
  89. }
  90. }
  91. public function small_p($sText)
  92. {
  93. }
  94. public function table($aConfig, $aData, $aParams = array())
  95. {
  96. }
  97. }