PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/tiny.php

https://bitbucket.org/malguzt/defierro
PHP | 74 lines | 33 code | 8 blank | 33 comment | 3 complexity | 22bec72f1788848a819e7141839c3cab MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright (c) 2009, Guillermo O. <Tordek> Freschi
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the name of Tordek nor the names of its contributors may be
  14. * used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY Guillermo O. Freschi ''AS IS'' AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. define("TEMPLATE_DIR", 'template/');
  29. define("COMPONENT_RUN_DIR", 'components/');
  30. define("COMPONENT_TEMPLATE_DIR", 'template/components/');
  31. define("LAYOUT_FILE", TEMPLATE_DIR . 'layout.php');
  32. /**
  33. *
  34. * @param string $template Nombre de la vista a usar, sin la extención .php
  35. * @param array $vars Arreglo con las variables que se quiere pasar a la vista. nombre => valor
  36. * @param string $showLayout
  37. * @author Guillermo O. <Tordek> Freschi
  38. */
  39. function ShowTemplate($template, $vars=null, $showLayout=true)
  40. {
  41. if($vars !== null) {
  42. extract($vars);
  43. }
  44. ob_start();
  45. include(TEMPLATE_DIR . $template . ".php");
  46. $tiny_content = ob_get_contents();
  47. ob_end_clean();
  48. if($showLayout) {
  49. ob_start();
  50. include(LAYOUT_FILE);
  51. $output = ob_get_contents();
  52. ob_end_clean();
  53. } else {
  54. $output = $tiny_content;
  55. }
  56. echo $output;
  57. }
  58. function AddComponent($component)
  59. {
  60. include(COMPONENT_RUN_DIR . $component . ".php");
  61. ob_start();
  62. include(COMPONENT_TEMPLATE_DIR. $component . ".php");
  63. $output = ob_get_contents();
  64. ob_end_clean();
  65. echo $output;
  66. }