ajaxwebpage.class.inc.php 2.9 KB

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