view.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /**
  13. * view
  14. *
  15. * Displays the templates
  16. */
  17. class view
  18. {
  19. /**
  20. * variables available in the template
  21. *
  22. * @access private
  23. * @var array
  24. */
  25. private $_variables = array();
  26. /**
  27. * assign variables to be used inside of the template
  28. *
  29. * @access public
  30. * @param string $name
  31. * @param mixed $value
  32. * @return void
  33. */
  34. public function assign($name, $value)
  35. {
  36. $this->_variables[$name] = $value;
  37. }
  38. /**
  39. * render a template
  40. *
  41. * @access public
  42. * @param string $template
  43. * @throws Exception
  44. * @return void
  45. */
  46. public function draw($template)
  47. {
  48. $path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $template . '.php';
  49. if (!file_exists($path))
  50. {
  51. throw new Exception('Template ' . $template . ' not found!', 80);
  52. }
  53. extract($this->_variables);
  54. include $path;
  55. }
  56. }