ajaxwebpage.class.inc.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. if (!empty($this->m_sReadyScript))
  58. {
  59. echo "<script>\n";
  60. echo $this->m_sReadyScript; // Ready Scripts are output as simple scripts
  61. echo "</script>\n";
  62. }
  63. if (trim($s_captured_output) != "")
  64. {
  65. echo $s_captured_output;
  66. }
  67. }
  68. /**
  69. * Adds a paragraph with a smaller font into the page
  70. * NOT implemented (i.e does nothing)
  71. * @param string $sText Content of the (small) paragraph
  72. * @return void
  73. */
  74. public function small_p($sText)
  75. {
  76. }
  77. /**
  78. * Adds a script to be executed when the DOM is ready (typical JQuery use)
  79. * NOT implemented in this version of the class.
  80. * @return void
  81. */
  82. public function add_ready_script($sScript)
  83. {
  84. // Does nothing in ajax rendered content.. for now...
  85. // Maybe we should add this as a simple <script> tag at the end of the output
  86. // considering that at this time everything in the page is "ready"...
  87. $this->m_sReadyScript .= $sScript;
  88. }
  89. }
  90. ?>