2018-10-17 15:07:17 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PrivateBin
|
|
|
|
*
|
|
|
|
* a zero-knowledge paste bin
|
|
|
|
*
|
|
|
|
* @link https://github.com/PrivateBin/PrivateBin
|
|
|
|
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
|
|
|
* @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
2019-04-12 18:14:25 +02:00
|
|
|
* @version 1.2.1
|
2018-10-17 15:07:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PrivateBin;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2019-04-12 18:14:25 +02:00
|
|
|
$file = substr($template, 0, 9) === 'bootstrap' ? 'bootstrap' : $template;
|
|
|
|
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
|
2018-10-17 15:07:17 +02:00
|
|
|
if (!file_exists($path)) {
|
|
|
|
throw new Exception('Template ' . $template . ' not found!', 80);
|
|
|
|
}
|
|
|
|
extract($this->_variables);
|
|
|
|
include $path;
|
|
|
|
}
|
|
|
|
}
|