ajaxwebpage.class.inc.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * Simple web page with no includes, header or fancy formatting, useful to
  18. * generate HTML fragments when called by an AJAX method
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. require_once("../application/webpage.class.inc.php");
  26. class ajax_page extends WebPage
  27. {
  28. /**
  29. * Jquery style ready script
  30. * @var Hash
  31. */
  32. protected $m_sReadyScript;
  33. /**
  34. * constructor for the web page
  35. * @param string $s_title Not used
  36. */
  37. function __construct($s_title)
  38. {
  39. parent::__construct($s_title);
  40. $this->m_sReadyScript = "";
  41. $this->add_header("Content-type: text/html; charset=utf-8");
  42. $this->add_header("Cache-control: no-cache");
  43. }
  44. /**
  45. * Echoes the content of the whole page
  46. * @return void
  47. */
  48. public function output()
  49. {
  50. foreach($this->a_headers as $s_header)
  51. {
  52. header($s_header);
  53. }
  54. $s_captured_output = ob_get_contents();
  55. ob_end_clean();
  56. echo $this->s_content;
  57. echo $this->s_deferred_content;
  58. if (!empty($this->m_sReadyScript))
  59. {
  60. echo "<script>\n";
  61. echo $this->m_sReadyScript; // Ready Scripts are output as simple scripts
  62. echo "</script>\n";
  63. }
  64. if (trim($s_captured_output) != "")
  65. {
  66. echo $s_captured_output;
  67. }
  68. }
  69. /**
  70. * Adds a paragraph with a smaller font into the page
  71. * NOT implemented (i.e does nothing)
  72. * @param string $sText Content of the (small) paragraph
  73. * @return void
  74. */
  75. public function small_p($sText)
  76. {
  77. }
  78. /**
  79. * Adds a script to be executed when the DOM is ready (typical JQuery use)
  80. * NOT implemented in this version of the class.
  81. * @return void
  82. */
  83. public function add_ready_script($sScript)
  84. {
  85. // Does nothing in ajax rendered content.. for now...
  86. // Maybe we should add this as a simple <script> tag at the end of the output
  87. // considering that at this time everything in the page is "ready"...
  88. $this->m_sReadyScript .= $sScript;
  89. }
  90. /**
  91. * Cannot be called in this context, since Ajax pages do not share
  92. * any context with the calling page !!
  93. */
  94. public function GetUniqueId()
  95. {
  96. assert(false);
  97. return 0;
  98. }
  99. }
  100. ?>