PrivateBin/lib/View.php

62 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/**
* PrivateBin
*
* a zero-knowledge paste bin
*
* @link https://github.com/PrivateBin/PrivateBin
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
2022-11-17 23:36:33 -05:00
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
2024-05-13 13:18:30 -04:00
* @version 1.7.3
*/
2016-12-12 12:43:23 -05:00
2016-12-12 12:50:00 -05:00
namespace PrivateBin;
2016-07-21 11:09:48 -04:00
use Exception;
/**
* View
*
* Displays the templates
*/
class View
{
/**
* variables available in the template
*
* @access private
* @var array
*/
private $_variables = array();
/**
* assign variables to be used inside of the template
*
* @access public
* @param string $name
* @param mixed $value
*/
public function assign($name, $value)
{
$this->_variables[$name] = $value;
}
/**
* render a template
*
* @access public
* @param string $template
* @throws Exception
*/
public function draw($template)
{
$file = substr($template, 0, 10) === 'bootstrap-' ? 'bootstrap' : $template;
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
if (!file_exists($path)) {
throw new Exception('Template ' . $template . ' not found!', 80);
}
extract($this->_variables);
include $path;
}
}