2016-07-19 20:02:26 +08: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
|
2016-08-25 15:53:31 +08:00
|
|
|
* @version 1.0
|
2016-07-19 20:02:26 +08:00
|
|
|
*/
|
2016-12-13 01:43:23 +08:00
|
|
|
|
|
|
|
namespace PrivateBin;;
|
2016-08-11 21:05:43 +08:00
|
|
|
|
2016-07-21 23:09:48 +08:00
|
|
|
use Exception;
|
|
|
|
|
2016-07-19 20:02:26 +08:00
|
|
|
/**
|
2016-08-09 17:54:42 +08:00
|
|
|
* View
|
2016-07-19 20:02:26 +08:00
|
|
|
*
|
|
|
|
* Displays the templates
|
|
|
|
*/
|
2016-08-09 17:54:42 +08:00
|
|
|
class View
|
2016-07-19 20:02:26 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function assign($name, $value)
|
|
|
|
{
|
|
|
|
$this->_variables[$name] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* render a template
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param string $template
|
|
|
|
* @throws Exception
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function draw($template)
|
|
|
|
{
|
|
|
|
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $template . '.php';
|
2016-07-26 14:19:35 +08:00
|
|
|
if (!file_exists($path)) {
|
2016-07-19 20:02:26 +08:00
|
|
|
throw new Exception('Template ' . $template . ' not found!', 80);
|
|
|
|
}
|
|
|
|
extract($this->_variables);
|
|
|
|
include $path;
|
|
|
|
}
|
|
|
|
}
|