mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-06 02:39:59 +02:00
Fix error when a custom template is not in the default available templates list
This commit is contained in:
parent
4eb6555e3c
commit
44f8cfbfb8
4 changed files with 67 additions and 9 deletions
28
lib/View.php
28
lib/View.php
|
@ -49,8 +49,7 @@ class View
|
|||
*/
|
||||
public function draw($template)
|
||||
{
|
||||
$file = substr($template, 0, 10) === 'bootstrap-' ? 'bootstrap' : $template;
|
||||
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
|
||||
$path = self::getTemplateFilePath($template);
|
||||
if (!file_exists($path)) {
|
||||
throw new Exception('Template ' . $template . ' not found!', 80);
|
||||
}
|
||||
|
@ -58,6 +57,31 @@ class View
|
|||
include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template file path
|
||||
*
|
||||
* @access public
|
||||
* @param string $template
|
||||
* @return string
|
||||
*/
|
||||
public static function getTemplateFilePath(string $template): string
|
||||
{
|
||||
$file = self::isBootstrapTemplate($template) ? 'bootstrap' : $template;
|
||||
return PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the template a variation of the bootstrap template
|
||||
*
|
||||
* @access public
|
||||
* @param string $template
|
||||
* @return bool
|
||||
*/
|
||||
public static function isBootstrapTemplate(string $template): bool
|
||||
{
|
||||
return substr($template, 0, 10) === 'bootstrap-';
|
||||
}
|
||||
|
||||
/**
|
||||
* echo script tag incl. SRI hash for given script file
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue