2024-06-04 01:13:55 -04:00
|
|
|
<?php declare(strict_types=1);
|
2016-07-19 08:02:26 -04:00
|
|
|
/**
|
|
|
|
* 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
|
2016-07-19 08:02:26 -04:00
|
|
|
*/
|
2016-12-12 12:43:23 -05:00
|
|
|
|
2016-12-12 12:50:00 -05:00
|
|
|
namespace PrivateBin;
|
2016-08-11 09:05:43 -04:00
|
|
|
|
2016-07-21 11:09:48 -04:00
|
|
|
use Exception;
|
|
|
|
|
2016-07-19 08:02:26 -04:00
|
|
|
/**
|
2016-08-09 05:54:42 -04:00
|
|
|
* View
|
2016-07-19 08:02:26 -04:00
|
|
|
*
|
|
|
|
* Displays the templates
|
|
|
|
*/
|
2016-08-09 05:54:42 -04:00
|
|
|
class View
|
2016-07-19 08:02:26 -04: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
|
|
|
|
*/
|
|
|
|
public function assign($name, $value)
|
|
|
|
{
|
|
|
|
$this->_variables[$name] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* render a template
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param string $template
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function draw($template)
|
|
|
|
{
|
2024-04-01 12:59:28 -04:00
|
|
|
$file = substr($template, 0, 10) === 'bootstrap-' ? 'bootstrap' : $template;
|
2017-01-08 04:02:07 -05:00
|
|
|
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
|
2016-07-26 02:19:35 -04:00
|
|
|
if (!file_exists($path)) {
|
2016-07-19 08:02:26 -04:00
|
|
|
throw new Exception('Template ' . $template . ' not found!', 80);
|
|
|
|
}
|
|
|
|
extract($this->_variables);
|
|
|
|
include $path;
|
|
|
|
}
|
2024-07-07 10:36:52 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* echo script tag incl. SRI hash for given script file
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @param string $file
|
2024-07-09 15:38:41 -04:00
|
|
|
* @param string $attributes additional attributes to add into the script tag
|
2024-07-07 10:36:52 -04:00
|
|
|
*/
|
2024-07-09 15:38:41 -04:00
|
|
|
private function _scriptTag($file, $attributes = '')
|
2024-07-07 10:36:52 -04:00
|
|
|
{
|
|
|
|
$sri = array_key_exists($file, $this->_variables['SRI']) ?
|
|
|
|
' integrity="' . $this->_variables['SRI'][$file] . '"' : '';
|
|
|
|
$suffix = preg_match('#\d.js$#', $file) == 0 ?
|
|
|
|
'?' . rawurlencode($this->_variables['VERSION']) : '';
|
2024-07-09 15:38:41 -04:00
|
|
|
echo '<script ', $attributes,
|
2024-07-07 10:36:52 -04:00
|
|
|
' type="text/javascript" data-cfasync="false" src="', $file,
|
|
|
|
$suffix, '"', $sri, ' crossorigin="anonymous"></script>', PHP_EOL;
|
|
|
|
}
|
2016-07-19 08:02:26 -04:00
|
|
|
}
|