capturewebpage.class.inc.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // Copyright (C) 2016 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. * Adapter class: when an API requires WebPage and you want to produce something else
  20. *
  21. * @copyright Copyright (C) 2016 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. require_once(APPROOT."/application/webpage.class.inc.php");
  25. class CaptureWebPage extends WebPage
  26. {
  27. protected $aReadyScripts;
  28. function __construct()
  29. {
  30. parent::__construct('capture web page');
  31. $this->aReadyScripts = array();
  32. }
  33. public function GetHtml()
  34. {
  35. $trash = $this->ob_get_clean_safe();
  36. return $this->s_content;
  37. }
  38. public function GetJS()
  39. {
  40. $sRet = implode("\n", $this->a_scripts);
  41. if (!empty($this->s_deferred_content))
  42. {
  43. $sRet .= "\n\$('body').append('".addslashes(str_replace("\n", '', $this->s_deferred_content))."');";
  44. }
  45. return $sRet;
  46. }
  47. public function GetReadyJS()
  48. {
  49. return "\$(document).ready(function() {\n".implode("\n", $this->aReadyScripts)."\n});";
  50. }
  51. public function GetCSS()
  52. {
  53. return $this->a_styles;
  54. }
  55. public function GetJSFiles()
  56. {
  57. return $this->a_linked_scripts;
  58. }
  59. public function GetCSSFiles()
  60. {
  61. return $this->a_linked_stylesheets;
  62. }
  63. public function output()
  64. {
  65. throw new Exception(__method__.' should not be called');
  66. }
  67. public function add_ready_script($sScript)
  68. {
  69. $this->aReadyScripts[] = $sScript;
  70. }
  71. }