view.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * PrivateBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link https://github.com/PrivateBin/PrivateBin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. * @version 0.22
  11. */
  12. namespace PrivateBin;
  13. use Exception;
  14. /**
  15. * view
  16. *
  17. * Displays the templates
  18. */
  19. class view
  20. {
  21. /**
  22. * variables available in the template
  23. *
  24. * @access private
  25. * @var array
  26. */
  27. private $_variables = array();
  28. /**
  29. * assign variables to be used inside of the template
  30. *
  31. * @access public
  32. * @param string $name
  33. * @param mixed $value
  34. * @return void
  35. */
  36. public function assign($name, $value)
  37. {
  38. $this->_variables[$name] = $value;
  39. }
  40. /**
  41. * render a template
  42. *
  43. * @access public
  44. * @param string $template
  45. * @throws Exception
  46. * @return void
  47. */
  48. public function draw($template)
  49. {
  50. $path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $template . '.php';
  51. if (!file_exists($path))
  52. {
  53. throw new Exception('Template ' . $template . ' not found!', 80);
  54. }
  55. extract($this->_variables);
  56. include $path;
  57. }
  58. }