Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

class.Template.inc.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * basic output functions
  4. *
  5. * PHP version 5
  6. *
  7. * @category PHP
  8. * @package PSI_Output
  9. * @author Damien Roth <iysaak@users.sourceforge.net>
  10. * @copyright 2009 phpSysInfo
  11. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  12. * @version SVN: $Id: class.Output.inc.php 315 2009-09-02 15:48:31Z bigmichi1 $
  13. * @link http://phpsysinfo.sourceforge.net
  14. */
  15. /**
  16. * basic output functions for all output formats
  17. *
  18. * @category PHP
  19. * @package PSI_Output
  20. * @author Damien Roth <iysaak@users.sourceforge.net>
  21. * @copyright 2009 phpSysInfo
  22. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  23. * @version Release: 3.0
  24. * @link http://phpsysinfo.sourceforge.net
  25. */
  26. class Template
  27. {
  28. /**
  29. * Vars used in the template
  30. *
  31. * @Array
  32. */
  33. private $_vars;
  34. /**
  35. * Template file
  36. *
  37. * @String
  38. */
  39. private $_file;
  40. /**
  41. * Constructor
  42. *
  43. * @param String $file the template file name
  44. */
  45. public function __construct($file=null)
  46. {
  47. $this->_file = $file;
  48. $this->_vars = array();
  49. }
  50. /**
  51. * Set a template variable.
  52. *
  53. * @param string variable name
  54. * @param string variable value
  55. */
  56. public function set($name, $value)
  57. {
  58. $this->_vars[$name] = is_object($value) ? $value->fetch() : $value;
  59. }
  60. /**
  61. * Open, parse, and return the template file.
  62. *
  63. * @param string $file
  64. *
  65. * @return string
  66. */
  67. public function fetch($file=null)
  68. {
  69. if (!$file) {
  70. $file = $this->_file;
  71. }
  72. // Extract the vars to local namespace
  73. extract($this->_vars);
  74. // Start output buffering
  75. ob_start();
  76. include(APP_ROOT.$file);
  77. // Get the contents of the buffer
  78. $contents = ob_get_contents();
  79. // End buffering and discard
  80. ob_end_clean();
  81. return $contents;
  82. }
  83. }